2020-04-29 04:49:27 +00:00
|
|
|
import
|
2020-08-31 03:32:41 +00:00
|
|
|
std/strutils,
|
2020-07-24 01:39:58 +00:00
|
|
|
confutils, confutils/defs, confutils/std/net,
|
|
|
|
chronicles, chronos,
|
2020-05-21 04:16:00 +00:00
|
|
|
libp2p/crypto/crypto,
|
|
|
|
libp2p/crypto/secp,
|
2020-07-20 04:40:35 +00:00
|
|
|
nimcrypto/utils,
|
|
|
|
eth/keys
|
2020-04-29 04:49:27 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
WakuNodeConf* = object
|
|
|
|
logLevel* {.
|
|
|
|
desc: "Sets the log level."
|
|
|
|
defaultValue: LogLevel.INFO
|
|
|
|
name: "log-level" }: LogLevel
|
|
|
|
|
2020-10-22 15:04:17 +00:00
|
|
|
listenAddress* {.
|
2020-07-24 01:39:58 +00:00
|
|
|
defaultValue: defaultListenAddress(config)
|
|
|
|
desc: "Listening address for the LibP2P traffic."
|
|
|
|
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
|
2020-04-29 04:49:27 +00:00
|
|
|
|
|
|
|
udpPort* {.
|
|
|
|
desc: "UDP listening port."
|
2020-05-28 03:28:44 +00:00
|
|
|
defaultValue: 60000
|
2020-07-24 01:39:58 +00:00
|
|
|
name: "udp-port" }: Port
|
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
|
|
|
|
|
|
|
|
staticnodes* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Peer multiaddr to directly connect with. Argument may be repeated."
|
2020-04-29 04:49:27 +00:00
|
|
|
name: "staticnode" }: seq[string]
|
|
|
|
|
2020-09-25 11:35:32 +00:00
|
|
|
storenode* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Peer multiaddr to query for storage.",
|
2020-09-25 11:35:32 +00:00
|
|
|
defaultValue: ""
|
|
|
|
name: "storenode" }: string
|
|
|
|
|
2020-10-20 02:36:27 +00:00
|
|
|
store* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Enable store protocol: true|false",
|
2020-10-20 02:36:27 +00:00
|
|
|
defaultValue: false
|
|
|
|
name: "store" }: bool
|
|
|
|
|
|
|
|
filter* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Enable filter protocol: true|false",
|
2020-10-20 02:36:27 +00:00
|
|
|
defaultValue: false
|
|
|
|
name: "filter" }: bool
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
rlnrelay* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Enable spam protection through rln-relay: true|false",
|
2021-01-08 17:56:58 +00:00
|
|
|
defaultValue: false
|
|
|
|
name: "rlnrelay" }: bool
|
2020-10-20 02:36:27 +00:00
|
|
|
|
2020-11-21 05:31:48 +00:00
|
|
|
swap* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Enable swap protocol: true|false",
|
2020-11-21 05:31:48 +00:00
|
|
|
defaultValue: false
|
|
|
|
name: "swap" }: bool
|
|
|
|
|
2020-10-09 13:58:50 +00:00
|
|
|
filternode* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Peer multiaddr to request content filtering of messages.",
|
2020-10-09 13:58:50 +00:00
|
|
|
defaultValue: ""
|
|
|
|
name: "filternode" }: string
|
2020-11-16 08:38:52 +00:00
|
|
|
|
|
|
|
dbpath* {.
|
|
|
|
desc: "The database path for the store protocol.",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "dbpath" }: string
|
2020-10-09 13:58:50 +00:00
|
|
|
|
2020-10-22 15:04:17 +00:00
|
|
|
topics* {.
|
2020-10-28 05:19:07 +00:00
|
|
|
desc: "Default topics to subscribe to (space separated list)."
|
|
|
|
defaultValue: "/waku/2/default-waku/proto"
|
2020-10-22 15:04:17 +00:00
|
|
|
name: "topics" .}: string
|
2020-04-29 04:49:27 +00:00
|
|
|
|
2020-05-21 04:16:00 +00:00
|
|
|
# NOTE: Signature is different here, we return PrivateKey and not KeyPair
|
2020-04-29 04:49:27 +00:00
|
|
|
nodekey* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "P2P node private key as 64 char hex string.",
|
2020-07-20 04:40:35 +00:00
|
|
|
defaultValue: crypto.PrivateKey.random(Secp256k1, keys.newRng()[]).tryGet()
|
|
|
|
name: "nodekey" }: crypto.PrivateKey
|
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
|
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
|
|
|
|
|
|
|
|
logMetrics* {.
|
2021-03-10 07:03:22 +00:00
|
|
|
desc: "Enable metrics logging: true|false"
|
2020-04-29 04:49:27 +00:00
|
|
|
defaultValue: false
|
|
|
|
name: "log-metrics" }: bool
|
|
|
|
|
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 @[]
|
|
|
|
|
|
|
|
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"))
|