From 76dd50a06084f3dd2d0fe378299d91629ac667ca Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 13 Jul 2025 13:14:18 +0200 Subject: [PATCH] Fixed potential AutoInterface peer discovery add before final init complete --- RNS/Interfaces/AutoInterface.py | 18 ++++++++++-------- RNS/Reticulum.py | 10 ++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/RNS/Interfaces/AutoInterface.py b/RNS/Interfaces/AutoInterface.py index 5bdf468..d3064a3 100644 --- a/RNS/Interfaces/AutoInterface.py +++ b/RNS/Interfaces/AutoInterface.py @@ -119,6 +119,7 @@ class AutoInterface(Interface): self.name = name self.owner = owner self.online = False + self.final_init_done = False self.peers = {} self.link_local_addresses = [] self.adopted_interfaces = {} @@ -274,8 +275,7 @@ class AutoInterface(Interface): discovery_socket.bind(addr_info[0][4]) # Set up thread for discovery packets - def discovery_loop(): - self.discovery_handler(discovery_socket, ifname) + def discovery_loop(): self.discovery_handler(discovery_socket, ifname) thread = threading.Thread(target=discovery_loop) thread.daemon = True @@ -325,6 +325,7 @@ class AutoInterface(Interface): time.sleep(peering_wait) self.online = True + self.final_init_done = True def discovery_handler(self, socket, ifname): def announce_loop(): @@ -336,12 +337,13 @@ class AutoInterface(Interface): while True: data, ipv6_src = socket.recvfrom(1024) - peering_hash = data[:RNS.Identity.HASHLENGTH//8] - expected_hash = RNS.Identity.full_hash(self.group_id+ipv6_src[0].encode("utf-8")) - if peering_hash == expected_hash: - self.add_peer(ipv6_src[0], ifname) - else: - RNS.log(str(self)+" received peering packet on "+str(ifname)+" from "+str(ipv6_src[0])+", but authentication hash was incorrect.", RNS.LOG_DEBUG) + if self.final_init_done: + peering_hash = data[:RNS.Identity.HASHLENGTH//8] + expected_hash = RNS.Identity.full_hash(self.group_id+ipv6_src[0].encode("utf-8")) + if peering_hash == expected_hash: + self.add_peer(ipv6_src[0], ifname) + else: + RNS.log(str(self)+" received peering packet on "+str(ifname)+" from "+str(ipv6_src[0])+", but authentication hash was incorrect.", RNS.LOG_DEBUG) def peer_jobs(self): while True: diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 23d88f6..cd80e64 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -651,13 +651,11 @@ class Reticulum: interface.mode = interface_mode interface.announce_cap = announce_cap - if configured_bitrate: - interface.bitrate = configured_bitrate + if configured_bitrate: interface.bitrate = configured_bitrate interface.optimise_mtu() - if ifac_size != None: - interface.ifac_size = ifac_size - else: - interface.ifac_size = interface.DEFAULT_IFAC_SIZE + + if ifac_size != None: interface.ifac_size = ifac_size + else: interface.ifac_size = interface.DEFAULT_IFAC_SIZE interface.announce_rate_target = announce_rate_target interface.announce_rate_grace = announce_rate_grace