1- # bittorrent-tracker [ ![ travis] [ travis-image ]] [ travis-url ] [ ![ npm] [ npm-image ]] [ npm-url ] [ ![ downloads] [ downloads-image ]] [ downloads-url ] [ ![ javascript style guide] [ standard-image ]] [ standard-url ]
2-
3- [ travis-image ] : https://img.shields.io/travis/webtorrent/bittorrent-tracker/master.svg
4- [ travis-url ] : https://travis-ci.org/webtorrent/bittorrent-tracker
5- [ npm-image ] : https://img.shields.io/npm/v/bittorrent-tracker.svg
6- [ npm-url ] : https://npmjs.org/package/bittorrent-tracker
7- [ downloads-image ] : https://img.shields.io/npm/dm/bittorrent-tracker.svg
8- [ downloads-url ] : https://npmjs.org/package/bittorrent-tracker
9- [ standard-image ] : https://img.shields.io/badge/code_style-standard-brightgreen.svg
10- [ standard-url ] : https://standardjs.com
1+ # bittorrent-tracker [ ![ build] ( https://img.shields.io/travis/feross/bittorrent-tracker.svg )] ( https://travis-ci.org/feross/bittorrent-tracker ) [ ![ npm] ( https://img.shields.io/npm/v/bittorrent-tracker.svg )] ( https://npmjs.org/package/bittorrent-tracker ) [ ![ npm downloads] ( https://img.shields.io/npm/dm/bittorrent-tracker.svg )] ( https://npmjs.org/package/bittorrent-tracker ) [ ![ gittip] ( https://img.shields.io/gittip/feross.svg )] ( https://www.gittip.com/feross/ )
112
123#### Simple, robust, BitTorrent tracker (client & server) implementation
134
14- ![ tracker visualization ] ( img /img.png)
5+ ![ tracker] ( https://raw.githubusercontent.com/feross/bittorrent-tracker/master /img.png)
156
167Node.js implementation of a [ BitTorrent tracker] ( https://wiki.theory.org/BitTorrentSpecification#Tracker_HTTP.2FHTTPS_Protocol ) , client and server.
178
18- A ** BitTorrent tracker** is a web service which responds to requests from BitTorrent
9+ A ** BitTorrent tracker** is an HTTP service which responds to GET requests from BitTorrent
1910clients. The requests include metrics from clients that help the tracker keep overall
2011statistics about the torrent. The response includes a peer list that helps the client
21- participate in the torrent swarm .
12+ participate in the torrent.
2213
23- This module is used by [ WebTorrent] ( http://webtorrent.io ) .
14+ Also see [ bittorrent-dht] ( https://github.com/feross/bittorrent-dht ) . This module is used
15+ by [ WebTorrent] ( http://webtorrent.io ) .
2416
2517## features
2618
2719- Includes client & server implementations
28- - Supports all mainstream tracker types:
29- - HTTP trackers
30- - UDP trackers ([ BEP 15] ( http://www.bittorrent.org/beps/bep_0015.html ) )
31- - WebTorrent trackers ([ BEP forthcoming] ( http://webtorrent.io ) )
32- - Supports ipv4 & ipv6
33- - Supports tracker "scrape" extension
34- - Robust and well-tested
35- - Comprehensive test suite (runs entirely offline, so it's reliable)
36- - Used by popular clients: [ WebTorrent] ( http://webtorrent.io ) , [ peerflix] ( https://www.npmjs.com/package/peerflix ) , and [ playback] ( https://mafintosh.github.io/playback/ )
37- - Tracker statistics available via web interface at ` /stats ` or JSON data at ` /stats.json `
38-
39- Also see [ bittorrent-dht] ( https://www.npmjs.com/package/bittorrent-dht ) .
40-
41- ### Tracker stats
42-
43- ![ Screenshot] ( img/trackerStats.png )
20+ - Supports HTTP & UDP trackers ([ BEP 15] ( http://www.bittorrent.org/beps/bep_0015.html ) )
21+ - Supports tracker scrape
4422
4523## install
4624
@@ -56,34 +34,16 @@ To connect to a tracker, just do this:
5634
5735``` js
5836var Client = require (' bittorrent-tracker' )
37+ var parseTorrent = require (' parse-torrent' )
38+ var fs = require (' fs' )
5939
60- var requiredOpts = {
61- infoHash: new Buffer (' 012345678901234567890' ), // hex string or Buffer
62- peerId: new Buffer (' 01234567890123456789' ), // hex string or Buffer
63- announce: [], // list of tracker server urls
64- port: 6881 // torrent client port, (in browser, optional)
65- }
66-
67- var optionalOpts = {
68- getAnnounceOpts : function () {
69- // Provide a callback that will be called whenever announce() is called
70- // internally (on timer), or by the user
71- return {
72- uploaded: 0 ,
73- downloaded: 0 ,
74- left: 0 ,
75- customParam: ' blah' // custom parameters supported
76- }
77- }
78- // RTCPeerConnection config object (only used in browser)
79- rtcConfig: {},
80- // User-Agent header for http requests
81- userAgent: ' ' ,
82- // Custom webrtc impl, useful in node to specify [wrtc](https://npmjs.com/package/wrtc)
83- wrtc: {},
84- }
85-
86- var client = new Client (requiredOpts)
40+ var torrent = fs .readFileSync (__dirname + ' /torrents/bitlove-intro.torrent' )
41+ var parsedTorrent = parseTorrent (torrent) // { infoHash: 'xxx', length: xx, announce: ['xx', 'xx'] }
42+
43+ var peerId = new Buffer (' 01234567890123456789' )
44+ var port = 6881
45+
46+ var client = new Client (peerId, port, parsedTorrent)
8747
8848client .on (' error' , function (err ) {
8949 // fatal client error!
@@ -114,28 +74,17 @@ client.complete()
11474// force a tracker announce. will trigger more 'update' events and maybe more 'peer' events
11575client .update ()
11676
117- // provide parameters to the tracker
118- client .update ({
119- uploaded: 0 ,
120- downloaded: 0 ,
121- left: 0 ,
122- customParam: ' blah' // custom parameters supported
123- })
124-
12577// stop getting peers from the tracker, gracefully leave the swarm
12678client .stop ()
12779
128- // ungracefully leave the swarm (without sending final 'stop' message)
129- client .destroy ()
130-
13180// scrape
13281client .scrape ()
13382
13483client .on (' scrape' , function (data ) {
13584 console .log (' got a scrape response from tracker: ' + data .announce )
13685 console .log (' number of seeders in the swarm: ' + data .complete )
13786 console .log (' number of leechers in the swarm: ' + data .incomplete )
138- console .log (' number of total downloads of this torrent: ' + data .downloaded )
87+ console .log (' number of total downloads of this torrent: ' + data .incomplete )
13988})
14089```
14190
@@ -148,37 +97,9 @@ var Server = require('bittorrent-tracker').Server
14897
14998var server = new Server ({
15099 udp: true , // enable udp server? [default=true]
151- http: true , // enable http server? [default=true]
152- ws: true , // enable websocket server? [default=true]
153- stats: true , // enable web-based statistics? [default=true]
154- filter : function (infoHash , params , cb ) {
155- // Blacklist/whitelist function for allowing/disallowing torrents. If this option is
156- // omitted, all torrents are allowed. It is possible to interface with a database or
157- // external system before deciding to allow/deny, because this function is async.
158-
159- // It is possible to block by peer id (whitelisting torrent clients) or by secret
160- // key (private trackers). Full access to the original HTTP/UDP request parameters
161- // are available in `params`.
162-
163- // This example only allows one torrent.
164-
165- var allowed = (infoHash === ' aaa67059ed6bd08362da625b3ae77f6f4a075aaa' )
166- if (allowed) {
167- // If the callback is passed `null`, the torrent will be allowed.
168- cb (null )
169- } else {
170- // If the callback is passed an `Error` object, the torrent will be disallowed
171- // and the error's `message` property will be given as the reason.
172- cb (new Error (' disallowed torrent' ))
173- }
174- }
100+ http: true // enable http server? [default=true]
175101})
176102
177- // Internal http, udp, and websocket servers exposed as public properties.
178- server .http
179- server .udp
180- server .ws
181-
182103server .on (' error' , function (err ) {
183104 // fatal server error!
184105 console .log (err .message )
@@ -189,14 +110,12 @@ server.on('warning', function (err) {
189110 console .log (err .message )
190111})
191112
192- server .on (' listening' , function () {
193- // fired when all requested servers are listening
194- console .log (' listening on http port:' + server .http .address ().port )
195- console .log (' listening on udp port:' + server .udp .address ().port )
113+ server .on (' listening' , function (port ) {
114+ console .log (' tracker server is now listening on ' + port)
196115})
197116
198- // start tracker server listening! Use 0 to listen on a random free port.
199- server .listen (port, hostname, onlistening )
117+ // start tracker server listening!
118+ server .listen (port)
200119
201120// listen for individual tracker messages from peers:
202121
@@ -223,63 +142,6 @@ server.torrents[infoHash].peers
223142
224143The http server will handle requests for the following paths: ` /announce ` , ` /scrape ` . Requests for other paths will not be handled.
225144
226- ## multi scrape
227-
228- Scraping multiple torrent info is possible with a static ` Client.scrape ` method:
229-
230- ``` js
231- var Client = require (' bittorrent-tracker' )
232- Client .scrape ({ announce: announceUrl, infoHash: [ infoHash1, infoHash2 ]}, function (err , results ) {
233- results[infoHash1].announce
234- results[infoHash1].infoHash
235- results[infoHash1].complete
236- results[infoHash1].incomplete
237- results[infoHash1].downloaded
238-
239- // ...
240- })
241- ````
242-
243- ## command line
244-
245- Install ` bittorrent-tracker` globally:
246-
247- ` ` ` sh
248- $ npm install -g bittorrent-tracker
249- ` ` `
250-
251- Easily start a tracker server:
252-
253- ` ` ` sh
254- $ bittorrent-tracker
255- http server listening on 8000
256- udp server listening on 8000
257- ws server listening on 8000
258- ` ` `
259-
260- Lots of options:
261-
262- ` ` ` sh
263- $ bittorrent-tracker --help
264- bittorrent-tracker - Start a bittorrent tracker server
265-
266- Usage:
267- bittorrent-tracker [OPTIONS]
268-
269- If no --http, --udp, or --ws option is supplied, all tracker types will be started.
270-
271- Options:
272- -p, --port [number] change the port [default: 8000]
273- --trust-proxy trust 'x-forwarded-for' header from reverse proxy
274- --interval client announce interval (ms) [default: 600000]
275- --http enable http server
276- --udp enable udp server
277- --ws enable websocket server
278- -q, --quiet only show error output
279- -s, --silent show no output
280- -v, --version print the current version
281- ` ` `
282-
283145## license
284146
285- MIT . Copyright (c) [Feross Aboukhadijeh](https : // feross.org) and [WebTorrent, LLC](https://webtorrent.io ).
147+ MIT. Copyright (c) [ Feross Aboukhadijeh] ( http ://feross.org) .
0 commit comments