Set config default descriptions (#852)

* Update fluffy config to set defaults descriptions

* Update portalcli config to set defaults descriptions
This commit is contained in:
Kim De Mey 2021-09-29 13:58:55 +02:00 committed by GitHub
parent 1d74ef4b98
commit b58920f29f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 20 deletions

View File

@ -13,12 +13,27 @@ import
eth/keys, eth/net/nat, eth/p2p/discoveryv5/[enr, node],
json_rpc/rpcproxy
proc defaultDataDir*(): string =
let dataDir = when defined(windows):
"AppData" / "Roaming" / "Fluffy"
elif defined(macosx):
"Library" / "Application Support" / "Fluffy"
else:
".cache" / "fluffy"
getHomeDir() / dataDir
const
DefaultListenAddress* = (static ValidIpAddress.init("0.0.0.0"))
DefaultAdminListenAddress* = (static ValidIpAddress.init("127.0.0.1"))
DefaultProxyAddress* = (static "http://127.0.0.1:8546")
DefaultClientConfig* = getHttpClientConfig(DefaultProxyAddress)
DefaultListenAddressDesc = $DefaultListenAddress
DefaultAdminListenAddressDesc = $DefaultAdminListenAddress
DefaultDataDirDesc = defaultDataDir()
DefaultClientConfigDesc = $(DefaultClientConfig.httpUri)
type
PortalCmd* = enum
noCommand
@ -26,6 +41,7 @@ type
PortalConf* = object
logLevel* {.
defaultValue: LogLevel.DEBUG
defaultValueDesc: $LogLevel.DEBUG
desc: "Sets the log level"
name: "log-level" .}: LogLevel
@ -36,6 +52,7 @@ type
listenAddress* {.
defaultValue: DefaultListenAddress
defaultValueDesc: $DefaultListenAddressDesc
desc: "Listening address for the Discovery v5 traffic"
name: "listen-address" }: ValidIpAddress
@ -47,6 +64,7 @@ type
desc: "Specify method to use for determining public address. " &
"Must be one of: any, none, upnp, pmp, extip:<IP>"
defaultValue: NatConfig(hasExtIp: false, nat: NatAny)
defaultValueDesc: "any"
name: "nat" .}: NatConfig
enrAutoUpdate* {.
@ -59,11 +77,13 @@ type
nodeKey* {.
desc: "P2P node private key as hex",
defaultValue: PrivateKey.random(keys.newRng()[])
defaultValueDesc: "random"
name: "nodekey" .}: PrivateKey
dataDir* {.
desc: "The directory where fluffy will store the content data"
defaultValue: config.defaultDataDir()
defaultValue: defaultDataDir()
defaultValueDesc: $DefaultDataDirDesc
name: "data-dir" }: OutDir
# Note: This will add bootstrap nodes for each enabled Portal network.
@ -79,6 +99,7 @@ type
metricsAddress* {.
defaultValue: DefaultAdminListenAddress
defaultValueDesc: $DefaultAdminListenAddressDesc
desc: "Listening address of the metrics server"
name: "metrics-address" .}: ValidIpAddress
@ -100,10 +121,12 @@ type
rpcAddress* {.
desc: "Listening address of the RPC server"
defaultValue: DefaultAdminListenAddress
defaultValueDesc: $DefaultAdminListenAddressDesc
name: "rpc-address" }: ValidIpAddress
bridgeUri* {.
defaultValue: none(string)
defaultValueDesc: ""
desc: "if provided, enables getting data from bridge node"
name: "bridge-client-uri" .}: Option[string]
@ -111,7 +134,8 @@ type
# it would be troublesome to add some fake uri param every time
proxyUri* {.
defaultValue: DefaultClientConfig
desc: "uri of client to get data for unimplemented rpc methods"
defaultValueDesc: $DefaultClientConfigDesc
desc: "URI of eth client where to proxy unimplemented rpc methods to"
name: "proxy-uri" .}: ClientConfig
case cmd* {.
@ -170,13 +194,3 @@ proc parseCmdArg*(T: type ClientConfig, p: TaintedString): T
proc completeCmdArg*(T: type ClientConfig, val: TaintedString): seq[string] =
return @[]
proc defaultDataDir*(config: PortalConf): string =
let dataDir = when defined(windows):
"AppData" / "Roaming" / "Fluffy"
elif defined(macosx):
"Library" / "Application Support" / "Fluffy"
else:
".cache" / "fluffy"
getHomeDir() / dataDir

View File

@ -16,6 +16,13 @@ import
../network/wire/[messages, portal_protocol],
../network/state/state_content
const
DefaultListenAddress* = (static ValidIpAddress.init("0.0.0.0"))
DefaultAdminListenAddress* = (static ValidIpAddress.init("127.0.0.1"))
DefaultListenAddressDesc = $DefaultListenAddress
DefaultAdminListenAddressDesc = $DefaultAdminListenAddress
type
PortalCmd* = enum
noCommand
@ -26,6 +33,7 @@ type
DiscoveryConf* = object
logLevel* {.
defaultValue: LogLevel.DEBUG
defaultValueDesc: $LogLevel.DEBUG
desc: "Sets the log level"
name: "log-level" .}: LogLevel
@ -35,7 +43,8 @@ type
name: "udp-port" .}: uint16
listenAddress* {.
defaultValue: defaultListenAddress(config)
defaultValue: DefaultListenAddress
defaultValueDesc: $DefaultListenAddressDesc
desc: "Listening address for the Discovery v5 traffic"
name: "listen-address" }: ValidIpAddress
@ -47,6 +56,7 @@ type
desc: "Specify method to use for determining public address. " &
"Must be one of: any, none, upnp, pmp, extip:<IP>"
defaultValue: NatConfig(hasExtIp: false, nat: NatAny)
defaultValueDesc: "any"
name: "nat" .}: NatConfig
enrAutoUpdate* {.
@ -59,6 +69,7 @@ type
nodeKey* {.
desc: "P2P node private key as hex",
defaultValue: PrivateKey.random(keys.newRng()[])
defaultValueDesc: "random"
name: "nodekey" .}: PrivateKey
portalBootnodes* {.
@ -71,7 +82,8 @@ type
name: "metrics" .}: bool
metricsAddress* {.
defaultValue: defaultAdminListenAddress(config)
defaultValue: DefaultAdminListenAddress
defaultValueDesc: $DefaultAdminListenAddressDesc
desc: "Listening address of the metrics server"
name: "metrics-address" .}: ValidIpAddress
@ -107,12 +119,6 @@ type
desc: "ENR URI of the node to send a findContent message"
name: "node" .}: Node
func defaultListenAddress*(conf: DiscoveryConf): ValidIpAddress =
(static ValidIpAddress.init("0.0.0.0"))
func defaultAdminListenAddress*(conf: DiscoveryConf): ValidIpAddress =
(static ValidIpAddress.init("127.0.0.1"))
proc parseCmdArg*(T: type enr.Record, p: TaintedString): T =
if not fromURI(result, p):
raise newException(ConfigurationError, "Invalid ENR")