Skip to content

Commit 38a8009

Browse files
committed
Fix UDP scrape returning invalid info hashes (Fix webtorrent#97)
1 parent e9322a3 commit 38a8009

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/client/udp-tracker.js

Lines changed: 1 addition & 1 deletion
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 && opts.infoHash.toString('hex')) || self.client._infoHash
149+
: [ (opts.infoHash && opts.infoHash.toString('hex')) || self.client._infoHash ]
150150

151151
for (var i = 0, len = (msg.length - 8) / 12; i < len; i += 1) {
152152
self.client.emit('scrape', {

test/scrape.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function testSingle (t, serverType) {
3636

3737
client.on('scrape', function (data) {
3838
t.equal(data.announce, announceUrl)
39+
t.equal(data.infoHash, parsedBitlove.infoHash)
3940
t.equal(typeof data.complete, 'number')
4041
t.equal(typeof data.incomplete, 'number')
4142
t.equal(typeof data.downloaded, 'number')
@@ -60,6 +61,7 @@ function clientScrapeStatic (t, serverType) {
6061
Client.scrape(announceUrl, infoHash1, function (err, data) {
6162
t.error(err)
6263
t.equal(data.announce, announceUrl)
64+
t.equal(data.infoHash, infoHash1)
6365
t.equal(typeof data.complete, 'number')
6466
t.equal(typeof data.incomplete, 'number')
6567
t.equal(typeof data.downloaded, 'number')
@@ -84,11 +86,13 @@ function clientScrapeMulti (t, serverType) {
8486
t.error(err)
8587

8688
t.equal(results[infoHash1].announce, announceUrl)
89+
t.equal(results[infoHash1].infoHash, infoHash1)
8790
t.equal(typeof results[infoHash1].complete, 'number')
8891
t.equal(typeof results[infoHash1].incomplete, 'number')
8992
t.equal(typeof results[infoHash1].downloaded, 'number')
9093

9194
t.equal(results[infoHash2].announce, announceUrl)
95+
t.equal(results[infoHash2].infoHash, infoHash2)
9296
t.equal(typeof results[infoHash2].complete, 'number')
9397
t.equal(typeof results[infoHash2].incomplete, 'number')
9498
t.equal(typeof results[infoHash2].downloaded, 'number')

0 commit comments

Comments
 (0)