add debug

This commit is contained in:
Feross Aboukhadijeh 2014-06-05 23:40:22 -07:00
parent 202bfe8385
commit 85b7c606b9
2 changed files with 6 additions and 1 deletions

View File

@ -6,6 +6,7 @@ var bncode = require('bncode')
var bufferEqual = require('buffer-equal') var bufferEqual = require('buffer-equal')
var compact2string = require('compact2string') var compact2string = require('compact2string')
var concat = require('concat-stream') var concat = require('concat-stream')
var debug = require('debug')('bittorrent-tracker')
var dgram = require('dgram') var dgram = require('dgram')
var EventEmitter = require('events').EventEmitter var EventEmitter = require('events').EventEmitter
var extend = require('extend.js') var extend = require('extend.js')
@ -400,6 +401,7 @@ inherits(Client, EventEmitter)
* @param {Number} opts.interval interval in ms to send announce requests to the tracker * @param {Number} opts.interval interval in ms to send announce requests to the tracker
*/ */
function Client (peerId, port, torrent, opts) { function Client (peerId, port, torrent, opts) {
var self = this var self = this
if (!(self instanceof Client)) return new Client(peerId, port, torrent, opts) if (!(self instanceof Client)) return new Client(peerId, port, torrent, opts)
EventEmitter.call(self) EventEmitter.call(self)
@ -414,17 +416,19 @@ function Client (peerId, port, torrent, opts) {
? torrent.infoHash ? torrent.infoHash
: new Buffer(torrent.infoHash, 'hex') : new Buffer(torrent.infoHash, 'hex')
self.torrentLength = torrent.length self.torrentLength = torrent.length
self._announce = torrent.announce
// optional // optional
self._numWant = self._opts.numWant || 80 self._numWant = self._opts.numWant || 80
self._intervalMs = self._opts.interval || (30 * 60 * 1000) // default: 30 minutes self._intervalMs = self._opts.interval || (30 * 60 * 1000) // default: 30 minutes
debug('new tracker client for ' + self._infoHash.toString('hex'))
if (typeof torrent.announce === 'string') { if (typeof torrent.announce === 'string') {
// magnet-uri returns a string if the magnet uri only contains one 'tr' parameter // magnet-uri returns a string if the magnet uri only contains one 'tr' parameter
torrent.announce = [torrent.announce] torrent.announce = [torrent.announce]
} }
self._trackers = torrent.announce.map(function (announceUrl) { self._trackers = torrent.announce.map(function (announceUrl) {
debug('creating tracker for ' + announceUrl)
return new Tracker(self, announceUrl, self._opts) return new Tracker(self, announceUrl, self._opts)
}) })
} }

View File

@ -16,6 +16,7 @@
"buffer-equal": "0.0.0", "buffer-equal": "0.0.0",
"compact2string": "^1.2.0", "compact2string": "^1.2.0",
"concat-stream": "^1.4.5", "concat-stream": "^1.4.5",
"debug": "^1.0.0",
"extend.js": "0.0.1", "extend.js": "0.0.1",
"hat": "0.0.3", "hat": "0.0.3",
"inherits": "^2.0.1", "inherits": "^2.0.1",