Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release

on:
push:
branches:
- master

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14
- name: Cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install dependencies
run: npm i
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [9.17.2](https://github.com/webtorrent/bittorrent-tracker/compare/v9.17.1...v9.17.2) (2021-06-15)


### Bug Fixes

* modernize ([e5994d2](https://github.com/webtorrent/bittorrent-tracker/commit/e5994d2ebdec10fe2165e31f5b498382eeeaaf5f))

## [9.17.1](https://github.com/webtorrent/bittorrent-tracker/compare/v9.17.0...v9.17.1) (2021-06-15)


### Bug Fixes

* add package-lock ([0e486b0](https://github.com/webtorrent/bittorrent-tracker/commit/0e486b09d80d30e1c13d4624e29c4251000d4092))
* **deps:** update dependency bn.js to ^5.2.0 ([2d36e4a](https://github.com/webtorrent/bittorrent-tracker/commit/2d36e4ae60b1bac51773f2dca81c1a158b51cb28))
* **deps:** update dependency chrome-dgram to ^3.0.6 ([a82aaaa](https://github.com/webtorrent/bittorrent-tracker/commit/a82aaaa31963a0d9adb640166f417142c5d7b970))
* **deps:** update dependency run-parallel to ^1.2.0 ([fcf25ed](https://github.com/webtorrent/bittorrent-tracker/commit/fcf25ed40e1fd64e630b10a0281bc09604b901d3))
* **deps:** update dependency run-series to ^1.1.9 ([fa2c33f](https://github.com/webtorrent/bittorrent-tracker/commit/fa2c33fc91f8ef0a47d0f40b7a046ae179ee328a))
* **deps:** update dependency simple-websocket to ^9.1.0 ([96fedbd](https://github.com/webtorrent/bittorrent-tracker/commit/96fedbdf56ddcf6627eb373a33589db885cb4fb7))
* **deps:** update dependency ws to ^7.4.5 ([6ad7ead](https://github.com/webtorrent/bittorrent-tracker/commit/6ad7ead994e5cb99980a406aea908e4b9ff6151c))
* **deps:** update webtorrent ([1e8d47d](https://github.com/webtorrent/bittorrent-tracker/commit/1e8d47dcd8f5f53b42aa75265a129f950d16feef))
* UDP url parsing ([8e24a8c](https://github.com/webtorrent/bittorrent-tracker/commit/8e24a8c97b55bbaaf2c92a496d1cd30b0c008934))
40 changes: 20 additions & 20 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (argv.version) {
}

if (argv.help) {
console.log(function () {
console.log((() => {
/*
bittorrent-tracker - Start a bittorrent tracker server

Expand All @@ -64,7 +64,7 @@ if (argv.help) {
-v, --version print the current version

*/
}.toString().split(/\n/).slice(2, -2).join('\n'))
}).toString().split(/\n/).slice(2, -2).join('\n'))
process.exit(0)
}

Expand All @@ -85,23 +85,23 @@ const server = new Server({
ws: argv.ws
})

server.on('error', function (err) {
if (!argv.silent) console.error('ERROR: ' + err.message)
server.on('error', err => {
if (!argv.silent) console.error(`ERROR: ${err.message}`)
})
server.on('warning', function (err) {
if (!argv.quiet) console.log('WARNING: ' + err.message)
server.on('warning', err => {
if (!argv.quiet) console.log(`WARNING: ${err.message}`)
})
server.on('update', function (addr) {
if (!argv.quiet) console.log('update: ' + addr)
server.on('update', addr => {
if (!argv.quiet) console.log(`update: ${addr}`)
})
server.on('complete', function (addr) {
if (!argv.quiet) console.log('complete: ' + addr)
server.on('complete', addr => {
if (!argv.quiet) console.log(`complete: ${addr}`)
})
server.on('start', function (addr) {
if (!argv.quiet) console.log('start: ' + addr)
server.on('start', addr => {
if (!argv.quiet) console.log(`start: ${addr}`)
})
server.on('stop', function (addr) {
if (!argv.quiet) console.log('stop: ' + addr)
server.on('stop', addr => {
if (!argv.quiet) console.log(`stop: ${addr}`)
})

const hostname = {
Expand All @@ -110,35 +110,35 @@ const hostname = {
udp6: argv['udp6-hostname']
}

server.listen(argv.port, hostname, function () {
server.listen(argv.port, hostname, () => {
if (server.http && argv.http && !argv.quiet) {
const httpAddr = server.http.address()
const httpHost = httpAddr.address !== '::' ? httpAddr.address : 'localhost'
const httpPort = httpAddr.port
console.log('HTTP tracker: http://' + httpHost + ':' + httpPort + '/announce')
console.log(`HTTP tracker: http://${httpHost}:${httpPort}/announce`)
}
if (server.udp && !argv.quiet) {
const udpAddr = server.udp.address()
const udpHost = udpAddr.address
const udpPort = udpAddr.port
console.log('UDP tracker: udp://' + udpHost + ':' + udpPort)
console.log(`UDP tracker: udp://${udpHost}:${udpPort}`)
}
if (server.udp6 && !argv.quiet) {
const udp6Addr = server.udp6.address()
const udp6Host = udp6Addr.address !== '::' ? udp6Addr.address : 'localhost'
const udp6Port = udp6Addr.port
console.log('UDP6 tracker: udp://' + udp6Host + ':' + udp6Port)
console.log(`UDP6 tracker: udp://${udp6Host}:${udp6Port}`)
}
if (server.ws && !argv.quiet) {
const wsAddr = server.http.address()
const wsHost = wsAddr.address !== '::' ? wsAddr.address : 'localhost'
const wsPort = wsAddr.port
console.log('WebSocket tracker: ws://' + wsHost + ':' + wsPort)
console.log(`WebSocket tracker: ws://${wsHost}:${wsPort}`)
}
if (server.http && argv.stats && !argv.quiet) {
const statsAddr = server.http.address()
const statsHost = statsAddr.address !== '::' ? statsAddr.address : 'localhost'
const statsPort = statsAddr.port
console.log('Tracker stats: http://' + statsHost + ':' + statsPort + '/stats')
console.log(`Tracker stats: http://${statsHost}:${statsPort}/stats`)
}
})
4 changes: 1 addition & 3 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,7 @@ Client.scrape = (opts, cb) => {
})

opts.infoHash = Array.isArray(opts.infoHash)
? opts.infoHash.map(infoHash => {
return Buffer.from(infoHash, 'hex')
})
? opts.infoHash.map(infoHash => Buffer.from(infoHash, 'hex'))
: Buffer.from(opts.infoHash, 'hex')
client.scrape({ infoHash: opts.infoHash })
return client
Expand Down
2 changes: 1 addition & 1 deletion examples/express-embed/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const server = new Server({
http: false, // we do our own
udp: false, // not interested
ws: false, // not interested
filter: function (params) {
filter (params) {
// black/whitelist for disallowing/allowing specific clients [default=allow all]
// this example only allows the uTorrent client
const client = params.peer_id[1] + params.peer_id[2]
Expand Down
6 changes: 2 additions & 4 deletions lib/client/http-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const HTTP_SCRAPE_SUPPORT = /\/(announce)[^/]*$/
* @param {Object} opts options object
*/
class HTTPTracker extends Tracker {
constructor (client, announceUrl, opts) {
constructor (client, announceUrl) {
super(client, announceUrl)

debug('new http tracker %s', announceUrl)
Expand Down Expand Up @@ -62,9 +62,7 @@ class HTTPTracker extends Tracker {
}

const infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
? opts.infoHash.map(infoHash => {
return infoHash.toString('binary')
})
? opts.infoHash.map(infoHash => infoHash.toString('binary'))
: (opts.infoHash && opts.infoHash.toString('binary')) || this.client._infoHashBinary
const params = {
info_hash: infoHashes
Expand Down
4 changes: 2 additions & 2 deletions lib/client/udp-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Tracker = require('./tracker')
* @param {Object} opts options object
*/
class UDPTracker extends Tracker {
constructor (client, announceUrl, opts) {
constructor (client, announceUrl) {
super(client, announceUrl)
debug('new udp tracker %s', announceUrl)

Expand Down Expand Up @@ -181,7 +181,7 @@ class UDPTracker extends Tracker {
return onError(new Error('invalid scrape message'))
}
const infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
? opts.infoHash.map(infoHash => { return infoHash.toString('hex') })
? opts.infoHash.map(infoHash => infoHash.toString('hex'))
: [(opts.infoHash && opts.infoHash.toString('hex')) || self.client.infoHash]

for (let i = 0, len = (msg.length - 8) / 12; i < len; i += 1) {
Expand Down
6 changes: 2 additions & 4 deletions lib/client/websocket-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const RECONNECT_VARIANCE = 5 * 60 * 1000
const OFFER_TIMEOUT = 50 * 1000

class WebSocketTracker extends Tracker {
constructor (client, announceUrl, opts) {
constructor (client, announceUrl) {
super(client, announceUrl)
debug('new websocket tracker %s', announceUrl)

Expand Down Expand Up @@ -76,9 +76,7 @@ class WebSocketTracker extends Tracker {
}

const infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
? opts.infoHash.map(infoHash => {
return infoHash.toString('binary')
})
? opts.infoHash.map(infoHash => infoHash.toString('binary'))
: (opts.infoHash && opts.infoHash.toString('binary')) || this.client._infoHashBinary
const params = {
action: 'scrape',
Expand Down
12 changes: 4 additions & 8 deletions lib/common-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,17 @@ exports.toUInt32 = toUInt32
* @param {string} q
* @return {Object}
*/
exports.querystringParse = function (q) {
return querystring.parse(q, null, null, { decodeURIComponent: unescape })
}
exports.querystringParse = q => querystring.parse(q, null, null, { decodeURIComponent: unescape })

/**
* `querystring.stringify` using `escape` instead of encodeURIComponent, since bittorrent
* clients send non-UTF8 querystrings
* @param {Object} obj
* @return {string}
*/
exports.querystringStringify = function (obj) {
exports.querystringStringify = obj => {
let ret = querystring.stringify(obj, null, null, { encodeURIComponent: escape })
ret = ret.replace(/[@*/+]/g, function (char) {
// `escape` doesn't encode the characters @*/+ so we do it manually
return '%' + char.charCodeAt(0).toString(16).toUpperCase()
})
ret = ret.replace(/[@*/+]/g, char => // `escape` doesn't encode the characters @*/+ so we do it manually
`%${char.charCodeAt(0).toString(16).toUpperCase()}`)
return ret
}
6 changes: 3 additions & 3 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
exports.DEFAULT_ANNOUNCE_PEERS = 50
exports.MAX_ANNOUNCE_PEERS = 82

exports.binaryToHex = function (str) {
exports.binaryToHex = str => {
if (typeof str !== 'string') {
str = String(str)
}
return Buffer.from(str, 'binary').toString('hex')
}

exports.hexToBinary = function (str) {
exports.hexToBinary = str => {
if (typeof str !== 'string') {
str = String(str)
}
Expand All @@ -31,7 +31,7 @@ exports.hexToBinary = function (str) {
// Bug reports:
// - Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=734880
// - Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1374505
exports.parseUrl = function (str) {
exports.parseUrl = str => {
const url = new URL(str.replace(/^udp:/, 'http:'))

if (str.match(/^udp:/)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/server/parse-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ function parseHttpRequest (req, opts) {
params.ip = opts.trustProxy
? req.headers['x-forwarded-for'] || req.connection.remoteAddress
: req.connection.remoteAddress.replace(common.REMOVE_IPV4_MAPPED_IPV6_RE, '') // force ipv4
params.addr = (common.IPV6_RE.test(params.ip) ? '[' + params.ip + ']' : params.ip) + ':' + params.port
params.addr = `${common.IPV6_RE.test(params.ip) ? `[${params.ip}]` : params.ip}:${params.port}`

params.headers = req.headers
} 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 (Array.isArray(params.info_hash)) {
params.info_hash = params.info_hash.map(function (binaryInfoHash) {
params.info_hash = params.info_hash.map(binaryInfoHash => {
if (typeof binaryInfoHash !== 'string' || binaryInfoHash.length !== 20) {
throw new Error('invalid info_hash')
}
return common.binaryToHex(binaryInfoHash)
})
}
} else {
throw new Error('invalid action in HTTP request: ' + req.url)
throw new Error(`invalid action in HTTP request: ${req.url}`)
}

return params
Expand Down
4 changes: 2 additions & 2 deletions lib/server/parse-udp.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function parseUdpRequest (msg, rinfo) {
)

params.port = msg.readUInt16BE(96) || rinfo.port // optional
params.addr = params.ip + ':' + params.port // TODO: ipv6 brackets
params.addr = `${params.ip}:${params.port}` // TODO: ipv6 brackets
params.compact = 1 // udp is always compact
} else if (params.action === common.ACTIONS.SCRAPE) { // scrape message
if ((msg.length - 16) % 20 !== 0) throw new Error('invalid scrape message')
Expand All @@ -54,7 +54,7 @@ function parseUdpRequest (msg, rinfo) {
params.info_hash.push(infoHash)
}
} else {
throw new Error('Invalid action in UDP packet: ' + params.action)
throw new Error(`Invalid action in UDP packet: ${params.action}`)
}

return params
Expand Down
6 changes: 3 additions & 3 deletions lib/server/parse-websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ function parseWebSocketRequest (socket, opts, params) {

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) {
params.info_hash = params.info_hash.map(binaryInfoHash => {
if (typeof binaryInfoHash !== 'string' || binaryInfoHash.length !== 20) {
throw new Error('invalid info_hash')
}
return common.binaryToHex(binaryInfoHash)
})
}
} else {
throw new Error('invalid action in WS request: ' + params.action)
throw new Error(`invalid action in WS request: ${params.action}`)
}

// On first parse, save important data from `socket.upgradeReq` and delete it
Expand All @@ -60,7 +60,7 @@ function parseWebSocketRequest (socket, opts, params) {
: socket.upgradeReq.connection.remoteAddress.replace(common.REMOVE_IPV4_MAPPED_IPV6_RE, '') // force ipv4
socket.port = socket.upgradeReq.connection.remotePort
if (socket.port) {
socket.addr = (common.IPV6_RE.test(socket.ip) ? '[' + socket.ip + ']' : socket.ip) + ':' + socket.port
socket.addr = `${common.IPV6_RE.test(socket.ip) ? `[${socket.ip}]` : socket.ip}:${socket.port}`
}

socket.headers = socket.upgradeReq.headers
Expand Down
Loading