Rewrite duplicate connection handling in i2p.listener, correct except clause
This commit is contained in:
parent
efc4be0ec1
commit
21fe906ac3
|
@ -15,8 +15,6 @@ class I2PListener(I2PThread):
|
||||||
|
|
||||||
self.version_reply = []
|
self.version_reply = []
|
||||||
|
|
||||||
self.new_socket()
|
|
||||||
|
|
||||||
def new_socket(self):
|
def new_socket(self):
|
||||||
self.s = socket.create_connection((self.host, self.port))
|
self.s = socket.create_connection((self.host, self.port))
|
||||||
self._send(b'HELLO VERSION MIN=3.0 MAX=3.3\n')
|
self._send(b'HELLO VERSION MIN=3.0 MAX=3.3\n')
|
||||||
|
@ -31,18 +29,26 @@ class I2PListener(I2PThread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while not self.state.shutting_down:
|
while not self.state.shutting_down:
|
||||||
|
self.new_socket()
|
||||||
|
duplicate = False
|
||||||
try:
|
try:
|
||||||
destination = self._receive_line().split()[0]
|
destination = self._receive_line().split()[0]
|
||||||
logging.info(
|
logging.info(
|
||||||
'Incoming I2P connection from: %s', destination.decode())
|
'Incoming I2P connection from: %s', destination.decode())
|
||||||
|
except socket.timeout:
|
||||||
|
continue
|
||||||
|
|
||||||
hosts = set()
|
|
||||||
for c in self.state.connections.copy():
|
for c in self.state.connections.copy():
|
||||||
hosts.add(c.host)
|
if c.host == destination:
|
||||||
|
duplicate = True
|
||||||
|
break
|
||||||
|
else:
|
||||||
for d in self.state.i2p_dialers.copy():
|
for d in self.state.i2p_dialers.copy():
|
||||||
hosts.add(d.destination)
|
if d.destination == destination:
|
||||||
if destination in hosts:
|
duplicate = True
|
||||||
logging.debug('Rejecting duplicate I2P connection.')
|
break
|
||||||
|
if duplicate:
|
||||||
|
logging.info('Rejecting duplicate I2P connection.')
|
||||||
self.s.close()
|
self.s.close()
|
||||||
else:
|
else:
|
||||||
c = self.state.connection(
|
c = self.state.connection(
|
||||||
|
@ -50,7 +56,5 @@ class I2PListener(I2PThread):
|
||||||
c.start()
|
c.start()
|
||||||
self.state.connections.add(c)
|
self.state.connections.add(c)
|
||||||
c = None
|
c = None
|
||||||
self.new_socket()
|
|
||||||
except socket.timeout:
|
|
||||||
pass
|
|
||||||
logging.debug('Shutting down I2P Listener')
|
logging.debug('Shutting down I2P Listener')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user