From d34453776677409048bb2eb6a2274fb9b3e213fc Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 2 Dec 2015 15:46:41 -0800 Subject: [PATCH] expose client.infoHash and client.infoHashBuffer --- client.js | 8 ++++---- lib/client/udp-tracker.js | 6 +++--- lib/client/websocket-tracker.js | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/client.js b/client.js index 281d974..451c942 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 = typeof torrent.infoHash === 'string' + self.infoHash = typeof torrent.infoHash === 'string' ? torrent.infoHash : torrent.infoHash.toString('hex') - self._infoHashBuffer = new Buffer(self._infoHash, 'hex') - self._infoHashBinary = self._infoHashBuffer.toString('binary') + self.infoHashBuffer = new Buffer(self.infoHash, '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._infoHash) + debug('new client %s', self.infoHash) var webrtcSupport = !!self._wrtc || typeof window !== 'undefined' diff --git a/lib/client/udp-tracker.js b/lib/client/udp-tracker.js index e51f5c7..3e3feff 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 && opts.infoHash.toString('hex')) || self.client._infoHash ] + : [ (opts.infoHash && opts.infoHash.toString('hex')) || self.client.infoHash ] 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._infoHashBuffer, + 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._infoHashBuffer) + : (opts.infoHash || self.client.infoHashBuffer) send(Buffer.concat([ connectionId, diff --git a/lib/client/websocket-tracker.js b/lib/client/websocket-tracker.js index a34d2ff..0a842c8 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._infoHash + 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._infoHash + JSON.stringify(data), self.announceUrl, self.client.infoHash ) var failure = data['failure reason']