From c03f2f63d203bdeffae732bee85551e984573f63 Mon Sep 17 00:00:00 2001 From: zixuanzh Date: Fri, 19 Apr 2019 15:26:30 -0400 Subject: [PATCH] replace id with peer_id --- libp2p/kademlia/routing.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libp2p/kademlia/routing.py b/libp2p/kademlia/routing.py index 3f88e8b..7d97494 100644 --- a/libp2p/kademlia/routing.py +++ b/libp2p/kademlia/routing.py @@ -34,24 +34,24 @@ class KBucket: two = KBucket(midpoint + 1, self.range[1], self.ksize) for node in self.nodes.values(): bucket = one if node.long_id <= midpoint else two - bucket.nodes[node.id] = node + bucket.nodes[node.peer_id] = node return (one, two) def remove_node(self, node): - if node.id not in self.nodes: + if node.peer_id not in self.nodes: return # delete node, and see if we can add a replacement - del self.nodes[node.id] + del self.nodes[node.peer_id] if self.replacement_nodes: newnode = self.replacement_nodes.pop() - self.nodes[newnode.id] = newnode + self.nodes[newnode.peer_id] = newnode def has_in_range(self, node): return self.range[0] <= node.long_id <= self.range[1] def is_new_node(self, node): - return node.id not in self.nodes + return node.peer_id not in self.nodes def add_node(self, node): """ @@ -61,11 +61,11 @@ class KBucket: If the bucket is full, keep track of node in a replacement list, per section 4.1 of the paper. """ - if node.id in self.nodes: - del self.nodes[node.id] - self.nodes[node.id] = node + if node.peer_id in self.nodes: + del self.nodes[node.peer_id] + self.nodes[node.peer_id] = node elif len(self) < self.ksize: - self.nodes[node.id] = node + self.nodes[node.peer_id] = node else: self.replacement_nodes.push(node) return False @@ -73,7 +73,7 @@ class KBucket: def depth(self): vals = self.nodes.values() - sprefix = shared_prefix([bytes_to_bit_string(n.id) for n in vals]) + sprefix = shared_prefix([bytes_to_bit_string(n.peer_id) for n in vals]) return len(sprefix) def head(self): @@ -185,7 +185,7 @@ class RoutingTable: nodes = [] for neighbor in TableTraverser(self, node): notexcluded = exclude is None or not neighbor.same_home_as(exclude) - if neighbor.id != node.id and notexcluded: + if neighbor.peer_id != node.peer_id and notexcluded: heapq.heappush(nodes, (node.distance_to(neighbor), neighbor)) if len(nodes) == k: break