Reject duplicate I2P connections and do not connect to ourselves
This commit is contained in:
parent
7ff7a16470
commit
f74cb829fc
|
@ -20,7 +20,7 @@ class I2PListener(threading.Thread):
|
||||||
|
|
||||||
self.version_reply = []
|
self.version_reply = []
|
||||||
|
|
||||||
self.create_socket()
|
self.new_socket()
|
||||||
|
|
||||||
def _receive_line(self):
|
def _receive_line(self):
|
||||||
line = receive_line(self.s)
|
line = receive_line(self.s)
|
||||||
|
@ -31,7 +31,7 @@ class I2PListener(threading.Thread):
|
||||||
# logging.debug('I2PListener -> ' + str(command))
|
# logging.debug('I2PListener -> ' + str(command))
|
||||||
self.s.sendall(command)
|
self.s.sendall(command)
|
||||||
|
|
||||||
def create_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')
|
||||||
self.version_reply = self._receive_line().split()
|
self.version_reply = self._receive_line().split()
|
||||||
|
@ -48,10 +48,20 @@ class I2PListener(threading.Thread):
|
||||||
try:
|
try:
|
||||||
destination = self._receive_line().split()[0]
|
destination = self._receive_line().split()[0]
|
||||||
logging.info('Incoming I2P connection from: {}'.format(destination.decode()))
|
logging.info('Incoming I2P connection from: {}'.format(destination.decode()))
|
||||||
|
|
||||||
|
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 = Connection(destination, 'i2p', self.s, 'i2p', True, destination)
|
||||||
c.start()
|
c.start()
|
||||||
shared.connections.add(c)
|
shared.connections.add(c)
|
||||||
self.create_socket()
|
self.new_socket()
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
pass
|
pass
|
||||||
logging.debug('Shutting down I2P Listener')
|
logging.debug('Shutting down I2P Listener')
|
||||||
|
|
|
@ -105,7 +105,7 @@ class Manager(threading.Thread):
|
||||||
if addr[0] in hosts:
|
if addr[0] in hosts:
|
||||||
continue
|
continue
|
||||||
if addr[1] == 'i2p' and shared.i2p_enabled:
|
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:
|
try:
|
||||||
d = I2PDialer(addr[0], shared.i2p_session_nick, shared.i2p_sam_host, shared.i2p_sam_port)
|
d = I2PDialer(addr[0], shared.i2p_session_nick, shared.i2p_sam_host, shared.i2p_sam_port)
|
||||||
d.start()
|
d.start()
|
||||||
|
@ -115,7 +115,6 @@ class Manager(threading.Thread):
|
||||||
logging.warning('Exception while trying to establish an I2P connection')
|
logging.warning('Exception while trying to establish an I2P connection')
|
||||||
logging.warning(e)
|
logging.warning(e)
|
||||||
else:
|
else:
|
||||||
logging.debug('We were going to connect to an I2P peer but our tunnels are not ready')
|
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
c = Connection(addr[0], addr[1])
|
c = Connection(addr[0], addr[1])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user