Skip to content

Commit 11cce83

Browse files
authored
fix: mangled scrape infohashes (webtorrent#486)
1 parent b487809 commit 11cce83

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/client/http-tracker.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import clone from 'clone'
44
import Debug from 'debug'
55
import get from 'simple-get'
66
import Socks from 'socks'
7-
import { bin2hex, hex2bin, arr2text } from 'uint8-util'
7+
import { bin2hex, hex2bin, arr2text, text2arr, arr2hex } from 'uint8-util'
88

99
import common from '../common.js'
1010
import Tracker from './tracker.js'
@@ -244,12 +244,14 @@ class HTTPTracker extends Tracker {
244244
return
245245
}
246246

247-
keys.forEach(infoHash => {
247+
keys.forEach(_infoHash => {
248248
// TODO: optionally handle data.flags.min_request_interval
249249
// (separate from announce interval)
250-
const response = Object.assign(data[infoHash], {
250+
const infoHash = _infoHash.length !== 20 ? arr2hex(text2arr(_infoHash)) : bin2hex(_infoHash)
251+
252+
const response = Object.assign(data[_infoHash], {
251253
announce: this.announceUrl,
252-
infoHash: bin2hex(infoHash)
254+
infoHash
253255
})
254256
this.client.emit('scrape', response)
255257
})

0 commit comments

Comments
 (0)