From ae1162f5b051d6e23dcafcb41d9a9dbfba8d2731 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Mon, 4 Feb 2019 13:31:46 -0500 Subject: [PATCH] don't try downloading from oneself -don't return the querying peer in results for findValue --- lbrynet/dht/node.py | 8 +++++++- lbrynet/dht/protocol/iterative_find.py | 1 - lbrynet/dht/protocol/protocol.py | 10 +++++----- lbrynet/dht/protocol/routing_table.py | 2 -- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lbrynet/dht/node.py b/lbrynet/dht/node.py index 004492296..5b20d952a 100644 --- a/lbrynet/dht/node.py +++ b/lbrynet/dht/node.py @@ -238,7 +238,13 @@ class Node: async with self.stream_peer_search_junction(search_queue) as search_junction: # pylint: disable=E1701 async for peers in search_junction: if peers: - result_queue.put_nowait(peers) + result_queue.put_nowait([ + peer for peer in peers + if not ( + peer.address == self.protocol.external_ip + and peer.tcp_port == self.protocol.peer_port + ) + ]) except asyncio.CancelledError: return diff --git a/lbrynet/dht/protocol/iterative_find.py b/lbrynet/dht/protocol/iterative_find.py index 8fadcc91a..ad5fa551c 100644 --- a/lbrynet/dht/protocol/iterative_find.py +++ b/lbrynet/dht/protocol/iterative_find.py @@ -255,7 +255,6 @@ class IterativeFinder: self.delayed_calls.clear() - class IterativeNodeFinder(IterativeFinder): def __init__(self, loop: asyncio.BaseEventLoop, peer_manager: 'PeerManager', routing_table: 'TreeRoutingTable', protocol: 'KademliaProtocol', key: bytes, diff --git a/lbrynet/dht/protocol/protocol.py b/lbrynet/dht/protocol/protocol.py index 1c7d2cc33..c74a6e98c 100644 --- a/lbrynet/dht/protocol/protocol.py +++ b/lbrynet/dht/protocol/protocol.py @@ -83,11 +83,11 @@ class KademliaRPC: response[b'protocolVersion'] = self.protocol.protocol_version # get peers we have stored for this blob_exchange - has_other_peers = self.protocol.data_store.has_peers_for_blob(key) - peers = [] - if has_other_peers: - peers.extend([peer.compact_address_tcp() for peer in self.protocol.data_store.get_peers_for_blob(key)]) - + peers = [ + peer.compact_address_tcp() + for peer in self.protocol.data_store.get_peers_for_blob(key) + if not rpc_contact.tcp_port or peer.compact_address_tcp() != rpc_contact.compact_address_tcp() + ] # if we don't have k storing peers to return and we have this hash locally, include our contact information if len(peers) < constants.k and binascii.hexlify(key).decode() in self.protocol.data_store.completed_blobs: peers.append(self.compact_address()) diff --git a/lbrynet/dht/protocol/routing_table.py b/lbrynet/dht/protocol/routing_table.py index d57d2561b..c33f44e16 100644 --- a/lbrynet/dht/protocol/routing_table.py +++ b/lbrynet/dht/protocol/routing_table.py @@ -183,8 +183,6 @@ class TreeRoutingTable: exclude = [self._parent_node_id] if sender_node_id: exclude.append(sender_node_id) - if key in exclude: - exclude.remove(key) count = count or constants.k distance = Distance(key) contacts = self.get_peers()