From 114f6b627b83141ee4cee657886edf2f656fc2de Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 31 Aug 2021 10:41:41 +0200 Subject: [PATCH] P2PServer: don't allow multiple connections to/from the same IP --- src/p2p_server.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index 57ea7fb..4241012 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -696,6 +696,17 @@ void P2PServer::P2PClient::reset() bool P2PServer::P2PClient::on_connect() { + P2PServer* server = static_cast(m_owner); + + // Don't allow multiple connections to/from the same IP + // server->m_clientsListLock is already locked here + for (P2PClient* client = static_cast(server->m_connectedClientsList->m_next); client != server->m_connectedClientsList; client = static_cast(client->m_next)) { + if ((client != this) && (client->m_addr == m_addr)) { + LOGWARN(5, "peer " << static_cast(m_addrString) << " is already connected as " << static_cast(client->m_addrString)); + return false; + } + } + m_lastAlive = time(nullptr); return send_handshake_challenge(); }