diff options
author | Jon Atack <jon@atack.com> | 2020-10-16 11:59:27 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2020-10-25 16:22:55 +0100 |
commit | 33e987452f869c279f2491499939e51e0af8364c (patch) | |
tree | f6c5caef65a80ab13eadc1ac2d22047970ce581f /src | |
parent | f8a1c4d9469cb496fdafaf6f4d94977687df9190 (diff) |
cli -netinfo: make age column variable-width
as it has a wide possible range and the new name ("age" instead of "uptime") is
much shorter.
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoin-cli.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 59b07a7edc..59e7ef312b 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -14,6 +14,7 @@ #include <rpc/mining.h> #include <rpc/protocol.h> #include <rpc/request.h> +#include <tinyformat.h> #include <util/strencodings.h> #include <util/system.h> #include <util/translation.h> @@ -313,14 +314,15 @@ private: 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_age_length{4}; size_t m_max_id_length{2}; struct Peer { std::string addr; std::string sub_version; std::string network; + std::string age; double min_ping; double ping; - int64_t conn_time; int64_t last_blck; int64_t last_recv; int64_t last_send; @@ -399,10 +401,12 @@ public: const double min_ping{peer["minping"].isNull() ? -1 : peer["minping"].get_real()}; const double ping{peer["pingtime"].isNull() ? -1 : peer["pingtime"].get_real()}; const std::string addr{peer["addr"].get_str()}; + const std::string age{conn_time == 0 ? "" : ToString((m_time_now - conn_time) / 60)}; const std::string sub_version{peer["subver"].get_str()}; - m_peers.push_back({addr, sub_version, network, min_ping, ping, conn_time, last_blck, last_recv, last_send, last_trxn, peer_id, mapped_as, version, is_block_relay, is_outbound}); - m_max_id_length = std::max(ToString(peer_id).length(), m_max_id_length); + m_peers.push_back({addr, sub_version, network, age, min_ping, ping, last_blck, last_recv, last_send, last_trxn, peer_id, mapped_as, version, is_block_relay, is_outbound}); m_max_addr_length = std::max(addr.length() + 1, m_max_addr_length); + m_max_age_length = std::max(age.length(), m_max_age_length); + m_max_id_length = std::max(ToString(peer_id).length(), m_max_id_length); m_is_asmap_on |= (mapped_as != 0); } } @@ -413,13 +417,13 @@ public: // Report detailed peer connections list sorted by direction and minimum ping time. if (DetailsRequested() && !m_peers.empty()) { std::sort(m_peers.begin(), m_peers.end()); - result += "Peer connections sorted by direction and min ping\n<-> relay net mping ping send recv txn blk age "; + result += strprintf("Peer connections sorted by direction and min ping\n<-> relay net mping ping send recv txn blk %*s ", m_max_age_length, "age"); if (m_is_asmap_on) result += " asmap "; result += strprintf("%*s %-*s%s\n", m_max_id_length, "id", IsAddressSelected() ? m_max_addr_length : 0, IsAddressSelected() ? "address" : "", IsVersionSelected() ? "version" : ""); for (const Peer& peer : m_peers) { std::string version{ToString(peer.version) + peer.sub_version}; result += strprintf( - "%3s %5s %5s%7s%7s%5s%5s%5s%5s%7s%*i %*s %-*s%s\n", + "%3s %5s %5s%7s%7s%5s%5s%5s%5s %*s%*i %*s %-*s%s\n", peer.is_outbound ? "out" : "in", peer.is_block_relay ? "block" : "full", peer.network, @@ -429,7 +433,8 @@ public: peer.last_recv == 0 ? "" : ToString(m_time_now - peer.last_recv), peer.last_trxn == 0 ? "" : ToString((m_time_now - peer.last_trxn) / 60), peer.last_blck == 0 ? "" : ToString((m_time_now - peer.last_blck) / 60), - peer.conn_time == 0 ? "" : ToString((m_time_now - peer.conn_time) / 60), + m_max_age_length, // variable spacing + peer.age, m_is_asmap_on ? 7 : 0, // variable spacing m_is_asmap_on && peer.mapped_as != 0 ? ToString(peer.mapped_as) : "", m_max_id_length, // variable spacing @@ -438,7 +443,7 @@ public: IsAddressSelected() ? peer.addr : "", IsVersionSelected() && version != "0" ? version : ""); } - result += " ms ms sec sec min min min\n\n"; + result += strprintf(" ms ms sec sec min min %*s\n\n", m_max_age_length, "min"); } // Report peer connection totals by type. |