From bdc7edea70b4c00a20e4b16baa1430b0e1648d2a Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 19 Feb 2015 12:56:09 -0800 Subject: [PATCH] preserve backwards compatibility --- README.md | 9 +++++---- server.js | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cded742..1fd8a7a 100644 --- a/README.md +++ b/README.md @@ -111,13 +111,14 @@ var Server = require('bittorrent-tracker').Server var server = new Server({ udp: true, // enable udp server? [default=true] http: true, // enable http server? [default=true] - filter: function (params) { + filter: function (infoHash, params) { // black/whitelist for disallowing/allowing torrents [default=allow all] // this example only allows this one torrent - return params.info_hash === 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa' - + return infoHash === 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa' + // you can also block by peer id (whitelisting torrent clients) or by - // secret key, as you get full access to the original http request + // secret key, as you get full access to the original http GET + // request parameters in `params` }) }) diff --git a/server.js b/server.js index 186024f..d50dc06 100644 --- a/server.js +++ b/server.js @@ -111,8 +111,9 @@ Server.prototype.close = function (cb) { Server.prototype.getSwarm = function (infoHash, params) { var self = this - if (Buffer.isBuffer(infoHash)) infoHash = params.info_hash = infoHash.toString('hex') - if (self._filter && !self._filter(params)) return null + if (!params) params = {} + if (Buffer.isBuffer(infoHash)) infoHash = infoHash.toString('hex') + if (self._filter && !self._filter(infoHash, params)) return null var swarm = self.torrents[infoHash] if (!swarm) swarm = self.torrents[infoHash] = new Swarm(infoHash, this) return swarm