From a1d7fc16000b1a4776dbdf8a93ffbc59d67f7b30 Mon Sep 17 00:00:00 2001 From: Adrien Matissart Date: Mon, 8 Aug 2022 16:04:49 +0200 Subject: [PATCH] upgrade tokio-udt to alpha6 and support udt on non-linux systems too (unoptimized) --- Cargo.toml | 3 +-- src/link/rendezvous/listener.rs | 17 +++++++---------- src/link/rendezvous/server.rs | 5 ++--- src/net/mod.rs | 4 +--- src/net/traits/connect.rs | 13 +++++-------- 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c6074fb..cfe1e4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,5 @@ 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" +tokio-udt = "0.1.0-alpha.6" diff --git a/src/link/rendezvous/listener.rs b/src/link/rendezvous/listener.rs index 081add6..cfd3012 100644 --- a/src/link/rendezvous/listener.rs +++ b/src/link/rendezvous/listener.rs @@ -20,12 +20,13 @@ use tokio::sync::{ mpsc::{Receiver, Sender}, }; +use tokio_udt::UdtListener; + type Outlet = Receiver<(Identity, SecureConnection)>; pub(crate) enum RawListener { Tcp(TcpListener), - #[cfg(target_os = "linux")] - Udt(tokio_udt::UdtListener), + Udt(UdtListener), } pub struct Listener { @@ -56,14 +57,11 @@ impl Listener { let port = listener.local_addr().unwrap().port(); (RawListener::Tcp(listener), port) } - #[cfg(target_os = "linux")] TransportProtocol::UDT(ref config) => { - let listener = tokio_udt::UdtListener::bind( - (Ipv4Addr::UNSPECIFIED, 0).into(), - Some(config.clone()), - ) - .await - .unwrap(); + let listener = + UdtListener::bind((Ipv4Addr::UNSPECIFIED, 0).into(), Some(config.clone())) + .await + .unwrap(); let port = listener.local_addr().unwrap().port(); (RawListener::Udt(listener), port) } @@ -103,7 +101,6 @@ 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 db89cbe..588bf21 100644 --- a/src/link/rendezvous/server.rs +++ b/src/link/rendezvous/server.rs @@ -17,6 +17,7 @@ use std::{ }; use tokio::{io, net::TcpListener}; +use tokio_udt::UdtListener; pub struct Server { _fuse: Fuse, @@ -63,9 +64,8 @@ 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) => { - tokio_udt::UdtListener::bind(address, Some(config.clone())) + UdtListener::bind(address, Some(config.clone())) .await .map(RawListener::Udt) } @@ -96,7 +96,6 @@ 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/net/mod.rs b/src/net/mod.rs index df18523..7dd14c6 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -16,15 +16,13 @@ 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/traits/connect.rs b/src/net/traits/connect.rs index 80fdbb9..5081c14 100644 --- a/src/net/traits/connect.rs +++ b/src/net/traits/connect.rs @@ -5,12 +5,12 @@ use crate::net::PlainConnection; use std::io::Result; use tokio::net::{TcpStream, ToSocketAddrs}; +use tokio_udt::{UdtConfiguration, UdtConnection}; #[derive(Clone, Debug)] pub enum TransportProtocol { TCP, - #[cfg(target_os = "linux")] - UDT(tokio_udt::UdtConfiguration), + UDT(UdtConfiguration), } #[derive(Clone, Debug)] @@ -42,12 +42,9 @@ where stream.set_nodelay(true)?; Ok(stream.into()) }), - #[cfg(target_os = "linux")] - TransportProtocol::UDT(config) => { - tokio_udt::UdtConnection::connect(&self, Some(config.clone())) - .await - .map(Into::into) - } + TransportProtocol::UDT(config) => UdtConnection::connect(&self, Some(config.clone())) + .await + .map(Into::into), } } }