From 218f0276ac5b15b9806660d964a3ddfbac07a082 Mon Sep 17 00:00:00 2001 From: Jazz Turner-Baggs <473256+jazzz@users.noreply.github.com> Date: Sun, 12 Jul 2026 16:08:08 -0700 Subject: [PATCH] Add meshshark listener --- Cargo.toml | 1 + bin/meshshark/Cargo.toml | 20 ++++++++++++++++++++ bin/meshshark/src/main.rs | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 bin/meshshark/Cargo.toml create mode 100644 bin/meshshark/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 1efb279..3114e5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ resolver = "3" members = [ "bin/chat-cli", + "bin/meshshark", "core/account", "core/conversations", "core/crypto", diff --git a/bin/meshshark/Cargo.toml b/bin/meshshark/Cargo.toml new file mode 100644 index 0000000..e871b39 --- /dev/null +++ b/bin/meshshark/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "meshshark" +version = "0.1.0" +edition = "2024" + +[[bin]] +name = "meshshark" +path = "src/main.rs" + +[dependencies] +# Workspace dependencies (sorted) +logos-delivery = { path = "../../extensions/logos-delivery-rust"} + +# External dependencies (sorted) +anyhow = "1.0" +clap = { version = "4", features = ["derive"] } +crossterm = "0.29" +ratatui = "0.29" +tracing = "0.1.44" +tracing-subscriber = "0.3" \ No newline at end of file diff --git a/bin/meshshark/src/main.rs b/bin/meshshark/src/main.rs new file mode 100644 index 0000000..97fd83b --- /dev/null +++ b/bin/meshshark/src/main.rs @@ -0,0 +1,39 @@ +use std::time::{Duration, Instant}; + +use logos_delivery::{DeliveryError, P2pConfig, ThreadedDeliveryWrapper}; +use tracing::info; + +fn run() -> Result<(), DeliveryError> { + let _ = tracing_subscriber::fmt() + .with_max_level(tracing::Level::DEBUG) + .try_init(); + + let mut cfg = P2pConfig::default(); + cfg.log_level = "DEBUG".into(); + cfg.tcp_port = 60012; + + let mut ld = ThreadedDeliveryWrapper::start(cfg, |x| Some(x))?; + let inbound = ld.inbound_queue(); + + ld.subscribe("/logos-chat/1/ping/proto")?; + + // Print each received message until the deadline. + let deadline = Instant::now() + Duration::from_secs(40); + while let Some(remaining) = deadline.checked_duration_since(Instant::now()) { + let Ok(event) = inbound.recv_timeout(remaining) else { + break; // timeout or channel closed + }; + let Some(msg) = event.into_received() else { + continue; // non-message event + }; + let topic = msg.content_topic().to_string(); + let payload = msg.into_payload().unwrap_or_default(); + info!(topic, "recv: {}", String::from_utf8_lossy(&payload)); + } + + Ok(()) +} + +fn main() { + run().unwrap() +}