Skip to content

Commit

Permalink
Read link MTU from link request packet
Browse files Browse the repository at this point in the history
  • Loading branch information
markqvist committed Jan 11, 2025
1 parent 8506118 commit 503f475
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion RNS/Interfaces/LocalInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion RNS/Interfaces/TCPInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions RNS/Link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 503f475

Please sign in to comment.