Skip to content

Commit c88bbb4

Browse files
committed
standard
1 parent e0c0eb8 commit c88bbb4

24 files changed

+220
-220
lines changed

bin/cmd.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env node
22

3-
var minimist = require('minimist')
4-
var Server = require('../').Server
3+
const minimist = require('minimist')
4+
const Server = require('../').Server
55

6-
var argv = minimist(process.argv.slice(2), {
6+
const argv = minimist(process.argv.slice(2), {
77
alias: {
88
h: 'help',
99
p: 'port',
@@ -70,13 +70,13 @@ if (argv.help) {
7070

7171
if (argv.silent) argv.quiet = true
7272

73-
var allFalsy = !argv.http && !argv.udp && !argv.ws
73+
const allFalsy = !argv.http && !argv.udp && !argv.ws
7474

7575
argv.http = allFalsy || argv.http
7676
argv.udp = allFalsy || argv.udp
7777
argv.ws = allFalsy || argv.ws
7878

79-
var server = new Server({
79+
const server = new Server({
8080
http: argv.http,
8181
interval: argv.interval,
8282
stats: argv.stats,
@@ -104,41 +104,41 @@ server.on('stop', function (addr) {
104104
if (!argv.quiet) console.log('stop: ' + addr)
105105
})
106106

107-
var hostname = {
107+
const hostname = {
108108
http: argv['http-hostname'],
109109
udp4: argv['udp-hostname'],
110110
udp6: argv['udp6-hostname']
111111
}
112112

113113
server.listen(argv.port, hostname, function () {
114114
if (server.http && argv.http && !argv.quiet) {
115-
var httpAddr = server.http.address()
116-
var httpHost = httpAddr.address !== '::' ? httpAddr.address : 'localhost'
117-
var httpPort = httpAddr.port
115+
const httpAddr = server.http.address()
116+
const httpHost = httpAddr.address !== '::' ? httpAddr.address : 'localhost'
117+
const httpPort = httpAddr.port
118118
console.log('HTTP tracker: http://' + httpHost + ':' + httpPort + '/announce')
119119
}
120120
if (server.udp && !argv.quiet) {
121-
var udpAddr = server.udp.address()
122-
var udpHost = udpAddr.address
123-
var udpPort = udpAddr.port
121+
const udpAddr = server.udp.address()
122+
const udpHost = udpAddr.address
123+
const udpPort = udpAddr.port
124124
console.log('UDP tracker: udp://' + udpHost + ':' + udpPort)
125125
}
126126
if (server.udp6 && !argv.quiet) {
127-
var udp6Addr = server.udp6.address()
128-
var udp6Host = udp6Addr.address !== '::' ? udp6Addr.address : 'localhost'
129-
var udp6Port = udp6Addr.port
127+
const udp6Addr = server.udp6.address()
128+
const udp6Host = udp6Addr.address !== '::' ? udp6Addr.address : 'localhost'
129+
const udp6Port = udp6Addr.port
130130
console.log('UDP6 tracker: udp://' + udp6Host + ':' + udp6Port)
131131
}
132132
if (server.ws && !argv.quiet) {
133-
var wsAddr = server.http.address()
134-
var wsHost = wsAddr.address !== '::' ? wsAddr.address : 'localhost'
135-
var wsPort = wsAddr.port
133+
const wsAddr = server.http.address()
134+
const wsHost = wsAddr.address !== '::' ? wsAddr.address : 'localhost'
135+
const wsPort = wsAddr.port
136136
console.log('WebSocket tracker: ws://' + wsHost + ':' + wsPort)
137137
}
138138
if (server.http && argv.stats && !argv.quiet) {
139-
var statsAddr = server.http.address()
140-
var statsHost = statsAddr.address !== '::' ? statsAddr.address : 'localhost'
141-
var statsPort = statsAddr.port
139+
const statsAddr = server.http.address()
140+
const statsHost = statsAddr.address !== '::' ? statsAddr.address : 'localhost'
141+
const statsPort = statsAddr.port
142142
console.log('Tracker stats: http://' + statsHost + ':' + statsPort + '/stats')
143143
}
144144
})

examples/express-embed/server.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
#!/usr/bin/env node
22

3-
var Server = require('../..').Server
4-
var express = require('express')
5-
var app = express()
3+
const Server = require('../..').Server
4+
const express = require('express')
5+
const app = express()
66

77
// https://wiki.theory.org/BitTorrentSpecification#peer_id
8-
var whitelist = {
8+
const whitelist = {
99
UT: true // uTorrent
1010
}
1111

12-
var server = new Server({
12+
const server = new Server({
1313
http: false, // we do our own
1414
udp: false, // not interested
1515
ws: false, // not interested
1616
filter: function (params) {
1717
// black/whitelist for disallowing/allowing specific clients [default=allow all]
1818
// this example only allows the uTorrent client
19-
var client = params.peer_id[1] + params.peer_id[2]
19+
const client = params.peer_id[1] + params.peer_id[2]
2020
return whitelist[client]
2121
}
2222
})
2323

24-
var onHttpRequest = server.onHttpRequest.bind(server)
24+
const onHttpRequest = server.onHttpRequest.bind(server)
2525
app.get('/announce', onHttpRequest)
2626
app.get('/scrape', onHttpRequest)
2727

lib/client/http-tracker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class HTTPTracker extends Tracker {
8686

8787
// Otherwise, wait a short time for pending requests to complete, then force
8888
// destroy them.
89-
var timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT)
89+
let timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT)
9090

9191
// But, if all pending requests complete before the timeout fires, do cleanup
9292
// right away.

lib/client/udp-tracker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class UDPTracker extends Tracker {
4646

4747
// Otherwise, wait a short time for pending requests to complete, then force
4848
// destroy them.
49-
var timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT)
49+
let timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT)
5050

5151
// But, if all pending requests complete before the timeout fires, do cleanup
5252
// right away.

lib/client/websocket-tracker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class WebSocketTracker extends Tracker {
134134

135135
// Otherwise, wait a short time for potential responses to come in from the
136136
// server, then force close the socket.
137-
var timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT)
137+
let timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT)
138138

139139
// But, if a response comes from the server before the timeout fires, do cleanup
140140
// right away.

lib/common-node.js

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

6-
var querystring = require('querystring')
6+
const querystring = require('querystring')
77

88
exports.IPV4_RE = /^[\d.]+$/
99
exports.IPV6_RE = /^[\da-fA-F:]+$/
@@ -38,7 +38,7 @@ exports.REQUEST_TIMEOUT = 15000
3838
exports.DESTROY_TIMEOUT = 1000
3939

4040
function toUInt32 (n) {
41-
var buf = Buffer.allocUnsafe(4)
41+
const buf = Buffer.allocUnsafe(4)
4242
buf.writeUInt32BE(n, 0)
4343
return buf
4444
}
@@ -61,7 +61,7 @@ exports.querystringParse = function (q) {
6161
* @return {string}
6262
*/
6363
exports.querystringStringify = function (obj) {
64-
var ret = querystring.stringify(obj, null, null, { encodeURIComponent: escape })
64+
let ret = querystring.stringify(obj, null, null, { encodeURIComponent: escape })
6565
ret = ret.replace(/[@*/+]/g, function (char) {
6666
// `escape` doesn't encode the characters @*/+ so we do it manually
6767
return '%' + char.charCodeAt(0).toString(16).toUpperCase()

lib/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ exports.hexToBinary = function (str) {
1919
return Buffer.from(str, 'hex').toString('binary')
2020
}
2121

22-
var config = require('./common-node')
22+
const config = require('./common-node')
2323
Object.assign(exports, config)

lib/server/parse-http.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module.exports = parseHttpRequest
22

3-
var common = require('../common')
3+
const common = require('../common')
44

55
function parseHttpRequest (req, opts) {
66
if (!opts) opts = {}
7-
var s = req.url.split('?')
8-
var params = common.querystringParse(s[1])
7+
const s = req.url.split('?')
8+
const params = common.querystringParse(s[1])
99
params.type = 'http'
1010

1111
if (opts.action === 'announce' || s[0] === '/announce') {

lib/server/parse-udp.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module.exports = parseUdpRequest
22

3-
var ipLib = require('ip')
4-
var common = require('../common')
3+
const ipLib = require('ip')
4+
const common = require('../common')
55

66
function parseUdpRequest (msg, rinfo) {
77
if (msg.length < 16) throw new Error('received packet is too short')
88

9-
var params = {
9+
const params = {
1010
connectionId: msg.slice(0, 8), // 64-bit
1111
action: msg.readUInt32BE(8),
1212
transactionId: msg.readUInt32BE(12),
@@ -29,7 +29,7 @@ function parseUdpRequest (msg, rinfo) {
2929
params.event = common.EVENT_IDS[msg.readUInt32BE(80)]
3030
if (!params.event) throw new Error('invalid event') // early return
3131

32-
var ip = msg.readUInt32BE(84) // optional
32+
const ip = msg.readUInt32BE(84) // optional
3333
params.ip = ip
3434
? ipLib.toString(ip)
3535
: rinfo.address
@@ -49,8 +49,8 @@ function parseUdpRequest (msg, rinfo) {
4949
} else if (params.action === common.ACTIONS.SCRAPE) { // scrape message
5050
if ((msg.length - 16) % 20 !== 0) throw new Error('invalid scrape message')
5151
params.info_hash = []
52-
for (var i = 0, len = (msg.length - 16) / 20; i < len; i += 1) {
53-
var infoHash = msg.slice(16 + (i * 20), 36 + (i * 20)).toString('hex') // 20 bytes
52+
for (let i = 0, len = (msg.length - 16) / 20; i < len; i += 1) {
53+
const infoHash = msg.slice(16 + (i * 20), 36 + (i * 20)).toString('hex') // 20 bytes
5454
params.info_hash.push(infoHash)
5555
}
5656
} else {
@@ -60,16 +60,16 @@ function parseUdpRequest (msg, rinfo) {
6060
return params
6161
}
6262

63-
var TWO_PWR_32 = (1 << 16) * 2
63+
const TWO_PWR_32 = (1 << 16) * 2
6464

6565
/**
6666
* Return the closest floating-point representation to the buffer value. Precision will be
6767
* lost for big numbers.
6868
*/
6969
function fromUInt64 (buf) {
70-
var high = buf.readUInt32BE(0) | 0 // force
71-
var low = buf.readUInt32BE(4) | 0
72-
var lowUnsigned = (low >= 0) ? low : TWO_PWR_32 + low
70+
const high = buf.readUInt32BE(0) | 0 // force
71+
const low = buf.readUInt32BE(4) | 0
72+
const lowUnsigned = (low >= 0) ? low : TWO_PWR_32 + low
7373

7474
return (high * TWO_PWR_32) + lowUnsigned
7575
}

lib/server/parse-websocket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = parseWebSocketRequest
22

3-
var common = require('../common')
3+
const common = require('../common')
44

55
function parseWebSocketRequest (socket, opts, params) {
66
if (!opts) opts = {}

0 commit comments

Comments
 (0)