update transport config and add TCPClient
This commit is contained in:
parent
99c9b543f2
commit
d9f6b53fa6
1 changed files with 23 additions and 6 deletions
29
src/main.rs
29
src/main.rs
|
|
@ -4,20 +4,27 @@ use clap::Parser;
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// RETICULUM INCLUDES
|
||||
use reticulum::iface::tcp_client::TcpClient;
|
||||
use reticulum::iface::tcp_server::TcpServer;
|
||||
use reticulum::transport::{Transport, TransportConfig};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
struct TcpServerConfig {
|
||||
bind_addr: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
enum InterfaceConfig {
|
||||
TcpServer(TcpServerConfig),
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
struct TcpClientConfig {
|
||||
bind_addr: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
enum InterfaceConfig {
|
||||
TcpServer(TcpServerConfig),
|
||||
TcpClient(TcpClientConfig),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
struct Config {
|
||||
interfaces: Vec<InterfaceConfig>,
|
||||
}
|
||||
|
|
@ -41,8 +48,11 @@ async fn main() {
|
|||
|
||||
println!("{config:?}");
|
||||
|
||||
let mut transport_config = TransportConfig::default();
|
||||
transport_config.set_retransmit(false);
|
||||
transport_config.set_broadcast(true);
|
||||
// set up the reticulum transport
|
||||
let transport = Transport::new(TransportConfig::default());
|
||||
let transport = Transport::new(transport_config);
|
||||
|
||||
// set up interfaces
|
||||
for iface_config in config.interfaces {
|
||||
|
|
@ -53,6 +63,13 @@ async fn main() {
|
|||
TcpServer::spawn,
|
||||
);
|
||||
}
|
||||
InterfaceConfig::TcpClient(cfg) => {
|
||||
let _ = transport
|
||||
.iface_manager()
|
||||
.lock()
|
||||
.await
|
||||
.spawn(TcpClient::new(cfg.bind_addr), TcpClient::spawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue