Add meshshark listener

This commit is contained in:
Jazz Turner-Baggs 2026-07-12 16:08:08 -07:00
parent f7a226660d
commit 218f0276ac
No known key found for this signature in database
3 changed files with 60 additions and 0 deletions

View File

@ -4,6 +4,7 @@ resolver = "3"
members = [
"bin/chat-cli",
"bin/meshshark",
"core/account",
"core/conversations",
"core/crypto",

20
bin/meshshark/Cargo.toml Normal file
View File

@ -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"

39
bin/meshshark/src/main.rs Normal file
View File

@ -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()
}