From 8788f2d3497e061d14e9ae4bd0864c6ea2373b39 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Tue, 2 Jan 2018 14:29:21 +0100 Subject: [PATCH] Server full and duplicate handling - will try to report "Server full" over protocol for 10 extra connections over limit, instead of simply dropping them - if connected to the same host inbound and outbound, handle as server full (prevents duplicate connections) --- src/network/bmproto.py | 14 ++++++++++++++ src/network/tcp.py | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/network/bmproto.py b/src/network/bmproto.py index 47c6c858..21ec692c 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -497,6 +497,20 @@ class BMProto(AdvancedDispatcher, ObjectTracker): return False except: pass + if not self.isOutbound: + # incoming from a peer we're connected to as outbound, or server full + # report the same error to counter deanonymisation + if state.Peer(self.destination.host, self.peerNode.port) in \ + network.connectionpool.BMConnectionPool().inboundConnections or \ + len(network.connectionpool.BMConnectionPool().inboundConnections) + \ + len(network.connectionpool.BMConnectionPool().outboundConnections) > \ + BMConfigParser().safeGetInt("bitmessagesettings", "maxtotalconnections") + \ + BMConfigParser().safeGetInt("bitmessagesettings", "maxbootstrapconnections"): + self.append_write_buf(protocol.assembleErrorMessage(fatal=2, + errorText="Server full, please try again later.")) + logger.debug ("Closed connection to %s due to server full or duplicate inbound/outbound.", + str(self.destination)) + return False if network.connectionpool.BMConnectionPool().isAlreadyConnected(self.nonce): self.append_write_buf(protocol.assembleErrorMessage(fatal=2, errorText="I'm connected to myself. Closing connection.")) diff --git a/src/network/tcp.py b/src/network/tcp.py index 922aa79d..5a27aca3 100644 --- a/src/network/tcp.py +++ b/src/network/tcp.py @@ -292,7 +292,10 @@ class TCPServer(AdvancedDispatcher): if len(network.connectionpool.BMConnectionPool().inboundConnections) + \ len(network.connectionpool.BMConnectionPool().outboundConnections) > \ BMConfigParser().safeGetInt("bitmessagesettings", "maxtotalconnections") + \ - BMConfigParser().safeGetInt("bitmessagesettings", "maxbootstrapconnections"): + BMConfigParser().safeGetInt("bitmessagesettings", "maxbootstrapconnections") + 10: + # 10 is a sort of buffer, in between it will go through the version handshake + # and return an error to the peer + logger.warning("Server full, dropping connection") sock.close() return try: