From: Cameron Dale Date: Thu, 20 Mar 2008 22:09:29 +0000 (-0700) Subject: Fix some bugs in the pinging and ID checking. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3fa6b85ac4e8e9f88a31b08fd3557961d799139d;p=quix0rs-apt-p2p.git Fix some bugs in the pinging and ID checking. Raise an exception if the node's ID has changed. This means the node's returned results will be ignored. The KTable replaceStaleNode now adds the new node if there's space even if the old one isn't found. This is due to the node ID having changed resulting in instantly removing the node from the routing table. The handler for the ping result in insertNode was mistakenly taking the Failure returned as a result as a node and passing it to replaceStaleNode. --- diff --git a/apt_p2p_Khashmir/khashmir.py b/apt_p2p_Khashmir/khashmir.py index 3ed7baf..230de1f 100644 --- a/apt_p2p_Khashmir/khashmir.py +++ b/apt_p2p_Khashmir/khashmir.py @@ -208,7 +208,7 @@ class KhashmirBase(protocol.Factory): (datetime.now() - old.lastSeen) > timedelta(seconds=self.config['MIN_PING_INTERVAL'])): - def _staleNodeHandler(oldnode = old, newnode = node): + def _staleNodeHandler(failure, oldnode = old, newnode = node): """The pinged node never responded, so replace it.""" self.table.replaceStaleNode(oldnode, newnode) diff --git a/apt_p2p_Khashmir/knode.py b/apt_p2p_Khashmir/knode.py index 2e2c9b6..36d77bd 100644 --- a/apt_p2p_Khashmir/knode.py +++ b/apt_p2p_Khashmir/knode.py @@ -21,6 +21,7 @@ class KNodeBase(Node): if self.id != NULL_ID and senderid != self.id: log.msg("Got response from different node than expected.") self.table.invalidateNode(self) + raise Exception, "Node ID has changed" return dict diff --git a/apt_p2p_Khashmir/ktable.py b/apt_p2p_Khashmir/ktable.py index 864dfe5..1107f00 100644 --- a/apt_p2p_Khashmir/ktable.py +++ b/apt_p2p_Khashmir/ktable.py @@ -128,11 +128,13 @@ class KTable: try: it = self.buckets[i].l.index(stale.num) except ValueError: - return - - # Remove the stale node and insert the new one - del(self.buckets[i].l[it]) - if new: + pass + else: + # Remove the stale node + del(self.buckets[i].l[it]) + + # Insert the new node + if new and self._bucketIndexForInt(new.num) == i and len(self.buckets[i].l) < self.config['K']: self.buckets[i].l.append(new) def insertNode(self, node, contacted = True):