net: use GetTime<T>() in leftover GetTimeSeconds() usage

This commit is contained in:
Kittywhiskers Van Gogh 2024-12-07 17:57:18 +00:00
parent b114718240
commit 8f8e73242d
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
3 changed files with 5 additions and 5 deletions

View File

@ -1901,7 +1901,7 @@ bool CConnman::AttemptToEvictConnection()
// follow when the incoming connection is from another masternode. When a message other than MNAUTH // follow when the incoming connection is from another masternode. When a message other than MNAUTH
// is received after VERSION/VERACK, the protection is lifted immediately. // is received after VERSION/VERACK, the protection is lifted immediately.
bool isProtected = GetTime<std::chrono::seconds>() - node->m_connected < INBOUND_EVICTION_PROTECTION_TIME; bool isProtected = GetTime<std::chrono::seconds>() - node->m_connected < INBOUND_EVICTION_PROTECTION_TIME;
if (node->nTimeFirstMessageReceived != 0 && !node->fFirstMessageIsMNAUTH) { if (node->nTimeFirstMessageReceived.load() != 0s && !node->fFirstMessageIsMNAUTH) {
isProtected = false; isProtected = false;
} }
// if MNAUTH was valid, the node is always protected (and at the same time not accounted when // if MNAUTH was valid, the node is always protected (and at the same time not accounted when
@ -3754,7 +3754,7 @@ void CConnman::ThreadOpenMasternodeConnections(CDeterministicMNManager& dmnman,
// we probably connected to it before it became a masternode // we probably connected to it before it became a masternode
// or maybe we are still waiting for mnauth // or maybe we are still waiting for mnauth
(void)ForNode(addr2, [&](CNode* pnode) { (void)ForNode(addr2, [&](CNode* pnode) {
if (pnode->nTimeFirstMessageReceived != 0 && GetTimeSeconds() - pnode->nTimeFirstMessageReceived > 5) { if (pnode->nTimeFirstMessageReceived.load() != 0s && GetTime<std::chrono::seconds>() - pnode->nTimeFirstMessageReceived.load() > 5s) {
// clearly not expecting mnauth to take that long even if it wasn't the first message // clearly not expecting mnauth to take that long even if it wasn't the first message
// we received (as it should normally), disconnect // we received (as it should normally), disconnect
LogPrint(BCLog::NET_NETCONN, "CConnman::%s -- dropping non-mnauth connection to %s, service=%s\n", _func_, proRegTxHash.ToString(), addr2.ToStringAddrPort()); LogPrint(BCLog::NET_NETCONN, "CConnman::%s -- dropping non-mnauth connection to %s, service=%s\n", _func_, proRegTxHash.ToString(), addr2.ToStringAddrPort());

View File

@ -766,7 +766,7 @@ public:
const std::chrono::seconds m_connected; const std::chrono::seconds m_connected;
std::atomic<int64_t> nTimeOffset{0}; std::atomic<int64_t> nTimeOffset{0};
std::atomic<int64_t> nLastWarningTime{0}; std::atomic<int64_t> nLastWarningTime{0};
std::atomic<int64_t> nTimeFirstMessageReceived{0}; std::atomic<std::chrono::seconds> nTimeFirstMessageReceived{0s};
std::atomic<bool> fFirstMessageIsMNAUTH{false}; std::atomic<bool> fFirstMessageIsMNAUTH{false};
// Address of this peer // Address of this peer
const CAddress addr; const CAddress addr;

View File

@ -3936,9 +3936,9 @@ void PeerManagerImpl::ProcessMessage(
return; return;
} }
if (pfrom.nTimeFirstMessageReceived == 0) { if (pfrom.nTimeFirstMessageReceived.load() == 0s) {
// First message after VERSION/VERACK // First message after VERSION/VERACK
pfrom.nTimeFirstMessageReceived = GetTimeSeconds(); pfrom.nTimeFirstMessageReceived = GetTime<std::chrono::seconds>();
pfrom.fFirstMessageIsMNAUTH = msg_type == NetMsgType::MNAUTH; pfrom.fFirstMessageIsMNAUTH = msg_type == NetMsgType::MNAUTH;
// Note: do not break the flow here // Note: do not break the flow here