From 291fddee716584328daa91716f4e8aa19894801b Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Tue, 25 Sep 2018 16:30:44 +0300 Subject: [PATCH] Better cmdline flags handling --- nimbus/config.nim | 18 ++++++++++++------ nimbus/nimbus.nim | 3 ++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/nimbus/config.nim b/nimbus/config.nim index d8eeb1d38..f9ea4527d 100644 --- a/nimbus/config.nim +++ b/nimbus/config.nim @@ -367,7 +367,7 @@ proc processNetArguments(key, value: string): ConfigStatus = let config = getConfiguration() let skey = key.toLowerAscii() if skey == "bootnodes": - result = processENodesList(value, config.net.bootnodes) + result = processENodesList(value, config.net.bootNodes) elif skey == "bootnodesv4": result = processENodesList(value, config.net.bootNodes) elif skey == "bootnodesv5": @@ -511,7 +511,7 @@ NETWORKING OPTIONS: --bootnodesv4: Comma separated enode URLs for P2P v4 discovery bootstrap (light server, full nodes) --bootnodesv5: Comma separated enode URLs for P2P v5 discovery bootstrap (light server, light nodes) --port: Network listening TCP port (default: 30303) - --discport: Network listening UDP port (default: 30303) + --discport: Network listening UDP port (defaults to --port argument) --maxpeers: Maximum number of network peers (default: 25) --maxpendpeers: Maximum number of pending connection attempts (default: 0) --nodiscover Disables the peer discovery mechanism (manual peer addition) @@ -538,7 +538,11 @@ LOGGING AND DEBUGGING OPTIONS: proc processArguments*(msg: var string): ConfigStatus = ## Process command line argument and update `NimbusConfiguration`. - discard getConfiguration() + let config = getConfiguration() + var tempBootNodes: seq[ENode] + swap(tempBootNodes, config.net.bootNodes) + config.net.discPort = 0 + var opt = initOptParser() var length = 0 for kind, key, value in opt.getopt(): @@ -566,9 +570,11 @@ proc processArguments*(msg: var string): ConfigStatus = result = ErrorParseOption break - if length == 0 and result == Success: - # msg = getHelpString() - result = Success + if config.net.bootNodes.len == 0: + swap(tempBootNodes, config.net.bootNodes) + + if config.net.discPort == 0: + config.net.discPort = config.net.bindPort proc processConfig*(pathname: string): ConfigStatus = ## Process configuration file `pathname` and update `NimbusConfiguration`. diff --git a/nimbus/nimbus.nim b/nimbus/nimbus.nim index b39511b3d..2f987c976 100644 --- a/nimbus/nimbus.nim +++ b/nimbus/nimbus.nim @@ -95,7 +95,8 @@ proc start(): NimbusObject = result = "EXITING" nimbus.rpcServer.start() - waitFor nimbus.ethNode.connectToNetwork(conf.net.bootNodes) + waitFor nimbus.ethNode.connectToNetwork(conf.net.bootNodes, + enableDiscovery = NoDiscover notin conf.net.flags) # TODO: temp code until the CLI/RPC interface is fleshed out let status = waitFor nimbus.ethNode.fastBlockchainSync()