mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2025-03-01 08:30:29 +00:00
Tunable max concurrent upgrades
This commit is contained in:
parent
78a65eebcc
commit
7ea4c354c7
@ -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:
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user