From 62049b1745b045b40f8939df35d56aff64fca76b Mon Sep 17 00:00:00 2001 From: OlivierHecart Date: Mon, 15 Jan 2024 10:11:15 +0100 Subject: [PATCH] Renaming --- zenoh/src/net/primitives/demux.rs | 12 ++--- zenoh/src/net/primitives/mux.rs | 32 ++++++------- zenoh/src/net/routing/dispatcher/tables.rs | 8 ++-- zenoh/src/net/routing/interceptor/mod.rs | 55 ++++++++++++---------- zenoh/src/net/routing/router.rs | 22 ++++----- 5 files changed, 66 insertions(+), 63 deletions(-) diff --git a/zenoh/src/net/primitives/demux.rs b/zenoh/src/net/primitives/demux.rs index 9ea371d0cf..95b89268df 100644 --- a/zenoh/src/net/primitives/demux.rs +++ b/zenoh/src/net/primitives/demux.rs @@ -14,7 +14,7 @@ use super::Primitives; use crate::net::routing::{ dispatcher::face::Face, - interceptor::{InterceptTrait, InterceptsChain}, + interceptor::{InterceptorTrait, InterceptorsChain}, RoutingContext, }; use std::any::Any; @@ -27,19 +27,19 @@ use zenoh_transport::TransportPeerEventHandler; pub struct DeMux { face: Face, pub(crate) transport: Option, - pub(crate) intercept: InterceptsChain, + pub(crate) interceptor: InterceptorsChain, } impl DeMux { pub(crate) fn new( face: Face, transport: Option, - intercept: InterceptsChain, + interceptor: InterceptorsChain, ) -> Self { Self { face, transport, - intercept, + interceptor, } } } @@ -47,9 +47,9 @@ impl DeMux { impl TransportPeerEventHandler for DeMux { #[inline] fn handle_message(&self, mut msg: NetworkMessage) -> ZResult<()> { - if !self.intercept.intercepts.is_empty() { + if !self.interceptor.interceptors.is_empty() { let ctx = RoutingContext::new_in(msg, self.face.clone()); - let ctx = match self.intercept.intercept(ctx) { + let ctx = match self.interceptor.intercept(ctx) { Some(ctx) => ctx, None => return Ok(()), }; diff --git a/zenoh/src/net/primitives/mux.rs b/zenoh/src/net/primitives/mux.rs index a31100e1d7..935d74ac5a 100644 --- a/zenoh/src/net/primitives/mux.rs +++ b/zenoh/src/net/primitives/mux.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use super::{EPrimitives, Primitives}; use crate::net::routing::{ dispatcher::{face::Face, tables::TablesLock}, - interceptor::{InterceptTrait, InterceptsChain}, + interceptor::{InterceptorTrait, InterceptorsChain}, RoutingContext, }; use zenoh_protocol::network::{ @@ -28,7 +28,7 @@ pub struct Mux { pub handler: TransportUnicast, pub(crate) fid: usize, pub(crate) tables: Arc, - pub(crate) intercept: InterceptsChain, + pub(crate) interceptor: InterceptorsChain, } impl Mux { @@ -36,13 +36,13 @@ impl Mux { handler: TransportUnicast, fid: usize, tables: Arc, - intercept: InterceptsChain, + interceptor: InterceptorsChain, ) -> Mux { Mux { handler, fid, tables, - intercept, + interceptor, } } } @@ -65,7 +65,7 @@ impl Primitives for Mux { state: face.clone(), }, ); - if let Some(ctx) = self.intercept.intercept(ctx) { + if let Some(ctx) = self.interceptor.intercept(ctx) { let _ = self.handler.schedule(ctx.msg); } } @@ -88,7 +88,7 @@ impl Primitives for Mux { state: face.clone(), }, ); - if let Some(ctx) = self.intercept.intercept(ctx) { + if let Some(ctx) = self.interceptor.intercept(ctx) { let _ = self.handler.schedule(ctx.msg); } } @@ -111,7 +111,7 @@ impl Primitives for Mux { state: face.clone(), }, ); - if let Some(ctx) = self.intercept.intercept(ctx) { + if let Some(ctx) = self.interceptor.intercept(ctx) { let _ = self.handler.schedule(ctx.msg); } } @@ -134,7 +134,7 @@ impl Primitives for Mux { state: face.clone(), }, ); - if let Some(ctx) = self.intercept.intercept(ctx) { + if let Some(ctx) = self.interceptor.intercept(ctx) { let _ = self.handler.schedule(ctx.msg); } } @@ -157,7 +157,7 @@ impl Primitives for Mux { state: face.clone(), }, ); - if let Some(ctx) = self.intercept.intercept(ctx) { + if let Some(ctx) = self.interceptor.intercept(ctx) { let _ = self.handler.schedule(ctx.msg); } } @@ -181,7 +181,7 @@ impl EPrimitives for Mux { prefix: ctx.prefix, full_expr: ctx.full_expr, }; - if let Some(ctx) = self.intercept.intercept(ctx) { + if let Some(ctx) = self.interceptor.intercept(ctx) { let _ = self.handler.schedule(ctx.msg); } } @@ -198,7 +198,7 @@ impl EPrimitives for Mux { prefix: ctx.prefix, full_expr: ctx.full_expr, }; - if let Some(ctx) = self.intercept.intercept(ctx) { + if let Some(ctx) = self.interceptor.intercept(ctx) { let _ = self.handler.schedule(ctx.msg); } } @@ -215,7 +215,7 @@ impl EPrimitives for Mux { prefix: ctx.prefix, full_expr: ctx.full_expr, }; - if let Some(ctx) = self.intercept.intercept(ctx) { + if let Some(ctx) = self.interceptor.intercept(ctx) { let _ = self.handler.schedule(ctx.msg); } } @@ -232,7 +232,7 @@ impl EPrimitives for Mux { prefix: ctx.prefix, full_expr: ctx.full_expr, }; - if let Some(ctx) = self.intercept.intercept(ctx) { + if let Some(ctx) = self.interceptor.intercept(ctx) { let _ = self.handler.schedule(ctx.msg); } } @@ -249,7 +249,7 @@ impl EPrimitives for Mux { prefix: ctx.prefix, full_expr: ctx.full_expr, }; - if let Some(ctx) = self.intercept.intercept(ctx) { + if let Some(ctx) = self.interceptor.intercept(ctx) { let _ = self.handler.schedule(ctx.msg); } } @@ -263,7 +263,7 @@ pub struct McastMux { pub handler: TransportMulticast, pub(crate) fid: usize, pub(crate) tables: Arc, - pub(crate) intercept: InterceptsChain, + pub(crate) intercept: InterceptorsChain, } impl McastMux { @@ -271,7 +271,7 @@ impl McastMux { handler: TransportMulticast, fid: usize, tables: Arc, - intercept: InterceptsChain, + intercept: InterceptorsChain, ) -> McastMux { McastMux { handler, diff --git a/zenoh/src/net/routing/dispatcher/tables.rs b/zenoh/src/net/routing/dispatcher/tables.rs index 1b02812a39..2fcfdf27c7 100644 --- a/zenoh/src/net/routing/dispatcher/tables.rs +++ b/zenoh/src/net/routing/dispatcher/tables.rs @@ -17,8 +17,8 @@ pub use super::queries::*; pub use super::resource::*; use crate::net::routing::hat; use crate::net::routing::hat::HatTrait; -use crate::net::routing::interceptor::interceptors; -use crate::net::routing::interceptor::Interceptor; +use crate::net::routing::interceptor::interceptor_factories; +use crate::net::routing::interceptor::InterceptorFactory; use std::any::Any; use std::collections::HashMap; use std::sync::{Arc, Weak}; @@ -69,7 +69,7 @@ pub struct Tables { pub(crate) faces: HashMap>, pub(crate) mcast_groups: Vec>, pub(crate) mcast_faces: Vec>, - pub(crate) interceptors: Vec, + pub(crate) interceptors: Vec, pub(crate) pull_caches_lock: Mutex<()>, pub(crate) hat: Box, pub(crate) hat_code: Arc, // TODO make this a Box @@ -96,7 +96,7 @@ impl Tables { faces: HashMap::new(), mcast_groups: vec![], mcast_faces: vec![], - interceptors: interceptors(config), + interceptors: interceptor_factories(config), pull_caches_lock: Mutex::new(()), hat: hat_code.new_tables(router_peers_failover_brokering), hat_code: hat_code.into(), diff --git a/zenoh/src/net/routing/interceptor/mod.rs b/zenoh/src/net/routing/interceptor/mod.rs index 171d93b021..22e0e4e549 100644 --- a/zenoh/src/net/routing/interceptor/mod.rs +++ b/zenoh/src/net/routing/interceptor/mod.rs @@ -22,58 +22,61 @@ use zenoh_config::Config; use zenoh_protocol::network::NetworkMessage; use zenoh_transport::{multicast::TransportMulticast, unicast::TransportUnicast}; -pub(crate) trait InterceptTrait { +pub(crate) trait InterceptorTrait { fn intercept( &self, ctx: RoutingContext, ) -> Option>; } -pub(crate) type Intercept = Box; -pub(crate) type IngressIntercept = Intercept; -pub(crate) type EgressIntercept = Intercept; +pub(crate) type Interceptor = Box; +pub(crate) type IngressInterceptor = Interceptor; +pub(crate) type EgressInterceptor = Interceptor; -pub(crate) trait InterceptorTrait { +pub(crate) trait InterceptorFactoryTrait { fn new_transport_unicast( &self, transport: &TransportUnicast, - ) -> (Option, Option); - fn new_transport_multicast(&self, transport: &TransportMulticast) -> Option; - fn new_peer_multicast(&self, transport: &TransportMulticast) -> Option; + ) -> (Option, Option); + fn new_transport_multicast(&self, transport: &TransportMulticast) -> Option; + fn new_peer_multicast(&self, transport: &TransportMulticast) -> Option; } -pub(crate) type Interceptor = Box; +pub(crate) type InterceptorFactory = Box; -pub(crate) fn interceptors(_config: &Config) -> Vec { +pub(crate) fn interceptor_factories(_config: &Config) -> Vec { // Add interceptors here + // TODO build the list of intercetors with the correct order from the config // vec![Box::new(LoggerInterceptor {})] vec![] } -pub(crate) struct InterceptsChain { - pub(crate) intercepts: Vec, +pub(crate) struct InterceptorsChain { + pub(crate) interceptors: Vec, } -impl InterceptsChain { +impl InterceptorsChain { #[allow(dead_code)] pub(crate) fn empty() -> Self { - Self { intercepts: vec![] } + Self { + interceptors: vec![], + } } } -impl From> for InterceptsChain { - fn from(intercepts: Vec) -> Self { - InterceptsChain { intercepts } +impl From> for InterceptorsChain { + fn from(interceptors: Vec) -> Self { + InterceptorsChain { interceptors } } } -impl InterceptTrait for InterceptsChain { +impl InterceptorTrait for InterceptorsChain { fn intercept( &self, mut ctx: RoutingContext, ) -> Option> { - for intercept in &self.intercepts { - match intercept.intercept(ctx) { + for interceptor in &self.interceptors { + match interceptor.intercept(ctx) { Some(newctx) => ctx = newctx, None => { log::trace!("Msg intercepted!"); @@ -87,7 +90,7 @@ impl InterceptTrait for InterceptsChain { pub(crate) struct IngressMsgLogger {} -impl InterceptTrait for IngressMsgLogger { +impl InterceptorTrait for IngressMsgLogger { fn intercept( &self, ctx: RoutingContext, @@ -105,7 +108,7 @@ impl InterceptTrait for IngressMsgLogger { } pub(crate) struct EgressMsgLogger {} -impl InterceptTrait for EgressMsgLogger { +impl InterceptorTrait for EgressMsgLogger { fn intercept( &self, ctx: RoutingContext, @@ -117,11 +120,11 @@ impl InterceptTrait for EgressMsgLogger { pub(crate) struct LoggerInterceptor {} -impl InterceptorTrait for LoggerInterceptor { +impl InterceptorFactoryTrait for LoggerInterceptor { fn new_transport_unicast( &self, transport: &TransportUnicast, - ) -> (Option, Option) { + ) -> (Option, Option) { log::debug!("New transport unicast {:?}", transport); ( Some(Box::new(IngressMsgLogger {})), @@ -129,12 +132,12 @@ impl InterceptorTrait for LoggerInterceptor { ) } - fn new_transport_multicast(&self, transport: &TransportMulticast) -> Option { + fn new_transport_multicast(&self, transport: &TransportMulticast) -> Option { log::debug!("New transport multicast {:?}", transport); Some(Box::new(EgressMsgLogger {})) } - fn new_peer_multicast(&self, transport: &TransportMulticast) -> Option { + fn new_peer_multicast(&self, transport: &TransportMulticast) -> Option { log::debug!("New peer multicast {:?}", transport); Some(Box::new(IngressMsgLogger {})) } diff --git a/zenoh/src/net/routing/router.rs b/zenoh/src/net/routing/router.rs index 3b6e8eba9c..79bfe70025 100644 --- a/zenoh/src/net/routing/router.rs +++ b/zenoh/src/net/routing/router.rs @@ -18,15 +18,15 @@ pub use super::dispatcher::resource::*; use super::dispatcher::tables::Tables; use super::dispatcher::tables::TablesLock; use super::hat; -use super::interceptor::EgressIntercept; -use super::interceptor::InterceptsChain; +use super::interceptor::EgressInterceptor; +use super::interceptor::InterceptorsChain; use super::runtime::Runtime; use crate::net::primitives::DeMux; use crate::net::primitives::DummyPrimitives; use crate::net::primitives::EPrimitives; use crate::net::primitives::McastMux; use crate::net::primitives::Mux; -use crate::net::routing::interceptor::IngressIntercept; +use crate::net::routing::interceptor::IngressInterceptor; use std::str::FromStr; use std::sync::Arc; use std::sync::{Mutex, RwLock}; @@ -120,8 +120,8 @@ impl Router { .map(|itor| itor.new_transport_unicast(&transport)) .unzip(); let (ingress, egress) = ( - InterceptsChain::from(ingress.into_iter().flatten().collect::>()), - InterceptsChain::from(egress.into_iter().flatten().collect::>()), + InterceptorsChain::from(ingress.into_iter().flatten().collect::>()), + InterceptorsChain::from(egress.into_iter().flatten().collect::>()), ); let newface = tables .faces @@ -162,12 +162,12 @@ impl Router { let mut tables = zwrite!(self.tables.tables); let fid = tables.face_counter; tables.face_counter += 1; - let intercept = InterceptsChain::from( + let interceptor = InterceptorsChain::from( tables .interceptors .iter() .filter_map(|itor| itor.new_transport_multicast(&transport)) - .collect::>(), + .collect::>(), ); tables.mcast_groups.push(FaceState::new( fid, @@ -180,7 +180,7 @@ impl Router { transport.clone(), fid, self.tables.clone(), - intercept, + interceptor, )), Some(transport), ctrl_lock.new_face(), @@ -201,12 +201,12 @@ impl Router { let mut tables = zwrite!(self.tables.tables); let fid = tables.face_counter; tables.face_counter += 1; - let intercept = InterceptsChain::from( + let interceptor = InterceptorsChain::from( tables .interceptors .iter() .filter_map(|itor| itor.new_peer_multicast(&transport)) - .collect::>(), + .collect::>(), ); let face_state = FaceState::new( fid, @@ -230,7 +230,7 @@ impl Router { state: face_state, }, None, - intercept, + interceptor, ))) } }