From 717240c8d404dcad7e09eab45cf94ea3ab6cb6b7 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Wed, 11 Sep 2024 02:09:43 +0200 Subject: [PATCH] Cleanup --- LXMF/LXMRouter.py | 2 +- LXMF/LXMessage.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/LXMF/LXMRouter.py b/LXMF/LXMRouter.py index 28e3854..d26f155 100644 --- a/LXMF/LXMRouter.py +++ b/LXMF/LXMRouter.py @@ -1299,7 +1299,7 @@ def save_job(): else: RNS.log(f"Received {message} with invalid stamp, but allowing anyway, since stamp enforcement is disabled", RNS.LOG_NOTICE) else: - RNS.log(f"Received {message} valid stamp", RNS.LOG_DEBUG) + RNS.log(f"Received {message} with valid stamp", RNS.LOG_DEBUG) if phy_stats != None: if "rssi" in phy_stats: message.rssi = phy_stats["rssi"] diff --git a/LXMF/LXMessage.py b/LXMF/LXMessage.py index 5a8a26f..08e1077 100644 --- a/LXMF/LXMessage.py +++ b/LXMF/LXMessage.py @@ -264,10 +264,14 @@ def stamp_valid(stamp, target_cost, workblock): def validate_stamp(self, target_cost, tickets=None): if tickets != None: for ticket in tickets: - if self.stamp == RNS.Identity.truncated_hash(ticket+self.message_id): - RNS.log(f"Stamp on {self} validated by inbound ticket", RNS.LOG_DEBUG) # TODO: Remove at some point - self.stamp_value = LXMessage.COST_TICKET - return True + try: + if self.stamp == RNS.Identity.truncated_hash(ticket+self.message_id): + RNS.log(f"Stamp on {self} validated by inbound ticket", RNS.LOG_DEBUG) # TODO: Remove at some point + self.stamp_value = LXMessage.COST_TICKET + return True + except Exception as e: + RNS.log(f"Error while validating ticket: {e}", RNS.LOG_ERROR) + RNS.trace_exception(e) if self.stamp == None: return False @@ -284,9 +288,10 @@ def get_stamp(self, timeout=None): # If an outbound ticket exists, use this for # generating a valid stamp. if self.outbound_ticket != None and type(self.outbound_ticket) == bytes and len(self.outbound_ticket) == LXMessage.TICKET_LENGTH: - RNS.log(f"Generating stamp with outbound ticket for {self}", RNS.LOG_DEBUG) # TODO: Remove at some point + generated_stamp = RNS.Identity.truncated_hash(self.outbound_ticket+self.message_id) self.stamp_value = LXMessage.COST_TICKET - return RNS.Identity.truncated_hash(self.outbound_ticket+self.message_id) + RNS.log(f"Generated stamp with outbound ticket {RNS.hexrep(self.outbound_ticket)} for {self}", RNS.LOG_DEBUG) # TODO: Remove at some point + return generated_stamp # If no stamp cost is required, we can just # return immediately.