From 1477d1cdddce83ef4113ef12045695c286c7d9e6 Mon Sep 17 00:00:00 2001 From: OlivierHecart Date: Thu, 5 Sep 2024 15:52:07 +0200 Subject: [PATCH] Fix BEST_MATCHING queryable selection --- zenoh/src/net/routing/dispatcher/queries.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/zenoh/src/net/routing/dispatcher/queries.rs b/zenoh/src/net/routing/dispatcher/queries.rs index c117bd51df..3f5d1767fb 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, RoutingExpr, Tables, TablesLock}, + tables::{NodeId, QueryTargetQabl, RoutingExpr, Tables, TablesLock}, }; use crate::net::routing::hat::{HatTrait, SendDeclare}; @@ -344,7 +344,20 @@ fn compute_final_route( TargetType::BestMatching => { if let Some(qabl) = qabls .iter() - .find(|qabl| qabl.direction.0.id != src_face.id && qabl.complete > 0) + .fold(None, |accu: Option<&QueryTargetQabl>, qabl| { + if let Some(accu) = accu { + if qabl.direction.0.id != src_face.id + && qabl.complete > 0 + && qabl.distance < accu.distance + { + Some(qabl) + } else { + Some(accu) + } + } else { + Some(qabl) + } + }) { let mut route = HashMap::new();