more parameters

This commit is contained in:
fryorcraken 2025-04-08 15:49:12 +10:00
parent 1f990e7b0d
commit 942fff1236
3 changed files with 53 additions and 5 deletions

View File

@ -60,7 +60,6 @@ proc initNode(
conf: WakuConf,
netConfig: NetConfig,
rng: ref HmacDrbgContext,
nodeKey: crypto.PrivateKey,
record: enr.Record,
peerStore: Option[WakuPeerStorage],
relay: Relay,
@ -97,7 +96,7 @@ proc initNode(
# Build waku node instance
var builder = WakuNodeBuilder.init()
builder.withRng(rng)
builder.withNodeKey(nodeKey)
builder.withNodeKey(conf.nodeKey)
builder.withRecord(record)
builder.withNetworkConfiguration(netConfig)
builder.withPeerStorage(pStorage, capacity = conf.peerStoreCapacity)
@ -156,7 +155,7 @@ proc getAutoshards*(
return ok(autoshards)
proc setupProtocols(
node: WakuNode, conf: WakuNodeConf, nodeKey: crypto.PrivateKey
node: WakuNode, conf: WakuConf, nodeKey: crypto.PrivateKey
): Future[Result[void, string]] {.async.} =
## Setup configured protocols on an existing Waku v2 node.
## Optionally include persistent message storage.
@ -483,7 +482,9 @@ proc startNode*(
return ok()
proc setupNode*(wakuConf: WakuConf, relay: Relay): Result[WakuNode, string] =
proc setupNode*(
wakuConf: WakuConf, rng: ref HmacDrbgContext = crypto.newRng(), relay: Relay
): Result[WakuNode, string] =
let netConfig = networkConfiguration(wakuConf, clientId).valueOr:
error "failed to create internal config", error = error
return err("failed to create internal config: " & error)
@ -514,7 +515,7 @@ proc setupNode*(wakuConf: WakuConf, relay: Relay): Result[WakuNode, string] =
debug "Mounting protocols"
try:
(waitFor node.setupProtocols(conf, key)).isOkOr:
(waitFor node.setupProtocols(wakuConf, key)).isOkOr:
error "Mounting protocols failed", error = error
return err("Mounting protocols failed: " & error)
except CatchableError:

View File

@ -87,6 +87,17 @@ type WakuConf* = ref object
# TODO: should clearly be a uint
maxConnections*: int
agentString*: string
colocationLimit*: int
rateLimits*: seq[string]
# TODO: those could be in a relay conf object
maxRelayPeers*: Option[int]
relayShardedPeerManagement*: bool
relayServiceRatio*: string
proc log*(conf: WakuConf) =
info "Configuration: Enabled protocols",
relay = conf.relay,

View File

@ -268,6 +268,15 @@ type WakuConfBuilder* = ref object
peerStoreCapacity: Option[int]
maxConnections: Option[int]
agentString: Option[string]
rateLimits: Option[seq[string]]
maxRelayPeers: Option[int]
relayShardedPeerManagement: Option[bool]
relayServiceRatio: Option[string]
proc init*(T: type WakuConfBuilder): WakuConfBuilder =
WakuConfBuilder(
rlnRelayConf: RlnRelayConfBuilder.init(),
@ -290,6 +299,11 @@ with(WakuConfbuilder, shards, seq[uint16])
with(WakuConfbuilder, dnsAddrsNameServers, seq[IpAddress])
with(WakuConfbuilder, p2pTcpPort, uint16, Port)
with(WakuConfbuilder, dns4DomainName, string, DomainName)
with(WakuConfbuilder, agentString, string)
with(WakuConfBuilder, colocationLimit, int)
with(WakuConfBuilder, rateLimits, seq[string])
with(WakuConfBuilder, maxRelayPeers, int)
with(WakuConfBuilder, relayServiceRatio, string)
proc withExtMultiAddr*(builder: var WakuConfBuilder, extMultiAddr: string) =
builder.extMultiAddrs.add(extMultiAddr)
@ -572,6 +586,23 @@ proc build*(
else:
return err "Max Connections was not specified"
let relayServiceRatio =
if builder.relayServiceRatio.isSome:
builder.relayServiceRatio.get()
else:
return err "Relay Service Ratio was not specified"
# TODO: Do the git version thing here
let agentString = builder.agentString.get("nwaku")
# TODO: use `DefaultColocationLimit`. the user of this value should
# probably be defining a config object
let colocationLimit = builder.colocationLimit.get(5)
let rateLimits = builder.rateLimits.get(newSeq[string](0))
# TODO: is there a strategy for experimental features? delete vs promote
let relayShardedPeerManagement = builder.relayShardedPeerManagement.get(false)
return ok(
WakuConf(
nodeKey: nodeKey,
@ -602,5 +633,10 @@ proc build*(
peerPersistence: peerPersistence,
peerStoreCapacity: builder.peerStoreCapacity,
maxConnections: maxConnections,
agentString: agentString,
colocationLimit: colocationLimit,
maxRelayPeers: builder.maxRelayPeers,
relayServiceRatio: relayServiceRatio
rateLimits: rateLimits
)
)