Skip to content

Commit 633230c

Browse files
authored
chore: deprecate async-io support in mDNS crate
Pull-Request: #5958.
1 parent 8ee6e32 commit 633230c

File tree

10 files changed

+13
-321
lines changed

10 files changed

+13
-321
lines changed

Cargo.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ libp2p-gossipsub = { version = "0.49.0", path = "protocols/gossipsub" }
8686
libp2p-identify = { version = "0.47.0", path = "protocols/identify" }
8787
libp2p-identity = { version = "0.2.11" }
8888
libp2p-kad = { version = "0.47.1", path = "protocols/kad" }
89-
libp2p-mdns = { version = "0.47.0", path = "protocols/mdns" }
89+
libp2p-mdns = { version = "0.48.0", path = "protocols/mdns" }
9090
libp2p-memory-connection-limits = { version = "0.4.0", path = "misc/memory-connection-limits" }
9191
libp2p-metrics = { version = "0.17.0", path = "misc/metrics" }
9292
libp2p-mplex = { version = "0.43.1", path = "muxers/mplex" }

libp2p/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ full = [
5353
"upnp",
5454
]
5555

56-
async-std = [ "libp2p-swarm/async-std", "libp2p-mdns?/async-io", "libp2p-tcp?/async-io", "libp2p-dns?/async-std", "libp2p-quic?/async-std",]
56+
async-std = [ "libp2p-swarm/async-std", "libp2p-tcp?/async-io", "libp2p-dns?/async-std", "libp2p-quic?/async-std",]
5757
autonat = ["dep:libp2p-autonat"]
5858
cbor = ["libp2p-request-response?/cbor"]
5959
dcutr = ["dep:libp2p-dcutr", "libp2p-metrics?/dcutr"]

protocols/mdns/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.48.0
2+
3+
- Remove `async_std` dependency [PR 5958](https://github.com/libp2p/rust-libp2p/pull/5958)
4+
15
## 0.47.0
26

37
- Emit `ToSwarm::NewExternalAddrOfPeer` on discovery.

protocols/mdns/Cargo.toml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "libp2p-mdns"
33
edition.workspace = true
44
rust-version = { workspace = true }
5-
version = "0.47.0"
5+
version = "0.48.0"
66
description = "Implementation of the libp2p mDNS discovery method"
77
authors = ["Parity Technologies <[email protected]>"]
88
license = "MIT"
@@ -11,8 +11,6 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
1111
categories = ["network-programming", "asynchronous"]
1212

1313
[dependencies]
14-
async-std = { version = "1.12.0", optional = true }
15-
async-io = { version = "2.3.3", optional = true }
1614
futures = { workspace = true }
1715
if-watch = { workspace = true }
1816
libp2p-core = { workspace = true }
@@ -21,25 +19,19 @@ libp2p-identity = { workspace = true }
2119
rand = "0.8.3"
2220
smallvec = "1.13.2"
2321
socket2 = { version = "0.5.7", features = ["all"] }
24-
tokio = { workspace = true, default-features = false, features = ["net", "time"], optional = true}
22+
tokio = { workspace = true, default-features = false, features = ["net", "time"], optional = true }
2523
tracing = { workspace = true }
2624
hickory-proto = { workspace = true, features = ["mdns"] }
2725

2826
[features]
2927
tokio = ["dep:tokio", "if-watch/tokio"]
30-
async-io = ["dep:async-io", "dep:async-std", "if-watch/smol"]
3128

3229
[dev-dependencies]
33-
async-std = { version = "1.9.0", features = ["attributes"] }
34-
libp2p-swarm = { workspace = true, features = ["tokio", "async-std"] }
30+
libp2p-swarm = { workspace = true, features = ["tokio"] }
3531
tokio = { workspace = true, features = ["macros", "rt", "rt-multi-thread", "time"] }
3632
libp2p-swarm-test = { path = "../../swarm-test" }
3733
tracing-subscriber = { workspace = true, features = ["env-filter"] }
3834

39-
[[test]]
40-
name = "use-async-std"
41-
required-features = ["async-io", "libp2p-swarm-test/async-std"]
42-
4335
[[test]]
4436
name = "use-tokio"
4537
required-features = ["tokio", "libp2p-swarm-test/tokio"]

protocols/mdns/src/behaviour.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -78,44 +78,6 @@ pub trait Abort {
7878
fn abort(self);
7979
}
8080

81-
/// The type of a [`Behaviour`] using the `async-io` implementation.
82-
#[cfg(feature = "async-io")]
83-
pub mod async_io {
84-
use std::future::Future;
85-
86-
use async_std::task::JoinHandle;
87-
use if_watch::smol::IfWatcher;
88-
89-
use super::Provider;
90-
use crate::behaviour::{socket::asio::AsyncUdpSocket, timer::asio::AsyncTimer, Abort};
91-
92-
#[doc(hidden)]
93-
pub enum AsyncIo {}
94-
95-
impl Provider for AsyncIo {
96-
type Socket = AsyncUdpSocket;
97-
type Timer = AsyncTimer;
98-
type Watcher = IfWatcher;
99-
type TaskHandle = JoinHandle<()>;
100-
101-
fn new_watcher() -> Result<Self::Watcher, std::io::Error> {
102-
IfWatcher::new()
103-
}
104-
105-
fn spawn(task: impl Future<Output = ()> + Send + 'static) -> JoinHandle<()> {
106-
async_std::task::spawn(task)
107-
}
108-
}
109-
110-
impl Abort for JoinHandle<()> {
111-
fn abort(self) {
112-
async_std::task::spawn(self.cancel());
113-
}
114-
}
115-
116-
pub type Behaviour = super::Behaviour<AsyncIo>;
117-
}
118-
11981
/// The type of a [`Behaviour`] using the `tokio` implementation.
12082
#[cfg(feature = "tokio")]
12183
pub mod tokio {

protocols/mdns/src/behaviour/socket.rs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,49 +50,6 @@ pub trait AsyncSocket: Unpin + Send + 'static {
5050
) -> Poll<Result<(), Error>>;
5151
}
5252

