diff --git a/Cargo.lock b/Cargo.lock index 274dee2..dcb8f5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1202,6 +1202,18 @@ dependencies = [ "tokio", ] +[[package]] +name = "ptth_multi_call_server" +version = "0.1.0" +dependencies = [ + "anyhow", + "ptth_server", + "quic_demo", + "tokio", + "tracing", + "tracing-subscriber", +] + [[package]] name = "ptth_quic_client_gui" version = "0.1.0" diff --git a/crates/ptth_core/src/prelude.rs b/crates/ptth_core/src/prelude.rs index 4a2b7d2..d674eeb 100644 --- a/crates/ptth_core/src/prelude.rs +++ b/crates/ptth_core/src/prelude.rs @@ -1,4 +1,5 @@ pub use std::{ + ffi::OsString, io::Write, sync::Arc, time::{Duration, Instant}, diff --git a/crates/ptth_multi_call_server/Cargo.toml b/crates/ptth_multi_call_server/Cargo.toml new file mode 100644 index 0000000..0313b6b --- /dev/null +++ b/crates/ptth_multi_call_server/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ptth_multi_call_server" +version = "0.1.0" +authors = ["Trish"] +edition = "2018" +license = "AGPL-3.0" + +[dependencies] +anyhow = "1.0.38" +ptth_server = { path = "../ptth_server" } +quic_demo = { path = "../../prototypes/quic_demo" } +tokio = { version = "1.8.1", features = ["full"] } +tracing-subscriber = "0.2.16" +tracing = "0.1.25" diff --git a/crates/ptth_multi_call_server/src/main.rs b/crates/ptth_multi_call_server/src/main.rs new file mode 100644 index 0000000..607d046 --- /dev/null +++ b/crates/ptth_multi_call_server/src/main.rs @@ -0,0 +1,51 @@ +use std::{ + iter::FromIterator, +}; + +enum Subcommand { + PtthServer, + PtthQuicEndServer, +} + +fn parse_subcommand (name: &str) -> Option +{ + if name.ends_with ("ptth_server") || name.ends_with ("ptth_server.exe") + { + Some (Subcommand::PtthServer) + } + else if name.ends_with ("ptth_quic_end_server") || name.ends_with ("ptth_quic_end_server.exe") + { + Some (Subcommand::PtthQuicEndServer) + } + else { + None + } +} + +#[tokio::main] +async fn main () -> anyhow::Result <()> { + tracing_subscriber::fmt::init (); + + let args = Vec::from_iter (std::env::args_os ()); + + let arg_0 = args [0].to_str ().expect ("exe name should be valid UTF-8"); + match parse_subcommand (arg_0) { + Some (Subcommand::PtthServer) => return ptth_server::executable::main (&args).await, + Some (Subcommand::PtthQuicEndServer) => return quic_demo::executable_end_server::main (&args).await, + _ => (), + } + + let arg_1 = match args.get (1) { + Some (x) => x, + None => anyhow::bail! ("Subcommand must be the first argument if it's not the exe name"), + }; + + let arg_1 = arg_1.to_str ().expect ("subcommand should be valid UTF-8"); + match parse_subcommand (arg_1) { + Some (Subcommand::PtthServer) => return ptth_server::executable::main (&args [1..]).await, + Some (Subcommand::PtthQuicEndServer) => return quic_demo::executable_end_server::main (&args [1..]).await, + _ => (), + } + + anyhow::bail! ("Subcommand should be provided in exe name or first argument, e.g. `./ptth_multi_call_server ptth_server`"); +} diff --git a/crates/ptth_server/src/bin/ptth_server.rs b/crates/ptth_server/src/bin/ptth_server.rs index a069c0a..a03af00 100644 --- a/crates/ptth_server/src/bin/ptth_server.rs +++ b/crates/ptth_server/src/bin/ptth_server.rs @@ -1,10 +1,12 @@ -#![warn (clippy::pedantic)] +use std::{ + iter::FromIterator, +}; #[tokio::main] async fn main () -> anyhow::Result <()> { tracing_subscriber::fmt::init (); - let args = std::env::args_os (); + let args = Vec::from_iter (std::env::args_os ()); - ptth_server::executable::main (args).await + ptth_server::executable::main (&args).await } diff --git a/crates/ptth_server/src/lib.rs b/crates/ptth_server/src/lib.rs index 0d3455c..8b55936 100644 --- a/crates/ptth_server/src/lib.rs +++ b/crates/ptth_server/src/lib.rs @@ -490,7 +490,7 @@ pub mod executable { prelude::*, }; - pub async fn main (args: std::env::ArgsOs) -> anyhow::Result <()> { + pub async fn main (args: &[OsString]) -> anyhow::Result <()> { let opt = Opt::from_iter (args); let asset_root = opt.asset_root; diff --git a/prototypes/quic_demo/src/bin/quic_demo_end_server.rs b/prototypes/quic_demo/src/bin/quic_demo_end_server.rs index 86c3cc8..f2d9f75 100644 --- a/prototypes/quic_demo/src/bin/quic_demo_end_server.rs +++ b/prototypes/quic_demo/src/bin/quic_demo_end_server.rs @@ -1,8 +1,12 @@ +use std::{ + iter::FromIterator, +}; + #[tokio::main] async fn main () -> anyhow::Result <()> { tracing_subscriber::fmt::init (); - let args = std::env::args_os (); + let args = Vec::from_iter (std::env::args_os ()); - quic_demo::executable_end_server::main (args).await + quic_demo::executable_end_server::main (&args).await } diff --git a/prototypes/quic_demo/src/executable_end_server.rs b/prototypes/quic_demo/src/executable_end_server.rs index 62804ac..bcadac4 100644 --- a/prototypes/quic_demo/src/executable_end_server.rs +++ b/prototypes/quic_demo/src/executable_end_server.rs @@ -16,7 +16,7 @@ struct Opt { cert_url: Option , } -pub async fn main (args: std::env::ArgsOs) -> anyhow::Result <()> { +pub async fn main (args: &[OsString]) -> anyhow::Result <()> { let opt = Arc::new (Opt::from_iter (args)); let server_cert = match opt.cert_url.as_ref () { diff --git a/prototypes/quic_demo/src/prelude.rs b/prototypes/quic_demo/src/prelude.rs index 03fc349..7515241 100644 --- a/prototypes/quic_demo/src/prelude.rs +++ b/prototypes/quic_demo/src/prelude.rs @@ -1,5 +1,6 @@ pub use std::{ collections::*, + ffi::OsString, net::SocketAddr, sync::{ Arc,