-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (53 loc) · 2.4 KB
/
index.js
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
var Server = require('bittorrent-tracker').Server
var server = new Server({
udp: false, // enable udp server? [default=true]
http: true, // enable http server? [default=true]
ws: true, // enable websocket server? [default=true]
stats: true, // enable web-based statistics? [default=true]
filter: function (infoHash, params, cb) {
// Blacklist/whitelist function for allowing/disallowing torrents. If this option is
// omitted, all torrents are allowed. It is possible to interface with a database or
// external system before deciding to allow/deny, because this function is async.
// It is possible to block by peer id (whitelisting torrent clients) or by secret
// key (private trackers). Full access to the original HTTP/UDP request parameters
// are available in `params`.
// This example only allows one torrent.
var allowed = (infoHash === 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa')
cb(true)
// In addition to returning a boolean (`true` for allowed, `false` for disallowed),
// you can return an `Error` object to disallow and provide a custom reason.
}
})
// Internal http, udp, and websocket servers exposed as public properties.
// server.http
// server.ws
server.on('error', function (err) {
// fatal server error!
console.log(err.message)
})
server.on('warning', function (err) {
// client sent bad data. probably not a problem, just a buggy client.
console.log(err.message)
})
server.on('listening', function () {
// fired when all requested servers are listening
console.log('listening on http port:' + server.http.address().port)
console.log('listening on ws port:' + server.ws.address().port) // ?
})
// start tracker server listening! Use 0 to listen on a random free port.
server.listen("12345", "0.0.0.0")
// listen for individual tracker messages from peers:
server.on('start', function (addr) {
console.log('got start message from ' + addr)
})
server.on('complete', function (addr) {})
server.on('update', function (addr) {})
server.on('stop', function (addr) {})
// // get info hashes for all torrents in the tracker server
// Object.keys(server.torrents)
// // get the number of seeders for a particular torrent
// server.torrents[infoHash].complete
// // get the number of leechers for a particular torrent
// server.torrents[infoHash].incomplete
// // get the peers who are in a particular torrent swarm
// server.torrents[infoHash].peers