mirror of https://github.com/waku-org/nwaku.git
parent
9fc3e11f3b
commit
928280bc4f
|
@ -8,135 +8,145 @@ type
|
|||
staging
|
||||
test
|
||||
|
||||
WakuNodeCmd* = enum
|
||||
noCommand
|
||||
genNodekey
|
||||
|
||||
WakuNodeConf* = object
|
||||
logLevel* {.
|
||||
desc: "Sets the log level."
|
||||
defaultValue: LogLevel.INFO
|
||||
name: "log-level" }: LogLevel
|
||||
name: "log-level" .}: LogLevel
|
||||
|
||||
tcpPort* {.
|
||||
desc: "TCP listening port."
|
||||
defaultValue: 30303
|
||||
name: "tcp-port" }: uint16
|
||||
case cmd* {.
|
||||
command
|
||||
defaultValue: noCommand .}: WakuNodeCmd
|
||||
|
||||
udpPort* {.
|
||||
desc: "UDP listening port."
|
||||
defaultValue: 30303
|
||||
name: "udp-port" }: uint16
|
||||
of noCommand:
|
||||
tcpPort* {.
|
||||
desc: "TCP listening port."
|
||||
defaultValue: 30303
|
||||
name: "tcp-port" .}: uint16
|
||||
|
||||
portsShift* {.
|
||||
desc: "Add a shift to all port numbers."
|
||||
defaultValue: 0
|
||||
name: "ports-shift" }: uint16
|
||||
udpPort* {.
|
||||
desc: "UDP listening port."
|
||||
defaultValue: 30303
|
||||
name: "udp-port" .}: uint16
|
||||
|
||||
nat* {.
|
||||
desc: "Specify method to use for determining public address. " &
|
||||
"Must be one of: any, none, upnp, pmp, extip:<IP>."
|
||||
defaultValue: "any" }: string
|
||||
portsShift* {.
|
||||
desc: "Add a shift to all port numbers."
|
||||
defaultValue: 0
|
||||
name: "ports-shift" .}: uint16
|
||||
|
||||
discovery* {.
|
||||
desc: "Enable/disable discovery v4."
|
||||
defaultValue: true
|
||||
name: "discovery" }: bool
|
||||
nat* {.
|
||||
desc: "Specify method to use for determining public address. " &
|
||||
"Must be one of: any, none, upnp, pmp, extip:<IP>."
|
||||
defaultValue: "any" .}: string
|
||||
|
||||
noListen* {.
|
||||
desc: "Disable listening for incoming peers."
|
||||
defaultValue: false
|
||||
name: "no-listen" }: bool
|
||||
discovery* {.
|
||||
desc: "Enable/disable discovery v4."
|
||||
defaultValue: true
|
||||
name: "discovery" .}: bool
|
||||
|
||||
fleet* {.
|
||||
desc: "Select the fleet to connect to."
|
||||
defaultValue: Fleet.none
|
||||
name: "fleet" }: Fleet
|
||||
noListen* {.
|
||||
desc: "Disable listening for incoming peers."
|
||||
defaultValue: false
|
||||
name: "no-listen" .}: bool
|
||||
|
||||
bootnodes* {.
|
||||
desc: "Enode URL to bootstrap P2P discovery with. Argument may be repeated."
|
||||
name: "bootnode" }: seq[string]
|
||||
fleet* {.
|
||||
desc: "Select the fleet to connect to."
|
||||
defaultValue: Fleet.none
|
||||
name: "fleet" .}: Fleet
|
||||
|
||||
staticnodes* {.
|
||||
desc: "Enode URL to directly connect with. Argument may be repeated."
|
||||
name: "staticnode" }: seq[string]
|
||||
bootnodes* {.
|
||||
desc: "Enode URL to bootstrap P2P discovery with. Argument may be repeated."
|
||||
name: "bootnode" .}: seq[string]
|
||||
|
||||
whisper* {.
|
||||
desc: "Enable the Whisper protocol."
|
||||
defaultValue: false
|
||||
name: "whisper" }: bool
|
||||
staticnodes* {.
|
||||
desc: "Enode URL to directly connect with. Argument may be repeated."
|
||||
name: "staticnode" .}: seq[string]
|
||||
|
||||
whisperBridge* {.
|
||||
desc: "Enable the Whisper protocol and bridge with Waku protocol."
|
||||
defaultValue: false
|
||||
name: "whisper-bridge" }: bool
|
||||
whisper* {.
|
||||
desc: "Enable the Whisper protocol."
|
||||
defaultValue: false
|
||||
name: "whisper" .}: bool
|
||||
|
||||
lightNode* {.
|
||||
desc: "Run as light node (no message relay).",
|
||||
defaultValue: false
|
||||
name: "light-node" }: bool
|
||||
whisperBridge* {.
|
||||
desc: "Enable the Whisper protocol and bridge with Waku protocol."
|
||||
defaultValue: false
|
||||
name: "whisper-bridge" .}: bool
|
||||
|
||||
wakuTopicInterest* {.
|
||||
desc: "Run as node with a topic-interest",
|
||||
defaultValue: false
|
||||
name: "waku-topic-interest" }: bool
|
||||
lightNode* {.
|
||||
desc: "Run as light node (no message relay).",
|
||||
defaultValue: false
|
||||
name: "light-node" .}: bool
|
||||
|
||||
wakuPow* {.
|
||||
desc: "PoW requirement of Waku node.",
|
||||
defaultValue: 0.002
|
||||
name: "waku-pow" }: float64
|
||||
wakuTopicInterest* {.
|
||||
desc: "Run as node with a topic-interest",
|
||||
defaultValue: false
|
||||
name: "waku-topic-interest" .}: bool
|
||||
|
||||
nodekey* {.
|
||||
desc: "P2P node private key as hex.",
|
||||
defaultValue: KeyPair.random().tryGet()
|
||||
name: "nodekey" }: KeyPair
|
||||
# TODO: Add nodekey file option
|
||||
wakuPow* {.
|
||||
desc: "PoW requirement of Waku node.",
|
||||
defaultValue: 0.002
|
||||
name: "waku-pow" .}: float64
|
||||
|
||||
bootnodeOnly* {.
|
||||
desc: "Run only as discovery bootnode."
|
||||
defaultValue: false
|
||||
name: "bootnode-only" }: bool
|
||||
nodekey* {.
|
||||
desc: "P2P node private key as hex.",
|
||||
defaultValue: KeyPair.random().tryGet()
|
||||
name: "nodekey" .}: KeyPair
|
||||
# TODO: Add nodekey file option
|
||||
|
||||
rpc* {.
|
||||
desc: "Enable Waku RPC server.",
|
||||
defaultValue: false
|
||||
name: "rpc" }: bool
|
||||
bootnodeOnly* {.
|
||||
desc: "Run only as discovery bootnode."
|
||||
defaultValue: false
|
||||
name: "bootnode-only" .}: bool
|
||||
|
||||
rpcAddress* {.
|
||||
desc: "Listening address of the RPC server.",
|
||||
defaultValue: parseIpAddress("127.0.0.1")
|
||||
name: "rpc-address" }: IpAddress
|
||||
rpc* {.
|
||||
desc: "Enable Waku RPC server.",
|
||||
defaultValue: false
|
||||
name: "rpc" .}: bool
|
||||
|
||||
rpcPort* {.
|
||||
desc: "Listening port of the RPC server.",
|
||||
defaultValue: 8545
|
||||
name: "rpc-port" }: uint16
|
||||
rpcAddress* {.
|
||||
desc: "Listening address of the RPC server.",
|
||||
defaultValue: parseIpAddress("127.0.0.1")
|
||||
name: "rpc-address" .}: IpAddress
|
||||
|
||||
metricsServer* {.
|
||||
desc: "Enable the metrics server."
|
||||
defaultValue: false
|
||||
name: "metrics-server" }: bool
|
||||
rpcPort* {.
|
||||
desc: "Listening port of the RPC server.",
|
||||
defaultValue: 8545
|
||||
name: "rpc-port" .}: uint16
|
||||
|
||||
metricsServerAddress* {.
|
||||
desc: "Listening address of the metrics server."
|
||||
defaultValue: parseIpAddress("127.0.0.1")
|
||||
name: "metrics-server-address" }: IpAddress
|
||||
metricsServer* {.
|
||||
desc: "Enable the metrics server."
|
||||
defaultValue: false
|
||||
name: "metrics-server" .}: bool
|
||||
|
||||
metricsServerPort* {.
|
||||
desc: "Listening HTTP port of the metrics server."
|
||||
defaultValue: 8008
|
||||
name: "metrics-server-port" }: uint16
|
||||
metricsServerAddress* {.
|
||||
desc: "Listening address of the metrics server."
|
||||
defaultValue: parseIpAddress("127.0.0.1")
|
||||
name: "metrics-server-address" .}: IpAddress
|
||||
|
||||
logMetrics* {.
|
||||
desc: "Enable metrics logging."
|
||||
defaultValue: false
|
||||
name: "log-metrics" }: bool
|
||||
metricsServerPort* {.
|
||||
desc: "Listening HTTP port of the metrics server."
|
||||
defaultValue: 8008
|
||||
name: "metrics-server-port" .}: uint16
|
||||
|
||||
# TODO:
|
||||
# - discv5 + topic register
|
||||
# - mailserver functionality
|
||||
logMetrics* {.
|
||||
desc: "Enable metrics logging."
|
||||
defaultValue: false
|
||||
name: "log-metrics" .}: bool
|
||||
|
||||
# TODO:
|
||||
# - discv5 + topic register
|
||||
# - mailserver functionality
|
||||
of genNodekey:
|
||||
discard
|
||||
|
||||
proc parseCmdArg*(T: type KeyPair, p: TaintedString): T =
|
||||
try:
|
||||
# TODO: add isValidPrivateKey check from Nimbus?
|
||||
result.seckey = PrivateKey.fromHex(string(p)).tryGet()
|
||||
result.pubkey = result.seckey.toPublicKey()[]
|
||||
let privkey = PrivateKey.fromHex(string(p)).tryGet()
|
||||
result = privkey.toKeyPair.expect("a valid private key after check above")
|
||||
except CatchableError as e:
|
||||
raise newException(ConfigurationError, "Invalid private key")
|
||||
|
||||
|
|
|
@ -62,9 +62,6 @@ proc setupNat(conf: WakuNodeConf): tuple[ip: IpAddress,
|
|||
(result.tcpPort, result.udpPort) = extPorts.get()
|
||||
|
||||
proc run(config: WakuNodeConf) =
|
||||
if config.logLevel != LogLevel.NONE:
|
||||
setLogLevel(config.logLevel)
|
||||
|
||||
let
|
||||
(ip, tcpPort, udpPort) = setupNat(config)
|
||||
address = Address(ip: ip, tcpPort: tcpPort, udpPort: udpPort)
|
||||
|
@ -150,4 +147,12 @@ proc run(config: WakuNodeConf) =
|
|||
|
||||
when isMainModule:
|
||||
let conf = WakuNodeConf.load()
|
||||
run(conf)
|
||||
|
||||
if conf.logLevel != LogLevel.NONE:
|
||||
setLogLevel(conf.logLevel)
|
||||
|
||||
case conf.cmd
|
||||
of genNodekey:
|
||||
echo PrivateKey.random().expect("Enough randomness to generate a key")
|
||||
of noCommand:
|
||||
run(conf)
|
||||
|
|
Loading…
Reference in New Issue