diff --git a/eth/backend.go b/eth/backend.go index af8b04bda6..8df563ca5c 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -465,6 +465,12 @@ func (s *Ethereum) Start() error { return nil } +func (s *Ethereum) setMaxPeers(max int) { + s.p2pServer.SetMaxPeers(max) + s.handler.SetMaxPeers(max) + s.dropper.SetMaxPeers(s.p2pServer.MaxDialedConns(), s.p2pServer.MaxInboundConns()) +} + func (s *Ethereum) newChainView(head *types.Header) *filtermaps.ChainView { if head == nil { return nil diff --git a/eth/dropper.go b/eth/dropper.go index dada5d07c0..05f25488b4 100644 --- a/eth/dropper.go +++ b/eth/dropper.go @@ -88,6 +88,11 @@ func newDropper(maxDialPeers, maxInboundPeers int) *dropper { return cm } +func (cm *dropper) SetMaxPeers(maxDialPeers, maxInboundPeers int) { + cm.maxDialPeers = maxDialPeers + cm.maxInboundPeers = maxInboundPeers +} + // Start the dropper. func (cm *dropper) Start(srv *p2p.Server, syncingFunc getSyncingFunc) { cm.peersFunc = srv.Peers diff --git a/eth/handler.go b/eth/handler.go index 76df635fb0..d8cf75898f 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -402,6 +402,10 @@ func (h *handler) unregisterPeer(id string) { } } +func (h *handler) SetMaxPeers(maxPeers int) { + h.maxPeers = maxPeers +} + func (h *handler) Start(maxPeers int) { h.maxPeers = maxPeers diff --git a/p2p/dial.go b/p2p/dial.go index 0ffcd10497..009923aac2 100644 --- a/p2p/dial.go +++ b/p2p/dial.go @@ -195,6 +195,10 @@ func newDialScheduler(config dialConfig, it enode.Iterator, setupFunc dialSetupF return d } +func (d *dialScheduler) setMaxDialPeers(maxDialPeers int) { + d.maxDialPeers = maxDialPeers +} + // stop shuts down the dialer, canceling all current dial tasks. func (d *dialScheduler) stop() { d.cancel() diff --git a/p2p/server.go b/p2p/server.go index 6d2323f9ce..a46651db4a 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -415,6 +415,13 @@ func (srv *Server) Start() (err error) { return nil } +func (srv *Server) SetMaxPeers(max int) { + srv.lock.Lock() + defer srv.lock.Unlock() + srv.MaxPeers = max + srv.dialsched.setMaxDialPeers(srv.MaxDialedConns()) +} + func (srv *Server) setupLocalNode() error { // Create the devp2p handshake. pubkey := crypto.FromECDSAPub(&srv.PrivateKey.PublicKey)