From 331b26dfe94b6a07462a6eeb16c2540fbaf4622f Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Tue, 19 Dec 2023 03:08:04 +0200 Subject: [PATCH] Don't connect to nodes with the same nonce --- minode/connection.py | 6 ++++++ minode/manager.py | 4 ++++ minode/shared.py | 1 + 3 files changed, 11 insertions(+) diff --git a/minode/connection.py b/minode/connection.py index b7f9a75..169568d 100644 --- a/minode/connection.py +++ b/minode/connection.py @@ -380,10 +380,16 @@ class ConnectionBase(threading.Thread): if ( version.protocol_version != shared.protocol_version or version.nonce == shared.nonce + or version.nonce in shared.nonce_pool.values() ): + logging.warning( + 'Disconnecting v%s node %s with nonce %s', + version.protocol_version, self.host_print, + base64.b16encode(version.nonce)) self.status = 'disconnecting' self.send_queue.put(None) else: + shared.nonce_pool[self.host] = version.nonce logging.info( '%s:%s claims to be %s', self.host_print, self.port, version.user_agent) diff --git a/minode/manager.py b/minode/manager.py index a03f9d6..f40d49d 100644 --- a/minode/manager.py +++ b/minode/manager.py @@ -76,6 +76,10 @@ class Manager(threading.Thread): if not c.is_alive() or c.status == 'disconnected': with shared.connections_lock: shared.connections.remove(c) + try: + del shared.nonce_pool[c.host] + except KeyError: + pass else: hosts.add(structure.NetAddrNoPrefix.network_group(c.host)) if not c.server: diff --git a/minode/shared.py b/minode/shared.py index 72864ec..d5ac8f4 100644 --- a/minode/shared.py +++ b/minode/shared.py @@ -54,6 +54,7 @@ core_nodes = set() node_pool = set() unchecked_node_pool = set() +nonce_pool = {} i2p_core_nodes = set() i2p_node_pool = set()