Skip to content

Commit

Permalink
Update tokio requirement from 0.2 to 0.3 (#1796)
Browse files Browse the repository at this point in the history
* 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](tokio-rs/tokio@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 tokio-rs/tokio#3016 for details.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
  • Loading branch information
dependabot[bot] and mxinden authored Nov 3, 2020
1 parent 8f53ec6 commit c812b8d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
3 changes: 2 additions & 1 deletion protocols/mdns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
3 changes: 2 additions & 1 deletion protocols/mdns/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion transports/tcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
11 changes: 10 additions & 1 deletion transports/tcp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;

Expand Down Expand Up @@ -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()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion transports/uds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c812b8d

Please sign in to comment.