From b3614d965d690e60d40d9acc159e534e3aec1688 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 11 Feb 2022 19:45:08 -0300 Subject: [PATCH] remove all references to bottoming out --- lbry/dht/constants.py | 1 - lbry/dht/node.py | 10 ++++------ lbry/dht/protocol/iterative_find.py | 22 +++++++--------------- lbry/extras/daemon/daemon.py | 13 +------------ 4 files changed, 12 insertions(+), 34 deletions(-) diff --git a/lbry/dht/constants.py b/lbry/dht/constants.py index 07dcec18a..7380ce60a 100644 --- a/lbry/dht/constants.py +++ b/lbry/dht/constants.py @@ -20,7 +20,6 @@ MAYBE_PING_DELAY = 300 # 5 minutes CHECK_REFRESH_INTERVAL = REFRESH_INTERVAL / 5 RPC_ID_LENGTH = 20 PROTOCOL_VERSION = 1 -BOTTOM_OUT_LIMIT = 3 MSG_SIZE_LIMIT = 1400 diff --git a/lbry/dht/node.py b/lbry/dht/node.py index 635adc2c4..864edc077 100644 --- a/lbry/dht/node.py +++ b/lbry/dht/node.py @@ -202,25 +202,23 @@ class Node: self._join_task = self.loop.create_task(self.join_network(interface, known_node_urls)) def get_iterative_node_finder(self, key: bytes, shortlist: typing.Optional[typing.List['KademliaPeer']] = None, - bottom_out_limit: int = constants.BOTTOM_OUT_LIMIT, max_results: int = constants.K) -> IterativeNodeFinder: return IterativeNodeFinder(self.loop, self.protocol.peer_manager, self.protocol.routing_table, self.protocol, - key, bottom_out_limit, max_results, None, shortlist) + key, max_results, None, shortlist) def get_iterative_value_finder(self, key: bytes, shortlist: typing.Optional[typing.List['KademliaPeer']] = None, - bottom_out_limit: int = 40, max_results: int = -1) -> IterativeValueFinder: return IterativeValueFinder(self.loop, self.protocol.peer_manager, self.protocol.routing_table, self.protocol, - key, bottom_out_limit, max_results, None, shortlist) + key, max_results, None, shortlist) async def peer_search(self, node_id: bytes, count=constants.K, max_results=constants.K * 2, - bottom_out_limit=60, shortlist: typing.Optional[typing.List['KademliaPeer']] = None + shortlist: typing.Optional[typing.List['KademliaPeer']] = None ) -> typing.List['KademliaPeer']: peers = [] async for iteration_peers in self.get_iterative_node_finder( - node_id, shortlist=shortlist, bottom_out_limit=bottom_out_limit, max_results=max_results): + node_id, shortlist=shortlist, max_results=max_results): peers.extend(iteration_peers) distance = Distance(node_id) peers.sort(key=lambda peer: distance(peer.node_id)) diff --git a/lbry/dht/protocol/iterative_find.py b/lbry/dht/protocol/iterative_find.py index 2fdc602eb..68c04692d 100644 --- a/lbry/dht/protocol/iterative_find.py +++ b/lbry/dht/protocol/iterative_find.py @@ -74,7 +74,7 @@ def get_shortlist(routing_table: 'TreeRoutingTable', key: bytes, class IterativeFinder: def __init__(self, loop: asyncio.AbstractEventLoop, peer_manager: 'PeerManager', routing_table: 'TreeRoutingTable', protocol: 'KademliaProtocol', key: bytes, - bottom_out_limit: typing.Optional[int] = 2, max_results: typing.Optional[int] = constants.K, + max_results: typing.Optional[int] = constants.K, exclude: typing.Optional[typing.List[typing.Tuple[str, int]]] = None, shortlist: typing.Optional[typing.List['KademliaPeer']] = None): if len(key) != constants.HASH_LENGTH: @@ -85,7 +85,6 @@ class IterativeFinder: self.protocol = protocol self.key = key - self.bottom_out_limit = bottom_out_limit self.max_results = max(constants.K, max_results) self.exclude = exclude or [] @@ -97,7 +96,6 @@ class IterativeFinder: self.running_probes: typing.Dict['KademliaPeer', asyncio.Task] = {} self.iteration_count = 0 - self.bottom_out_count = 0 self.running = False self.tasks: typing.List[asyncio.Task] = [] self.delayed_call: asyncio.Handle = None @@ -232,8 +230,8 @@ class IterativeFinder: self.loop.call_soon(self.aclose) def _log_state(self): - log.debug("[%s] check result: %i active nodes %i contacted %i bottomed count", - self.key.hex()[:8], len(self.active), len(self.contacted), self.bottom_out_count) + log.debug("[%s] check result: %i active nodes %i contacted", + self.key.hex()[:8], len(self.active), len(self.contacted)) def _search(self): self._search_task() @@ -272,10 +270,10 @@ class IterativeFinder: class IterativeNodeFinder(IterativeFinder): def __init__(self, loop: asyncio.AbstractEventLoop, peer_manager: 'PeerManager', routing_table: 'TreeRoutingTable', protocol: 'KademliaProtocol', key: bytes, - bottom_out_limit: typing.Optional[int] = 2, max_results: typing.Optional[int] = constants.K, + max_results: typing.Optional[int] = constants.K, exclude: typing.Optional[typing.List[typing.Tuple[str, int]]] = None, shortlist: typing.Optional[typing.List['KademliaPeer']] = None): - super().__init__(loop, peer_manager, routing_table, protocol, key, bottom_out_limit, max_results, exclude, + super().__init__(loop, peer_manager, routing_table, protocol, key, max_results, exclude, shortlist) self.yielded_peers: typing.Set['KademliaPeer'] = set() @@ -314,10 +312,10 @@ class IterativeNodeFinder(IterativeFinder): class IterativeValueFinder(IterativeFinder): def __init__(self, loop: asyncio.AbstractEventLoop, peer_manager: 'PeerManager', routing_table: 'TreeRoutingTable', protocol: 'KademliaProtocol', key: bytes, - bottom_out_limit: typing.Optional[int] = 2, max_results: typing.Optional[int] = constants.K, + max_results: typing.Optional[int] = constants.K, exclude: typing.Optional[typing.List[typing.Tuple[str, int]]] = None, shortlist: typing.Optional[typing.List['KademliaPeer']] = None): - super().__init__(loop, peer_manager, routing_table, protocol, key, bottom_out_limit, max_results, exclude, + super().__init__(loop, peer_manager, routing_table, protocol, key, max_results, exclude, shortlist) self.blob_peers: typing.Set['KademliaPeer'] = set() # this tracks the index of the most recent page we requested from each peer @@ -362,18 +360,12 @@ class IterativeValueFinder(IterativeFinder): blob_peers = [self.peer_manager.decode_tcp_peer_from_compact_address(compact_addr) for compact_addr in response.found_compact_addresses] to_yield = [] - self.bottom_out_count = 0 for blob_peer in blob_peers: if blob_peer not in self.blob_peers: self.blob_peers.add(blob_peer) to_yield.append(blob_peer) if to_yield: - # log.info("found %i new peers for blob", len(to_yield)) self.iteration_queue.put_nowait(to_yield) - # if self.max_results and len(self.blob_peers) >= self.max_results: - # log.info("enough blob peers found") - # if not self.finished.is_set(): - # self.finished.set() def get_initial_result(self) -> typing.List['KademliaPeer']: if self.protocol.data_store.has_peers_for_blob(self.key): diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index 003ea9cf7..fb25207f7 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -4885,20 +4885,16 @@ class Daemon(metaclass=JSONRPCServerType): """ @requires(DHT_COMPONENT) - async def jsonrpc_peer_list(self, blob_hash, search_bottom_out_limit=None, page=None, page_size=None): + async def jsonrpc_peer_list(self, blob_hash, page=None, page_size=None): """ Get peers for blob hash Usage: peer_list ( | --blob_hash=) - [ | --search_bottom_out_limit=] [--page=] [--page_size=] Options: --blob_hash= : (str) find available peers for this blob hash - --search_bottom_out_limit= : (int) the number of search probes in a row - that don't find any new peers - before giving up and returning --page= : (int) page to return during paginating --page_size= : (int) number of items on page during pagination @@ -4910,13 +4906,6 @@ class Daemon(metaclass=JSONRPCServerType): if not is_valid_blobhash(blob_hash): # TODO: use error from lbry.error raise Exception("invalid blob hash") - if search_bottom_out_limit is not None: - search_bottom_out_limit = int(search_bottom_out_limit) - if search_bottom_out_limit <= 0: - # TODO: use error from lbry.error - raise Exception("invalid bottom out limit") - else: - search_bottom_out_limit = 4 peers = [] peer_q = asyncio.Queue(loop=self.component_manager.loop) await self.dht_node._peers_for_value_producer(blob_hash, peer_q)