diff --git a/RNS/Interfaces/BackboneInterface.py b/RNS/Interfaces/BackboneInterface.py index 9a262b48..6d602528 100644 --- a/RNS/Interfaces/BackboneInterface.py +++ b/RNS/Interfaces/BackboneInterface.py @@ -757,6 +757,7 @@ class BackboneInterface(Interface): spawned_interface.announce_rate_penalty = self.announce_rate_penalty spawned_interface.mode = self.mode spawned_interface.gravity = self.gravity + spawned_interface.hop_limiter = self.hop_limiter spawned_interface.recursive_prs = self.recursive_prs spawned_interface.announces_from_internal = self.announces_from_internal spawned_interface.announces_to_internal = self.announces_to_internal diff --git a/RNS/Interfaces/I2PInterface.py b/RNS/Interfaces/I2PInterface.py index e74859ca..9a3a08b2 100644 --- a/RNS/Interfaces/I2PInterface.py +++ b/RNS/Interfaces/I2PInterface.py @@ -920,6 +920,7 @@ class I2PInterface(Interface): spawned_interface.mode = self.mode spawned_interface.recursive_prs = self.recursive_prs spawned_interface.gravity = self.gravity + spawned_interface.hop_limiter = self.hop_limiter spawned_interface.HW_MTU = self.HW_MTU RNS.log("Spawned new I2PInterface Peer: "+str(spawned_interface), RNS.LOG_VERBOSE) RNS.Transport.add_interface(spawned_interface) diff --git a/RNS/Interfaces/Interface.py b/RNS/Interfaces/Interface.py index e2396610..c5ee4349 100755 --- a/RNS/Interfaces/Interface.py +++ b/RNS/Interfaces/Interface.py @@ -134,6 +134,7 @@ class Interface: self.wants_tunnel = False self.remote_transport = None self.ingress_control = True + self.hop_limiter = None self.phy_keepalive = False self.shared_medium = False diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index 2372f546..50577029 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -648,6 +648,7 @@ class TCPServerInterface(Interface): spawned_interface.announce_rate_penalty = self.announce_rate_penalty spawned_interface.mode = self.mode spawned_interface.gravity = self.gravity + spawned_interface.hop_limiter = self.hop_limiter spawned_interface.recursive_prs = self.recursive_prs spawned_interface.announces_from_internal = self.announces_from_internal spawned_interface.announces_to_internal = self.announces_to_internal diff --git a/RNS/Interfaces/WeaveInterface.py b/RNS/Interfaces/WeaveInterface.py index 2aa987e0..fa8cbd80 100644 --- a/RNS/Interfaces/WeaveInterface.py +++ b/RNS/Interfaces/WeaveInterface.py @@ -975,6 +975,7 @@ class WeaveInterface(Interface): spawned_interface.mode = self.mode spawned_interface.gravity = self.gravity + spawned_interface.hop_limiter = self.hop_limiter spawned_interface.HW_MTU = self.HW_MTU spawned_interface._online = True diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 1853b70a..c0d9b674 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -1010,6 +1010,11 @@ class Reticulum: gravity = self._default_gravity() if "gravity" in c: gravity = c.as_int("gravity") + hop_limiter = None + if "hop_limiter" in c: + v = c.as_int("hop_limiter") + hop_limiter = max(0, min(v, RNS.Transport.PATHFINDER_M)) + destination_cost = None if "destination_cost" in c: v = c.as_float("destination_cost") @@ -1170,11 +1175,12 @@ class Reticulum: if "outgoing" in c and c.as_bool("outgoing") == False: interface.OUT = False else: interface.OUT = True - interface.mode = interface_mode - interface.gravity = gravity - interface.announce_cap = announce_cap - interface.bootstrap_only = bootstrap_only - if configured_bitrate: interface.bitrate = configured_bitrate + interface.mode = interface_mode + interface.gravity = gravity + interface.hop_limiter = hop_limiter + interface.announce_cap = announce_cap + interface.bootstrap_only = bootstrap_only + if configured_bitrate: interface.bitrate = configured_bitrate interface.optimise_mtu() if ifac_size != None: interface.ifac_size = ifac_size diff --git a/RNS/Transport.py b/RNS/Transport.py index 38f0b538..a53d478c 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -2082,6 +2082,7 @@ class Transport: packet = RNS.Packet(None, raw) if not packet.unpack(): return interface.protocol_violation(f"Malformed packet ({len(raw)} bytes)", level=RNS.LOG_EXTREME) if interface else None + if interface.hop_limiter and not packet.hops < interface.hop_limiter: return interface.hop_limiter_hit() if not packet.hops < Transport.HOP_LIMITER: return interface.hop_limiter_hit() if not Transport.packet_filter(packet): return interface.packet_filter_hit() traffic_class = tc or Transport.TC_DATA