Reject duplicate I2P connections and do not connect to ourselves

This commit is contained in:
TheKysek 2017-07-30 09:26:16 +02:00
parent 7ff7a16470
commit f74cb829fc
No known key found for this signature in database
GPG Key ID: 50D9AF00D0B1C497
2 changed files with 17 additions and 8 deletions

View File

@ -20,7 +20,7 @@ class I2PListener(threading.Thread):
self.version_reply = []
self.create_socket()
self.new_socket()
def _receive_line(self):
line = receive_line(self.s)
@ -31,7 +31,7 @@ class I2PListener(threading.Thread):
# logging.debug('I2PListener -> ' + str(command))
self.s.sendall(command)
def create_socket(self):
def new_socket(self):
self.s = socket.create_connection((self.host, self.port))
self._send(b'HELLO VERSION MIN=3.0 MAX=3.3\n')
self.version_reply = self._receive_line().split()
@ -48,10 +48,20 @@ class I2PListener(threading.Thread):
try:
destination = self._receive_line().split()[0]
logging.info('Incoming I2P connection from: {}'.format(destination.decode()))
c = Connection(destination, 'i2p', self.s, 'i2p', True, destination)
c.start()
shared.connections.add(c)
self.create_socket()
hosts = set()
for c in shared.connections.copy():
hosts.add(c.host)
for d in shared.i2p_dialers.copy():
hosts.add(d.destination)
if destination in hosts:
logging.debug('Rejecting duplicate I2P connection.')
self.s.close()
else:
c = Connection(destination, 'i2p', self.s, 'i2p', True, destination)
c.start()
shared.connections.add(c)
self.new_socket()
except socket.timeout:
pass
logging.debug('Shutting down I2P Listener')

View File

@ -105,7 +105,7 @@ class Manager(threading.Thread):
if addr[0] in hosts:
continue
if addr[1] == 'i2p' and shared.i2p_enabled:
if shared.i2p_session_nick:
if shared.i2p_session_nick and addr[0] != shared.i2p_dest_pub:
try:
d = I2PDialer(addr[0], shared.i2p_session_nick, shared.i2p_sam_host, shared.i2p_sam_port)
d.start()
@ -115,7 +115,6 @@ class Manager(threading.Thread):
logging.warning('Exception while trying to establish an I2P connection')
logging.warning(e)
else:
logging.debug('We were going to connect to an I2P peer but our tunnels are not ready')
continue
else:
c = Connection(addr[0], addr[1])