expose client.infoHash and client.infoHashBuffer

This commit is contained in:
Feross Aboukhadijeh 2015-12-02 15:46:41 -08:00
parent 633f6f5924
commit d344537766
3 changed files with 9 additions and 9 deletions

View File

@ -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'

View File

@ -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,

View File

@ -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']