Closed benjistokman closed 3 years ago
Bittorrent-tracker does allow you to whitelist only specific infohashes. From the documentation:
var server = new Server({
udp: true, // 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')
if (allowed) {
// If the callback is passed `null`, the torrent will be allowed.
cb(null)
} else {
// If the callback is passed an `Error` object, the torrent will be disallowed
// and the error's `message` property will be given as the reason.
cb(new Error('disallowed torrent'))
}
}
})
Okay thanks, but how do I actually do that? The documentation only gives a single torrent example and no other information whatsoever. And the example seems to do nothing because it's in my /usr/bin/bittorrent-tracker.js
and the tracker still responds to everything.
I've used the bittorrent-tracker example server code exactly as written in the documentation and it wouldn't allow any trackers until I removed that section of code. It sounds like something with how you're implementing it. Care to share your code?
/usr/bin/bittorrent-tracker.js:
var Server = require('bittorrent-tracker').Server
var server = new Server({
udp: true, // 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')
if (allowed) {
// If the callback is passed `null`, the torrent will be allowed.
cb(null)
} else {
// If the callback is passed an `Error` object, the torrent will be disallowed
// and the error's `message` property will be given as the reason.
cb(new Error('disallowed torrent'))
}
}
})
// Internal http, udp, and websocket servers exposed as public properties.
server.http
server.udp
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 udp port:' + server.udp.address().port)
})
// start tracker server listening! Use 0 to listen on a random free port.
server.listen(port, hostname, onlistening)
// 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
Startup command:
bittorrent-tracker -p 6969
Okay so I figured out that I was apparently editing the wrong file. /usr/bin/bittorrent-tracker.js is just an example, the actual file is /usr/local/bin/bittorrent-tracker
What version of this package are you using?
9.17.4
What problem do you want to solve?
Not having the ability to have a static tracker, AKA a tracker that only allows certain infohashes
What do you think is the correct solution to this problem?
Adding the ability to have a static tracker
Are you willing to submit a pull request to implement this change?
No