diff --git a/waku/factory/external_config.nim b/waku/factory/external_config.nim index b78567095a..b7b790c58d 100644 --- a/waku/factory/external_config.nim +++ b/waku/factory/external_config.nim @@ -193,12 +193,6 @@ type WakuNodeConf* = object name: "ext-multiaddr-only" .}: bool - maxConnections* {. - desc: "Maximum allowed number of libp2p connections.", - defaultValue: 50, - name: "max-connections" - .}: uint16 - colocationLimit* {. desc: "Max num allowed peers from the same IP. Set it to 0 to remove the limitation.", @@ -207,12 +201,16 @@ type WakuNodeConf* = object .}: int maxRelayPeers* {. - desc: "Maximum allowed number of relay peers.", name: "max-relay-peers" - .}: Option[int] + desc: "Maximum allowed number of relay peers.", + name: "max-relay-peers" + defaultValue: 50 + .}: uint64 maxServicePeers* {. - desc: "Maximum allowed number of service peers.", name: "max-service-peers" - .}: Option[int] + desc: "Maximum allowed number of service peers.", + name: "max-service-peers" + defaultValue: 50 + .}: uint64 peerStoreCapacity* {. desc: "Maximum stored peers in the peerstore.", name: "peer-store-capacity" diff --git a/waku/node/peer_manager/peer_manager.nim b/waku/node/peer_manager/peer_manager.nim index b9d549d89b..ec9ec56895 100644 --- a/waku/node/peer_manager/peer_manager.nim +++ b/waku/node/peer_manager/peer_manager.nim @@ -973,7 +973,7 @@ proc new*( shardedPeerManagement = false, ): PeerManager {.gcsafe.} = let capacity = switch.peerStore.capacity - let maxConnections = switch.connManager.inSema.size + let maxConnections = maxRelayPeers.get() + maxServicePeers.get() if maxConnections > capacity: error "Max number of connections can't be greater than PeerManager capacity", capacity = capacity, maxConnections = maxConnections @@ -981,42 +981,6 @@ proc new*( Defect, "Max number of connections can't be greater than PeerManager capacity" ) - var maxRelayPeersValue = 0 - if maxRelayPeers.isSome(): - if maxRelayPeers.get() > maxConnections: - error "Max number of relay peers can't be greater than the max amount of connections", - maxConnections = maxConnections, maxRelayPeers = maxRelayPeers.get() - raise newException( - Defect, - "Max number of relay peers can't be greater than the max amount of connections", - ) - - if maxRelayPeers.get() == maxConnections: - warn "Max number of relay peers is equal to max amount of connections, peer won't be contributing to service peers", - maxConnections = maxConnections, maxRelayPeers = maxRelayPeers.get() - maxRelayPeersValue = maxRelayPeers.get() - else: - # Leave by default 20% of connections for service peers - maxRelayPeersValue = maxConnections - (maxConnections div 5) - - var maxServicePeersValue = 0 - var d_low = 4 - - if maxServicePeers.isSome(): - if maxServicePeers.get() > maxConnections - d_low: - error "Max number of service peers can't be greater than the max amount of connections minus d_low", - maxConnections = maxConnections, maxServicePeers = maxServicePeers.get() - raise newException( - Defect, - "Max number of service peers can't be greater than the max amount of connections minus d_low", - ) - maxServicePeersValue = - min(maxServicePeers.get(), maxConnections - maxRelayPeersValue) - # relay has higher priority then service peers - else: - maxServicePeersValue = - max(maxConnections - maxRelayPeersValue, maxConnections div 5) - # attempt to calculate max backoff to prevent potential overflows or unreasonably high values let backoff = calculateBackoff(initialBackoffInSec, backoffFactor, maxFailedAttempts) if backoff.weeks() > 1: