diff --git a/minode/i2p/listener.py b/minode/i2p/listener.py index 7ec1954..73cffce 100644 --- a/minode/i2p/listener.py +++ b/minode/i2p/listener.py @@ -15,8 +15,6 @@ class I2PListener(I2PThread): self.version_reply = [] - self.new_socket() - 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') @@ -31,25 +29,31 @@ class I2PListener(I2PThread): def run(self): while not self.state.shutting_down: + self.new_socket() + duplicate = False try: destination = self._receive_line().split()[0] logging.info( 'Incoming I2P connection from: %s', destination.decode()) - - hosts = set() - for c in self.state.connections.copy(): - hosts.add(c.host) - for d in self.state.i2p_dialers.copy(): - hosts.add(d.destination) - if destination in hosts: - logging.debug('Rejecting duplicate I2P connection.') - self.s.close() - else: - c = self.state.connection(destination, 'i2p', self.s, True) - c.start() - self.state.connections.add(c) - c = None - self.new_socket() except socket.timeout: - pass + continue + + for c in self.state.connections.copy(): + if c.host == destination: + duplicate = True + break + else: + for d in self.state.i2p_dialers.copy(): + if d.destination == destination: + duplicate = True + break + if duplicate: + logging.info('Rejecting duplicate I2P connection.') + self.s.close() + else: + c = self.state.connection(destination, 'i2p', self.s, True) + c.start() + self.state.connections.add(c) + c = None + logging.debug('Shutting down I2P Listener')