From b94b52511da4e768248789aa2078cba46dd7f7fa Mon Sep 17 00:00:00 2001 From: drk Date: Mon, 29 Apr 2024 16:42:51 -0500 Subject: [PATCH] bugfix: prevent peercount from being negative --- p2p/peerManager/peerManager.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/p2p/peerManager/peerManager.go b/p2p/peerManager/peerManager.go index 5b09f6a268..2cf90793e9 100644 --- a/p2p/peerManager/peerManager.go +++ b/p2p/peerManager/peerManager.go @@ -342,13 +342,14 @@ func (pm *BasicPeerManager) GetPeers(location common.Location, data interface{}, panic("Invalid peer quality") } - if len(peerList) == C_peerCount { + lenPeer := len(peerList) + if lenPeer >= C_peerCount { // Found sufficient number of peers return peerList } // Query the DHT for more peers - return pm.queryDHT(location, data, peerList, C_peerCount-len(peerList)) + return pm.queryDHT(location, data, peerList, C_peerCount-lenPeer) } func (pm *BasicPeerManager) queryDHT(location common.Location, data interface{}, peerList []p2p.PeerID, peerCount int) []p2p.PeerID {