2020-04-29 04:49:27 +00:00
|
|
|
import
|
2022-10-26 15:10:30 +00:00
|
|
|
std/[strutils, nre],
|
|
|
|
stew/results,
|
|
|
|
chronicles,
|
|
|
|
chronos,
|
2022-10-18 12:06:54 +00:00
|
|
|
confutils,
|
|
|
|
confutils/defs,
|
|
|
|
confutils/std/net,
|
2022-05-17 15:48:08 +00:00
|
|
|
confutils/toml/defs as confTomlDefs,
|
|
|
|
confutils/toml/std/net as confTomlNet,
|
2020-05-21 04:16:00 +00:00
|
|
|
libp2p/crypto/crypto,
|
|
|
|
libp2p/crypto/secp,
|
2022-10-18 12:06:54 +00:00
|
|
|
nimcrypto/utils
|
2022-05-17 15:48:08 +00:00
|
|
|
|
|
|
|
export
|
|
|
|
confTomlDefs,
|
|
|
|
confTomlNet
|
2022-10-26 15:10:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
type ConfResult*[T] = Result[T, string]
|
2021-12-08 18:35:47 +00:00
|
|
|
|
2020-04-29 04:49:27 +00:00
|
|
|
type
|
|
|
|
WakuNodeConf* = object
|
2021-05-11 15:07:26 +00:00
|
|
|
## General node config
|
|
|
|
|
2022-05-17 15:48:08 +00:00
|
|
|
configFile* {.
|
|
|
|
desc: "Loads configuration from a TOML file (cmd-line parameters take precedence)"
|
|
|
|
name: "config-file" }: Option[InputFile]
|
|
|
|
|
2020-04-29 04:49:27 +00:00
|
|
|
logLevel* {.
|
|
|
|
desc: "Sets the log level."
|
|
|
|
defaultValue: LogLevel.INFO
|
|
|
|
name: "log-level" }: LogLevel
|
2022-05-17 20:11:07 +00:00
|
|
|
|
|
|
|
version* {.
|
|
|
|
desc: "prints the version"
|
|
|
|
defaultValue: false
|
|
|
|
name: "version" }: bool
|
2022-10-28 13:12:06 +00:00
|
|
|
|
|
|
|
agentString* {.
|
|
|
|
defaultValue: "nwaku",
|
|
|
|
desc: "Node agent string which is used as identifier in network"
|
|
|
|
name: "agent-string" .}: string
|
2021-05-11 15:07:26 +00:00
|
|
|
|
|
|
|
nodekey* {.
|
|
|
|
desc: "P2P node private key as 64 char hex string.",
|
2022-10-18 12:06:54 +00:00
|
|
|
defaultValue: defaultPrivateKey()
|
|
|
|
name: "nodekey" }: PrivateKey
|
2020-04-29 04:49:27 +00:00
|
|
|
|
2020-10-22 15:04:17 +00:00
|
|
|
listenAddress* {.
|
2022-10-18 12:06:54 +00:00
|
|
|
defaultValue: defaultListenAddress()
|
2021-11-01 18:02:39 +00:00
|
|
|
desc: "Listening address for LibP2P (and Discovery v5, if enabled) traffic."
|
2020-07-24 01:39:58 +00:00
|
|
|
name: "listen-address"}: ValidIpAddress
|
|
|
|
|
2020-04-29 04:49:27 +00:00
|
|
|
tcpPort* {.
|
|
|
|
desc: "TCP listening port."
|
2020-05-28 03:28:44 +00:00
|
|
|
defaultValue: 60000
|
2020-07-24 01:39:58 +00:00
|
|
|
name: "tcp-port" }: Port
|
2021-11-02 10:29:11 +00:00
|
|
|
|
2020-04-29 04:49:27 +00:00
|
|
|
portsShift* {.
|
|
|
|
desc: "Add a shift to all port numbers."
|
|
|
|
defaultValue: 0
|
|
|
|
name: "ports-shift" }: uint16
|
|
|
|
|
|
|
|
nat* {.
|
|
|
|
desc: "Specify method to use for determining public address. " &
|
|
|
|
"Must be one of: any, none, upnp, pmp, extip:<IP>."
|
|
|
|
defaultValue: "any" }: string
|
2021-10-12 12:48:48 +00:00
|
|
|
|
|
|
|
maxConnections* {.
|
|
|
|
desc: "Maximum allowed number of libp2p connections."
|
|
|
|
defaultValue: 50
|
|
|
|
name: "max-connections" }: uint16
|
2021-05-11 15:07:26 +00:00
|
|
|
|
2022-10-26 15:10:30 +00:00
|
|
|
peerPersistence* {.
|
|
|
|
desc: "Enable peer persistence.",
|
|
|
|
defaultValue: false,
|
|
|
|
name: "peer-persistence" }: bool
|
|
|
|
|
2022-02-16 16:12:09 +00:00
|
|
|
## DNS addrs config
|
|
|
|
|
|
|
|
dnsAddrs* {.
|
|
|
|
desc: "Enable resolution of `dnsaddr`, `dns4` or `dns6` multiaddrs"
|
|
|
|
defaultValue: true
|
|
|
|
name: "dns-addrs" }: bool
|
|
|
|
|
|
|
|
dnsAddrsNameServers* {.
|
|
|
|
desc: "DNS name server IPs to query for DNS multiaddrs resolution. Argument may be repeated."
|
|
|
|
defaultValue: @[ValidIpAddress.init("1.1.1.1"), ValidIpAddress.init("1.0.0.1")]
|
|
|
|
name: "dns-addrs-name-server" }: seq[ValidIpAddress]
|
2022-02-18 11:10:38 +00:00
|
|
|
|
|
|
|
dns4DomainName* {.
|
|
|
|
desc: "The domain name resolving to the node's public IPv4 address",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "dns4-domain-name" }: string
|
2021-05-03 21:30:52 +00:00
|
|
|
|
2021-05-11 15:07:26 +00:00
|
|
|
## Relay config
|
2020-10-20 02:36:27 +00:00
|
|
|
|
|
|
|
relay* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Enable relay protocol: true|false",
|
2020-10-20 02:36:27 +00:00
|
|
|
defaultValue: true
|
|
|
|
name: "relay" }: bool
|
2021-01-08 17:56:58 +00:00
|
|
|
|
2022-03-29 08:09:48 +00:00
|
|
|
relayPeerExchange* {.
|
|
|
|
desc: "Enable gossipsub peer exchange in relay protocol: true|false",
|
2022-05-13 16:18:09 +00:00
|
|
|
defaultValue: false
|
2022-03-29 08:09:48 +00:00
|
|
|
name: "relay-peer-exchange" }: bool
|
|
|
|
|
2021-05-11 15:07:26 +00:00
|
|
|
rlnRelay* {.
|
|
|
|
desc: "Enable spam protection through rln-relay: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "rln-relay" }: bool
|
|
|
|
|
2022-08-18 17:35:02 +00:00
|
|
|
rlnRelayCredPath* {.
|
|
|
|
desc: "The path for peristing rln-relay credential",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "rln-relay-cred-path" }: string
|
|
|
|
|
2022-10-03 20:25:56 +00:00
|
|
|
rlnRelayMembershipIndex* {.
|
2021-09-24 17:32:45 +00:00
|
|
|
desc: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive",
|
2022-09-07 01:51:10 +00:00
|
|
|
defaultValue: 0
|
|
|
|
name: "rln-relay-membership-index" }: uint
|
2021-09-24 17:32:45 +00:00
|
|
|
|
|
|
|
rlnRelayPubsubTopic* {.
|
|
|
|
desc: "the pubsub topic for which rln-relay gets enabled",
|
2022-02-04 23:58:27 +00:00
|
|
|
defaultValue: "/waku/2/default-waku/proto"
|
2021-09-24 17:32:45 +00:00
|
|
|
name: "rln-relay-pubsub-topic" }: string
|
2022-02-04 23:58:27 +00:00
|
|
|
|
|
|
|
rlnRelayContentTopic* {.
|
|
|
|
desc: "the pubsub topic for which rln-relay gets enabled",
|
2022-03-24 17:47:40 +00:00
|
|
|
defaultValue: "/toy-chat/2/luzhou/proto"
|
2022-10-18 12:06:54 +00:00
|
|
|
name: "rln-relay-content-topic" }: string
|
2021-11-01 18:02:39 +00:00
|
|
|
|
2022-06-17 22:00:19 +00:00
|
|
|
rlnRelayDynamic* {.
|
|
|
|
desc: "Enable waku-rln-relay with on-chain dynamic group management: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "rln-relay-dynamic" }: bool
|
|
|
|
|
|
|
|
rlnRelayIdKey* {.
|
|
|
|
desc: "Rln relay identity secret key as a Hex string",
|
|
|
|
defaultValue: ""
|
2022-10-03 20:25:56 +00:00
|
|
|
name: "rln-relay-id-key" }: string
|
2022-06-17 22:00:19 +00:00
|
|
|
|
|
|
|
rlnRelayIdCommitmentKey* {.
|
|
|
|
desc: "Rln relay identity commitment key as a Hex string",
|
|
|
|
defaultValue: ""
|
2022-10-03 20:25:56 +00:00
|
|
|
name: "rln-relay-id-commitment-key" }: string
|
2022-06-17 22:00:19 +00:00
|
|
|
|
2022-10-26 15:10:30 +00:00
|
|
|
# NOTE: This can be derived from the private key, but kept for future use
|
2022-10-03 20:25:56 +00:00
|
|
|
rlnRelayEthAccountAddress* {.
|
2022-07-01 01:05:38 +00:00
|
|
|
desc: "Account address for the Ethereum testnet Goerli",
|
2022-06-17 22:00:19 +00:00
|
|
|
defaultValue: ""
|
2022-10-03 20:25:56 +00:00
|
|
|
name: "rln-relay-eth-account-address" }: string
|
2022-07-01 01:05:38 +00:00
|
|
|
|
2022-10-03 20:25:56 +00:00
|
|
|
rlnRelayEthAccountPrivateKey* {.
|
2022-07-01 01:05:38 +00:00
|
|
|
desc: "Account private key for the Ethereum testnet Goerli",
|
|
|
|
defaultValue: ""
|
2022-10-03 20:25:56 +00:00
|
|
|
name: "rln-relay-eth-account-private-key" }: string
|
2022-06-17 22:00:19 +00:00
|
|
|
|
|
|
|
rlnRelayEthClientAddress* {.
|
2022-09-24 04:57:28 +00:00
|
|
|
desc: "WebSocket address of an Ethereum testnet client e.g., ws://localhost:8540/",
|
2022-06-17 22:00:19 +00:00
|
|
|
defaultValue: "ws://localhost:8540/"
|
2022-10-03 20:25:56 +00:00
|
|
|
name: "rln-relay-eth-client-address" }: string
|
2022-06-17 22:00:19 +00:00
|
|
|
|
2022-10-03 20:25:56 +00:00
|
|
|
rlnRelayEthContractAddress* {.
|
2022-06-17 22:00:19 +00:00
|
|
|
desc: "Address of membership contract on an Ethereum testnet",
|
|
|
|
defaultValue: ""
|
2022-10-03 20:25:56 +00:00
|
|
|
name: "rln-relay-eth-contract-address" }: string
|
2022-10-28 09:13:05 +00:00
|
|
|
|
|
|
|
rlnRelayCredentialsPassword* {.
|
|
|
|
desc: "Password for encrypting RLN credentials",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "rln-relay-cred-password" }: string
|
|
|
|
|
2021-05-11 15:07:26 +00:00
|
|
|
staticnodes* {.
|
|
|
|
desc: "Peer multiaddr to directly connect with. Argument may be repeated."
|
|
|
|
name: "staticnode" }: seq[string]
|
|
|
|
|
2021-04-30 12:07:46 +00:00
|
|
|
keepAlive* {.
|
|
|
|
desc: "Enable keep-alive for idle connections: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "keep-alive" }: bool
|
2020-10-20 02:36:27 +00:00
|
|
|
|
2021-05-11 15:07:26 +00:00
|
|
|
topics* {.
|
|
|
|
desc: "Default topics to subscribe to (space separated list)."
|
|
|
|
defaultValue: "/waku/2/default-waku/proto"
|
|
|
|
name: "topics" .}: string
|
|
|
|
|
2022-10-26 15:10:30 +00:00
|
|
|
## Store and message store config
|
2021-05-11 15:07:26 +00:00
|
|
|
|
|
|
|
store* {.
|
2022-10-26 15:10:30 +00:00
|
|
|
desc: "Enable/disable waku store protocol",
|
2022-10-27 22:05:02 +00:00
|
|
|
defaultValue: true,
|
2021-05-11 15:07:26 +00:00
|
|
|
name: "store" }: bool
|
|
|
|
|
2022-10-27 22:05:02 +00:00
|
|
|
storenode* {.
|
|
|
|
desc: "Peer multiaddress to query for storage",
|
|
|
|
defaultValue: "",
|
|
|
|
name: "storenode" }: string
|
|
|
|
|
2022-10-26 15:10:30 +00:00
|
|
|
storeMessageRetentionPolicy* {.
|
|
|
|
desc: "Message store retention policy. Time retention policy: 'time:<seconds>'. Capacity retention policy: 'capacity:<count>'",
|
|
|
|
defaultValue: "time:" & $2.days.seconds,
|
|
|
|
name: "store-message-retention-policy" }: string
|
|
|
|
|
|
|
|
storeMessageDbUrl* {.
|
|
|
|
desc: "The database connection URL for peristent storage.",
|
|
|
|
defaultValue: "sqlite://store.sqlite3",
|
|
|
|
name: "store-message-db-url" }: string
|
|
|
|
|
|
|
|
storeMessageDbVacuum* {.
|
|
|
|
desc: "Enable database vacuuming at start. Only supported by SQLite database engine.",
|
|
|
|
defaultValue: false,
|
|
|
|
name: "store-message-db-vacuum" }: bool
|
|
|
|
|
|
|
|
storeMessageDbMigration* {.
|
|
|
|
desc: "Enable database migration at start.",
|
|
|
|
defaultValue: true,
|
|
|
|
name: "store-message-db-migration" }: bool
|
|
|
|
|
|
|
|
storeResumePeer* {.
|
|
|
|
desc: "Peer multiaddress to resume the message store at boot.",
|
|
|
|
defaultValue: "",
|
|
|
|
name: "store-resume-peer" }: string
|
|
|
|
|
2021-05-11 15:07:26 +00:00
|
|
|
## Filter config
|
|
|
|
|
|
|
|
filter* {.
|
|
|
|
desc: "Enable filter protocol: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "filter" }: bool
|
|
|
|
|
|
|
|
filternode* {.
|
|
|
|
desc: "Peer multiaddr to request content filtering of messages.",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "filternode" }: string
|
|
|
|
|
2021-12-08 18:35:47 +00:00
|
|
|
filterTimeout* {.
|
|
|
|
desc: "Timeout for filter node in seconds.",
|
|
|
|
defaultValue: 14400 # 4 hours
|
|
|
|
name: "filter-timeout" }: int64
|
|
|
|
|
2021-05-11 15:07:26 +00:00
|
|
|
## Swap config
|
|
|
|
|
2020-11-21 05:31:48 +00:00
|
|
|
swap* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Enable swap protocol: true|false",
|
2022-06-08 07:16:45 +00:00
|
|
|
defaultValue: false
|
2020-11-21 05:31:48 +00:00
|
|
|
name: "swap" }: bool
|
2021-05-11 15:07:26 +00:00
|
|
|
|
|
|
|
## Lightpush config
|
2020-11-21 05:31:48 +00:00
|
|
|
|
2021-04-24 04:56:37 +00:00
|
|
|
lightpush* {.
|
|
|
|
desc: "Enable lightpush protocol: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "lightpush" }: bool
|
2020-11-16 08:38:52 +00:00
|
|
|
|
2021-06-04 10:02:47 +00:00
|
|
|
lightpushnode* {.
|
|
|
|
desc: "Peer multiaddr to request lightpush of published messages.",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "lightpushnode" }: string
|
|
|
|
|
2021-05-11 15:07:26 +00:00
|
|
|
## JSON-RPC config
|
2020-04-29 04:49:27 +00:00
|
|
|
|
|
|
|
rpc* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Enable Waku JSON-RPC server: true|false",
|
2020-04-29 05:19:48 +00:00
|
|
|
defaultValue: true
|
2020-04-29 04:49:27 +00:00
|
|
|
name: "rpc" }: bool
|
|
|
|
|
|
|
|
rpcAddress* {.
|
2020-12-24 08:02:30 +00:00
|
|
|
desc: "Listening address of the JSON-RPC server.",
|
2020-07-24 01:39:58 +00:00
|
|
|
defaultValue: ValidIpAddress.init("127.0.0.1")
|
|
|
|
name: "rpc-address" }: ValidIpAddress
|
2020-04-29 04:49:27 +00:00
|
|
|
|
|
|
|
rpcPort* {.
|
2020-12-24 08:02:30 +00:00
|
|
|
desc: "Listening port of the JSON-RPC server.",
|
2020-04-29 04:49:27 +00:00
|
|
|
defaultValue: 8545
|
|
|
|
name: "rpc-port" }: uint16
|
2020-12-24 08:02:30 +00:00
|
|
|
|
|
|
|
rpcAdmin* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Enable access to JSON-RPC Admin API: true|false",
|
2020-12-24 08:02:30 +00:00
|
|
|
defaultValue: false
|
|
|
|
name: "rpc-admin" }: bool
|
|
|
|
|
|
|
|
rpcPrivate* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Enable access to JSON-RPC Private API: true|false",
|
2020-12-24 08:02:30 +00:00
|
|
|
defaultValue: false
|
|
|
|
name: "rpc-private" }: bool
|
2022-06-28 10:22:59 +00:00
|
|
|
|
|
|
|
## REST HTTP config
|
|
|
|
|
|
|
|
rest* {.
|
|
|
|
desc: "Enable Waku REST HTTP server: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "rest" }: bool
|
|
|
|
|
|
|
|
restAddress* {.
|
|
|
|
desc: "Listening address of the REST HTTP server.",
|
|
|
|
defaultValue: ValidIpAddress.init("127.0.0.1")
|
|
|
|
name: "rest-address" }: ValidIpAddress
|
|
|
|
|
|
|
|
restPort* {.
|
|
|
|
desc: "Listening port of the REST HTTP server.",
|
|
|
|
defaultValue: 8645
|
|
|
|
name: "rest-port" }: uint16
|
|
|
|
|
2022-08-30 13:57:45 +00:00
|
|
|
restRelayCacheCapacity* {.
|
2022-06-28 10:22:59 +00:00
|
|
|
desc: "Capacity of the Relay REST API message cache.",
|
|
|
|
defaultValue: 30
|
|
|
|
name: "rest-relay-cache-capacity" }: uint32
|
|
|
|
|
|
|
|
restAdmin* {.
|
|
|
|
desc: "Enable access to REST HTTP Admin API: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "rest-admin" }: bool
|
|
|
|
|
|
|
|
restPrivate* {.
|
|
|
|
desc: "Enable access to REST HTTP Private API: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "rest-private" }: bool
|
2021-05-11 15:07:26 +00:00
|
|
|
|
|
|
|
## Metrics config
|
2020-04-29 04:49:27 +00:00
|
|
|
|
|
|
|
metricsServer* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Enable the metrics server: true|false"
|
2020-04-29 04:49:27 +00:00
|
|
|
defaultValue: false
|
|
|
|
name: "metrics-server" }: bool
|
|
|
|
|
|
|
|
metricsServerAddress* {.
|
|
|
|
desc: "Listening address of the metrics server."
|
2020-07-24 01:39:58 +00:00
|
|
|
defaultValue: ValidIpAddress.init("127.0.0.1")
|
|
|
|
name: "metrics-server-address" }: ValidIpAddress
|
2020-04-29 04:49:27 +00:00
|
|
|
|
|
|
|
metricsServerPort* {.
|
|
|
|
desc: "Listening HTTP port of the metrics server."
|
|
|
|
defaultValue: 8008
|
|
|
|
name: "metrics-server-port" }: uint16
|
|
|
|
|
2021-05-11 15:07:26 +00:00
|
|
|
metricsLogging* {.
|
|
|
|
desc: "Enable metrics logging: true|false"
|
2022-08-31 09:53:28 +00:00
|
|
|
defaultValue: true
|
2021-05-11 15:07:26 +00:00
|
|
|
name: "metrics-logging" }: bool
|
2021-08-12 08:51:38 +00:00
|
|
|
|
|
|
|
## DNS discovery config
|
|
|
|
|
|
|
|
dnsDiscovery* {.
|
|
|
|
desc: "Enable discovering nodes via DNS"
|
|
|
|
defaultValue: false
|
|
|
|
name: "dns-discovery" }: bool
|
|
|
|
|
|
|
|
dnsDiscoveryUrl* {.
|
|
|
|
desc: "URL for DNS node list in format 'enrtree://<key>@<fqdn>'",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "dns-discovery-url" }: string
|
2021-08-25 11:57:35 +00:00
|
|
|
|
|
|
|
dnsDiscoveryNameServers* {.
|
|
|
|
desc: "DNS name server IPs to query. Argument may be repeated."
|
|
|
|
defaultValue: @[ValidIpAddress.init("1.1.1.1"), ValidIpAddress.init("1.0.0.1")]
|
|
|
|
name: "dns-discovery-name-server" }: seq[ValidIpAddress]
|
2021-11-01 18:02:39 +00:00
|
|
|
|
|
|
|
## Discovery v5 config
|
|
|
|
|
|
|
|
discv5Discovery* {.
|
|
|
|
desc: "Enable discovering nodes via Node Discovery v5"
|
|
|
|
defaultValue: false
|
|
|
|
name: "discv5-discovery" }: bool
|
|
|
|
|
|
|
|
discv5UdpPort* {.
|
|
|
|
desc: "Listening UDP port for Node Discovery v5."
|
|
|
|
defaultValue: 9000
|
|
|
|
name: "discv5-udp-port" }: Port
|
|
|
|
|
|
|
|
discv5BootstrapNodes* {.
|
|
|
|
desc: "Text-encoded ENR for bootstrap node. Used when connecting to the network. Argument may be repeated."
|
|
|
|
name: "discv5-bootstrap-node" }: seq[string]
|
|
|
|
|
|
|
|
discv5EnrAutoUpdate* {.
|
|
|
|
desc: "Discovery can automatically update its ENR with the IP address " &
|
|
|
|
"and UDP port as seen by other nodes it communicates with. " &
|
|
|
|
"This option allows to enable/disable this functionality"
|
|
|
|
defaultValue: false
|
|
|
|
name: "discv5-enr-auto-update" .}: bool
|
2021-05-11 15:07:26 +00:00
|
|
|
|
2022-03-01 14:11:56 +00:00
|
|
|
discv5TableIpLimit* {.
|
|
|
|
hidden
|
|
|
|
desc: "Maximum amount of nodes with the same IP in discv5 routing tables"
|
|
|
|
defaultValue: 10
|
|
|
|
name: "discv5-table-ip-limit" .}: uint
|
|
|
|
|
|
|
|
discv5BucketIpLimit* {.
|
|
|
|
hidden
|
|
|
|
desc: "Maximum amount of nodes with the same IP in discv5 routing table buckets"
|
|
|
|
defaultValue: 2
|
|
|
|
name: "discv5-bucket-ip-limit" .}: uint
|
|
|
|
|
|
|
|
discv5BitsPerHop* {.
|
|
|
|
hidden
|
|
|
|
desc: "Kademlia's b variable, increase for less hops per lookup"
|
|
|
|
defaultValue: 1
|
|
|
|
name: "discv5-bits-per-hop" .}: int
|
|
|
|
|
2022-09-20 11:03:34 +00:00
|
|
|
## waku peer exchange config
|
|
|
|
peerExchange* {.
|
|
|
|
desc: "Enable waku peer exchange protocol (responder side): true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "peer-exchange" }: bool
|
|
|
|
|
|
|
|
peerExchangeNode* {.
|
|
|
|
desc: "Peer multiaddr to send peer exchange requests to. (enables peer exchange protocol requester side)",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "peer-exchange-node" }: string
|
|
|
|
|
2021-11-02 10:29:11 +00:00
|
|
|
## websocket config
|
|
|
|
websocketSupport* {.
|
|
|
|
desc: "Enable websocket: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "websocket-support"}: bool
|
|
|
|
|
|
|
|
websocketPort* {.
|
|
|
|
desc: "WebSocket listening port."
|
|
|
|
defaultValue: 8000
|
|
|
|
name: "websocket-port" }: Port
|
2021-11-10 12:05:36 +00:00
|
|
|
|
|
|
|
websocketSecureSupport* {.
|
|
|
|
desc: "Enable secure websocket: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "websocket-secure-support"}: bool
|
|
|
|
|
|
|
|
websocketSecureKeyPath* {.
|
|
|
|
desc: "Secure websocket key path: '/path/to/key.txt' ",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "websocket-secure-key-path"}: string
|
|
|
|
|
|
|
|
websocketSecureCertPath* {.
|
|
|
|
desc: "Secure websocket Certificate path: '/path/to/cert.txt' ",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "websocket-secure-cert-path"}: string
|
2021-11-02 10:29:11 +00:00
|
|
|
|
2020-05-21 04:16:00 +00:00
|
|
|
# NOTE: Keys are different in nim-libp2p
|
2020-07-20 04:40:35 +00:00
|
|
|
proc parseCmdArg*(T: type crypto.PrivateKey, p: TaintedString): T =
|
2020-04-29 04:49:27 +00:00
|
|
|
try:
|
2020-05-26 03:55:53 +00:00
|
|
|
let key = SkPrivateKey.init(utils.fromHex(p)).tryGet()
|
|
|
|
# XXX: Here at the moment
|
2020-07-20 04:40:35 +00:00
|
|
|
result = crypto.PrivateKey(scheme: Secp256k1, skkey: key)
|
2020-04-29 04:49:27 +00:00
|
|
|
except CatchableError as e:
|
|
|
|
raise newException(ConfigurationError, "Invalid private key")
|
|
|
|
|
2020-07-20 04:40:35 +00:00
|
|
|
proc completeCmdArg*(T: type crypto.PrivateKey, val: TaintedString): seq[string] =
|
2020-04-29 04:49:27 +00:00
|
|
|
return @[]
|
|
|
|
|
2020-07-24 01:39:58 +00:00
|
|
|
proc parseCmdArg*(T: type ValidIpAddress, p: TaintedString): T =
|
2020-04-29 04:49:27 +00:00
|
|
|
try:
|
2020-07-24 01:39:58 +00:00
|
|
|
result = ValidIpAddress.init(p)
|
2020-04-29 04:49:27 +00:00
|
|
|
except CatchableError as e:
|
|
|
|
raise newException(ConfigurationError, "Invalid IP address")
|
|
|
|
|
2020-07-24 01:39:58 +00:00
|
|
|
proc completeCmdArg*(T: type ValidIpAddress, val: TaintedString): seq[string] =
|
2020-04-29 04:49:27 +00:00
|
|
|
return @[]
|
2020-07-24 01:39:58 +00:00
|
|
|
|
|
|
|
proc parseCmdArg*(T: type Port, p: TaintedString): T =
|
|
|
|
try:
|
|
|
|
result = Port(parseInt(p))
|
|
|
|
except CatchableError as e:
|
|
|
|
raise newException(ConfigurationError, "Invalid Port number")
|
|
|
|
|
|
|
|
proc completeCmdArg*(T: type Port, val: TaintedString): seq[string] =
|
|
|
|
return @[]
|
|
|
|
|
2022-10-18 12:06:54 +00:00
|
|
|
proc defaultListenAddress*(): ValidIpAddress =
|
2020-07-24 01:39:58 +00:00
|
|
|
# TODO: How should we select between IPv4 and IPv6
|
|
|
|
# Maybe there should be a config option for this.
|
2022-03-01 14:11:56 +00:00
|
|
|
(static ValidIpAddress.init("0.0.0.0"))
|
2022-05-17 15:48:08 +00:00
|
|
|
|
2022-10-18 12:06:54 +00:00
|
|
|
proc defaultPrivateKey*(): PrivateKey =
|
|
|
|
crypto.PrivateKey.random(Secp256k1, crypto.newRng()[]).value
|
2022-05-17 15:48:08 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-10-26 15:10:30 +00:00
|
|
|
|
|
|
|
## Configuration validation
|
|
|
|
|
|
|
|
let DbUrlRegex = re"^[\w\+]+:\/\/[\w\/\\\.\:\@]+$"
|
|
|
|
|
|
|
|
proc validateDbUrl*(val: string): ConfResult[string] =
|
|
|
|
let val = val.strip()
|
|
|
|
|
|
|
|
if val == "" or val.match(DbUrlRegex).isSome():
|
|
|
|
return ok(val)
|
|
|
|
else:
|
|
|
|
return err("invalid 'db url' option format: " & val)
|
|
|
|
|
|
|
|
|
|
|
|
let StoreMessageRetentionPolicyRegex = re"^\w+:\w$"
|
|
|
|
|
|
|
|
proc validateStoreMessageRetentionPolicy*(val: string): ConfResult[string] =
|
|
|
|
let val = val.strip()
|
|
|
|
|
|
|
|
if val == "" or val.match(StoreMessageRetentionPolicyRegex).isSome():
|
|
|
|
return ok(val)
|
|
|
|
else:
|
|
|
|
return err("invalid 'store message retention policy' option format: " & val)
|