diff options
author | Keuin <[email protected]> | 2023-09-05 01:52:56 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-09-05 01:56:21 +0800 |
commit | 50dbc034090614d004d097c7a45b0a28a3bbb80b (patch) | |
tree | b8ad419bb8c2fed12ac419274755c716166eb90b /src/main.rs | |
parent | 863473cdcb29d9989c39b4ff96bd54e14b13c6b6 (diff) |
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index b588f2d..da5c2f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use crate::server::SharedConfig; mod arguments; mod client; mod config; +mod protocol; mod server; fn load_config<P: AsRef<Path>>(file_path: P) -> config::Root { @@ -74,7 +75,8 @@ async fn main() -> io::Result<()> { } async fn server_main(cfg: config::Root) -> io::Result<()> { - let listener = TcpListener::bind(cfg.server.unwrap().listen).await?; + let server_config = cfg.server.unwrap(); + let listener = TcpListener::bind(server_config.listen).await?; info!("Server listening on {:?}", listener); let max_srv_name_length = cfg .service @@ -89,6 +91,7 @@ async fn server_main(cfg: config::Root) -> io::Result<()> { max_srv_name_length, services: cfg.service, allow_help: cfg.allow_help, + no_ack_extension: server_config.no_ack_extension, })); loop { let (sock, addr) = listener.accept().await?; @@ -97,6 +100,7 @@ async fn server_main(cfg: config::Root) -> io::Result<()> { } async fn client_server_main( + cfg: &'static client::SharedConfig, upstream_addr: &'static String, listener: TcpListener, service_name: &'static String, @@ -104,20 +108,32 @@ async fn client_server_main( loop { let (sock, addr) = listener.accept().await?; info!("Client connected: {}", addr); - tokio::spawn(client::handle_client(sock, upstream_addr, service_name)); + tokio::spawn(client::handle_client( + cfg, + sock, + upstream_addr, + service_name, + )); } } async fn client_main(cfg: config::Root) -> io::Result<()> { let mut fut_servers = Vec::new(); - let upstream_addr = Box::leak(Box::new(cfg.client.unwrap().addr)); + let client_cfg = cfg.client.unwrap(); + + let upstream_addr = Box::leak(Box::new(client_cfg.addr)); + + let shared_config = Box::leak(Box::new(client::SharedConfig { + no_ack: client_cfg.no_ack, + })); for s in cfg.service { let listener = TcpListener::bind(&s.addr).await?; info!("Server listening on {:?} (service {})", listener, &s.name); let service_name = Box::leak(Box::new(s.name)); fut_servers.push(tokio::spawn(client_server_main( + shared_config, upstream_addr, listener, service_name, |