From bed58a749fa066ed8dd00bf16441fbed40dec908 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Mon, 21 Jun 2021 08:57:48 -0400 Subject: [PATCH] p2p: address audit issues with the peer manager (#6603) --- internal/p2p/peermanager.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/p2p/peermanager.go b/internal/p2p/peermanager.go index c30a933ff..91de3a3db 100644 --- a/internal/p2p/peermanager.go +++ b/internal/p2p/peermanager.go @@ -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 }