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
|
|
|
|
Fleet* = enum
|
|
|
|
none
|
|
|
|
prod
|
|
|
|
staging
|
|
|
|
test
|
|
|
|
|
|
|
|
WakuNodeConf* = object
|
|
|
|
logLevel* {.
|
|
|
|
desc: "Sets the log level."
|
|
|
|
defaultValue: LogLevel.INFO
|
|
|
|
name: "log-level" }: LogLevel
|
|
|
|
|
2020-07-24 01:39:58 +00:00
|
|
|
libp2pAddress* {.
|
|
|
|
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
|
|
|
|
|
|
|
|
discovery* {.
|
|
|
|
desc: "Enable/disable discovery v4."
|
|
|
|
defaultValue: true
|
|
|
|
name: "discovery" }: bool
|
|
|
|
|
|
|
|
noListen* {.
|
|
|
|
desc: "Disable listening for incoming peers."
|
|
|
|
defaultValue: false
|
|
|
|
name: "no-listen" }: bool
|
|
|
|
|
|
|
|
fleet* {.
|
|
|
|
desc: "Select the fleet to connect to."
|
|
|
|
defaultValue: Fleet.none
|
|
|
|
name: "fleet" }: Fleet
|
|
|
|
|
|
|
|
bootnodes* {.
|
|
|
|
desc: "Enode URL to bootstrap P2P discovery with. Argument may be repeated."
|
|
|
|
name: "bootnode" }: seq[string]
|
|
|
|
|
|
|
|
staticnodes* {.
|
|
|
|
desc: "Enode URL to directly connect with. Argument may be repeated."
|
|
|
|
name: "staticnode" }: seq[string]
|
|
|
|
|
2020-09-25 11:35:32 +00:00
|
|
|
storenode* {.
|
|
|
|
desc: "Enode URL to query for storage.",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "storenode" }: string
|
|
|
|
|
2020-10-20 02:36:27 +00:00
|
|
|
store* {.
|
|
|
|
desc: "Flag whether to start store protocol",
|
|
|
|
defaultValue: false
|
|
|
|
name: "store" }: bool
|
|
|
|
|
|
|
|
filter* {.
|
|
|
|
desc: "Flag whether to start filter protocol",
|
|
|
|
defaultValue: false
|
|
|
|
name: "filter" }: bool
|
|
|
|
|
|
|
|
relay* {.
|
|
|
|
desc: "Flag whether to start relay protocol",
|
|
|
|
defaultValue: true
|
|
|
|
name: "relay" }: bool
|
|
|
|
|
2020-10-09 13:58:50 +00:00
|
|
|
filternode* {.
|
|
|
|
desc: "Enode URL to filter.",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "filternode" }: string
|
|
|
|
|
2020-04-29 04:49:27 +00:00
|
|
|
whisper* {.
|
|
|
|
desc: "Enable the Whisper protocol."
|
|
|
|
defaultValue: false
|
|
|
|
name: "whisper" }: bool
|
|
|
|
|
|
|
|
whisperBridge* {.
|
|
|
|
desc: "Enable the Whisper protocol and bridge with Waku protocol."
|
|
|
|
defaultValue: false
|
|
|
|
name: "whisper-bridge" }: bool
|
|
|
|
|
|
|
|
lightNode* {.
|
|
|
|
desc: "Run as light node (no message relay).",
|
|
|
|
defaultValue: false
|
|
|
|
name: "light-node" }: bool
|
|
|
|
|
|
|
|
wakuTopicInterest* {.
|
|
|
|
desc: "Run as node with a topic-interest",
|
|
|
|
defaultValue: false
|
|
|
|
name: "waku-topic-interest" }: bool
|
|
|
|
|
|
|
|
wakuPow* {.
|
|
|
|
desc: "PoW requirement of Waku node.",
|
|
|
|
defaultValue: 0.002
|
|
|
|
name: "waku-pow" }: float64
|
|
|
|
|
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* {.
|
|
|
|
desc: "P2P node private key as hex.",
|
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
|
|
|
# TODO: Add nodekey file option
|
|
|
|
|
|
|
|
bootnodeOnly* {.
|
|
|
|
desc: "Run only as discovery bootnode."
|
|
|
|
defaultValue: false
|
|
|
|
name: "bootnode-only" }: bool
|
|
|
|
|
|
|
|
rpc* {.
|
|
|
|
desc: "Enable Waku RPC server.",
|
2020-04-29 05:19:48 +00:00
|
|
|
defaultValue: true
|
2020-04-29 04:49:27 +00:00
|
|
|
name: "rpc" }: bool
|
|
|
|
|
|
|
|
rpcAddress* {.
|
|
|
|
desc: "Listening address of the 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* {.
|
|
|
|
desc: "Listening port of the RPC server.",
|
|
|
|
defaultValue: 8545
|
|
|
|
name: "rpc-port" }: uint16
|
|
|
|
|
|
|
|
metricsServer* {.
|
|
|
|
desc: "Enable the metrics server."
|
|
|
|
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* {.
|
|
|
|
desc: "Enable metrics logging."
|
|
|
|
defaultValue: false
|
|
|
|
name: "log-metrics" }: bool
|
2020-09-11 11:28:27 +00:00
|
|
|
|
|
|
|
topics* {.
|
|
|
|
desc: "Default topics to subscribe to (space seperated list)."
|
|
|
|
defaultValue: "waku"
|
|
|
|
name: "topics" .}: string
|
2020-04-29 04:49:27 +00:00
|
|
|
|
|
|
|
# TODO:
|
|
|
|
# - discv5 + topic register
|
|
|
|
# - mailserver functionality
|
|
|
|
|
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"))
|