mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 20:21:36 +00:00
Fixes for PR #134
This commit is contained in:
parent
20b7a66f54
commit
5ee3f22e2b
17
server.js
17
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
|
||||
|
Loading…
Reference in New Issue
Block a user