From c812b8d56c2919bd00921c5ac06f6e3614c82356 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2020 14:09:10 +0100 Subject: [PATCH] Update tokio requirement from 0.2 to 0.3 (#1796) * Update tokio requirement from 0.2 to 0.3 Updates the requirements on [tokio](https://github.com/tokio-rs/tokio) to permit the latest version. - [Release notes](https://github.com/tokio-rs/tokio/releases) - [Commits](https://github.com/tokio-rs/tokio/compare/tokio-0.2.0...tokio-0.3.0) Signed-off-by: dependabot[bot] * protocols/mdns: Ensure to set non_blocking on tokio udp socket * transports/tcp: Ensure to set non_blocking on tokio tcp socket See https://github.com/tokio-rs/tokio/pull/3016 for details. Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Max Inden --- CHANGELOG.md | 3 ++- Cargo.toml | 2 +- protocols/mdns/Cargo.toml | 3 ++- protocols/mdns/src/service.rs | 3 ++- transports/tcp/Cargo.toml | 2 +- transports/tcp/src/lib.rs | 11 ++++++++++- transports/uds/Cargo.toml | 2 +- 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c79d642b..2c25ea28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,8 @@ # Version 0.30.0 [unreleased] -- Update `libp2p-core` and all its dependers. +- Update `libp2p-mdns`, `libp2p-tcp` and `libp2p-uds` as well as `libp2p-core` + and all its dependers. # Version 0.29.1 [2020-10-20] diff --git a/Cargo.toml b/Cargo.toml index 2d16e6d0..029a78bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,7 +95,7 @@ libp2p-websocket = { version = "0.25.0", path = "transports/websocket", optional [dev-dependencies] async-std = "1.6.2" env_logger = "0.8.1" -tokio = { version = "0.2", features = ["io-util", "io-std", "stream", "macros"] } +tokio = { version = "0.3", features = ["io-util", "io-std", "stream", "macros", "rt", "rt-multi-thread"] } [workspace] members = [ diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index f369c827..f933a228 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -22,9 +22,10 @@ log = "0.4" net2 = "0.2" rand = "0.7" smallvec = "1.0" -tokio = { version = "0.2", default-features = false, features = ["udp"], optional = true } +tokio = { version = "0.3", default-features = false, features = ["net"], optional = true } void = "1.0" wasm-timer = "0.2.4" [dev-dependencies] if-addrs = "0.6.4" +tokio = { version = "0.3", default-features = false, features = ["rt", "rt-multi-thread"] } diff --git a/protocols/mdns/src/service.rs b/protocols/mdns/src/service.rs index 16f6fae3..4815a427 100644 --- a/protocols/mdns/src/service.rs +++ b/protocols/mdns/src/service.rs @@ -298,8 +298,9 @@ impl fmt::Debug for $service_name { #[cfg(feature = "async-std")] codegen!("async-std", MdnsService, async_std::net::UdpSocket, (|socket| Ok::<_, std::io::Error>(async_std::net::UdpSocket::from(socket)))); +// Note: Tokio's UdpSocket::from_std does not set the socket into non-blocking mode. #[cfg(feature = "tokio")] -codegen!("tokio", TokioMdnsService, tokio::net::UdpSocket, (|socket| tokio::net::UdpSocket::from_std(socket))); +codegen!("tokio", TokioMdnsService, tokio::net::UdpSocket, (|socket: std::net::UdpSocket| { socket.set_nonblocking(true); tokio::net::UdpSocket::from_std(socket) })); /// A valid mDNS packet received by the service. diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index d1f37be4..eff426c9 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -18,7 +18,7 @@ ipnet = "2.0.0" libp2p-core = { version = "0.24.0", path = "../../core" } log = "0.4.1" socket2 = "0.3.12" -tokio = { version = "0.2", default-features = false, features = ["tcp"], optional = true } +tokio = { version = "0.3", default-features = false, features = ["net"], optional = true } [dev-dependencies] libp2p-tcp = { path = ".", features = ["async-std"] } diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index 7336f59e..b08062fe 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -123,6 +123,11 @@ impl Transport for $tcp_config { socket.bind(&socket_addr.into())?; socket.listen(1024)?; // we may want to make this configurable + // Note: Tokio's TcpListener::from_std, which the TcpListener's TryFrom implementation + // uses, does not set the socket into non-blocking mode. + #[cfg(feature = "tokio")] + socket.set_nonblocking(true); + let listener = <$tcp_listener>::try_from(socket.into_tcp_listener()) .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; @@ -353,7 +358,11 @@ impl AsyncWrite for TcpTransStream { #[cfg(feature = "tokio")] impl AsyncRead for TokioTcpTransStream { fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context, buf: &mut [u8]) -> Poll> { - tokio::io::AsyncRead::poll_read(Pin::new(&mut self.inner), cx, buf) + // Adapted from + // https://github.com/tokio-rs/tokio/blob/6d99e1c7dec4c6a37c4c7bf2801bc82cc210351d/tokio-util/src/compat.rs#L126. + let mut read_buf = tokio::io::ReadBuf::new(buf); + futures::ready!(tokio::io::AsyncRead::poll_read(Pin::new(&mut self.inner), cx, &mut read_buf))?; + Poll::Ready(Ok(read_buf.filled().len())) } } diff --git a/transports/uds/Cargo.toml b/transports/uds/Cargo.toml index 8b4e349e..0df652ce 100644 --- a/transports/uds/Cargo.toml +++ b/transports/uds/Cargo.toml @@ -14,7 +14,7 @@ async-std = { version = "1.6.2", optional = true } libp2p-core = { version = "0.24.0", path = "../../core" } log = "0.4.1" futures = "0.3.1" -tokio = { version = "0.2", default-features = false, features = ["uds"], optional = true } +tokio = { version = "0.3", default-features = false, features = ["net"], optional = true } [target.'cfg(all(unix, not(target_os = "emscripten")))'.dev-dependencies] tempfile = "3.0"