p2p: wake dialing thread after sleep (#8803)

This commit is contained in:
Sam Kleinman
2022-06-20 15:47:56 +00:00
committed by GitHub
parent acf97128f3
commit 28d3239958
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,