add periodic heartbeat broadcast
This commit is contained in:
parent
b53def2613
commit
7c53ed5ae7
1 changed files with 27 additions and 4 deletions
31
src/main.rs
31
src/main.rs
|
|
@ -1,3 +1,6 @@
|
|||
use rand_core::OsRng;
|
||||
use reticulum::destination::DestinationName;
|
||||
use reticulum::identity::PrivateIdentity;
|
||||
use tokio::fs;
|
||||
|
||||
use clap::Parser;
|
||||
|
|
@ -8,6 +11,7 @@ use reticulum::iface::tcp_client::TcpClient;
|
|||
use reticulum::iface::tcp_server::TcpServer;
|
||||
use reticulum::iface::udp::UdpInterface;
|
||||
use reticulum::transport::{Transport, TransportConfig};
|
||||
use tokio::time::{Duration, interval};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
struct TcpServerConfig {
|
||||
|
|
@ -60,7 +64,15 @@ async fn main() {
|
|||
transport_config.set_retransmit(false);
|
||||
transport_config.set_broadcast(true);
|
||||
// set up the reticulum transport
|
||||
let transport = Transport::new(transport_config);
|
||||
let mut transport = Transport::new(transport_config);
|
||||
|
||||
// set up destination
|
||||
let id = PrivateIdentity::new_from_rand(OsRng);
|
||||
|
||||
let hb_destination = transport
|
||||
.add_destination(id, DestinationName::new("transport node", "heartbeat"))
|
||||
.await;
|
||||
log::info!("dest ID: {}", hb_destination.lock().await.desc.address_hash);
|
||||
|
||||
// set up interfaces
|
||||
for iface_config in config.interfaces {
|
||||
|
|
@ -87,8 +99,19 @@ async fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
// run until exit
|
||||
let _ = tokio::signal::ctrl_c().await;
|
||||
let mut heartbeat_interval = interval(Duration::from_secs(5));
|
||||
|
||||
log::info!("exit");
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = tokio::signal::ctrl_c() => {
|
||||
break;
|
||||
}
|
||||
_ = heartbeat_interval.tick() => {
|
||||
log::trace!("send heartbeat");
|
||||
transport.send_announce(&hb_destination, None).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log::info!("exit!");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue