mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-02-07 13:59:07 +00:00
server: more thorough socket cleanup
This commit is contained in:
parent
5ee3f22e2b
commit
0740f92d7c
44
server.js
44
server.js
@ -301,9 +301,15 @@ Server.prototype.onWebSocketConnection = function (socket, opts) {
|
|||||||
socket.peerId = null // as hex
|
socket.peerId = null // as hex
|
||||||
socket.infoHashes = [] // swarms that this socket is participating in
|
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('error', self._onWebSocketError.bind(self, socket))
|
socket.onMessageBound = self._onWebSocketRequest.bind(self, socket, opts)
|
||||||
socket.on('close', self._onWebSocketClose.bind(self, socket))
|
socket.on('message', self.onMessageBound)
|
||||||
|
|
||||||
|
socket.onErrorBound = self._onWebSocketError.bind(self, socket)
|
||||||
|
socket.on('error', self.onErrorBound)
|
||||||
|
|
||||||
|
socket.onCloseBound = self._onWebSocketClose.bind(self, socket)
|
||||||
|
socket.on('close', self.onCloseBound)
|
||||||
}
|
}
|
||||||
|
|
||||||
Server.prototype._onWebSocketRequest = function (socket, opts, params) {
|
Server.prototype._onWebSocketRequest = function (socket, opts, params) {
|
||||||
@ -598,19 +604,27 @@ Server.prototype._onWebSocketSend = function (socket, err) {
|
|||||||
|
|
||||||
Server.prototype._onWebSocketClose = function (socket) {
|
Server.prototype._onWebSocketClose = function (socket) {
|
||||||
var self = this
|
var self = this
|
||||||
if (!socket.peerId || !socket.infoHashes) return
|
debug('websocket close %s', socket.peerId)
|
||||||
debug('websocket close')
|
|
||||||
|
|
||||||
socket.infoHashes.forEach(function (infoHash) {
|
if (socket.peerId) {
|
||||||
var swarm = self.torrents[infoHash]
|
socket.infoHashes.forEach(function (infoHash) {
|
||||||
if (swarm) {
|
var swarm = self.torrents[infoHash]
|
||||||
swarm.announce({
|
if (swarm) {
|
||||||
event: 'stopped',
|
swarm.announce({
|
||||||
numwant: 0,
|
event: 'stopped',
|
||||||
peer_id: socket.peerId
|
numwant: 0,
|
||||||
}, function () {})
|
peer_id: socket.peerId
|
||||||
}
|
}, function () {})
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.peerId = null
|
||||||
|
socket.infoHashes = null
|
||||||
|
socket.onSend = null
|
||||||
|
socket.removeListener('message', socket.onMessageBound)
|
||||||
|
socket.removeListener('error', socket.onErrorBound)
|
||||||
|
socket.removeListener('close', socket.onCloseBound)
|
||||||
}
|
}
|
||||||
|
|
||||||
Server.prototype._onWebSocketError = function (socket, err) {
|
Server.prototype._onWebSocketError = function (socket, err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user