add the multi-call server

This exe can act as both a PTTH and PTTH_QUIC end server.
It's only 17 MB, which is a big improvement over the 15 + 15 for shipping both servers as their own exes
main
_ 2021-10-02 18:13:14 +00:00
parent 97fc2c74d4
commit f44613540e
9 changed files with 92 additions and 7 deletions

12
Cargo.lock generated
View File

@ -1202,6 +1202,18 @@ dependencies = [
"tokio", "tokio",
] ]
[[package]]
name = "ptth_multi_call_server"
version = "0.1.0"
dependencies = [
"anyhow",
"ptth_server",
"quic_demo",
"tokio",
"tracing",
"tracing-subscriber",
]
[[package]] [[package]]
name = "ptth_quic_client_gui" name = "ptth_quic_client_gui"
version = "0.1.0" version = "0.1.0"

View File

@ -1,4 +1,5 @@
pub use std::{ pub use std::{
ffi::OsString,
io::Write, io::Write,
sync::Arc, sync::Arc,
time::{Duration, Instant}, time::{Duration, Instant},

View File

@ -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"

View File

@ -0,0 +1,51 @@
use std::{
iter::FromIterator,
};
enum Subcommand {
PtthServer,
PtthQuicEndServer,
}
fn parse_subcommand (name: &str) -> Option <Subcommand>
{
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`");
}

View File

@ -1,10 +1,12 @@
#![warn (clippy::pedantic)] use std::{
iter::FromIterator,
};
#[tokio::main] #[tokio::main]
async fn main () -> anyhow::Result <()> { async fn main () -> anyhow::Result <()> {
tracing_subscriber::fmt::init (); 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
} }

View File

@ -490,7 +490,7 @@ pub mod executable {
prelude::*, 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 opt = Opt::from_iter (args);
let asset_root = opt.asset_root; let asset_root = opt.asset_root;

View File

@ -1,8 +1,12 @@
use std::{
iter::FromIterator,
};
#[tokio::main] #[tokio::main]
async fn main () -> anyhow::Result <()> { async fn main () -> anyhow::Result <()> {
tracing_subscriber::fmt::init (); 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
} }

View File

@ -16,7 +16,7 @@ struct Opt {
cert_url: Option <String>, cert_url: Option <String>,
} }
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 opt = Arc::new (Opt::from_iter (args));
let server_cert = match opt.cert_url.as_ref () { let server_cert = match opt.cert_url.as_ref () {

View File

@ -1,5 +1,6 @@
pub use std::{ pub use std::{
collections::*, collections::*,
ffi::OsString,
net::SocketAddr, net::SocketAddr,
sync::{ sync::{
Arc, Arc,