p2p: wake dialing thread after sleep (#8803) (#8804)

(cherry picked from commit 28d3239958)

Co-authored-by: Sam Kleinman <garen@tychoish.com>
This commit is contained in:
mergify[bot]
2022-06-20 12:40:00 -04:00
committed by GitHub
co-authored by Sam Kleinman
parent 1975cdd750
commit 1b872d768b
2 changed files with 14 additions and 0 deletions
+9
View File
@@ -498,6 +498,15 @@ func (m *PeerManager) HasMaxPeerCapacity() bool {
return len(m.connected) >= int(m.options.MaxConnected)
}
func (m *PeerManager) HasDialedMaxPeers() bool {
m.mtx.Lock()
defer m.mtx.Unlock()
stats := m.getConnectedInfo()
return stats.outgoing >= m.options.MaxOutgoingConnections
}
// DialNext finds an appropriate peer address to dial, and marks it as dialing.
// If no peer is found, or all connection slots are full, it blocks until one
// becomes available. The caller must call Dialed() or DialFailed() for the
+5
View File
@@ -466,6 +466,11 @@ func (r *Router) dialSleep(ctx context.Context) {
}
r.options.DialSleep(ctx)
if !r.peerManager.HasDialedMaxPeers() {
r.peerManager.dialWaker.Wake()
}
}
// acceptPeers accepts inbound connections from peers on the given transport,