From d94c143b5de76f447eb0d5704c3ec992abf632e2 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 27 Aug 2016 10:23:49 -0700 Subject: [PATCH] pool: minor fixes. --- lib/net/pool.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/net/pool.js b/lib/net/pool.js index 98f1389a..6834312d 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -1045,7 +1045,7 @@ Pool.prototype.createPeer = function createPeer(addr, socket) { self.stopInterval(); self.stopTimeout(); - if (self.peers.regular.length === 0) { + if (self.peers.size() === 0) { self.logger.warning('%s %s %s', 'Could not connect to any peers.', 'Do you have a network connection?', @@ -1969,15 +1969,25 @@ PeerList.prototype.remove = function remove(peer) { }; PeerList.prototype.repurpose = function repurpose(peer) { + var r1, r2; + assert(peer.outbound); assert(!this.load); - utils.binaryRemove(this.pending, peer, compare); - utils.binaryRemove(this.regular, peer, compare); + + r1 = utils.binaryRemove(this.pending, peer, compare); + r2 = utils.binaryRemove(this.regular, peer, compare); + + assert(r1 || r2); + this.load = peer; }; PeerList.prototype.isFull = function isFull() { - return this.regular.length + this.pending.length >= this.pool.maxPeers - 1; + return this.size() >= this.pool.maxPeers - 1; +}; + +PeerList.prototype.size = function size() { + return this.regular.length + this.pending.length; }; PeerList.prototype.addLeech = function addLeech(peer) {