From 0804e6fb9fcef87cf131a340983d809e38131b03 Mon Sep 17 00:00:00 2001 From: tycho garen Date: Wed, 15 Jun 2022 10:36:04 -0400 Subject: [PATCH] comments mostly (cherry picked from commit 053ecd9b8c6099e55887bafdb4b4c3f064c8e16a) --- internal/p2p/peermanager.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/p2p/peermanager.go b/internal/p2p/peermanager.go index ffe5f9970..12a7e6ee5 100644 --- a/internal/p2p/peermanager.go +++ b/internal/p2p/peermanager.go @@ -128,7 +128,9 @@ type PeerManagerOptions struct { // MaxOutgoingConnections specifies how many outgoing // connections. It must be lower than MaxConnected. If it is - // 0, then all connections can be outgoing. + // 0, then all connections can be outgoing. Once this limit is + // reached, the node will not dial peers, allowing the + // remaining peer connections to be used by incoming connections. MaxOutgoingConnections uint16 // MaxConnectedUpgrade is the maximum number of additional connections to @@ -590,8 +592,6 @@ func (m *PeerManager) TryDialNext() (NodeAddress, error) { // DialFailed reports a failed dial attempt. This will make the peer available // for dialing again when appropriate (possibly after a retry timeout). -// -// FIXME: This should probably delete or mark bad addresses/peers after some time. func (m *PeerManager) DialFailed(address NodeAddress) error { m.mtx.Lock() defer m.mtx.Unlock() @@ -615,11 +615,12 @@ func (m *PeerManager) DialFailed(address NodeAddress) error { addressInfo.LastDialFailure = time.Now().UTC() addressInfo.DialFailures++ + // If a dial fails more than MaxFailedDialAttempts we should + // mark it inactive and not attempt to dial it again. var totalDialFailures uint32 for _, addr := range peer.AddressInfo { totalDialFailures += addr.DialFailures } - if m.options.MaxFailedDialAttempts > 0 && totalDialFailures > m.options.MaxFailedDialAttempts { peer.Inactive = true m.metrics.PeersInactivated.Add(1) @@ -904,6 +905,9 @@ func (m *PeerManager) Errored(peerID types.NodeID, err error) { m.evictWaker.Wake() } +// Inactivate marks a peer as inactive which means we won't attempt to +// dial this peer again. A peer can be reactivated by successfully +// dialing and connecting to the node. func (m *PeerManager) Inactivate(peerID types.NodeID) error { m.mtx.Lock() defer m.mtx.Unlock()