logos-delivery/waku/factory/conf_builder/rate_limit_conf_builder.nim
NagyZoltanPeter 1f9c4cb8cc
Chore: adapt cli args for delivery api (#3744)
* LogosDeliveryAPI: NodeConfig -> WakluNodeConf + mode selector and logos.dev preset

* Adjustment made on test, logos.dev preset

* change default agentString from nwaku to logos-delivery

* Add p2pReliability switch to presets and make it default to true.

* Borrow entryNode idea from NodeConfig to WakuNodeConf to easy shortcut among diffrent bootstrap node list all needs different formats

* Fix rateLimit assignment for builder

* Remove Core mode default as we already have a defaul, user must override

* Removed obsolate API createNode with NodeConfig - tests are refactored for WakuNodeConf usage

* Fix failing test due to twn-clusterid(1) default has overwrite for maxMessagSize. Fix readme.
2026-03-03 19:17:54 +01:00

36 lines
1.1 KiB
Nim

import chronicles, std/[net, options], results
import waku/common/rate_limit/setting
logScope:
topics = "waku conf builder rate limit"
type RateLimitConfBuilder* = object
strValue: Option[seq[string]]
objValue: Option[ProtocolRateLimitSettings]
proc init*(T: type RateLimitConfBuilder): RateLimitConfBuilder =
RateLimitConfBuilder()
proc withRateLimits*(b: var RateLimitConfBuilder, rateLimits: seq[string]) =
b.strValue = some(rateLimits)
proc withRateLimitsIfNotAssigned*(
b: var RateLimitConfBuilder, rateLimits: seq[string]
) =
if b.strValue.isNone() or b.strValue.get().len == 0:
b.strValue = some(rateLimits)
proc build*(b: RateLimitConfBuilder): Result[ProtocolRateLimitSettings, string] =
if b.strValue.isSome() and b.objValue.isSome():
return err("Rate limits conf must only be set once on the builder")
if b.objValue.isSome():
return ok(b.objValue.get())
if b.strValue.isSome():
let rateLimits = ProtocolRateLimitSettings.parse(b.strValue.get()).valueOr:
return err("Invalid rate limits settings:" & $error)
return ok(rateLimits)
return ok(DefaultProtocolRateLimit)