Skip to content

Commit

Permalink
bugfix: prevent peercount from being negative
Browse files Browse the repository at this point in the history
  • Loading branch information
kiltsonfire committed Apr 29, 2024
1 parent bf604a5 commit b94b525
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions p2p/peerManager/peerManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b94b525

Please sign in to comment.