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 18, 2024
1 parent 5976432 commit edd5bfd
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 @@ -507,15 +507,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) {
Expand Down

0 comments on commit edd5bfd

Please sign in to comment.