add debug messages

This commit is contained in:
Feross Aboukhadijeh 2014-06-06 00:23:02 -07:00
parent 125e9f5796
commit c52169d136

View File

@ -36,6 +36,7 @@ inherits(Tracker, EventEmitter)
* @param {Object} opts optional options * @param {Object} opts optional options
*/ */
function Tracker (client, announceUrl, opts) { function Tracker (client, announceUrl, opts) {
debug('new tracker for ' + announceUrl)
var self = this var self = this
EventEmitter.call(self) EventEmitter.call(self)
self._opts = opts || {} self._opts = opts || {}
@ -51,9 +52,11 @@ function Tracker (client, announceUrl, opts) {
} else { } else {
self._requestImpl = self._requestHttp self._requestImpl = self._requestHttp
} }
} }
Tracker.prototype.start = function (opts) { Tracker.prototype.start = function (opts) {
debug('sent `start` to ' + self._announceUrl)
var self = this var self = this
opts = opts || {} opts = opts || {}
opts.event = 'started' opts.event = 'started'
@ -63,6 +66,7 @@ Tracker.prototype.start = function (opts) {
} }
Tracker.prototype.stop = function (opts) { Tracker.prototype.stop = function (opts) {
debug('sent `stop` to ' + self._announceUrl)
var self = this var self = this
opts = opts || {} opts = opts || {}
opts.event = 'stopped' opts.event = 'stopped'
@ -72,6 +76,7 @@ Tracker.prototype.stop = function (opts) {
} }
Tracker.prototype.complete = function (opts) { Tracker.prototype.complete = function (opts) {
debug('sent `complete` to ' + self._announceUrl)
var self = this var self = this
opts = opts || {} opts = opts || {}
opts.event = 'completed' opts.event = 'completed'
@ -80,6 +85,7 @@ Tracker.prototype.complete = function (opts) {
} }
Tracker.prototype.update = function (opts) { Tracker.prototype.update = function (opts) {
debug('sent `update` to ' + self._announceUrl)
var self = this var self = this
opts = opts || {} opts = opts || {}
self._request(opts) self._request(opts)
@ -98,10 +104,13 @@ Tracker.prototype.scrape = function (opts) {
} }
if (!self._scrapeUrl) { if (!self._scrapeUrl) {
debug('scrape not supported by ' + self._announceUrl)
self.client.emit('error', new Error('scrape not supported for announceUrl ' + self._announceUrl)) self.client.emit('error', new Error('scrape not supported for announceUrl ' + self._announceUrl))
return return
} }
debug('sent `scrape` to ' + self._announceUrl)
opts = extend({ opts = extend({
info_hash: bytewiseEncodeURIComponent(self.client._infoHash) info_hash: bytewiseEncodeURIComponent(self.client._infoHash)
}, opts) }, opts)
@ -428,7 +437,6 @@ function Client (peerId, port, torrent, opts) {
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)
}) })
} }