p2p/server: expose MaxInboundConns and MaxDialedConns

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2025-03-25 18:19:25 +01:00
parent 23cda63d5a
commit ea8d05a1c9

View file

@ -511,7 +511,7 @@ func (srv *Server) setupDiscovery() error {
func (srv *Server) setupDialScheduler() { func (srv *Server) setupDialScheduler() {
config := dialConfig{ config := dialConfig{
self: srv.localnode.ID(), self: srv.localnode.ID(),
maxDialPeers: srv.maxDialedConns(), maxDialPeers: srv.MaxDialedConns(),
maxActiveDials: srv.MaxPendingPeers, maxActiveDials: srv.MaxPendingPeers,
log: srv.Logger, log: srv.Logger,
netRestrict: srv.NetRestrict, netRestrict: srv.NetRestrict,
@ -535,11 +535,11 @@ func (srv *Server) setupConnManager() {
srv.connman = newConnManager(config, srv.Peers) srv.connman = newConnManager(config, srv.Peers)
} }
func (srv *Server) maxInboundConns() int { func (srv *Server) MaxInboundConns() int {
return srv.MaxPeers - srv.maxDialedConns() return srv.MaxPeers - srv.MaxDialedConns()
} }
func (srv *Server) maxDialedConns() (limit int) { func (srv *Server) MaxDialedConns() (limit int) {
if srv.NoDial || srv.MaxPeers == 0 { if srv.NoDial || srv.MaxPeers == 0 {
return 0 return 0
} }
@ -746,7 +746,7 @@ func (srv *Server) postHandshakeChecks(peers map[enode.ID]*Peer, inboundCount in
switch { switch {
case !c.is(trustedConn) && len(peers) >= srv.MaxPeers: case !c.is(trustedConn) && len(peers) >= srv.MaxPeers:
return DiscTooManyPeers return DiscTooManyPeers
case !c.is(trustedConn) && c.is(inboundConn) && inboundCount >= srv.maxInboundConns(): case !c.is(trustedConn) && c.is(inboundConn) && inboundCount >= srv.MaxInboundConns():
return DiscTooManyPeers return DiscTooManyPeers
case peers[c.node.ID()] != nil: case peers[c.node.ID()] != nil:
return DiscAlreadyConnected return DiscAlreadyConnected