diff --git a/zenoh/src/net/routing/dispatcher/queries.rs b/zenoh/src/net/routing/dispatcher/queries.rs index bf23211241..7d1287beeb 100644 --- a/zenoh/src/net/routing/dispatcher/queries.rs +++ b/zenoh/src/net/routing/dispatcher/queries.rs @@ -41,7 +41,7 @@ use zenoh_util::Timed; use super::{ face::FaceState, resource::{QueryRoute, QueryRoutes, QueryTargetQablSet, Resource}, - tables::{NodeId, QueryTargetQabl, RoutingExpr, Tables, TablesLock}, + tables::{NodeId, RoutingExpr, Tables, TablesLock}, }; use crate::net::routing::hat::{HatTrait, SendDeclare}; @@ -342,29 +342,9 @@ fn compute_final_route( route } TargetType::BestMatching => { - if let Some(qabl) = qabls - .iter() - .fold(None, |accu: Option<&QueryTargetQabl>, qabl| { - if qabl.direction.0.id != src_face.id - && qabl.info.is_some_and(|info| { - info.complete - && accu - .map(|accu| { - info.distance - < accu - .info - .map(|info| info.distance) - .unwrap_or(u16::MAX) - }) - .unwrap_or(true) - }) - { - Some(qabl) - } else { - accu - } - }) - { + if let Some(qabl) = qabls.iter().find(|qabl| { + qabl.direction.0.id != src_face.id && qabl.info.is_some_and(|info| info.complete) + }) { let mut route = HashMap::new(); let mut direction = qabl.direction.clone(); diff --git a/zenoh/src/net/routing/hat/client/queries.rs b/zenoh/src/net/routing/hat/client/queries.rs index d648f766da..b51b3c3e7f 100644 --- a/zenoh/src/net/routing/hat/client/queries.rs +++ b/zenoh/src/net/routing/hat/client/queries.rs @@ -375,7 +375,7 @@ impl HatQueriesTrait for HatCode { direction: (context.face.clone(), key_expr.to_owned(), NodeId::default()), info: Some(QueryableInfoType { complete: complete && qabl_info.complete, - distance: 0, + distance: 1, }), }); } diff --git a/zenoh/src/net/routing/hat/linkstate_peer/queries.rs b/zenoh/src/net/routing/hat/linkstate_peer/queries.rs index 5639538291..8a46b9a0b0 100644 --- a/zenoh/src/net/routing/hat/linkstate_peer/queries.rs +++ b/zenoh/src/net/routing/hat/linkstate_peer/queries.rs @@ -999,7 +999,7 @@ impl HatQueriesTrait for HatCode { ), info: Some(QueryableInfoType { complete: complete && qabl_info.complete, - distance: 0, + distance: 1, }), }); } diff --git a/zenoh/src/net/routing/hat/p2p_peer/queries.rs b/zenoh/src/net/routing/hat/p2p_peer/queries.rs index 311952fabf..ee498e1677 100644 --- a/zenoh/src/net/routing/hat/p2p_peer/queries.rs +++ b/zenoh/src/net/routing/hat/p2p_peer/queries.rs @@ -638,7 +638,7 @@ impl HatQueriesTrait for HatCode { ), info: Some(QueryableInfoType { complete: complete && qabl_info.complete, - distance: 0, + distance: 1, }), }); } diff --git a/zenoh/src/net/routing/hat/router/queries.rs b/zenoh/src/net/routing/hat/router/queries.rs index 1a7f20b03a..3fa518ca0f 100644 --- a/zenoh/src/net/routing/hat/router/queries.rs +++ b/zenoh/src/net/routing/hat/router/queries.rs @@ -1481,7 +1481,7 @@ impl HatQueriesTrait for HatCode { ), info: Some(QueryableInfoType { complete: complete && qabl_info.complete, - distance: 0, + distance: 1, }), }); }