diff options
author | fanquake <fanquake@gmail.com> | 2021-02-16 17:52:40 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2021-02-16 18:48:30 +0800 |
commit | 9bbf08bf98487eeb75f143c120cfd544ea3135fb (patch) | |
tree | a917e243c064a64bf4cc73066742492e2426c872 /src/net.h | |
parent | b55dc3ad84abec4f58e54a8581bdf8556c74b1e3 (diff) | |
parent | a5e15ae45ccae7948a6c5b95e6621f01afb88d55 (diff) | |
download | bitcoin-9bbf08bf98487eeb75f143c120cfd544ea3135fb.tar.xz |
Merge #20721: Net: Move ping data to net_processing
a5e15ae45ccae7948a6c5b95e6621f01afb88d55 scripted-diff: rename ping members (John Newbery)
45dcf2266125c65d7f546bdb211a278bd090a284 [net processing] Move ping data fields to net processing (John Newbery)
dd2646d12c172cb8899669af717c590483a17404 [net processing] Move ping timeout logic to net processing (John Newbery)
0b43b81f69ff13dbc1e893a80950f186690b4f62 [net processing] Move send ping message logic into function (John Newbery)
1a07600b4b0d08cffc7cd5c58af33fcd1ede558e [net] Add RunInactivityChecks() (John Newbery)
f8b3058992b507f3a6aac9d4e2db00102ae1b197 [net processing] Add Peer& arg to MaybeDiscourageAndDisconnect() (John Newbery)
Pull request description:
This continues the work of moving application layer data into net_processing, by moving all ping data into the new Peer object added in #19607.
For motivation, see #19398.
ACKs for top commit:
glozow:
reACK https://github.com/bitcoin/bitcoin/commit/a5e15ae45ccae7948a6c5b95e6621f01afb88d55
MarcoFalke:
review ACK a5e15ae45ccae7948a6c5b95e6621f01afb88d55 🥉
amitiuttarwar:
ACK a5e15ae45c
Tree-SHA512: fb84241613d6a6e1f2832fa5378030b5877a02e8308188f57ab545a6eaf2ab731a93abb7dcd3a7f7285bb66700f938096378a8e90cd6a3e6f3309f81d85a344e
Diffstat (limited to 'src/net.h')
-rw-r--r-- | src/net.h | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -260,7 +260,6 @@ public: mapMsgCmdSize mapRecvBytesPerMsgCmd; NetPermissionFlags m_permissionFlags; int64_t m_ping_usec; - int64_t m_ping_wait_usec; int64_t m_min_ping_usec; CAmount minFeeFilter; // Our address, as reported by the peer @@ -591,17 +590,12 @@ public: * in CConnman::AttemptToEvictConnection. */ std::atomic<int64_t> nLastTXTime{0}; - // Ping time measurement: - // The pong reply we're expecting, or 0 if no pong expected. - std::atomic<uint64_t> nPingNonceSent{0}; - /** When the last ping was sent, or 0 if no ping was ever sent */ - std::atomic<std::chrono::microseconds> m_ping_start{0us}; - // Last measured round-trip time. - std::atomic<int64_t> nPingUsecTime{0}; - // Best measured round-trip time. - std::atomic<int64_t> nMinPingUsecTime{std::numeric_limits<int64_t>::max()}; - // Whether a ping is requested. - std::atomic<bool> fPingQueued{false}; + /** Last measured round-trip time. Used only for RPC/GUI stats/debugging.*/ + std::atomic<int64_t> m_last_ping_time{0}; + + /** Lowest measured round-trip time. Used as an inbound peer eviction + * criterium in CConnman::AttemptToEvictConnection. */ + std::atomic<int64_t> m_min_ping_time{std::numeric_limits<int64_t>::max()}; CNode(NodeId id, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion); ~CNode(); @@ -721,6 +715,12 @@ public: std::string ConnectionTypeAsString() const { return ::ConnectionTypeAsString(m_conn_type); } + /** A ping-pong round trip has completed successfully. Update latest and minimum ping times. */ + void PongReceived(std::chrono::microseconds ping_time) { + m_last_ping_time = count_microseconds(ping_time); + m_min_ping_time = std::min(m_min_ping_time.load(), count_microseconds(ping_time)); + } + private: const NodeId id; const uint64_t nLocalHostNonce; @@ -1022,6 +1022,9 @@ public: void SetAsmap(std::vector<bool> asmap) { addrman.m_asmap = std::move(asmap); } + /** Return true if the peer has been connected for long enough to do inactivity checks. */ + bool RunInactivityChecks(const CNode& node) const; + private: struct ListenSocket { public: @@ -1250,7 +1253,7 @@ struct NodeEvictionCandidate { NodeId id; int64_t nTimeConnected; - int64_t nMinPingUsecTime; + int64_t m_min_ping_time; int64_t nLastBlockTime; int64_t nLastTXTime; bool fRelevantServices; |