Browse Source

p2p: MinNumOutboundPeers. Closes #1501

pull/1519/head
Ethan Buchman 7 years ago
parent
commit
2761861b6b
2 changed files with 7 additions and 2 deletions
  1. +1
    -1
      p2p/pex/pex_reactor.go
  2. +6
    -1
      p2p/switch.go

+ 1
- 1
p2p/pex/pex_reactor.go View File

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


+ 6
- 1
p2p/switch.go View File

@ -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


Loading…
Cancel
Save