From ab3482fc4f87d363dd05d33b7b1d35210406ef97 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Sun, 29 Nov 2015 16:02:29 +0200 Subject: [PATCH] Changed infoHash to always be hex --- client.js | 8 ++++---- lib/client/http-tracker.js | 2 +- lib/client/udp-tracker.js | 6 +++--- lib/client/websocket-tracker.js | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client.js b/client.js index f1ff304..035dec0 100644 --- a/client.js +++ b/client.js @@ -40,11 +40,11 @@ function Client (peerId, port, torrent, opts) { self._peerIdHex = self._peerId.toString('hex') self._peerIdBinary = self._peerId.toString('binary') - self._infoHash = Buffer.isBuffer(torrent.infoHash) + self._infoHashBuffer = Buffer.isBuffer(torrent.infoHash) ? torrent.infoHash : new Buffer(torrent.infoHash, 'hex') - self._infoHashHex = self._infoHash.toString('hex') - self._infoHashBinary = self._infoHash.toString('binary') + self._infoHash = self._infoHashBuffer.toString('hex') + self._infoHashBinary = self._infoHashBuffer.toString('binary') self.torrentLength = torrent.length self.destroyed = false @@ -54,7 +54,7 @@ function Client (peerId, port, torrent, opts) { self._rtcConfig = opts.rtcConfig self._wrtc = opts.wrtc - debug('new client %s', self._infoHashHex) + debug('new client %s', self._infoHash) var webrtcSupport = !!self._wrtc || typeof window !== 'undefined' diff --git a/lib/client/http-tracker.js b/lib/client/http-tracker.js index b82691f..d6d6873 100644 --- a/lib/client/http-tracker.js +++ b/lib/client/http-tracker.js @@ -68,7 +68,7 @@ HTTPTracker.prototype.scrape = function (opts) { ? opts.infoHash.map(function (infoHash) { return infoHash.toString('binary') }) - : (opts.infoHash || self.client._infoHash).toString('binary') + : (opts.infoHash || self.client._infoHashBuffer).toString('binary') var params = { info_hash: infoHashes } diff --git a/lib/client/udp-tracker.js b/lib/client/udp-tracker.js index ead529c..c9bf5fb 100644 --- a/lib/client/udp-tracker.js +++ b/lib/client/udp-tracker.js @@ -146,7 +146,7 @@ UDPTracker.prototype._request = function (opts) { } var infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0) ? opts.infoHash.map(function (infoHash) { return infoHash.toString('hex') }) - : (opts.infoHash || self.client._infoHash).toString('hex') + : (opts.infoHash || self.client._infoHashBuffer).toString('hex') for (var i = 0, len = (msg.length - 8) / 12; i < len; i += 1) { self.client.emit('scrape', { @@ -193,7 +193,7 @@ UDPTracker.prototype._request = function (opts) { connectionId, common.toUInt32(common.ACTIONS.ANNOUNCE), transactionId, - self.client._infoHash, + self.client._infoHashBuffer, self.client._peerId, toUInt64(opts.downloaded), opts.left != null ? toUInt64(opts.left) : new Buffer('FFFFFFFFFFFFFFFF', 'hex'), @@ -211,7 +211,7 @@ UDPTracker.prototype._request = function (opts) { var infoHash = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0) ? Buffer.concat(opts.infoHash) - : (opts.infoHash || self.client._infoHash) + : (opts.infoHash || self.client._infoHashBuffer) send(Buffer.concat([ connectionId, diff --git a/lib/client/websocket-tracker.js b/lib/client/websocket-tracker.js index c30136a..a34d2ff 100644 --- a/lib/client/websocket-tracker.js +++ b/lib/client/websocket-tracker.js @@ -137,7 +137,7 @@ WebSocketTracker.prototype._onSocketData = function (data) { if (data.info_hash !== self.client._infoHashBinary) { debug( 'ignoring websocket data from %s for %s (looking for %s: reused socket)', - self.announceUrl, common.binaryToHex(data.info_hash), self.client._infoHashHex + self.announceUrl, common.binaryToHex(data.info_hash), self.client._infoHash ) return } @@ -149,7 +149,7 @@ WebSocketTracker.prototype._onSocketData = function (data) { debug( 'received %s from %s for %s', - JSON.stringify(data), self.announceUrl, self.client._infoHashHex + JSON.stringify(data), self.announceUrl, self.client._infoHash ) var failure = data['failure reason']