bittorrent-tracker
Simple, robust, BitTorrent tracker (client & server) implementation
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 = // RTCPeerConnection config object (only used in browser) rtcConfig: {} // custom webrtc impl, useful in node to specify [wrtc](https://npmjs.com/package/wrtc) wrtc: {} { // 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 } proxyOpts: // Socks proxy options (used to proxy requests in node) socksProxy: // Configuration from socks module (https://github.com/JoshGlazebrook/socks) proxy: // IP Address of Proxy (Required) ipaddress: "1.2.3.4" // TCP Port of Proxy (Required) port: 1080 // Proxy Type [4, 5] (Required) // Note: 4 works for both 4 and 4a. // Type 4 does not support UDP association relay type: 5 // SOCKS 4 Specific: // UserId used when making a SOCKS 4/4a request. (Optional) userid: "someuserid" // SOCKS 5 Specific: // Authentication used for SOCKS 5 (when it's required) (Optional) authentication: username: "Josh" password: "somepassword" // Amount of time to wait for a connection to be established. (Optional) // - defaults to 10000ms (10 seconds) timeout: 10000 // NodeJS HTTP agents (used to proxy HTTP and Websocket requests in node) // Populated with Socks.Agent if socksProxy is provided httpAgent: {} httpsAgent: {} 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' // 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.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
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 Please report bugs! https://github.com/feross/bittorrent-tracker/issues
license
MIT. Copyright (c) Feross Aboukhadijeh.