diff options
author | Jon Atack <jon@atack.com> | 2020-08-13 16:49:39 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2020-08-31 16:12:04 +0200 |
commit | 3a0ab93e1ce8d91235a6d46a57c6cb110fc5bf03 (patch) | |
tree | c41dbf5dc2a71148c94284ad38bce5e62eabe56e | |
parent | c227100919dd2422b29eb3bca9c0f1a7983cc3a8 (diff) | |
download | bitcoin-3a0ab93e1ce8d91235a6d46a57c6cb110fc5bf03.tar.xz |
cli: add NetType enum struct and NetTypeEnumToString()
-rw-r--r-- | src/bitcoin-cli.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index ac59665c12..b9877f5126 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -315,6 +315,20 @@ private: (onion_pos == addr_len - ONION_LEN || onion_pos == addr.find_last_of(":") - ONION_LEN); } bool m_verbose{false}; //!< Whether user requested verbose -netinfo report + enum struct NetType { + ipv4, + ipv6, + onion, + }; + std::string NetTypeEnumToString(NetType t) + { + switch (t) { + case NetType::ipv4: return "ipv4"; + case NetType::ipv6: return "ipv6"; + case NetType::onion: return "onion"; + } // no default case, so the compiler can warn about missing cases + assert(false); + } std::string ChainToString() const { if (gArgs.GetChainName() == CBaseChainParams::TESTNET) return " testnet"; @@ -354,10 +368,13 @@ public: const int mapped_as{peer["mapped_as"].isNull() ? 0 : peer["mapped_as"].get_int()}; const bool is_block_relay{!peer["relaytxes"].get_bool()}; const bool is_inbound{peer["inbound"].get_bool()}; + NetType net_type{NetType::ipv4}; if (is_inbound) { if (IsAddrIPv6(addr)) { + net_type = NetType::ipv6; ++ipv6_i; } else if (IsInboundOnion(addr_local, mapped_as)) { + net_type = NetType::onion; ++onion_i; } else { ++ipv4_i; @@ -365,8 +382,10 @@ public: if (is_block_relay) ++block_relay_i; } else { if (IsAddrIPv6(addr)) { + net_type = NetType::ipv6; ++ipv6_o; } else if (IsOutboundOnion(addr, mapped_as)) { + net_type = NetType::onion; ++onion_o; } else { ++ipv4_o; |