Skip to content

Commit

Permalink
protocols/kad/behaviour: Return peers independent of record existence (
Browse files Browse the repository at this point in the history
…libp2p#1544)

A node receiving a `GetRecord` request first checks whether it has the
given record. If it does have the record it does not return closer
nodes.

A node that knows the record for the given key is likely within a
neighborhood of nodes that know the record as well. In addition the node
likely knows its neighboorhood well.

When querying for a key with a quorum of 1 the above behavior of only
returning the record but not any close peers is fine. Once one queries
with a higher quorum having a node respond with the record as well as
close nodes is likely going to speed up the query, given that the
returned peers probably know the record as well.
  • Loading branch information
mxinden committed Apr 8, 2020
1 parent 4bcb4b2 commit 2a071fb
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1278,13 +1278,7 @@ where
None => None
};

// If no record is found, at least report known closer peers.
let closer_peers =
if record.is_none() {
self.find_closest(&kbucket::Key::new(key), &source)
} else {
Vec::new()
};
let closer_peers = self.find_closest(&kbucket::Key::new(key), &source);

self.queued_events.push_back(NetworkBehaviourAction::NotifyHandler {
peer_id: source,
Expand Down

0 comments on commit 2a071fb

Please sign in to comment.