From c6a9616cfdeca0cdbc01686750437a76b0e7d485 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Wed, 10 Jul 2019 10:08:59 +0800 Subject: [PATCH] cmd: encapsulate les relative cli options --- cmd/geth/usage.go | 9 +++++-- cmd/utils/flags.go | 67 +++++++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 08bd76778..1b40f76a4 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -82,6 +82,13 @@ var AppHelpFlagGroups = []flagGroup{ utils.GCModeFlag, utils.EthStatsURLFlag, utils.IdentityFlag, + utils.LightKDFFlag, + utils.WhitelistFlag, + }, + }, + { + Name: "LES", + Flags: []cli.Flag{ utils.LightServFlag, utils.LightBandwidthInFlag, utils.LightBandwidthOutFlag, @@ -89,8 +96,6 @@ var AppHelpFlagGroups = []flagGroup{ utils.UltraLightServersFlag, utils.UltraLightFractionFlag, utils.UltraLightOnlyAnnounceFlag, - utils.LightKDFFlag, - utils.WhitelistFlag, }, }, { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index e381f9bbb..8fff0baf4 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -174,20 +174,6 @@ var ( Name: "exitwhensynced", Usage: "Exits after block synchronisation completes", } - UltraLightServersFlag = cli.StringFlag{ - Name: "ulc.servers", - Usage: "List of trusted ultra-light servers", - Value: strings.Join(eth.DefaultConfig.UltraLightServers, ","), - } - UltraLightFractionFlag = cli.IntFlag{ - Name: "ulc.fraction", - Usage: "Minimum % of trusted ultra-light servers required to announce a new head", - Value: eth.DefaultConfig.UltraLightFraction, - } - UltraLightOnlyAnnounceFlag = cli.BoolFlag{ - Name: "ulc.onlyannounce", - Usage: "Ultra light server sends announcements only", - } IterativeOutputFlag = cli.BoolFlag{ Name: "iterative", Usage: "Print streaming JSON iteratively, delimited by newlines", @@ -215,6 +201,15 @@ var ( Usage: `Blockchain garbage collection mode ("full", "archive")`, Value: "full", } + LightKDFFlag = cli.BoolFlag{ + Name: "lightkdf", + Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength", + } + WhitelistFlag = cli.StringFlag{ + Name: "whitelist", + Usage: "Comma separated block number-to-hash mappings to enforce (=)", + } + // LES settings LightServFlag = cli.IntFlag{ Name: "lightserv", Usage: "Maximum percentage of time allowed for serving LES requests (multi-threaded processing allows values over 100)", @@ -235,13 +230,19 @@ var ( Usage: "Maximum number of LES client peers", Value: eth.DefaultConfig.LightPeers, } - LightKDFFlag = cli.BoolFlag{ - Name: "lightkdf", - Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength", + UltraLightServersFlag = cli.StringFlag{ + Name: "ulc.servers", + Usage: "List of trusted ultra-light servers", + Value: strings.Join(eth.DefaultConfig.UltraLightServers, ","), } - WhitelistFlag = cli.StringFlag{ - Name: "whitelist", - Usage: "Comma separated block number-to-hash mappings to enforce (=)", + UltraLightFractionFlag = cli.IntFlag{ + Name: "ulc.fraction", + Usage: "Minimum % of trusted ultra-light servers required to announce a new head", + Value: eth.DefaultConfig.UltraLightFraction, + } + UltraLightOnlyAnnounceFlag = cli.BoolFlag{ + Name: "ulc.onlyannounce", + Usage: "Ultra light server sends announcements only", } // Dashboard settings DashboardEnabledFlag = cli.BoolFlag{ @@ -949,8 +950,20 @@ func setIPC(ctx *cli.Context, cfg *node.Config) { } } -// setUltraLight configures the ultra light client settings from the command line flags. -func setUltraLight(ctx *cli.Context, cfg *eth.Config) { +// setLes configures the les server and ultra light client settings from the command line flags. +func setLes(ctx *cli.Context, cfg *eth.Config) { + if ctx.GlobalIsSet(LightServFlag.Name) { + cfg.LightServ = ctx.GlobalInt(LightServFlag.Name) + } + if ctx.GlobalIsSet(LightBandwidthInFlag.Name) { + cfg.LightBandwidthIn = ctx.GlobalInt(LightBandwidthInFlag.Name) + } + if ctx.GlobalIsSet(LightBandwidthOutFlag.Name) { + cfg.LightBandwidthOut = ctx.GlobalInt(LightBandwidthOutFlag.Name) + } + if ctx.GlobalIsSet(LightPeersFlag.Name) { + cfg.LightPeers = ctx.GlobalInt(LightPeersFlag.Name) + } if ctx.GlobalIsSet(UltraLightServersFlag.Name) { cfg.UltraLightServers = strings.Split(ctx.GlobalString(UltraLightServersFlag.Name), ",") } @@ -1379,19 +1392,11 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { setEthash(ctx, cfg) setMiner(ctx, &cfg.Miner) setWhitelist(ctx, cfg) - setUltraLight(ctx, cfg) + setLes(ctx, cfg) if ctx.GlobalIsSet(SyncModeFlag.Name) { cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode) } - if ctx.GlobalIsSet(LightServFlag.Name) { - cfg.LightServ = ctx.GlobalInt(LightServFlag.Name) - } - cfg.LightBandwidthIn = ctx.GlobalInt(LightBandwidthInFlag.Name) - cfg.LightBandwidthOut = ctx.GlobalInt(LightBandwidthOutFlag.Name) - if ctx.GlobalIsSet(LightPeersFlag.Name) { - cfg.LightPeers = ctx.GlobalInt(LightPeersFlag.Name) - } if ctx.GlobalIsSet(NetworkIdFlag.Name) { cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name) }