From 03cd6b7200837e6f6dedec98243e1f301193b8c9 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Thu, 21 Feb 2019 13:37:20 -0500 Subject: [PATCH] fix cases where buckets could be unjoined after removing a peer --- lbrynet/dht/protocol/protocol.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lbrynet/dht/protocol/protocol.py b/lbrynet/dht/protocol/protocol.py index 0c95be813..64198f14d 100644 --- a/lbrynet/dht/protocol/protocol.py +++ b/lbrynet/dht/protocol/protocol.py @@ -302,6 +302,7 @@ class KademliaProtocol(DatagramProtocol): for p in self.routing_table.get_peers(): if (p.address, p.udp_port) == (peer.address, peer.udp_port) and p.node_id != peer.node_id: self.routing_table.remove_peer(p) + self.routing_table.join_buckets() bucket_index = self.routing_table.kbucket_index(peer.node_id) if self.routing_table.buckets[bucket_index].add_peer(peer): return True @@ -526,7 +527,9 @@ class KademliaProtocol(DatagramProtocol): except (asyncio.TimeoutError, RemoteException): self.peer_manager.report_failure(peer.address, peer.udp_port) if self.peer_manager.peer_is_good(peer) is False: - self.routing_table.remove_peer(peer) + async with self._split_lock: + self.routing_table.remove_peer(peer) + self.routing_table.join_buckets() raise async def send_response(self, peer: 'KademliaPeer', response: ResponseDatagram):