diff --git a/lbrynet/dht/iterativefind.py b/lbrynet/dht/iterativefind.py index d8136a8ac..218d5a8f5 100644 --- a/lbrynet/dht/iterativefind.py +++ b/lbrynet/dht/iterativefind.py @@ -16,7 +16,7 @@ def get_contact(contact_list, node_id, address, port): def expand_peer(compact_peer_info): - host = ".".join([str(ord(d)) for d in compact_peer_info[:4]]) + host = ".".join([str(d) for d in compact_peer_info[:4]]) port, = struct.unpack('>H', compact_peer_info[4:6]) peer_node_id = compact_peer_info[6:] return (peer_node_id, host, port) @@ -103,9 +103,9 @@ class _IterativeFind: if self.is_find_value_request and self.key in result: # We have found the value for peer in result[self.key]: - _, host, port = expand_peer(peer) + node_id, host, port = expand_peer(peer) if (host, port) not in self.exclude: - self.find_value_result.setdefault(self.key, []).append(peer) + self.find_value_result.setdefault(self.key, []).append((node_id, host, port)) if self.find_value_result: self.finished_deferred.callback(self.find_value_result) else: diff --git a/lbrynet/dht/node.py b/lbrynet/dht/node.py index 3433519e4..2e22f5439 100644 --- a/lbrynet/dht/node.py +++ b/lbrynet/dht/node.py @@ -18,17 +18,9 @@ from .peerfinder import DHTPeerFinder from .contact import ContactManager from .iterativefind import iterativeFind - log = logging.getLogger(__name__) -def expand_peer(compact_peer_info): - host = ".".join([str(ord(d)) for d in compact_peer_info[:4]]) - port, = struct.unpack('>H', compact_peer_info[4:6]) - peer_node_id = compact_peer_info[6:] - return peer_node_id, host, port - - def rpcmethod(func): """ Decorator to expose Node methods as remote procedure calls @@ -422,22 +414,15 @@ class Node(MockKademliaHelper): else: pass - expanded_peers = [] - if find_result: - if key in find_result: - for peer in find_result[key]: - expanded = expand_peer(peer) - if expanded not in expanded_peers: - expanded_peers.append(expanded) - # TODO: get this working - # if 'closestNodeNoValue' in find_result: - # closest_node_without_value = find_result['closestNodeNoValue'] - # try: - # response, address = yield closest_node_without_value.findValue(key, rawResponse=True) - # yield closest_node_without_value.store(key, response.response['token'], self.peerPort) - # except TimeoutError: - # pass - defer.returnValue(expanded_peers) + defer.returnValue(list(set(find_result.get(key, []) if find_result else []))) + # TODO: get this working + # if 'closestNodeNoValue' in find_result: + # closest_node_without_value = find_result['closestNodeNoValue'] + # try: + # response, address = yield closest_node_without_value.findValue(key, rawResponse=True) + # yield closest_node_without_value.store(key, response.response['token'], self.peerPort) + # except TimeoutError: + # pass def addContact(self, contact): """ Add/update the given contact; simple wrapper for the same method