From efb8c8500d87df13d42011cc5c1595beebe44837 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 18 Aug 2026 11:45:20 +0200 Subject: [PATCH] Made queue lengths configurable --- RNS/Interfaces/Interface.py | 2 +- RNS/Reticulum.py | 36 ++++++++++++++++++++++++++++++++++++ RNS/Transport.py | 30 ++++++++++++++++++------------ 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/RNS/Interfaces/Interface.py b/RNS/Interfaces/Interface.py index b629d2e5..a5012e1a 100755 --- a/RNS/Interfaces/Interface.py +++ b/RNS/Interfaces/Interface.py @@ -247,7 +247,7 @@ class Interface: RNS.log("Releasing held announce packet "+str(selected_announce_packet)+" from "+str(self), RNS.LOG_EXTREME) self.ic_held_release = time.time() + self.ic_held_release_interval self.held_announces.pop(selected_announce_packet.destination_hash) - def release(): RNS.Transport.inbound(selected_announce_packet.raw, selected_announce_packet.receiving_interface) + def release(): RNS.Transport.inbound(selected_announce_packet.raw, selected_announce_packet.receiving_interface, tc=RNS.Transport.TC_INGRESS_LIMITED) threading.Thread(target=release, daemon=True).start() except Exception as e: diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 9c380d79..dd5ef1a8 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -284,6 +284,10 @@ class Reticulum: Reticulum.__ic_held_release_interval = None Reticulum.__ec_pr_freq = None Reticulum.__egress_control = None + Reticulum.__inbound_data_queue_length = None + Reticulum.__inbound_announce_queue_length = None + Reticulum.__inbound_pr_queue_length = None + Reticulum.__inbound_il_queue_length = None Reticulum.panic_on_interface_error = False @@ -696,6 +700,22 @@ class Reticulum: v = self.config["reticulum"].as_float(option) if v >= 0: Reticulum.__ic_held_release_interval = v + if option == "qlen_in_data": + v = self.config["reticulum"].as_int(option) + if v > 0: Reticulum.__inbound_data_queue_length = v + + if option == "qlen_in_announce": + v = self.config["reticulum"].as_int(option) + if v > 0: Reticulum.__inbound_announce_queue_length = v + + if option == "qlen_in_pr": + v = self.config["reticulum"].as_int(option) + if v > 0: Reticulum.__inbound_pr_queue_length = v + + if option == "qlen_in_il": + v = self.config["reticulum"].as_int(option) + if v > 0: Reticulum.__inbound_il_queue_length = v + if RNS.compiled: RNS.log("Reticulum running in compiled mode", RNS.LOG_DEBUG) else: RNS.log("Reticulum running in interpreted mode", RNS.LOG_DEBUG) @@ -1900,6 +1920,22 @@ class Reticulum: def local_hops_delta(): return Reticulum.__local_hops_delta + @staticmethod + def default_data_queue_length(): + return Reticulum.__inbound_data_queue_length + + @staticmethod + def default_announce_queue_length(): + return Reticulum.__inbound_announce_queue_length + + @staticmethod + def default_pr_queue_length(): + return Reticulum.__inbound_pr_queue_length + + @staticmethod + def default_il_queue_length(): + return Reticulum.__inbound_il_queue_length + # Default configuration file: __default_rns_config__ = '''# This is the default Reticulum config file. # You should probably edit it to include any additional, diff --git a/RNS/Transport.py b/RNS/Transport.py index d9526858..68d753ad 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -131,11 +131,11 @@ class Transport: USE_INBOUND_QUEUE = True USE_OUTBOUND_QUEUE = False - INBOUND_DA_QUEUE_LENGTH = 8192 - INBOUND_AN_QUEUE_LENGTH = 1024 - INBOUND_PR_QUEUE_LENGTH = 1024 - INBOUND_IL_QUEUE_LENGTH = 256 - OUTBOUND_QUEUE_LENGTH = 32768 + INBOUND_DA_QUEUE_LENGTH = 4096 + INBOUND_AN_QUEUE_LENGTH = 256 + INBOUND_PR_QUEUE_LENGTH = 256 + INBOUND_IL_QUEUE_LENGTH = 128 + OUTBOUND_QUEUE_LENGTH = 4096 STATE_UNKNOWN = 0x00 STATE_UNRESPONSIVE = 0x01 @@ -184,10 +184,7 @@ class Transport: max_queued_discovery_prs = 32 # Maximum amount of queued discovery path requests pr_destination_hash = None # Destination hash of the local path request destination - inbound_queues = InboundQueues((INBOUND_DA_QUEUE_LENGTH, - INBOUND_AN_QUEUE_LENGTH, - INBOUND_PR_QUEUE_LENGTH, - INBOUND_IL_QUEUE_LENGTH)) + inbound_queues = None interfaces_lock = Lock() destinations_lock = Lock() destinations_map_lock = Lock() @@ -279,6 +276,15 @@ class Transport: def start(reticulum_instance): Transport.owner = reticulum_instance + Transport.INBOUND_DA_QUEUE_LENGTH = RNS.Reticulum.default_data_queue_length() or Transport.INBOUND_DA_QUEUE_LENGTH + Transport.INBOUND_AN_QUEUE_LENGTH = RNS.Reticulum.default_announce_queue_length() or Transport.INBOUND_AN_QUEUE_LENGTH + Transport.INBOUND_PR_QUEUE_LENGTH = RNS.Reticulum.default_pr_queue_length() or Transport.INBOUND_PR_QUEUE_LENGTH + Transport.INBOUND_IL_QUEUE_LENGTH = RNS.Reticulum.default_il_queue_length() or Transport.INBOUND_IL_QUEUE_LENGTH + Transport.inbound_queues = InboundQueues((Transport.INBOUND_DA_QUEUE_LENGTH, + Transport.INBOUND_AN_QUEUE_LENGTH, + Transport.INBOUND_PR_QUEUE_LENGTH, + Transport.INBOUND_IL_QUEUE_LENGTH)) + if Transport.identity == None: transport_identity_path = RNS.Reticulum.storagepath+"/transport_identity" if os.path.isfile(transport_identity_path): @@ -1519,7 +1525,7 @@ class Transport: return False @staticmethod - def inbound(raw, interface=None): + def inbound(raw, interface=None, tc=None): if not Transport.ready: wait_start = time.time() while not Transport.ready: @@ -1584,14 +1590,14 @@ class Transport: packet = RNS.Packet(None, raw) if not packet.unpack(): return if not Transport.packet_filter(packet): return - traffic_class = Transport.TC_DATA + traffic_class = tc or Transport.TC_DATA packet.receiving_interface = interface packet.hops += 1 # Ingress limit announces early if packet.packet_type == RNS.Packet.ANNOUNCE: - traffic_class = Transport.TC_ANNOUNCE + if not tc: traffic_class = Transport.TC_ANNOUNCE announce_signature_valid = RNS.Identity.validate_announce(packet, only_validate_signature=True) if not announce_signature_valid: return elif packet.receiving_interface != None: packet.receiving_interface.received_announce()