From 58015d1fb42ee36f6ee5bc09f1de3719225846ec Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Fri, 7 Jun 2019 17:50:06 +0300 Subject: [PATCH] Report which key exactly was not found. (#1171) --- protocols/kad/src/behaviour.rs | 8 ++++++-- protocols/kad/src/behaviour/test.rs | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index a2ca91f0..a5a7961d 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -972,9 +972,10 @@ where self.queued_events.push(event); } }, - QueryInfoInner::GetValue { key: _, results, .. } => { + QueryInfoInner::GetValue { key, results, .. } => { let result = match results.len() { 0 => GetValueResult::NotFound{ + key, closest_peers: closer_peers.collect() }, _ => GetValueResult::Found{ results }, @@ -1023,7 +1024,10 @@ pub enum GetValueResult { /// The results received from peers. Always contains non-zero number of results. Found { results: Vec }, /// The record wasn't found. - NotFound { closest_peers: Vec } + NotFound { + key: Multihash, + closest_peers: Vec + } } /// The result of a `PUT_VALUE` query. diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index 2fc80115..f7e8df0a 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -252,7 +252,8 @@ fn get_value_not_found() { loop { match swarm.poll().unwrap() { 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!(closest_peers.contains(&swarm_ids[1])); assert!(closest_peers.contains(&swarm_ids[2]));