From 97cfdfd0231938b950cb7037e076c7c7fe421138 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 11 Jan 2025 16:58:09 +0100 Subject: [PATCH] Unify link ID across versions regardless of MTU discovery support --- RNS/Link.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/RNS/Link.py b/RNS/Link.py index 8333ed7..f2b62b9 100644 --- a/RNS/Link.py +++ b/RNS/Link.py @@ -127,10 +127,6 @@ class Link: else: return None - @staticmethod - def link_id_from_lr_packet(packet): - return RNS.Identity.truncated_hash(packet.get_hashable_part()[:Link.ECPUBSIZE]) - @staticmethod def validate_request(owner, data, packet): if len(data) == Link.ECPUBSIZE or len(data) == Link.ECPUBSIZE+Link.LINK_MTU_SIZE: @@ -276,6 +272,15 @@ class Link: if not hasattr(self.peer_pub, "curve"): self.peer_pub.curve = Link.CURVE + @staticmethod + def link_id_from_lr_packet(packet): + hashable_part = packet.get_hashable_part() + if len(packet.data) > Link.ECPUBSIZE: + diff = len(packet.data) - Link.ECPUBSIZE + hashable_part = hashable_part[:-diff] + + return RNS.Identity.truncated_hash(hashable_part) + def set_link_id(self, packet): self.link_id = Link.link_id_from_lr_packet(packet) self.hash = self.link_id