From 681ebcceca78caeb9731f97d339ef926432e29ef Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Fri, 11 Oct 2024 15:11:34 -0600 Subject: [PATCH] netinfo: rename and hoist max level constant to use in top-level help to avoid overlooking to update the top-level help if the value of the constant changes. --- src/bitcoin-cli.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 1c433b03b02..17d44917bc6 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -57,6 +57,7 @@ static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900; static constexpr int DEFAULT_WAIT_CLIENT_TIMEOUT = 0; static const bool DEFAULT_NAMED=false; static const int CONTINUE_EXECUTION=-1; +static constexpr uint8_t NETINFO_MAX_LEVEL{4}; static constexpr int8_t UNKNOWN_NETWORK{-1}; // See GetNetworkName() in netbase.cpp static constexpr std::array NETWORKS{"not_publicly_routable", "ipv4", "ipv6", "onion", "i2p", "cjdns", "internal"}; @@ -90,7 +91,7 @@ static void SetupCliArgs(ArgsManager& argsman) ArgsManager::ALLOW_ANY, OptionsCategory::CLI_COMMANDS); argsman.AddArg("-addrinfo", "Get the number of addresses known to the node, per network and total, after filtering for quality and recency. The total number of addresses known to the node may be higher.", ArgsManager::ALLOW_ANY, OptionsCategory::CLI_COMMANDS); argsman.AddArg("-getinfo", "Get general information from the remote server. Note that unlike server-side RPC calls, the output of -getinfo is the result of multiple non-atomic requests. Some entries in the output may represent results from different states (e.g. wallet balance may be as of a different block from the chain state reported)", ArgsManager::ALLOW_ANY, OptionsCategory::CLI_COMMANDS); - argsman.AddArg("-netinfo", "Get network peer connection information from the remote server. An optional integer argument from 0 to 4 can be passed for different peers listings (default: 0). Pass \"help\" for detailed help documentation.", ArgsManager::ALLOW_ANY, OptionsCategory::CLI_COMMANDS); + argsman.AddArg("-netinfo", strprintf("Get network peer connection information from the remote server. An optional integer argument from 0 to %d can be passed for different peers listings (default: 0). Pass \"help\" for detailed help documentation.", NETINFO_MAX_LEVEL), ArgsManager::ALLOW_ANY, OptionsCategory::CLI_COMMANDS); SetupChainParamsBaseOptions(argsman); argsman.AddArg("-color=", strprintf("Color setting for CLI output (default: %s). Valid values: always, auto (add color codes when standard output is connected to a terminal and OS is not WIN32), never.", DEFAULT_COLOR_SETTING), ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS); @@ -379,7 +380,6 @@ public: class NetinfoRequestHandler : public BaseRequestHandler { private: - static constexpr uint8_t MAX_DETAIL_LEVEL{4}; std::array, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total) uint8_t m_block_relay_peers_count{0}; uint8_t m_manual_peers_count{0}; @@ -477,7 +477,7 @@ public: if (!args.empty()) { uint8_t n{0}; if (ParseUInt8(args.at(0), &n)) { - m_details_level = std::min(n, MAX_DETAIL_LEVEL); + m_details_level = std::min(n, NETINFO_MAX_LEVEL); } else { throw std::runtime_error(strprintf("invalid -netinfo argument: %s\nFor more information, run: bitcoin-cli -netinfo help", args.at(0))); } @@ -652,12 +652,12 @@ public: "Returns a network peer connections dashboard with information from the remote server.\n" "This human-readable interface will change regularly and is not intended to be a stable API.\n" "Under the hood, -netinfo fetches the data by calling getpeerinfo and getnetworkinfo.\n" - + strprintf("An optional integer argument from 0 to %d can be passed for different peers listings; %d to 255 are parsed as %d.\n", MAX_DETAIL_LEVEL, MAX_DETAIL_LEVEL, MAX_DETAIL_LEVEL) + + + strprintf("An optional integer argument from 0 to %d can be passed for different peers listings; values from %d to 255 are parsed as %d.\n", NETINFO_MAX_LEVEL, NETINFO_MAX_LEVEL, NETINFO_MAX_LEVEL) + "Pass \"help\" to see this detailed help documentation.\n" "If more than one argument is passed, only the first one is read and parsed.\n" "Suggestion: use with the Linux watch(1) command for a live dashboard; see example below.\n\n" "Arguments:\n" - + strprintf("1. level (integer 0-%d, optional) Specify the info level of the peers dashboard (default 0):\n", MAX_DETAIL_LEVEL) + + + strprintf("1. level (integer 0-%d, optional) Specify the info level of the peers dashboard (default 0):\n", NETINFO_MAX_LEVEL) + " 0 - Peer counts for each reachable network as well as for block relay peers\n" " and manual peers, and the list of local addresses and ports\n" " 1 - Like 0 but preceded by a peers listing (without address and version columns)\n" @@ -666,7 +666,7 @@ public: " 4 - Like 1 but with both address and version columns\n" "2. help (string \"help\", optional) Print this help documentation instead of the dashboard.\n\n" "Result:\n\n" - + strprintf("* The peers listing in levels 1-%d displays all of the peers sorted by direction and minimum ping time:\n\n", MAX_DETAIL_LEVEL) + + + strprintf("* The peers listing in levels 1-%d displays all of the peers sorted by direction and minimum ping time:\n\n", NETINFO_MAX_LEVEL) + " Column Description\n" " ------ -----------\n" " <-> Direction\n" @@ -716,9 +716,9 @@ public: "The same, preceded by a peers listing without address and version columns\n" "> bitcoin-cli -netinfo 1\n\n" "Full dashboard\n" - + strprintf("> bitcoin-cli -netinfo %d\n\n", MAX_DETAIL_LEVEL) + + + strprintf("> bitcoin-cli -netinfo %d\n\n", NETINFO_MAX_LEVEL) + "Full live dashboard, adjust --interval or --no-title as needed (Linux)\n" - + strprintf("> watch --interval 1 --no-title bitcoin-cli -netinfo %d\n\n", MAX_DETAIL_LEVEL) + + + strprintf("> watch --interval 1 --no-title bitcoin-cli -netinfo %d\n\n", NETINFO_MAX_LEVEL) + "See this help\n" "> bitcoin-cli -netinfo help\n"}; };