Skip to content

Commit 9d6aeca

Browse files
committed
netinfo: add bip152 high-bandwidth to/from fields
1 parent 5de7a6c commit 9d6aeca

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/bitcoin-cli.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
318318
bool IsVersionSelected() const { return m_details_level == 3 || m_details_level == 4; }
319319
bool m_is_asmap_on{false};
320320
size_t m_max_addr_length{0};
321-
size_t m_max_age_length{4};
321+
size_t m_max_age_length{3};
322322
size_t m_max_id_length{2};
323323
struct Peer {
324324
std::string addr;
@@ -335,6 +335,8 @@ class NetinfoRequestHandler : public BaseRequestHandler
335335
int id;
336336
int mapped_as;
337337
int version;
338+
bool is_bip152_hb_from;
339+
bool is_bip152_hb_to;
338340
bool is_block_relay;
339341
bool is_outbound;
340342
bool operator<(const Peer& rhs) const { return std::tie(is_outbound, min_ping) < std::tie(rhs.is_outbound, rhs.min_ping); }
@@ -399,6 +401,9 @@ class NetinfoRequestHandler : public BaseRequestHandler
399401
" recv Time since last message received from the peer, in seconds\n"
400402
" txn Time since last novel transaction received from the peer and accepted into our mempool, in minutes\n"
401403
" blk Time since last novel block passing initial validity checks received from the peer, in minutes\n"
404+
" hb High-bandwidth BIP152 compact block relay\n"
405+
" \".\" (to) - we selected the peer as a high-bandwidth peer\n"
406+
" \"*\" (from) - the peer selected us as a high-bandwidth peer\n"
402407
" age Duration of connection to the peer, in minutes\n"
403408
" asmap Mapped AS (Autonomous System) number in the BGP route to the peer, used for diversifying\n"
404409
" peer selection (only displayed if the -asmap config option is set)\n"
@@ -490,7 +495,9 @@ class NetinfoRequestHandler : public BaseRequestHandler
490495
const std::string addr{peer["addr"].get_str()};
491496
const std::string age{conn_time == 0 ? "" : ToString((m_time_now - conn_time) / 60)};
492497
const std::string sub_version{peer["subver"].get_str()};
493-
m_peers.push_back({addr, sub_version, conn_type, network, age, min_ping, ping, last_blck, last_recv, last_send, last_trxn, peer_id, mapped_as, version, is_block_relay, is_outbound});
498+
const bool is_bip152_hb_from{peer["bip152_hb_from"].get_bool()};
499+
const bool is_bip152_hb_to{peer["bip152_hb_to"].get_bool()};
500+
m_peers.push_back({addr, sub_version, conn_type, network, age, min_ping, ping, last_blck, last_recv, last_send, last_trxn, peer_id, mapped_as, version, is_bip152_hb_from, is_bip152_hb_to, is_block_relay, is_outbound});
494501
m_max_addr_length = std::max(addr.length() + 1, m_max_addr_length);
495502
m_max_age_length = std::max(age.length(), m_max_age_length);
496503
m_max_id_length = std::max(ToString(peer_id).length(), m_max_id_length);
@@ -504,13 +511,13 @@ class NetinfoRequestHandler : public BaseRequestHandler
504511
// Report detailed peer connections list sorted by direction and minimum ping time.
505512
if (DetailsRequested() && !m_peers.empty()) {
506513
std::sort(m_peers.begin(), m_peers.end());
507-
result += strprintf("<-> type net mping ping send recv txn blk %*s ", m_max_age_length, "age");
514+
result += strprintf("<-> type net mping ping send recv txn blk hb %*s ", m_max_age_length, "age");
508515
if (m_is_asmap_on) result += " asmap ";
509516
result += strprintf("%*s %-*s%s\n", m_max_id_length, "id", IsAddressSelected() ? m_max_addr_length : 0, IsAddressSelected() ? "address" : "", IsVersionSelected() ? "version" : "");
510517
for (const Peer& peer : m_peers) {
511518
std::string version{ToString(peer.version) + peer.sub_version};
512519
result += strprintf(
513-
"%3s %6s %5s%7s%7s%5s%5s%5s%5s %*s%*i %*s %-*s%s\n",
520+
"%3s %6s %5s%7s%7s%5s%5s%5s%5s %2s %*s%*i %*s %-*s%s\n",
514521
peer.is_outbound ? "out" : "in",
515522
ConnectionTypeForNetinfo(peer.conn_type),
516523
peer.network,
@@ -520,6 +527,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
520527
peer.last_recv == 0 ? "" : ToString(m_time_now - peer.last_recv),
521528
peer.last_trxn == 0 ? "" : ToString((m_time_now - peer.last_trxn) / 60),
522529
peer.last_blck == 0 ? "" : ToString((m_time_now - peer.last_blck) / 60),
530+
strprintf("%s%s", peer.is_bip152_hb_to ? "." : " ", peer.is_bip152_hb_from ? "*" : " "),
523531
m_max_age_length, // variable spacing
524532
peer.age,
525533
m_is_asmap_on ? 7 : 0, // variable spacing
@@ -530,7 +538,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
530538
IsAddressSelected() ? peer.addr : "",
531539
IsVersionSelected() && version != "0" ? version : "");
532540
}
533-
result += strprintf(" ms ms sec sec min min %*s\n\n", m_max_age_length, "min");
541+
result += strprintf(" ms ms sec sec min min %*s\n\n", m_max_age_length, "min");
534542
}
535543

536544
// Report peer connection totals by type.

0 commit comments

Comments
 (0)