@@ -49,6 +49,7 @@ static constexpr int DEFAULT_WAIT_CLIENT_TIMEOUT = 0;
49
49
static const bool DEFAULT_NAMED=false ;
50
50
static const int CONTINUE_EXECUTION=-1 ;
51
51
static constexpr int8_t UNKNOWN_NETWORK{-1 };
52
+ static constexpr std::array NETWORKS{" ipv4" , " ipv6" , " onion" , " i2p" , " cjdns" };
52
53
53
54
/* * Default number of blocks to generate for RPC generatetoaddress. */
54
55
static const std::string DEFAULT_NBLOCKS = " 1" ;
@@ -242,11 +243,10 @@ class BaseRequestHandler
242
243
class AddrinfoRequestHandler : public BaseRequestHandler
243
244
{
244
245
private:
245
- static constexpr std::array m_networks{" ipv4" , " ipv6" , " onion" , " i2p" , " cjdns" };
246
246
int8_t NetworkStringToId (const std::string& str) const
247
247
{
248
- for (size_t i = 0 ; i < m_networks .size (); ++i) {
249
- if (str == m_networks. at (i) ) return i;
248
+ for (size_t i = 0 ; i < NETWORKS .size (); ++i) {
249
+ if (str == NETWORKS[i] ) return i;
250
250
}
251
251
return UNKNOWN_NETWORK;
252
252
}
@@ -269,7 +269,7 @@ class AddrinfoRequestHandler : public BaseRequestHandler
269
269
throw std::runtime_error (" -addrinfo requires bitcoind server to be running v22.0 and up" );
270
270
}
271
271
// Count the number of peers known to our node, by network.
272
- std::array<uint64_t , m_networks .size ()> counts{{}};
272
+ std::array<uint64_t , NETWORKS .size ()> counts{{}};
273
273
for (const UniValue& node : nodes) {
274
274
std::string network_name{node[" network" ].get_str ()};
275
275
const int8_t network_id{NetworkStringToId (network_name)};
@@ -279,8 +279,8 @@ class AddrinfoRequestHandler : public BaseRequestHandler
279
279
// Prepare result to return to user.
280
280
UniValue result{UniValue::VOBJ}, addresses{UniValue::VOBJ};
281
281
uint64_t total{0 }; // Total address count
282
- for (size_t i = 0 ; i < m_networks .size (); ++i) {
283
- addresses.pushKV (m_networks. at (i) , counts.at (i));
282
+ for (size_t i = 0 ; i < NETWORKS .size (); ++i) {
283
+ addresses.pushKV (NETWORKS[i] , counts.at (i));
284
284
total += counts.at (i);
285
285
}
286
286
addresses.pushKV (" total" , total);
@@ -363,14 +363,13 @@ class NetinfoRequestHandler : public BaseRequestHandler
363
363
{
364
364
private:
365
365
static constexpr uint8_t MAX_DETAIL_LEVEL{4 };
366
- static constexpr std::array m_networks{" ipv4" , " ipv6" , " onion" , " i2p" , " cjdns" };
367
- std::array<std::array<uint16_t , m_networks.size() + 1 >, 3 > m_counts{{{}}}; // !< Peer counts by (in/out/total, networks/total)
366
+ std::array<std::array<uint16_t , NETWORKS.size() + 1 >, 3 > m_counts{{{}}}; // !< Peer counts by (in/out/total, networks/total)
368
367
uint8_t m_block_relay_peers_count{0 };
369
368
uint8_t m_manual_peers_count{0 };
370
369
int8_t NetworkStringToId (const std::string& str) const
371
370
{
372
- for (size_t i = 0 ; i < m_networks .size (); ++i) {
373
- if (str == m_networks. at (i) ) return i;
371
+ for (size_t i = 0 ; i < NETWORKS .size (); ++i) {
372
+ if (str == NETWORKS[i] ) return i;
374
373
}
375
374
return UNKNOWN_NETWORK;
376
375
}
@@ -471,10 +470,10 @@ class NetinfoRequestHandler : public BaseRequestHandler
471
470
const bool is_outbound{!peer[" inbound" ].get_bool ()};
472
471
const bool is_block_relay{!peer[" relaytxes" ].get_bool ()};
473
472
const std::string conn_type{peer[" connection_type" ].get_str ()};
474
- ++m_counts.at (is_outbound).at (network_id); // in/out by network
475
- ++m_counts.at (is_outbound).at (m_networks .size ()); // in/out overall
476
- ++m_counts.at (2 ).at (network_id); // total by network
477
- ++m_counts.at (2 ).at (m_networks .size ()); // total overall
473
+ ++m_counts.at (is_outbound).at (network_id); // in/out by network
474
+ ++m_counts.at (is_outbound).at (NETWORKS .size ()); // in/out overall
475
+ ++m_counts.at (2 ).at (network_id); // total by network
476
+ ++m_counts.at (2 ).at (NETWORKS .size ()); // total overall
478
477
if (conn_type == " block-relay-only" ) ++m_block_relay_peers_count;
479
478
if (conn_type == " manual" ) ++m_manual_peers_count;
480
479
if (DetailsRequested ()) {
@@ -571,7 +570,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
571
570
for (int8_t n : reachable_networks) {
572
571
result += strprintf (" %8i" , m_counts.at (i).at (n)); // network peers count
573
572
}
574
- result += strprintf (" %5i" , m_counts.at (i).at (m_networks .size ())); // total peers count
573
+ result += strprintf (" %5i" , m_counts.at (i).at (NETWORKS .size ())); // total peers count
575
574
if (i == 1 ) { // the outbound row has two extra columns for block relay and manual peer counts
576
575
result += strprintf (" %5i" , m_block_relay_peers_count);
577
576
if (m_manual_peers_count) result += strprintf (" %5i" , m_manual_peers_count);
0 commit comments