diff options
author | Jon Atack <jon@atack.com> | 2020-08-13 17:13:14 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2020-08-31 16:12:44 +0200 |
commit | ce57bf6cc0cdaf8233fd8a20e0d1c5b69d17d2a3 (patch) | |
tree | d218c0c0e1be5ff576d42271f98482cc26eb9fa2 /src/bitcoin-cli.cpp | |
parent | f5edd66e5d136b229c805af9e6ea73218f6cedde (diff) |
cli: create peer connections report sorted by dir, minping
Diffstat (limited to 'src/bitcoin-cli.cpp')
-rw-r--r-- | src/bitcoin-cli.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index e50d9c43fa..ad514e7939 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -374,8 +374,11 @@ public: if (!batch[ID_NETWORKINFO]["error"].isNull()) return batch[ID_NETWORKINFO]; // Count peer connection totals, and if m_verbose is true, store peer data in a vector of structs. + const int64_t time_now{GetSystemTimeInSeconds()}; int ipv4_i{0}, ipv6_i{0}, onion_i{0}, block_relay_i{0}, total_i{0}; // inbound conn counters int ipv4_o{0}, ipv6_o{0}, onion_o{0}, block_relay_o{0}, total_o{0}; // outbound conn counters + size_t max_peer_id_length{2}, max_version_length{1}; + bool is_asmap_on{false}; std::vector<Peer> peers; const UniValue& getpeerinfo{batch[ID_PEERINFO]["result"]}; @@ -420,6 +423,9 @@ public: const double min_ping{peer["minping"].isNull() ? -1 : peer["minping"].get_real()}; const double ping{peer["pingtime"].isNull() ? -1 : peer["pingtime"].get_real()}; peers.push_back({peer_id, mapped_as, version, conn_time, last_recv, last_send, min_ping, ping, addr, sub_version, net_type, is_block_relay, !is_inbound}); + max_peer_id_length = std::max(ToString(peer_id).length(), max_peer_id_length); + max_version_length = std::max((ToString(version) + sub_version).length(), max_version_length); + is_asmap_on |= (mapped_as != 0); } } @@ -427,6 +433,35 @@ public: const UniValue& networkinfo{batch[ID_NETWORKINFO]["result"]}; std::string result{strprintf("%s %s%s - %i%s\n\n", PACKAGE_NAME, FormatFullVersion(), ChainToString(), networkinfo["protocolversion"].get_int(), networkinfo["subversion"].get_str())}; + // Report detailed peer connections list sorted by direction and minimum ping time. + if (m_verbose && !peers.empty()) { + std::sort(peers.begin(), peers.end()); + result += "Peer connections sorted by direction and min ping\n<-> relay net minping ping lastsend lastrecv uptime "; + if (is_asmap_on) result += " asmap "; + result += strprintf("%*s %-*s address\n", max_peer_id_length, "id", max_version_length, "version"); + for (const Peer& peer : peers) { + std::string version{ToString(peer.version) + peer.sub_version}; + result += strprintf( + "%3s %5s %5s%8s%7s %8s %8s%7s%*i %*s %-*s %s\n", + peer.is_outbound ? "out" : "in", + peer.is_block_relay ? "block" : "full", + NetTypeEnumToString(peer.net_type), + peer.min_ping == -1 ? "" : ToString(round(1000 * peer.min_ping)), + peer.ping == -1 ? "" : ToString(round(1000 * peer.ping)), + peer.last_send == 0 ? "" : ToString(time_now - peer.last_send), + peer.last_recv == 0 ? "" : ToString(time_now - peer.last_recv), + peer.conn_time == 0 ? "" : ToString((time_now - peer.conn_time) / 60), + is_asmap_on ? 7 : 0, // variable spacing + is_asmap_on && peer.mapped_as != 0 ? ToString(peer.mapped_as) : "", + max_peer_id_length, // variable spacing + peer.id, + max_version_length, // variable spacing + version == "0" ? "" : version, + peer.addr); + } + result += " ms ms sec sec min\n\n"; + } + // Report peer connection totals by type. total_i = ipv4_i + ipv6_i + onion_i; total_o = ipv4_o + ipv6_o + onion_o; |