Skip to content

Commit

Permalink
Add gossip target option for p2p peers
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart committed Dec 13, 2024
1 parent 77923a2 commit 608b0eb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
9 changes: 9 additions & 0 deletions commons/zenoh-config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ pub mod scouting {
pub mod gossip {
pub const enabled: bool = true;
pub const multihop: bool = false;
pub mod target {
pub const router: &crate::WhatAmIMatcher = // "router|peer"
&crate::WhatAmIMatcher::empty().router().peer();
pub const peer: &crate::WhatAmIMatcher = // "router|peer"
&crate::WhatAmIMatcher::empty().router().peer();
pub const client: &crate::WhatAmIMatcher = // ""
&crate::WhatAmIMatcher::empty();
mode_accessor!(crate::WhatAmIMatcher);
}
pub mod autoconnect {
pub const router: &crate::WhatAmIMatcher = // ""
&crate::WhatAmIMatcher::empty();
Expand Down
2 changes: 2 additions & 0 deletions commons/zenoh-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ validated_struct::validator! {
/// It mostly makes sense when using "linkstate" routing mode where all nodes in the subsystem don't have
/// direct connectivity with each other.
multihop: Option<bool>,
/// Which type of Zenoh instances to send gossip messages to.
target: Option<ModeDependentValue<WhatAmIMatcher>>,
/// Which type of Zenoh instances to automatically establish sessions with upon discovery through gossip.
autoconnect: Option<ModeDependentValue<WhatAmIMatcher>>,
},
Expand Down
27 changes: 20 additions & 7 deletions zenoh/src/net/routing/hat/p2p_peer/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub(super) struct Network {
pub(super) router_peers_failover_brokering: bool,
pub(super) gossip: bool,
pub(super) gossip_multihop: bool,
pub(super) target: WhatAmIMatcher,
pub(super) autoconnect: WhatAmIMatcher,
pub(super) wait_declares: bool,
pub(super) idx: NodeIndex,
Expand All @@ -113,6 +114,7 @@ impl Network {
router_peers_failover_brokering: bool,
gossip: bool,
gossip_multihop: bool,
target: WhatAmIMatcher,
autoconnect: WhatAmIMatcher,
wait_declares: bool,
) -> Self {
Expand All @@ -130,6 +132,7 @@ impl Network {
router_peers_failover_brokering,
gossip,
gossip_multihop,
target,
autoconnect,
wait_declares,
idx,
Expand Down Expand Up @@ -231,13 +234,18 @@ impl Network {
}

fn send_on_link(&self, idxs: Vec<(NodeIndex, Details)>, transport: &TransportUnicast) {
if let Ok(msg) = self.make_msg(idxs) {
tracing::trace!("{} Send to {:?} {:?}", self.name, transport.get_zid(), msg);
if let Err(e) = transport.schedule(msg) {
tracing::debug!("{} Error sending LinkStateList: {}", self.name, e);
if transport
.get_whatami()
.is_ok_and(|w| self.target.matches(w))
{
if let Ok(msg) = self.make_msg(idxs) {
tracing::trace!("{} Send to {:?} {:?}", self.name, transport.get_zid(), msg);
if let Err(e) = transport.schedule(msg) {
tracing::debug!("{} Error sending LinkStateList: {}", self.name, e);
}
} else {
tracing::error!("Failed to encode Linkstate message");
}
} else {
tracing::error!("Failed to encode Linkstate message");
}
}

Expand All @@ -247,7 +255,12 @@ impl Network {
{
if let Ok(msg) = self.make_msg(idxs) {
for link in self.links.values() {
if parameters(link) {
if link
.transport
.get_whatami()
.is_ok_and(|w| self.target.matches(w))
&& parameters(link)
{
tracing::trace!("{} Send to {} {:?}", self.name, link.zid, msg);
if let Err(e) = link.transport.schedule(msg.clone()) {
tracing::debug!("{} Error sending LinkStateList: {}", self.name, e);
Expand Down
6 changes: 6 additions & 0 deletions zenoh/src/net/routing/hat/p2p_peer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ impl HatBaseTrait for HatCode {
let whatami = tables.whatami;
let gossip = unwrap_or_default!(config.scouting().gossip().enabled());
let gossip_multihop = unwrap_or_default!(config.scouting().gossip().multihop());
let gossip_target = if gossip {
*unwrap_or_default!(config.scouting().gossip().target().get(whatami))
} else {
WhatAmIMatcher::empty()
};
let autoconnect = if gossip {
*unwrap_or_default!(config.scouting().gossip().autoconnect().get(whatami))
} else {
Expand All @@ -133,6 +138,7 @@ impl HatBaseTrait for HatCode {
router_peers_failover_brokering,
gossip,
gossip_multihop,
gossip_target,
autoconnect,
wait_declares,
));
Expand Down

0 comments on commit 608b0eb

Please sign in to comment.