You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge bitcoin/bitcoin#30930: netinfo: add peer services column and outbound-only option
87532fe netinfo: allow setting an outbound-only peer list (Jon Atack)
681ebcc netinfo: rename and hoist max level constant to use in top-level help (Jon Atack)
e7d307c netinfo: clarify relaytxes and addr_relay_enabled help docs (Jon Atack)
eef2a9d netinfo: add peer services column (Jon Atack)
Pull request description:
Been using this since May 2023.
- add a peer services column (considered displaying the p2p_v2 flag as "p" or "2"; proposing "2" here for continuity with the "v" column, but "p" is fine for me as well)
- clarify in the help that "relaytxes" and "addr_relay_enabled" are from getpeerinfo
- hoist (and rename) the 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 (as caught by Larry Ruane in review below)
- add an optional "outonly" (or "o") argument for an outbound-only peer list, as suggested by Vasil Dimov in his review below. Several people have requested this, to keep the output within screen limits when running netinfo as a live dashboard (i.e. with `watch`) on a node with many peers. While doing this, also permit passing "h" for the help in addition to "help".
ACKs for top commit:
achow101:
ACK 87532fe
rkrux:
tACK 87532fe
tdb3:
cr re ACK 87532fe
brunoerg:
crACK 87532fe
Tree-SHA512: 35b1b0de28dfecaad58bf5af194757a5e0f563553cf69ea4d76f2e1963f8d662717254df2549114c7bba4a041bf5282d5cb3fba8d436b2807f2a00560787d64c
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);
92
93
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);
93
-
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);
94
+
argsman.AddArg("-netinfo", strprintf("Get network peer connection information from the remote server. An optional argument from 0 to %d can be passed for different peers listings (default: 0). If a non-zero value is passed, an additional \"outonly\" (or \"o\") argument can be passed to see outbound peers only. Pass \"help\"(or \"h\") for detailed help documentation.", NETINFO_MAX_LEVEL), ArgsManager::ALLOW_ANY, OptionsCategory::CLI_COMMANDS);
94
95
95
96
SetupChainParamsBaseOptions(argsman);
96
97
argsman.AddArg("-color=<when>", 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 @@ class GetinfoRequestHandler: public BaseRequestHandler
throwstd::runtime_error(strprintf("invalid -netinfo outonly argument: %s\nThe outonly argument is only valid for a level greater than 0 (the first argument). For more information, run: bitcoin-cli -netinfo help", s));
492
+
}
472
493
}
473
494
}
474
495
UniValue result(UniValue::VARR);
@@ -503,6 +524,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
503
524
++m_counts.at(2).at(NETWORKS.size()); // total overall
504
525
if (conn_type == "block-relay-only") ++m_block_relay_peers_count;
505
526
if (conn_type == "manual") ++m_manual_peers_count;
527
+
if (m_outbound_only_selected && !is_outbound) continue;
506
528
if (DetailsRequested()) {
507
529
// Push data for this peer to the peers vector.
508
530
constint peer_id{peer["id"].getInt<int>()};
@@ -519,17 +541,19 @@ class NetinfoRequestHandler : public BaseRequestHandler
@@ -575,7 +602,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
575
602
IsAddressSelected() ? peer.addr : "",
576
603
IsVersionSelected() && version != "0" ? version : "");
577
604
}
578
-
result += strprintf(" ms ms sec sec min min %*s\n\n", m_max_age_length, "min");
605
+
result += strprintf("%*sms ms sec sec min min %*s\n\n", m_max_services_length, "", m_max_age_length, "min");
579
606
}
580
607
581
608
// Report peer connection totals by type.
@@ -632,25 +659,28 @@ class NetinfoRequestHandler : public BaseRequestHandler
632
659
}
633
660
634
661
const std::string m_help_doc{
635
-
"-netinfo level|\"help\"\n\n"
662
+
"-netinfo (level [outonly]) | help\n\n"
636
663
"Returns a network peer connections dashboard with information from the remote server.\n"
637
664
"This human-readable interface will change regularly and is not intended to be a stable API.\n"
638
665
"Under the hood, -netinfo fetches the data by calling getpeerinfo and getnetworkinfo.\n"
639
-
+ 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) +
640
-
"Pass \"help\" to see this detailed help documentation.\n"
641
-
"If more than one argument is passed, only the first one is read and parsed.\n"
642
-
"Suggestion: use with the Linux watch(1) command for a live dashboard; see example below.\n\n"
666
+
+ strprintf("An optional argument from 0 to %d can be passed for different peers listings; values above %d up to 255 are parsed as %d.\n", NETINFO_MAX_LEVEL, NETINFO_MAX_LEVEL, NETINFO_MAX_LEVEL) +
667
+
"If that argument is passed, an optional additional \"outonly\" argument may be passed to obtain the listing with outbound peers only.\n"
668
+
"Pass \"help\" or \"h\" to see this detailed help documentation.\n"
669
+
"If more than two arguments are passed, only the first two are read and parsed.\n"
670
+
"Suggestion: use -netinfo with the Linux watch(1) command for a live dashboard; see example below.\n\n"
643
671
"Arguments:\n"
644
-
+ strprintf("1. level (integer 0-%d, optional) Specify the info level of the peers dashboard (default 0):\n", MAX_DETAIL_LEVEL) +
672
+
+ strprintf("1. level (integer 0-%d, optional) Specify the info level of the peers dashboard (default 0):\n", NETINFO_MAX_LEVEL) +
645
673
" 0 - Peer counts for each reachable network as well as for block relay peers\n"
646
674
" and manual peers, and the list of local addresses and ports\n"
647
675
" 1 - Like 0 but preceded by a peers listing (without address and version columns)\n"
648
676
" 2 - Like 1 but with an address column\n"
649
677
" 3 - Like 1 but with a version column\n"
650
678
" 4 - Like 1 but with both address and version columns\n"
651
-
"2. help (string \"help\", optional) Print this help documentation instead of the dashboard.\n\n"
679
+
"2. outonly (\"outonly\" or \"o\", optional) Return the peers listing with outbound peers only, i.e. to save screen space\n"
680
+
" when a node has many inbound peers. Only valid if a level is passed.\n\n"
681
+
"help (\"help\" or \"h\", optional) Print this help documentation instead of the dashboard.\n\n"
652
682
"Result:\n\n"
653
-
+ 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) +
683
+
+ 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) +
654
684
" Column Description\n"
655
685
" ------ -----------\n"
656
686
" <-> Direction\n"
@@ -663,19 +693,27 @@ class NetinfoRequestHandler : public BaseRequestHandler
663
693
"\"feeler\" - short-lived connection for testing addresses\n"
664
694
"\"addr\" - address fetch; short-lived connection for requesting addresses\n"
665
695
" net Network the peer connected through (\"ipv4\", \"ipv6\", \"onion\", \"i2p\", \"cjdns\", or \"npr\" (not publicly routable))\n"
696
+
" serv Services offered by the peer\n"
697
+
"\"n\" - NETWORK: peer can serve the full block chain\n"
698
+
"\"b\" - BLOOM: peer can handle bloom-filtered connections (see BIP 111)\n"
699
+
"\"w\" - WITNESS: peer can be asked for blocks and transactions with witness data (SegWit)\n"
700
+
"\"c\" - COMPACT_FILTERS: peer can handle basic block filter requests (see BIPs 157 and 158)\n"
701
+
"\"l\" - NETWORK_LIMITED: peer limited to serving only the last 288 blocks (~2 days)\n"
702
+
"\"2\" - P2P_V2: peer supports version 2 P2P transport protocol, as defined in BIP 324\n"
703
+
"\"u\" - UNKNOWN: unrecognized bit flag\n"
666
704
" v Version of transport protocol used for the connection\n"
667
705
" mping Minimum observed ping time, in milliseconds (ms)\n"
668
706
" ping Last observed ping time, in milliseconds (ms)\n"
669
707
" send Time since last message sent to the peer, in seconds\n"
670
708
" recv Time since last message received from the peer, in seconds\n"
671
709
" txn Time since last novel transaction received from the peer and accepted into our mempool, in minutes\n"
672
-
"\"*\" - we do not relay transactions to this peer (relaytxes is false)\n"
710
+
"\"*\" - we do not relay transactions to this peer (getpeerinfo \"relaytxes\" is false)\n"
673
711
" blk Time since last novel block passing initial validity checks received from the peer, in minutes\n"
674
712
" hb High-bandwidth BIP152 compact block relay\n"
675
713
"\".\" (to) - we selected the peer as a high-bandwidth peer\n"
676
714
"\"*\" (from) - the peer selected us as a high-bandwidth peer\n"
677
715
" addrp Total number of addresses processed, excluding those dropped due to rate limiting\n"
678
-
"\".\" - we do not relay addresses to this peer (addr_relay_enabled is false)\n"
716
+
"\".\" - we do not relay addresses to this peer (getpeerinfo \"addr_relay_enabled\" is false)\n"
679
717
" addrl Total number of addresses dropped due to rate limiting\n"
680
718
" age Duration of connection to the peer, in minutes\n"
681
719
" asmap Mapped AS (Autonomous System) number at the end of the BGP route to the peer, used for diversifying\n"
@@ -692,9 +730,11 @@ class NetinfoRequestHandler : public BaseRequestHandler
692
730
"The same, preceded by a peers listing without address and version columns\n"
0 commit comments