Improved protocol violation logging

This commit is contained in:
Mark Qvist 2026-11-02 22:51:28 +01:00
parent cda4d72bb8
commit ecd677ba7f
No known key found for this signature in database
2 changed files with 5 additions and 8 deletions

View file

@ -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):

View file

@ -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