fix cases where buckets could be unjoined after removing a peer

This commit is contained in:
Jack Robison 2019-02-21 13:37:20 -05:00
parent 6915a7a553
commit 03cd6b7200
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -302,6 +302,7 @@ class KademliaProtocol(DatagramProtocol):
for p in self.routing_table.get_peers(): 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: 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.remove_peer(p)
self.routing_table.join_buckets()
bucket_index = self.routing_table.kbucket_index(peer.node_id) bucket_index = self.routing_table.kbucket_index(peer.node_id)
if self.routing_table.buckets[bucket_index].add_peer(peer): if self.routing_table.buckets[bucket_index].add_peer(peer):
return True return True
@ -526,7 +527,9 @@ class KademliaProtocol(DatagramProtocol):
except (asyncio.TimeoutError, RemoteException): except (asyncio.TimeoutError, RemoteException):
self.peer_manager.report_failure(peer.address, peer.udp_port) self.peer_manager.report_failure(peer.address, peer.udp_port)
if self.peer_manager.peer_is_good(peer) is False: if self.peer_manager.peer_is_good(peer) is False:
async with self._split_lock:
self.routing_table.remove_peer(peer) self.routing_table.remove_peer(peer)
self.routing_table.join_buckets()
raise raise
async def send_response(self, peer: 'KademliaPeer', response: ResponseDatagram): async def send_response(self, peer: 'KademliaPeer', response: ResponseDatagram):