Skip to content

Commit 66ce58f

Browse files
committed
Implemented path updating for moving nodes
1 parent e8ee26f commit 66ce58f

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

RNS/Destination.py

-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ def announce(self, app_data=None, path_response=False):
149149
destination_hash = self.hash
150150
random_hash = RNS.Identity.get_random_hash()[0:5]+int(time.time()).to_bytes(5, "big")
151151

152-
# TODO: Remove
153-
RNS.log("ArB: "+RNS.hexrep(random_hash))
154-
155152
if app_data == None and self.default_app_data != None:
156153
if isinstance(self.default_app_data, bytes):
157154
app_data = self.default_app_data

RNS/Transport.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -775,12 +775,8 @@ def inbound(raw, interface=None):
775775
# First, check that the announce is not for a destination
776776
# local to this system, and that hops are less than the max
777777
if (not any(packet.destination_hash == d.hash for d in Transport.destinations) and packet.hops < Transport.PATHFINDER_M+1):
778-
random_blob = packet.data[RNS.Identity.KEYSIZE//8+10:RNS.Identity.KEYSIZE//8+20]
779-
778+
random_blob = packet.data[RNS.Identity.KEYSIZE//8:RNS.Identity.KEYSIZE//8+RNS.Reticulum.TRUNCATED_HASHLENGTH//8]
780779
announce_emitted = int.from_bytes(random_blob[5:10], "big")
781-
# TODO: Remove
782-
RNS.log("ArB: "+RNS.hexrep(random_blob))
783-
RNS.log("Announce timestamp is: "+str(announce_emitted))
784780
random_blobs = []
785781
if packet.destination_hash in Transport.destination_table:
786782
random_blobs = Transport.destination_table[packet.destination_hash][4]
@@ -807,17 +803,12 @@ def inbound(raw, interface=None):
807803
path_expires = Transport.destination_table[packet.destination_hash][3]
808804

809805
path_announce_emitted = 0
810-
for random_blob in random_blobs:
811-
path_announce_emitted = max(path_announce_emitted, int.from_bytes(random_blob[5:10], "big"))
812-
if path_announce_emitted > announce_emitted:
806+
for path_random_blob in random_blobs:
807+
path_announce_emitted = max(path_announce_emitted, int.from_bytes(path_random_blob[5:10], "big"))
808+
if path_announce_emitted >= announce_emitted:
813809
break
814810

815-
# TODO: Remove
816-
RNS.log("PA e: "+str(path_announce_emitted))
817-
RNS.log("A e: "+str(announce_emitted))
818-
##############
819-
820-
if (now >= path_expires or announce_emitted >= path_announce_emitted):
811+
if (now >= path_expires):
821812
# We also check that the announce hash is
822813
# different from ones we've already heard,
823814
# to avoid loops in the network
@@ -829,7 +820,13 @@ def inbound(raw, interface=None):
829820
else:
830821
should_add = False
831822
else:
832-
should_add = False
823+
if (announce_emitted > path_announce_emitted):
824+
if not random_blob in random_blobs:
825+
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)
826+
should_add = True
827+
else:
828+
should_add = False
829+
833830
else:
834831
# If this destination is unknown in our table
835832
# we should add it

0 commit comments

Comments
 (0)