From fca7c3baef10110adaf0e599dff8cdb0f81c06c7 Mon Sep 17 00:00:00 2001 From: umgefahren <55623006+umgefahren@users.noreply.github.com> Date: Tue, 4 Oct 2022 15:48:46 +0200 Subject: [PATCH 1/4] Updated if-warch --- protocols/mdns/Cargo.toml | 2 +- protocols/mdns/src/behaviour.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index 466c9eb9e25..6fd9ce38946 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"] data-encoding = "2.3.2" dns-parser = "0.8.0" futures = "0.3.13" -if-watch = "1.1.1" +if-watch = "2.0.0" lazy_static = "1.4.0" libp2p-core = { version = "0.37.0", path = "../../core" } libp2p-swarm = { version = "0.40.0", path = "../../swarm" } diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index d645468ed5c..cc3dd769d7d 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -25,7 +25,6 @@ mod timer; use self::iface::InterfaceState; use crate::behaviour::{socket::AsyncSocket, timer::Builder}; use crate::MdnsConfig; -use futures::prelude::*; use futures::Stream; use if_watch::{IfEvent, IfWatcher}; use libp2p_core::transport::ListenerId; @@ -83,7 +82,7 @@ where { /// Builds a new `Mdns` behaviour. pub async fn new(config: MdnsConfig) -> io::Result { - let if_watch = if_watch::IfWatcher::new().await?; + let if_watch = if_watch::IfWatcher::new()?; Ok(Self { config, if_watch, @@ -170,7 +169,7 @@ where params: &mut impl PollParameters, ) -> Poll> { // Poll ifwatch. - while let Poll::Ready(event) = Pin::new(&mut self.if_watch).poll(cx) { + while let Poll::Ready(Some(event)) = Pin::new(&mut self.if_watch).poll_next(cx) { match event { Ok(IfEvent::Up(inet)) => { let addr = inet.addr(); From df6e5ca5a8a7e2fa3ab7be0df747e506619b7132 Mon Sep 17 00:00:00 2001 From: umgefahren <55623006+umgefahren@users.noreply.github.com> Date: Tue, 4 Oct 2022 15:53:10 +0200 Subject: [PATCH 2/4] Added changelog entry --- protocols/mdns/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index d0562caa511..2b0acc00dfd 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -8,8 +8,11 @@ - Fix a bug that could cause a delay of ~10s until peers would get discovered when using the tokio runtime. See [PR 2939]. +- Update to `if-watch` `v2.0.0`. See [PR 2978]. + [PR 2918]: https://github.com/libp2p/rust-libp2p/pull/2918 [PR 2939]: https://github.com/libp2p/rust-libp2p/pull/2939 +[PR 2978]: https://github.com/libp2p/rust-libp2p/pull/2978 # 0.40.0 From fcae4f5851c6e54b1b483b64f1f82af3f617b109 Mon Sep 17 00:00:00 2001 From: umgefahren <55623006+umgefahren@users.noreply.github.com> Date: Wed, 5 Oct 2022 10:28:31 +0200 Subject: [PATCH 3/4] Removed the need for async --- examples/chat-tokio.rs | 2 +- examples/chat.rs | 4 ++-- examples/distributed-key-value-store.rs | 4 ++-- examples/mdns-passive-discovery.rs | 2 +- protocols/mdns/src/behaviour.rs | 2 +- protocols/mdns/tests/use-async-std.rs | 2 +- protocols/mdns/tests/use-tokio.rs | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/chat-tokio.rs b/examples/chat-tokio.rs index 8ad61ef8a6c..eee4886cc5a 100644 --- a/examples/chat-tokio.rs +++ b/examples/chat-tokio.rs @@ -113,7 +113,7 @@ async fn main() -> Result<(), Box> { // Create a Swarm to manage peers and events. let mut swarm = { - let mdns = TokioMdns::new(Default::default()).await?; + let mdns = TokioMdns::new(Default::default())?; let mut behaviour = MyBehaviour { floodsub: Floodsub::new(peer_id), mdns, diff --git a/examples/chat.rs b/examples/chat.rs index ee5527bfca7..11778ab0708 100644 --- a/examples/chat.rs +++ b/examples/chat.rs @@ -49,7 +49,7 @@ //! //! The two nodes then connect. -use async_std::{io, task}; +use async_std::io; use futures::{ prelude::{stream::StreamExt, *}, select, @@ -108,7 +108,7 @@ async fn main() -> Result<(), Box> { // Create a Swarm to manage peers and events let mut swarm = { - let mdns = task::block_on(Mdns::new(MdnsConfig::default()))?; + let mdns = Mdns::new(MdnsConfig::default())?; let mut behaviour = MyBehaviour { floodsub: Floodsub::new(local_peer_id), mdns, diff --git a/examples/distributed-key-value-store.rs b/examples/distributed-key-value-store.rs index 7fef717cf78..de02ddf81be 100644 --- a/examples/distributed-key-value-store.rs +++ b/examples/distributed-key-value-store.rs @@ -40,7 +40,7 @@ //! //! 4. Close with Ctrl-c. -use async_std::{io, task}; +use async_std::io; use futures::{prelude::*, select}; use libp2p::kad::record::store::MemoryStore; use libp2p::kad::{ @@ -96,7 +96,7 @@ async fn main() -> Result<(), Box> { // Create a Kademlia behaviour. let store = MemoryStore::new(local_peer_id); let kademlia = Kademlia::new(local_peer_id, store); - let mdns = task::block_on(Mdns::new(MdnsConfig::default()))?; + let mdns = Mdns::new(MdnsConfig::default())?; let behaviour = MyBehaviour { kademlia, mdns }; Swarm::new(transport, behaviour, local_peer_id) }; diff --git a/examples/mdns-passive-discovery.rs b/examples/mdns-passive-discovery.rs index a63ec7d5afe..9ac7e1a45a0 100644 --- a/examples/mdns-passive-discovery.rs +++ b/examples/mdns-passive-discovery.rs @@ -40,7 +40,7 @@ async fn main() -> Result<(), Box> { let transport = libp2p::development_transport(id_keys).await?; // Create an MDNS network behaviour. - let behaviour = Mdns::new(MdnsConfig::default()).await?; + let behaviour = Mdns::new(MdnsConfig::default())?; // Create a Swarm that establishes connections through the given transport. // Note that the MDNS behaviour itself will not actually inititiate any connections, diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index cc3dd769d7d..334c3462e68 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -81,7 +81,7 @@ where T: Builder, { /// Builds a new `Mdns` behaviour. - pub async fn new(config: MdnsConfig) -> io::Result { + pub fn new(config: MdnsConfig) -> io::Result { let if_watch = if_watch::IfWatcher::new()?; Ok(Self { config, diff --git a/protocols/mdns/tests/use-async-std.rs b/protocols/mdns/tests/use-async-std.rs index 1bd311dbcbe..2ddb36355be 100644 --- a/protocols/mdns/tests/use-async-std.rs +++ b/protocols/mdns/tests/use-async-std.rs @@ -61,7 +61,7 @@ async fn create_swarm(config: MdnsConfig) -> Result, Box> let id_keys = identity::Keypair::generate_ed25519(); let peer_id = PeerId::from(id_keys.public()); let transport = libp2p::development_transport(id_keys).await?; - let behaviour = Mdns::new(config).await?; + let behaviour = Mdns::new(config)?; let mut swarm = Swarm::new(transport, behaviour, peer_id); swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?; Ok(swarm) diff --git a/protocols/mdns/tests/use-tokio.rs b/protocols/mdns/tests/use-tokio.rs index 040b32a984e..830557d3f00 100644 --- a/protocols/mdns/tests/use-tokio.rs +++ b/protocols/mdns/tests/use-tokio.rs @@ -57,7 +57,7 @@ async fn create_swarm(config: MdnsConfig) -> Result, Box Date: Wed, 5 Oct 2022 19:00:04 +0200 Subject: [PATCH 4/4] Update protocols/mdns/CHANGELOG.md Co-authored-by: Max Inden --- protocols/mdns/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index 8a9ef7f31b1..915564341ae 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -10,7 +10,7 @@ - Removed the `lazy_static` dependency. See [PR 2977]. -- Update to `if-watch` `v2.0.0`. See [PR 2978]. +- Update to `if-watch` `v2.0.0` and thus the `async` method `Mdns::new` and `TokioMdns::new` becomes synchronous. See [PR 2978]. [PR 2918]: https://github.com/libp2p/rust-libp2p/pull/2918 [PR 2939]: https://github.com/libp2p/rust-libp2p/pull/2939