Skip to content

Commit 3a0ab93

Browse files
committed
cli: add NetType enum struct and NetTypeEnumToString()
1 parent c227100 commit 3a0ab93

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/bitcoin-cli.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,20 @@ class NetinfoRequestHandler : public BaseRequestHandler
315315
(onion_pos == addr_len - ONION_LEN || onion_pos == addr.find_last_of(":") - ONION_LEN);
316316
}
317317
bool m_verbose{false}; //!< Whether user requested verbose -netinfo report
318+
enum struct NetType {
319+
ipv4,
320+
ipv6,
321+
onion,
322+
};
323+
std::string NetTypeEnumToString(NetType t)
324+
{
325+
switch (t) {
326+
case NetType::ipv4: return "ipv4";
327+
case NetType::ipv6: return "ipv6";
328+
case NetType::onion: return "onion";
329+
} // no default case, so the compiler can warn about missing cases
330+
assert(false);
331+
}
318332
std::string ChainToString() const
319333
{
320334
if (gArgs.GetChainName() == CBaseChainParams::TESTNET) return " testnet";
@@ -354,19 +368,24 @@ class NetinfoRequestHandler : public BaseRequestHandler
354368
const int mapped_as{peer["mapped_as"].isNull() ? 0 : peer["mapped_as"].get_int()};
355369
const bool is_block_relay{!peer["relaytxes"].get_bool()};
356370
const bool is_inbound{peer["inbound"].get_bool()};
371+
NetType net_type{NetType::ipv4};
357372
if (is_inbound) {
358373
if (IsAddrIPv6(addr)) {
374+
net_type = NetType::ipv6;
359375
++ipv6_i;
360376
} else if (IsInboundOnion(addr_local, mapped_as)) {
377+
net_type = NetType::onion;
361378
++onion_i;
362379
} else {
363380
++ipv4_i;
364381
}
365382
if (is_block_relay) ++block_relay_i;
366383
} else {
367384
if (IsAddrIPv6(addr)) {
385+
net_type = NetType::ipv6;
368386
++ipv6_o;
369387
} else if (IsOutboundOnion(addr, mapped_as)) {
388+
net_type = NetType::onion;
370389
++onion_o;
371390
} else {
372391
++ipv4_o;

0 commit comments

Comments
 (0)