Skip to content

Commit 398045b

Browse files
committed
cli -netinfo: print oversized/extreme ping times as "-"
1 parent 773f4c9 commit 398045b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/bitcoin-cli.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ class NetinfoRequestHandler : public BaseRequestHandler
343343
if (gArgs.GetChainName() == CBaseChainParams::REGTEST) return " regtest";
344344
return "";
345345
}
346+
std::string PingTimeToString(double seconds) const
347+
{
348+
if (seconds < 0) return "";
349+
const double milliseconds{round(1000 * seconds)};
350+
return milliseconds > 999999 ? "-" : ToString(milliseconds);
351+
}
346352
const int64_t m_time_now{GetSystemTimeInSeconds()};
347353

348354
public:
@@ -428,8 +434,8 @@ class NetinfoRequestHandler : public BaseRequestHandler
428434
peer.is_outbound ? "out" : "in",
429435
peer.is_block_relay ? "block" : "full",
430436
peer.network,
431-
peer.min_ping == -1 ? "" : ToString(round(1000 * peer.min_ping)),
432-
peer.ping == -1 ? "" : ToString(round(1000 * peer.ping)),
437+
PingTimeToString(peer.min_ping),
438+
PingTimeToString(peer.ping),
433439
peer.last_send == 0 ? "" : ToString(m_time_now - peer.last_send),
434440
peer.last_recv == 0 ? "" : ToString(m_time_now - peer.last_recv),
435441
peer.last_trxn == 0 ? "" : ToString((m_time_now - peer.last_trxn) / 60),

0 commit comments

Comments
 (0)