File tree Expand file tree Collapse file tree 3 files changed +21
-7
lines changed
Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -111,10 +111,13 @@ var Server = require('bittorrent-tracker').Server
111111var server = new Server ({
112112 udp: true , // enable udp server? [default=true]
113113 http: true , // enable http server? [default=true]
114- filter : function (infoHash ) {
114+ filter : function (params ) {
115115 // black/whitelist for disallowing/allowing torrents [default=allow all]
116116 // this example only allows this one torrent
117- return infoHash === ' aaa67059ed6bd08362da625b3ae77f6f4a075aaa'
117+ return params .info_hash === ' aaa67059ed6bd08362da625b3ae77f6f4a075aaa'
118+
119+ // you can also block by peer id (whitelisting torrent clients) or by
120+ // secret key, as you get full access to the original http request
118121 })
119122})
120123
Original file line number Diff line number Diff line change @@ -4,9 +4,20 @@ var Server = require('../..').Server
44var express = require ( 'express' )
55var app = express ( )
66
7+ // https://wiki.theory.org/BitTorrentSpecification#peer_id
8+ var whitelist = {
9+ UT : true // uTorrent
10+ }
11+
712var server = new Server ( {
813 http : false , // we do our own
9- udp : false // not interested
14+ udp : false , // not interested
15+ filter : function ( params ) {
16+ // black/whitelist for disallowing/allowing specific clients [default=allow all]
17+ // this example only allows the uTorrent client
18+ var client = params . peer_id [ 1 ] + params . peer_id [ 2 ]
19+ return whitelist [ client ]
20+ }
1021} )
1122
1223var onHttpRequest = server . onHttpRequest . bind ( server )
Original file line number Diff line number Diff line change @@ -109,10 +109,10 @@ Server.prototype.close = function (cb) {
109109 }
110110}
111111
112- Server . prototype . getSwarm = function ( infoHash ) {
112+ Server . prototype . getSwarm = function ( infoHash , params ) {
113113 var self = this
114- if ( Buffer . isBuffer ( infoHash ) ) infoHash = infoHash . toString ( 'hex' )
115- if ( self . _filter && ! self . _filter ( infoHash ) ) return null
114+ if ( Buffer . isBuffer ( infoHash ) ) infoHash = params . info_hash = infoHash . toString ( 'hex' )
115+ if ( self . _filter && ! self . _filter ( params ) ) return null
116116 var swarm = self . torrents [ infoHash ]
117117 if ( ! swarm ) swarm = self . torrents [ infoHash ] = new Swarm ( infoHash , this )
118118 return swarm
@@ -207,7 +207,7 @@ Server.prototype._onRequest = function (params, cb) {
207207
208208Server . prototype . _onAnnounce = function ( params , cb ) {
209209 var self = this
210- var swarm = self . getSwarm ( params . info_hash )
210+ var swarm = self . getSwarm ( params . info_hash , params )
211211 if ( swarm === null ) return cb ( new Error ( 'disallowed info_hash' ) )
212212 if ( ! params . event || params . event === 'empty' ) params . event = 'update'
213213 swarm . announce ( params , function ( err , response ) {
You can’t perform that action at this time.
0 commit comments