Move InactivityCheck logic to private method.
This commit is contained in:
parent
7479b63d91
commit
2af9cff11a
2 changed files with 35 additions and 32 deletions
66
src/net.cpp
66
src/net.cpp
|
@ -1229,6 +1229,39 @@ void CConnman::NotifyNumConnectionsChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CConnman::InactivityCheck(CNode *pnode)
|
||||||
|
{
|
||||||
|
int64_t nTime = GetSystemTimeInSeconds();
|
||||||
|
if (nTime - pnode->nTimeConnected > 60)
|
||||||
|
{
|
||||||
|
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
|
||||||
|
{
|
||||||
|
LogPrint(BCLog::NET, "socket no message in first 60 seconds, %d %d from %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->GetId());
|
||||||
|
pnode->fDisconnect = true;
|
||||||
|
}
|
||||||
|
else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL)
|
||||||
|
{
|
||||||
|
LogPrintf("socket sending timeout: %is\n", nTime - pnode->nLastSend);
|
||||||
|
pnode->fDisconnect = true;
|
||||||
|
}
|
||||||
|
else if (nTime - pnode->nLastRecv > (pnode->nVersion > BIP0031_VERSION ? TIMEOUT_INTERVAL : 90*60))
|
||||||
|
{
|
||||||
|
LogPrintf("socket receive timeout: %is\n", nTime - pnode->nLastRecv);
|
||||||
|
pnode->fDisconnect = true;
|
||||||
|
}
|
||||||
|
else if (pnode->nPingNonceSent && pnode->nPingUsecStart + TIMEOUT_INTERVAL * 1000000 < GetTimeMicros())
|
||||||
|
{
|
||||||
|
LogPrintf("ping timeout: %fs\n", 0.000001 * (GetTimeMicros() - pnode->nPingUsecStart));
|
||||||
|
pnode->fDisconnect = true;
|
||||||
|
}
|
||||||
|
else if (!pnode->fSuccessfullyConnected)
|
||||||
|
{
|
||||||
|
LogPrint(BCLog::NET, "version handshake timeout from %d\n", pnode->GetId());
|
||||||
|
pnode->fDisconnect = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CConnman::ThreadSocketHandler()
|
void CConnman::ThreadSocketHandler()
|
||||||
{
|
{
|
||||||
while (!interruptNet)
|
while (!interruptNet)
|
||||||
|
@ -1425,38 +1458,7 @@ void CConnman::ThreadSocketHandler()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
InactivityCheck(pnode);
|
||||||
// Inactivity checking
|
|
||||||
//
|
|
||||||
int64_t nTime = GetSystemTimeInSeconds();
|
|
||||||
if (nTime - pnode->nTimeConnected > 60)
|
|
||||||
{
|
|
||||||
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
|
|
||||||
{
|
|
||||||
LogPrint(BCLog::NET, "socket no message in first 60 seconds, %d %d from %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->GetId());
|
|
||||||
pnode->fDisconnect = true;
|
|
||||||
}
|
|
||||||
else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL)
|
|
||||||
{
|
|
||||||
LogPrintf("socket sending timeout: %is\n", nTime - pnode->nLastSend);
|
|
||||||
pnode->fDisconnect = true;
|
|
||||||
}
|
|
||||||
else if (nTime - pnode->nLastRecv > (pnode->nVersion > BIP0031_VERSION ? TIMEOUT_INTERVAL : 90*60))
|
|
||||||
{
|
|
||||||
LogPrintf("socket receive timeout: %is\n", nTime - pnode->nLastRecv);
|
|
||||||
pnode->fDisconnect = true;
|
|
||||||
}
|
|
||||||
else if (pnode->nPingNonceSent && pnode->nPingUsecStart + TIMEOUT_INTERVAL * 1000000 < GetTimeMicros())
|
|
||||||
{
|
|
||||||
LogPrintf("ping timeout: %fs\n", 0.000001 * (GetTimeMicros() - pnode->nPingUsecStart));
|
|
||||||
pnode->fDisconnect = true;
|
|
||||||
}
|
|
||||||
else if (!pnode->fSuccessfullyConnected)
|
|
||||||
{
|
|
||||||
LogPrint(BCLog::NET, "version handshake timeout from %d\n", pnode->GetId());
|
|
||||||
pnode->fDisconnect = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
|
|
|
@ -338,6 +338,7 @@ private:
|
||||||
void AcceptConnection(const ListenSocket& hListenSocket);
|
void AcceptConnection(const ListenSocket& hListenSocket);
|
||||||
void DisconnectNodes();
|
void DisconnectNodes();
|
||||||
void NotifyNumConnectionsChanged();
|
void NotifyNumConnectionsChanged();
|
||||||
|
void InactivityCheck(CNode *pnode);
|
||||||
void ThreadSocketHandler();
|
void ThreadSocketHandler();
|
||||||
void ThreadDNSAddressSeed();
|
void ThreadDNSAddressSeed();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue