Skip to content

Commit eb4f01f

Browse files
committed
merge bitcoin#26584: include local ("unreachable") peers in -netinfo table
1 parent 10dc874 commit eb4f01f

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/bitcoin-cli.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ static constexpr int DEFAULT_WAIT_CLIENT_TIMEOUT = 0;
5252
static const bool DEFAULT_NAMED=false;
5353
static const int CONTINUE_EXECUTION=-1;
5454
static constexpr int8_t UNKNOWN_NETWORK{-1};
55-
static constexpr std::array NETWORKS{"ipv4", "ipv6", "onion", "i2p", "cjdns"};
55+
// See GetNetworkName() in netbase.cpp
56+
static constexpr std::array NETWORKS{"not_publicly_routable", "ipv4", "ipv6", "onion", "i2p", "cjdns", "internal"};
57+
static constexpr std::array NETWORK_SHORT_NAMES{"npr", "ipv4", "ipv6", "onion", "i2p", "cjdns", "int"};
58+
static constexpr std::array UNREACHABLE_NETWORK_IDS{/*not_publicly_routable*/0, /*internal*/6};
5659

5760
/** Default number of blocks to generate for RPC generatetoaddress. */
5861
static const std::string DEFAULT_NBLOCKS = "1";
@@ -296,7 +299,7 @@ class AddrinfoRequestHandler : public BaseRequestHandler
296299
// Prepare result to return to user.
297300
UniValue result{UniValue::VOBJ}, addresses{UniValue::VOBJ};
298301
uint64_t total{0}; // Total address count
299-
for (size_t i = 0; i < NETWORKS.size(); ++i) {
302+
for (size_t i = 1; i < NETWORKS.size() - 1; ++i) {
300303
addresses.pushKV(NETWORKS[i], counts.at(i));
301304
total += counts.at(i);
302305
}
@@ -517,7 +520,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
517520
const bool is_addr_relay_enabled{peer["addr_relay_enabled"].isNull() ? false : peer["addr_relay_enabled"].get_bool()};
518521
const bool is_bip152_hb_from{peer["bip152_hb_from"].get_bool()};
519522
const bool is_bip152_hb_to{peer["bip152_hb_to"].get_bool()};
520-
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_block_relay, is_outbound});
523+
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_block_relay, is_outbound});
521524
m_max_addr_length = std::max(addr.length() + 1, m_max_addr_length);
522525
m_max_addr_processed_length = std::max(ToString(addr_processed).length(), m_max_addr_processed_length);
523526
m_max_addr_rate_limited_length = std::max(ToString(addr_rate_limited).length(), m_max_addr_rate_limited_length);
@@ -582,6 +585,13 @@ class NetinfoRequestHandler : public BaseRequestHandler
582585
reachable_networks.push_back(network_id);
583586
}
584587
};
588+
589+
for (const size_t network_id : UNREACHABLE_NETWORK_IDS) {
590+
if (m_counts.at(2).at(network_id) == 0) continue;
591+
result += strprintf("%8s", NETWORK_SHORT_NAMES.at(network_id)); // column header
592+
reachable_networks.push_back(network_id);
593+
}
594+
585595
result += " total block";
586596
if (m_manual_peers_count) result += " manual";
587597

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

0 commit comments

Comments
 (0)