Repository: dogecoin/dogecoin
File: src/net.cpp (C++)

Code before:
                    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)
                {
                    LogPrintf("version handshake timeout from %d\n", pnode->id);
                    pnode->fDisconnect = true;
                }
            }
        }
        //
        // Reduce number of connections, if needed
        //
        if (vNodesCopy.size() > (size_t)nMaxConnections)
        {
            LogPrintf("%s: attempting to reduce connections: max=%u current=%u", __func__, vNodesCopy.size(), nMaxConnections);
            DisconnectUnusedNodes();
            DeleteDisconnectedNodes();
            AttemptToEvictConnection();
        }

        {
            LOCK(cs_vNodes);
            BOOST_FOREACH(CNode* pnode, vNodesCopy)
                pnode->Release();
        }
    }
}

void CConnman::SetMaxConnections(int newMaxConnections)
{
    newMaxConnections = std::max(newMaxConnections, MAX_ADDNODE_CONNECTIONS);
    nMaxConnections = std::min(newMaxConnections, nAvailableFds);
    if (nMaxConnections != newMaxConnections) {
        LogPrintf("%s: capped new maxconnections request of %d to %d", __func__, newMaxConnections, nMaxConnections);
    }
}


void CConnman::WakeMessageHandler()
{

Review comment (suggestion):
needs `\n` at the end, and I mixed up the variable positions - my bad for just writing it here and not testing my own suggestions.

Code after:
                if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
                {
                    LogPrint("net", "socket no message in first 60 seconds, %d %d from %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->id);
                    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)
                {
                    LogPrintf("version handshake timeout from %d\n", pnode->id);
                    pnode->fDisconnect = true;
                }
            }
        }
        //
        // Reduce number of connections, if needed
        //

        long unsigned int nKeepConnections = nUnevictableConnections + nWhitelistedConnections;
        long unsigned int nNodesCopy       = vNodesCopy.size();

        if (nNodesCopy > nKeepConnections && (nNodesCopy > (long unsigned int)nMaxConnections))
        {
            LogPrintf("%s: attempting to reduce connections: max=%u current=%u keep=%u\n", __func__, nMaxConnections, nNodesCopy, nKeepConnections);
            DisconnectUnusedNodes();
            DeleteDisconnectedNodes();

            if (!AttemptToEvictConnection()) {
                LogPrint("net", "Failed to evict connections\n");
            }
        }

        {
            LOCK(cs_vNodes);
            BOOST_FOREACH(CNode* pnode, vNodesCopy)
                pnode->Release();
        }
    }