From 5ee3f22e2be2bc25ce8ca32fdd424d1d22d76f4b Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 18 Mar 2016 15:02:12 -0700 Subject: [PATCH] Fixes for PR #134 --- server.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/server.js b/server.js index 57518a3..9f132b7 100644 --- a/server.js +++ b/server.js @@ -299,7 +299,7 @@ Server.prototype.onWebSocketConnection = function (socket, opts) { if (!opts) opts = {} opts.trustProxy = opts.trustProxy || self._trustProxy socket.peerId = null // as hex - socket.infoHashes = [] + socket.infoHashes = [] // swarms that this socket is participating in socket.onSend = self._onWebSocketSend.bind(self, socket) socket.on('message', self._onWebSocketRequest.bind(self, socket, opts)) socket.on('error', self._onWebSocketError.bind(self, socket)) @@ -337,15 +337,6 @@ Server.prototype._onWebSocketRequest = function (socket, opts, params) { } if (self.destroyed) return - var hashes - if (typeof params.info_hash === 'string') hashes = [ params.info_hash ] - else hashes = params.info_hash - hashes.forEach(function (info_hash) { - if (socket.infoHashes.indexOf(info_hash) === -1) { - socket.infoHashes.push(info_hash) - } - }) - response.action = params.action === common.ACTIONS.ANNOUNCE ? 'announce' : 'scrape' var peers @@ -353,6 +344,12 @@ Server.prototype._onWebSocketRequest = function (socket, opts, params) { peers = response.peers delete response.peers + params.info_hash.forEach(function (info_hash) { + if (socket.infoHashes.indexOf(info_hash) === -1) { + socket.infoHashes.push(info_hash) + } + }) + response.info_hash = common.hexToBinary(params.info_hash) // WebSocket tracker should have a shorter interval – default: 2 minutes