Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not match keyexprs for local faces #1786

Merged
merged 8 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions zenoh/src/net/routing/dispatcher/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct FaceState {
pub(crate) in_interceptors: Option<Arc<InterceptorsChain>>,
pub(crate) hat: Box<dyn Any + Send + Sync>,
pub(crate) task_controller: TaskController,
pub(crate) is_local: bool,
}

impl FaceState {
Expand All @@ -89,6 +90,7 @@ impl FaceState {
mcast_group: Option<TransportMulticast>,
in_interceptors: Option<Arc<InterceptorsChain>>,
hat: Box<dyn Any + Send + Sync>,
is_local: bool,
) -> Arc<FaceState> {
Arc::new(FaceState {
id,
Expand All @@ -108,6 +110,7 @@ impl FaceState {
in_interceptors,
hat,
task_controller: TaskController::default(),
is_local,
})
}

Expand Down
4 changes: 4 additions & 0 deletions zenoh/src/net/routing/dispatcher/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ impl Resource {
face: &mut Arc<FaceState>,
push: bool,
) -> WireExpr<'static> {
if face.is_local {
return res.expr().to_string().into();
}

let (nonwild_prefix, wildsuffix) = Resource::nonwild_prefix(res);
match nonwild_prefix {
Some(mut nonwild_prefix) => {
Expand Down
5 changes: 5 additions & 0 deletions zenoh/src/net/routing/hat/linkstate_peer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,8 @@ fn get_peer(tables: &Tables, face: &Arc<FaceState>, nodeid: NodeId) -> Option<Ze
}

impl HatTrait for HatCode {}

#[inline]
pub(super) fn push_declaration_profile(face: &FaceState) -> bool {
face.whatami != WhatAmI::Client
}
18 changes: 9 additions & 9 deletions zenoh/src/net/routing/hat/linkstate_peer/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use zenoh_protocol::{
use zenoh_sync::get_mut_unchecked;

use super::{
face_hat, face_hat_mut, get_peer, hat, hat_mut, network::Network, res_hat, res_hat_mut,
HatCode, HatContext, HatFace, HatTables,
face_hat, face_hat_mut, get_peer, hat, hat_mut, network::Network, push_declaration_profile,
res_hat, res_hat_mut, HatCode, HatContext, HatFace, HatTables,
};
#[cfg(feature = "unstable")]
use crate::key_expr::KeyExpr;
Expand Down Expand Up @@ -67,7 +67,7 @@ fn send_sourced_subscription_to_net_children(
.map(|src_face| someface.id != src_face.id)
.unwrap_or(true)
{
let push_declaration = someface.whatami != WhatAmI::Client;
let push_declaration = push_declaration_profile(&someface);
let key_expr = Resource::decl_key(res, &mut someface, push_declaration);

someface.primitives.send_declare(RoutingContext::with_expr(
Expand Down Expand Up @@ -109,7 +109,7 @@ fn propagate_simple_subscription_to(
if dst_face.whatami != WhatAmI::Client {
let id = face_hat!(dst_face).next_id.fetch_add(1, Ordering::SeqCst);
face_hat_mut!(dst_face).local_subs.insert(res.clone(), id);
let key_expr = Resource::decl_key(res, dst_face, dst_face.whatami != WhatAmI::Client);
let key_expr = Resource::decl_key(res, dst_face, push_declaration_profile(dst_face));
send_declare(
&dst_face.primitives,
RoutingContext::with_expr(
Expand Down Expand Up @@ -149,7 +149,7 @@ fn propagate_simple_subscription_to(
let id = face_hat!(dst_face).next_id.fetch_add(1, Ordering::SeqCst);
face_hat_mut!(dst_face).local_subs.insert(res.clone(), id);
let key_expr =
Resource::decl_key(res, dst_face, dst_face.whatami != WhatAmI::Client);
Resource::decl_key(res, dst_face, push_declaration_profile(dst_face));
send_declare(
&dst_face.primitives,
RoutingContext::with_expr(
Expand Down Expand Up @@ -355,7 +355,7 @@ fn send_forget_sourced_subscription_to_net_children(
.map(|src_face| someface.id != src_face.id)
.unwrap_or(true)
{
let push_declaration = someface.whatami != WhatAmI::Client;
let push_declaration = push_declaration_profile(&someface);
let wire_expr = Resource::decl_key(res, &mut someface, push_declaration);

someface.primitives.send_declare(RoutingContext::with_expr(
Expand Down Expand Up @@ -707,7 +707,7 @@ pub(super) fn declare_sub_interest(
&& (remote_simple_subs(sub, face) || remote_linkstatepeer_subs(tables, sub))
}) {
let id = make_sub_id(res, face, mode);
let wire_expr = Resource::decl_key(res, face, face.whatami != WhatAmI::Client);
let wire_expr = Resource::decl_key(res, face, push_declaration_profile(face));
send_declare(
&face.primitives,
RoutingContext::with_expr(
Expand All @@ -733,7 +733,7 @@ pub(super) fn declare_sub_interest(
{
let id = make_sub_id(sub, face, mode);
let wire_expr =
Resource::decl_key(sub, face, face.whatami != WhatAmI::Client);
Resource::decl_key(sub, face, push_declaration_profile(face));
send_declare(
&face.primitives,
RoutingContext::with_expr(
Expand All @@ -759,7 +759,7 @@ pub(super) fn declare_sub_interest(
&& (remote_simple_subs(sub, face) || remote_linkstatepeer_subs(tables, sub))
{
let id = make_sub_id(sub, face, mode);
let wire_expr = Resource::decl_key(sub, face, face.whatami != WhatAmI::Client);
let wire_expr = Resource::decl_key(sub, face, push_declaration_profile(face));
send_declare(
&face.primitives,
RoutingContext::with_expr(
Expand Down
16 changes: 8 additions & 8 deletions zenoh/src/net/routing/hat/linkstate_peer/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ use zenoh_protocol::{
use zenoh_sync::get_mut_unchecked;

use super::{
face_hat, face_hat_mut, get_peer, hat, hat_mut, network::Network, res_hat, res_hat_mut,
HatCode, HatContext, HatFace, HatTables,
face_hat, face_hat_mut, get_peer, hat, hat_mut, network::Network, push_declaration_profile,
res_hat, res_hat_mut, HatCode, HatContext, HatFace, HatTables,
};
#[cfg(feature = "unstable")]
use crate::key_expr::KeyExpr;
Expand Down Expand Up @@ -138,7 +138,7 @@ fn send_sourced_queryable_to_net_children(
.map(|src_face| someface.id != src_face.id)
.unwrap_or(true)
{
let push_declaration = someface.whatami != WhatAmI::Client;
let push_declaration = push_declaration_profile(&someface);
let key_expr = Resource::decl_key(res, &mut someface, push_declaration);

someface.primitives.send_declare(RoutingContext::with_expr(
Expand Down Expand Up @@ -192,7 +192,7 @@ fn propagate_simple_queryable(
face_hat_mut!(&mut dst_face)
.local_qabls
.insert(res.clone(), (id, info));
let push_declaration = dst_face.whatami != WhatAmI::Client;
let push_declaration = push_declaration_profile(&dst_face);
let key_expr = Resource::decl_key(res, &mut dst_face, push_declaration);
send_declare(
&dst_face.primitives,
Expand Down Expand Up @@ -371,7 +371,7 @@ fn send_forget_sourced_queryable_to_net_children(
.map(|src_face| someface.id != src_face.id)
.unwrap_or(true)
{
let push_declaration = someface.whatami != WhatAmI::Client;
let push_declaration = push_declaration_profile(&someface);
let wire_expr = Resource::decl_key(res, &mut someface, push_declaration);

someface.primitives.send_declare(RoutingContext::with_expr(
Expand Down Expand Up @@ -779,7 +779,7 @@ pub(super) fn declare_qabl_interest(
}) {
let info = local_qabl_info(tables, res, face);
let id = make_qabl_id(res, face, mode, info);
let wire_expr = Resource::decl_key(res, face, face.whatami != WhatAmI::Client);
let wire_expr = Resource::decl_key(res, face, push_declaration_profile(face));
send_declare(
&face.primitives,
RoutingContext::with_expr(
Expand Down Expand Up @@ -808,7 +808,7 @@ pub(super) fn declare_qabl_interest(
let info = local_qabl_info(tables, qabl, face);
let id = make_qabl_id(qabl, face, mode, info);
let key_expr =
Resource::decl_key(qabl, face, face.whatami != WhatAmI::Client);
Resource::decl_key(qabl, face, push_declaration_profile(face));
send_declare(
&face.primitives,
RoutingContext::with_expr(
Expand Down Expand Up @@ -836,7 +836,7 @@ pub(super) fn declare_qabl_interest(
{
let info = local_qabl_info(tables, qabl, face);
let id = make_qabl_id(qabl, face, mode, info);
let key_expr = Resource::decl_key(qabl, face, face.whatami != WhatAmI::Client);
let key_expr = Resource::decl_key(qabl, face, push_declaration_profile(face));
send_declare(
&face.primitives,
RoutingContext::with_expr(
Expand Down
19 changes: 9 additions & 10 deletions zenoh/src/net/routing/hat/linkstate_peer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use zenoh_protocol::{
use zenoh_sync::get_mut_unchecked;

use super::{
face_hat, face_hat_mut, get_peer, hat, hat_mut, network::Network, res_hat, res_hat_mut,
HatCode, HatContext, HatFace, HatTables,
face_hat, face_hat_mut, get_peer, hat, hat_mut, network::Network, push_declaration_profile,
res_hat, res_hat_mut, HatCode, HatContext, HatFace, HatTables,
};
use crate::net::routing::{
dispatcher::{face::FaceState, interests::RemoteInterest, tables::Tables},
Expand All @@ -54,7 +54,7 @@ fn send_sourced_token_to_net_clildren(
.map(|src_face| someface.id != src_face.id)
.unwrap_or(true)
{
let push_declaration = someface.whatami != WhatAmI::Client;
let push_declaration = push_declaration_profile(&someface);
let key_expr = Resource::decl_key(res, &mut someface, push_declaration);

someface.primitives.send_declare(RoutingContext::with_expr(
Expand Down Expand Up @@ -95,7 +95,7 @@ fn propagate_simple_token_to(
if dst_face.whatami != WhatAmI::Client {
let id = face_hat!(dst_face).next_id.fetch_add(1, Ordering::SeqCst);
face_hat_mut!(dst_face).local_tokens.insert(res.clone(), id);
let key_expr = Resource::decl_key(res, dst_face, dst_face.whatami != WhatAmI::Client);
let key_expr = Resource::decl_key(res, dst_face, push_declaration_profile(dst_face));
send_declare(
&dst_face.primitives,
RoutingContext::with_expr(
Expand Down Expand Up @@ -135,7 +135,7 @@ fn propagate_simple_token_to(
let id = face_hat!(dst_face).next_id.fetch_add(1, Ordering::SeqCst);
face_hat_mut!(dst_face).local_tokens.insert(res.clone(), id);
let key_expr =
Resource::decl_key(res, dst_face, dst_face.whatami != WhatAmI::Client);
Resource::decl_key(res, dst_face, push_declaration_profile(dst_face));
send_declare(
&dst_face.primitives,
RoutingContext::with_expr(
Expand Down Expand Up @@ -327,7 +327,7 @@ fn send_forget_sourced_token_to_net_clildren(
.map(|src_face| someface.id != src_face.id)
.unwrap_or(true)
{
let push_declaration = someface.whatami != WhatAmI::Client;
let push_declaration = push_declaration_profile(&someface);
let wire_expr = Resource::decl_key(res, &mut someface, push_declaration);

someface.primitives.send_declare(RoutingContext::with_expr(
Expand Down Expand Up @@ -673,7 +673,7 @@ pub(crate) fn declare_token_interest(
|| remote_linkstatepeer_tokens(tables, token))
}) {
let id = make_token_id(res, face, mode);
let wire_expr = Resource::decl_key(res, face, face.whatami != WhatAmI::Client);
let wire_expr = Resource::decl_key(res, face, push_declaration_profile(face));
send_declare(
&face.primitives,
RoutingContext::with_expr(
Expand All @@ -697,7 +697,7 @@ pub(crate) fn declare_token_interest(
{
let id = make_token_id(token, face, mode);
let wire_expr =
Resource::decl_key(token, face, face.whatami != WhatAmI::Client);
Resource::decl_key(token, face, push_declaration_profile(face));
send_declare(
&face.primitives,
RoutingContext::with_expr(
Expand All @@ -721,8 +721,7 @@ pub(crate) fn declare_token_interest(
|| remote_linkstatepeer_tokens(tables, token))
{
let id = make_token_id(token, face, mode);
let wire_expr =
Resource::decl_key(token, face, face.whatami != WhatAmI::Client);
let wire_expr = Resource::decl_key(token, face, push_declaration_profile(face));
send_declare(
&face.primitives,
RoutingContext::with_expr(
Expand Down
8 changes: 4 additions & 4 deletions zenoh/src/net/routing/hat/p2p_peer/interests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ pub(super) fn interests_new_face(tables: &mut Tables, face: &mut Arc<FaceState>)
finalized: false,
},
);
let wire_expr = res
.as_ref()
.map(|res| Resource::decl_key(res, face, face.whatami != WhatAmI::Client));
let wire_expr = res.as_ref().map(|res| {
Resource::decl_key(res, face, super::push_declaration_profile(face))
});
face.primitives.send_interest(RoutingContext::with_expr(
Interest {
id,
Expand Down Expand Up @@ -179,7 +179,7 @@ impl HatInterestTrait for HatCode {
);
}
let wire_expr = res.as_ref().map(|res| {
Resource::decl_key(res, dst_face, dst_face.whatami != WhatAmI::Client)
Resource::decl_key(res, dst_face, super::push_declaration_profile(dst_face))
});
dst_face.primitives.send_interest(RoutingContext::with_expr(
Interest {
Expand Down
5 changes: 5 additions & 0 deletions zenoh/src/net/routing/hat/p2p_peer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,8 @@ const INITIAL_INTEREST_ID: u32 = 0;
fn initial_interest(face: &FaceState) -> Option<&InterestState> {
face.local_interests.get(&INITIAL_INTEREST_ID)
}

#[inline]
pub(super) fn push_declaration_profile(face: &FaceState) -> bool {
face.whatami != WhatAmI::Client
}
22 changes: 15 additions & 7 deletions zenoh/src/net/routing/hat/p2p_peer/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ fn propagate_simple_subscription_to(
if dst_face.whatami != WhatAmI::Client {
let id = face_hat!(dst_face).next_id.fetch_add(1, Ordering::SeqCst);
face_hat_mut!(dst_face).local_subs.insert(res.clone(), id);
let key_expr = Resource::decl_key(res, dst_face, dst_face.whatami != WhatAmI::Client);
let key_expr =
Resource::decl_key(res, dst_face, super::push_declaration_profile(dst_face));
send_declare(
&dst_face.primitives,
RoutingContext::with_expr(
Expand Down Expand Up @@ -102,8 +103,11 @@ fn propagate_simple_subscription_to(
if !face_hat!(dst_face).local_subs.contains_key(res) {
let id = face_hat!(dst_face).next_id.fetch_add(1, Ordering::SeqCst);
face_hat_mut!(dst_face).local_subs.insert(res.clone(), id);
let key_expr =
Resource::decl_key(res, dst_face, dst_face.whatami != WhatAmI::Client);
let key_expr = Resource::decl_key(
res,
dst_face,
super::push_declaration_profile(dst_face),
);
send_declare(
&dst_face.primitives,
RoutingContext::with_expr(
Expand Down Expand Up @@ -440,7 +444,8 @@ pub(super) fn declare_sub_interest(
.any(|sub| sub.context.is_some() && sub.matches(res))
}) {
let id = make_sub_id(res, face, mode);
let wire_expr = Resource::decl_key(res, face, face.whatami != WhatAmI::Client);
let wire_expr =
Resource::decl_key(res, face, super::push_declaration_profile(face));
send_declare(
&face.primitives,
RoutingContext::with_expr(
Expand Down Expand Up @@ -469,8 +474,11 @@ pub(super) fn declare_sub_interest(
for sub in face_hat!(src_face).remote_subs.values() {
if sub.context.is_some() && sub.matches(res) {
let id = make_sub_id(sub, face, mode);
let wire_expr =
Resource::decl_key(sub, face, face.whatami != WhatAmI::Client);
let wire_expr = Resource::decl_key(
sub,
face,
super::push_declaration_profile(face),
);
send_declare(
&face.primitives,
RoutingContext::with_expr(
Expand Down Expand Up @@ -502,7 +510,7 @@ pub(super) fn declare_sub_interest(
for sub in face_hat!(src_face).remote_subs.values() {
let id = make_sub_id(sub, face, mode);
let wire_expr =
Resource::decl_key(sub, face, face.whatami != WhatAmI::Client);
Resource::decl_key(sub, face, super::push_declaration_profile(face));
send_declare(
&face.primitives,
RoutingContext::with_expr(
Expand Down
Loading