diff --git a/Cargo.toml b/Cargo.toml index b566565..c6074fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,5 +32,6 @@ socket2 = { version = "0.4.4" } nix = { version = "0.24.2" } num_cpus = { version = "1.13" } +[target.'cfg(target_os="linux")'.dependencies] #tokio-udt = { git = "https://github.com/amatissart/tokio-udt/", rev="f9fdae" } tokio-udt = "0.1.0-alpha.5" diff --git a/src/link/rendezvous/client.rs b/src/link/rendezvous/client.rs index f4b72de..a33ddd4 100644 --- a/src/link/rendezvous/client.rs +++ b/src/link/rendezvous/client.rs @@ -1,7 +1,7 @@ use crate::{ crypto::{Identity, KeyCard}, link::rendezvous::{ClientSettings, Request, Response, ShardId}, - net::traits::{ConnectSettings, Connect}, + net::traits::{Connect, ConnectSettings}, }; use doomstack::{here, Doom, ResultExt, Top}; diff --git a/src/link/rendezvous/listener.rs b/src/link/rendezvous/listener.rs index cfd3012..081add6 100644 --- a/src/link/rendezvous/listener.rs +++ b/src/link/rendezvous/listener.rs @@ -20,13 +20,12 @@ use tokio::sync::{ mpsc::{Receiver, Sender}, }; -use tokio_udt::UdtListener; - type Outlet = Receiver<(Identity, SecureConnection)>; pub(crate) enum RawListener { Tcp(TcpListener), - Udt(UdtListener), + #[cfg(target_os = "linux")] + Udt(tokio_udt::UdtListener), } pub struct Listener { @@ -57,11 +56,14 @@ impl Listener { let port = listener.local_addr().unwrap().port(); (RawListener::Tcp(listener), port) } + #[cfg(target_os = "linux")] TransportProtocol::UDT(ref config) => { - let listener = - UdtListener::bind((Ipv4Addr::UNSPECIFIED, 0).into(), Some(config.clone())) - .await - .unwrap(); + let listener = tokio_udt::UdtListener::bind( + (Ipv4Addr::UNSPECIFIED, 0).into(), + Some(config.clone()), + ) + .await + .unwrap(); let port = listener.local_addr().unwrap().port(); (RawListener::Udt(listener), port) } @@ -101,6 +103,7 @@ impl Listener { Ok((stream.into(), addr)) }) } + #[cfg(target_os = "linux")] RawListener::Udt(ref udt_listener) => udt_listener .accept() .await diff --git a/src/link/rendezvous/server.rs b/src/link/rendezvous/server.rs index 588bf21..db89cbe 100644 --- a/src/link/rendezvous/server.rs +++ b/src/link/rendezvous/server.rs @@ -17,7 +17,6 @@ use std::{ }; use tokio::{io, net::TcpListener}; -use tokio_udt::UdtListener; pub struct Server { _fuse: Fuse, @@ -64,8 +63,9 @@ impl Server { let listener = { let result = match settings.connect.transport { TransportProtocol::TCP => TcpListener::bind(address).await.map(RawListener::Tcp), + #[cfg(target_os = "linux")] TransportProtocol::UDT(ref config) => { - UdtListener::bind(address, Some(config.clone())) + tokio_udt::UdtListener::bind(address, Some(config.clone())) .await .map(RawListener::Udt) } @@ -96,6 +96,7 @@ impl Server { .accept() .await .map(|(stream, address)| (stream.into(), address)), + #[cfg(target_os = "linux")] RawListener::Udt(ref udt_listener) => udt_listener .accept() .await diff --git a/src/link/test/tests.rs b/src/link/test/tests.rs index c8e1fe2..8fbb0cf 100644 --- a/src/link/test/tests.rs +++ b/src/link/test/tests.rs @@ -7,7 +7,7 @@ mod context { }, net::{ test::{System as NetSystem, TestConnector}, - traits::{ConnectSettings, Connect}, + traits::{Connect, ConnectSettings}, Connector, Listener, PlainConnection, }, time::test::join, diff --git a/src/net/mod.rs b/src/net/mod.rs index 7dd14c6..df18523 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -16,13 +16,15 @@ mod session_connector; mod session_control; mod session_listener; mod socket; -mod udt; mod unit_receiver; mod unit_sender; pub mod sockets; pub mod traits; +#[cfg(target_os = "linux")] +mod udt; + #[cfg(any(test, feature = "test_utilities"))] pub mod test; diff --git a/src/net/test/test_connector.rs b/src/net/test/test_connector.rs index 0e3478d..49fccba 100644 --- a/src/net/test/test_connector.rs +++ b/src/net/test/test_connector.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use crate::{ crypto::{Identity, KeyChain}, net::{ - traits::{ConnectSettings, Connect}, + traits::{Connect, ConnectSettings}, Connector, SecureConnection, }, }; diff --git a/src/net/traits/connect.rs b/src/net/traits/connect.rs index ea56ae1..80fdbb9 100644 --- a/src/net/traits/connect.rs +++ b/src/net/traits/connect.rs @@ -5,17 +5,12 @@ use crate::net::PlainConnection; use std::io::Result; use tokio::net::{TcpStream, ToSocketAddrs}; -use tokio_udt::{UdtConfiguration, UdtConnection}; - -/* TODO: - * Define generic Connect - * Retry handshake / RDV queue in UDT -*/ #[derive(Clone, Debug)] pub enum TransportProtocol { TCP, - UDT(UdtConfiguration), + #[cfg(target_os = "linux")] + UDT(tokio_udt::UdtConfiguration), } #[derive(Clone, Debug)] @@ -47,9 +42,12 @@ where stream.set_nodelay(true)?; Ok(stream.into()) }), - TransportProtocol::UDT(config) => UdtConnection::connect(&self, Some(config.clone())) - .await - .map(Into::into), + #[cfg(target_os = "linux")] + TransportProtocol::UDT(config) => { + tokio_udt::UdtConnection::connect(&self, Some(config.clone())) + .await + .map(Into::into) + } } } } diff --git a/src/net/traits/mod.rs b/src/net/traits/mod.rs index 4ebafa2..7448e66 100644 --- a/src/net/traits/mod.rs +++ b/src/net/traits/mod.rs @@ -1,3 +1,3 @@ mod connect; -pub use connect::{ConnectSettings, Connect, TransportProtocol}; +pub use connect::{Connect, ConnectSettings, TransportProtocol};