summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-12-20 10:16:40 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-12-20 10:16:40 +0100
commit9a22b05a96f5ed066d588ab3aadf620f242d7ae5 (patch)
tree085bf79d2d6a98144619f16906147f1331565786
parentcd54ce4a394066e51c671e24da119b0a5b358e13 (diff)
Receive gossip and log about it
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--cli/src/profile.rs29
1 files changed, 28 insertions, 1 deletions
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::<LogStrategy>::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