Prem Chaitanya Prathi 2033358df2
feat(mix): add cover traffic, disable-spam-protection flag, and fix option_shims crash
- Add cover traffic support with constant rate as per spec
- Add mix-user-message-limit and mix-disable-spam-protection CLI flags
- Fix option_shims.nim double-evaluation bug causing UnpackDefect crash
  in ping (template expanded await expression twice, racing two calls)
- Reduce default rate limit to 2 msgs/epoch for simulation testing
- Add check_cover_traffic.sh metrics monitoring script

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 23:09:26 +05:30

52 lines
1.8 KiB
Nim

import chronicles, std/options, results
import libp2p/crypto/crypto, libp2p/crypto/curve25519, libp2p/protocols/mix/curve25519
import ../waku_conf, waku/waku_mix
logScope:
topics = "waku conf builder mix"
##################################
## Mix Config Builder ##
##################################
type MixConfBuilder* = object
enabled: Option[bool]
mixKey: Option[string]
mixNodes: seq[MixNodePubInfo]
userMessageLimit: Option[int]
disableSpamProtection: bool
proc init*(T: type MixConfBuilder): MixConfBuilder =
MixConfBuilder()
proc withEnabled*(b: var MixConfBuilder, enabled: bool) =
b.enabled = some(enabled)
proc withMixKey*(b: var MixConfBuilder, mixKey: string) =
b.mixKey = some(mixKey)
proc withMixNodes*(b: var MixConfBuilder, mixNodes: seq[MixNodePubInfo]) =
b.mixNodes = mixNodes
proc withUserMessageLimit*(b: var MixConfBuilder, limit: int) =
b.userMessageLimit = some(limit)
proc withDisableSpamProtection*(b: var MixConfBuilder, disable: bool) =
b.disableSpamProtection = disable
proc build*(b: MixConfBuilder): Result[Option[MixConf], string] =
if not b.enabled.get(false):
return ok(none[MixConf]())
else:
if b.mixKey.isSome():
let mixPrivKey = intoCurve25519Key(ncrutils.fromHex(b.mixKey.get()))
let mixPubKey = public(mixPrivKey)
return ok(
some(MixConf(mixKey: mixPrivKey, mixPubKey: mixPubKey, mixNodes: b.mixNodes, userMessageLimit: b.userMessageLimit, disableSpamProtection: b.disableSpamProtection))
)
else:
let (mixPrivKey, mixPubKey) = generateKeyPair().valueOr:
return err("Generate key pair error: " & $error)
return ok(
some(MixConf(mixKey: mixPrivKey, mixPubKey: mixPubKey, mixNodes: b.mixNodes, userMessageLimit: b.userMessageLimit, disableSpamProtection: b.disableSpamProtection))
)