mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-16 17:04:05 +02:00
refactor: Use NodeClock::duration for m_last_ping_time/m_min_ping_time/m_ping_wait
This refactor does not change any behavior and is needed for a future commit, to avoid having to add duration casts. It also improves the docs to better document that this is not a time point, but a duration. Also, it uses decltype to explain where the _::max() is coming from.
This commit is contained in:
11
src/net.h
11
src/net.h
@@ -210,8 +210,8 @@ public:
|
||||
uint64_t nRecvBytes;
|
||||
mapMsgTypeSize mapRecvBytesPerMsgType;
|
||||
NetPermissionFlags m_permission_flags;
|
||||
std::chrono::microseconds m_last_ping_time;
|
||||
std::chrono::microseconds m_min_ping_time;
|
||||
NodeClock::duration m_last_ping_time;
|
||||
NodeClock::duration m_min_ping_time;
|
||||
// Our address, as reported by the peer
|
||||
std::string addrLocal;
|
||||
// Address of this peer
|
||||
@@ -890,11 +890,11 @@ public:
|
||||
std::atomic<std::chrono::seconds> m_last_tx_time{0s};
|
||||
|
||||
/// Last measured round-trip duration. Used only for stats.
|
||||
std::atomic<std::chrono::microseconds> m_last_ping_time{0us};
|
||||
std::atomic<NodeClock::duration> m_last_ping_time{0us};
|
||||
|
||||
/// Lowest measured round-trip duration. Used as an inbound peer eviction
|
||||
/// criterion in CConnman::AttemptToEvictConnection.
|
||||
std::atomic<std::chrono::microseconds> m_min_ping_time{std::chrono::microseconds::max()};
|
||||
std::atomic<NodeClock::duration> m_min_ping_time{NodeClock::duration::max()};
|
||||
|
||||
CNode(NodeId id,
|
||||
std::shared_ptr<Sock> sock,
|
||||
@@ -981,7 +981,8 @@ public:
|
||||
std::string DisconnectMsg() const;
|
||||
|
||||
/// A ping-pong round trip has completed successfully. Update latest and minimum ping durations.
|
||||
void PongReceived(std::chrono::microseconds ping_time) {
|
||||
void PongReceived(NodeClock::duration ping_time)
|
||||
{
|
||||
m_last_ping_time = ping_time;
|
||||
m_min_ping_time = std::min(m_min_ping_time.load(), ping_time);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ static const unsigned int MAX_HEADERS_RESULTS = 2000;
|
||||
struct CNodeStateStats {
|
||||
int nSyncHeight = -1;
|
||||
int nCommonHeight = -1;
|
||||
std::chrono::microseconds m_ping_wait;
|
||||
NodeClock::duration m_ping_wait;
|
||||
std::vector<int> vHeightInFlight;
|
||||
bool m_relay_txs;
|
||||
int m_inv_to_send = 0;
|
||||
|
||||
@@ -18,7 +18,7 @@ typedef int64_t NodeId;
|
||||
struct NodeEvictionCandidate {
|
||||
NodeId id;
|
||||
std::chrono::seconds m_connected;
|
||||
std::chrono::microseconds m_min_ping_time;
|
||||
NodeClock::duration m_min_ping_time;
|
||||
std::chrono::seconds m_last_block_time;
|
||||
std::chrono::seconds m_last_tx_time;
|
||||
bool fRelevantServices;
|
||||
|
||||
@@ -767,9 +767,9 @@ QString formatServicesStr(quint64 mask)
|
||||
return QObject::tr("None");
|
||||
}
|
||||
|
||||
QString formatPingTime(std::chrono::microseconds ping_time)
|
||||
QString formatPingTime(NodeClock::duration ping_time)
|
||||
{
|
||||
return (ping_time == std::chrono::microseconds::max() || ping_time == 0us) ?
|
||||
return (ping_time == decltype(CNode::m_min_ping_time.load())::max() || ping_time == 0us) ?
|
||||
QObject::tr("N/A") :
|
||||
QObject::tr("%1 ms").arg(QString::number(Ticks<std::chrono::milliseconds>(ping_time)));
|
||||
}
|
||||
|
||||
@@ -237,8 +237,8 @@ namespace GUIUtil
|
||||
/** Format CNodeStats.nServices bitmask into a user-readable string */
|
||||
QString formatServicesStr(quint64 mask);
|
||||
|
||||
/** Format a CNodeStats.m_last_ping_time into a user-readable string or display N/A, if 0 */
|
||||
QString formatPingTime(std::chrono::microseconds ping_time);
|
||||
/// Format a CNodeStats.m_last_ping_time/m_min_ping_time/m_ping_wait into a user-readable string if it exists, or display N/A
|
||||
QString formatPingTime(NodeClock::duration ping_time);
|
||||
|
||||
/** Format a CNodeStateStats.time_offset into a user-readable string */
|
||||
QString formatTimeOffset(int64_t time_offset);
|
||||
|
||||
@@ -253,7 +253,7 @@ static RPCHelpMan getpeerinfo()
|
||||
if (stats.m_last_ping_time > 0us) {
|
||||
obj.pushKV("pingtime", Ticks<SecondsDouble>(stats.m_last_ping_time));
|
||||
}
|
||||
if (stats.m_min_ping_time < std::chrono::microseconds::max()) {
|
||||
if (stats.m_min_ping_time < decltype(CNode::m_min_ping_time.load())::max()) {
|
||||
obj.pushKV("minping", Ticks<SecondsDouble>(stats.m_min_ping_time));
|
||||
}
|
||||
if (statestats.m_ping_wait > 0s) {
|
||||
|
||||
Reference in New Issue
Block a user