Skip to content

Commit 6f2c4fd

Browse files
committed
netinfo: add user help documentation
and drop no longer needed sort description header to save screen space
1 parent 6f97172 commit 6f2c4fd

File tree

1 file changed

+67
-3
lines changed

1 file changed

+67
-3
lines changed

src/bitcoin-cli.cpp

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void SetupCliArgs(ArgsManager& argsman)
5959
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6060
argsman.AddArg("-generate", strprintf("Generate blocks immediately, equivalent to RPC generatenewaddress 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);
6161
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);
62-
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).", ArgsManager::ALLOW_INT, OptionsCategory::OPTIONS);
62+
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::OPTIONS);
6363

6464
SetupChainParamsBaseOptions(argsman);
6565
argsman.AddArg("-named", strprintf("Pass named instead of positional arguments (default: %s)", DEFAULT_NAMED), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@@ -309,7 +309,8 @@ class NetinfoRequestHandler : public BaseRequestHandler
309309
}
310310
return UNKNOWN_NETWORK;
311311
}
312-
uint8_t m_details_level{0}; //!< Optional user-supplied arg to set dashboard details level
312+
uint8_t m_details_level{0}; //!< Optional user-supplied arg to set dashboard details level
313+
bool m_is_help_requested{false}; //!< Optional user-supplied arg to print help documentation
313314
bool DetailsRequested() const { return m_details_level > 0 && m_details_level < 5; }
314315
bool IsAddressSelected() const { return m_details_level == 2 || m_details_level == 4; }
315316
bool IsVersionSelected() const { return m_details_level == 3 || m_details_level == 4; }
@@ -349,6 +350,62 @@ class NetinfoRequestHandler : public BaseRequestHandler
349350
const double milliseconds{round(1000 * seconds)};
350351
return milliseconds > 999999 ? "-" : ToString(milliseconds);
351352
}
353+
const UniValue NetinfoHelp()
354+
{
355+
return std::string{
356+
"-netinfo level|\"help\" \n\n"
357+
"Returns a network peer connections dashboard with information from the remote server.\n"
358+
"Under the hood, -netinfo fetches the data by calling getpeerinfo and getnetworkinfo.\n"
359+
"An optional integer argument from 0 to 4 can be passed for different peers listings.\n"
360+
"Pass \"help\" to see this detailed help documentation.\n"
361+
"If more than one argument is passed, only the first one is read and parsed.\n"
362+
"Suggestion: use with the Linux watch(1) command for a live dashboard; see example below.\n\n"
363+
"Arguments:\n"
364+
"1. level (integer 0-4, optional) Specify the info level of the peers dashboard (default 0):\n"
365+
" 0 - Connection counts and local addresses\n"
366+
" 1 - Like 0 but with a peers listing (without address or version columns)\n"
367+
" 2 - Like 1 but with an address column\n"
368+
" 3 - Like 1 but with a version column\n"
369+
" 4 - Like 1 but with both address and version columns\n"
370+
"2. help (string \"help\", optional) Print this help documentation instead of the dashboard.\n\n"
371+
"Result:\n\n"
372+
"* The peers listing in levels 1-4 displays all of the peers sorted by direction and minimum ping time:\n\n"
373+
" Column Description\n"
374+
" ------ -----------\n"
375+
" <-> Direction\n"
376+
" \"in\" - inbound connections are those initiated by the peer\n"
377+
" \"out\" - outbound connections are those initiated by us\n"
378+
" type Type of peer connection\n"
379+
" \"full\" - full relay, the default\n"
380+
" \"block\" - block relay; like full relay but does not relay transactions or addresses\n"
381+
" net Network the peer connected through (\"ipv4\", \"ipv6\", \"onion\", \"i2p\", or \"cjdns\")\n"
382+
" mping Minimum observed ping time, in milliseconds (ms)\n"
383+
" ping Last observed ping time, in milliseconds (ms)\n"
384+
" send Time since last message sent to the peer, in seconds\n"
385+
" recv Time since last message received from the peer, in seconds\n"
386+
" txn Time since last novel transaction received from the peer and accepted into our mempool, in minutes\n"
387+
" blk Time since last novel block passing initial validity checks received from the peer, in minutes\n"
388+
" age Duration of connection to the peer, in minutes\n"
389+
" asmap Mapped AS (Autonomous System) number in the BGP route to the peer, used for diversifying\n"
390+
" peer selection (only displayed if the -asmap config option is set)\n"
391+
" id Peer index, in increasing order of peer connections since node startup\n"
392+
" address IP address and port of the peer\n"
393+
" version Peer version and subversion concatenated, e.g. \"70016/Satoshi:21.0.0/\"\n\n"
394+
"* The connection counts table displays the number of peers by direction, network, and the totals\n"
395+
" for each, as well as a column for block relay peers.\n\n"
396+
"* The local addresses table lists each local address broadcast by the node, the port, and the score.\n\n"
397+
"Examples:\n\n"
398+
"Connection counts and local addresses only\n"
399+
"> bitcoin-cli -netinfo\n\n"
400+
"Compact peers listing\n"
401+
"> bitcoin-cli -netinfo 1\n\n"
402+
"Full dashboard\n"
403+
"> bitcoin-cli -netinfo 4\n\n"
404+
"Full live dashboard, adjust --interval or --no-title as needed (Linux)\n"
405+
"> watch --interval 1 --no-title bitcoin-cli -netinfo 4\n\n"
406+
"See this help\n"
407+
"> bitcoin-cli -netinfo help\n"};
408+
}
352409
const int64_t m_time_now{GetSystemTimeInSeconds()};
353410

354411
public:
@@ -361,6 +418,10 @@ class NetinfoRequestHandler : public BaseRequestHandler
361418
uint8_t n{0};
362419
if (ParseUInt8(args.at(0), &n)) {
363420
m_details_level = n;
421+
} else if (args.at(0) == "help") {
422+
m_is_help_requested = true;
423+
} else {
424+
throw std::runtime_error(strprintf("invalid -netinfo argument: %s", args.at(0)));
364425
}
365426
}
366427
UniValue result(UniValue::VARR);
@@ -371,6 +432,9 @@ class NetinfoRequestHandler : public BaseRequestHandler
371432

372433
UniValue ProcessReply(const UniValue& batch_in) override
373434
{
435+
if (m_is_help_requested) {
436+
return JSONRPCReplyObj(NetinfoHelp(), NullUniValue, 1);
437+
}
374438
const std::vector<UniValue> batch{JSONRPCProcessBatchReply(batch_in)};
375439
if (!batch[ID_PEERINFO]["error"].isNull()) return batch[ID_PEERINFO];
376440
if (!batch[ID_NETWORKINFO]["error"].isNull()) return batch[ID_NETWORKINFO];
@@ -424,7 +488,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
424488
// Report detailed peer connections list sorted by direction and minimum ping time.
425489
if (DetailsRequested() && !m_peers.empty()) {
426490
std::sort(m_peers.begin(), m_peers.end());
427-
result += strprintf("Peer connections sorted by direction and min ping\n<-> relay net mping ping send recv txn blk %*s ", m_max_age_length, "age");
491+
result += strprintf("<-> relay net mping ping send recv txn blk %*s ", m_max_age_length, "age");
428492
if (m_is_asmap_on) result += " asmap ";
429493
result += strprintf("%*s %-*s%s\n", m_max_id_length, "id", IsAddressSelected() ? m_max_addr_length : 0, IsAddressSelected() ? "address" : "", IsVersionSelected() ? "version" : "");
430494
for (const Peer& peer : m_peers) {

0 commit comments

Comments
 (0)