From f23c169eec7f71b4b217cfb842fb1224b0af398a Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Wed, 31 May 2017 00:04:21 +0200 Subject: [PATCH] Don't connect to myself - track local IP+port of incoming connections and don't connect to them in the future --- src/network/connectionpool.py | 3 +++ src/network/tcp.py | 1 + src/state.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/network/connectionpool.py b/src/network/connectionpool.py index ef2fb26b..4afada16 100644 --- a/src/network/connectionpool.py +++ b/src/network/connectionpool.py @@ -134,6 +134,9 @@ class BMConnectionPool(object): continue if chosen.host in self.inboundConnections: continue + # don't connect to self + if chosen.host in state.ownAddresses: + continue #for c in self.outboundConnections: # if chosen == c.destination: diff --git a/src/network/tcp.py b/src/network/tcp.py index 2a2188ea..3ce4cc52 100644 --- a/src/network/tcp.py +++ b/src/network/tcp.py @@ -205,6 +205,7 @@ class TCPServer(AdvancedDispatcher): pair = self.accept() if pair is not None: sock, addr = pair + state.ownAddresses[state.Peer(sock.getsockname()[0], sock.getsockname()[1])] = True try: network.connectionpool.BMConnectionPool().addConnection(TCPConnection(sock=sock)) except socket.error: diff --git a/src/state.py b/src/state.py index ff8a143d..618b6c92 100644 --- a/src/state.py +++ b/src/state.py @@ -25,6 +25,8 @@ maximumNumberOfHalfOpenConnections = 0 invThread = None +ownAddresses = {} + # If the trustedpeer option is specified in keys.dat then this will # contain a Peer which will be connected to instead of using the # addresses advertised by other peers. The client will only connect to