From ecd677ba7fe6ac0ad0bcc7ee8f33e84b2c725d15 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 2 Nov 2026 22:51:28 +0100 Subject: [PATCH] Improved protocol violation logging --- RNS/Interfaces/Interface.py | 5 +++-- RNS/Transport.py | 8 ++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/RNS/Interfaces/Interface.py b/RNS/Interfaces/Interface.py index 722bbf94..4a3043e7 100755 --- a/RNS/Interfaces/Interface.py +++ b/RNS/Interfaces/Interface.py @@ -328,9 +328,10 @@ class Interface: if hasattr(self, "parent_interface") and self.parent_interface != None: self.parent_interface.sent_path_request(size=size, from_spawned=True) - def protocol_violation(self, description=None): + def protocol_violation(self, description=None, level=None): + if level == None: level = RNS.LOG_DEBUG self.protocol_violations += 1 - RNS.log(f"Protocol violation on {self}: {description}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None + RNS.log(f"Protocol violation on {self}: {description}", level) if RNS.sl(level) else None return None def ifac_violation(self, description=None): diff --git a/RNS/Transport.py b/RNS/Transport.py index 58a7f0c1..17eab5da 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -2067,11 +2067,7 @@ class Transport: elif len(packet.data) > Transport.PR_STAMPED_LENGTH: return packet.receiving_interface.protocol_violation(f"Excessive path request size of {len(packet.data)} bytes") if packet.receiving_interface else None else: pr = Transport.parse_path_request(packet.data) - if pr == None: - destination_hash = packet.data[:RNS.Identity.TRUNCATED_HASHLENGTH//8] - RNS.log(f"Ignoring tagless path request for {RNS.prettyhexrep(destination_hash)}", RNS.LOG_PATHING) if RNS.sl(RNS.LOG_PATHING) else None - return packet.receiving_interface.protocol_violation("Tagless path request") if packet.receiving_interface else None - + if pr == None: return packet.receiving_interface.protocol_violation("Tagless path request", level=RNS.LOG_PATHING) if packet.receiving_interface else None else: destination_hash = pr[0] tag_bytes = pr[2] @@ -2080,7 +2076,7 @@ class Transport: pr_length = len(packet.data) if pr_length != Transport.PR_STAMPED_LENGTH and pr_length != Transport.PR_LENGTH and pr_length != Transport.PR_LEGACY_LENGTH: # TODO: Only allow stamped size after transition - if packet.receiving_interface: return packet.receiving_interface.protocol_violation(f"Invalid path request size {pr_length}") + if packet.receiving_interface: return packet.receiving_interface.protocol_violation(f"Invalid path request size {pr_length}", level=RNS.LOG_PATHING) unique_tag = destination_hash+tag_bytes