cli -netinfo: print oversized/extreme ping times as "-"

This commit is contained in:
Jon Atack 2020-10-25 15:11:41 +01:00
parent 773f4c99c0
commit 398045ba8b
No known key found for this signature in database
GPG key ID: 4F5721B3D0E3921D

View file

@ -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),