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] <support@github.com>

* 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 <mail@max-inden.de>
This commit is contained in:
dependabot[bot] 2020-11-03 14:09:10 +01:00 committed by GitHub
parent 8f53ec61fd
commit c812b8d56c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 7 deletions

View File

@ -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]

View File

@ -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 = [

View File

@ -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"] }

View File

@ -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.

View File

@ -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"] }

View File

@ -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<Result<usize, io::Error>> {
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()))
}
}

View File

@ -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"