Skip to content

Commit ef614bb

Browse files
committed
cli: small -netinfo simplification and performance improvement
that removes code and particularly this code from the loop of all peers: `m_is_i2p_on |= (network_id == NET_I2P);`
1 parent 6b45ef3 commit ef614bb

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/bitcoin-cli.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ class NetinfoRequestHandler : public BaseRequestHandler
300300
{
301301
private:
302302
static constexpr int8_t UNKNOWN_NETWORK{-1};
303-
static constexpr int8_t NET_I2P{3}; // pos of "i2p" in m_networks
304303
static constexpr uint8_t m_networks_size{4};
305304
static constexpr uint8_t MAX_DETAIL_LEVEL{4};
306305
const std::array<std::string, m_networks_size> m_networks{{"ipv4", "ipv6", "onion", "i2p"}};
@@ -319,7 +318,6 @@ class NetinfoRequestHandler : public BaseRequestHandler
319318
bool IsAddressSelected() const { return m_details_level == 2 || m_details_level == 4; }
320319
bool IsVersionSelected() const { return m_details_level == 3 || m_details_level == 4; }
321320
bool m_is_asmap_on{false};
322-
bool m_is_i2p_on{false};
323321
size_t m_max_addr_length{0};
324322
size_t m_max_age_length{3};
325323
size_t m_max_id_length{2};
@@ -404,7 +402,6 @@ class NetinfoRequestHandler : public BaseRequestHandler
404402
const std::string network{peer["network"].get_str()};
405403
const int8_t network_id{NetworkStringToId(network)};
406404
if (network_id == UNKNOWN_NETWORK) continue;
407-
m_is_i2p_on |= (network_id == NET_I2P);
408405
const bool is_outbound{!peer["inbound"].get_bool()};
409406
const bool is_block_relay{!peer["relaytxes"].get_bool()};
410407
const std::string conn_type{peer["connection_type"].get_str()};
@@ -477,13 +474,14 @@ class NetinfoRequestHandler : public BaseRequestHandler
477474

478475
// Report peer connection totals by type.
479476
result += " ipv4 ipv6 onion";
480-
if (m_is_i2p_on) result += " i2p";
477+
const bool any_i2p_peers = m_counts.at(2).at(3); // false if total i2p peers count is 0, otherwise true
478+
if (any_i2p_peers) result += " i2p";
481479
result += " total block";
482480
if (m_manual_peers_count) result += " manual";
483481
const std::array<std::string, 3> rows{{"in", "out", "total"}};
484482
for (uint8_t i = 0; i < 3; ++i) {
485483
result += strprintf("\n%-5s %5i %5i %5i", rows.at(i), m_counts.at(i).at(0), m_counts.at(i).at(1), m_counts.at(i).at(2)); // ipv4/ipv6/onion peers counts
486-
if (m_is_i2p_on) result += strprintf(" %5i", m_counts.at(i).at(3)); // i2p peers count
484+
if (any_i2p_peers) result += strprintf(" %5i", m_counts.at(i).at(3)); // i2p peers count
487485
result += strprintf(" %5i", m_counts.at(i).at(m_networks_size)); // total peers count
488486
if (i == 1) { // the outbound row has two extra columns for block relay and manual peer counts
489487
result += strprintf(" %5i", m_block_relay_peers_count);

0 commit comments

Comments
 (0)