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