mirror of https://github.com/waku-org/nwaku.git
feat(config): add config file support (#953)
including * bump vendor/nim-confutils * add nim-toml-serialization submodule * feat(config): add example config file * add new feature to CHANGELOG
This commit is contained in:
parent
bd70a1b7bb
commit
51cbc39d49
|
@ -140,3 +140,6 @@
|
|||
url = https://github.com/ba0f3/dnsclient.nim.git
|
||||
ignore = untracked
|
||||
branch = master
|
||||
[submodule "vendor/nim-toml-serialization"]
|
||||
path = vendor/nim-toml-serialization
|
||||
url = https://github.com/status-im/nim-toml-serialization.git
|
||||
|
|
|
@ -12,6 +12,7 @@ The full list of changes is below.
|
|||
|
||||
- Support for bootstrapping [`33/WAKU-DISCV5`](https://rfc.vac.dev/spec/33) via [DNS discovery](https://rfc.vac.dev/spec/10/#discovery-methods)
|
||||
- Support for GossipSub [Peer Exchange](https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md#prune-backoff-and-peer-exchange)
|
||||
- Support for TOML config files via `--config-file=<path/to/config.toml>`
|
||||
|
||||
|
||||
### Changes
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
relay=true
|
||||
store=true
|
||||
filter=true
|
||||
db-path="./dbs/db1"
|
||||
rpc-admin=true
|
||||
persist-peers=true
|
||||
keep-alive=true
|
||||
persist-messages=true
|
||||
lightpush=true
|
||||
nodekey="f157b19b13e9ee818acfc9d3d7eec6b81f70c0a978dec19def261172acbe26e6"
|
||||
ports-shift=1
|
|
@ -1 +1 @@
|
|||
Subproject commit 05a438414a91ae6729c6f1966358909840368e0c
|
||||
Subproject commit d06f6187dca702ad884b9b948f52b26bf6596765
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 90369dd67b4a41109e26716829f6f3f077eddf38
|
|
@ -1,6 +1,8 @@
|
|||
import
|
||||
std/strutils,
|
||||
confutils, confutils/defs, confutils/std/net,
|
||||
confutils/toml/defs as confTomlDefs,
|
||||
confutils/toml/std/net as confTomlNet,
|
||||
chronicles, chronos,
|
||||
libp2p/crypto/crypto,
|
||||
libp2p/crypto/secp,
|
||||
|
@ -8,11 +10,19 @@ import
|
|||
eth/keys,
|
||||
../protocol/waku_rln_relay/waku_rln_relay_types,
|
||||
../protocol/waku_message
|
||||
|
||||
export
|
||||
confTomlDefs,
|
||||
confTomlNet
|
||||
|
||||
type
|
||||
WakuNodeConf* = object
|
||||
## General node config
|
||||
|
||||
configFile* {.
|
||||
desc: "Loads configuration from a TOML file (cmd-line parameters take precedence)"
|
||||
name: "config-file" }: Option[InputFile]
|
||||
|
||||
logLevel* {.
|
||||
desc: "Sets the log level."
|
||||
defaultValue: LogLevel.INFO
|
||||
|
@ -348,3 +358,11 @@ func defaultListenAddress*(conf: WakuNodeConf): ValidIpAddress =
|
|||
# TODO: How should we select between IPv4 and IPv6
|
||||
# Maybe there should be a config option for this.
|
||||
(static ValidIpAddress.init("0.0.0.0"))
|
||||
|
||||
|
||||
proc readValue*(r: var TomlReader, val: var crypto.PrivateKey)
|
||||
{.raises: [Defect, IOError, SerializationError].} =
|
||||
val = try: parseCmdArg(crypto.PrivateKey, r.readValue(string))
|
||||
except CatchableError as err:
|
||||
raise newException(SerializationError, err.msg)
|
||||
|
||||
|
|
|
@ -972,7 +972,7 @@ when isMainModule:
|
|||
## 6. Setup graceful shutdown hooks
|
||||
|
||||
import
|
||||
confutils,
|
||||
confutils, toml_serialization,
|
||||
system/ansi_c,
|
||||
libp2p/nameresolving/dnsresolver,
|
||||
../../common/utils/nat,
|
||||
|
@ -1293,10 +1293,19 @@ when isMainModule:
|
|||
Port(conf.metricsServerPort + conf.portsShift))
|
||||
|
||||
ok(true) # Success
|
||||
|
||||
let
|
||||
conf = WakuNodeConf.load()
|
||||
|
||||
|
||||
{.push warning[ProveInit]: off.}
|
||||
let conf = try:
|
||||
WakuNodeConf.load(
|
||||
secondarySources = proc (conf: WakuNodeConf, sources: auto) =
|
||||
if conf.configFile.isSome:
|
||||
sources.addConfigFile(Toml, conf.configFile.get)
|
||||
)
|
||||
except CatchableError as err:
|
||||
error "Failure while loading the configuration: \n", err_msg=err.msg
|
||||
quit 1 # if we don't leave here, the initialization of conf does not work in the success case
|
||||
{.pop.}
|
||||
|
||||
var
|
||||
node: WakuNode # This is the node we're going to setup using the conf
|
||||
|
||||
|
|
Loading…
Reference in New Issue