From 82e490f998cf82388bdd4ddd18a4e516fff13e7b Mon Sep 17 00:00:00 2001 From: wizeguyy Date: Mon, 11 Nov 2024 11:58:51 -0600 Subject: [PATCH] bugfix: Handle nil DB on get peers --- p2p/node/peerManager/peerManager.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/p2p/node/peerManager/peerManager.go b/p2p/node/peerManager/peerManager.go index 69be991be..5b6f72ca5 100644 --- a/p2p/node/peerManager/peerManager.go +++ b/p2p/node/peerManager/peerManager.go @@ -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) {