comments mostly

This commit is contained in:
tycho garen
2022-06-15 10:36:04 -04:00
parent 95bc03927c
commit 053ecd9b8c
+8 -4
View File
@@ -110,7 +110,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
@@ -567,8 +569,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(ctx context.Context, address NodeAddress) error {
m.mtx.Lock()
defer m.mtx.Unlock()
@@ -592,11 +592,12 @@ func (m *PeerManager) DialFailed(ctx context.Context, 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)
@@ -881,6 +882,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()