This commit is contained in:
Csaba Kiraly 2026-05-21 22:00:02 -07:00 committed by GitHub
commit 13623bcb6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 0 deletions

View file

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

View file

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

View file

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

View file

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

View file

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