Fixes for PR #134

This commit is contained in:
Feross Aboukhadijeh 2016-03-18 15:02:12 -07:00
parent 20b7a66f54
commit 5ee3f22e2b

View File

@ -299,7 +299,7 @@ Server.prototype.onWebSocketConnection = function (socket, opts) {
if (!opts) opts = {} if (!opts) opts = {}
opts.trustProxy = opts.trustProxy || self._trustProxy opts.trustProxy = opts.trustProxy || self._trustProxy
socket.peerId = null // as hex socket.peerId = null // as hex
socket.infoHashes = [] socket.infoHashes = [] // swarms that this socket is participating in
socket.onSend = self._onWebSocketSend.bind(self, socket) socket.onSend = self._onWebSocketSend.bind(self, socket)
socket.on('message', self._onWebSocketRequest.bind(self, socket, opts)) socket.on('message', self._onWebSocketRequest.bind(self, socket, opts))
socket.on('error', self._onWebSocketError.bind(self, socket)) socket.on('error', self._onWebSocketError.bind(self, socket))
@ -337,15 +337,6 @@ Server.prototype._onWebSocketRequest = function (socket, opts, params) {
} }
if (self.destroyed) return 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' response.action = params.action === common.ACTIONS.ANNOUNCE ? 'announce' : 'scrape'
var peers var peers
@ -353,6 +344,12 @@ Server.prototype._onWebSocketRequest = function (socket, opts, params) {
peers = response.peers peers = response.peers
delete 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) response.info_hash = common.hexToBinary(params.info_hash)
// WebSocket tracker should have a shorter interval default: 2 minutes // WebSocket tracker should have a shorter interval default: 2 minutes