p2p: address audit issues with the peer manager (#6603)

This commit is contained in:
Sam Kleinman
2021-06-21 08:57:48 -04:00
committed by GitHub
parent 5f553bb3ee
commit bed58a749f

View File

@@ -434,11 +434,13 @@ func (m *PeerManager) Add(address NodeAddress) (bool, error) {
// PeerRatio returns the ratio of peer addresses stored to the maximum size.
func (m *PeerManager) PeerRatio() float64 {
m.mtx.Lock()
defer m.mtx.Unlock()
if m.options.MaxPeers == 0 {
return 0
}
m.mtx.Lock()
defer m.mtx.Unlock()
return float64(m.store.Size()) / float64(m.options.MaxPeers)
}
@@ -551,9 +553,10 @@ func (m *PeerManager) DialFailed(address NodeAddress) error {
case <-m.closeCh:
}
}()
} else {
m.dialWaker.Wake()
}
m.dialWaker.Wake()
return nil
}