Merge pull request #1855 from lbryio/findvalue-always-include-close-contacts

Always return close peers from findValue
This commit is contained in:
Jack Robison 2019-02-04 15:30:17 -05:00 committed by GitHub
commit ad30b7df6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View file

@ -77,6 +77,7 @@ class KademliaRPC:
response = {
b'token': self.make_token(rpc_contact.compact_ip()),
b'contacts': self.find_node(rpc_contact, key)
}
if self.protocol.protocol_version:
@ -93,8 +94,6 @@ class KademliaRPC:
peers.append(self.compact_address())
if peers:
response[key] = peers
else:
response[b'contacts'] = self.find_node(rpc_contact, key)
return response
def refresh_token(self): # TODO: this needs to be called periodically

View file

@ -81,8 +81,9 @@ class TestProtocol(AsyncioTestCase):
self.assertListEqual([peer2_from_peer1], peer1.data_store.get_storing_contacts())
peer1.data_store.completed_blobs.add(binascii.hexlify(b'2' * 48).decode())
find_value_response = peer1.node_rpc.find_value(peer3, b'2' * 48)
self.assertEqual(len(find_value_response[b'contacts']), 0)
self.assertSetEqual(
{b'2' * 48, b'token', b'protocolVersion'}, set(find_value_response.keys())
{b'2' * 48, b'token', b'protocolVersion', b'contacts'}, set(find_value_response.keys())
)
self.assertEqual(2, len(find_value_response[b'2' * 48]))
self.assertEqual(find_value_response[b'2' * 48][0], peer2_from_peer1.compact_address_tcp())