This commit is contained in:
Feross Aboukhadijeh 2019-07-05 14:36:14 -07:00
parent db4a06d97f
commit 1a075bd159
9 changed files with 14 additions and 14 deletions

View File

@ -62,7 +62,7 @@ class Client extends EventEmitter {
this._wrtc = typeof opts.wrtc === 'function' ? opts.wrtc() : opts.wrtc
let announce = typeof opts.announce === 'string'
? [ opts.announce ]
? [opts.announce]
: opts.announce == null ? [] : opts.announce
// Remove trailing slash from trackers to catch duplicates

View File

@ -176,7 +176,7 @@ class UDPTracker extends Tracker {
}
const infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
? opts.infoHash.map(infoHash => { return infoHash.toString('hex') })
: [ (opts.infoHash && opts.infoHash.toString('hex')) || self.client.infoHash ]
: [(opts.infoHash && opts.infoHash.toString('hex')) || self.client.infoHash]
for (let i = 0, len = (msg.length - 8) / 12; i < len; i += 1) {
self.client.emit('scrape', {

View File

@ -10,7 +10,7 @@ exports.IPV4_RE = /^[\d.]+$/
exports.IPV6_RE = /^[\da-fA-F:]+$/
exports.REMOVE_IPV4_MAPPED_IPV6_RE = /^::ffff:/
exports.CONNECTION_ID = Buffer.concat([ toUInt32(0x417), toUInt32(0x27101980) ])
exports.CONNECTION_ID = Buffer.concat([toUInt32(0x417), toUInt32(0x27101980)])
exports.ACTIONS = { CONNECT: 0, ANNOUNCE: 1, SCRAPE: 2, ERROR: 3 }
exports.EVENTS = { update: 0, completed: 1, started: 2, stopped: 3 }
exports.EVENT_IDS = {

View File

@ -42,7 +42,7 @@ function parseHttpRequest (req, opts) {
} else if (opts.action === 'scrape' || s[0] === '/scrape') {
params.action = common.ACTIONS.SCRAPE
if (typeof params.info_hash === 'string') params.info_hash = [ params.info_hash ]
if (typeof params.info_hash === 'string') params.info_hash = [params.info_hash]
if (Array.isArray(params.info_hash)) {
params.info_hash = params.info_hash.map(function (binaryInfoHash) {
if (typeof binaryInfoHash !== 'string' || binaryInfoHash.length !== 20) {

View File

@ -39,7 +39,7 @@ function parseWebSocketRequest (socket, opts, params) {
} else if (params.action === 'scrape') {
params.action = common.ACTIONS.SCRAPE
if (typeof params.info_hash === 'string') params.info_hash = [ params.info_hash ]
if (typeof params.info_hash === 'string') params.info_hash = [params.info_hash]
if (Array.isArray(params.info_hash)) {
params.info_hash = params.info_hash.map(function (binaryInfoHash) {
if (typeof binaryInfoHash !== 'string' || binaryInfoHash.length !== 20) {

View File

@ -357,7 +357,7 @@ function testClientAnnounceWithNumWant (t, serverType) {
common.createServer(t, serverType, function (server, announceUrl) {
var client1 = new Client({
infoHash: fixtures.leaves.parsedTorrent.infoHash,
announce: [ announceUrl ],
announce: [announceUrl],
peerId: peerId1,
port: port,
wrtc: {}

View File

@ -31,7 +31,7 @@ function serverTest (t, serverType, serverFamily) {
var client1 = new Client({
infoHash: infoHash,
announce: [ announceUrl ],
announce: [announceUrl],
peerId: peerId,
port: 6881,
wrtc: wrtc
@ -43,7 +43,7 @@ function serverTest (t, serverType, serverFamily) {
client1.once('update', function (data) {
var client2 = new Client({
infoHash: infoHash,
announce: [ announceUrl ],
announce: [announceUrl],
peerId: peerId2,
port: 6882,
wrtc: wrtc
@ -68,7 +68,7 @@ function serverTest (t, serverType, serverFamily) {
var client3 = new Client({
infoHash: infoHash,
announce: [ announceUrl ],
announce: [announceUrl],
peerId: peerId3,
port: 6880,
wrtc: wrtc

View File

@ -119,7 +119,7 @@ function clientScrapeMulti (t, serverType) {
commonTest.createServer(t, serverType, function (server, announceUrl) {
Client.scrape({
infoHash: [ infoHash1, infoHash2 ],
infoHash: [infoHash1, infoHash2],
announce: announceUrl
}, function (err, results) {
t.error(err)
@ -161,7 +161,7 @@ test('server: multiple info_hash scrape (manual http request)', function (t) {
var scrapeUrl = announceUrl.replace('/announce', '/scrape')
var url = scrapeUrl + '?' + commonLib.querystringStringify({
info_hash: [ binaryInfoHash1, binaryInfoHash2 ]
info_hash: [binaryInfoHash1, binaryInfoHash2]
})
get.concat(url, function (err, res, data) {

View File

@ -33,7 +33,7 @@ function serverTest (t, serverType, serverFamily) {
var client1 = new Client({
infoHash: infoHash,
announce: [ announceUrl ],
announce: [announceUrl],
peerId: peerId,
port: 6881,
wrtc: wrtc
@ -93,7 +93,7 @@ function serverTest (t, serverType, serverFamily) {
var client2 = new Client({
infoHash: infoHash,
announce: [ announceUrl ],
announce: [announceUrl],
peerId: peerId2,
port: 6882,
wrtc: wrtc
@ -113,7 +113,7 @@ function serverTest (t, serverType, serverFamily) {
var client3 = new Client({
infoHash: infoHash,
announce: [ announceUrl ],
announce: [announceUrl],
peerId: peerId3,
port: 6880,
wrtc: wrtc