Skip to content

Commit 40efd99

Browse files
authored
Adding the ability to return an error from the interceptors factory (#737)
1 parent dfe3d4a commit 40efd99

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

zenoh/src/net/routing/dispatcher/tables.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use zenoh_config::unwrap_or_default;
2828
use zenoh_config::Config;
2929
use zenoh_protocol::core::{ExprId, WhatAmI, ZenohId};
3030
use zenoh_protocol::network::Mapping;
31+
use zenoh_result::ZResult;
3132
// use zenoh_collections::Timer;
3233
use zenoh_sync::get_mut_unchecked;
3334

@@ -76,15 +77,20 @@ pub struct Tables {
7677
}
7778

7879
impl Tables {
79-
pub fn new(zid: ZenohId, whatami: WhatAmI, hlc: Option<Arc<HLC>>, config: &Config) -> Self {
80+
pub fn new(
81+
zid: ZenohId,
82+
whatami: WhatAmI,
83+
hlc: Option<Arc<HLC>>,
84+
config: &Config,
85+
) -> ZResult<Self> {
8086
let drop_future_timestamp =
8187
unwrap_or_default!(config.timestamping().drop_future_timestamp());
8288
let router_peers_failover_brokering =
8389
unwrap_or_default!(config.routing().router().peers_failover_brokering());
8490
// let queries_default_timeout =
8591
// Duration::from_millis(unwrap_or_default!(config.queries_default_timeout()));
8692
let hat_code = hat::new_hat(whatami, config);
87-
Tables {
93+
Ok(Tables {
8894
zid,
8995
whatami,
9096
face_counter: 0,
@@ -96,11 +102,11 @@ impl Tables {
96102
faces: HashMap::new(),
97103
mcast_groups: vec![],
98104
mcast_faces: vec![],
99-
interceptors: interceptor_factories(config),
105+
interceptors: interceptor_factories(config)?,
100106
pull_caches_lock: Mutex::new(()),
101107
hat: hat_code.new_tables(router_peers_failover_brokering),
102108
hat_code: hat_code.into(),
103-
}
109+
})
104110
}
105111

106112
#[doc(hidden)]

zenoh/src/net/routing/interceptor/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use super::RoutingContext;
2121
use zenoh_config::Config;
2222
use zenoh_protocol::network::NetworkMessage;
23+
use zenoh_result::ZResult;
2324
use zenoh_transport::{multicast::TransportMulticast, unicast::TransportUnicast};
2425

2526
pub(crate) trait InterceptorTrait {
@@ -44,11 +45,11 @@ pub(crate) trait InterceptorFactoryTrait {
4445

4546
pub(crate) type InterceptorFactory = Box<dyn InterceptorFactoryTrait + Send + Sync>;
4647

47-
pub(crate) fn interceptor_factories(_config: &Config) -> Vec<InterceptorFactory> {
48+
pub(crate) fn interceptor_factories(_config: &Config) -> ZResult<Vec<InterceptorFactory>> {
4849
// Add interceptors here
4950
// @TODO build the list of intercetors with the correct order from the config
5051
// vec![Box::new(LoggerInterceptor {})]
51-
vec![]
52+
Ok(vec![])
5253
}
5354

5455
pub(crate) struct InterceptorsChain {

zenoh/src/net/routing/router.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,20 @@ pub struct Router {
4545
}
4646

4747
impl Router {
48-
pub fn new(zid: ZenohId, whatami: WhatAmI, hlc: Option<Arc<HLC>>, config: &Config) -> Self {
49-
Router {
48+
pub fn new(
49+
zid: ZenohId,
50+
whatami: WhatAmI,
51+
hlc: Option<Arc<HLC>>,
52+
config: &Config,
53+
) -> ZResult<Self> {
54+
Ok(Router {
5055
// whatami,
5156
tables: Arc::new(TablesLock {
52-
tables: RwLock::new(Tables::new(zid, whatami, hlc, config)),
57+
tables: RwLock::new(Tables::new(zid, whatami, hlc, config)?),
5358
ctrl_lock: Mutex::new(hat::new_hat(whatami, config)),
5459
queries_lock: RwLock::new(()),
5560
}),
56-
}
61+
})
5762
}
5863

5964
#[allow(clippy::too_many_arguments)]

zenoh/src/net/runtime/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Runtime {
9595
let hlc = (*unwrap_or_default!(config.timestamping().enabled().get(whatami)))
9696
.then(|| Arc::new(HLCBuilder::new().with_id(uhlc::ID::from(&zid)).build()));
9797

98-
let router = Arc::new(Router::new(zid, whatami, hlc.clone(), &config));
98+
let router = Arc::new(Router::new(zid, whatami, hlc.clone(), &config)?);
9999

100100
let handler = Arc::new(RuntimeTransportEventHandler {
101101
runtime: std::sync::RwLock::new(None),

zenoh/src/net/tests/tables.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ fn base_test() {
3838
WhatAmI::Client,
3939
Some(Arc::new(HLC::default())),
4040
&config,
41-
);
41+
)
42+
.unwrap();
4243
let tables = router.tables.clone();
4344

4445
let primitives = Arc::new(DummyPrimitives {});
@@ -133,7 +134,8 @@ fn match_test() {
133134
WhatAmI::Client,
134135
Some(Arc::new(HLC::default())),
135136
&config,
136-
);
137+
)
138+
.unwrap();
137139
let tables = router.tables.clone();
138140

139141
let primitives = Arc::new(DummyPrimitives {});
@@ -172,7 +174,8 @@ fn clean_test() {
172174
WhatAmI::Client,
173175
Some(Arc::new(HLC::default())),
174176
&config,
175-
);
177+
)
178+
.unwrap();
176179
let tables = router.tables.clone();
177180

178181
let primitives = Arc::new(DummyPrimitives {});
@@ -478,7 +481,8 @@ fn client_test() {
478481
WhatAmI::Client,
479482
Some(Arc::new(HLC::default())),
480483
&config,
481-
);
484+
)
485+
.unwrap();
482486
let tables = router.tables.clone();
483487

484488
let sub_info = SubscriberInfo {

0 commit comments

Comments
 (0)