|
| 1 | +var Server = require('bittorrent-tracker').Server |
| 2 | + |
| 3 | +var server = new Server({ |
| 4 | + udp: true, // enable udp server? [default=true] |
| 5 | + http: true, // enable http server? [default=true] |
| 6 | + ws: true, // enable websocket server? [default=true] |
| 7 | + stats: true, // enable web-based statistics? [default=true] |
| 8 | + filter: function (infoHash, params, cb) { |
| 9 | + // Blacklist/whitelist function for allowing/disallowing torrents. If this option is |
| 10 | + // omitted, all torrents are allowed. It is possible to interface with a database or |
| 11 | + // external system before deciding to allow/deny, because this function is async. |
| 12 | + |
| 13 | + // It is possible to block by peer id (whitelisting torrent clients) or by secret |
| 14 | + // key (private trackers). Full access to the original HTTP/UDP request parameters |
| 15 | + // are available in `params`. |
| 16 | + |
| 17 | + // This example only allows one torrent. |
| 18 | + |
| 19 | + // var allowed = (infoHash === 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa') |
| 20 | + // if (allowed) { |
| 21 | + // // If the callback is passed `null`, the torrent will be allowed. |
| 22 | + // cb(null) |
| 23 | + // } else { |
| 24 | + // // If the callback is passed an `Error` object, the torrent will be disallowed |
| 25 | + // // and the error's `message` property will be given as the reason. |
| 26 | + // cb(new Error('disallowed torrent')) |
| 27 | + // } |
| 28 | + } |
| 29 | +}) |
| 30 | + |
| 31 | +// Internal http, udp, and websocket servers exposed as public properties. |
| 32 | +server.http |
| 33 | +server.udp |
| 34 | +server.ws |
| 35 | + |
| 36 | +server.on('error', function (err) { |
| 37 | + // fatal server error! |
| 38 | + console.log(err.message) |
| 39 | +}) |
| 40 | + |
| 41 | +server.on('warning', function (err) { |
| 42 | + // client sent bad data. probably not a problem, just a buggy client. |
| 43 | + console.log(err.message) |
| 44 | +}) |
| 45 | + |
| 46 | +server.on('listening', function () { |
| 47 | + // fired when all requested servers are listening |
| 48 | + console.log('listening on http port:' + server.http.address().port) |
| 49 | + console.log('listening on udp port:' + server.udp.address().port) |
| 50 | +}) |
| 51 | + |
| 52 | +// start tracker server listening! Use 0 to listen on a random free port. |
| 53 | +server.listen(port, hostname, onlistening) |
| 54 | + |
| 55 | +// listen for individual tracker messages from peers: |
| 56 | + |
| 57 | +server.on('start', function (addr) { |
| 58 | + console.log('got start message from ' + addr) |
| 59 | +}) |
| 60 | + |
| 61 | +server.on('complete', function (addr) {}) |
| 62 | +server.on('update', function (addr) {}) |
| 63 | +server.on('stop', function (addr) {}) |
0 commit comments