Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
markqvist committed Sep 11, 2024
1 parent 4537728 commit 717240c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion LXMF/LXMRouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
17 changes: 11 additions & 6 deletions LXMF/LXMessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 717240c

Please sign in to comment.