Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ testwaku: | build deps rln-deps librln
wakunode2: | build deps librln
echo -e $(BUILD_MSG) "build/$@" && \
\
$(ENV_SCRIPT) nim wakunode2 $(NIM_PARAMS) waku.nims
$(ENV_SCRIPT) nim wakunode2 $(NIM_PARAMS) -d:chronicles_runtime_filtering:on waku.nims

benchmarks: | build deps librln
echo -e $(BUILD_MSG) "build/$@" && \
Expand Down
22 changes: 2 additions & 20 deletions apps/chat2mix/chat2mix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -397,22 +397,6 @@ proc maintainSubscription(

await sleepAsync(30000) # Subscription maintenance interval

proc processMixNodes(localnode: WakuNode, nodes: seq[string]) {.async.} =
if nodes.len == 0:
return

info "Processing mix nodes: ", nodes = $nodes
for node in nodes:
var enrRec: enr.Record
if enrRec.fromURI(node):
let peerInfo = enrRec.toRemotePeerInfo().valueOr:
error "Failed to parse mix node", error = error
continue
localnode.peermanager.addPeer(peerInfo, Discv5)
info "Added mix node", peer = peerInfo
else:
error "Failed to parse mix node ENR", node = node

{.pop.}
# @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError
proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
Expand Down Expand Up @@ -486,11 +470,9 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
error "failed to generate mix key pair", error = error
return

(await node.mountMix(conf.clusterId, mixPrivKey)).isOkOr:
(await node.mountMix(conf.clusterId, mixPrivKey, conf.mixnodes)).isOkOr:
error "failed to mount waku mix protocol: ", error = $error
quit(QuitFailure)
if conf.mixnodes.len > 0:
await processMixNodes(node, conf.mixnodes)
await node.start()

node.peerManager.start()
Expand Down Expand Up @@ -624,7 +606,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
servicePeerInfo = parsePeerInfo(conf.serviceNode).valueOr:
error "Couldn't parse conf.serviceNode", error = error
RemotePeerInfo()
if $servicePeerInfo.peerId == "":
if servicePeerInfo == nil or $servicePeerInfo.peerId == "":
# Assuming that service node supports all services
servicePeerInfo = selectRandomServicePeer(
node.peerManager, none(RemotePeerInfo), WakuLightpushCodec
Expand Down
28 changes: 25 additions & 3 deletions apps/chat2mix/config_chat2mix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import
eth/keys,
libp2p/crypto/crypto,
libp2p/crypto/secp,
libp2p/crypto/curve25519,
libp2p/multiaddress,
libp2p/multicodec,
nimcrypto/utils,
confutils,
confutils/defs,
confutils/std/net

import waku/waku_core
import waku/waku_core, waku/waku_mix

type
Fleet* = enum
Expand Down Expand Up @@ -83,8 +86,10 @@ type
.}: seq[string]

mixnodes* {.
desc: "Peer ENR to add as a mixnode. Argument may be repeated.", name: "mixnode"
.}: seq[string]
desc:
"Multiaddress and mix-key of mix node to be statically specified in format multiaddr:mixPubKey. Argument may be repeated.",
name: "mixnode"
.}: seq[MixNodePubInfo]

keepAlive* {.
desc: "Enable keep-alive for idle connections: true|false",
Expand Down Expand Up @@ -225,6 +230,23 @@ type
name: "websocket-secure-support"
.}: bool ## rln-relay configuration

proc parseCmdArg*(T: type MixNodePubInfo, p: string): T =
let elements = p.split(":")
if elements.len != 2:
raise newException(
ValueError, "Invalid format for mix node expected multiaddr:mixPublicKey"
)
let multiaddr = MultiAddress.init(elements[0]).valueOr:
raise newException(ValueError, "Invalid multiaddress format")
if not multiaddr.contains(multiCodec("ip4")).get():
raise newException(
ValueError, "Invalid format for ip address, expected a ipv4 multiaddress"
)

return MixNodePubInfo(
multiaddr: elements[0], pubKey: intoCurve25519Key(ncrutils.fromHex(elements[1]))
)

# NOTE: Keys are different in nim-libp2p
proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
try:
Expand Down
2 changes: 1 addition & 1 deletion apps/wakunode2/wakunode2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ when isMainModule:
quit(QuitFailure)

