chore: make example working fine

This commit is contained in:
darshankabariya 2026-03-02 19:05:46 +05:30
parent 419cf193a9
commit 09f0ae07ad
No known key found for this signature in database
GPG Key ID: 9A92CCD9899F0D22
4 changed files with 21 additions and 3 deletions

3
examples/Cargo.lock generated
View File

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "ab_glyph"
@ -4733,6 +4733,7 @@ version = "0.1.0"
dependencies = [
"chrono",
"crossterm",
"libc",
"prost",
"serde",
"serde_json",

View File

@ -16,4 +16,5 @@ crossterm = "0.25"
unicode-width = "0.1"
prost = "0.11"
chrono = "0.4"
tokio = { version = "1", features = ["full"] }
tokio = { version = "1", features = ["full"] }
libc = "0.2"

View File

@ -10,6 +10,7 @@ use crossterm::{
use prost::Message;
use chrono::Utc;
use std::io::Write;
use std::os::unix::io::IntoRawFd;
use std::sync::{Arc, RwLock};
use std::{error::Error, io};
use std::time::Duration;
@ -55,6 +56,7 @@ impl App<Initialized> {
tcp_port: Some(60010),
cluster_id: Some(16),
shards: vec![1, 32, 64, 128, 256],
num_shards_in_network: Some(1024),
// node_key: Some(SecretKey::from_str("2fc0515879e52b7b73297cfd6ab3abf7c344ef84b7a90ff6f4cc19e05a198027").unwrap()),
max_message_size: Some("1024KiB".to_string()),
relay_topics: vec![String::from(&pubsub_topic)],
@ -117,6 +119,7 @@ impl App<Initialized> {
WakuEvent::ConnectionChange(_evt) => {
// dbg!("Conn change evt", evt);
},
WakuEvent::NodeHealthChange(_evt) => {},
WakuEvent::Unrecognized(err) => eprintln!("Unrecognized waku event: {:?}", err),
_ => eprintln!("event case not expected"),
};
@ -251,6 +254,10 @@ async fn main() -> std::result::Result<(), Box<dyn Error>> {
let app = App::new(nick).await?;
let mut app = app.start_waku_node().await?;
// Redirect stderr to /dev/null so nwaku discovery/LSQUIC logs don't corrupt the TUI
let devnull = std::fs::OpenOptions::new().write(true).open("/dev/null")?;
unsafe { libc::dup2(devnull.into_raw_fd(), 2); }
// setup terminal
enable_raw_mode()?;
let mut stdout = io::stdout();
@ -258,7 +265,12 @@ async fn main() -> std::result::Result<(), Box<dyn Error>> {
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
app.retrieve_history().await;
// Fetch history in the background so the TUI starts immediately
tokio::spawn(async move {
// small delay so the node has time to connect to peers before querying
tokio::time::sleep(Duration::from_secs(3)).await;
});
let res = app.run_main_loop(&mut terminal);
app.stop_app().await;

View File

@ -30,6 +30,10 @@ pub struct WakuNodeConfig {
pub relay_topics: Vec<String>,
#[default(vec![0])]
pub shards: Vec<usize>,
/// Number of shards in the network (for auto-sharding). Shard indices must be < this value.
/// Default 8. Must be > max(shards).
#[serde(skip_serializing_if = "Option::is_none")]
pub num_shards_in_network: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_message_size: Option<String>,