From ca8fb996d7893ac3ff20161b756925ca6b685b59 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 0ef662026..39b86e26e 100644 --- a/p2p/node/peerManager/peerManager.go +++ b/p2p/node/peerManager/peerManager.go @@ -510,15 +510,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 nil } 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 nil } 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 nil } func (pm *BasicPeerManager) AdjustPeerQuality(peer p2p.PeerID, topic string, adjFn func(int) int) {