Add ports-shift convenience option

This commit is contained in:
kdeme 2019-12-16 16:35:03 +01:00 committed by zah
parent c3aeb15ce5
commit 7a7075eea6
2 changed files with 37 additions and 20 deletions

View File

@ -22,7 +22,12 @@ type
udpPort* {. udpPort* {.
desc: "UDP listening port." desc: "UDP listening port."
defaultValue: 30303 defaultValue: 30303
name: "udp-port" }: int name: "udp-port" }: uint16
portsShift* {.
desc: "Add a shift to all port numbers."
defaultValue: 0
name: "ports-shift" }: uint16
discovery* {. discovery* {.
desc: "Enable/disable discovery v4." desc: "Enable/disable discovery v4."
@ -40,11 +45,11 @@ type
name: "fleet" }: Fleet name: "fleet" }: Fleet
bootnodes* {. bootnodes* {.
desc: "Comma separated enode URLs for P2P discovery bootstrap" desc: "Comma separated enode URLs for P2P discovery bootstrap."
name: "bootnodes" }: seq[string] name: "bootnodes" }: seq[string]
staticnodes* {. staticnodes* {.
desc: "Comma separated enode URLs to directly connect with" desc: "Comma separated enode URLs to directly connect with."
name: "staticnodes" }: seq[string] name: "staticnodes" }: seq[string]
whisper* {. whisper* {.
@ -53,38 +58,43 @@ type
name: "whisper" }: bool name: "whisper" }: bool
whisperBridge* {. whisperBridge* {.
desc: "Enable the Whisper protocol and bridge with Waku protocol" desc: "Enable the Whisper protocol and bridge with Waku protocol."
defaultValue: false defaultValue: false
name: "whisper-bridge" }: bool name: "whisper-bridge" }: bool
nodekey* {. nodekey* {.
desc: "P2P node private key as hex", desc: "P2P node private key as hex.",
defaultValue: newKeyPair() defaultValue: newKeyPair()
name: "nodekey" }: KeyPair name: "nodekey" }: KeyPair
# TODO: Add nodekey file option # TODO: Add nodekey file option
bootnodeOnly* {. bootnodeOnly* {.
desc: "Run only as bootnode" desc: "Run only as discovery bootnode."
defaultValue: false defaultValue: false
name: "bootnode-only" }: bool name: "bootnode-only" }: bool
rpc* {. rpc* {.
desc: "Enable Waku RPC server", desc: "Enable Waku RPC server.",
defaultValue: false defaultValue: false
name: "rpc" }: bool name: "rpc" }: bool
# TODO: get this validated and/or switch to TransportAddress rpcAddress* {.
rpcBinds* {. desc: "Listening address of the RPC server.",
desc: "Enable Waku RPC server", defaultValue: parseIpAddress("127.0.0.1")
name: "rpc-binds" }: seq[string] name: "rpc-address" }: IpAddress
rpcPort* {.
desc: "Listening port of the RPC server.",
defaultValue: 8545
name: "rpc-port" }: uint16
wakuMode* {. wakuMode* {.
desc: "Select the Waku mode", desc: "Select the Waku mode.",
defaultValue: WakuSan defaultValue: WakuSan
name: "waku-mode" }: WakuMode name: "waku-mode" }: WakuMode
wakuPow* {. wakuPow* {.
desc: "PoW requirement of Waku node", desc: "PoW requirement of Waku node.",
defaultValue: 0.002 defaultValue: 0.002
name: "waku-pow" }: float64 name: "waku-pow" }: float64
@ -104,3 +114,12 @@ proc parseCmdArg*(T: type KeyPair, p: TaintedString): T =
proc completeCmdArg*(T: type KeyPair, val: TaintedString): seq[string] = proc completeCmdArg*(T: type KeyPair, val: TaintedString): seq[string] =
return @[] return @[]
proc parseCmdArg*(T: type IpAddress, p: TaintedString): T =
try:
result = parseIpAddress(p)
except CatchableError as e:
raise newException(ConfigurationError, "Invalid IP address")
proc completeCmdArg*(T: type IpAddress, val: TaintedString): seq[string] =
return @[]

View File

@ -29,8 +29,8 @@ proc run(config: WakuNodeConf) =
var address: Address var address: Address
# TODO: make configurable # TODO: make configurable
address.ip = parseIpAddress("0.0.0.0") address.ip = parseIpAddress("0.0.0.0")
address.tcpPort = Port(config.tcpPort) address.tcpPort = Port(config.tcpPort + config.portsShift)
address.udpPort = Port(config.udpPort) address.udpPort = Port(config.udpPort + config.portsShift)
# Set-up node # Set-up node
var node = newEthereumNode(config.nodekey, address, 1, nil, var node = newEthereumNode(config.nodekey, address, 1, nil,
@ -66,11 +66,9 @@ proc run(config: WakuNodeConf) =
elif config.fleet == staging: connectToNodes(node, WhisperNodesStaging) elif config.fleet == staging: connectToNodes(node, WhisperNodesStaging)
if config.rpc: if config.rpc:
var rpcServer: RpcHttpServer let ta = initTAddress(config.rpcAddress,
if config.rpcBinds.len == 0: Port(config.rpcPort + config.portsShift))
rpcServer = newRpcHttpServer(["localhost:8545"]) var rpcServer = newRpcHttpServer([ta])
else:
rpcServer = newRpcHttpServer(config.rpcBinds)
let keys = newWakuKeys() let keys = newWakuKeys()
setupWakuRPC(node, keys, rpcServer) setupWakuRPC(node, keys, rpcServer)
rpcServer.start() rpcServer.start()