Skip to content

Commit f92bce8

Browse files
committed
Hoist -netinfo max detail level and use in help
1 parent 22fa911 commit f92bce8

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/bitcoin-cli.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static constexpr int DEFAULT_WAIT_CLIENT_TIMEOUT = 0;
4444
static const bool DEFAULT_NAMED=false;
4545
static const int CONTINUE_EXECUTION=-1;
4646
static constexpr int8_t UNKNOWN_NETWORK{-1};
47+
static constexpr uint8_t NETINFO_MAX_DETAIL_LEVEL{5};
4748

4849
/** Default number of blocks to generate for RPC generatetoaddress. */
4950
static const std::string DEFAULT_NBLOCKS = "1";
@@ -63,8 +64,7 @@ static void SetupCliArgs(ArgsManager& argsman)
6364
argsman.AddArg("-generate", strprintf("Generate blocks immediately, equivalent to RPC getnewaddress followed by RPC generatetoaddress. Optional positional integer arguments are number of blocks to generate (default: %s) and maximum iterations to try (default: %s), equivalent to RPC generatetoaddress nblocks and maxtries arguments. Example: bitcoin-cli -generate 4 1000", DEFAULT_NBLOCKS, DEFAULT_MAX_TRIES), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6465
argsman.AddArg("-addrinfo", "Get the number of addresses known to the node, per network and total.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6566
argsman.AddArg("-getinfo", "Get general information from the remote server. Note that unlike server-side RPC calls, the results of -getinfo is the result of multiple non-atomic requests. Some entries in the result 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::OPTIONS);
66-
argsman.AddArg("-netinfo", "Get network peer connection information from the remote server. An optional integer argument from 0 to 5 can be passed for different peers listings (default: 0). Pass \"help\" for detailed help documentation.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
67-
67+
argsman.AddArg("-netinfo", strprintf("Get network peer connection information from the remote server. An optional integer argument from 0 to %u can be passed for different peers listings (default: 0). Pass \"help\" for detailed help documentation.", NETINFO_MAX_DETAIL_LEVEL), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6868
SetupChainParamsBaseOptions(argsman);
6969
argsman.AddArg("-named", strprintf("Pass named instead of positional arguments (default: %s)", DEFAULT_NAMED), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
7070
argsman.AddArg("-rpcclienttimeout=<n>", strprintf("Timeout in seconds during HTTP requests, or 0 for no timeout. (default: %d)", DEFAULT_HTTP_CLIENT_TIMEOUT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@@ -357,7 +357,6 @@ class GetinfoRequestHandler: public BaseRequestHandler
357357
class NetinfoRequestHandler : public BaseRequestHandler
358358
{
359359
private:
360-
static constexpr uint8_t MAX_DETAIL_LEVEL{5};
361360
static constexpr std::array m_networks{"ipv4", "ipv6", "onion", "i2p"};
362361
std::array<std::array<uint16_t, m_networks.size() + 1>, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total)
363362
uint8_t m_block_relay_peers_count{0};
@@ -436,7 +435,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
436435
if (!args.empty()) {
437436
uint8_t n{0};
438437
if (ParseUInt8(args.at(0), &n)) {
439-
m_details_level = std::min(n, MAX_DETAIL_LEVEL);
438+
m_details_level = std::min(n, NETINFO_MAX_DETAIL_LEVEL);
440439
} else {
441440
throw std::runtime_error(strprintf("invalid -netinfo argument: %s\nFor more information, run: bitcoin-cli -netinfo help", args.at(0)));
442441
}
@@ -582,12 +581,12 @@ class NetinfoRequestHandler : public BaseRequestHandler
582581
"Returns a network peer connections dashboard with information from the remote server.\n"
583582
"This human-readable interface will change regularly and is not intended to be a stable API.\n"
584583
"Under the hood, -netinfo fetches the data by calling getpeerinfo and getnetworkinfo.\n"
585-
+ 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) +
584+
+ strprintf("An optional integer argument from 0 to %u can be passed for different peers listings; %u to 255 are parsed as %u.\n", NETINFO_MAX_DETAIL_LEVEL, NETINFO_MAX_DETAIL_LEVEL, NETINFO_MAX_DETAIL_LEVEL) +
586585
"Pass \"help\" to see this detailed help documentation.\n"
587586
"If more than one argument is passed, only the first one is read and parsed.\n"
588587
"Suggestion: use with the Linux watch(1) command for a live dashboard; see example below.\n\n"
589588
"Arguments:\n"
590-
+ strprintf("1. level (integer 0-%d, optional) Specify the info level of the peers dashboard (default 0):\n", MAX_DETAIL_LEVEL) +
589+
+ strprintf("1. level (integer 0-%u, optional) Specify the info level of the peers dashboard (default 0):\n", NETINFO_MAX_DETAIL_LEVEL) +
591590
" 0 - Connection counts and local addresses\n"
592591
" 1 - Like 0 but with a peers listing (without address or version columns)\n"
593592
" 2 - Like 1 but with an address column\n"
@@ -596,7 +595,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
596595
" 5 - Like 4 but with additional data for development and testing purposes\n"
597596
"2. help (string \"help\", optional) Print this help documentation instead of the dashboard.\n\n"
598597
"Result:\n\n"
599-
+ 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) +
598+
+ strprintf("* The peers listing in levels 1-%u displays all of the peers sorted by direction and minimum ping time:\n\n", NETINFO_MAX_DETAIL_LEVEL) +
600599
" Column Description\n"
601600
" ------ -----------\n"
602601
" <-> Direction\n"
@@ -635,9 +634,9 @@ class NetinfoRequestHandler : public BaseRequestHandler
635634
"Compact peers listing\n"
636635
"> bitcoin-cli -netinfo 1\n\n"
637636
"Full dashboard\n"
638-
+ strprintf("> bitcoin-cli -netinfo %d\n\n", MAX_DETAIL_LEVEL) +
637+
+ strprintf("> bitcoin-cli -netinfo %u\n\n", NETINFO_MAX_DETAIL_LEVEL) +
639638
"Full live dashboard, adjust --interval or --no-title as needed (Linux)\n"
640-
+ strprintf("> watch --interval 1 --no-title bitcoin-cli -netinfo %d\n\n", MAX_DETAIL_LEVEL) +
639+
+ strprintf("> watch --interval 1 --no-title bitcoin-cli -netinfo %u\n\n", NETINFO_MAX_DETAIL_LEVEL) +
641640
"See this help\n"
642641
"> bitcoin-cli -netinfo help\n"};
643642
};

0 commit comments

Comments
 (0)