Improved PR ingress limiter

This commit is contained in:
Mark Qvist 2026-08-18 13:17:34 +02:00
parent 1a70bd3cd1
commit 503bd6c87b
No known key found for this signature in database
3 changed files with 12 additions and 5 deletions

View file

@ -122,6 +122,7 @@ class Interface:
self.ic_burst_activated = 0
self.ic_pr_burst_active = False
self.ic_pr_burst_activated = 0
self.ic_pr_burst_cooldown = 0
self.ic_held_release = 0
self.ic_max_held_announces = RNS.Reticulum.get_instance()._default_ic_max_held_announces()
self.ic_burst_hold = RNS.Reticulum.get_instance()._default_ic_burst_hold()
@ -178,7 +179,9 @@ class Interface:
if self.ic_pr_burst_active:
if ip_freq < freq_threshold and time.time() > self.ic_pr_burst_activated+self.ic_burst_hold:
self.ic_pr_burst_active = False
if self.ic_pr_burst_cooldown <= 0: self.ic_pr_burst_active = False
else: self.ic_pr_burst_cooldown -= 1
else: self.ic_pr_burst_cooldown = 3
return True
@ -186,6 +189,7 @@ class Interface:
if ip_freq > freq_threshold:
self.ic_pr_burst_active = True
self.ic_pr_burst_activated = time.time()
self.ic_pr_burst_cooldown = 3
return True
else: return False

View file

@ -117,7 +117,7 @@ class Packet:
__slots__ = "hops", "header", "header_type", "packet_type", "transport_type", "context", "context_flag", "destination"
__slots__ += "transport_id", "data", "flags", "raw", "packed", "sent", "create_receipt", "receipt", "fromPacked", "MTU"
__slots__ += "sent_at", "packet_hash", "ratchet_id", "attached_interface", "receiving_interface", "rssi", "snr", "q"
__slots__ += "ciphertext", "plaintext", "destination_hash", "destination_type", "link", "map_hash", "is_outbound_pr"
__slots__ += "ciphertext", "plaintext", "destination_hash", "destination_type", "link", "map_hash", "is_outbound_pr", "traffic_class"
def __init__(self, destination, data, packet_type = DATA, context = NONE, transport_type = RNS.Transport.BROADCAST,
header_type = HEADER_1, transport_id = None, attached_interface = None, create_receipt = True, context_flag=FLAG_UNSET):
@ -159,6 +159,7 @@ class Packet:
self.packet_hash = None
self.ratchet_id = None
self.traffic_class = None
self.attached_interface = attached_interface
self.receiving_interface = None
self.is_outbound_pr = False

View file

@ -1657,6 +1657,7 @@ class Transport:
if not Transport.USE_INBOUND_QUEUE: return Transport._inbound(packet)
else:
if traffic_class == Transport.TC_INGRESS_LIMITED: packet.traffic_class = Transport.TC_INGRESS_LIMITED
try: Transport.inbound_queues.put(traffic_class, packet, block=False)
except Full: RNS.log(f"Dropping inbound packet, queue is full (tc={traffic_class})", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None
except Exception as e: RNS.log(f"Error while inserting into inbound queue: {e}", RNS.LOG_ERROR)
@ -3147,19 +3148,20 @@ class Transport:
Transport.from_local_client(packet),
packet.receiving_interface,
requestor_transport_id = requesting_transport_instance,
tag=tag_bytes)
tag=tag_bytes,
ingress_limited=packet.traffic_class == Transport.TC_INGRESS_LIMITED)
else: RNS.log("Ignoring tagless path request for "+RNS.prettyhexrep(destination_hash), RNS.LOG_PATHING) if RNS.sl(RNS.LOG_PATHING) else None
except Exception as e: RNS.log(f"Error while handling path request. The contained exception was: {e}", RNS.LOG_ERROR)
@staticmethod
def path_request(destination_hash, is_from_local_client, attached_interface, requestor_transport_id=None, tag=None):
def path_request(destination_hash, is_from_local_client, attached_interface, requestor_transport_id=None, tag=None, ingress_limited=False):
should_search_for_unknown = False
should_ingress_limit = False
search_mode_filter = None
if attached_interface != None:
should_ingress_limit = attached_interface.should_ingress_limit_pr()
should_ingress_limit = ingress_limited or attached_interface.should_ingress_limit_pr()
if RNS.Reticulum.transport_enabled():
if attached_interface.recursive_prs: should_search_for_unknown = True
elif attached_interface.mode in RNS.Interfaces.Interface.Interface.DISCOVER_PATHS_FOR: should_search_for_unknown = True