Skip to content

Commit 806ce1d

Browse files
committed
Address @DiegoRBaquero's feedback
From comment: webtorrent#198 (comment) 95
1 parent cd4a976 commit 806ce1d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/server/swarm.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,27 @@ var randomIterate = require('random-iterate')
77
// Regard this as the default implementation of an interface that you
88
// need to support when overriding Server.createSwarm() and Server.getSwarm()
99
function Swarm (infoHash, server) {
10-
this.infoHash = infoHash
11-
this.complete = 0
12-
this.incomplete = 0
10+
var self = this
11+
self.infoHash = infoHash
12+
self.complete = 0
13+
self.incomplete = 0
1314

14-
this.peers = new LRU({
15+
self.peers = new LRU({
1516
max: server.peersCacheLength || 1000,
1617
maxAge: server.peersCacheTtl || 20 * 60 * 1000 // 20 minutes
1718
})
1819

1920
// When a peer is evicted from the LRU store, send a synthetic 'stopped' event
2021
// so the stats get updated correctly.
21-
this.peers.on('evict', function (data) {
22+
self.peers.on('evict', function (data) {
2223
var peer = data.value
23-
this.announce({
24+
var params = {
2425
type: peer.type,
2526
event: 'stopped',
2627
numwant: 0,
2728
peer_id: peer.peerId
28-
}, noop)
29+
}
30+
self._onAnnounceStopped(params, peer, peer.peerId)
2931

3032
// When a websocket peer is evicted, and it's not in any other swarms, close
3133
// the websocket to conserve server resources.
@@ -151,5 +153,3 @@ Swarm.prototype._getPeers = function (numwant, ownPeerId, isWebRTC) {
151153
}
152154
return peers
153155
}
154-
155-
function noop () {}

0 commit comments

Comments
 (0)