Skip to content

Commit

Permalink
netinfo: allow setting an outbound-only peer list
Browse files Browse the repository at this point in the history
to keep the output within screen limits when running as a live dashboard,
i.e. with `watch`.
  • Loading branch information
jonatack committed Sep 19, 2024
1 parent 5e30009 commit 18fcca4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class GetinfoRequestHandler: public BaseRequestHandler
class NetinfoRequestHandler : public BaseRequestHandler
{
private:
static constexpr uint8_t MAX_DETAIL_LEVEL{4};
static constexpr uint8_t MAX_DETAIL_LEVEL{5};
std::array<std::array<uint16_t, NETWORKS.size() + 1>, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total)
uint8_t m_block_relay_peers_count{0};
uint8_t m_manual_peers_count{0};
Expand All @@ -391,9 +391,10 @@ class NetinfoRequestHandler : public BaseRequestHandler
return UNKNOWN_NETWORK;
}
uint8_t m_details_level{0}; //!< Optional user-supplied arg to set dashboard details level
bool DetailsRequested() const { return m_details_level > 0 && m_details_level < 5; }
bool IsAddressSelected() const { return m_details_level == 2 || m_details_level == 4; }
bool IsVersionSelected() const { return m_details_level == 3 || m_details_level == 4; }
bool OutboundOnlySelected() const { return m_details_level == 5; }
bool DetailsRequested() const { return m_details_level > 0 && m_details_level <= MAX_DETAIL_LEVEL; }
bool IsAddressSelected() const { return m_details_level == 2 || m_details_level >= 4; }
bool IsVersionSelected() const { return m_details_level == 3 || m_details_level >= 4; }
bool m_is_asmap_on{false};
size_t m_max_addr_length{0};
size_t m_max_addr_processed_length{5};
Expand Down Expand Up @@ -477,7 +478,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
if (!args.empty()) {
uint8_t n{0};
if (ParseUInt8(args.at(0), &n)) {
m_details_level = std::min(n, MAX_DETAIL_LEVEL);
m_details_level = (n <= MAX_DETAIL_LEVEL) ? n : 4;
} else {
throw std::runtime_error(strprintf("invalid -netinfo argument: %s\nFor more information, run: bitcoin-cli -netinfo help", args.at(0)));
}
Expand Down Expand Up @@ -514,6 +515,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
++m_counts.at(2).at(NETWORKS.size()); // total overall
if (conn_type == "block-relay-only") ++m_block_relay_peers_count;
if (conn_type == "manual") ++m_manual_peers_count;
if (!is_outbound && OutboundOnlySelected()) continue;
if (DetailsRequested()) {
// Push data for this peer to the peers vector.
const int peer_id{peer["id"].getInt<int>()};
Expand Down Expand Up @@ -662,6 +664,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
" 2 - Like 1 but with an address column\n"
" 3 - Like 1 but with a version column\n"
" 4 - Like 1 but with both address and version columns\n"
" 5 - Like 4 but limited to outbound peers only, to save screen space\n"
"2. help (string \"help\", optional) Print this help documentation instead of the dashboard.\n\n"
"Result:\n\n"
+ strprintf("* The peers listing in levels 1-%d displays all of the peers sorted by direction and minimum ping time:\n\n", MAX_DETAIL_LEVEL) +
Expand Down

0 comments on commit 18fcca4

Please sign in to comment.