From 503f475ca5ee44e8a02fa82d077e422f64848f85 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 11 Jan 2025 03:12:31 +0100 Subject: [PATCH] Read link MTU from link request packet --- RNS/Interfaces/LocalInterface.py | 2 +- RNS/Interfaces/TCPInterface.py | 2 +- RNS/Link.py | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/RNS/Interfaces/LocalInterface.py b/RNS/Interfaces/LocalInterface.py index f007cc9f..9dff4c26 100644 --- a/RNS/Interfaces/LocalInterface.py +++ b/RNS/Interfaces/LocalInterface.py @@ -59,7 +59,7 @@ def __init__(self, owner, name, target_port = None, connected_socket=None): # TODO: Remove at some point # self.rxptime = 0 - self.HW_MTU = 1064 + self.HW_MTU = 32768 self.online = False diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index 563e38b6..bd601494 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -96,7 +96,7 @@ def __init__(self, owner, configuration, connected_socket=None): connect_timeout = c.as_int("connect_timeout") if "connect_timeout" in c else None max_reconnect_tries = c.as_int("max_reconnect_tries") if "max_reconnect_tries" in c else None - self.HW_MTU = 1064 + self.HW_MTU = 32768 self.IN = True self.OUT = False diff --git a/RNS/Link.py b/RNS/Link.py index c53fb959..f90adadc 100644 --- a/RNS/Link.py +++ b/RNS/Link.py @@ -68,8 +68,9 @@ class Link: Timeout for link establishment in seconds per hop to destination. """ - TRAFFIC_TIMEOUT_MIN_MS = 5 - TRAFFIC_TIMEOUT_FACTOR = 6 + LINK_MTU_SIZE = 3 + TRAFFIC_TIMEOUT_MIN_MS = 5 + TRAFFIC_TIMEOUT_FACTOR = 6 KEEPALIVE_TIMEOUT_FACTOR = 4 """ RTT timeout factor used in link timeout calculation. @@ -108,14 +109,22 @@ class Link: @staticmethod def validate_request(owner, data, packet): - if len(data) == (Link.ECPUBSIZE): + if len(data) == Link.ECPUBSIZE or len(data) == Link.ECPUBSIZE+Link.LINK_MTU_SIZE: try: link = Link(owner = owner, peer_pub_bytes=data[:Link.ECPUBSIZE//2], peer_sig_pub_bytes=data[Link.ECPUBSIZE//2:Link.ECPUBSIZE]) link.set_link_id(packet) + + if len(data) == Link.ECPUBSIZE+Link.LINK_MTU_SIZE: + try: + link.mtu = (ord(a[Link.ECPUBSIZE]) << 16) + (ord(a[Link.ECPUBSIZE+1]) << 8) + (ord(a[Link.ECPUBSIZE+2])) + except Exception as e: + link.mtu = Reticulum.MTU + link.destination = packet.destination link.establishment_timeout = Link.ESTABLISHMENT_TIMEOUT_PER_HOP * max(1, packet.hops) + Link.KEEPALIVE link.establishment_cost += len(packet.raw) - RNS.log("Validating link request "+RNS.prettyhexrep(link.link_id), RNS.LOG_VERBOSE) + RNS.log(f"Validating link request {RNS.prettyhexrep(link.link_id), RNS.LOG_VERBOSE}") + RNS.log(f"Link MTU configured to {RNS.prettysize(link.mtu)}", RNS.LOG_EXTREME) RNS.log(f"Establishment timeout is {RNS.prettytime(link.establishment_timeout)} for incoming link request "+RNS.prettyhexrep(link.link_id), RNS.LOG_EXTREME) link.handshake() link.attached_interface = packet.receiving_interface @@ -142,6 +151,7 @@ def __init__(self, destination=None, established_callback = None, closed_callbac if destination != None and destination.type != RNS.Destination.SINGLE: raise TypeError("Links can only be established to the \"single\" destination type") self.rtt = None + self.mtu = Reticulum.MTU self.establishment_cost = 0 self.establishment_rate = None self.callbacks = LinkCallbacks()