Skip to content

Commit ee1294f

Browse files
committed
Merge bitcoin/bitcoin#23324: Print peer counts for all reachable networks in -netinfo
96f469f netinfo: print peer counts for all reachable networks (Jon Atack) Pull request description: instead of only for networks we have peer connections to. Users reported the previous behavior caused confusion, as no column was printed when a network was reachable but no peers were connected. Users expected a column to be printed with 0 peers. This commit aligns behavior with that expectation. In addition, the ipv4, ipv6, and onion columns were always printed whether or not they were reachable. With this change, only the reachable ones will be returned. Example with CJDNS reachable but no CJDNS peers (built on #23077 and #23175): before ``` ipv4 ipv6 onion i2p total block manual in 0 0 12 5 17 out 8 1 6 4 19 2 8 total 8 1 18 9 36 ``` after ``` ipv4 ipv6 onion i2p cjdns total block manual in 0 0 12 5 0 17 out 8 1 6 4 0 19 2 8 total 8 1 18 9 0 36 ``` There is one additional space between the in/out/total row headers and the network counts. ACKs for top commit: jsarenik: Tested ACK 96f469f prayank23: utACK bitcoin/bitcoin@96f469f laanwj: Code review and lightly tested ACK 96f469f naumenkogs: ACK 96f469f. hebasto: ACK 96f469f, tested by comparing the output of `watch src/bitcoin-cli -netinfo` with the Peer tab of the Node window in the GUI 🐅 Tree-SHA512: 3489f40148a2bd0afc9eef1e1577d44150c1fccec8dbf2a675bc23aa9343bfcae6c4039f5b96e54730668c83f40bc932fb6808f5540e86ff7249fde8dc0fff67
2 parents 88fc795 + 96f469f commit ee1294f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/bitcoin-cli.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,15 +551,26 @@ class NetinfoRequestHandler : public BaseRequestHandler
551551
}
552552

553553
// Report peer connection totals by type.
554-
result += " ipv4 ipv6 onion";
555-
const bool any_i2p_peers = m_counts.at(2).at(3); // false if total i2p peers count is 0, otherwise true
556-
if (any_i2p_peers) result += " i2p";
554+
result += " ";
555+
std::vector<int8_t> reachable_networks;
556+
for (const UniValue& network : networkinfo["networks"].getValues()) {
557+
if (network["reachable"].get_bool()) {
558+
const std::string& network_name{network["name"].get_str()};
559+
const int8_t network_id{NetworkStringToId(network_name)};
560+
if (network_id == UNKNOWN_NETWORK) continue;
561+
result += strprintf("%8s", network_name); // column header
562+
reachable_networks.push_back(network_id);
563+
}
564+
};
557565
result += " total block";
558566
if (m_manual_peers_count) result += " manual";
567+
559568
const std::array rows{"in", "out", "total"};
560-
for (uint8_t i = 0; i < 3; ++i) {
561-
result += strprintf("\n%-5s %5i %5i %5i", rows.at(i), m_counts.at(i).at(0), m_counts.at(i).at(1), m_counts.at(i).at(2)); // ipv4/ipv6/onion peers counts
562-
if (any_i2p_peers) result += strprintf(" %5i", m_counts.at(i).at(3)); // i2p peers count
569+
for (size_t i = 0; i < rows.size(); ++i) {
570+
result += strprintf("\n%-5s", rows[i]); // row header
571+
for (int8_t n : reachable_networks) {
572+
result += strprintf("%8i", m_counts.at(i).at(n)); // network peers count
573+
}
563574
result += strprintf(" %5i", m_counts.at(i).at(m_networks.size())); // total peers count
564575
if (i == 1) { // the outbound row has two extra columns for block relay and manual peer counts
565576
result += strprintf(" %5i", m_block_relay_peers_count);

0 commit comments

Comments
 (0)