mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 14:03:06 +00:00
fix: add safe default values for peer-store-capacity (#1525)
This commit is contained in:
parent
5147048b9b
commit
1a425b0bf6
@ -87,8 +87,7 @@ type
|
||||
|
||||
peerStoreCapacity* {.
|
||||
desc: "Maximum stored peers in the peerstore."
|
||||
defaultValue: 100
|
||||
name: "peer-store-capacity" }: int
|
||||
name: "peer-store-capacity" }: Option[int]
|
||||
|
||||
peerPersistence* {.
|
||||
desc: "Enable peer persistence.",
|
||||
@ -494,6 +493,11 @@ proc parseCmdArg*(T: type Port, p: string): T =
|
||||
proc completeCmdArg*(T: type Port, val: string): seq[string] =
|
||||
return @[]
|
||||
|
||||
proc parseCmdArg*(T: type Option[int], p: string): T =
|
||||
try:
|
||||
some(parseInt(p))
|
||||
except:
|
||||
raise newException(ConfigurationError, "Invalid number")
|
||||
|
||||
## Configuration validation
|
||||
|
||||
|
||||
@ -288,7 +288,7 @@ proc initNode(conf: WakuNodeConf,
|
||||
dns4DomainName,
|
||||
discv5UdpPort,
|
||||
some(conf.agentString),
|
||||
some(conf.peerStoreCapacity))
|
||||
conf.peerStoreCapacity)
|
||||
except:
|
||||
return err("failed to create waku node instance: " & getCurrentExceptionMsg())
|
||||
|
||||
|
||||
@ -150,7 +150,7 @@ proc new*(T: type WakuNode,
|
||||
dns4DomainName = none(string),
|
||||
discv5UdpPort = none(Port),
|
||||
agentString = none(string), # defaults to nim-libp2p version
|
||||
peerStoreCapacity = none(int), # defaults to nim-libp2p max size
|
||||
peerStoreCapacity = none(int), # defaults to 1.25 maxConnections
|
||||
): T {.raises: [Defect, LPError, IOError, TLSStreamProtocolError].} =
|
||||
## Creates a Waku Node instance.
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ else:
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/options,
|
||||
std/[options, math],
|
||||
chronos, chronicles,
|
||||
eth/keys,
|
||||
libp2p/crypto/crypto,
|
||||
@ -76,7 +76,7 @@ proc newWakuSwitch*(
|
||||
secureKeyPath: string = "",
|
||||
secureCertPath: string = "",
|
||||
agentString = none(string), # defaults to nim-libp2p version
|
||||
peerStoreCapacity = none(int), # defaults to nim-libp2p max size
|
||||
peerStoreCapacity = none(int), # defaults to 1.25 maxConnections
|
||||
services: seq[switch.Service] = @[],
|
||||
): Switch
|
||||
{.raises: [Defect, IOError, LPError].} =
|
||||
@ -98,6 +98,9 @@ proc newWakuSwitch*(
|
||||
|
||||
if peerStoreCapacity.isSome():
|
||||
b = b.withPeerStore(peerStoreCapacity.get())
|
||||
else:
|
||||
let defaultPeerStoreCapacity = int(round(float64(maxConnections)*1.25))
|
||||
b = b.withPeerStore(defaultPeerStoreCapacity)
|
||||
if agentString.isSome():
|
||||
b = b.withAgentVersion(agentString.get())
|
||||
if privKey.isSome():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user