Skip to content

Commit 5ea9d61

Browse files
Fix declaration propagation to avoid infinite loop in p2p (#2140)
* Don't propagate UndeclareToken from peer to peer to avoid loop * Don't register remote Current interests * Minor improvement
1 parent 1df0b59 commit 5ea9d61

File tree

5 files changed

+70
-69
lines changed

5 files changed

+70
-69
lines changed

zenoh/src/net/routing/hat/client/interests.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,16 @@ impl HatInterestTrait for HatCode {
9797
send_declare,
9898
)
9999
}
100-
face_hat_mut!(face).remote_interests.insert(
101-
id,
102-
RemoteInterest {
103-
res: res.as_deref().cloned(),
104-
options,
105-
mode,
106-
},
107-
);
100+
if mode.future() {
101+
face_hat_mut!(face).remote_interests.insert(
102+
id,
103+
RemoteInterest {
104+
res: res.as_deref().cloned(),
105+
options,
106+
mode,
107+
},
108+
);
109+
}
108110

109111
let interest = Arc::new(CurrentInterest {
110112
src_face: face.clone(),

zenoh/src/net/routing/hat/p2p_peer/interests.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ impl HatInterestTrait for HatCode {
127127
send_declare,
128128
)
129129
}
130-
face_hat_mut!(face).remote_interests.insert(
131-
id,
132-
RemoteInterest {
133-
res: res.as_ref().map(|res| (*res).clone()),
134-
options,
135-
mode,
136-
},
137-
);
130+
if mode.future() {
131+
face_hat_mut!(face).remote_interests.insert(
132+
id,
133+
RemoteInterest {
134+
res: res.as_ref().map(|res| (*res).clone()),
135+
options,
136+
mode,
137+
},
138+
);
139+
}
138140

139141
let interest = Arc::new(CurrentInterest {
140142
src_face: face.clone(),

zenoh/src/net/routing/hat/p2p_peer/pubsub.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -468,34 +468,34 @@ pub(super) fn declare_sub_interest(
468468
for src_face in tables
469469
.faces
470470
.values()
471+
.filter(|f| f.id != face.id)
471472
.cloned()
472473
.collect::<Vec<Arc<FaceState>>>()
473474
{
474-
if src_face.id != face.id {
475-
for sub in face_hat!(src_face).remote_subs.values() {
476-
if sub.context.is_some() && sub.matches(res) {
477-
let id = make_sub_id(sub, face, mode);
478-
let wire_expr = Resource::decl_key(
479-
sub,
480-
face,
481-
super::push_declaration_profile(face),
482-
);
483-
send_declare(
484-
&face.primitives,
485-
RoutingContext::with_expr(
486-
Declare {
487-
interest_id,
488-
ext_qos: ext::QoSType::DECLARE,
489-
ext_tstamp: None,
490-
ext_nodeid: ext::NodeIdType::DEFAULT,
491-
body: DeclareBody::DeclareSubscriber(
492-
DeclareSubscriber { id, wire_expr },
493-
),
494-
},
495-
sub.expr().to_string(),
496-
),
497-
);
498-
}
475+
for sub in face_hat!(src_face).remote_subs.values() {
476+
if sub.context.is_some() && sub.matches(res) {
477+
let id = make_sub_id(sub, face, mode);
478+
let wire_expr = Resource::decl_key(
479+
sub,
480+
face,
481+
super::push_declaration_profile(face),
482+
);
483+
send_declare(
484+
&face.primitives,
485+
RoutingContext::with_expr(
486+
Declare {
487+
interest_id,
488+
ext_qos: ext::QoSType::DECLARE,
489+
ext_tstamp: None,
490+
ext_nodeid: ext::NodeIdType::DEFAULT,
491+
body: DeclareBody::DeclareSubscriber(DeclareSubscriber {
492+
id,
493+
wire_expr,
494+
}),
495+
},
496+
sub.expr().to_string(),
497+
),
498+
);
499499
}
500500
}
501501
}

zenoh/src/net/routing/hat/p2p_peer/queries.rs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -484,37 +484,33 @@ pub(super) fn declare_qabl_interest(
484484
for src_face in tables
485485
.faces
486486
.values()
487+
.filter(|f| f.id != face.id)
487488
.cloned()
488489
.collect::<Vec<Arc<FaceState>>>()
489490
{
490-
if src_face.id != face.id {
491-
for qabl in face_hat!(src_face).remote_qabls.values() {
492-
if qabl.context.is_some() {
493-
let info = local_qabl_info(tables, qabl, face);
494-
let id = make_qabl_id(qabl, face, mode, info);
495-
let key_expr = Resource::decl_key(
496-
qabl,
497-
face,
498-
super::push_declaration_profile(face),
499-
);
500-
send_declare(
501-
&face.primitives,
502-
RoutingContext::with_expr(
503-
Declare {
504-
interest_id,
505-
ext_qos: ext::QoSType::DECLARE,
506-
ext_tstamp: None,
507-
ext_nodeid: ext::NodeIdType::DEFAULT,
508-
body: DeclareBody::DeclareQueryable(DeclareQueryable {
509-
id,
510-
wire_expr: key_expr,
511-
ext_info: info,
512-
}),
513-
},
514-
qabl.expr().to_string(),
515-
),
516-
);
517-
}
491+
for qabl in face_hat!(src_face).remote_qabls.values() {
492+
if qabl.context.is_some() {
493+
let info = local_qabl_info(tables, qabl, face);
494+
let id = make_qabl_id(qabl, face, mode, info);
495+
let key_expr =
496+
Resource::decl_key(qabl, face, super::push_declaration_profile(face));
497+
send_declare(
498+
&face.primitives,
499+
RoutingContext::with_expr(
500+
Declare {
501+
interest_id,
502+
ext_qos: ext::QoSType::DECLARE,
503+
ext_tstamp: None,
504+
ext_nodeid: ext::NodeIdType::DEFAULT,
505+
body: DeclareBody::DeclareQueryable(DeclareQueryable {
506+
id,
507+
wire_expr: key_expr,
508+
ext_info: info,
509+
}),
510+
},
511+
qabl.expr().to_string(),
512+
),
513+
);
518514
}
519515
}
520516
}

zenoh/src/net/routing/hat/p2p_peer/token.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ fn propagate_forget_simple_token(
281281
),
282282
);
283283
} else if src_face.id != face.id
284+
&& (src_face.whatami == WhatAmI::Client || face.whatami == WhatAmI::Client)
284285
&& face_hat!(face)
285286
.remote_interests
286287
.values()

0 commit comments

Comments
 (0)