bittorrent-tracker
Simple, robust, ZeroNet-style BitTorrent tracker (client & server) implementation
Adding support for trackers on the ZeroNet Protocol and onion addresses
Node.js implementation of a BitTorrent tracker, client and server.
A BitTorrent tracker is a web service which responds to requests from BitTorrent clients. The requests include metrics from clients that help the tracker keep overall statistics about the torrent. The response includes a peer list that helps the client participate in the torrent swarm.
This module is used by WebTorrent.
features
- Includes client & server implementations
- Supports all mainstream tracker types:
- HTTP trackers
- UDP trackers (BEP 15)
- WebTorrent trackers (BEP forthcoming)
- Supports ipv4 & ipv6
- Supports tracker "scrape" extension
- Robust and well-tested
- Comprehensive test suite (runs entirely offline, so it's reliable)
- Used by popular clients: WebTorrent, peerflix, and playback
- Tracker statistics available via web interface at
/stats
or JSON data at/stats.json
Also see bittorrent-dht.
install
npm install bittorrent-tracker
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: '' // Custom webrtc impl, useful in node to specify [wrtc](https://npmjs.com/package/wrtc) wrtc: {} 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 = 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] { // 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.serverhttpserverudpserverws 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 bittorrent-tracker
globally:
$ npm install -g bittorrent-tracker
Easily start a tracker server:
$ bittorrent-trackerhttp server listening on 8000udp server listening on 8000ws server listening on 8000
Lots of options:
$ bittorrent-tracker --help 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] --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.