@@ -67,6 +67,12 @@ var requiredOpts = {
6767}
6868
6969var optionalOpts = {
70+ // RTCPeerConnection config object (only used in browser)
71+ rtcConfig: {},
72+ // User-Agent header for http requests
73+ userAgent: ' ' ,
74+ // Custom webrtc impl, useful in node to specify [wrtc](https://npmjs.com/package/wrtc)
75+ wrtc: {},
7076 getAnnounceOpts : function () {
7177 // Provide a callback that will be called whenever announce() is called
7278 // internally (on timer), or by the user
@@ -77,12 +83,44 @@ var optionalOpts = {
7783 customParam: ' blah' // custom parameters supported
7884 }
7985 },
80- // RTCPeerConnection config object (only used in browser)
81- rtcConfig: {},
82- // User-Agent header for http requests
83- userAgent: ' ' ,
84- // Custom webrtc impl, useful in node to specify [wrtc](https://npmjs.com/package/wrtc)
85- wrtc: {},
86+ // Proxy config object
87+ proxyOpts: {
88+ // Socks proxy options (used to proxy requests in node)
89+ socksProxy: {
90+ // Configuration from socks module (https://github.com/JoshGlazebrook/socks)
91+ proxy: {
92+ // IP Address of Proxy (Required)
93+ ipaddress: " 1.2.3.4" ,
94+ // TCP Port of Proxy (Required)
95+ port: 1080 ,
96+ // Proxy Type [4, 5] (Required)
97+ // Note: 4 works for both 4 and 4a.
98+ // Type 4 does not support UDP association relay
99+ type: 5 ,
100+
101+ // SOCKS 4 Specific:
102+
103+ // UserId used when making a SOCKS 4/4a request. (Optional)
104+ userid: " someuserid" ,
105+
106+ // SOCKS 5 Specific:
107+
108+ // Authentication used for SOCKS 5 (when it's required) (Optional)
109+ authentication: {
110+ username: " Josh" ,
111+ password: " somepassword"
112+ }
113+ },
114+
115+ // Amount of time to wait for a connection to be established. (Optional)
116+ // - defaults to 10000ms (10 seconds)
117+ timeout: 10000
118+ },
119+ // NodeJS HTTP agents (used to proxy HTTP and Websocket requests in node)
120+ // Populated with Socks.Agent if socksProxy is provided
121+ httpAgent: {},
122+ httpsAgent: {}
123+ },
86124}
87125
88126var client = new Client (requiredOpts)
@@ -146,13 +184,14 @@ client.on('scrape', function (data) {
146184To start a BitTorrent tracker server to track swarms of peers:
147185
148186``` js
149- var Server = require (' bittorrent-tracker' ).Server
187+ const Server = require (' bittorrent-tracker' ).Server
150188
151- var server = new Server ({
189+ const server = new Server ({
152190 udp: true , // enable udp server? [default=true]
153191 http: true , // enable http server? [default=true]
154192 ws: true , // enable websocket server? [default=true]
155193 stats: true , // enable web-based statistics? [default=true]
194+ trustProxy: false , // enable trusting x-forwarded-for header for remote IP [default=false]
156195 filter : function (infoHash , params , cb ) {
157196 // Blacklist/whitelist function for allowing/disallowing torrents. If this option is
158197 // omitted, all torrents are allowed. It is possible to interface with a database or
@@ -164,7 +203,7 @@ var server = new Server({
164203
165204 // This example only allows one torrent.
166205
167- var allowed = (infoHash === ' aaa67059ed6bd08362da625b3ae77f6f4a075aaa' )
206+ const allowed = (infoHash === ' aaa67059ed6bd08362da625b3ae77f6f4a075aaa' )
168207 if (allowed) {
169208 // If the callback is passed `null`, the torrent will be allowed.
170209 cb (null )
@@ -193,12 +232,34 @@ server.on('warning', function (err) {
193232
194233server .on (' listening' , function () {
195234 // fired when all requested servers are listening
196- console .log (' listening on http port:' + server .http .address ().port )
197- console .log (' listening on udp port:' + server .udp .address ().port )
235+
236+ // HTTP
237+ const httpAddr = server .http .address ()
238+ const httpHost = httpAddr .address !== ' ::' ? httpAddr .address : ' localhost'
239+ const httpPort = httpAddr .port
240+ console .log (` HTTP tracker: http://${ httpHost} :${ httpPort} /announce` )
241+
242+ // UDP
243+ const udpAddr = server .udp .address ()
244+ const udpHost = udpAddr .address
245+ const udpPort = udpAddr .port
246+ console .log (` UDP tracker: udp://${ udpHost} :${ udpPort} ` )
247+
248+ // WS
249+ const wsAddr = server .http .address ()
250+ const wsHost = wsAddr .address !== ' ::' ? wsAddr .address : ' localhost'
251+ const wsPort = wsAddr .port
252+ console .log (` WebSocket tracker: ws://${ wsHost} :${ wsPort} ` )
253+
198254})
199255
256+
200257// start tracker server listening! Use 0 to listen on a random free port.
201- server .listen (port, hostname, onlistening)
258+ const port = 0
259+ const hostname = " localhost"
260+ server .listen (port, hostname, () => {
261+ // Do something on listening...
262+ })
202263
203264// listen for individual tracker messages from peers:
204265
0 commit comments