[net] InactivityCheck() takes a CNode reference

pull/826/head
John Newbery 4 years ago
parent e7eb37128c
commit 06fa85cd50

@ -1216,35 +1216,35 @@ void CConnman::NotifyNumConnectionsChanged()
} }
} }
void CConnman::InactivityCheck(CNode *pnode) const void CConnman::InactivityCheck(CNode& node) const
{ {
int64_t nTime = GetSystemTimeInSeconds(); int64_t nTime = GetSystemTimeInSeconds();
if (nTime - pnode->nTimeConnected > m_peer_connect_timeout) if (nTime - node.nTimeConnected > m_peer_connect_timeout)
{ {
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0) if (node.nLastRecv == 0 || node.nLastSend == 0)
{ {
LogPrint(BCLog::NET, "socket no message in first %i seconds, %d %d from %d\n", m_peer_connect_timeout, pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->GetId()); LogPrint(BCLog::NET, "socket no message in first %i seconds, %d %d from %d\n", m_peer_connect_timeout, node.nLastRecv != 0, node.nLastSend != 0, node.GetId());
pnode->fDisconnect = true; node.fDisconnect = true;
} }
else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL) else if (nTime - node.nLastSend > TIMEOUT_INTERVAL)
{ {
LogPrintf("socket sending timeout: %is\n", nTime - pnode->nLastSend); LogPrintf("socket sending timeout: %is\n", nTime - node.nLastSend);
pnode->fDisconnect = true; node.fDisconnect = true;
} }
else if (nTime - pnode->nLastRecv > TIMEOUT_INTERVAL) else if (nTime - node.nLastRecv > TIMEOUT_INTERVAL)
{ {
LogPrintf("socket receive timeout: %is\n", nTime - pnode->nLastRecv); LogPrintf("socket receive timeout: %is\n", nTime - node.nLastRecv);
pnode->fDisconnect = true; node.fDisconnect = true;
} }
else if (pnode->nPingNonceSent && pnode->m_ping_start.load() + std::chrono::seconds{TIMEOUT_INTERVAL} < GetTime<std::chrono::microseconds>()) else if (node.nPingNonceSent && node.m_ping_start.load() + std::chrono::seconds{TIMEOUT_INTERVAL} < GetTime<std::chrono::microseconds>())
{ {
LogPrintf("ping timeout: %fs\n", 0.000001 * count_microseconds(GetTime<std::chrono::microseconds>() - pnode->m_ping_start.load())); LogPrintf("ping timeout: %fs\n", 0.000001 * count_microseconds(GetTime<std::chrono::microseconds>() - node.m_ping_start.load()));
pnode->fDisconnect = true; node.fDisconnect = true;
} }
else if (!pnode->fSuccessfullyConnected) else if (!node.fSuccessfullyConnected)
{ {
LogPrint(BCLog::NET, "version handshake timeout from %d\n", pnode->GetId()); LogPrint(BCLog::NET, "version handshake timeout from %d\n", node.GetId());
pnode->fDisconnect = true; node.fDisconnect = true;
} }
} }
} }
@ -1522,7 +1522,7 @@ void CConnman::SocketHandler()
if (bytes_sent) RecordBytesSent(bytes_sent); if (bytes_sent) RecordBytesSent(bytes_sent);
} }
InactivityCheck(pnode); InactivityCheck(*pnode);
} }
{ {
LOCK(cs_vNodes); LOCK(cs_vNodes);

@ -1044,7 +1044,7 @@ private:
void AcceptConnection(const ListenSocket& hListenSocket); void AcceptConnection(const ListenSocket& hListenSocket);
void DisconnectNodes(); void DisconnectNodes();
void NotifyNumConnectionsChanged(); void NotifyNumConnectionsChanged();
void InactivityCheck(CNode *pnode) const; void InactivityCheck(CNode& node) const;
bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set); bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set); void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
void SocketHandler(); void SocketHandler();

Loading…
Cancel
Save