c_signal(ansi_c.SIGSEGV, handleSigsegv)

logging.setTopicConfig(wakuNodeConf.logTopicsConfig)
info "Node setup complete"

runForever()
2 changes: 1 addition & 1 deletion examples/lightpush_mix/lightpush_publisher_mix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LightPushMixConf) {.async.}
let (mixPrivKey, mixPubKey) = generateKeyPair().valueOr:
error "failed to generate mix key pair", error = error
return
(await node.mountMix(clusterId, mixPrivKey)).isOkOr:
(await node.mountMix(clusterId, mixPrivKey, conf.mixnodes)).isOkOr:
error "failed to mount waku mix protocol: ", error = $error
return

Expand Down
32 changes: 31 additions & 1 deletion examples/lightpush_mix/lightpush_publisher_mix_config.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import confutils/defs
import
confutils/defs,
libp2p/crypto/curve25519,
libp2p/multiaddress,
libp2p/multicodec,
nimcrypto/utils as ncrutils

import waku/waku_mix

type LightPushMixConf* = object
destPeerAddr* {.desc: "Destination peer address with peerId.", name: "dp-addr".}:
Expand Down Expand Up @@ -26,3 +33,26 @@ type LightPushMixConf* = object
mixDisabled* {.
desc: "Do not use mix for publishing.", defaultValue: false, name: "without-mix"
.}: bool

mixnodes* {.
desc:
"Multiaddress and mix-key of mix node to be statically specified in format multiaddr:mixPubKey. Argument may be repeated.",
name: "mixnode"
.}: seq[MixNodePubInfo]

proc parseCmdArg*(T: typedesc[MixNodePubInfo], p: string): T =
let elements = p.split(":")
if elements.len != 2:
raise newException(
ValueError, "Invalid format for mix node expected multiaddr:mixPublicKey"
)

