forked from webtorrent/bittorrent-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.js
More file actions
executable file
·144 lines (129 loc) · 4.01 KB
/
cmd.js
File metadata and controls
executable file
·144 lines (129 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env node
const minimist = require('minimist')
const Server = require('../').Server
const argv = minimist(process.argv.slice(2), {
alias: {
h: 'help',
p: 'port',
q: 'quiet',
s: 'silent',
v: 'version'
},
boolean: [
'help',
'http',
'quiet',
'silent',
'trust-proxy',
'udp',
'version',
'ws',
'stats'
],
string: [
'http-hostname',
'udp-hostname',
'udp6-hostname'
],
default: {
port: 8000,
stats: true
}
})
if (argv.version) {
console.log(require('../package.json').version)
process.exit(0)
}
if (argv.help) {
console.log((() => {
/*
bittorrent-tracker - Start a bittorrent tracker server
Usage:
bittorrent-tracker [OPTIONS]
If no --http, --udp, or --ws option is supplied, all tracker types will be started.
Options:
-p, --port [number] change the port [default: 8000]
--http-hostname [string] change the http server hostname [default: '::']
--udp-hostname [string] change the udp hostname [default: '0.0.0.0']
--udp6-hostname [string] change the udp6 hostname [default: '::']
--trust-proxy trust 'x-forwarded-for' header from reverse proxy
--interval client announce interval (ms) [default: 600000]
--http enable http server
--udp enable udp server
--ws enable websocket server
--stats enable web-based statistics (default: true)
-q, --quiet only show error output
-s, --silent show no output
-v, --version print the current version
*/
}).toString().split(/\n/).slice(2, -2).join('\n'))
process.exit(0)
}
if (argv.silent) argv.quiet = true
const allFalsy = !argv.http && !argv.udp && !argv.ws
argv.http = allFalsy || argv.http
argv.udp = allFalsy || argv.udp
argv.ws = allFalsy || argv.ws
const server = new Server({
http: argv.http,
interval: argv.interval,
stats: argv.stats,
trustProxy: argv['trust-proxy'],
udp: argv.udp,
ws: argv.ws
})
server.on('error', err => {
if (!argv.silent) console.error(`ERROR: ${err.message}`)
})
server.on('warning', err => {
if (!argv.quiet) console.log(`WARNING: ${err.message}`)
})
server.on('update', addr => {
if (!argv.quiet) console.log(`update: ${addr}`)
})
server.on('complete', addr => {
if (!argv.quiet) console.log(`complete: ${addr}`)
})
server.on('start', addr => {
if (!argv.quiet) console.log(`start: ${addr}`)
})
server.on('stop', addr => {
if (!argv.quiet) console.log(`stop: ${addr}`)
})
const hostname = {
http: argv['http-hostname'],
udp4: argv['udp-hostname'],
udp6: argv['udp6-hostname']
}
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`)
}
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}`)
}
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}`)
}
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}`)
}
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`)
}
})