From 873f049e206b9c8a40c716f7d551a80418a9bdb7 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 2 Nov 2023 04:35:57 +0100 Subject: [PATCH] Fixed redundant rediscovery path request --- RNS/Interfaces/Android/RNodeInterface.py | 2 +- RNS/Interfaces/RNodeInterface.py | 2 +- RNS/Reticulum.py | 2 +- RNS/Transport.py | 25 ++++++++++++++++++------ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/RNS/Interfaces/Android/RNodeInterface.py b/RNS/Interfaces/Android/RNodeInterface.py index dac5926..cb71c6c 100644 --- a/RNS/Interfaces/Android/RNodeInterface.py +++ b/RNS/Interfaces/Android/RNodeInterface.py @@ -1170,7 +1170,7 @@ class RNodeInterface(Interface): if got == 0: time_since_last = int(time.time()*1000) - last_read_ms if len(data_buffer) > 0 and time_since_last > self.timeout: - RNS.log(str(self)+" serial read timeout", RNS.LOG_DEBUG) + RNS.log(str(self)+" serial read timeout", RNS.LOG_WARNING) data_buffer = b"" in_frame = False command = KISS.CMD_UNKNOWN diff --git a/RNS/Interfaces/RNodeInterface.py b/RNS/Interfaces/RNodeInterface.py index 07f5c50..d15178e 100644 --- a/RNS/Interfaces/RNodeInterface.py +++ b/RNS/Interfaces/RNodeInterface.py @@ -799,7 +799,7 @@ class RNodeInterface(Interface): else: time_since_last = int(time.time()*1000) - last_read_ms if len(data_buffer) > 0 and time_since_last > self.timeout: - RNS.log(str(self)+" serial read timeout", RNS.LOG_DEBUG) + RNS.log(str(self)+" serial read timeout", RNS.LOG_WARNING) data_buffer = b"" in_frame = False command = KISS.CMD_UNKNOWN diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index d9baa70..496f5c8 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -119,7 +119,7 @@ class Reticulum: # TODO: Let Reticulum somehow continously build a map of per-hop # latencies and use this map for global timeout calculation. - DEFAULT_PER_HOP_TIMEOUT = 4 + DEFAULT_PER_HOP_TIMEOUT = 6 # Length of truncated hashes in bits. TRUNCATED_HASHLENGTH = 128 diff --git a/RNS/Transport.py b/RNS/Transport.py index 1cff195..8f03910 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -305,7 +305,8 @@ class Transport: @staticmethod def jobs(): outgoing = [] - path_requests = [] + path_requests = {} + blocked_if = None Transport.jobs_running = True try: @@ -333,7 +334,7 @@ class Transport: if time.time() - last_path_request > Transport.PATH_REQUEST_MI: RNS.log("Trying to rediscover path for "+RNS.prettyhexrep(link.destination.hash)+" since an attempted link was never established", RNS.LOG_DEBUG) if not link.destination.hash in path_requests: - path_requests.append(link.destination.hash) + path_requests[link.destination.hash] = None Transport.pending_links.remove(link) @@ -482,14 +483,16 @@ class Transport: elif not path_request_throttle and Transport.hops_to(link_entry[6]) == 1: RNS.log("Trying to rediscover path for "+RNS.prettyhexrep(link_entry[6])+" since an attempted link was never established, and destination was previously local to an interface on this instance", RNS.LOG_DEBUG) path_request_conditions = True + blocked_if = link_entry[4] - # If the link initiator was previously only 1 hop - # away, this likely means that network topology has + # If the link initiator is only 1 hop away, + # this likely means that network topology has # changed. In that case, we try to discover a new path, # and mark the old one as potentially unresponsive. elif not path_request_throttle and lr_taken_hops == 1: RNS.log("Trying to rediscover path for "+RNS.prettyhexrep(link_entry[6])+" since an attempted link was never established, and link initiator is local to an interface on this instance", RNS.LOG_DEBUG) path_request_conditions = True + blocked_if = link_entry[4] if RNS.Reticulum.transport_enabled(): if hasattr(link_entry[4], "mode") and link_entry[4].mode != RNS.Interfaces.Interface.Interface.MODE_BOUNDARY: @@ -497,7 +500,7 @@ class Transport: if path_request_conditions: if not link_entry[6] in path_requests: - path_requests.append(link_entry[6]) + path_requests[link_entry[6]] = blocked_if if not RNS.Reticulum.transport_enabled(): # Drop current path if we are not a transport instance, to @@ -652,7 +655,17 @@ class Transport: packet.send() for destination_hash in path_requests: - Transport.request_path(destination_hash) + blocked_if = path_requests[destination_hash] + if blocked_if == None: + Transport.request_path(destination_hash) + else: + for interface in Transport.interfaces: + if interface != blocked_if: + # RNS.log("Transmitting path request on "+str(interface), RNS.LOG_DEBUG) + Transport.request_path(destination_hash, on_interface=interface) + else: + pass + # RNS.log("Blocking path request on "+str(interface), RNS.LOG_DEBUG) @staticmethod def transmit(interface, raw):