From 9bb45b1c906fe3b39cbf1a89478177c721a45138 Mon Sep 17 00:00:00 2001 From: Brian Muller Date: Sat, 2 May 2020 20:38:59 -0400 Subject: [PATCH] optimized calculation of max_replacement_nodes in Router, Fixes #79 --- kademlia/routing.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kademlia/routing.py b/kademlia/routing.py index eaa356a..ba757e4 100644 --- a/kademlia/routing.py +++ b/kademlia/routing.py @@ -15,7 +15,7 @@ class KBucket: self.replacement_nodes = OrderedDict() self.touch_last_updated() self.ksize = ksize - self.replacement_node_factor = replacementNodeFactor + self.max_replacement_nodes = self.ksize * replacementNodeFactor def touch_last_updated(self): self.last_updated = time.monotonic() @@ -68,8 +68,7 @@ class KBucket: if node.id in self.replacement_nodes: del self.replacement_nodes[node.id] self.replacement_nodes[node.id] = node - max_replacement_nodes = self.ksize * self.replacement_node_factor - while len(self.replacement_nodes) > max_replacement_nodes: + while len(self.replacement_nodes) > self.max_replacement_nodes: self.replacement_nodes.popitem(last=False) return False return True