Skip to content

Commit

Permalink
refactor: Implement liveliness dispatching logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzypixelz committed Mar 26, 2024
1 parent 5128497 commit 97e3eed
Showing 1 changed file with 81 additions and 3 deletions.
84 changes: 81 additions & 3 deletions zenoh/src/net/routing/dispatcher/liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

use std::sync::Arc;

use zenoh_keyexpr::keyexpr;
use zenoh_protocol::{
core::WireExpr,
network::declare::{common::ext, TokenId},
};

use crate::net::routing::hat::HatTrait;
use crate::net::routing::{hat::HatTrait, router::Resource};

use super::{
face::FaceState,
Expand All @@ -34,7 +35,52 @@ pub(crate) fn declare_liveliness(
expr: &WireExpr,
node_id: NodeId,
) {
todo!()
let rtables = zread!(tables.tables);
match rtables
.get_mapping(face, &expr.scope, expr.mapping)
.cloned()
{
Some(mut prefix) => {
log::debug!(
"{} Declare liveliness {} ({}{})",
face,
id,
prefix.expr(),
expr.suffix
);
let res = Resource::get_resource(&prefix, &expr.suffix);
let (mut res, mut wtables) =
if res.as_ref().map(|r| r.context.is_some()).unwrap_or(false) {
drop(rtables);
let wtables = zwrite!(tables.tables);
(res.unwrap(), wtables)
} else {
let mut fullexpr = prefix.expr();
fullexpr.push_str(expr.suffix.as_ref());
let mut matches = keyexpr::new(fullexpr.as_str())
.map(|ke| Resource::get_matches(&rtables, ke))
.unwrap_or_default();
drop(rtables);
let mut wtables = zwrite!(tables.tables);
let mut res =
Resource::make_resource(&mut wtables, &mut prefix, expr.suffix.as_ref());
matches.push(Arc::downgrade(&res));
Resource::match_resource(&wtables, &mut res, matches);
(res, wtables)
};

hat_code.declare_liveliness(&mut wtables, face, id, &mut res, node_id);
drop(wtables);

// NOTE(fuzzypixelz): I removed all data route handling.
}
None => log::error!(
"{} Declare liveliness {} for unknown scope {}!",
face,
id,
expr.scope
),
}
}

pub(crate) fn undeclare_liveliness(
Expand All @@ -45,5 +91,37 @@ pub(crate) fn undeclare_liveliness(
expr: &ext::WireExprType,
node_id: NodeId,
) {
todo!()
let res = if expr.wire_expr.is_empty() {
None
} else {
let rtables = zread!(tables.tables);
match rtables.get_mapping(face, &expr.wire_expr.scope, expr.wire_expr.mapping) {
Some(prefix) => match Resource::get_resource(prefix, expr.wire_expr.suffix.as_ref()) {
Some(res) => Some(res),
None => {
log::error!(
"{} Undeclare unknown liveliness token {}{}!",
face,
prefix.expr(),
expr.wire_expr.suffix
);
return;
}
},
None => {
log::error!(
"{} Undeclare liveliness token with unknown scope {}",
face,
expr.wire_expr.scope
);
return;
}
}
};

let mut wtables = zwrite!(tables.tables);
hat_code.undeclare_liveliness(&mut wtables, face, id, res, node_id);

// NOTE(fuzzypixelz): I removed all data route handling.
// NOTE(fuzzypixelz): Unlike in `undeclare_liveliness` this doesn't return the ressource.
}

0 comments on commit 97e3eed

Please sign in to comment.