Skip to content

Commit 76d198a

Browse files
committed
netinfo: add i2p network
the i2p peer counts column is displayed iff the node is connected to at least one i2p peer, so this doesn't add clutter for users who are not running an i2p service
1 parent 9d6aeca commit 76d198a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/bitcoin-cli.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,9 @@ class NetinfoRequestHandler : public BaseRequestHandler
300300
{
301301
private:
302302
static constexpr int8_t UNKNOWN_NETWORK{-1};
303-
static constexpr uint8_t m_networks_size{3};
304-
const std::array<std::string, m_networks_size> m_networks{{"ipv4", "ipv6", "onion"}};
303+
static constexpr int8_t NET_I2P{3}; // pos of "i2p" in m_networks
304+
static constexpr uint8_t m_networks_size{4};
305+
const std::array<std::string, m_networks_size> m_networks{{"ipv4", "ipv6", "onion", "i2p"}};
305306
std::array<std::array<uint16_t, m_networks_size + 2>, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total/block-relay)
306307
uint8_t m_manual_peers_count{0};
307308
int8_t NetworkStringToId(const std::string& str) const
@@ -317,6 +318,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
317318
bool IsAddressSelected() const { return m_details_level == 2 || m_details_level == 4; }
318319
bool IsVersionSelected() const { return m_details_level == 3 || m_details_level == 4; }
319320
bool m_is_asmap_on{false};
321+
bool m_is_i2p_on{false};
320322
size_t m_max_addr_length{0};
321323
size_t m_max_age_length{3};
322324
size_t m_max_id_length{2};
@@ -468,6 +470,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
468470
const std::string network{peer["network"].get_str()};
469471
const int8_t network_id{NetworkStringToId(network)};
470472
if (network_id == UNKNOWN_NETWORK) continue;
473+
m_is_i2p_on |= (network_id == NET_I2P);
471474
const bool is_outbound{!peer["inbound"].get_bool()};
472475
const bool is_block_relay{!peer["relaytxes"].get_bool()};
473476
const std::string conn_type{peer["connection_type"].get_str()};
@@ -542,11 +545,15 @@ class NetinfoRequestHandler : public BaseRequestHandler
542545
}
543546

544547
// Report peer connection totals by type.
545-
result += " ipv4 ipv6 onion total block";
548+
result += " ipv4 ipv6 onion";
549+
if (m_is_i2p_on) result += " i2p";
550+
result += " total block";
546551
if (m_manual_peers_count) result += " manual";
547552
const std::array<std::string, 3> rows{{"in", "out", "total"}};
548-
for (uint8_t i = 0; i < m_networks_size; ++i) {
549-
result += strprintf("\n%-5s %5i %5i %5i %5i %5i", rows.at(i), m_counts.at(i).at(0), m_counts.at(i).at(1), m_counts.at(i).at(2), m_counts.at(i).at(m_networks_size), m_counts.at(i).at(m_networks_size + 1));
553+
for (uint8_t i = 0; i < 3; ++i) {
554+
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
555+
if (m_is_i2p_on) result += strprintf(" %5i", m_counts.at(i).at(3)); // i2p peers count
556+
result += strprintf(" %5i %5i", m_counts.at(i).at(m_networks_size), m_counts.at(i).at(m_networks_size + 1));
550557
if (i == 1 && m_manual_peers_count) result += strprintf(" %5i", m_manual_peers_count);
551558
}
552559

0 commit comments

Comments
 (0)