diff --git a/Cargo.toml b/Cargo.toml index 274d1a3..4f09d9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ multicast-socket = "0.2.1" hex = "0.4.3" pretty-hash = "0.4.1" hyperswarm-dht = { git = "https://github.com/Frando/hyperswarm-dht.git", branch = "hyperspace" } -colmeia-hyperswarm-mdns = { git = "https://github.com/bltavares/colmeia.git", rev = "e92ab71981356197a21592b7ce6854e209582985" } +colmeia-hyperswarm-mdns = { git = "https://github.com/bltavares/colmeia.git", rev = "53761799f7a9ee123875534e0108d7483a117885" } libutp-rs = { git = "https://github.com/Frando/libutp-rs.git", branch = "feat/clone", optional = true } [dev-dependencies] diff --git a/src/discovery/mdns.rs b/src/discovery/mdns.rs index adcb4db..d72cd05 100644 --- a/src/discovery/mdns.rs +++ b/src/discovery/mdns.rs @@ -2,6 +2,7 @@ use async_std::channel; use async_std::stream::Stream; use async_std::task::{Context, Poll}; use colmeia_hyperswarm_mdns::{self_id, Announcer, Locator}; +use futures::FutureExt; use futures_lite::ready; // use log::*; use std::convert::TryInto; @@ -108,29 +109,26 @@ impl Stream for MdnsDiscovery { return Poll::Ready(Some(Err(e))); } - if let Poll::Ready(Some(_command)) = Pin::new(&mut this.pending_commands_rx).poll_next(cx) { - // TODO: Boxing the add_topic future does not work because there's no valid - // lifetime. Best would be to make the add_topic functions sync, or return - // a future that can be boxed. - // let fut = match command { - // Command::Lookup(topic) => { - // let fut = this.locator.add_topic(&topic); - // let fut = fut.map(|r| { - // r.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("{}", e))) - // }); - // let fut: CommandFut = fut.boxed(); - // fut - // } - // Command::Announce(topic) => { - // let fut = this.announcer.add_topic(&topic); - // let fut = fut.map(|r| { - // r.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("{}", e))) - // }); - // let fut: CommandFut = fut.boxed(); - // fut - // } - // }; - // this.pending_future = Some(fut); + if let Poll::Ready(Some(command)) = Pin::new(&mut this.pending_commands_rx).poll_next(cx) { + let fut = match command { + Command::Lookup(topic) => { + let fut = this.locator.add_topic(topic.to_vec()); + let fut = fut.map(|r| { + r.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("{}", e))) + }); + let fut: CommandFut = fut.boxed(); + fut + } + Command::Announce(topic) => { + let fut = this.announcer.add_topic(topic.to_vec()); + let fut = fut.map(|r| { + r.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("{}", e))) + }); + let fut: CommandFut = fut.boxed(); + fut + } + }; + this.pending_future = Some(fut); } if let Err(e) = ready!(this.poll_pending_future(cx)) {