From 9a22b05a96f5ed066d588ab3aadf620f242d7ae5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 20 Dec 2021 10:16:40 +0100 Subject: Receive gossip and log about it Signed-off-by: Matthias Beyer --- cli/src/profile.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/cli/src/profile.rs b/cli/src/profile.rs index 953a8e3..cf1a2f0 100644 --- a/cli/src/profile.rs +++ b/cli/src/profile.rs @@ -85,17 +85,44 @@ async fn profile_serve(matches: &ArgMatches) -> Result<()> { } } + let mut gossip_channel = Box::pin({ + profile.client() + .pubsub_subscribe("distrox".to_string()) + .await + .map(|stream| { + use distrox_lib::gossip::deserializer::GossipDeserializer; + use distrox_lib::gossip::deserializer::LogStrategy; + + GossipDeserializer::::new().run(stream) + })? + }); + let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); + let own_peer_id = profile.client().own_id().await?; + ctrlc::set_handler(move || { r.store(false, Ordering::SeqCst); }).context("Error setting Ctrl-C handler")?; log::info!("Serving..."); while running.load(Ordering::SeqCst) { + use futures::stream::StreamExt; + use distrox_lib::gossip::GossipMessage; + tokio::time::sleep(std::time::Duration::from_millis(500)).await; // sleep not so busy - profile.gossip_own_state("distrox".to_string()).await? + + tokio::select! { + own = profile.gossip_own_state("distrox".to_string()) => own?, + other = gossip_channel.next() => { + let gossip_myself = other.as_ref().map(|(source, _)| *source == own_peer_id).unwrap_or(false); + + if !gossip_myself { + log::trace!("Received gossip: {:?}", other); + } + } + } } log::info!("Shutting down..."); profile.exit().await -- cgit v1.2.3