add heartbeat destination broadcasting to transport node #2
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 tokio::fs;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
@ -8,6 +11,7 @@ use reticulum::iface::tcp_client::TcpClient;
|
||||||
use reticulum::iface::tcp_server::TcpServer;
|
use reticulum::iface::tcp_server::TcpServer;
|
||||||
use reticulum::iface::udp::UdpInterface;
|
use reticulum::iface::udp::UdpInterface;
|
||||||
use reticulum::transport::{Transport, TransportConfig};
|
use reticulum::transport::{Transport, TransportConfig};
|
||||||
|
use tokio::time::{Duration, interval};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
struct TcpServerConfig {
|
struct TcpServerConfig {
|
||||||
|
|
@ -60,7 +64,15 @@ async fn main() {
|
||||||
transport_config.set_retransmit(false);
|
transport_config.set_retransmit(false);
|
||||||
transport_config.set_broadcast(true);
|
transport_config.set_broadcast(true);
|
||||||
// set up the reticulum transport
|
// 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
|
// set up interfaces
|
||||||
for iface_config in config.interfaces {
|
for iface_config in config.interfaces {
|
||||||
|
|
@ -87,8 +99,19 @@ async fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// run until exit
|
let mut heartbeat_interval = interval(Duration::from_secs(5));
|
||||||
let _ = tokio::signal::ctrl_c().await;
|
|
||||||
|
|
||||||
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