From 502efaee30cd2aa867bda64ccfcf6d7026666493 Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Wed, 4 Dec 2024 17:30:15 +0100 Subject: [PATCH 01/12] Move socket to stream/listener functions to zenoh-link-commons --- io/zenoh-link-commons/src/lib.rs | 1 + io/zenoh-link-commons/src/tcp.rs | 80 ++++++++++++++++++++ io/zenoh-links/zenoh-link-tcp/src/unicast.rs | 74 ++---------------- 3 files changed, 86 insertions(+), 69 deletions(-) create mode 100644 io/zenoh-link-commons/src/tcp.rs diff --git a/io/zenoh-link-commons/src/lib.rs b/io/zenoh-link-commons/src/lib.rs index fae26cd02d..b33c527fde 100644 --- a/io/zenoh-link-commons/src/lib.rs +++ b/io/zenoh-link-commons/src/lib.rs @@ -21,6 +21,7 @@ extern crate alloc; mod listener; mod multicast; +pub mod tcp; #[cfg(feature = "tls")] pub mod tls; mod unicast; diff --git a/io/zenoh-link-commons/src/tcp.rs b/io/zenoh-link-commons/src/tcp.rs new file mode 100644 index 0000000000..a8e762d44e --- /dev/null +++ b/io/zenoh-link-commons/src/tcp.rs @@ -0,0 +1,80 @@ +// +// Copyright (c) 2024 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// +use std::net::SocketAddr; + +use tokio::net::{TcpListener, TcpSocket, TcpStream}; +use zenoh_result::{zerror, ZResult}; + +pub struct TcpSocketUtils; + +impl TcpSocketUtils { + /// Build a new TCP listener bound to `addr` with the given configration parameters + pub fn listen(addr: &SocketAddr, iface: Option<&str>) -> ZResult<(TcpListener, SocketAddr)> { + let socket = match addr { + SocketAddr::V4(_) => TcpSocket::new_v4(), + SocketAddr::V6(_) => TcpSocket::new_v6(), + }?; + + if let Some(iface) = iface { + zenoh_util::net::set_bind_to_device_tcp_socket(&socket, iface)?; + } + + // Build a TcpListener from TcpSocket + // https://docs.rs/tokio/latest/tokio/net/struct.TcpSocket.html + socket.set_reuseaddr(true)?; + socket.bind(*addr).map_err(|e| zerror!("{}: {}", addr, e))?; + // backlog (the maximum number of pending connections are queued): 1024 + let listener = socket + .listen(1024) + .map_err(|e| zerror!("{}: {}", addr, e))?; + + let local_addr = listener + .local_addr() + .map_err(|e| zerror!("{}: {}", addr, e))?; + + Ok((listener, local_addr)) + } + + /// Connect to a TCP socket address at `dst_addr` with the given configuration parameters + pub async fn connect( + dst_addr: &SocketAddr, + iface: Option<&str>, + ) -> ZResult<(TcpStream, SocketAddr, SocketAddr)> { + let socket = match dst_addr { + SocketAddr::V4(_) => TcpSocket::new_v4(), + SocketAddr::V6(_) => TcpSocket::new_v6(), + }?; + + if let Some(iface) = iface { + zenoh_util::net::set_bind_to_device_tcp_socket(&socket, iface)?; + } + + // Build a TcpStream from TcpSocket + // https://docs.rs/tokio/latest/tokio/net/struct.TcpSocket.html + let stream = socket + .connect(*dst_addr) + .await + .map_err(|e| zerror!("{}: {}", dst_addr, e))?; + + let src_addr = stream + .local_addr() + .map_err(|e| zerror!("{}: {}", dst_addr, e))?; + + let dst_addr = stream + .peer_addr() + .map_err(|e| zerror!("{}: {}", dst_addr, e))?; + + Ok((stream, src_addr, dst_addr)) + } +} diff --git a/io/zenoh-links/zenoh-link-tcp/src/unicast.rs b/io/zenoh-links/zenoh-link-tcp/src/unicast.rs index e3eb9d9796..4a27fa6fa8 100644 --- a/io/zenoh-links/zenoh-link-tcp/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-tcp/src/unicast.rs @@ -16,12 +16,12 @@ use std::{cell::UnsafeCell, convert::TryInto, fmt, net::SocketAddr, sync::Arc, t use async_trait::async_trait; use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, - net::{TcpListener, TcpSocket, TcpStream}, + net::{TcpListener, TcpStream}, }; use tokio_util::sync::CancellationToken; use zenoh_link_commons::{ - get_ip_interface_names, LinkAuthId, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, - ListenersUnicastIP, NewLinkChannelSender, BIND_INTERFACE, + get_ip_interface_names, tcp::TcpSocketUtils, LinkAuthId, LinkManagerUnicastTrait, LinkUnicast, + LinkUnicastTrait, ListenersUnicastIP, NewLinkChannelSender, BIND_INTERFACE, }; use zenoh_protocol::{ core::{EndPoint, Locator}, @@ -241,70 +241,6 @@ impl LinkManagerUnicastTcp { } } -impl LinkManagerUnicastTcp { - async fn new_link_inner( - &self, - dst_addr: &SocketAddr, - iface: Option<&str>, - ) -> ZResult<(TcpStream, SocketAddr, SocketAddr)> { - let socket = match dst_addr { - SocketAddr::V4(_) => TcpSocket::new_v4(), - SocketAddr::V6(_) => TcpSocket::new_v6(), - }?; - - if let Some(iface) = iface { - zenoh_util::net::set_bind_to_device_tcp_socket(&socket, iface)?; - } - - // Build a TcpStream from TcpSocket - // https://docs.rs/tokio/latest/tokio/net/struct.TcpSocket.html - let stream = socket - .connect(*dst_addr) - .await - .map_err(|e| zerror!("{}: {}", dst_addr, e))?; - - let src_addr = stream - .local_addr() - .map_err(|e| zerror!("{}: {}", dst_addr, e))?; - - let dst_addr = stream - .peer_addr() - .map_err(|e| zerror!("{}: {}", dst_addr, e))?; - - Ok((stream, src_addr, dst_addr)) - } - - async fn new_listener_inner( - &self, - addr: &SocketAddr, - iface: Option<&str>, - ) -> ZResult<(TcpListener, SocketAddr)> { - let socket = match addr { - SocketAddr::V4(_) => TcpSocket::new_v4(), - SocketAddr::V6(_) => TcpSocket::new_v6(), - }?; - - if let Some(iface) = iface { - zenoh_util::net::set_bind_to_device_tcp_socket(&socket, iface)?; - } - - // Build a TcpListener from TcpSocket - // https://docs.rs/tokio/latest/tokio/net/struct.TcpSocket.html - socket.set_reuseaddr(true)?; - socket.bind(*addr).map_err(|e| zerror!("{}: {}", addr, e))?; - // backlog (the maximum number of pending connections are queued): 1024 - let listener = socket - .listen(1024) - .map_err(|e| zerror!("{}: {}", addr, e))?; - - let local_addr = listener - .local_addr() - .map_err(|e| zerror!("{}: {}", addr, e))?; - - Ok((listener, local_addr)) - } -} - #[async_trait] impl LinkManagerUnicastTrait for LinkManagerUnicastTcp { async fn new_link(&self, endpoint: EndPoint) -> ZResult { @@ -314,7 +250,7 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTcp { let mut errs: Vec = vec![]; for da in dst_addrs { - match self.new_link_inner(&da, iface).await { + match TcpSocketUtils::connect(&da, iface).await { Ok((stream, src_addr, dst_addr)) => { let link = Arc::new(LinkUnicastTcp::new(stream, src_addr, dst_addr)); return Ok(LinkUnicast(link)); @@ -343,7 +279,7 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTcp { let mut errs: Vec = vec![]; for da in addrs { - match self.new_listener_inner(&da, iface).await { + match TcpSocketUtils::listen(&da, iface) { Ok((socket, local_addr)) => { // Update the endpoint locator address endpoint = EndPoint::new( From bc22cd1028a98e48ae82720eec4d62e425e3d3e3 Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Wed, 4 Dec 2024 19:15:14 +0100 Subject: [PATCH 02/12] Use TcpSocketUtils to create listener/stream in TLS link --- io/zenoh-links/zenoh-link-tls/src/unicast.rs | 40 ++++++-------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/io/zenoh-links/zenoh-link-tls/src/unicast.rs b/io/zenoh-links/zenoh-link-tls/src/unicast.rs index 046288800e..ecccccb26e 100644 --- a/io/zenoh-links/zenoh-link-tls/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-tls/src/unicast.rs @@ -26,6 +26,7 @@ use x509_parser::prelude::{FromDer, X509Certificate}; use zenoh_core::zasynclock; use zenoh_link_commons::{ get_ip_interface_names, + tcp::TcpSocketUtils, tls::expiration::{LinkCertExpirationManager, LinkWithCertExpiration}, LinkAuthId, LinkAuthType, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, ListenersUnicastIP, NewLinkChannelSender, @@ -324,29 +325,15 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTls { let connector = TlsConnector::from(config); // Initialize the TcpStream - let tcp_stream = TcpStream::connect(addr).await.map_err(|e| { - zerror!( - "Can not create a new TLS link bound to {:?}: {}", - server_name, - e - ) - })?; - - let src_addr = tcp_stream.local_addr().map_err(|e| { - zerror!( - "Can not create a new TLS link bound to {:?}: {}", - server_name, - e - ) - })?; - - let dst_addr = tcp_stream.peer_addr().map_err(|e| { - zerror!( - "Can not create a new TLS link bound to {:?}: {}", - server_name, - e - ) - })?; + // TODO: Add interface binding + let (tcp_stream, src_addr, dst_addr) = + TcpSocketUtils::connect(&addr, None).await.map_err(|e| { + zerror!( + "Can not create a new TLS link bound to {:?}: {}", + server_name, + e + ) + })?; // Initialize the TlsStream let tls_stream = connector @@ -404,13 +391,10 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTls { .map_err(|e| zerror!("Cannot create a new TLS listener on {addr}. {e}"))?; // Initialize the TcpListener - let socket = TcpListener::bind(addr) - .await + // TODO: Add interface bindings + let (socket, local_addr) = TcpSocketUtils::listen(&addr, None) .map_err(|e| zerror!("Can not create a new TLS listener on {}: {}", addr, e))?; - let local_addr = socket - .local_addr() - .map_err(|e| zerror!("Can not create a new TLS listener on {}: {}", addr, e))?; let local_port = local_addr.port(); // Initialize the TlsAcceptor From d85665551d4ecc0ed1da81973f4ee699240ad22e Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Wed, 4 Dec 2024 19:50:54 +0100 Subject: [PATCH 03/12] Change TcpSocketUtils to TcpSocketConfig --- io/zenoh-link-commons/src/tcp.rs | 64 +++++++++++++------- io/zenoh-links/zenoh-link-tcp/src/unicast.rs | 10 ++- io/zenoh-links/zenoh-link-tls/src/unicast.rs | 13 ++-- 3 files changed, 57 insertions(+), 30 deletions(-) diff --git a/io/zenoh-link-commons/src/tcp.rs b/io/zenoh-link-commons/src/tcp.rs index a8e762d44e..37700d799d 100644 --- a/io/zenoh-link-commons/src/tcp.rs +++ b/io/zenoh-link-commons/src/tcp.rs @@ -16,20 +16,28 @@ use std::net::SocketAddr; use tokio::net::{TcpListener, TcpSocket, TcpStream}; use zenoh_result::{zerror, ZResult}; -pub struct TcpSocketUtils; - -impl TcpSocketUtils { - /// Build a new TCP listener bound to `addr` with the given configration parameters - pub fn listen(addr: &SocketAddr, iface: Option<&str>) -> ZResult<(TcpListener, SocketAddr)> { - let socket = match addr { - SocketAddr::V4(_) => TcpSocket::new_v4(), - SocketAddr::V6(_) => TcpSocket::new_v6(), - }?; +pub struct TcpSocketConfig<'a> { + tx_buffer_size: Option, + rx_buffer_size: Option, + iface: Option<&'a str>, +} - if let Some(iface) = iface { - zenoh_util::net::set_bind_to_device_tcp_socket(&socket, iface)?; +impl<'a> TcpSocketConfig<'a> { + pub fn new( + tx_buffer_size: Option, + rx_buffer_size: Option, + iface: Option<&'a str>, + ) -> Self { + Self { + tx_buffer_size, + rx_buffer_size, + iface, } + } + /// Build a new TCPListener bound to `addr` with the given configration parameters + pub fn new_listener(&self, addr: &SocketAddr) -> ZResult<(TcpListener, SocketAddr)> { + let socket = self.socket_with_config(addr)?; // Build a TcpListener from TcpSocket // https://docs.rs/tokio/latest/tokio/net/struct.TcpSocket.html socket.set_reuseaddr(true)?; @@ -47,19 +55,11 @@ impl TcpSocketUtils { } /// Connect to a TCP socket address at `dst_addr` with the given configuration parameters - pub async fn connect( + pub async fn new_link( + &self, dst_addr: &SocketAddr, - iface: Option<&str>, ) -> ZResult<(TcpStream, SocketAddr, SocketAddr)> { - let socket = match dst_addr { - SocketAddr::V4(_) => TcpSocket::new_v4(), - SocketAddr::V6(_) => TcpSocket::new_v6(), - }?; - - if let Some(iface) = iface { - zenoh_util::net::set_bind_to_device_tcp_socket(&socket, iface)?; - } - + let socket = self.socket_with_config(dst_addr)?; // Build a TcpStream from TcpSocket // https://docs.rs/tokio/latest/tokio/net/struct.TcpSocket.html let stream = socket @@ -77,4 +77,24 @@ impl TcpSocketUtils { Ok((stream, src_addr, dst_addr)) } + + /// Creates a TcpSocket with the provided config + fn socket_with_config(&self, addr: &SocketAddr) -> ZResult { + let socket = match addr { + SocketAddr::V4(_) => TcpSocket::new_v4(), + SocketAddr::V6(_) => TcpSocket::new_v6(), + }?; + + if let Some(iface) = self.iface { + zenoh_util::net::set_bind_to_device_tcp_socket(&socket, iface)?; + } + if let Some(size) = self.tx_buffer_size { + socket.set_send_buffer_size(size)?; + } + if let Some(size) = self.rx_buffer_size { + socket.set_recv_buffer_size(size)?; + } + + Ok(socket) + } } diff --git a/io/zenoh-links/zenoh-link-tcp/src/unicast.rs b/io/zenoh-links/zenoh-link-tcp/src/unicast.rs index 4a27fa6fa8..4a317bd876 100644 --- a/io/zenoh-links/zenoh-link-tcp/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-tcp/src/unicast.rs @@ -20,7 +20,7 @@ use tokio::{ }; use tokio_util::sync::CancellationToken; use zenoh_link_commons::{ - get_ip_interface_names, tcp::TcpSocketUtils, LinkAuthId, LinkManagerUnicastTrait, LinkUnicast, + get_ip_interface_names, tcp::TcpSocketConfig, LinkAuthId, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, ListenersUnicastIP, NewLinkChannelSender, BIND_INTERFACE, }; use zenoh_protocol::{ @@ -246,11 +246,13 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTcp { async fn new_link(&self, endpoint: EndPoint) -> ZResult { let dst_addrs = get_tcp_addrs(endpoint.address()).await?; let config = endpoint.config(); + let iface = config.get(BIND_INTERFACE); + let socket_config = TcpSocketConfig::new(None, None, iface); let mut errs: Vec = vec![]; for da in dst_addrs { - match TcpSocketUtils::connect(&da, iface).await { + match socket_config.new_link(&da).await { Ok((stream, src_addr, dst_addr)) => { let link = Arc::new(LinkUnicastTcp::new(stream, src_addr, dst_addr)); return Ok(LinkUnicast(link)); @@ -275,11 +277,13 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTcp { async fn new_listener(&self, mut endpoint: EndPoint) -> ZResult { let addrs = get_tcp_addrs(endpoint.address()).await?; let config = endpoint.config(); + let iface = config.get(BIND_INTERFACE); + let socket_config = TcpSocketConfig::new(None, None, iface); let mut errs: Vec = vec![]; for da in addrs { - match TcpSocketUtils::listen(&da, iface) { + match socket_config.new_listener(&da) { Ok((socket, local_addr)) => { // Update the endpoint locator address endpoint = EndPoint::new( diff --git a/io/zenoh-links/zenoh-link-tls/src/unicast.rs b/io/zenoh-links/zenoh-link-tls/src/unicast.rs index ecccccb26e..688ca079b9 100644 --- a/io/zenoh-links/zenoh-link-tls/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-tls/src/unicast.rs @@ -26,7 +26,7 @@ use x509_parser::prelude::{FromDer, X509Certificate}; use zenoh_core::zasynclock; use zenoh_link_commons::{ get_ip_interface_names, - tcp::TcpSocketUtils, + tcp::TcpSocketConfig, tls::expiration::{LinkCertExpirationManager, LinkWithCertExpiration}, LinkAuthId, LinkAuthType, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, ListenersUnicastIP, NewLinkChannelSender, @@ -324,10 +324,11 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTls { let config = Arc::new(client_config.client_config); let connector = TlsConnector::from(config); - // Initialize the TcpStream // TODO: Add interface binding + let socket_config = TcpSocketConfig::new(None, None, None); + // Initialize the TcpStream let (tcp_stream, src_addr, dst_addr) = - TcpSocketUtils::connect(&addr, None).await.map_err(|e| { + socket_config.new_link(&addr).await.map_err(|e| { zerror!( "Can not create a new TLS link bound to {:?}: {}", server_name, @@ -390,9 +391,11 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTls { .await .map_err(|e| zerror!("Cannot create a new TLS listener on {addr}. {e}"))?; + // TODO: Add interface binding + let socket_config = TcpSocketConfig::new(None, None, None); // Initialize the TcpListener - // TODO: Add interface bindings - let (socket, local_addr) = TcpSocketUtils::listen(&addr, None) + let (socket, local_addr) = socket_config + .new_listener(&addr) .map_err(|e| zerror!("Can not create a new TLS listener on {}: {}", addr, e))?; let local_port = local_addr.port(); From 59102bee334a5887f9ec11cfb30d16a226dde875 Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Wed, 4 Dec 2024 20:29:52 +0100 Subject: [PATCH 04/12] Add TCP buffer size endpoint parameters and parsing --- io/zenoh-link-commons/src/lib.rs | 2 + io/zenoh-links/zenoh-link-tcp/src/lib.rs | 1 + io/zenoh-links/zenoh-link-tcp/src/unicast.rs | 20 ++++--- io/zenoh-links/zenoh-link-tcp/src/utils.rs | 55 ++++++++++++++++++++ io/zenoh-links/zenoh-link-tls/src/unicast.rs | 15 +++--- io/zenoh-links/zenoh-link-tls/src/utils.rs | 54 ++++++++++++++++--- 6 files changed, 124 insertions(+), 23 deletions(-) create mode 100644 io/zenoh-links/zenoh-link-tcp/src/utils.rs diff --git a/io/zenoh-link-commons/src/lib.rs b/io/zenoh-link-commons/src/lib.rs index b33c527fde..93500e7a80 100644 --- a/io/zenoh-link-commons/src/lib.rs +++ b/io/zenoh-link-commons/src/lib.rs @@ -45,6 +45,8 @@ use zenoh_result::ZResult; /*************************************/ pub const BIND_INTERFACE: &str = "iface"; +pub const TCP_TX_BUFFER_SIZE: &str = "tcp_buffer_tx"; +pub const TCP_RX_BUFFER_SIZE: &str = "tcp_buffer_rx"; #[derive(Clone, Debug, Serialize, Hash, PartialEq, Eq)] pub struct Link { diff --git a/io/zenoh-links/zenoh-link-tcp/src/lib.rs b/io/zenoh-links/zenoh-link-tcp/src/lib.rs index 0654943f4f..f9af9885ae 100644 --- a/io/zenoh-links/zenoh-link-tcp/src/lib.rs +++ b/io/zenoh-links/zenoh-link-tcp/src/lib.rs @@ -29,6 +29,7 @@ use zenoh_protocol::{ use zenoh_result::{zerror, ZResult}; mod unicast; +mod utils; pub use unicast::*; // Default MTU (TCP PDU) in bytes. diff --git a/io/zenoh-links/zenoh-link-tcp/src/unicast.rs b/io/zenoh-links/zenoh-link-tcp/src/unicast.rs index 4a317bd876..d61bf515dd 100644 --- a/io/zenoh-links/zenoh-link-tcp/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-tcp/src/unicast.rs @@ -21,7 +21,7 @@ use tokio::{ use tokio_util::sync::CancellationToken; use zenoh_link_commons::{ get_ip_interface_names, tcp::TcpSocketConfig, LinkAuthId, LinkManagerUnicastTrait, LinkUnicast, - LinkUnicastTrait, ListenersUnicastIP, NewLinkChannelSender, BIND_INTERFACE, + LinkUnicastTrait, ListenersUnicastIP, NewLinkChannelSender, }; use zenoh_protocol::{ core::{EndPoint, Locator}, @@ -29,9 +29,9 @@ use zenoh_protocol::{ }; use zenoh_result::{bail, zerror, Error as ZError, ZResult}; -use super::{ - get_tcp_addrs, TCP_ACCEPT_THROTTLE_TIME, TCP_DEFAULT_MTU, TCP_LINGER_TIMEOUT, - TCP_LOCATOR_PREFIX, +use crate::{ + get_tcp_addrs, utils::TcpLinkConfig, TCP_ACCEPT_THROTTLE_TIME, TCP_DEFAULT_MTU, + TCP_LINGER_TIMEOUT, TCP_LOCATOR_PREFIX, }; pub struct LinkUnicastTcp { @@ -247,8 +247,12 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTcp { let dst_addrs = get_tcp_addrs(endpoint.address()).await?; let config = endpoint.config(); - let iface = config.get(BIND_INTERFACE); - let socket_config = TcpSocketConfig::new(None, None, iface); + let link_config = TcpLinkConfig::new(&config)?; + let socket_config = TcpSocketConfig::new( + link_config.tx_buffer_size, + link_config.rx_buffer_size, + link_config.bind_iface, + ); let mut errs: Vec = vec![]; for da in dst_addrs { @@ -278,8 +282,8 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTcp { let addrs = get_tcp_addrs(endpoint.address()).await?; let config = endpoint.config(); - let iface = config.get(BIND_INTERFACE); - let socket_config = TcpSocketConfig::new(None, None, iface); + let link_config = TcpLinkConfig::new(&config)?; + let socket_config: TcpSocketConfig<'_> = link_config.into(); let mut errs: Vec = vec![]; for da in addrs { diff --git a/io/zenoh-links/zenoh-link-tcp/src/utils.rs b/io/zenoh-links/zenoh-link-tcp/src/utils.rs new file mode 100644 index 0000000000..4ee3c7bb00 --- /dev/null +++ b/io/zenoh-links/zenoh-link-tcp/src/utils.rs @@ -0,0 +1,55 @@ +// +// Copyright (c) 2024 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// +use zenoh_link_commons::{ + tcp::TcpSocketConfig, BIND_INTERFACE, TCP_RX_BUFFER_SIZE, TCP_TX_BUFFER_SIZE, +}; +use zenoh_protocol::core::Config; +use zenoh_result::{zerror, ZResult}; + +pub(crate) struct TcpLinkConfig<'a> { + pub(crate) rx_buffer_size: Option, + pub(crate) tx_buffer_size: Option, + pub(crate) bind_iface: Option<&'a str>, +} + +impl<'a> TcpLinkConfig<'a> { + pub(crate) fn new(config: &'a Config) -> ZResult { + let mut tcp_config = Self { + rx_buffer_size: None, + tx_buffer_size: None, + bind_iface: config.get(BIND_INTERFACE), + }; + + if let Some(size) = config.get(TCP_RX_BUFFER_SIZE) { + tcp_config.rx_buffer_size = Some( + size.parse() + .map_err(|_| zerror!("Unknown TCP read buffer size argument: {}", size))?, + ); + }; + if let Some(size) = config.get(TCP_TX_BUFFER_SIZE) { + tcp_config.tx_buffer_size = Some( + size.parse() + .map_err(|_| zerror!("Unknown TCP write buffer size argument: {}", size))?, + ); + }; + + Ok(tcp_config) + } +} + +impl<'a> From> for TcpSocketConfig<'a> { + fn from(value: TcpLinkConfig<'a>) -> Self { + Self::new(value.tx_buffer_size, value.rx_buffer_size, value.bind_iface) + } +} diff --git a/io/zenoh-links/zenoh-link-tls/src/unicast.rs b/io/zenoh-links/zenoh-link-tls/src/unicast.rs index 688ca079b9..62250d354a 100644 --- a/io/zenoh-links/zenoh-link-tls/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-tls/src/unicast.rs @@ -26,7 +26,6 @@ use x509_parser::prelude::{FromDer, X509Certificate}; use zenoh_core::zasynclock; use zenoh_link_commons::{ get_ip_interface_names, - tcp::TcpSocketConfig, tls::expiration::{LinkCertExpirationManager, LinkWithCertExpiration}, LinkAuthId, LinkAuthType, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, ListenersUnicastIP, NewLinkChannelSender, @@ -324,11 +323,12 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTls { let config = Arc::new(client_config.client_config); let connector = TlsConnector::from(config); - // TODO: Add interface binding - let socket_config = TcpSocketConfig::new(None, None, None); // Initialize the TcpStream - let (tcp_stream, src_addr, dst_addr) = - socket_config.new_link(&addr).await.map_err(|e| { + let (tcp_stream, src_addr, dst_addr) = client_config + .tcp_socket_config + .new_link(&addr) + .await + .map_err(|e| { zerror!( "Can not create a new TLS link bound to {:?}: {}", server_name, @@ -391,10 +391,9 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTls { .await .map_err(|e| zerror!("Cannot create a new TLS listener on {addr}. {e}"))?; - // TODO: Add interface binding - let socket_config = TcpSocketConfig::new(None, None, None); // Initialize the TcpListener - let (socket, local_addr) = socket_config + let (socket, local_addr) = tls_server_config + .tcp_socket_config .new_listener(&addr) .map_err(|e| zerror!("Can not create a new TLS listener on {}: {}", addr, e))?; diff --git a/io/zenoh-links/zenoh-link-tls/src/utils.rs b/io/zenoh-links/zenoh-link-tls/src/utils.rs index 74e7cc9e51..1b747a6ad1 100644 --- a/io/zenoh-links/zenoh-link-tls/src/utils.rs +++ b/io/zenoh-links/zenoh-link-tls/src/utils.rs @@ -31,7 +31,10 @@ use rustls_pki_types::ServerName; use secrecy::ExposeSecret; use webpki::anchor_from_trusted_cert; use zenoh_config::Config as ZenohConfig; -use zenoh_link_commons::{tls::WebPkiVerifierAnyServerName, ConfigurationInspector}; +use zenoh_link_commons::{ + tcp::TcpSocketConfig, tls::WebPkiVerifierAnyServerName, ConfigurationInspector, + TCP_RX_BUFFER_SIZE, TCP_TX_BUFFER_SIZE, +}; use zenoh_protocol::core::{ endpoint::{Address, Config}, parameters, @@ -154,14 +157,15 @@ impl ConfigurationInspector for TlsConfigurator { } } -pub(crate) struct TlsServerConfig { +pub(crate) struct TlsServerConfig<'a> { pub(crate) server_config: ServerConfig, pub(crate) tls_handshake_timeout: Duration, pub(crate) tls_close_link_on_expiration: bool, + pub(crate) tcp_socket_config: TcpSocketConfig<'a>, } -impl TlsServerConfig { - pub async fn new(config: &Config<'_>) -> ZResult { +impl<'a> TlsServerConfig<'a> { + pub async fn new(config: &Config<'a>) -> ZResult { let tls_server_client_auth: bool = match config.get(TLS_ENABLE_MTLS) { Some(s) => s .parse() @@ -241,10 +245,27 @@ impl TlsServerConfig { .unwrap_or(config::TLS_HANDSHAKE_TIMEOUT_MS_DEFAULT), ); + let mut tcp_rx_buffer_size = None; + if let Some(size) = config.get(TCP_RX_BUFFER_SIZE) { + tcp_rx_buffer_size = Some( + size.parse() + .map_err(|_| zerror!("Unknown TCP read buffer size argument: {}", size))?, + ); + }; + let mut tcp_tx_buffer_size = None; + if let Some(size) = config.get(TCP_TX_BUFFER_SIZE) { + tcp_tx_buffer_size = Some( + size.parse() + .map_err(|_| zerror!("Unknown TCP write buffer size argument: {}", size))?, + ); + }; + Ok(TlsServerConfig { server_config: sc, tls_handshake_timeout, tls_close_link_on_expiration, + // TODO: add interface binding + tcp_socket_config: TcpSocketConfig::new(tcp_tx_buffer_size, tcp_rx_buffer_size, None), }) } @@ -269,13 +290,14 @@ impl TlsServerConfig { } } -pub(crate) struct TlsClientConfig { +pub(crate) struct TlsClientConfig<'a> { pub(crate) client_config: ClientConfig, pub(crate) tls_close_link_on_expiration: bool, + pub(crate) tcp_socket_config: TcpSocketConfig<'a>, } -impl TlsClientConfig { - pub async fn new(config: &Config<'_>) -> ZResult { +impl<'a> TlsClientConfig<'a> { + pub async fn new(config: &Config<'a>) -> ZResult { let tls_client_server_auth: bool = match config.get(TLS_ENABLE_MTLS) { Some(s) => s .parse() @@ -386,9 +408,27 @@ impl TlsClientConfig { .with_no_client_auth() } }; + + let mut tcp_rx_buffer_size = None; + if let Some(size) = config.get(TCP_RX_BUFFER_SIZE) { + tcp_rx_buffer_size = Some( + size.parse() + .map_err(|_| zerror!("Unknown TCP read buffer size argument: {}", size))?, + ); + }; + let mut tcp_tx_buffer_size = None; + if let Some(size) = config.get(TCP_TX_BUFFER_SIZE) { + tcp_tx_buffer_size = Some( + size.parse() + .map_err(|_| zerror!("Unknown TCP write buffer size argument: {}", size))?, + ); + }; + Ok(TlsClientConfig { client_config: cc, tls_close_link_on_expiration, + // TODO: add interface binding + tcp_socket_config: TcpSocketConfig::new(tcp_tx_buffer_size, tcp_rx_buffer_size, None), }) } From 36133a28fdf6c44e3728dfba656ad30a1a9f414a Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Wed, 4 Dec 2024 21:04:43 +0100 Subject: [PATCH 05/12] Add TCP buffer sizes to config file --- Cargo.lock | 1 + DEFAULT_CONFIG.json5 | 6 +++++ commons/zenoh-config/src/lib.rs | 4 +++ io/zenoh-link/src/lib.rs | 13 +++++++++- io/zenoh-links/zenoh-link-tcp/Cargo.toml | 1 + io/zenoh-links/zenoh-link-tcp/src/lib.rs | 1 + io/zenoh-links/zenoh-link-tcp/src/utils.rs | 29 ++++++++++++++++++++-- io/zenoh-links/zenoh-link-tls/src/utils.rs | 13 ++++++++++ 8 files changed, 65 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0129941564..a06bbf9c94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5335,6 +5335,7 @@ dependencies = [ "tokio", "tokio-util", "tracing", + "zenoh-config", "zenoh-core", "zenoh-link-commons", "zenoh-protocol", diff --git a/DEFAULT_CONFIG.json5 b/DEFAULT_CONFIG.json5 index 8d140ee9ba..a26d6da65d 100644 --- a/DEFAULT_CONFIG.json5 +++ b/DEFAULT_CONFIG.json5 @@ -474,6 +474,12 @@ // note that mTLS (client authentication) is required for a listener to disconnect a client on expiration close_link_on_expiration: false, }, + /// Optional configration for TCP system buffers sizes. Applies to TCP and TLS links. + /// + /// Configure TCP read buffer size (bytes) + // tcp_rx_buffer: 123456, + /// Configure TCP write buffer size (bytes) + // tcp_tx_buffer: 123456, }, /// Shared memory configuration. /// NOTE: shared memory can be used only if zenoh is compiled with "shared-memory" feature, otherwise diff --git a/commons/zenoh-config/src/lib.rs b/commons/zenoh-config/src/lib.rs index 51c851b3ab..4f37f1431b 100644 --- a/commons/zenoh-config/src/lib.rs +++ b/commons/zenoh-config/src/lib.rs @@ -505,6 +505,10 @@ validated_struct::validator! { UnixPipeConf { file_access_mask: Option }, + /// Configure TCP read buffer size + pub tcp_rx_buffer: Option, + /// Configure TCP write buffer size + pub tcp_tx_buffer: Option, }, pub shared_memory: ShmConf { diff --git a/io/zenoh-link/src/lib.rs b/io/zenoh-link/src/lib.rs index b092aaf9d6..d621182b5b 100644 --- a/io/zenoh-link/src/lib.rs +++ b/io/zenoh-link/src/lib.rs @@ -34,7 +34,9 @@ use zenoh_link_serial::{LinkManagerUnicastSerial, SerialLocatorInspector, SERIAL #[cfg(feature = "transport_tcp")] pub use zenoh_link_tcp as tcp; #[cfg(feature = "transport_tcp")] -use zenoh_link_tcp::{LinkManagerUnicastTcp, TcpLocatorInspector, TCP_LOCATOR_PREFIX}; +use zenoh_link_tcp::{ + LinkManagerUnicastTcp, TcpConfigurator, TcpLocatorInspector, TCP_LOCATOR_PREFIX, +}; #[cfg(feature = "transport_tls")] pub use zenoh_link_tls as tls; #[cfg(feature = "transport_tls")] @@ -172,6 +174,8 @@ impl LocatorInspector { } #[derive(Default)] pub struct LinkConfigurator { + #[cfg(feature = "transport_tcp")] + tcp_inspector: TcpConfigurator, #[cfg(feature = "transport_quic")] quic_inspector: QuicConfigurator, #[cfg(feature = "transport_tls")] @@ -199,6 +203,13 @@ impl LinkConfigurator { errors.insert(proto, e); } }; + #[cfg(feature = "transport_tcp")] + { + insert_config( + TCP_LOCATOR_PREFIX.into(), + self.tcp_inspector.inspect_config(config), + ); + } #[cfg(feature = "transport_quic")] { insert_config( diff --git a/io/zenoh-links/zenoh-link-tcp/Cargo.toml b/io/zenoh-links/zenoh-link-tcp/Cargo.toml index 8a631bdfbc..457aac78eb 100644 --- a/io/zenoh-links/zenoh-link-tcp/Cargo.toml +++ b/io/zenoh-links/zenoh-link-tcp/Cargo.toml @@ -30,6 +30,7 @@ socket2 = { workspace = true } tokio = { workspace = true, features = ["net", "io-util", "rt", "time"] } tokio-util = { workspace = true, features = ["rt"] } tracing = {workspace = true} +zenoh-config = { workspace = true } zenoh-core = { workspace = true } zenoh-link-commons = { workspace = true } zenoh-protocol = { workspace = true } diff --git a/io/zenoh-links/zenoh-link-tcp/src/lib.rs b/io/zenoh-links/zenoh-link-tcp/src/lib.rs index f9af9885ae..bd642ece83 100644 --- a/io/zenoh-links/zenoh-link-tcp/src/lib.rs +++ b/io/zenoh-links/zenoh-link-tcp/src/lib.rs @@ -31,6 +31,7 @@ use zenoh_result::{zerror, ZResult}; mod unicast; mod utils; pub use unicast::*; +pub use utils::TcpConfigurator; // Default MTU (TCP PDU) in bytes. // NOTE: Since TCP is a byte-stream oriented transport, theoretically it has diff --git a/io/zenoh-links/zenoh-link-tcp/src/utils.rs b/io/zenoh-links/zenoh-link-tcp/src/utils.rs index 4ee3c7bb00..4969693193 100644 --- a/io/zenoh-links/zenoh-link-tcp/src/utils.rs +++ b/io/zenoh-links/zenoh-link-tcp/src/utils.rs @@ -11,12 +11,37 @@ // Contributors: // ZettaScale Zenoh Team, // +use zenoh_config::Config as ZenohConfig; use zenoh_link_commons::{ - tcp::TcpSocketConfig, BIND_INTERFACE, TCP_RX_BUFFER_SIZE, TCP_TX_BUFFER_SIZE, + tcp::TcpSocketConfig, ConfigurationInspector, BIND_INTERFACE, TCP_RX_BUFFER_SIZE, + TCP_TX_BUFFER_SIZE, }; -use zenoh_protocol::core::Config; +use zenoh_protocol::core::{parameters, Config}; use zenoh_result::{zerror, ZResult}; +#[derive(Default, Clone, Copy, Debug)] +pub struct TcpConfigurator; + +impl ConfigurationInspector for TcpConfigurator { + fn inspect_config(&self, config: &ZenohConfig) -> ZResult { + let mut ps: Vec<(&str, &str)> = vec![]; + let c = config.transport().link(); + + let rx_buffer_size; + if let Some(size) = c.tcp_rx_buffer { + rx_buffer_size = size.to_string(); + ps.push((TCP_RX_BUFFER_SIZE, &rx_buffer_size)); + } + let tx_buffer_size; + if let Some(size) = c.tcp_tx_buffer { + tx_buffer_size = size.to_string(); + ps.push((TCP_TX_BUFFER_SIZE, &tx_buffer_size)); + } + + Ok(parameters::from_iter(ps.drain(..))) + } +} + pub(crate) struct TcpLinkConfig<'a> { pub(crate) rx_buffer_size: Option, pub(crate) tx_buffer_size: Option, diff --git a/io/zenoh-links/zenoh-link-tls/src/utils.rs b/io/zenoh-links/zenoh-link-tls/src/utils.rs index 1b747a6ad1..e85be4573f 100644 --- a/io/zenoh-links/zenoh-link-tls/src/utils.rs +++ b/io/zenoh-links/zenoh-link-tls/src/utils.rs @@ -153,6 +153,19 @@ impl ConfigurationInspector for TlsConfigurator { false => ps.push((TLS_CLOSE_LINK_ON_EXPIRATION, "false")), } + let link_c = config.transport().link(); + let rx_buffer_size; + if let Some(size) = link_c.tcp_rx_buffer { + rx_buffer_size = size.to_string(); + ps.push((TCP_RX_BUFFER_SIZE, &rx_buffer_size)); + } + + let tx_buffer_size; + if let Some(size) = link_c.tcp_tx_buffer { + tx_buffer_size = size.to_string(); + ps.push((TCP_TX_BUFFER_SIZE, &tx_buffer_size)); + } + Ok(parameters::from_iter(ps.drain(..))) } } From 5b609ff973abb09b5ca9d43167708cb2aff0fd98 Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Wed, 4 Dec 2024 21:07:51 +0100 Subject: [PATCH 06/12] Rename endpoint parameters to match config file --- io/zenoh-link-commons/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io/zenoh-link-commons/src/lib.rs b/io/zenoh-link-commons/src/lib.rs index 93500e7a80..ed6f5e72f8 100644 --- a/io/zenoh-link-commons/src/lib.rs +++ b/io/zenoh-link-commons/src/lib.rs @@ -45,8 +45,8 @@ use zenoh_result::ZResult; /*************************************/ pub const BIND_INTERFACE: &str = "iface"; -pub const TCP_TX_BUFFER_SIZE: &str = "tcp_buffer_tx"; -pub const TCP_RX_BUFFER_SIZE: &str = "tcp_buffer_rx"; +pub const TCP_TX_BUFFER_SIZE: &str = "tcp_tx_buffer"; +pub const TCP_RX_BUFFER_SIZE: &str = "tcp_rx_buffer"; #[derive(Clone, Debug, Serialize, Hash, PartialEq, Eq)] pub struct Link { From 8c47bda7612b05c4910f3a3f1644e9bda944e96b Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Wed, 4 Dec 2024 21:11:02 +0100 Subject: [PATCH 07/12] Correct typo --- DEFAULT_CONFIG.json5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEFAULT_CONFIG.json5 b/DEFAULT_CONFIG.json5 index a26d6da65d..2b725f961c 100644 --- a/DEFAULT_CONFIG.json5 +++ b/DEFAULT_CONFIG.json5 @@ -474,7 +474,7 @@ // note that mTLS (client authentication) is required for a listener to disconnect a client on expiration close_link_on_expiration: false, }, - /// Optional configration for TCP system buffers sizes. Applies to TCP and TLS links. + /// Optional configuration for TCP system buffers sizes. Applies to TCP and TLS links. /// /// Configure TCP read buffer size (bytes) // tcp_rx_buffer: 123456, From 04fe336605aea2c4b7f34aa7808ec84f257fbee5 Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Wed, 4 Dec 2024 21:13:51 +0100 Subject: [PATCH 08/12] Fix more typos --- io/zenoh-link-commons/src/tcp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io/zenoh-link-commons/src/tcp.rs b/io/zenoh-link-commons/src/tcp.rs index 37700d799d..db7da4d562 100644 --- a/io/zenoh-link-commons/src/tcp.rs +++ b/io/zenoh-link-commons/src/tcp.rs @@ -35,7 +35,7 @@ impl<'a> TcpSocketConfig<'a> { } } - /// Build a new TCPListener bound to `addr` with the given configration parameters + /// Build a new TCPListener bound to `addr` with the given configuration parameters pub fn new_listener(&self, addr: &SocketAddr) -> ZResult<(TcpListener, SocketAddr)> { let socket = self.socket_with_config(addr)?; // Build a TcpListener from TcpSocket From dfb110b69e9d5f47cf36351512479215b000f5d7 Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Thu, 5 Dec 2024 11:50:30 +0100 Subject: [PATCH 09/12] Remove unused cargo dependency --- Cargo.lock | 1 - io/zenoh-links/zenoh-link-tcp/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a06bbf9c94..2ac3891f17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5340,7 +5340,6 @@ dependencies = [ "zenoh-link-commons", "zenoh-protocol", "zenoh-result", - "zenoh-util", ] [[package]] diff --git a/io/zenoh-links/zenoh-link-tcp/Cargo.toml b/io/zenoh-links/zenoh-link-tcp/Cargo.toml index 457aac78eb..c6bce930ea 100644 --- a/io/zenoh-links/zenoh-link-tcp/Cargo.toml +++ b/io/zenoh-links/zenoh-link-tcp/Cargo.toml @@ -35,4 +35,3 @@ zenoh-core = { workspace = true } zenoh-link-commons = { workspace = true } zenoh-protocol = { workspace = true } zenoh-result = { workspace = true } -zenoh-util = { workspace = true } From 0e863e265c07c6bc8691930c240f19a92d863f36 Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Thu, 5 Dec 2024 12:46:51 +0100 Subject: [PATCH 10/12] Add TCP buffer sizes config tests --- zenoh/tests/tcp_buffers.rs | 89 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 zenoh/tests/tcp_buffers.rs diff --git a/zenoh/tests/tcp_buffers.rs b/zenoh/tests/tcp_buffers.rs new file mode 100644 index 0000000000..22c7e40f06 --- /dev/null +++ b/zenoh/tests/tcp_buffers.rs @@ -0,0 +1,89 @@ +// +// Copyright (c) 2024 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// + +use zenoh::{Config, Wait}; + +#[test] +fn buffer_size_config() { + let mut config = Config::default(); + config + .insert_json5( + "transport/link", + r#" + { + tcp_tx_buffer: 65000, + tcp_rx_buffer: 65000, + } + "#, + ) + .unwrap(); + + config + .insert_json5("listen/endpoints", r#"["tcp/[::]:0"]"#) + .unwrap(); + + zenoh::open(config).wait().unwrap(); +} + +#[test] +fn buffer_size_endpoint() { + let mut config = Config::default(); + config + .insert_json5( + "listen/endpoints", + r#"["tcp/[::]:0#tcp_tx_buffer=65000;tcp_rx_buffer=65000"]"#, + ) + .unwrap(); + + zenoh::open(config).wait().unwrap(); +} + +#[test] +#[should_panic(expected = "Can not create a new TCP listener")] +fn buffer_size_config_override() { + let mut config = Config::default(); + config + .insert_json5( + "transport/link", + r#" + { + tcp_tx_buffer: 0, + tcp_rx_buffer: 0, + } + "#, + ) + .unwrap(); + + config + .insert_json5( + "listen/endpoints", + r#"["tcp/[::]:0#tcp_tx_buffer=65000;tcp_rx_buffer=65000"]"#, + ) + .unwrap(); + + zenoh::open(config).wait().unwrap(); +} + +#[test] +#[should_panic(expected = "Can not create a new TCP listener")] +fn listen_zero_buffers() { + let mut config = Config::default(); + config + .insert_json5( + "listen/endpoints", + r#"["tcp/[::]:0#tcp_tx_buffer=0;tcp_rx_buffer=0"]"#, + ) + .unwrap(); + zenoh::open(config).wait().unwrap(); +} From 8e5904da3fc370defb657aa9b592d13bd4132b1c Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Thu, 5 Dec 2024 13:20:38 +0100 Subject: [PATCH 11/12] Allow zero-buffer tests to panic only on mac --- zenoh/tests/tcp_buffers.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/zenoh/tests/tcp_buffers.rs b/zenoh/tests/tcp_buffers.rs index 22c7e40f06..8794c5e4a9 100644 --- a/zenoh/tests/tcp_buffers.rs +++ b/zenoh/tests/tcp_buffers.rs @@ -49,6 +49,19 @@ fn buffer_size_endpoint() { zenoh::open(config).wait().unwrap(); } +#[cfg(target_os = "macos")] +#[test] +#[should_panic(expected = "Can not create a new TCP listener")] +fn buffer_size_override() { + buffer_size_config_override(); +} + +#[cfg(not(target_os = "macos"))] +#[test] +fn buffer_size_override() { + buffer_size_config_override(); +} + #[test] #[should_panic(expected = "Can not create a new TCP listener")] fn buffer_size_config_override() { @@ -75,8 +88,19 @@ fn buffer_size_config_override() { zenoh::open(config).wait().unwrap(); } +#[cfg(target_os = "macos")] #[test] #[should_panic(expected = "Can not create a new TCP listener")] +fn buffer_size_zero() { + listen_zero_buffers(); +} + +#[cfg(not(target_os = "macos"))] +#[test] +fn buffer_size_zero() { + listen_zero_buffers(); +} + fn listen_zero_buffers() { let mut config = Config::default(); config From 2eabe99b92299151ab6f3fba8223b971cca8294f Mon Sep 17 00:00:00 2001 From: Oussama Teffahi Date: Thu, 5 Dec 2024 14:21:14 +0100 Subject: [PATCH 12/12] Remove test headers from function --- zenoh/tests/tcp_buffers.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/zenoh/tests/tcp_buffers.rs b/zenoh/tests/tcp_buffers.rs index 8794c5e4a9..8d75682507 100644 --- a/zenoh/tests/tcp_buffers.rs +++ b/zenoh/tests/tcp_buffers.rs @@ -62,8 +62,6 @@ fn buffer_size_override() { buffer_size_config_override(); } -#[test] -#[should_panic(expected = "Can not create a new TCP listener")] fn buffer_size_config_override() { let mut config = Config::default(); config