Report which key exactly was not found. (#1171)

This commit is contained in:
Fedor Sakharov
2019-06-07 17:50:06 +03:00
committed by GitHub
parent 60228f7dcb
commit 58015d1fb4
2 changed files with 8 additions and 3 deletions

View File

@ -972,9 +972,10 @@ where
self.queued_events.push(event); self.queued_events.push(event);
} }
}, },
QueryInfoInner::GetValue { key: _, results, .. } => { QueryInfoInner::GetValue { key, results, .. } => {
let result = match results.len() { let result = match results.len() {
0 => GetValueResult::NotFound{ 0 => GetValueResult::NotFound{
key,
closest_peers: closer_peers.collect() closest_peers: closer_peers.collect()
}, },
_ => GetValueResult::Found{ results }, _ => GetValueResult::Found{ results },
@ -1023,7 +1024,10 @@ pub enum GetValueResult {
/// The results received from peers. Always contains non-zero number of results. /// The results received from peers. Always contains non-zero number of results.
Found { results: Vec<Record> }, Found { results: Vec<Record> },
/// The record wasn't found. /// The record wasn't found.
NotFound { closest_peers: Vec<PeerId> } NotFound {
key: Multihash,
closest_peers: Vec<PeerId>
}
} }
/// The result of a `PUT_VALUE` query. /// The result of a `PUT_VALUE` query.

View File

@ -252,7 +252,8 @@ fn get_value_not_found() {
loop { loop {
match swarm.poll().unwrap() { match swarm.poll().unwrap() {
Async::Ready(Some(KademliaOut::GetValueResult(result))) => { Async::Ready(Some(KademliaOut::GetValueResult(result))) => {
if let GetValueResult::NotFound { closest_peers} = result { if let GetValueResult::NotFound { key, closest_peers } = result {
assert_eq!(key, target_key);
assert_eq!(closest_peers.len(), 2); assert_eq!(closest_peers.len(), 2);
assert!(closest_peers.contains(&swarm_ids[1])); assert!(closest_peers.contains(&swarm_ids[1]));
assert!(closest_peers.contains(&swarm_ids[2])); assert!(closest_peers.contains(&swarm_ids[2]));