p2p: MinNumOutboundPeers. Closes #1501

This commit is contained in:
Ethan Buchman
2018-04-28 15:52:05 -04:00
parent 64569b15e5
commit 2761861b6b
2 changed files with 7 additions and 2 deletions

View File

@ -31,7 +31,7 @@ const (
// ensure we have enough peers // ensure we have enough peers
defaultEnsurePeersPeriod = 30 * time.Second defaultEnsurePeersPeriod = 30 * time.Second
defaultMinNumOutboundPeers = 10 defaultMinNumOutboundPeers = p2p.DefaultMinNumOutboundPeers
// Seed/Crawler constants // Seed/Crawler constants

View File

@ -26,6 +26,10 @@ const (
// ie. 3**10 = 16hrs // ie. 3**10 = 16hrs
reconnectBackOffAttempts = 10 reconnectBackOffAttempts = 10
reconnectBackOffBaseSeconds = 3 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 // 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() { 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) sw.Logger.Info("Ignoring inbound connection: already have enough peers", "address", inConn.RemoteAddr().String(), "numPeers", sw.peers.Size(), "max", maxPeers)
continue continue