forked from sigil-03/transport-node
Compare commits
6 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fb75bbf4df | |||
| 119fd14f50 | |||
| 184314975a | |||
| 7c53ed5ae7 | |||
| b53def2613 | |||
| b5c94b562e |
3 changed files with 49 additions and 10 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
|
@ -1035,8 +1035,7 @@ checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reticulum"
|
name = "reticulum"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/BeechatNetworkSystemsLtd/Reticulum-rs.git#5012cf2c48044034775207ab7ee2c67d285276bb"
|
||||||
checksum = "d838809ab28f9bfa5354b3397bcfc2b4a7a7258e98d9ed2b18a6e39437b00202"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
"aes",
|
||||||
"cbc",
|
"cbc",
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ tokio-util = "0.7.15"
|
||||||
# Logging
|
# Logging
|
||||||
log = "0.4.27"
|
log = "0.4.27"
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
reticulum = "0.1.0"
|
reticulum = { git = "https://github.com/BeechatNetworkSystemsLtd/Reticulum-rs.git" }
|
||||||
|
# reticulum = "0.1.0"
|
||||||
clap = { version = "4.5.53", features = ["derive"] }
|
clap = { version = "4.5.53", features = ["derive"] }
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
bincode = { version = "2.0.1", features = ["serde"] }
|
bincode = { version = "2.0.1", features = ["serde"] }
|
||||||
|
|
|
||||||
53
src/main.rs
53
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;
|
||||||
|
|
@ -6,7 +9,9 @@ use serde::{Deserialize, Serialize};
|
||||||
// RETICULUM INCLUDES
|
// RETICULUM INCLUDES
|
||||||
use reticulum::iface::tcp_client::TcpClient;
|
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::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 {
|
||||||
|
|
@ -18,15 +23,24 @@ struct TcpClientConfig {
|
||||||
bind_addr: String,
|
bind_addr: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
struct UdpConfig {
|
||||||
|
bind_addr: String,
|
||||||
|
forward_addr: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
enum InterfaceConfig {
|
enum InterfaceConfig {
|
||||||
TcpServer(TcpServerConfig),
|
TcpServer(TcpServerConfig),
|
||||||
TcpClient(TcpClientConfig),
|
TcpClient(TcpClientConfig),
|
||||||
|
Udp(UdpConfig),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
struct Config {
|
struct Config {
|
||||||
interfaces: Vec<InterfaceConfig>,
|
interfaces: Vec<InterfaceConfig>,
|
||||||
|
broadcast: bool,
|
||||||
|
retransmit: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
|
@ -37,7 +51,7 @@ struct Cli {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("trace")).init();
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
||||||
|
|
||||||
log::info!(">>> TRANSPORT NODE <<<");
|
log::info!(">>> TRANSPORT NODE <<<");
|
||||||
|
|
||||||
|
|
@ -49,10 +63,18 @@ async fn main() {
|
||||||
println!("{config:?}");
|
println!("{config:?}");
|
||||||
|
|
||||||
let mut transport_config = TransportConfig::default();
|
let mut transport_config = TransportConfig::default();
|
||||||
transport_config.set_retransmit(false);
|
transport_config.set_retransmit(config.retransmit);
|
||||||
transport_config.set_broadcast(true);
|
transport_config.set_broadcast(config.broadcast);
|
||||||
// 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 {
|
||||||
|
|
@ -70,11 +92,28 @@ async fn main() {
|
||||||
.await
|
.await
|
||||||
.spawn(TcpClient::new(cfg.bind_addr), TcpClient::spawn);
|
.spawn(TcpClient::new(cfg.bind_addr), TcpClient::spawn);
|
||||||
}
|
}
|
||||||
|
InterfaceConfig::Udp(cfg) => {
|
||||||
|
let _ = transport.iface_manager().lock().await.spawn(
|
||||||
|
UdpInterface::new(cfg.bind_addr, cfg.forward_addr),
|
||||||
|
UdpInterface::spawn,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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