webrtc-torrent-tracker
Modified version from [web-bt-tracker]: https://npmjs.org/package/web-bt-tracker
install
npm install wtt
usage
client
To connect to a tracker, just do this:
var Client = var requiredOpts = infoHash: '012345678901234567890' // hex string or Buffer peerId: '01234567890123456789' // hex string or Buffer announce: // list of tracker server urls port: 6881 // torrent client port, (in browser, optional) var optionalOpts = { // Provide a callback that will be called whenever announce() is called // internally (on timer), or by the user return uploaded: 0 downloaded: 0 left: 0 customParam: 'blah' // custom parameters supported } // RTCPeerConnection config object (only used in browser) rtcConfig: {} // User-Agent header for http requests userAgent: '' var client = requiredOpts client client // start getting peers from the trackerclientstart client client // announce that download has completed (and you are now a seeder)clientcomplete // force a tracker announce. will trigger more 'update' events and maybe more 'peer' eventsclient // provide parameters to the trackerclient // stop getting peers from the tracker, gracefully leave the swarmclient // ungracefully leave the swarm (without sending final 'stop' message)client // scrapeclient client
server
To start a BitTorrent tracker server to track swarms of peers:
var Server = Server var server = ws: true // enable websocket server? [default=true] stats: true // enable web-based statistics? [default=true] { // 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. 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. } // Internal http, udp, and websocket servers exposed as public properties.serverws server server server // start tracker server listening! Use 0 to listen on a random free port.server // listen for individual tracker messages from peers: server serverserverserver // get info hashes for all torrents in the tracker serverObject // get the number of seeders for a particular torrentservertorrentsinfoHashcomplete // get the number of leechers for a particular torrentservertorrentsinfoHashincomplete // get the peers who are in a particular torrent swarmservertorrentsinfoHashpeers
The http server will handle requests for the following paths: /announce
, /scrape
. Requests for other paths will not be handled.
multi scrape
Scraping multiple torrent info is possible with a static Client.scrape
method:
var Client = Client
command line
Install web-bt-tracker
globally:
$ npm install -g web-bt-tracker
Easily start a tracker server:
$ web-bt-trackerws server listening on 8000
Lots of options:
$ web-bt-tracker --help web-bt-tracker - Start a bittorrent tracker server Usage: web-bt-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] --trust-proxy trust 'x-forwarded-for' header from reverse proxy --interval client announce interval [default: 600000] --http enable http server --udp enable udp server --ws enable websocket server -q, --quiet only show error output -s, --silent show no output -v, --version print the current version
license
MIT. Copyright (c) Feross Aboukhadijeh and WebTorrent, LLC.