Skip to content

Commit 683b558

Browse files
committed
netinfo: allow setting an outbound-only peer list
to keep the output within screen limits when running as a live dashboard, i.e. with `watch`.
1 parent 102995b commit 683b558

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/bitcoin-cli.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ class GetinfoRequestHandler: public BaseRequestHandler
379379
class NetinfoRequestHandler : public BaseRequestHandler
380380
{
381381
private:
382-
static constexpr uint8_t MAX_DETAIL_LEVEL{4};
382+
static constexpr uint8_t MAX_DETAIL_LEVEL{5};
383383
std::array<std::array<uint16_t, NETWORKS.size() + 1>, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total)
384384
uint8_t m_block_relay_peers_count{0};
385385
uint8_t m_manual_peers_count{0};
@@ -391,9 +391,10 @@ class NetinfoRequestHandler : public BaseRequestHandler
391391
return UNKNOWN_NETWORK;
392392
}
393393
uint8_t m_details_level{0}; //!< Optional user-supplied arg to set dashboard details level
394-
bool DetailsRequested() const { return m_details_level > 0 && m_details_level < 5; }
395-
bool IsAddressSelected() const { return m_details_level == 2 || m_details_level == 4; }
396-
bool IsVersionSelected() const { return m_details_level == 3 || m_details_level == 4; }
394+
bool DetailsRequested() const { return m_details_level > 0 && m_details_level <= MAX_DETAIL_LEVEL; }
395+
bool IsAddressSelected() const { return m_details_level == 2 || m_details_level >= 4; }
396+
bool IsVersionSelected() const { return m_details_level >= 3; }
397+
bool OutboundOnlySelected() const { return m_details_level == 5; }
397398
bool m_is_asmap_on{false};
398399
size_t m_max_addr_length{0};
399400
size_t m_max_addr_processed_length{5};
@@ -477,7 +478,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
477478
if (!args.empty()) {
478479
uint8_t n{0};
479480
if (ParseUInt8(args.at(0), &n)) {
480-
m_details_level = std::min(n, MAX_DETAIL_LEVEL);
481+
m_details_level = (n <= MAX_DETAIL_LEVEL) ? n : 4;
481482
} else {
482483
throw std::runtime_error(strprintf("invalid -netinfo argument: %s\nFor more information, run: bitcoin-cli -netinfo help", args.at(0)));
483484
}
@@ -514,6 +515,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
514515
++m_counts.at(2).at(NETWORKS.size()); // total overall
515516
if (conn_type == "block-relay-only") ++m_block_relay_peers_count;
516517
if (conn_type == "manual") ++m_manual_peers_count;
518+
if (!is_outbound && OutboundOnlySelected()) continue;
517519
if (DetailsRequested()) {
518520
// Push data for this peer to the peers vector.
519521
const int peer_id{peer["id"].getInt<int>()};
@@ -664,6 +666,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
664666
" 2 - Like 1 but with an address column\n"
665667
" 3 - Like 1 but with a version column\n"
666668
" 4 - Like 1 but with both address and version columns\n"
669+
" 5 - Like 4 but limited to outbound peers only, to save screen space\n"
667670
"2. help (string \"help\", optional) Print this help documentation instead of the dashboard.\n\n"
668671
"Result:\n\n"
669672
+ 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) +

0 commit comments

Comments
 (0)