Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion lib/client/http-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions lib/client/udp-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down Expand Up @@ -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'),
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/client/websocket-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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']
Expand Down