forked from sigil-03/transport-node
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};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
// RETICULUM INCLUDES
|
// RETICULUM INCLUDES
|
||||||
|
use reticulum::iface::tcp_client::TcpClient;
|
||||||
use reticulum::iface::tcp_server::TcpServer;
|
use reticulum::iface::tcp_server::TcpServer;
|
||||||
use reticulum::transport::{Transport, TransportConfig};
|
use reticulum::transport::{Transport, TransportConfig};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
struct TcpServerConfig {
|
struct TcpServerConfig {
|
||||||
bind_addr: String,
|
bind_addr: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
enum InterfaceConfig {
|
struct TcpClientConfig {
|
||||||
TcpServer(TcpServerConfig),
|
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 {
|
struct Config {
|
||||||
interfaces: Vec<InterfaceConfig>,
|
interfaces: Vec<InterfaceConfig>,
|
||||||
}
|
}
|
||||||
|
|
@ -41,8 +48,11 @@ async fn main() {
|
||||||
|
|
||||||
println!("{config:?}");
|
println!("{config:?}");
|
||||||
|
|
||||||
|
let mut transport_config = TransportConfig::default();
|
||||||
|
transport_config.set_retransmit(false);
|
||||||
|
transport_config.set_broadcast(true);
|
||||||
// set up the reticulum transport
|
// set up the reticulum transport
|
||||||
let transport = Transport::new(TransportConfig::default());
|
let transport = Transport::new(transport_config);
|
||||||
|
|
||||||
// set up interfaces
|
// set up interfaces
|
||||||
for iface_config in config.interfaces {
|
for iface_config in config.interfaces {
|
||||||
|
|
@ -53,6 +63,13 @@ async fn main() {
|
||||||
TcpServer::spawn,
|
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