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