From a8ad0ca1fd31658a28ceea36ba76b1ed860cef8f Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 3 Aug 2014 02:28:54 -0700 Subject: [PATCH] handle numWant === 0 --- server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index ed7229a..9e870dd 100644 --- a/server.js +++ b/server.js @@ -468,6 +468,7 @@ Server.prototype._onUdpRequest = function (msg, rinfo) { Server.prototype._getPeers = function (swarm, numWant) { var peers = [] for (var peerId in swarm.peers) { + if (peers.length >= numWant) break var peer = swarm.peers[peerId] if (!peer) continue // ignore null values peers.push({ @@ -475,7 +476,6 @@ Server.prototype._getPeers = function (swarm, numWant) { ip: peer.ip, port: peer.port }) - if (peers.length === numWant) break } return peers } @@ -484,10 +484,10 @@ Server.prototype._getPeersCompact = function (swarm, numWant) { var peers = [] for (var peerId in swarm.peers) { + if (peers.length >= numWant) break var peer = swarm.peers[peerId] if (!peer) continue // ignore null values peers.push(peer.ip + ':' + peer.port) - if (peers.length === numWant) break } return string2compact(peers)