From 398045ba8b3694931069f88ec95553b3207dd1a6 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sun, 25 Oct 2020 15:11:41 +0100 Subject: [PATCH] cli -netinfo: print oversized/extreme ping times as "-" --- src/bitcoin-cli.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 8e17319425..ef4641cb63 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -343,6 +343,12 @@ private: if (gArgs.GetChainName() == CBaseChainParams::REGTEST) return " regtest"; return ""; } + std::string PingTimeToString(double seconds) const + { + if (seconds < 0) return ""; + const double milliseconds{round(1000 * seconds)}; + return milliseconds > 999999 ? "-" : ToString(milliseconds); + } const int64_t m_time_now{GetSystemTimeInSeconds()}; public: @@ -428,8 +434,8 @@ public: peer.is_outbound ? "out" : "in", peer.is_block_relay ? "block" : "full", peer.network, - peer.min_ping == -1 ? "" : ToString(round(1000 * peer.min_ping)), - peer.ping == -1 ? "" : ToString(round(1000 * peer.ping)), + PingTimeToString(peer.min_ping), + PingTimeToString(peer.ping), peer.last_send == 0 ? "" : ToString(m_time_now - peer.last_send), peer.last_recv == 0 ? "" : ToString(m_time_now - peer.last_recv), peer.last_trxn == 0 ? "" : ToString((m_time_now - peer.last_trxn) / 60),