From 5bd40a3e84a35e0cdf802b132dac5725b9558f32 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Mon, 4 Oct 2021 16:13:05 +0200 Subject: cli: add cjdns network to -addrinfo and -netinfo --- src/bitcoin-cli.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 338d32ef6b..9ebad02389 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -242,7 +242,7 @@ public: class AddrinfoRequestHandler : public BaseRequestHandler { private: - static constexpr std::array m_networks{"ipv4", "ipv6", "onion", "i2p"}; + static constexpr std::array m_networks{"ipv4", "ipv6", "onion", "i2p", "cjdns"}; int8_t NetworkStringToId(const std::string& str) const { for (size_t i = 0; i < m_networks.size(); ++i) { @@ -363,7 +363,7 @@ class NetinfoRequestHandler : public BaseRequestHandler { private: static constexpr uint8_t MAX_DETAIL_LEVEL{4}; - static constexpr std::array m_networks{"ipv4", "ipv6", "onion", "i2p"}; + static constexpr std::array m_networks{"ipv4", "ipv6", "onion", "i2p", "cjdns"}; std::array, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total) uint8_t m_block_relay_peers_count{0}; uint8_t m_manual_peers_count{0}; -- cgit v1.2.3 From 7b6528746acf9c915d7157bb860ec899b58dded7 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Mon, 4 Oct 2021 16:17:01 +0200 Subject: cli: hoist networks class data members to a constant --- src/bitcoin-cli.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 9ebad02389..279521a761 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -49,6 +49,7 @@ static constexpr int DEFAULT_WAIT_CLIENT_TIMEOUT = 0; static const bool DEFAULT_NAMED=false; static const int CONTINUE_EXECUTION=-1; static constexpr int8_t UNKNOWN_NETWORK{-1}; +static constexpr std::array NETWORKS{"ipv4", "ipv6", "onion", "i2p", "cjdns"}; /** Default number of blocks to generate for RPC generatetoaddress. */ static const std::string DEFAULT_NBLOCKS = "1"; @@ -242,11 +243,10 @@ public: class AddrinfoRequestHandler : public BaseRequestHandler { private: - static constexpr std::array m_networks{"ipv4", "ipv6", "onion", "i2p", "cjdns"}; int8_t NetworkStringToId(const std::string& str) const { - for (size_t i = 0; i < m_networks.size(); ++i) { - if (str == m_networks.at(i)) return i; + for (size_t i = 0; i < NETWORKS.size(); ++i) { + if (str == NETWORKS[i]) return i; } return UNKNOWN_NETWORK; } @@ -269,7 +269,7 @@ public: throw std::runtime_error("-addrinfo requires bitcoind server to be running v22.0 and up"); } // Count the number of peers known to our node, by network. - std::array counts{{}}; + std::array counts{{}}; for (const UniValue& node : nodes) { std::string network_name{node["network"].get_str()}; const int8_t network_id{NetworkStringToId(network_name)}; @@ -279,8 +279,8 @@ public: // Prepare result to return to user. UniValue result{UniValue::VOBJ}, addresses{UniValue::VOBJ}; uint64_t total{0}; // Total address count - for (size_t i = 0; i < m_networks.size(); ++i) { - addresses.pushKV(m_networks.at(i), counts.at(i)); + for (size_t i = 0; i < NETWORKS.size(); ++i) { + addresses.pushKV(NETWORKS[i], counts.at(i)); total += counts.at(i); } addresses.pushKV("total", total); @@ -363,14 +363,13 @@ class NetinfoRequestHandler : public BaseRequestHandler { private: static constexpr uint8_t MAX_DETAIL_LEVEL{4}; - static constexpr std::array m_networks{"ipv4", "ipv6", "onion", "i2p", "cjdns"}; - std::array, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total) + std::array, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total) uint8_t m_block_relay_peers_count{0}; uint8_t m_manual_peers_count{0}; int8_t NetworkStringToId(const std::string& str) const { - for (size_t i = 0; i < m_networks.size(); ++i) { - if (str == m_networks.at(i)) return i; + for (size_t i = 0; i < NETWORKS.size(); ++i) { + if (str == NETWORKS[i]) return i; } return UNKNOWN_NETWORK; } @@ -471,10 +470,10 @@ public: const bool is_outbound{!peer["inbound"].get_bool()}; const bool is_block_relay{!peer["relaytxes"].get_bool()}; const std::string conn_type{peer["connection_type"].get_str()}; - ++m_counts.at(is_outbound).at(network_id); // in/out by network - ++m_counts.at(is_outbound).at(m_networks.size()); // in/out overall - ++m_counts.at(2).at(network_id); // total by network - ++m_counts.at(2).at(m_networks.size()); // total overall + ++m_counts.at(is_outbound).at(network_id); // in/out by network + ++m_counts.at(is_outbound).at(NETWORKS.size()); // in/out overall + ++m_counts.at(2).at(network_id); // total by network + ++m_counts.at(2).at(NETWORKS.size()); // total overall if (conn_type == "block-relay-only") ++m_block_relay_peers_count; if (conn_type == "manual") ++m_manual_peers_count; if (DetailsRequested()) { @@ -571,7 +570,7 @@ public: for (int8_t n : reachable_networks) { result += strprintf("%8i", m_counts.at(i).at(n)); // network peers count } - result += strprintf(" %5i", m_counts.at(i).at(m_networks.size())); // total peers count + result += strprintf(" %5i", m_counts.at(i).at(NETWORKS.size())); // total peers count if (i == 1) { // the outbound row has two extra columns for block relay and manual peer counts result += strprintf(" %5i", m_block_relay_peers_count); if (m_manual_peers_count) result += strprintf(" %5i", m_manual_peers_count); -- cgit v1.2.3