From 66ce58f0f4f5d0105004d2448bb3030b516d0fe1 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 9 Oct 2021 22:13:27 +0200 Subject: [PATCH] Implemented path updating for moving nodes --- RNS/Destination.py | 3 --- RNS/Transport.py | 27 ++++++++++++--------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/RNS/Destination.py b/RNS/Destination.py index 0e9426b..2d24fbb 100755 --- a/RNS/Destination.py +++ b/RNS/Destination.py @@ -149,9 +149,6 @@ class Destination: destination_hash = self.hash random_hash = RNS.Identity.get_random_hash()[0:5]+int(time.time()).to_bytes(5, "big") - # TODO: Remove - RNS.log("ArB: "+RNS.hexrep(random_hash)) - if app_data == None and self.default_app_data != None: if isinstance(self.default_app_data, bytes): app_data = self.default_app_data diff --git a/RNS/Transport.py b/RNS/Transport.py index 4f07ab1..1676de7 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -775,12 +775,8 @@ class Transport: # First, check that the announce is not for a destination # 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] - + random_blob = packet.data[RNS.Identity.KEYSIZE//8:RNS.Identity.KEYSIZE//8+RNS.Reticulum.TRUNCATED_HASHLENGTH//8] announce_emitted = int.from_bytes(random_blob[5:10], "big") - # TODO: Remove - RNS.log("ArB: "+RNS.hexrep(random_blob)) - 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] @@ -807,17 +803,12 @@ class Transport: 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: + for path_random_blob in random_blobs: + path_announce_emitted = max(path_announce_emitted, int.from_bytes(path_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): + if (now >= path_expires): # We also check that the announce hash is # different from ones we've already heard, # to avoid loops in the network @@ -829,7 +820,13 @@ class Transport: else: should_add = False else: - should_add = False + if (announce_emitted > path_announce_emitted): + if not random_blob in random_blobs: + RNS.log("Replacing destination table entry for "+str(RNS.prettyhexrep(packet.destination_hash))+" with new announce, since it was more recently emitted", RNS.LOG_DEBUG) + should_add = True + else: + should_add = False + else: # If this destination is unknown in our table # we should add it