53-
#[cfg(feature = "async-io")]
54-
pub(crate) mod asio {
55-
use async_io::Async;
56-
use futures::FutureExt;
57-
58-
use super::*;
59-
60-
/// AsyncIo UdpSocket
61-
pub(crate) type AsyncUdpSocket = Async<UdpSocket>;
62-
impl AsyncSocket for AsyncUdpSocket {
63-
fn from_std(socket: UdpSocket) -> std::io::Result<Self> {
64-
Async::new(socket)
65-
}
66-
67-
fn poll_read(
68-
&mut self,
69-
cx: &mut Context,
70-
buf: &mut [u8],
71-
) -> Poll<Result<(usize, SocketAddr), Error>> {
72-
// Poll receive socket.
73-
futures::ready!(self.poll_readable(cx))?;
74-
match self.recv_from(buf).now_or_never() {
75-
Some(data) => Poll::Ready(data),
76-
None => Poll::Pending,
77-
}
78-
}
79-
80-
fn poll_write(
81-
&mut self,
82-
cx: &mut Context,
83-
packet: &[u8],
84-
to: SocketAddr,
85-
) -> Poll<Result<(), Error>> {
86-
futures::ready!(self.poll_writable(cx))?;
87-
match self.send_to(packet, to).now_or_never() {
88-
Some(Ok(_)) => Poll::Ready(Ok(())),
89-
Some(Err(err)) => Poll::Ready(Err(err)),
90-
None => Poll::Pending,
91-
}
92-
}
93-
}
94-
}
95-
9653
#[cfg(feature = "tokio")]
9754
pub(crate) mod tokio {
9855
use ::tokio::{io::ReadBuf, net::UdpSocket as TkUdpSocket};

protocols/mdns/src/behaviour/timer.rs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::time::{Duration, Instant};
2222

2323
/// Simple wrapper for the different type of timers
2424
#[derive(Debug)]
25-
#[cfg(any(feature = "async-io", feature = "tokio"))]
25+
#[cfg(feature = "tokio")]
2626
pub struct Timer<T> {
2727
inner: T,
2828
}
@@ -40,49 +40,6 @@ pub trait Builder: Send + Unpin + 'static {
4040
fn interval_at(start: Instant, duration: Duration) -> Self;
4141
}
4242

43-
#[cfg(feature = "async-io")]
44-
pub(crate) mod asio {
45-
use std::{
46-
pin::Pin,
47-
task::{Context, Poll},
48-
};
49-
50-
use async_io::Timer as AsioTimer;
51-
use futures::Stream;
52-
53-
use super::*;
54-
55-
/// Async Timer
56-
pub(crate) type AsyncTimer = Timer<AsioTimer>;
57-
impl Builder for AsyncTimer {
58-
fn at(instant: Instant) -> Self {
59-
Self {
60-
inner: AsioTimer::at(instant),
61-
}
62-
}
63-
64-
fn interval(duration: Duration) -> Self {
65-
Self {
66-
inner: AsioTimer::interval(duration),
67-
}
68-
}
69-
70-
fn interval_at(start: Instant, duration: Duration) -> Self {
71-
Self {
72-
inner: AsioTimer::interval_at(start, duration),
73-
}
74-
}
75-
}
76-
77-
impl Stream for AsyncTimer {
78-
type Item = Instant;
79-
80-
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
81-
Pin::new(&mut self.inner).poll_next(cx)
82-
}
83-
}
84-
}
85-
8643
#[cfg(feature = "tokio")]
8744
pub(crate) mod tokio {
8845
use std::{

protocols/mdns/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
//!
2929
//! # Usage
3030
//!
31-
//! This crate provides a `Mdns` and `TokioMdns`, depending on the enabled features, which
32-
//! implements the `NetworkBehaviour` trait. This struct will automatically discover other
31+
//! This crate provides `TokioMdns`
32+
//! which implements the `NetworkBehaviour` trait. This struct will automatically discover other
3333
//! libp2p nodes on the local network.
3434
3535
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
@@ -40,8 +40,6 @@ use std::{
4040
};
4141

4242
mod behaviour;
43-
#[cfg(feature = "async-io")]
44-
pub use crate::behaviour::async_io;
4543
#[cfg(feature = "tokio")]
4644
pub use crate::behaviour::tokio;
4745
pub use crate::behaviour::{Behaviour, Event};

0 commit comments

Comments
 (0)