mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-27 23:27:27 +00:00
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
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -140,3 +140,6 @@
|
|||||||
url = https://github.com/ba0f3/dnsclient.nim.git
|
url = https://github.com/ba0f3/dnsclient.nim.git
|
||||||
ignore = untracked
|
ignore = untracked
|
||||||
branch = master
|
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 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 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
|
### Changes
|
||||||
|
11
examples/v2/example_config.toml
Normal file
11
examples/v2/example_config.toml
Normal file
@ -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
|
2
vendor/nim-confutils
vendored
2
vendor/nim-confutils
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 05a438414a91ae6729c6f1966358909840368e0c
|
Subproject commit d06f6187dca702ad884b9b948f52b26bf6596765
|
1
vendor/nim-toml-serialization
vendored
Submodule
1
vendor/nim-toml-serialization
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 90369dd67b4a41109e26716829f6f3f077eddf38
|
@ -1,6 +1,8 @@
|
|||||||
import
|
import
|
||||||
std/strutils,
|
std/strutils,
|
||||||
confutils, confutils/defs, confutils/std/net,
|
confutils, confutils/defs, confutils/std/net,
|
||||||
|
confutils/toml/defs as confTomlDefs,
|
||||||
|
confutils/toml/std/net as confTomlNet,
|
||||||
chronicles, chronos,
|
chronicles, chronos,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/crypto/secp,
|
libp2p/crypto/secp,
|
||||||
@ -9,10 +11,18 @@ import
|
|||||||
../protocol/waku_rln_relay/waku_rln_relay_types,
|
../protocol/waku_rln_relay/waku_rln_relay_types,
|
||||||
../protocol/waku_message
|
../protocol/waku_message
|
||||||
|
|
||||||
|
export
|
||||||
|
confTomlDefs,
|
||||||
|
confTomlNet
|
||||||
|
|
||||||
type
|
type
|
||||||
WakuNodeConf* = object
|
WakuNodeConf* = object
|
||||||
## General node config
|
## General node config
|
||||||
|
|
||||||
|
configFile* {.
|
||||||
|
desc: "Loads configuration from a TOML file (cmd-line parameters take precedence)"
|
||||||
|
name: "config-file" }: Option[InputFile]
|
||||||
|
|
||||||
logLevel* {.
|
logLevel* {.
|
||||||
desc: "Sets the log level."
|
desc: "Sets the log level."
|
||||||
defaultValue: LogLevel.INFO
|
defaultValue: LogLevel.INFO
|
||||||
@ -348,3 +358,11 @@ func defaultListenAddress*(conf: WakuNodeConf): ValidIpAddress =
|
|||||||
# TODO: How should we select between IPv4 and IPv6
|
# TODO: How should we select between IPv4 and IPv6
|
||||||
# Maybe there should be a config option for this.
|
# Maybe there should be a config option for this.
|
||||||
(static ValidIpAddress.init("0.0.0.0"))
|
(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
|
## 6. Setup graceful shutdown hooks
|
||||||
|
|
||||||
import
|
import
|
||||||
confutils,
|
confutils, toml_serialization,
|
||||||
system/ansi_c,
|
system/ansi_c,
|
||||||
libp2p/nameresolving/dnsresolver,
|
libp2p/nameresolving/dnsresolver,
|
||||||
../../common/utils/nat,
|
../../common/utils/nat,
|
||||||
@ -1294,8 +1294,17 @@ when isMainModule:
|
|||||||
|
|
||||||
ok(true) # Success
|
ok(true) # Success
|
||||||
|
|
||||||
let
|
{.push warning[ProveInit]: off.}
|
||||||
conf = WakuNodeConf.load()
|
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
|
var
|
||||||
node: WakuNode # This is the node we're going to setup using the conf
|
node: WakuNode # This is the node we're going to setup using the conf
|
||||||
|
Loading…
x
Reference in New Issue
Block a user