mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 12:11:36 +00:00
standard
This commit is contained in:
parent
db4a06d97f
commit
1a075bd159
@ -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
|
||||
|
@ -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', {
|
||||
|
@ -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 = {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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: {}
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user