Skip to content

Commit

Permalink
upgrade tokio-udt to alpha6 and support udt on non-linux systems too …
Browse files Browse the repository at this point in the history
…(unoptimized)
  • Loading branch information
amatissart committed Aug 8, 2022
1 parent 60a57b8 commit a1d7fc1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 26 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
17 changes: 7 additions & 10 deletions src/link/rendezvous/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -103,7 +101,6 @@ impl Listener {
Ok((stream.into(), addr))
})
}
#[cfg(target_os = "linux")]
RawListener::Udt(ref udt_listener) => udt_listener
.accept()
.await
Expand Down
5 changes: 2 additions & 3 deletions src/link/rendezvous/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::{
};

use tokio::{io, net::TcpListener};
use tokio_udt::UdtListener;

pub struct Server {
_fuse: Fuse,
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 5 additions & 8 deletions src/net/traits/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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),
}
}
}

0 comments on commit a1d7fc1

Please sign in to comment.