Skip to content

Commit

Permalink
Fix liveliness bug (#1321)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart authored Aug 22, 2024
1 parent 1696e75 commit 8b027e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
14 changes: 7 additions & 7 deletions zenoh/src/net/routing/hat/linkstate_peer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ fn simple_tokens(res: &Arc<Resource>) -> Vec<Arc<FaceState>> {
}

#[inline]
fn remote_simple_tokens(res: &Arc<Resource>, face: &Arc<FaceState>) -> bool {
fn remote_simple_tokens(tables: &Tables, res: &Arc<Resource>, face: &Arc<FaceState>) -> bool {
res.session_ctxs
.values()
.any(|ctx| ctx.face.id != face.id && ctx.token)
.any(|ctx| (ctx.face.id != face.id || face.zid == tables.zid) && ctx.token)
}

#[inline]
Expand Down Expand Up @@ -375,7 +375,7 @@ fn propagate_forget_simple_token(
if !res.context().matches.iter().any(|m| {
m.upgrade().is_some_and(|m| {
m.context.is_some()
&& (remote_simple_tokens(&m, &face)
&& (remote_simple_tokens(tables, &m, &face)
|| remote_linkstatepeer_tokens(tables, &m))
})
}) {
Expand Down Expand Up @@ -530,7 +530,7 @@ pub(super) fn undeclare_simple_token(
if !res.context().matches.iter().any(|m| {
m.upgrade().is_some_and(|m| {
m.context.is_some()
&& (remote_simple_tokens(&m, face)
&& (remote_simple_tokens(tables, &m, face)
|| remote_linkstatepeer_tokens(tables, &m))
})
}) {
Expand Down Expand Up @@ -643,7 +643,7 @@ pub(crate) fn declare_token_interest(
if hat!(tables).linkstatepeer_tokens.iter().any(|token| {
token.context.is_some()
&& token.matches(res)
&& (remote_simple_tokens(token, face)
&& (remote_simple_tokens(tables, token, face)
|| remote_linkstatepeer_tokens(tables, token))
}) {
let id = if mode.future() {
Expand Down Expand Up @@ -672,7 +672,7 @@ pub(crate) fn declare_token_interest(
for token in &hat!(tables).linkstatepeer_tokens {
if token.context.is_some()
&& token.matches(res)
&& (remote_simple_tokens(token, face)
&& (remote_simple_tokens(tables, token, face)
|| remote_linkstatepeer_tokens(tables, token))
{
let id = if mode.future() {
Expand Down Expand Up @@ -702,7 +702,7 @@ pub(crate) fn declare_token_interest(
} else {
for token in &hat!(tables).linkstatepeer_tokens {
if token.context.is_some()
&& (remote_simple_tokens(token, face)
&& (remote_simple_tokens(tables, token, face)
|| remote_linkstatepeer_tokens(tables, token))
{
let id = if mode.future() {
Expand Down
15 changes: 8 additions & 7 deletions zenoh/src/net/routing/hat/p2p_peer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ use crate::net::routing::{

#[inline]
fn propagate_simple_token_to(
_tables: &mut Tables,
tables: &mut Tables,
dst_face: &mut Arc<FaceState>,
res: &Arc<Resource>,
src_face: &mut Arc<FaceState>,
send_declare: &mut SendDeclare,
) {
if (src_face.id != dst_face.id || dst_face.whatami == WhatAmI::Client)
if (src_face.id != dst_face.id || dst_face.zid == tables.zid)
&& !face_hat!(dst_face).local_tokens.contains_key(res)
&& (src_face.whatami == WhatAmI::Client || dst_face.whatami == WhatAmI::Client)
{
Expand Down Expand Up @@ -173,10 +173,10 @@ fn simple_tokens(res: &Arc<Resource>) -> Vec<Arc<FaceState>> {
}

#[inline]
fn remote_simple_tokens(res: &Arc<Resource>, face: &Arc<FaceState>) -> bool {
fn remote_simple_tokens(tables: &Tables, res: &Arc<Resource>, face: &Arc<FaceState>) -> bool {
res.session_ctxs
.values()
.any(|ctx| ctx.face.id != face.id && ctx.token)
.any(|ctx| (ctx.face.id != face.id || face.zid == tables.zid) && ctx.token)
}

fn propagate_forget_simple_token(
Expand Down Expand Up @@ -234,7 +234,7 @@ fn propagate_forget_simple_token(
{
if !res.context().matches.iter().any(|m| {
m.upgrade()
.is_some_and(|m| m.context.is_some() && remote_simple_tokens(&m, &face))
.is_some_and(|m| m.context.is_some() && remote_simple_tokens(tables, &m, &face))
}) {
if let Some(id) = face_hat_mut!(&mut face).local_tokens.remove(&res) {
send_declare(
Expand Down Expand Up @@ -332,8 +332,9 @@ pub(super) fn undeclare_simple_token(
.collect::<Vec<Arc<Resource>>>()
{
if !res.context().matches.iter().any(|m| {
m.upgrade()
.is_some_and(|m| m.context.is_some() && remote_simple_tokens(&m, face))
m.upgrade().is_some_and(|m| {
m.context.is_some() && remote_simple_tokens(tables, &m, face)
})
}) {
if let Some(id) = face_hat_mut!(&mut face).local_tokens.remove(&res) {
send_declare(
Expand Down
12 changes: 6 additions & 6 deletions zenoh/src/net/routing/hat/router/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn propagate_simple_token_to(
full_peer_net: bool,
send_declare: &mut SendDeclare,
) {
if (src_face.id != dst_face.id || dst_face.whatami == WhatAmI::Client)
if (src_face.id != dst_face.id || dst_face.zid == tables.zid)
&& !face_hat!(dst_face).local_tokens.contains_key(res)
&& if full_peer_net {
dst_face.whatami == WhatAmI::Client
Expand Down Expand Up @@ -335,10 +335,10 @@ fn simple_tokens(res: &Arc<Resource>) -> Vec<Arc<FaceState>> {
}

#[inline]
fn remote_simple_tokens(res: &Arc<Resource>, face: &Arc<FaceState>) -> bool {
fn remote_simple_tokens(tables: &Tables, res: &Arc<Resource>, face: &Arc<FaceState>) -> bool {
res.session_ctxs
.values()
.any(|ctx| ctx.face.id != face.id && ctx.token)
.any(|ctx| (ctx.face.id != face.id || face.zid == tables.zid) && ctx.token)
}

#[inline]
Expand Down Expand Up @@ -446,7 +446,7 @@ fn propagate_forget_simple_token(
if !res.context().matches.iter().any(|m| {
m.upgrade().is_some_and(|m| {
m.context.is_some()
&& (remote_simple_tokens(&m, &face)
&& (remote_simple_tokens(tables, &m, &face)
|| remote_linkstatepeer_tokens(tables, &m)
|| remote_router_tokens(tables, &m))
})
Expand Down Expand Up @@ -729,7 +729,7 @@ pub(super) fn undeclare_simple_token(
if !res.context().matches.iter().any(|m| {
m.upgrade().is_some_and(|m| {
m.context.is_some()
&& (remote_simple_tokens(&m, face)
&& (remote_simple_tokens(tables, &m, face)
|| remote_linkstatepeer_tokens(tables, &m)
|| remote_router_tokens(tables, &m))
})
Expand Down Expand Up @@ -966,7 +966,7 @@ pub(crate) fn declare_token_interest(
if hat!(tables).router_tokens.iter().any(|token| {
token.context.is_some()
&& token.matches(res)
&& (remote_simple_tokens(token, face)
&& (remote_simple_tokens(tables, token, face)
|| remote_linkstatepeer_tokens(tables, token)
|| remote_router_tokens(tables, token))
}) {
Expand Down

0 comments on commit 8b027e9

Please sign in to comment.