diff options
-rw-r--r-- | lib/torrent.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 093e6b5..a2c6c57 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -66,10 +66,8 @@ inherits(Torrent, EventEmitter) function Torrent (torrentId, client, opts) { EventEmitter.call(this) + this._debugId = 'unknown infohash' this.client = client - this._debugId = this.client.peerId.toString('hex').substring(0, 7) - - this._debug('new torrent') this.announce = opts.announce this.urlList = opts.urlList @@ -124,6 +122,8 @@ function Torrent (torrentId, client, opts) { this._fileModtimes = opts.fileModtimes if (torrentId !== null) this._onTorrentId(torrentId) + + this._debug('new torrent') } Object.defineProperty(Torrent.prototype, 'timeRemaining', { @@ -226,6 +226,7 @@ Torrent.prototype._onTorrentId = function (torrentId) { if (parsedTorrent) { // Attempt to set infoHash property synchronously self.infoHash = parsedTorrent.infoHash + self._debugId = parsedTorrent.infoHash.toString('hex').substring(0, 7) process.nextTick(function () { if (self.destroyed) return self._onParsedTorrent(parsedTorrent) @@ -277,6 +278,8 @@ Torrent.prototype._onParsedTorrent = function (parsedTorrent) { } Torrent.prototype._processParsedTorrent = function (parsedTorrent) { + this._debugId = parsedTorrent.infoHash.toString('hex').substring(0, 7) + if (this.announce) { // Allow specifying trackers via `opts` parameter parsedTorrent.announce = parsedTorrent.announce.concat(this.announce) @@ -1634,7 +1637,7 @@ Torrent.prototype.resume = function () { Torrent.prototype._debug = function () { var args = [].slice.call(arguments) - args[0] = '[' + this._debugId + '] ' + args[0] + args[0] = '[' + this.client._debugId + '] [' + this._debugId + '] ' + args[0] debug.apply(null, args) } |