diff --git a/minode/i2p/listener.py b/minode/i2p/listener.py index f68c2b4..854c257 100644 --- a/minode/i2p/listener.py +++ b/minode/i2p/listener.py @@ -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') diff --git a/minode/manager.py b/minode/manager.py index 5d5de4e..bcde093 100644 --- a/minode/manager.py +++ b/minode/manager.py @@ -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])