Skip to content

Commit 5de7a6c

Browse files
committed
netinfo: display manual peers count
1 parent d3cca3b commit 5de7a6c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/bitcoin-cli.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
303303
static constexpr uint8_t m_networks_size{3};
304304
const std::array<std::string, m_networks_size> m_networks{{"ipv4", "ipv6", "onion"}};
305305
std::array<std::array<uint16_t, m_networks_size + 2>, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total/block-relay)
306+
uint8_t m_manual_peers_count{0};
306307
int8_t NetworkStringToId(const std::string& str) const
307308
{
308309
for (uint8_t i = 0; i < m_networks_size; ++i) {
@@ -405,7 +406,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
405406
" address IP address and port of the peer\n"
406407
" version Peer version and subversion concatenated, e.g. \"70016/Satoshi:21.0.0/\"\n\n"
407408
"* The connection counts table displays the number of peers by direction, network, and the totals\n"
408-
" for each, as well as a column for block relay peers.\n\n"
409+
" for each, as well as two special outbound columns for block relay peers and manual peers.\n\n"
409410
"* The local addresses table lists each local address broadcast by the node, the port, and the score.\n\n"
410411
"Examples:\n\n"
411412
"Connection counts and local addresses only\n"
@@ -473,6 +474,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
473474
++m_counts.at(is_outbound).at(m_networks_size + 1); // in/out block-relay
474475
++m_counts.at(2).at(m_networks_size + 1); // total block-relay
475476
}
477+
if (conn_type == "manual") ++m_manual_peers_count;
476478
if (DetailsRequested()) {
477479
// Push data for this peer to the peers vector.
478480
const int peer_id{peer["id"].get_int()};
@@ -532,14 +534,16 @@ class NetinfoRequestHandler : public BaseRequestHandler
532534
}
533535

534536
// Report peer connection totals by type.
535-
result += " ipv4 ipv6 onion total block-relay\n";
537+
result += " ipv4 ipv6 onion total block";
538+
if (m_manual_peers_count) result += " manual";
536539
const std::array<std::string, 3> rows{{"in", "out", "total"}};
537540
for (uint8_t i = 0; i < m_networks_size; ++i) {
538-
result += strprintf("%-5s %5i %5i %5i %5i %5i\n", rows.at(i), m_counts.at(i).at(0), m_counts.at(i).at(1), m_counts.at(i).at(2), m_counts.at(i).at(m_networks_size), m_counts.at(i).at(m_networks_size + 1));
541+
result += strprintf("\n%-5s %5i %5i %5i %5i %5i", rows.at(i), m_counts.at(i).at(0), m_counts.at(i).at(1), m_counts.at(i).at(2), m_counts.at(i).at(m_networks_size), m_counts.at(i).at(m_networks_size + 1));
542+
if (i == 1 && m_manual_peers_count) result += strprintf(" %5i", m_manual_peers_count);
539543
}
540544

541545
// Report local addresses, ports, and scores.
542-
result += "\nLocal addresses";
546+
result += "\n\nLocal addresses";
543547
const std::vector<UniValue>& local_addrs{networkinfo["localaddresses"].getValues()};
544548
if (local_addrs.empty()) {
545549
result += ": n/a\n";

0 commit comments

Comments
 (0)