diff --git a/RNS/Destination.py b/RNS/Destination.py index 0418d56..2d24fbb 100755 --- a/RNS/Destination.py +++ b/RNS/Destination.py @@ -1,5 +1,6 @@ import base64 import math +import time import RNS from cryptography.fernet import Fernet @@ -146,7 +147,7 @@ class Destination: :param path_response: Internal flag used by :ref:`RNS.Transport`. Ignore. """ destination_hash = self.hash - random_hash = RNS.Identity.get_random_hash() + random_hash = RNS.Identity.get_random_hash()[0:5]+int(time.time()).to_bytes(5, "big") if app_data == None and self.default_app_data != None: if isinstance(self.default_app_data, bytes): diff --git a/RNS/Resource.py b/RNS/Resource.py index c8c391c..41fcb07 100644 --- a/RNS/Resource.py +++ b/RNS/Resource.py @@ -804,7 +804,7 @@ class Resource: return progress def __str__(self): - return RNS.prettyhexrep(self.hash)+str(self.link) + return "<"+RNS.hexrep(self.hash)+"/"+RNS.hexrep(self.link.link_id)+">" class ResourceAdvertisement: diff --git a/RNS/Transport.py b/RNS/Transport.py index dc07bd3..5d314fb 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -776,6 +776,9 @@ class Transport: # local to this system, and that hops are less than the max if (not any(packet.destination_hash == d.hash for d in Transport.destinations) and packet.hops < Transport.PATHFINDER_M+1): random_blob = packet.data[RNS.Identity.KEYSIZE//8+10:RNS.Identity.KEYSIZE//8+20] + announce_emitted = int.from_bytes(random_blob[5:10], "big") + # TODO: Remove + RNS.log("Announce timestamp is: "+str(announce_emitted)) random_blobs = [] if packet.destination_hash in Transport.destination_table: random_blobs = Transport.destination_table[packet.destination_hash][4] @@ -796,8 +799,23 @@ class Transport: else: # If an announce arrives with a larger hop # count than we already have in the table, - # ignore it, unless the path is expired - if (time.time() > Transport.destination_table[packet.destination_hash][3]): + # ignore it, unless the path is expired, or + # the emission timestamp is more recent. + now = time.time() + path_expires = Transport.destination_table[packet.destination_hash][3] + + path_announce_emitted = 0 + for random_blob in random_blobs: + path_announce_emitted = max(path_announce_emitted, int.from_bytes(random_blob[5:10], "big")) + if path_announce_emitted > announce_emitted: + break + + # TODO: Remove + RNS.log("PA e: "+str(path_announce_emitted)) + RNS.log("A e: "+str(announce_emitted)) + ############## + + if (now >= path_expires or announce_emitted >= path_announce_emitted): # We also check that the announce hash is # different from ones we've already heard, # to avoid loops in the network