Skip to content

Commit 68e484a

Browse files
Merge bitcoin/bitcoin#26584: cli: include local ("unroutable") peers in -netinfo table
77192c9 cli: include local ("unreachable") peers in -netinfo table (Matthew Zipkin) Pull request description: Closes bitcoin/bitcoin#26579 The `-netinfo` dashboard did not list peers that were connected via "unroutable" networks. This included local peers including local-network peers. Personally, I run one bitcoind instance on my network that is used by other services like Wasabi Wallet and LND running on other machines. This PR adds an "npr" (not publicly routable) column to the table of networks (ipv4, ipv6, onion, etc) so that every connection to the node is listed, and the totals are accurate as they relate to max inbound and max outbound limits. Example connecting in regtest mode to one local and one remote peer: ``` Bitcoin Core client v24.99.0-151ce099ea8f-dirty regtest - server 70016/Satoshi:24.99.0/ <-> type net mping ping send recv txn blk hb addrp addrl age id address version in npr 0 0 90 90 1 1 127.0.0.1:59180 70016/Satoshi:24.99.0/ out manual ipv4 63 63 84 84 3 3 0 143.244.175.41 70016/Satoshi:24.0.1/ ms ms sec sec min min min ipv4 ipv6 npr total block manual in 0 0 1 1 out 1 0 0 1 0 1 total 1 0 1 2 Local addresses: n/a ``` ACKs for top commit: jonatack: Re-tested ACK 77192c9 Tree-SHA512: 78aa68bcff0dbaadb5f0604bf023fe8fd921313bd8276d12581f7655c089466a48765f9e123cb31d7f1d294d5ca45fdefdf8aa220466ff738f32414f41099c06
2 parents 576e16e + 77192c9 commit 68e484a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/bitcoin-cli.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ static constexpr int DEFAULT_WAIT_CLIENT_TIMEOUT = 0;
5555
static const bool DEFAULT_NAMED=false;
5656
static const int CONTINUE_EXECUTION=-1;
5757
static constexpr int8_t UNKNOWN_NETWORK{-1};
58-
static constexpr std::array NETWORKS{"ipv4", "ipv6", "onion", "i2p", "cjdns"};
58+
// See GetNetworkName() in netbase.cpp
59+
static constexpr std::array NETWORKS{"not_publicly_routable", "ipv4", "ipv6", "onion", "i2p", "cjdns", "internal"};
60+
static constexpr std::array NETWORK_SHORT_NAMES{"npr", "ipv4", "ipv6", "onion", "i2p", "cjdns", "int"};
61+
static constexpr std::array UNREACHABLE_NETWORK_IDS{/*not_publicly_routable*/0, /*internal*/6};
5962

6063
/** Default number of blocks to generate for RPC generatetoaddress. */
6164
static const std::string DEFAULT_NBLOCKS = "1";
@@ -289,7 +292,7 @@ class AddrinfoRequestHandler : public BaseRequestHandler
289292
// Prepare result to return to user.
290293
UniValue result{UniValue::VOBJ}, addresses{UniValue::VOBJ};
291294
uint64_t total{0}; // Total address count
292-
for (size_t i = 0; i < NETWORKS.size(); ++i) {
295+
for (size_t i = 1; i < NETWORKS.size() - 1; ++i) {
293296
addresses.pushKV(NETWORKS[i], counts.at(i));
294297
total += counts.at(i);
295298
}
@@ -506,7 +509,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
506509
const bool is_addr_relay_enabled{peer["addr_relay_enabled"].isNull() ? false : peer["addr_relay_enabled"].get_bool()};
507510
const bool is_bip152_hb_from{peer["bip152_hb_from"].get_bool()};
508511
const bool is_bip152_hb_to{peer["bip152_hb_to"].get_bool()};
509-
m_peers.push_back({addr, sub_version, conn_type, network, age, min_ping, ping, addr_processed, addr_rate_limited, last_blck, last_recv, last_send, last_trxn, peer_id, mapped_as, version, is_addr_relay_enabled, is_bip152_hb_from, is_bip152_hb_to, is_outbound, is_tx_relay});
512+
m_peers.push_back({addr, sub_version, conn_type, NETWORK_SHORT_NAMES[network_id], age, min_ping, ping, addr_processed, addr_rate_limited, last_blck, last_recv, last_send, last_trxn, peer_id, mapped_as, version, is_addr_relay_enabled, is_bip152_hb_from, is_bip152_hb_to, is_outbound, is_tx_relay});
510513
m_max_addr_length = std::max(addr.length() + 1, m_max_addr_length);
511514
m_max_addr_processed_length = std::max(ToString(addr_processed).length(), m_max_addr_processed_length);
512515
m_max_addr_rate_limited_length = std::max(ToString(addr_rate_limited).length(), m_max_addr_rate_limited_length);
@@ -571,6 +574,13 @@ class NetinfoRequestHandler : public BaseRequestHandler
571574
reachable_networks.push_back(network_id);
572575
}
573576
};
577+
578+
for (const size_t network_id : UNREACHABLE_NETWORK_IDS) {
579+
if (m_counts.at(2).at(network_id) == 0) continue;
580+
result += strprintf("%8s", NETWORK_SHORT_NAMES.at(network_id)); // column header
581+
reachable_networks.push_back(network_id);
582+
}
583+
574584
result += " total block";
575585
if (m_manual_peers_count) result += " manual";
576586

@@ -636,7 +646,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
636646
" \"manual\" - peer we manually added using RPC addnode or the -addnode/-connect config options\n"
637647
" \"feeler\" - short-lived connection for testing addresses\n"
638648
" \"addr\" - address fetch; short-lived connection for requesting addresses\n"
639-
" net Network the peer connected through (\"ipv4\", \"ipv6\", \"onion\", \"i2p\", or \"cjdns\")\n"
649+
" net Network the peer connected through (\"ipv4\", \"ipv6\", \"onion\", \"i2p\", \"cjdns\", or \"npr\" (not publicly routable))\n"
640650
" mping Minimum observed ping time, in milliseconds (ms)\n"
641651
" ping Last observed ping time, in milliseconds (ms)\n"
642652
" send Time since last message sent to the peer, in seconds\n"

0 commit comments

Comments
 (0)