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 this._wrtc = typeof opts.wrtc === 'function' ? opts.wrtc() : opts.wrtc
let announce = typeof opts.announce === 'string' let announce = typeof opts.announce === 'string'
? [ opts.announce ] ? [opts.announce]
: opts.announce == null ? [] : opts.announce : opts.announce == null ? [] : opts.announce
// Remove trailing slash from trackers to catch duplicates // 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) const infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
? opts.infoHash.map(infoHash => { return infoHash.toString('hex') }) ? 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) { for (let i = 0, len = (msg.length - 8) / 12; i < len; i += 1) {
self.client.emit('scrape', { self.client.emit('scrape', {

View File

@ -10,7 +10,7 @@ exports.IPV4_RE = /^[\d.]+$/
exports.IPV6_RE = /^[\da-fA-F:]+$/ exports.IPV6_RE = /^[\da-fA-F:]+$/
exports.REMOVE_IPV4_MAPPED_IPV6_RE = /^::ffff:/ 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.ACTIONS = { CONNECT: 0, ANNOUNCE: 1, SCRAPE: 2, ERROR: 3 }
exports.EVENTS = { update: 0, completed: 1, started: 2, stopped: 3 } exports.EVENTS = { update: 0, completed: 1, started: 2, stopped: 3 }
exports.EVENT_IDS = { exports.EVENT_IDS = {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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