diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index bb770e7a8..357926495 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -31,7 +31,7 @@ const ( // ensure we have enough peers defaultEnsurePeersPeriod = 30 * time.Second - defaultMinNumOutboundPeers = 10 + defaultMinNumOutboundPeers = p2p.DefaultMinNumOutboundPeers // Seed/Crawler constants diff --git a/p2p/switch.go b/p2p/switch.go index 7a06a69f0..1f0c01f02 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -26,6 +26,10 @@ const ( // ie. 3**10 = 16hrs reconnectBackOffAttempts = 10 reconnectBackOffBaseSeconds = 3 + + // keep at least this many outbound peers + // TODO: move to config + DefaultMinNumOutboundPeers = 10 ) //----------------------------------------------------------------------------- @@ -458,7 +462,8 @@ func (sw *Switch) listenerRoutine(l Listener) { } // ignore connection if we already have enough - maxPeers := sw.config.MaxNumPeers + // leave room for MinNumOutboundPeers + maxPeers := sw.config.MaxNumPeers - DefaultMinNumOutboundPeers if maxPeers <= sw.peers.Size() { sw.Logger.Info("Ignoring inbound connection: already have enough peers", "address", inConn.RemoteAddr().String(), "numPeers", sw.peers.Size(), "max", maxPeers) continue