From dbe1606d572b6c45ff472fbc700a0e2eda4f660a Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Fri, 2 Aug 2024 12:39:26 +0200 Subject: [PATCH] Add validaton in Router::new to update_workers argument Signed-off-by: Lee Smet --- mycelium/src/router.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mycelium/src/router.rs b/mycelium/src/router.rs index 0ef7573..6f9f8aa 100644 --- a/mycelium/src/router.rs +++ b/mycelium/src/router.rs @@ -88,6 +88,11 @@ impl Router where M: Metrics + Clone + Send + 'static, { + /// Create a new `Router`. + /// + /// # Panics + /// + /// If update_workers is not in the range of [1..255], this will panic. pub fn new( update_workers: usize, node_tun: UnboundedSender, @@ -97,6 +102,12 @@ where update_filters: Vec>, metrics: M, ) -> Result> { + // We could use a NonZeroU8 here, but for now just handle this manually as this might get + // changed in the future. + if !(1..255).contains(&update_workers) { + panic!("update workers must be at least 1 and at most 255"); + } + // Tx is passed onto each new peer instance. This enables peers to send control packets to the router. let (router_control_tx, router_control_rx) = mpsc::unbounded_channel(); // Tx is passed onto each new peer instance. This enables peers to send data packets to the router.