From: Cameron Dale Date: Sat, 8 Mar 2008 03:56:17 +0000 (-0800) Subject: Fixed justSeenNode in KTable to update the bucket properly. X-Git-Url: https://git.mxchange.org/?p=quix0rs-apt-p2p.git;a=commitdiff_plain;h=742952098988651e561baa30dcde02aeede2eddf;hp=5e73ae20956e409b7f70ab292af360aa41b49c93 Fixed justSeenNode in KTable to update the bucket properly. It now moves the seen node to the end and marks the bucket as having been updated. --- diff --git a/TODO b/TODO index f726992..2475df8 100644 --- a/TODO +++ b/TODO @@ -1,15 +1,3 @@ -Evaluate and fix some errors in the ktable khashmir module. - -The KTable implementation has some possible errors in it. insertNode -does not remove the original and use the new node when updating a node -already in the table, as claimed by the comments. justSeenNode doesn't -verify that the found node is the node that was being looked for, nor -does it move the node to the end of the list of nodes (since they are -supposed to be sorted by their lastSeen time) or update the bucket's -last touched time.nodeFailed also doesn't verify the found node is the -right node. - - Consider what happens when we are the closest node. In some of the actions it is unclear what happens when we are one of the diff --git a/apt_p2p_Khashmir/ktable.py b/apt_p2p_Khashmir/ktable.py index 3e60f5c..864dfe5 100644 --- a/apt_p2p_Khashmir/ktable.py +++ b/apt_p2p_Khashmir/ktable.py @@ -226,6 +226,12 @@ class KTable: n = self.buckets[i].l[it] tstamp = n.lastSeen n.updateLastSeen() + + # Move the node to the end and touch the bucket + del(self.buckets[i].l[it]) + self.buckets[i].l.append(n) + self.buckets[i].touch() + return tstamp def invalidateNode(self, n):