Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quinn_udp: use async_io instead of tokio #1183

Closed
wants to merge 11 commits into from
11 changes: 4 additions & 7 deletions quinn-udp/src/fallback.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use crate::{RecvMeta, SocketType};
use crate::RecvMeta;
use proto::Transmit;

use std::io::{IoSliceMut, Result};

pub fn init(socket: &std::net::UdpSocket) -> Result<SocketType> {
Ok(if socket.local_addr()?.is_ipv4() {
SocketType::Ipv4
} else {
SocketType::Ipv6Only
})
pub fn init(_socket: &std::net::UdpSocket) -> Result<()> {
// We do nothing with the given socket.
Ok(())
}

pub fn send(socket: &std::net::UdpSocket, transmits: &[Transmit]) -> Result<usize> {
Expand Down
11 changes: 0 additions & 11 deletions quinn-udp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@ impl Default for RecvMeta {
}
}

/// Socket type.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SocketType {
/// Socket is bound to an ip4 address.
Ipv4,
/// Socket is bound to an ip6 address and is not dual stack.
Ipv6Only,
/// Socket is bound to an ip6 address and supports ip4 packets.
Ipv6,
}

/// Log at most 1 IO error per minute
const IO_ERROR_LOG_INTERVAL: Duration = std::time::Duration::from_secs(60);

Expand Down
10 changes: 2 additions & 8 deletions quinn-udp/src/socket.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use proto::{Transmit};
use crate::{RecvMeta, SocketType, UdpCapabilities};
use crate::{RecvMeta, UdpCapabilities};
use async_io::Async;
use futures_lite::future::poll_fn;
use std::io::{IoSliceMut, Result};
Expand All @@ -15,7 +15,6 @@ use crate::platform as platform;
#[derive(Debug)]
pub struct UdpSocket {
inner: Async<std::net::UdpSocket>,
ty: SocketType,
}

impl UdpSocket {
Expand All @@ -27,10 +26,9 @@ impl UdpSocket {
}

pub fn from_std(socket: std::net::UdpSocket) -> Result<Self> {
let ty = platform::init(&socket)?;
platform::init(&socket)?;
Ok(Self {
inner: Async::new(socket)?,
ty,
})
}

Expand All @@ -39,10 +37,6 @@ impl UdpSocket {
Self::from_std(socket)
}

pub fn socket_type(&self) -> SocketType {
self.ty
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure we don't use this in libp2p-quic? you need to be able to figure out if you can dial ipv4 addresses when bound to an ipv6 address

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. I will revert this change if you are right


pub fn local_addr(&self) -> Result<SocketAddr> {
self.inner.get_ref().local_addr()
}
Expand Down
12 changes: 3 additions & 9 deletions quinn-udp/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use std::{
};

use proto::{EcnCodepoint, Transmit};
use crate::{cmsg, RecvMeta, SocketType};
use crate::{cmsg, RecvMeta};

#[cfg(target_os = "freebsd")]
type IpTosTy = libc::c_uchar;
#[cfg(not(target_os = "freebsd"))]
type IpTosTy = libc::c_int;

pub fn init(io: &UdpSocket) -> io::Result<SocketType> {
pub fn init(io: &UdpSocket) -> io::Result<()> {
let mut cmsg_platform_space = 0;
if cfg!(target_os = "linux") {
cmsg_platform_space +=
Expand Down Expand Up @@ -134,13 +134,7 @@ pub fn init(io: &UdpSocket) -> io::Result<SocketType> {
}
}

Ok(if addr.is_ipv4() {
SocketType::Ipv4
} else if only_v6 {
SocketType::Ipv6Only
} else {
SocketType::Ipv6
})
Ok(())
}

#[cfg(not(any(target_os = "macos", target_os = "ios")))]
Expand Down