Give only 5 seconds for new connections to complete handshake

This is to detect random port scans/non-p2pool connections quickly
This commit is contained in:
SChernykh 2021-08-25 11:14:23 +02:00
parent 336349e189
commit 7ab3c22114

View file

@ -165,7 +165,9 @@ void P2PServer::update_peer_connections()
connected_clients.reserve(m_numConnections); connected_clients.reserve(m_numConnections);
for (P2PClient* client = static_cast<P2PClient*>(m_connectedClientsList->m_next); client != m_connectedClientsList; client = static_cast<P2PClient*>(client->m_next)) { for (P2PClient* client = static_cast<P2PClient*>(m_connectedClientsList->m_next); client != m_connectedClientsList; client = static_cast<P2PClient*>(client->m_next)) {
connected_clients.emplace_back(client->m_addr); connected_clients.emplace_back(client->m_addr);
if (cur_time > client->m_lastAlive + 5 * 60) {
const int timeout = client->m_handshakeComplete ? 300 : 5;
if (cur_time >= client->m_lastAlive + timeout) {
const uint64_t idle_time = static_cast<uint64_t>(cur_time - client->m_lastAlive); const uint64_t idle_time = static_cast<uint64_t>(cur_time - client->m_lastAlive);
LOGWARN(5, "peer " << static_cast<char*>(client->m_addrString) << " has been idle for " << idle_time << " seconds, disconnecting"); LOGWARN(5, "peer " << static_cast<char*>(client->m_addrString) << " has been idle for " << idle_time << " seconds, disconnecting");
client->close(); client->close();