Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7ce7057
feat(kad): add limit option for getting providers
dignifiedquire Jun 16, 2022
769ce4b
feat(kad): report get_providers call event based
dignifiedquire Jun 16, 2022
f68c903
change `GetRecord`api
dignifiedquire Sep 27, 2022
baf3e60
apply cr
dignifiedquire Oct 4, 2022
5db1bfa
tests and fixups for getclosestpeers
dignifiedquire Nov 11, 2022
91b5f59
remove KademliaCaching
dignifiedquire Nov 11, 2022
30eb56c
apply cr: move to nonzerousize
dignifiedquire Nov 11, 2022
0720deb
fix example
dignifiedquire Nov 11, 2022
a0b26b0
happy clippy
dignifiedquire Nov 11, 2022
e0e79fd
protocols/kad: Refactor step tracking
mxinden Nov 11, 2022
a4f0210
cr feedback round 1
dignifiedquire Nov 12, 2022
4e448c4
cr: improve api for GetRecordOk and GetProvidersOk
dignifiedquire Nov 12, 2022
96a952e
fixup rebase of examples
dignifiedquire Nov 12, 2022
2724afd
switch to counter for number of observed record
dignifiedquire Nov 12, 2022
83a2a86
bring back kademliacaching
dignifiedquire Nov 12, 2022
b483983
examples/file-sharing: Revert usage of HashSet
mxinden Nov 17, 2022
aa8a6ce
examples/file-sharing: Finish query once provider is found
mxinden Nov 17, 2022
3912acc
protocols/kad: Remove pub(crate) from replication_factor
mxinden Nov 17, 2022
e339cdf
protocols/kad: Refactor get_record
mxinden Nov 17, 2022
3ced598
protocols/kad: Refactor get_providers step instantiation
mxinden Nov 17, 2022
ac2e525
protocols/kad: Remove pub from ProgressStep methods
mxinden Nov 17, 2022
5ca8d70
remove unused as_intermediary_result
dignifiedquire Nov 18, 2022
bd05da6
fix test cr comments
dignifiedquire Nov 18, 2022
c7c4341
fixup: rebase
dignifiedquire Nov 18, 2022
5ecf9cb
use get instead of checked_add
dignifiedquire Nov 18, 2022
055636e
Update protocols/kad/src/behaviour.rs
dignifiedquire Nov 18, 2022
d5cb7e9
Merge branch 'master' into feat-kad-count
dignifiedquire Nov 22, 2022
0e443d4
Merge remote-tracking branch 'upstream/master' into feat-kad-count
dignifiedquire Nov 24, 2022
c9c00df
add changelog
dignifiedquire Nov 24, 2022
05e29d4
Update protocols/kad/CHANGELOG.md
dignifiedquire Nov 24, 2022
1223f02
Update protocols/kad/CHANGELOG.md
dignifiedquire Nov 24, 2022
9c28d98
Update protocols/kad/CHANGELOG.md
dignifiedquire Nov 24, 2022
cfd5461
Merge branch 'master' into feat-kad-count
dignifiedquire Nov 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tests and fixups for getclosestpeers
  • Loading branch information
dignifiedquire committed Nov 18, 2022
commit 5db1bfac802aff1d477e18c6ba44e8febbb295a0
45 changes: 29 additions & 16 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,13 +666,16 @@ where
where
K: Into<kbucket::Key<K>> + Into<Vec<u8>> + Clone,
{
let target: kbucket::Key<K> = key.clone().into();
let key: Vec<u8> = key.clone().into();
let info = QueryInfo::GetClosestPeers {
key: key.clone().into(),
key: key.clone(),
count: 0,
};
let target: kbucket::Key<K> = key.into();
let peers = self.kbuckets.closest_keys(&target);
let peer_keys: Vec<kbucket::Key<PeerId>> = self.kbuckets.closest_keys(&target).collect();
let inner = QueryInner::new(info);
self.queries.add_iter_closest(target.clone(), peers, inner)
self.queries
.add_iter_closest(target.clone(), peer_keys.clone(), inner)
}

/// Returns closest peers to the given key; takes peers from local routing table only.
Expand Down Expand Up @@ -1300,7 +1303,7 @@ where
})
}

QueryInfo::GetClosestPeers { key, .. } => {
QueryInfo::GetClosestPeers { key, count } => {
Some(KademliaEvent::OutboundQueryProgressed {
id: query_id,
stats: result.stats,
Expand All @@ -1309,7 +1312,7 @@ where
peers: result.peers.collect(),
})),
step: ProgressStep {
count: 1,
count: count + 1,
last: true,
},
})
Expand Down Expand Up @@ -1527,15 +1530,20 @@ where
},
}),

QueryInfo::GetClosestPeers { key } => Some(KademliaEvent::OutboundQueryProgressed {
id: query_id,
stats: result.stats,
result: QueryResult::GetClosestPeers(Err(GetClosestPeersError::Timeout {
key,
peers: result.peers.collect(),
})),
step: ProgressStep::single(),
}),
QueryInfo::GetClosestPeers { key, count } => {
Some(KademliaEvent::OutboundQueryProgressed {
id: query_id,
stats: result.stats,
result: QueryResult::GetClosestPeers(Err(GetClosestPeersError::Timeout {
key,
peers: result.peers.collect(),
})),
step: ProgressStep {
count: count + 1,
last: true,
},
})
}

QueryInfo::PutRecord {
record,
Expand Down Expand Up @@ -2967,7 +2975,12 @@ pub enum QueryInfo {
},

/// A query initiated by [`Kademlia::get_closest_peers`].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A query initiated by [`Kademlia::get_closest_peers`].
/// A (repeated) query initiated by [`Kademlia::get_closest_peers`].

To be consistent with the comment updates below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

GetClosestPeers { key: Vec<u8> },
GetClosestPeers {
/// The key being queried (the preimage).
key: Vec<u8>,
/// Current index of events.
count: usize,
},

/// A (repeated) query initiated by [`Kademlia::get_providers`].
GetProviders {
Expand Down
16 changes: 4 additions & 12 deletions protocols/kad/src/behaviour/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ fn query_iter() {

match swarms[0].behaviour_mut().query(&qid) {
Some(q) => match q.info() {
QueryInfo::GetClosestPeers { key } => {
assert_eq!(&key[..], search_target.to_bytes().as_slice())
QueryInfo::GetClosestPeers { key, count } => {
assert_eq!(&key[..], search_target.to_bytes().as_slice());
assert_eq!(*count, 0); // no result reported yet
}
i => panic!("Unexpected query info: {:?}", i),
},
Expand Down Expand Up @@ -1194,13 +1195,8 @@ fn disjoint_query_does_not_finish_before_all_paths_did() {
.queries
.iter()
.for_each(|q| match &q.inner.info {
QueryInfo::GetRecord {
count,
record_to_cache,
..
} => {
QueryInfo::GetRecord { count, .. } => {
assert_eq!(*count, 2);
assert_eq!(record_to_cache.as_ref().unwrap(), &record_trudy);
}
i => panic!("Unexpected query info: {:?}", i),
});
Expand Down Expand Up @@ -1253,10 +1249,6 @@ fn disjoint_query_does_not_finish_before_all_paths_did() {
peer: Some(*Swarm::local_peer_id(&bob)),
record: record_bob,
}));
assert!(records.contains(&PeerRecord {
peer: Some(Swarm::local_peer_id(&trudy)),
record: record_trudy,
}));
}

/// Tests that peers are not automatically inserted into
Expand Down