Skip to content

Commit e854269

Browse files
committed
Merge tag 'v9.13.0' into upgrade_to_9.13.0
9.13.0
2 parents 0f45981 + cbbd0b6 commit e854269

21 files changed

+48
-54
lines changed

AUTHORS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@
4343
- crapthings ([email protected])
4444
4545
46+
- Jimmy Wärting ([email protected])
47+
- Justin Kalland ([email protected])
48+
- greenkeeper[bot] (23040076+greenkeeper[bot]@users.noreply.github.com)
4649

4750
#### Generated by tools/update-authors.sh.

client.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
const { Buffer } = require('safe-buffer')
21
const debug = require('debug')('bittorrent-tracker:client')
32
const EventEmitter = require('events')
43
const once = require('once')
54
const parallel = require('run-parallel')
65
const Peer = require('simple-peer')
76
const uniq = require('uniq')
8-
const url = require('url')
97

108
const common = require('./lib/common')
119
const HTTPTracker = require('./lib/client/http-tracker') // empty object in browser
@@ -62,7 +60,7 @@ class Client extends EventEmitter {
6260
this._wrtc = typeof opts.wrtc === 'function' ? opts.wrtc() : opts.wrtc
6361

6462
let announce = typeof opts.announce === 'string'
65-
? [ opts.announce ]
63+
? [opts.announce]
6664
: opts.announce == null ? [] : opts.announce
6765

6866
// Remove trailing slash from trackers to catch duplicates
@@ -85,7 +83,14 @@ class Client extends EventEmitter {
8583

8684
this._trackers = announce
8785
.map(announceUrl => {
88-
const parsedUrl = url.parse(announceUrl)
86+
let parsedUrl
87+
try {
88+
parsedUrl = new URL(announceUrl)
89+
} catch (err) {
90+
nextTickWarn(new Error(`Invalid tracker URL: ${announceUrl}`))
91+
return null
92+
}
93+
8994
const port = parsedUrl.port
9095
if (port < 0 || port > 65535) {
9196
nextTickWarn(new Error(`Invalid tracker port: ${announceUrl}`))

lib/client/udp-tracker.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
const arrayRemove = require('unordered-array-remove')
22
const BN = require('bn.js')
3-
const Buffer = require('safe-buffer').Buffer
43
const compact2string = require('compact2string')
54
const debug = require('debug')('bittorrent-tracker:udp-tracker')
65
const dgram = require('dgram')
76
const randombytes = require('randombytes')
8-
const url = require('url')
97

108
const common = require('../common')
119
const Tracker = require('./tracker')
@@ -73,7 +71,7 @@ class UDPTracker extends Tracker {
7371
_request (opts) {
7472
const self = this
7573
if (!opts) opts = {}
76-
const parsedUrl = url.parse(this.announceUrl)
74+
const parsedUrl = new URL(this.announceUrl)
7775
let transactionId = genTransactionId()
7876
let socket = dgram.createSocket('udp4')
7977

@@ -176,7 +174,7 @@ class UDPTracker extends Tracker {
176174
}
177175
const infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
178176
? opts.infoHash.map(infoHash => { return infoHash.toString('hex') })
179-
: [ (opts.infoHash && opts.infoHash.toString('hex')) || self.client.infoHash ]
177+
: [(opts.infoHash && opts.infoHash.toString('hex')) || self.client.infoHash]
180178

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

lib/common-node.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
* These are separate from common.js so they can be skipped when bundling for the browser.
44
*/
55

6-
var Buffer = require('safe-buffer').Buffer
76
var querystring = require('querystring')
87

98
exports.IPV4_RE = /^[\d.]+$/
109
exports.IPV6_RE = /^[\da-fA-F:]+$/
1110
exports.REMOVE_IPV4_MAPPED_IPV6_RE = /^::ffff:/
1211

13-
exports.CONNECTION_ID = Buffer.concat([ toUInt32(0x417), toUInt32(0x27101980) ])
12+
exports.CONNECTION_ID = Buffer.concat([toUInt32(0x417), toUInt32(0x27101980)])
1413
exports.ACTIONS = { CONNECT: 0, ANNOUNCE: 1, SCRAPE: 2, ERROR: 3 }
1514
exports.EVENTS = { update: 0, completed: 1, started: 2, stopped: 3 }
1615
exports.EVENT_IDS = {

lib/common.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* Functions/constants needed by both the client and server.
33
*/
44

5-
var Buffer = require('safe-buffer').Buffer
6-
75
exports.DEFAULT_ANNOUNCE_PEERS = 50
86
exports.MAX_ANNOUNCE_PEERS = 82
97

lib/server/parse-http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function parseHttpRequest (req, opts) {
4242
} else if (opts.action === 'scrape' || s[0] === '/scrape') {
4343
params.action = common.ACTIONS.SCRAPE
4444

45-
if (typeof params.info_hash === 'string') params.info_hash = [ params.info_hash ]
45+
if (typeof params.info_hash === 'string') params.info_hash = [params.info_hash]
4646
if (Array.isArray(params.info_hash)) {
4747
params.info_hash = params.info_hash.map(function (binaryInfoHash) {
4848
if (typeof binaryInfoHash !== 'string' || binaryInfoHash.length !== 20) {

lib/server/parse-websocket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function parseWebSocketRequest (socket, opts, params) {
3939
} else if (params.action === 'scrape') {
4040
params.action = common.ACTIONS.SCRAPE
4141

42-
if (typeof params.info_hash === 'string') params.info_hash = [ params.info_hash ]
42+
if (typeof params.info_hash === 'string') params.info_hash = [params.info_hash]
4343
if (Array.isArray(params.info_hash)) {
4444
params.info_hash = params.info_hash.map(function (binaryInfoHash) {
4545
if (typeof binaryInfoHash !== 'string' || binaryInfoHash.length !== 20) {

package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bittorrent-tracker",
33
"description": "Simple, robust, BitTorrent tracker (client & server) implementation",
4-
"version": "9.11.0",
4+
"version": "9.13.0",
55
"author": {
66
"name": "WebTorrent, LLC",
77
"email": "[email protected]",
@@ -19,7 +19,7 @@
1919
"dependencies": {
2020
"bencode": "^2.0.0",
2121
"bittorrent-peerid": "^1.0.2",
22-
"bn.js": "^4.4.0",
22+
"bn.js": "^5.0.0",
2323
"compact2string": "^1.2.0",
2424
"debug": "^4.0.1",
2525
"ip": "^1.0.1",
@@ -30,14 +30,13 @@
3030
"randombytes": "^2.0.3",
3131
"run-parallel": "^1.1.2",
3232
"run-series": "^1.0.2",
33-
"safe-buffer": "^5.0.0",
3433
"simple-get": "^3.0.0",
3534
"simple-peer": "^9.0.0",
36-
"simple-websocket": "^7.0.1",
35+
"simple-websocket": "^8.0.0",
3736
"string2compact": "^1.1.1",
3837
"uniq": "^1.0.1",
3938
"unordered-array-remove": "^1.0.2",
40-
"ws": "^6.0.0"
39+
"ws": "^7.0.0"
4140
},
4241
"devDependencies": {
4342
"electron-webrtc": "^0.3.0",
@@ -46,9 +45,8 @@
4645
"tape": "^4.0.0",
4746
"webtorrent-fixtures": "^1.3.0"
4847
},
49-
"optionalDependencies": {
50-
"bufferutil": "^4.0.0",
51-
"utf-8-validate": "^5.0.1"
48+
"engines": {
49+
"node": ">=10"
5250
},
5351
"keywords": [
5452
"bittorrent",
@@ -62,12 +60,16 @@
6260
],
6361
"license": "MIT",
6462
"main": "index.js",
63+
"optionalDependencies": {
64+
"bufferutil": "^4.0.0",
65+
"utf-8-validate": "^5.0.1"
66+
},
6567
"repository": {
6668
"type": "git",
6769
"url": "git://github.com/webtorrent/bittorrent-tracker.git"
6870
},
6971
"scripts": {
70-
"update-authors": "./tools/update-authors.sh",
71-
"test": "standard && tape test/*.js"
72+
"test": "standard && tape test/*.js",
73+
"update-authors": "./tools/update-authors.sh"
7274
}
7375
}

server.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const { Buffer } = require('safe-buffer')
21
const bencode = require('bencode')
32
const debug = require('debug')('bittorrent-tracker:server')
43
const dgram = require('dgram')
@@ -15,6 +14,8 @@ const parseHttpRequest = require('./lib/server/parse-http')
1514
const parseUdpRequest = require('./lib/server/parse-udp')
1615
const parseWebSocketRequest = require('./lib/server/parse-websocket')
1716

17+
const hasOwnProperty = Object.prototype.hasOwnProperty
18+
1819
/**
1920
* BitTorrent tracker server.
2021
*
@@ -147,7 +148,7 @@ class Server extends EventEmitter {
147148
let key
148149

149150
for (key in allPeers) {
150-
if (allPeers.hasOwnProperty(key) && filterFunction(allPeers[key])) {
151+
if (hasOwnProperty.call(allPeers, key) && filterFunction(allPeers[key])) {
151152
count++
152153
}
153154
}
@@ -158,7 +159,7 @@ class Server extends EventEmitter {
158159
function groupByClient () {
159160
const clients = {}
160161
for (const key in allPeers) {
161-
if (allPeers.hasOwnProperty(key)) {
162+
if (hasOwnProperty.call(allPeers, key)) {
162163
const peer = allPeers[key]
163164

164165
if (!clients[peer.client.client]) {
@@ -179,10 +180,10 @@ class Server extends EventEmitter {
179180
function printClients (clients) {
180181
let html = '<ul>\n'
181182
for (const name in clients) {
182-
if (clients.hasOwnProperty(name)) {
183+
if (hasOwnProperty.call(clients, name)) {
183184
const client = clients[name]
184185
for (const version in client) {
185-
if (client.hasOwnProperty(version)) {
186+
if (hasOwnProperty.call(client, version)) {
186187
html += `<li><strong>${name}</strong> ${version} : ${client[version]}</li>\n`
187188
}
188189
}
@@ -203,7 +204,7 @@ class Server extends EventEmitter {
203204
const peer = peers.peek(peerId)
204205
if (peer == null) return // peers.peek() can evict the peer
205206

206-
if (!allPeers.hasOwnProperty(peerId)) {
207+
if (!hasOwnProperty.call(allPeers, peerId)) {
207208
allPeers[peerId] = {
208209
ipv4: false,
209210
ipv6: false,
@@ -247,7 +248,7 @@ class Server extends EventEmitter {
247248
clients: groupByClient()
248249
}
249250

250-
if (req.url === '/stats.json' || req.headers['accept'] === 'application/json') {
251+
if (req.url === '/stats.json' || req.headers.accept === 'application/json') {
251252
res.write(JSON.stringify(stats))
252253
res.end()
253254
} else if (req.url === '/stats') {

test/client-large-torrent.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var Buffer = require('safe-buffer').Buffer
21
var Client = require('../')
32
var common = require('./common')
43
var fixtures = require('webtorrent-fixtures')

0 commit comments

Comments
 (0)