Don't connect to myself

- track local IP+port of incoming connections and don't connect
to them in the future
This commit is contained in:
Peter Šurda 2017-05-31 00:04:21 +02:00
parent fa9811f426
commit f23c169eec
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
3 changed files with 6 additions and 0 deletions

View File

@ -134,6 +134,9 @@ class BMConnectionPool(object):
continue continue
if chosen.host in self.inboundConnections: if chosen.host in self.inboundConnections:
continue continue
# don't connect to self
if chosen.host in state.ownAddresses:
continue
#for c in self.outboundConnections: #for c in self.outboundConnections:
# if chosen == c.destination: # if chosen == c.destination:

View File

@ -205,6 +205,7 @@ class TCPServer(AdvancedDispatcher):
pair = self.accept() pair = self.accept()
if pair is not None: if pair is not None:
sock, addr = pair sock, addr = pair
state.ownAddresses[state.Peer(sock.getsockname()[0], sock.getsockname()[1])] = True
try: try:
network.connectionpool.BMConnectionPool().addConnection(TCPConnection(sock=sock)) network.connectionpool.BMConnectionPool().addConnection(TCPConnection(sock=sock))
except socket.error: except socket.error:

View File

@ -25,6 +25,8 @@ maximumNumberOfHalfOpenConnections = 0
invThread = None invThread = None
ownAddresses = {}
# If the trustedpeer option is specified in keys.dat then this will # If the trustedpeer option is specified in keys.dat then this will
# contain a Peer which will be connected to instead of using the # contain a Peer which will be connected to instead of using the
# addresses advertised by other peers. The client will only connect to # addresses advertised by other peers. The client will only connect to