let multiaddr = MultiAddress.init(elements[0]).valueOr:
raise newException(ValueError, "Invalid multiaddress format")
if not multiaddr.contains(multiCodec("ip4")).get():
raise newException(
ValueError, "Invalid format for ip address, expected a ipv4 multiaddress"
)
return MixNodePubInfo(
multiaddr: elements[0], pubKey: intoCurve25519Key(ncrutils.fromHex(elements[1]))
)
1 change: 1 addition & 0 deletions simulations/mixnet/config1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ rendezvous = true
listen-address = "127.0.0.1"
nat = "extip:127.0.0.1"
ip-colocation-limit=0
log-topic-config=["wakumix:TRACE"]
#staticnode = ["/ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o", "/ip4/127.0.0.1/tcp/60003/p2p/16Uiu2HAmTEDHwAziWUSz6ZE23h5vxG2o4Nn7GazhMor4bVuMXTrA","/ip4/127.0.0.1/tcp/60004/p2p/16Uiu2HAmPwRKZajXtfb1Qsv45VVfRZgK3ENdfmnqzSrVm3BczF6f","/ip4/127.0.0.1/tcp/60005/p2p/16Uiu2HAmRhxmCHBYdXt1RibXrjAUNJbduAhzaTHwFCZT4qWnqZAu"]
2 changes: 1 addition & 1 deletion simulations/mixnet/run_chat_mix.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
../../build/chat2mix --cluster-id=2 --num-shards-in-network=1 --shard=0 --servicenode="/ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o" --log-level=TRACE --mixnode="enr:-Nq4QIPd6TbOWns1TsbSq2KB6g3hIClJa8qBUWFFwbGut9OBCwTHYshi0-iv1ilTMx4FkuSJ4NtkZVx0QSrrMRTGpEsDgmlkgnY0gmlwhH8AAAGHbWl4LWtleaCSMehtpkMlApAKhPhnAEznhjKrUs2OMLHsMizXlXEMKoptdWx0aWFkZHJzigAIBMCoRD4G6mKCcnOFAAIBAACJc2VjcDI1NmsxoQN6R8gw1Pu8IwMlTap0_E7vVd1wcaFgg_VUaaeVWSZYVIN0Y3CC6mKDdWRwgiMrhXdha3UyLQ" --mixnode="enr:-Nq4QC6XyKXZSlJNFzTDPI118SBC2ilLqE05RR4o4OzEZxueGkYtExHtTBvmY-9pl17EXZtXvF_tIV_2g0K_fb2LmsoDgmlkgnY0gmlwhH8AAAGHbWl4LWtleaAnXNaInh8pykjlue24ANGpT0nxPTk6Ds8aB691NQbebIptdWx0aWFkZHJzigAIBMCoRD4G6mOCcnOFAAIBAACJc2VjcDI1NmsxoQPYhmrbTqylbdenVfvO2U0w6EC4A-l5lwvu3QWL7IqkO4N0Y3CC6mODdWRwgiMthXdha3UyLQ" --mixnode="enr:-Nq4QKoh8Ta8Q3zLLAkf4hyYzxpuTc-BRBGb_WYVIm6hRptKZFuIo3DNlWCpfIxJnNI5epjLWQWHFUo3dqpAoWhoXEUDgmlkgnY0gmlwhH8AAAGHbWl4LWtleaDg7VlKjVBmgb4HXo4jcjR4OI-xgkd_ekaTCaJecHb8GIptdWx0aWFkZHJzigAIBMCoRD4G6mSCcnOFAAIBAACJc2VjcDI1NmsxoQOnphVC3U5zmOCkjOI2tY0v8K5QkXSaE5xO37q3iFfKGIN0Y3CC6mSDdWRwgiMvhXdha3UyLQ" --mixnode="enr:-Nq4QN7ub3xi53eDyKKstEM2IjFo7oY5Kf4glFz45W2saWqNXPqJFruw08c9B_EIu1LoW4opwXId_4zvPmekZwYHKp8DgmlkgnY0gmlwhH8AAAGHbWl4LWtleaCP16GnwZtAPSMUUqmx6kDrHMdvRV2RjviYDnaF-e7rH4ptdWx0aWFkZHJzigAIBMCoRD4G6mWCcnOFAAIBAACJc2VjcDI1NmsxoQLJtl9kA98YgBkVElkJgl9XyyRNco78oShb1hsv6Mlbs4N0Y3CC6mWDdWRwgiMxhXdha3UyLQ"
../../build/chat2mix --cluster-id=2 --num-shards-in-network=1 --shard=0 --servicenode="/ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o" --log-level=TRACE --mixnode="/ip4/127.0.0.1/tcp/60002/p2p/16Uiu2HAmLtKaFaSWDohToWhWUZFLtqzYZGPFuXwKrojFVF6az5UF:9231e86da6432502900a84f867004ce78632ab52cd8e30b1ec322cd795710c2a" --mixnode="/ip4/127.0.0.1/tcp/60003/p2p/16Uiu2HAmTEDHwAziWUSz6ZE23h5vxG2o4Nn7GazhMor4bVuMXTrA:275cd6889e1f29ca48e5b9edb800d1a94f49f13d393a0ecf1a07af753506de6c" --mixnode="/ip4/127.0.0.1/tcp/60004/p2p/16Uiu2HAmPwRKZajXtfb1Qsv45VVfRZgK3ENdfmnqzSrVm3BczF6f:e0ed594a8d506681be075e8e23723478388fb182477f7a469309a25e7076fc18" --mixnode="/ip4/127.0.0.1/tcp/60005/p2p/16Uiu2HAmRhxmCHBYdXt1RibXrjAUNJbduAhzaTHwFCZT4qWnqZAu:8fd7a1a7c19b403d231452a9b1ea40eb1cc76f455d918ef8980e7685f9eeeb1f"
2 changes: 1 addition & 1 deletion simulations/mixnet/run_chat_mix1.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
../../build/chat2mix --cluster-id=2 --num-shards-in-network=1 --shard=0 --servicenode="/ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o" --log-level=TRACE --mixnode="enr:-Nq4QIPd6TbOWns1TsbSq2KB6g3hIClJa8qBUWFFwbGut9OBCwTHYshi0-iv1ilTMx4FkuSJ4NtkZVx0QSrrMRTGpEsDgmlkgnY0gmlwhH8AAAGHbWl4LWtleaCSMehtpkMlApAKhPhnAEznhjKrUs2OMLHsMizXlXEMKoptdWx0aWFkZHJzigAIBMCoRD4G6mKCcnOFAAIBAACJc2VjcDI1NmsxoQN6R8gw1Pu8IwMlTap0_E7vVd1wcaFgg_VUaaeVWSZYVIN0Y3CC6mKDdWRwgiMrhXdha3UyLQ" --mixnode="enr:-Nq4QC6XyKXZSlJNFzTDPI118SBC2ilLqE05RR4o4OzEZxueGkYtExHtTBvmY-9pl17EXZtXvF_tIV_2g0K_fb2LmsoDgmlkgnY0gmlwhH8AAAGHbWl4LWtleaAnXNaInh8pykjlue24ANGpT0nxPTk6Ds8aB691NQbebIptdWx0aWFkZHJzigAIBMCoRD4G6mOCcnOFAAIBAACJc2VjcDI1NmsxoQPYhmrbTqylbdenVfvO2U0w6EC4A-l5lwvu3QWL7IqkO4N0Y3CC6mODdWRwgiMthXdha3UyLQ" --mixnode="enr:-Nq4QKoh8Ta8Q3zLLAkf4hyYzxpuTc-BRBGb_WYVIm6hRptKZFuIo3DNlWCpfIxJnNI5epjLWQWHFUo3dqpAoWhoXEUDgmlkgnY0gmlwhH8AAAGHbWl4LWtleaDg7VlKjVBmgb4HXo4jcjR4OI-xgkd_ekaTCaJecHb8GIptdWx0aWFkZHJzigAIBMCoRD4G6mSCcnOFAAIBAACJc2VjcDI1NmsxoQOnphVC3U5zmOCkjOI2tY0v8K5QkXSaE5xO37q3iFfKGIN0Y3CC6mSDdWRwgiMvhXdha3UyLQ" --mixnode="enr:-Nq4QN7ub3xi53eDyKKstEM2IjFo7oY5Kf4glFz45W2saWqNXPqJFruw08c9B_EIu1LoW4opwXId_4zvPmekZwYHKp8DgmlkgnY0gmlwhH8AAAGHbWl4LWtleaCP16GnwZtAPSMUUqmx6kDrHMdvRV2RjviYDnaF-e7rH4ptdWx0aWFkZHJzigAIBMCoRD4G6mWCcnOFAAIBAACJc2VjcDI1NmsxoQLJtl9kA98YgBkVElkJgl9XyyRNco78oShb1hsv6Mlbs4N0Y3CC6mWDdWRwgiMxhXdha3UyLQ"
../../build/chat2mix --cluster-id=2 --num-shards-in-network=1 --shard=0 --servicenode="/ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o" --log-level=TRACE --mixnode="/ip4/127.0.0.1/tcp/60002/p2p/16Uiu2HAmLtKaFaSWDohToWhWUZFLtqzYZGPFuXwKrojFVF6az5UF:9231e86da6432502900a84f867004ce78632ab52cd8e30b1ec322cd795710c2a" --mixnode="/ip4/127.0.0.1/tcp/60003/p2p/16Uiu2HAmTEDHwAziWUSz6ZE23h5vxG2o4Nn7GazhMor4bVuMXTrA:275cd6889e1f29ca48e5b9edb800d1a94f49f13d393a0ecf1a07af753506de6c" --mixnode="/ip4/127.0.0.1/tcp/60004/p2p/16Uiu2HAmPwRKZajXtfb1Qsv45VVfRZgK3ENdfmnqzSrVm3BczF6f:e0ed594a8d506681be075e8e23723478388fb182477f7a469309a25e7076fc18" --mixnode="/ip4/127.0.0.1/tcp/60005/p2p/16Uiu2HAmRhxmCHBYdXt1RibXrjAUNJbduAhzaTHwFCZT4qWnqZAu:8fd7a1a7c19b403d231452a9b1ea40eb1cc76f455d918ef8980e7685f9eeeb1f"
24 changes: 13 additions & 11 deletions tests/wakunode_rest/test_rest_health.nim
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ suite "Waku v2 REST API - health":
response.status == 200
$response.contentType == $MIMETYPE_JSON
response.data.nodeHealth == HealthStatus.READY
response.data.protocolsHealth.len() == 14
response.data.protocolsHealth.len() == 15
response.data.protocolsHealth[0].protocol == "Relay"
response.data.protocolsHealth[0].health == HealthStatus.NOT_READY
response.data.protocolsHealth[0].desc == some("No connected peers")
Expand All @@ -114,19 +114,21 @@ suite "Waku v2 REST API - health":
response.data.protocolsHealth[7].health == HealthStatus.NOT_MOUNTED
response.data.protocolsHealth[8].protocol == "Rendezvous"
response.data.protocolsHealth[8].health == HealthStatus.NOT_MOUNTED
response.data.protocolsHealth[9].protocol == "Lightpush Client"
response.data.protocolsHealth[9].health == HealthStatus.NOT_READY
response.data.protocolsHealth[9].desc ==
response.data.protocolsHealth[9].protocol == "Mix"
response.data.protocolsHealth[9].health == HealthStatus.NOT_MOUNTED
response.data.protocolsHealth[10].protocol == "Lightpush Client"
response.data.protocolsHealth[10].health == HealthStatus.NOT_READY
response.data.protocolsHealth[10].desc ==
some("No Lightpush service peer available yet")
response.data.protocolsHealth[10].protocol == "Legacy Lightpush Client"
response.data.protocolsHealth[10].health == HealthStatus.NOT_MOUNTED
response.data.protocolsHealth[11].protocol == "Store Client"
response.data.protocolsHealth[11].protocol == "Legacy Lightpush Client"
response.data.protocolsHealth[11].health == HealthStatus.NOT_MOUNTED
response.data.protocolsHealth[12].protocol == "Legacy Store Client"
response.data.protocolsHealth[12].protocol == "Store Client"
response.data.protocolsHealth[12].health == HealthStatus.NOT_MOUNTED
response.data.protocolsHealth[13].protocol == "Filter Client"
response.data.protocolsHealth[13].health == HealthStatus.NOT_READY
response.data.protocolsHealth[13].desc ==
response.data.protocolsHealth[13].protocol == "Legacy Store Client"
response.data.protocolsHealth[13].health == HealthStatus.NOT_MOUNTED
response.data.protocolsHealth[14].protocol == "Filter Client"
response.data.protocolsHealth[14].health == HealthStatus.NOT_READY
response.data.protocolsHealth[14].desc ==
some("No Filter service peer available yet")

