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
6 changes: 3 additions & 3 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ function Client (peerId, port, torrent, opts) {
self._peerIdHex = self._peerId.toString('hex')
self._peerIdBinary = self._peerId.toString('binary')

self._infoHashBuffer = Buffer.isBuffer(torrent.infoHash)
self._infoHash = typeof torrent.infoHash === 'string'
? torrent.infoHash
: new Buffer(torrent.infoHash, 'hex')
self._infoHash = self._infoHashBuffer.toString('hex')
: torrent.infoHash.toString('hex')
self._infoHashBuffer = new Buffer(self._infoHash, 'hex')
self._infoHashBinary = self._infoHashBuffer.toString('binary')

self.torrentLength = torrent.length
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._infoHashBuffer).toString('binary')
: (opts.infoHash && opts.infoHash.toString('binary')) || self.client._infoHashBinary
var params = {
info_hash: infoHashes
}
Expand Down
2 changes: 1 addition & 1 deletion 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._infoHashBuffer).toString('hex')
: [ (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', {
Expand Down
4 changes: 4 additions & 0 deletions test/scrape.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function testSingle (t, serverType) {

client.on('scrape', function (data) {
t.equal(data.announce, announceUrl)
t.equal(data.infoHash, parsedBitlove.infoHash)
t.equal(typeof data.complete, 'number')
t.equal(typeof data.incomplete, 'number')
t.equal(typeof data.downloaded, 'number')
Expand All @@ -60,6 +61,7 @@ function clientScrapeStatic (t, serverType) {
Client.scrape(announceUrl, infoHash1, function (err, data) {
t.error(err)
t.equal(data.announce, announceUrl)
t.equal(data.infoHash, infoHash1)
t.equal(typeof data.complete, 'number')
t.equal(typeof data.incomplete, 'number')
t.equal(typeof data.downloaded, 'number')
Expand All @@ -84,11 +86,13 @@ function clientScrapeMulti (t, serverType) {
t.error(err)

t.equal(results[infoHash1].announce, announceUrl)
t.equal(results[infoHash1].infoHash, infoHash1)
t.equal(typeof results[infoHash1].complete, 'number')
t.equal(typeof results[infoHash1].incomplete, 'number')
t.equal(typeof results[infoHash1].downloaded, 'number')

t.equal(results[infoHash2].announce, announceUrl)
t.equal(results[infoHash2].infoHash, infoHash2)
t.equal(typeof results[infoHash2].complete, 'number')
t.equal(typeof results[infoHash2].incomplete, 'number')
t.equal(typeof results[infoHash2].downloaded, 'number')
Expand Down