logos-delivery/waku/node/waku_switch.nim

124 lines
4.2 KiB
Nim
Raw Normal View History

# Waku Switch utils.
{.push raises: [].}
import
std/options,
chronos,
chronicles,
eth/keys,
libp2p/crypto/crypto,
feat(mix): bump libp2p stack to v2.0.0 + adopt stateless RLN spam protection Combines five dep-and-build changes that all flow from the libp2p v2.0.0 upgrade and the move to the extracted libp2p_mix / mix-rln plugin stack: waku.nimble: * libp2p: ff8d51857 -> c43199378 (release/v2.0.0 tip; sha-pinned until vacp2p cuts a v2.0.0 tag). * Drop the bare `zlib < 0.2` cap — no longer needed by the upgraded libp2p. * websock: bare ">= 0.4.0" — replaces the d4cd68b URL+SHA workaround that pinned through a libp2p commit-specific websock SHA. * nim-json-rpc: switch to chaitanyaprem/nim-json-rpc#f05fad25 — relaxes websock cap to allow >=0.4.0. TODO: revert to status-im/nim-json-rpc once status-im/nim-json-rpc#277 merges and a tag is cut. * lsquic: bare ">= 0.4.1" (drops URL form). * Add mix-rln-spam-protection-plugin pin (23b278b4) and nim-libp2p-mix pin (50c4ab4f — PR #14 HEAD); the plugin pins the same libp2p_mix SHA so the diamond dep collapses to a single source. waku/factory/waku.nim: * Explicit HPService.setup(switch) / AutonatService.setup(switch) calls. libp2p v2.0.0's Service lifecycle refactor (libp2p#2462) removed switch.start's auto-setup loop, so any caller that assigns directly to switch.services (we do) is responsible for calling setup() themselves. Without it, AutonatService.addressMapper stays nil and peerInfo.expandAddrs SIGSEGVs during start(). Wrapped in try/except for ServiceSetupError so a setup failure surfaces as a logged error rather than a crash. Build / scripts: * scripts/build_rln_mix.sh removed and Makefile simplified — librln is now a single shared archive built from zerokit's `stateless` features (no separate librln_mix archive). * simulations/mixnet/build_setup.sh + setup_credentials.nim updated to use librln_v2.0.2.a directly and run RLN keystore setup before nodes start. Validated: * Cold local-cache nimble setup --localdeps -y. * wakunode2 and chat2mix link cleanly. * Mixnet roundtrip sim: [PASS] bob received message from alice. * RLN proof generation + verification on every in-path mix node: 5 gen_called == 5 verified, 0 SPAM_PROOF_* errors.
2026-06-04 16:54:44 +05:30
libp2p/crypto/rng as libp2p_rng,
libp2p/protocols/pubsub/gossipsub,
libp2p/protocols/rendezvous,
libp2p/protocols/connectivity/relay/relay,
libp2p/nameresolving/nameresolver,
libp2p/builders,
libp2p/switch,
libp2p/transports/[transport, tcptransport, wstransport]
# override nim-libp2p default value (which is also 1)
const MaxConnectionsPerPeer* = 1
feat(mix): bump libp2p stack to v2.0.0 + adopt stateless RLN spam protection Combines five dep-and-build changes that all flow from the libp2p v2.0.0 upgrade and the move to the extracted libp2p_mix / mix-rln plugin stack: waku.nimble: * libp2p: ff8d51857 -> c43199378 (release/v2.0.0 tip; sha-pinned until vacp2p cuts a v2.0.0 tag). * Drop the bare `zlib < 0.2` cap — no longer needed by the upgraded libp2p. * websock: bare ">= 0.4.0" — replaces the d4cd68b URL+SHA workaround that pinned through a libp2p commit-specific websock SHA. * nim-json-rpc: switch to chaitanyaprem/nim-json-rpc#f05fad25 — relaxes websock cap to allow >=0.4.0. TODO: revert to status-im/nim-json-rpc once status-im/nim-json-rpc#277 merges and a tag is cut. * lsquic: bare ">= 0.4.1" (drops URL form). * Add mix-rln-spam-protection-plugin pin (23b278b4) and nim-libp2p-mix pin (50c4ab4f — PR #14 HEAD); the plugin pins the same libp2p_mix SHA so the diamond dep collapses to a single source. waku/factory/waku.nim: * Explicit HPService.setup(switch) / AutonatService.setup(switch) calls. libp2p v2.0.0's Service lifecycle refactor (libp2p#2462) removed switch.start's auto-setup loop, so any caller that assigns directly to switch.services (we do) is responsible for calling setup() themselves. Without it, AutonatService.addressMapper stays nil and peerInfo.expandAddrs SIGSEGVs during start(). Wrapped in try/except for ServiceSetupError so a setup failure surfaces as a logged error rather than a crash. Build / scripts: * scripts/build_rln_mix.sh removed and Makefile simplified — librln is now a single shared archive built from zerokit's `stateless` features (no separate librln_mix archive). * simulations/mixnet/build_setup.sh + setup_credentials.nim updated to use librln_v2.0.2.a directly and run RLN keystore setup before nodes start. Validated: * Cold local-cache nimble setup --localdeps -y. * wakunode2 and chat2mix link cleanly. * Mixnet roundtrip sim: [PASS] bob received message from alice. * RLN proof generation + verification on every in-path mix node: 5 gen_called == 5 verified, 0 SPAM_PROOF_* errors.
2026-06-04 16:54:44 +05:30
# libp2p 1.15.3 ships a built-in `withWsTransport` matching this name, so
# the plain-WS wrapper that used to live here is now redundant. Callers
# that did `b.withWsTransport()` resolve to libp2p's overload (zero args =
# no TLS, no flags). Callers passing `tlsPrivateKey=`/`tlsCertificate=`
# also use libp2p's built-in.
# nim-libp2p#2329 made libp2p's MaxConnections const private (renamed to
# DefaultMaxConnections); redeclare here to keep waku's cap explicit.
const MaxConnections* = 50
proc getSecureKey(path: string): TLSPrivateKey {.raises: [Defect, IOError].} =
trace "Key path is.", path = path
let stringkey: string = readFile(path)
Secure websocket (#759) * add config Signed-off-by: rshiv <reeshav96@gmail.com> * secure websocket integration Signed-off-by: rshiv <reeshav96@gmail.com> * secure websocket debug Signed-off-by: rshiv <reeshav96@gmail.com> * config change Signed-off-by: rshiv <reeshav96@gmail.com> * working secure websocket changes Signed-off-by: rshiv <reeshav96@gmail.com> * Update submodules (#761) * Release v0.6 (#760) * Read from path Signed-off-by: rshiv <reeshav96@gmail.com> * Tests for secure websockets Signed-off-by: rshiv <reeshav96@gmail.com> * CI failure fix Signed-off-by: rshiv <reeshav96@gmail.com> * path resolver CI Signed-off-by: rshiv <reeshav96@gmail.com> * self review fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update examples/v2/config_chat2.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update waku/v2/utils/peers.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/node/wakunode2.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update tests/v2/test_wakunode.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * handle review comments Signed-off-by: rshiv <reeshav96@gmail.com> Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com>
2021-11-10 12:05:36 +00:00
try:
let key = TLSPrivateKey.init(stringkey)
return key
except TLSStreamProtocolError as exc:
info "exception raised from getSecureKey", err = exc.msg
proc getSecureCert(path: string): TLSCertificate {.raises: [Defect, IOError].} =
trace "Certificate path is.", path = path
let stringCert: string = readFile(path)
Secure websocket (#759) * add config Signed-off-by: rshiv <reeshav96@gmail.com> * secure websocket integration Signed-off-by: rshiv <reeshav96@gmail.com> * secure websocket debug Signed-off-by: rshiv <reeshav96@gmail.com> * config change Signed-off-by: rshiv <reeshav96@gmail.com> * working secure websocket changes Signed-off-by: rshiv <reeshav96@gmail.com> * Update submodules (#761) * Release v0.6 (#760) * Read from path Signed-off-by: rshiv <reeshav96@gmail.com> * Tests for secure websockets Signed-off-by: rshiv <reeshav96@gmail.com> * CI failure fix Signed-off-by: rshiv <reeshav96@gmail.com> * path resolver CI Signed-off-by: rshiv <reeshav96@gmail.com> * self review fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update examples/v2/config_chat2.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update waku/v2/utils/peers.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/node/wakunode2.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update tests/v2/test_wakunode.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * handle review comments Signed-off-by: rshiv <reeshav96@gmail.com> Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com>
2021-11-10 12:05:36 +00:00
try:
let cert = TLSCertificate.init(stringCert)
Secure websocket (#759) * add config Signed-off-by: rshiv <reeshav96@gmail.com> * secure websocket integration Signed-off-by: rshiv <reeshav96@gmail.com> * secure websocket debug Signed-off-by: rshiv <reeshav96@gmail.com> * config change Signed-off-by: rshiv <reeshav96@gmail.com> * working secure websocket changes Signed-off-by: rshiv <reeshav96@gmail.com> * Update submodules (#761) * Release v0.6 (#760) * Read from path Signed-off-by: rshiv <reeshav96@gmail.com> * Tests for secure websockets Signed-off-by: rshiv <reeshav96@gmail.com> * CI failure fix Signed-off-by: rshiv <reeshav96@gmail.com> * path resolver CI Signed-off-by: rshiv <reeshav96@gmail.com> * self review fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update examples/v2/config_chat2.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update waku/v2/utils/peers.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/node/wakunode2.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update tests/v2/test_wakunode.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * handle review comments Signed-off-by: rshiv <reeshav96@gmail.com> Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com>
2021-11-10 12:05:36 +00:00
return cert
except TLSStreamProtocolError as exc:
info "exception raised from getSecureCert", err = exc.msg
proc withWssTransport*(
b: SwitchBuilder, secureKeyPath: string, secureCertPath: string
): SwitchBuilder {.raises: [Defect, IOError].} =
let key: TLSPrivateKey = getSecureKey(secureKeyPath)
let cert: TLSCertificate = getSecureCert(secureCertPath)
b.withWsTransport(
tlsPrivateKey = key,
tlsCertificate = cert,
{TLSFlags.NoVerifyHost, TLSFlags.NoVerifyServerName}, # THIS IS INSECURE, NO?
)
Secure websocket (#759) * add config Signed-off-by: rshiv <reeshav96@gmail.com> * secure websocket integration Signed-off-by: rshiv <reeshav96@gmail.com> * secure websocket debug Signed-off-by: rshiv <reeshav96@gmail.com> * config change Signed-off-by: rshiv <reeshav96@gmail.com> * working secure websocket changes Signed-off-by: rshiv <reeshav96@gmail.com> * Update submodules (#761) * Release v0.6 (#760) * Read from path Signed-off-by: rshiv <reeshav96@gmail.com> * Tests for secure websockets Signed-off-by: rshiv <reeshav96@gmail.com> * CI failure fix Signed-off-by: rshiv <reeshav96@gmail.com> * path resolver CI Signed-off-by: rshiv <reeshav96@gmail.com> * self review fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update examples/v2/config_chat2.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update waku/v2/utils/peers.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/node/wakunode2.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update tests/v2/test_wakunode.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * handle review comments Signed-off-by: rshiv <reeshav96@gmail.com> Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com>
2021-11-10 12:05:36 +00:00
proc newWakuSwitch*(
privKey = none(crypto.PrivateKey),
address = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
2021-12-06 20:51:37 +01:00
wsAddress = none(MultiAddress),
secureManagers: openarray[SecureProtocol] = [SecureProtocol.Noise],
transportFlags: set[ServerFlags] = {},
feat(mix): bump libp2p stack to v2.0.0 + adopt stateless RLN spam protection Combines five dep-and-build changes that all flow from the libp2p v2.0.0 upgrade and the move to the extracted libp2p_mix / mix-rln plugin stack: waku.nimble: * libp2p: ff8d51857 -> c43199378 (release/v2.0.0 tip; sha-pinned until vacp2p cuts a v2.0.0 tag). * Drop the bare `zlib < 0.2` cap — no longer needed by the upgraded libp2p. * websock: bare ">= 0.4.0" — replaces the d4cd68b URL+SHA workaround that pinned through a libp2p commit-specific websock SHA. * nim-json-rpc: switch to chaitanyaprem/nim-json-rpc#f05fad25 — relaxes websock cap to allow >=0.4.0. TODO: revert to status-im/nim-json-rpc once status-im/nim-json-rpc#277 merges and a tag is cut. * lsquic: bare ">= 0.4.1" (drops URL form). * Add mix-rln-spam-protection-plugin pin (23b278b4) and nim-libp2p-mix pin (50c4ab4f — PR #14 HEAD); the plugin pins the same libp2p_mix SHA so the diamond dep collapses to a single source. waku/factory/waku.nim: * Explicit HPService.setup(switch) / AutonatService.setup(switch) calls. libp2p v2.0.0's Service lifecycle refactor (libp2p#2462) removed switch.start's auto-setup loop, so any caller that assigns directly to switch.services (we do) is responsible for calling setup() themselves. Without it, AutonatService.addressMapper stays nil and peerInfo.expandAddrs SIGSEGVs during start(). Wrapped in try/except for ServiceSetupError so a setup failure surfaces as a logged error rather than a crash. Build / scripts: * scripts/build_rln_mix.sh removed and Makefile simplified — librln is now a single shared archive built from zerokit's `stateless` features (no separate librln_mix archive). * simulations/mixnet/build_setup.sh + setup_credentials.nim updated to use librln_v2.0.2.a directly and run RLN keystore setup before nodes start. Validated: * Cold local-cache nimble setup --localdeps -y. * wakunode2 and chat2mix link cleanly. * Mixnet roundtrip sim: [PASS] bob received message from alice. * RLN proof generation + verification on every in-path mix node: 5 gen_called == 5 verified, 0 SPAM_PROOF_* errors.
2026-06-04 16:54:44 +05:30
rng: libp2p_rng.Rng,
inTimeout: Duration = 5.minutes,
outTimeout: Duration = 5.minutes,
maxConnections = MaxConnections,
maxIn = -1,
maxOut = -1,
maxConnsPerPeer = MaxConnectionsPerPeer,
nameResolver: NameResolver = nil,
sendSignedPeerRecord = false,
Secure websocket (#759) * add config Signed-off-by: rshiv <reeshav96@gmail.com> * secure websocket integration Signed-off-by: rshiv <reeshav96@gmail.com> * secure websocket debug Signed-off-by: rshiv <reeshav96@gmail.com> * config change Signed-off-by: rshiv <reeshav96@gmail.com> * working secure websocket changes Signed-off-by: rshiv <reeshav96@gmail.com> * Update submodules (#761) * Release v0.6 (#760) * Read from path Signed-off-by: rshiv <reeshav96@gmail.com> * Tests for secure websockets Signed-off-by: rshiv <reeshav96@gmail.com> * CI failure fix Signed-off-by: rshiv <reeshav96@gmail.com> * path resolver CI Signed-off-by: rshiv <reeshav96@gmail.com> * self review fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update examples/v2/config_chat2.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update waku/v2/utils/peers.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Update waku/v2/node/wakunode2.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * Update tests/v2/test_wakunode.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * Update waku/v2/utils/wakuswitch.nim Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com> * handle review comments Signed-off-by: rshiv <reeshav96@gmail.com> Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Co-authored-by: Sanaz Taheri Boshrooyeh <35961250+staheri14@users.noreply.github.com>
2021-11-10 12:05:36 +00:00
wssEnabled: bool = false,
secureKeyPath: string = "",
secureCertPath: string = "",
agentString = none(string), # defaults to nim-libp2p version
peerStoreCapacity = none(int), # defaults to 1.25 maxConnections
feat(mix): bump libp2p stack to v2.0.0 + adopt stateless RLN spam protection Combines five dep-and-build changes that all flow from the libp2p v2.0.0 upgrade and the move to the extracted libp2p_mix / mix-rln plugin stack: waku.nimble: * libp2p: ff8d51857 -> c43199378 (release/v2.0.0 tip; sha-pinned until vacp2p cuts a v2.0.0 tag). * Drop the bare `zlib < 0.2` cap — no longer needed by the upgraded libp2p. * websock: bare ">= 0.4.0" — replaces the d4cd68b URL+SHA workaround that pinned through a libp2p commit-specific websock SHA. * nim-json-rpc: switch to chaitanyaprem/nim-json-rpc#f05fad25 — relaxes websock cap to allow >=0.4.0. TODO: revert to status-im/nim-json-rpc once status-im/nim-json-rpc#277 merges and a tag is cut. * lsquic: bare ">= 0.4.1" (drops URL form). * Add mix-rln-spam-protection-plugin pin (23b278b4) and nim-libp2p-mix pin (50c4ab4f — PR #14 HEAD); the plugin pins the same libp2p_mix SHA so the diamond dep collapses to a single source. waku/factory/waku.nim: * Explicit HPService.setup(switch) / AutonatService.setup(switch) calls. libp2p v2.0.0's Service lifecycle refactor (libp2p#2462) removed switch.start's auto-setup loop, so any caller that assigns directly to switch.services (we do) is responsible for calling setup() themselves. Without it, AutonatService.addressMapper stays nil and peerInfo.expandAddrs SIGSEGVs during start(). Wrapped in try/except for ServiceSetupError so a setup failure surfaces as a logged error rather than a crash. Build / scripts: * scripts/build_rln_mix.sh removed and Makefile simplified — librln is now a single shared archive built from zerokit's `stateless` features (no separate librln_mix archive). * simulations/mixnet/build_setup.sh + setup_credentials.nim updated to use librln_v2.0.2.a directly and run RLN keystore setup before nodes start. Validated: * Cold local-cache nimble setup --localdeps -y. * wakunode2 and chat2mix link cleanly. * Mixnet roundtrip sim: [PASS] bob received message from alice. * RLN proof generation + verification on every in-path mix node: 5 gen_called == 5 verified, 0 SPAM_PROOF_* errors.
2026-06-04 16:54:44 +05:30
rendezvous: Opt[RendezVousConfig] = Opt.none(RendezVousConfig),
circuitRelay: Relay,
): Switch {.raises: [Defect, IOError, LPError].} =
feat(mix): bump libp2p stack to v2.0.0 + adopt stateless RLN spam protection Combines five dep-and-build changes that all flow from the libp2p v2.0.0 upgrade and the move to the extracted libp2p_mix / mix-rln plugin stack: waku.nimble: * libp2p: ff8d51857 -> c43199378 (release/v2.0.0 tip; sha-pinned until vacp2p cuts a v2.0.0 tag). * Drop the bare `zlib < 0.2` cap — no longer needed by the upgraded libp2p. * websock: bare ">= 0.4.0" — replaces the d4cd68b URL+SHA workaround that pinned through a libp2p commit-specific websock SHA. * nim-json-rpc: switch to chaitanyaprem/nim-json-rpc#f05fad25 — relaxes websock cap to allow >=0.4.0. TODO: revert to status-im/nim-json-rpc once status-im/nim-json-rpc#277 merges and a tag is cut. * lsquic: bare ">= 0.4.1" (drops URL form). * Add mix-rln-spam-protection-plugin pin (23b278b4) and nim-libp2p-mix pin (50c4ab4f — PR #14 HEAD); the plugin pins the same libp2p_mix SHA so the diamond dep collapses to a single source. waku/factory/waku.nim: * Explicit HPService.setup(switch) / AutonatService.setup(switch) calls. libp2p v2.0.0's Service lifecycle refactor (libp2p#2462) removed switch.start's auto-setup loop, so any caller that assigns directly to switch.services (we do) is responsible for calling setup() themselves. Without it, AutonatService.addressMapper stays nil and peerInfo.expandAddrs SIGSEGVs during start(). Wrapped in try/except for ServiceSetupError so a setup failure surfaces as a logged error rather than a crash. Build / scripts: * scripts/build_rln_mix.sh removed and Makefile simplified — librln is now a single shared archive built from zerokit's `stateless` features (no separate librln_mix archive). * simulations/mixnet/build_setup.sh + setup_credentials.nim updated to use librln_v2.0.2.a directly and run RLN keystore setup before nodes start. Validated: * Cold local-cache nimble setup --localdeps -y. * wakunode2 and chat2mix link cleanly. * Mixnet roundtrip sim: [PASS] bob received message from alice. * RLN proof generation + verification on every in-path mix node: 5 gen_called == 5 verified, 0 SPAM_PROOF_* errors.
2026-06-04 16:54:44 +05:30
var b = SwitchBuilder.new().withRng(rng).withMaxConnections(maxConnections)
# libp2p 1.15.3 asserts both maxIn and maxOut > 0; only opt into independent
# in/out caps when the caller actually supplied them. Otherwise the single
# `withMaxConnections` cap from above remains in effect.
if maxIn > 0 and maxOut > 0:
b = b.withMaxInOut(maxIn, maxOut)
b = b
.withMaxConnsPerPeer(maxConnsPerPeer)
.withYamux()
.withMplex(inTimeout, outTimeout)
.withNoise()
.withTcpTransport(transportFlags)
.withNameResolver(nameResolver)
.withSignedPeerRecord(sendSignedPeerRecord)
.withCircuitRelay(circuitRelay)
.withAutonat()
if peerStoreCapacity.isSome():
b = b.withPeerStore(peerStoreCapacity.get())
else:
let defaultPeerStoreCapacity = int(maxConnections) * 5
b = b.withPeerStore(defaultPeerStoreCapacity)
if agentString.isSome():
b = b.withAgentVersion(agentString.get())
if privKey.isSome():
b = b.withPrivateKey(privKey.get())
if wsAddress.isSome():
b = b.withAddresses(@[wsAddress.get(), address])
if wssEnabled:
b = b.withWssTransport(secureKeyPath, secureCertPath)
else:
b = b.withWsTransport()
else:
b = b.withAddress(address)
feat(mix): bump libp2p stack to v2.0.0 + adopt stateless RLN spam protection Combines five dep-and-build changes that all flow from the libp2p v2.0.0 upgrade and the move to the extracted libp2p_mix / mix-rln plugin stack: waku.nimble: * libp2p: ff8d51857 -> c43199378 (release/v2.0.0 tip; sha-pinned until vacp2p cuts a v2.0.0 tag). * Drop the bare `zlib < 0.2` cap — no longer needed by the upgraded libp2p. * websock: bare ">= 0.4.0" — replaces the d4cd68b URL+SHA workaround that pinned through a libp2p commit-specific websock SHA. * nim-json-rpc: switch to chaitanyaprem/nim-json-rpc#f05fad25 — relaxes websock cap to allow >=0.4.0. TODO: revert to status-im/nim-json-rpc once status-im/nim-json-rpc#277 merges and a tag is cut. * lsquic: bare ">= 0.4.1" (drops URL form). * Add mix-rln-spam-protection-plugin pin (23b278b4) and nim-libp2p-mix pin (50c4ab4f — PR #14 HEAD); the plugin pins the same libp2p_mix SHA so the diamond dep collapses to a single source. waku/factory/waku.nim: * Explicit HPService.setup(switch) / AutonatService.setup(switch) calls. libp2p v2.0.0's Service lifecycle refactor (libp2p#2462) removed switch.start's auto-setup loop, so any caller that assigns directly to switch.services (we do) is responsible for calling setup() themselves. Without it, AutonatService.addressMapper stays nil and peerInfo.expandAddrs SIGSEGVs during start(). Wrapped in try/except for ServiceSetupError so a setup failure surfaces as a logged error rather than a crash. Build / scripts: * scripts/build_rln_mix.sh removed and Makefile simplified — librln is now a single shared archive built from zerokit's `stateless` features (no separate librln_mix archive). * simulations/mixnet/build_setup.sh + setup_credentials.nim updated to use librln_v2.0.2.a directly and run RLN keystore setup before nodes start. Validated: * Cold local-cache nimble setup --localdeps -y. * wakunode2 and chat2mix link cleanly. * Mixnet roundtrip sim: [PASS] bob received message from alice. * RLN proof generation + verification on every in-path mix node: 5 gen_called == 5 verified, 0 SPAM_PROOF_* errors.
2026-06-04 16:54:44 +05:30
if rendezvous.isSome():
b = b.withRendezVous(rendezvous.get())
b.build()