await restServer.stop()
Expand Down
83 changes: 82 additions & 1 deletion tools/confutils/cli_args.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import
std/[strutils, strformat, sequtils],
std/[strutils, strformat, sequtils, enumutils],
results,
chronicles,
chronos,
Expand All @@ -11,9 +11,11 @@ import
confutils/std/net,
confutils/toml/defs as confTomlDefs,
confutils/toml/std/net as confTomlNet,
libp2p/crypto/curve25519,
libp2p/crypto/crypto,
libp2p/crypto/secp,
libp2p/multiaddress,
libp2p/multicodec,
nimcrypto/utils,
secp256k1,
json
Expand All @@ -26,6 +28,7 @@ import
node/peer_manager,
waku_core/topics/pubsub_topic,
waku_core/message/default_values,
waku_mix,
],
../../tools/rln_keystore_generator/rln_keystore_generator

Expand Down Expand Up @@ -68,6 +71,13 @@ type WakuNodeConf* = object
name: "log-format"
.}: logging.LogFormat

logTopicsConfig* {.
desc:
"Sets the log level for specific topics. Format: <topic>:<level>. Argument may be repeated. ",
defaultValue: newSeq[LogTopicConfig](0),
name: "log-topic-config"
.}: seq[LogTopicConfig]

rlnRelayCredPath* {.
desc: "The path for persisting rln-relay credential",
defaultValue: "",
Expand Down Expand Up @@ -615,6 +625,12 @@ with the drawback of consuming some more bandwidth.""",
name: "mixkey"
.}: Option[string]

mixnodes* {.
desc:
"Multiaddress and mix-key of mix node to be statically specified in format multiaddr:mixPubKey. Argument may be repeated.",
name: "mixnode"
.}: seq[MixNodePubInfo]

## websocket config
websocketSupport* {.
desc: "Enable websocket: true|false",
Expand Down Expand Up @@ -694,6 +710,37 @@ proc isNumber(x: string): bool =
except ValueError:
result = false

proc parseCmdArg*(T: type LogTopicConfig, p: string): T =
let elements = p.split(":")
if elements.len != 2:
raise newException(
ValueError, "Invalid format for logTopicsConfig expected topic:loglevel"
)

var logTopicConfig: LogTopicConfig
try:
let logLevel = parseEnum[LogLevel](elements[1])
logTopicConfig = LogTopicConfig(topic: elements[0], level: logLevel)
except ValueError:
raise newException(ValueError, "Invalid log level")
return logTopicConfig

proc parseCmdArg*(T: type MixNodePubInfo, p: string): T =
let elements = p.split(":")
if elements.len != 2:
raise newException(
ValueError, "Invalid format for mix node expected multiaddr:mixPublicKey"
)
let multiaddr = MultiAddress.init(elements[0]).valueOr:
raise newException(ValueError, "Invalid multiaddress format")
if not multiaddr.contains(multiCodec("ip4")).get():
raise newException(
ValueError, "Invalid format for ip address, expected a ipv4 multiaddress"
)
return MixNodePubInfo(
multiaddr: elements[0], pubKey: intoCurve25519Key(ncrutils.fromHex(elements[1]))
)

proc parseCmdArg*(T: type ProtectedShard, p: string): T =
let elements = p.split(":")
if elements.len != 2:
Expand Down Expand Up @@ -778,6 +825,38 @@ proc readValue*(
except CatchableError:
raise newException(SerializationError, getCurrentExceptionMsg())

proc readValue*(
r: var TomlReader, value: var LogTopicConfig
) {.raises: [SerializationError].} =
try:
value = parseCmdArg(LogTopicConfig, r.readValue(string))
except CatchableError:
raise newException(SerializationError, getCurrentExceptionMsg())

proc readValue*(
r: var EnvvarReader, value: var LogTopicConfig
) {.raises: [SerializationError].} =
try:
value = parseCmdArg(LogTopicConfig, r.readValue(string))
except CatchableError:
raise newException(SerializationError, getCurrentExceptionMsg())

proc readValue*(
r: var TomlReader, value: var MixNodePubInfo
) {.raises: [SerializationError].} =
try:
value = parseCmdArg(MixNodePubInfo, r.readValue(string))
except CatchableError:
raise newException(SerializationError, getCurrentExceptionMsg())

proc readValue*(
r: var EnvvarReader, value: var MixNodePubInfo
) {.raises: [SerializationError].} =
try:
value = parseCmdArg(MixNodePubInfo, r.readValue(string))
except CatchableError:
raise newException(SerializationError, getCurrentExceptionMsg())

proc readValue*(
r: var TomlReader, value: var ProtectedShard
) {.raises: [SerializationError].} =
Expand Down Expand Up @@ -870,6 +949,7 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] =

b.withLogLevel(n.logLevel)
b.withLogFormat(n.logFormat)
b.withLogTopicsConfig(n.logTopicsConfig)

b.rlnRelayConf.withEnabled(n.rlnRelay)
if n.rlnRelayCredPath != "":
Expand Down Expand Up @@ -972,6 +1052,7 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] =
b.storeServiceConf.storeSyncConf.withRelayJitterSec(n.storeSyncRelayJitter)

b.mixConf.withEnabled(n.mix)
b.mixConf.withMixNodes(n.mixnodes)
b.withMix(n.mix)
if n.mixkey.isSome():
b.mixConf.withMixKey(n.mixkey.get())
Expand Down
13 changes: 12 additions & 1 deletion waku/common/logging.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ type LogFormat* = enum
TEXT
JSON

type LogTopicConfig* = object
topic*: string
level*: LogLevel

## Utils

proc stripAnsi(v: string): string =
Expand Down Expand Up @@ -63,7 +67,6 @@ proc writeAndFlush(f: syncio.File, s: LogOutputStr) =
## Setup

proc setupLogLevel(level: LogLevel) =
# TODO: Support per topic level configuratio
topics_registry.setLogLevel(level)

proc setupLogFormat(format: LogFormat, color = true) =
Expand Down Expand Up @@ -103,3 +106,11 @@ proc setupLog*(level: LogLevel, format: LogFormat) =

setupLogLevel(level)
setupLogFormat(format, color)

proc setTopicConfig*(logTopicsConfig: seq[LogTopicConfig]) =
for topicConf in logTopicsConfig:
if not topics_registry.setTopicState(topicConf.topic, Enabled, topicConf.level):
error "Unknown logging topic or unable to set loglevel",
topic = topicConf.topic, level = $topicConf.level

{.pop.}
Loading
Loading