mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
Merge #18638: net: Use mockable time for ping/pong, add tests
fa3365430cnet: Use mockable time for ping/pong, add tests (MarcoFalke)faab4aaf2futil: Add count_microseconds helper (MarcoFalke) Pull request description: Switch `CNode::m_ping_start` and `CNetMessage::m_time` to mockable time, so that tests can be added. Mockable time is also type-safe, since it uses `std::chrono` ACKs for top commit: jonatack: Code review re-ACKfa33654re-read code, verified rebase per `git range-diff4b5c919fa94d6f fa33654`, previous tested ACKs still valid troygiorshev: ACKfa3365430cTree-SHA512: 7d632bd6019ce7c882029e71b667a61517e783af82755a85dd979ef09380934e172dec8b8f91d57b200a30a6e096aeaf01f19fee7f3aed0e0e871c72eb44d70e
This commit is contained in:
16
src/net.h
16
src/net.h
@@ -612,13 +612,13 @@ public:
|
||||
*/
|
||||
class CNetMessage {
|
||||
public:
|
||||
CDataStream m_recv; // received message data
|
||||
int64_t m_time = 0; // time (in microseconds) of message receipt.
|
||||
CDataStream m_recv; //!< received message data
|
||||
std::chrono::microseconds m_time{0}; //!< time of message receipt
|
||||
bool m_valid_netmagic = false;
|
||||
bool m_valid_header = false;
|
||||
bool m_valid_checksum = false;
|
||||
uint32_t m_message_size = 0; // size of the payload
|
||||
uint32_t m_raw_message_size = 0; // used wire size of the message (including header/checksum)
|
||||
uint32_t m_message_size{0}; //!< size of the payload
|
||||
uint32_t m_raw_message_size{0}; //!< used wire size of the message (including header/checksum)
|
||||
std::string m_command;
|
||||
|
||||
CNetMessage(CDataStream&& recv_in) : m_recv(std::move(recv_in)) {}
|
||||
@@ -642,7 +642,7 @@ public:
|
||||
// read and deserialize data
|
||||
virtual int Read(const char *data, unsigned int bytes) = 0;
|
||||
// decomposes a message from the context
|
||||
virtual CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, int64_t time) = 0;
|
||||
virtual CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, std::chrono::microseconds time) = 0;
|
||||
virtual ~TransportDeserializer() {}
|
||||
};
|
||||
|
||||
@@ -695,7 +695,7 @@ public:
|
||||
if (ret < 0) Reset();
|
||||
return ret;
|
||||
}
|
||||
CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, int64_t time) override;
|
||||
CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, std::chrono::microseconds time) override;
|
||||
};
|
||||
|
||||
/** The TransportSerializer prepares messages for the network transport
|
||||
@@ -845,8 +845,8 @@ public:
|
||||
// Ping time measurement:
|
||||
// The pong reply we're expecting, or 0 if no pong expected.
|
||||
std::atomic<uint64_t> nPingNonceSent{0};
|
||||
// Time (in usec) the last ping was sent, or 0 if no ping was ever sent.
|
||||
std::atomic<int64_t> nPingUsecStart{0};
|
||||
/** When the last ping was sent, or 0 if no ping was ever sent */
|
||||
std::atomic<std::chrono::microseconds> m_ping_start{std::chrono::microseconds{0}};
|
||||
// Last measured round-trip time.
|
||||
std::atomic<int64_t> nPingUsecTime{0};
|
||||
// Best measured round-trip time.
|
||||
|
||||
Reference in New Issue
Block a user