From 0075dcc2c04b307159c8c57ea814b67935bb2db0 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Mon, 13 May 2019 02:40:04 -0300 Subject: [PATCH] iterative find probes bad peers + test case for edge scenario Tom found --- lbrynet/dht/protocol/iterative_find.py | 2 +- tests/integration/test_dht.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lbrynet/dht/protocol/iterative_find.py b/lbrynet/dht/protocol/iterative_find.py index ad92342cf..94cebb609 100644 --- a/lbrynet/dht/protocol/iterative_find.py +++ b/lbrynet/dht/protocol/iterative_find.py @@ -181,7 +181,7 @@ class IterativeFinder: if added >= constants.alpha: break origin_address = (peer.address, peer.udp_port) - if origin_address in self.exclude or self.peer_manager.peer_is_good(peer) is False: + if origin_address in self.exclude: continue if peer.node_id == self.protocol.node_id: continue diff --git a/tests/integration/test_dht.py b/tests/integration/test_dht.py index 23d6c5491..cccf2e8f9 100644 --- a/tests/integration/test_dht.py +++ b/tests/integration/test_dht.py @@ -92,3 +92,23 @@ class DHTIntegrationTest(AsyncioTestCase): node2.protocol.node_rpc.refresh_token() node_ids = await node1.announce_blob(blob_hash) self.assertIn(node2.protocol.node_id, node_ids) + + async def test_peer_search_removes_bad_peers(self): + # that's an edge case discovered by Tom, but an important one + # imagine that you only got bad peers and refresh will happen in one hour + # instead of failing for one hour we should be able to recover by scheduling pings to bad peers we find + await self.setup_network(2, seed_nodes=2) + node1, node2 = self.nodes + node2.stop() + # forcefully make it a bad peer but dont remove it from routing table + address, port, node_id = node2.protocol.external_ip, node2.protocol.udp_port, node2.protocol.node_id + peer = KademliaPeer(self.loop, address, node_id, port) + self.assertTrue(node1.protocol.peer_manager.peer_is_good(peer)) + node1.protocol.peer_manager.report_failure(node2.protocol.external_ip, node2.protocol.udp_port) + node1.protocol.peer_manager.report_failure(node2.protocol.external_ip, node2.protocol.udp_port) + self.assertFalse(node1.protocol.peer_manager.peer_is_good(peer)) + + # now a search happens, which removes bad peers while contacting them + self.assertTrue(node1.protocol.routing_table.get_peers()) + await node1.peer_search(node2.protocol.node_id) + self.assertFalse(node1.protocol.routing_table.get_peers())