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) {