Skip to content

Commit 3cd8441

Browse files
committed
Fixes for PR webtorrent#142
1 parent 74f9cda commit 3cd8441

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This module is used by [WebTorrent](http://webtorrent.io).
3232
- Robust and well-tested
3333
- Comprehensive test suite (runs entirely offline, so it's reliable)
3434
- Used by popular clients: [WebTorrent](http://webtorrent.io), [peerflix](https://github.com/mafintosh/peerflix), and [playback](https://mafintosh.github.io/playback/)
35-
- Web-Based Statistics
35+
- Tracker stats avaialable via web interface at `/stats`
3636

3737
Also see [bittorrent-dht](https://github.com/feross/bittorrent-dht).
3838

@@ -144,7 +144,7 @@ var server = new Server({
144144
udp: true, // enable udp server? [default=true]
145145
http: true, // enable http server? [default=true]
146146
ws: true, // enable websocket server? [default=true]
147-
stats: true, // enable web-based statistics [default=true]
147+
stats: true, // enable web-based statistics? [default=true]
148148
filter: function (infoHash, params, cb) {
149149
// Blacklist/whitelist function for allowing/disallowing torrents. If this option is
150150
// omitted, all torrents are allowed. It is possible to interface with a database or

bin/cmd.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ var argv = minimist(process.argv.slice(2), {
2020
'udp',
2121
'version',
2222
'ws',
23-
'no-stats'
23+
'stats'
2424
],
2525
string: [
2626
'http-hostname',
2727
'udp-hostname',
2828
'udp6-hostname'
2929
],
3030
default: {
31-
port: 8000
31+
port: 8000,
32+
stats: true
3233
}
3334
})
3435

@@ -57,7 +58,7 @@ if (argv.help) {
5758
--http enable http server
5859
--udp enable udp server
5960
--ws enable websocket server
60-
--no-stats disable web-based statistics
61+
--stats enable web-based statistics (default: true)
6162
-q, --quiet only show error output
6263
-s, --silent show no output
6364
-v, --version print the current version
@@ -77,12 +78,10 @@ argv.http = allFalsy || argv.http
7778
argv.udp = allFalsy || argv.udp
7879
argv.ws = allFalsy || argv.ws
7980

80-
argv['no-stats'] = !!argv['no-stats']
81-
8281
var server = new Server({
8382
http: argv.http,
8483
interval: argv.interval,
85-
stats: argv['no-stats'],
84+
stats: argv.stats,
8685
trustProxy: argv['trust-proxy'],
8786
udp: argv.udp,
8887
ws: argv.ws
@@ -138,10 +137,10 @@ server.listen(argv.port, hostname, function () {
138137
var wsPort = wsAddr.port
139138
console.log('WebSocket tracker: ws://' + wsHost + ':' + wsPort)
140139
}
141-
if (server.http && argv['no-stats'] && !argv.quiet) {
140+
if (server.http && argv.stats && !argv.quiet) {
142141
var statsAddr = server.http.address()
143142
var statsHost = statsAddr.address !== '::' ? statsAddr.address : 'localhost'
144143
var statsPort = statsAddr.port
145-
console.log('Tracker statistics: http://' + statsHost + ':' + statsPort)
144+
console.log('Tracker stats: http://' + statsHost + ':' + statsPort + '/stats')
146145
}
147146
})

server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ inherits(Server, EventEmitter)
3131
* @param {boolean} opts.http start an http server? (default: true)
3232
* @param {boolean} opts.udp start a udp server? (default: true)
3333
* @param {boolean} opts.ws start a websocket server? (default: true)
34+
* @param {boolean} opts.stats enable web-based statistics? (default: true)
3435
* @param {function} opts.filter black/whitelist fn for disallowing/allowing torrents
3536
*/
3637
function Server (opts) {
@@ -128,7 +129,7 @@ function Server (opts) {
128129
}
129130

130131
// Http handler for '/stats' route
131-
self.http.on('request', function (req, res, opts) {
132+
self.http.on('request', function (req, res) {
132133
if (res.headersSent) return
133134

134135
var infoHashes = Object.keys(self.torrents)

0 commit comments

Comments
 (0)