Tunable max concurrent upgrades

This commit is contained in:
Tanguy 2022-07-19 16:39:17 +02:00
parent 78a65eebcc
commit 7ea4c354c7
No known key found for this signature in database
GPG Key ID: 7DD8EC6B6CE6C45E
2 changed files with 13 additions and 2 deletions

View File

@ -50,6 +50,7 @@ type
transports: seq[TransportProvider]
rng: ref HmacDrbgContext
maxConnections: int
maxConcurrentUpgrades: int
maxIn: int
sendSignedPeerRecord: bool
maxOut: int
@ -73,6 +74,7 @@ proc new*(T: type[SwitchBuilder]): T {.public.} =
addresses: @[address],
secureManagers: @[],
maxConnections: MaxConnections,
maxConcurrentUpgrades: ConcurrentUpgrades,
maxIn: -1,
maxOut: -1,
maxConnsPerPeer: MaxConnectionsPerPeer,
@ -155,6 +157,11 @@ proc withMaxConnections*(b: SwitchBuilder, maxConnections: int): SwitchBuilder {
b.maxConnections = maxConnections
b
proc withMaxConcurrentUpgrades*(b: SwitchBuilder, maxConcurrentUpgrades: int): SwitchBuilder {.public.} =
## Maximum concurrent upgrades on the switch. Default to 4
b.maxConcurrentUpgrades = maxConcurrentUpgrades
b
proc withMaxIn*(b: SwitchBuilder, maxIn: int): SwitchBuilder {.public.} =
## Maximum concurrent incoming connections. Should be used with `withMaxOut<#withMaxOut,SwitchBuilder,int>`_
b.maxIn = maxIn
@ -253,6 +260,7 @@ proc build*(b: SwitchBuilder): Switch
connManager = connManager,
ms = ms,
nameResolver = b.nameResolver,
concurrentUpgrades = b.maxConcurrentUpgrades,
peerStore = peerStore)
if b.isCircuitRelay:

View File

@ -71,6 +71,7 @@ type
peerStore*: PeerStore
nameResolver*: NameResolver
started: bool
concurrentUpgrades: int
proc addConnEventHandler*(s: Switch,
handler: ConnEventHandler,
@ -327,7 +328,8 @@ proc newSwitch*(peerInfo: PeerInfo,
connManager: ConnManager,
ms: MultistreamSelect,
nameResolver: NameResolver = nil,
peerStore = PeerStore.new()): Switch
peerStore = PeerStore.new(),
concurrentUpgrades = ConcurrentUpgrades): Switch
{.raises: [Defect, LPError], public.} =
if secureManagers.len == 0:
raise newException(LPError, "Provide at least one secure manager")
@ -339,7 +341,8 @@ proc newSwitch*(peerInfo: PeerInfo,
connManager: connManager,
peerStore: peerStore,
dialer: Dialer.new(peerInfo.peerId, connManager, transports, ms, nameResolver),
nameResolver: nameResolver)
nameResolver: nameResolver,
concurrentUpgrades: ConcurrentUpgrades)
switch.connManager.peerStore = peerStore
switch.mount(identity)