From 806ce1d18ba736fdd5cae581ca1d840f21801299 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 8 Feb 2017 13:13:20 -0800 Subject: [PATCH] Address @DiegoRBaquero's feedback From comment: https://github.com/feross/bittorrent-tracker/pull/198#discussion_r993882 95 --- lib/server/swarm.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/server/swarm.js b/lib/server/swarm.js index 6f08543..5203318 100644 --- a/lib/server/swarm.js +++ b/lib/server/swarm.js @@ -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 () {}