mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 12:11:36 +00:00
Address @DiegoRBaquero's feedback
From comment: https://github.com/feross/bittorrent-tracker/pull/198#discussion_r993882 95
This commit is contained in:
parent
cd4a976121
commit
806ce1d18b
@ -7,25 +7,27 @@ var randomIterate = require('random-iterate')
|
||||
// Regard this as the default implementation of an interface that you
|
||||
// need to support when overriding Server.createSwarm() and Server.getSwarm()
|
||||
function Swarm (infoHash, server) {
|
||||
this.infoHash = infoHash
|
||||
this.complete = 0
|
||||
this.incomplete = 0
|
||||
var self = this
|
||||
self.infoHash = infoHash
|
||||
self.complete = 0
|
||||
self.incomplete = 0
|
||||
|
||||
this.peers = new LRU({
|
||||
self.peers = new LRU({
|
||||
max: server.peersCacheLength || 1000,
|
||||
maxAge: server.peersCacheTtl || 20 * 60 * 1000 // 20 minutes
|
||||
})
|
||||
|
||||
// When a peer is evicted from the LRU store, send a synthetic 'stopped' event
|
||||
// so the stats get updated correctly.
|
||||
this.peers.on('evict', function (data) {
|
||||
self.peers.on('evict', function (data) {
|
||||
var peer = data.value
|
||||
this.announce({
|
||||
var params = {
|
||||
type: peer.type,
|
||||
event: 'stopped',
|
||||
numwant: 0,
|
||||
peer_id: peer.peerId
|
||||
}, noop)
|
||||
}
|
||||
self._onAnnounceStopped(params, peer, peer.peerId)
|
||||
|
||||
// When a websocket peer is evicted, and it's not in any other swarms, close
|
||||
// the websocket to conserve server resources.
|
||||
@ -151,5 +153,3 @@ Swarm.prototype._getPeers = function (numwant, ownPeerId, isWebRTC) {
|
||||
}
|
||||
return peers
|
||||
}
|
||||
|
||||
function noop () {}
|
||||
|
Loading…
Reference in New Issue
Block a user