Skip to content

Commit ab3482f

Browse files
author
Aram Drevekenin
committed
Changed infoHash to always be hex
1 parent da760b0 commit ab3482f

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

client.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ function Client (peerId, port, torrent, opts) {
4040
self._peerIdHex = self._peerId.toString('hex')
4141
self._peerIdBinary = self._peerId.toString('binary')
4242

43-
self._infoHash = Buffer.isBuffer(torrent.infoHash)
43+
self._infoHashBuffer = Buffer.isBuffer(torrent.infoHash)
4444
? torrent.infoHash
4545
: new Buffer(torrent.infoHash, 'hex')
46-
self._infoHashHex = self._infoHash.toString('hex')
47-
self._infoHashBinary = self._infoHash.toString('binary')
46+
self._infoHash = self._infoHashBuffer.toString('hex')
47+
self._infoHashBinary = self._infoHashBuffer.toString('binary')
4848

4949
self.torrentLength = torrent.length
5050
self.destroyed = false
@@ -54,7 +54,7 @@ function Client (peerId, port, torrent, opts) {
5454
self._rtcConfig = opts.rtcConfig
5555
self._wrtc = opts.wrtc
5656

57-
debug('new client %s', self._infoHashHex)
57+
debug('new client %s', self._infoHash)
5858

5959
var webrtcSupport = !!self._wrtc || typeof window !== 'undefined'
6060

lib/client/http-tracker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ HTTPTracker.prototype.scrape = function (opts) {
6868
? opts.infoHash.map(function (infoHash) {
6969
return infoHash.toString('binary')
7070
})
71-
: (opts.infoHash || self.client._infoHash).toString('binary')
71+
: (opts.infoHash || self.client._infoHashBuffer).toString('binary')
7272
var params = {
7373
info_hash: infoHashes
7474
}

lib/client/udp-tracker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ UDPTracker.prototype._request = function (opts) {
146146
}
147147
var infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
148148
? opts.infoHash.map(function (infoHash) { return infoHash.toString('hex') })
149-
: (opts.infoHash || self.client._infoHash).toString('hex')
149+
: (opts.infoHash || self.client._infoHashBuffer).toString('hex')
150150

151151
for (var i = 0, len = (msg.length - 8) / 12; i < len; i += 1) {
152152
self.client.emit('scrape', {
@@ -193,7 +193,7 @@ UDPTracker.prototype._request = function (opts) {
193193
connectionId,
194194
common.toUInt32(common.ACTIONS.ANNOUNCE),
195195
transactionId,
196-
self.client._infoHash,
196+
self.client._infoHashBuffer,
197197
self.client._peerId,
198198
toUInt64(opts.downloaded),
199199
opts.left != null ? toUInt64(opts.left) : new Buffer('FFFFFFFFFFFFFFFF', 'hex'),
@@ -211,7 +211,7 @@ UDPTracker.prototype._request = function (opts) {
211211

212212
var infoHash = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
213213
? Buffer.concat(opts.infoHash)
214-
: (opts.infoHash || self.client._infoHash)
214+
: (opts.infoHash || self.client._infoHashBuffer)
215215

216216
send(Buffer.concat([
217217
connectionId,

lib/client/websocket-tracker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ WebSocketTracker.prototype._onSocketData = function (data) {
137137
if (data.info_hash !== self.client._infoHashBinary) {
138138
debug(
139139
'ignoring websocket data from %s for %s (looking for %s: reused socket)',
140-
self.announceUrl, common.binaryToHex(data.info_hash), self.client._infoHashHex
140+
self.announceUrl, common.binaryToHex(data.info_hash), self.client._infoHash
141141
)
142142
return
143143
}
@@ -149,7 +149,7 @@ WebSocketTracker.prototype._onSocketData = function (data) {
149149

150150
debug(
151151
'received %s from %s for %s',
152-
JSON.stringify(data), self.announceUrl, self.client._infoHashHex
152+
JSON.stringify(data), self.announceUrl, self.client._infoHash
153153
)
154154

155155
var failure = data['failure reason']

0 commit comments

Comments
 (0)