mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
[net] Changes to RunInactivityChecks
- rename to ShouldRunInactivityChecks (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r576394790) - take optional time now (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r575895661) - call from within InactivityChecks (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r575894665) - update comment (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r575894343) - change ordering of inequality (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r574925129)
This commit is contained in:
parent
2b2ab9ab78
commit
5ed535a02f
3 changed files with 9 additions and 6 deletions
|
@ -1255,9 +1255,10 @@ void CConnman::NotifyNumConnectionsChanged()
|
|||
}
|
||||
}
|
||||
|
||||
bool CConnman::RunInactivityChecks(const CNode& node) const
|
||||
bool CConnman::ShouldRunInactivityChecks(const CNode& node, std::optional<int64_t> now_in) const
|
||||
{
|
||||
return GetSystemTimeInSeconds() > node.nTimeConnected + m_peer_connect_timeout;
|
||||
const int64_t now = now_in ? now_in.value() : GetSystemTimeInSeconds();
|
||||
return node.nTimeConnected + m_peer_connect_timeout < now;
|
||||
}
|
||||
|
||||
bool CConnman::InactivityCheck(const CNode& node) const
|
||||
|
@ -1266,6 +1267,8 @@ bool CConnman::InactivityCheck(const CNode& node) const
|
|||
// use setmocktime in the tests).
|
||||
int64_t now = GetSystemTimeInSeconds();
|
||||
|
||||
if (!ShouldRunInactivityChecks(node, now)) return false;
|
||||
|
||||
if (node.nLastRecv == 0 || node.nLastSend == 0) {
|
||||
LogPrint(BCLog::NET, "socket no message in first %i seconds, %d %d peer=%d\n", m_peer_connect_timeout, node.nLastRecv != 0, node.nLastSend != 0, node.GetId());
|
||||
return true;
|
||||
|
@ -1562,7 +1565,7 @@ void CConnman::SocketHandler()
|
|||
if (bytes_sent) RecordBytesSent(bytes_sent);
|
||||
}
|
||||
|
||||
if (RunInactivityChecks(*pnode) && InactivityCheck(*pnode)) pnode->fDisconnect = true;
|
||||
if (InactivityCheck(*pnode)) pnode->fDisconnect = true;
|
||||
}
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
|
|
|
@ -1018,8 +1018,8 @@ 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;
|
||||
/** Return true if we should disconnect the peer for failing an inactivity check. */
|
||||
bool ShouldRunInactivityChecks(const CNode& node, std::optional<int64_t> now=std::nullopt) const;
|
||||
|
||||
private:
|
||||
struct ListenSocket {
|
||||
|
|
|
@ -4108,7 +4108,7 @@ void PeerManagerImpl::CheckForStaleTipAndEvictPeers()
|
|||
|
||||
void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::microseconds now)
|
||||
{
|
||||
if (m_connman.RunInactivityChecks(node_to) && peer.m_ping_nonce_sent &&
|
||||
if (m_connman.ShouldRunInactivityChecks(node_to) && peer.m_ping_nonce_sent &&
|
||||
now > peer.m_ping_start.load() + std::chrono::seconds{TIMEOUT_INTERVAL}) {
|
||||
LogPrint(BCLog::NET, "ping timeout: %fs peer=%d\n", 0.000001 * count_microseconds(now - peer.m_ping_start.load()), peer.m_id);
|
||||
node_to.fDisconnect = true;
|
||||
|
|
Loading…
Add table
Reference in a new issue