Skip to content

Commit

Permalink
bugfix: Handle nil DB on get peers
Browse files Browse the repository at this point in the history
  • Loading branch information
wizeguyy committed Nov 19, 2024
1 parent a10706f commit 82930b6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions p2p/node/peerManager/peerManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,24 @@ func (pm *BasicPeerManager) queryDHT(topic *pubsubManager.Topic, peerList map[p2
}

func (pm *BasicPeerManager) getBestPeers(topic string) map[p2p.PeerID]struct{} {
return pm.getPeersHelper(pm.peerDBs[topic][Best], c_minBestPeersFromDb)
if db, ok := pm.peerDBs[topic]; ok {
return pm.getPeersHelper(db[Best], c_minBestPeersFromDb)
}
return make(map[peer.ID]struct{})
}

func (pm *BasicPeerManager) getResponsivePeers(topic string) map[p2p.PeerID]struct{} {
return pm.getPeersHelper(pm.peerDBs[topic][Responsive], c_minResponsivePeersFromDb)
if db, ok := pm.peerDBs[topic]; ok {
return pm.getPeersHelper(db[Responsive], c_minBestPeersFromDb)
}
return make(map[peer.ID]struct{})
}

func (pm *BasicPeerManager) getLastResortPeers(topic string) map[p2p.PeerID]struct{} {
return pm.getPeersHelper(pm.peerDBs[topic][LastResort], c_minLastResortPeersFromDb)
if db, ok := pm.peerDBs[topic]; ok {
return pm.getPeersHelper(db[LastResort], c_minBestPeersFromDb)
}
return make(map[peer.ID]struct{})
}

func (pm *BasicPeerManager) AdjustPeerQuality(peer p2p.PeerID, topic string, adjFn func(int) int) {
Expand Down

0 comments on commit 82930b6

Please sign in to comment.