diff --git a/Cargo.lock b/Cargo.lock index 7c6b9c6..99e697e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1206,6 +1206,8 @@ dependencies = [ "ptth_file_server", "ptth_server", "quic_demo", + "reqwest", + "rusty_ulid", "tokio", "tracing", "tracing-subscriber", diff --git a/crates/ptth_multi_call_server/Cargo.toml b/crates/ptth_multi_call_server/Cargo.toml index 5142e40..72affb4 100644 --- a/crates/ptth_multi_call_server/Cargo.toml +++ b/crates/ptth_multi_call_server/Cargo.toml @@ -6,11 +6,23 @@ edition = "2018" license = "AGPL-3.0" [dependencies] + +# Cookie 01FYZ3SDP2XABT7W19ACQVYKXT +# Dependencies should be in sync because ptth_multi_call_server intentionally +# tries to re-use as much code as possible between all of its subcommands, +# including ptth_server and ptth_file_server. + anyhow = "1.0.38" ctrlc = "3.2.1" ptth_file_server = { path = "../ptth_file_server_bin" } ptth_server = { path = "../ptth_server" } quic_demo = { path = "../../prototypes/quic_demo" } +rusty_ulid = "0.10.1" tokio = { version = "1.8.1", features = ["full"] } tracing-subscriber = "0.2.16" tracing = "0.1.25" + +[dependencies.reqwest] +version = "0.11.1" +default-features = false +features = ["stream", "rustls-tls", "hyper-rustls"] diff --git a/crates/ptth_multi_call_server/src/download.rs b/crates/ptth_multi_call_server/src/download.rs new file mode 100644 index 0000000..25891d5 --- /dev/null +++ b/crates/ptth_multi_call_server/src/download.rs @@ -0,0 +1,49 @@ +use std::{ + ffi::OsString, + time::Duration, +}; + +use anyhow::{ + anyhow, + bail, +}; + +pub async fn main (args: &[OsString]) -> anyhow::Result <()> { + let mut url = None; + let mut sha512 = None; + + let mut args = args [1..].into_iter (); + + loop { + let arg = match args.next () { + None => break, + Some (x) => x, + }; + + match arg.to_str ().ok_or_else (|| anyhow! ("All arguments must be valid UTF-8"))? + { + "--help" => println! ("For now, just look at the source code"), + "--sha512" => { + sha512 = args.next (); + } + arg => { + url = Some (arg); + break; + }, + } + } + + let url = match url { + None => bail! ("URL argument is required"), + Some (x) => x, + }; + + // Cookie 01FYZ3W64SM6KYNP48J6EWSCEF + // Try to keep the Clients similar here + + let client = reqwest::Client::builder () + .connect_timeout (Duration::from_secs (30)) + .build ()?; + + Ok (()) +} diff --git a/crates/ptth_multi_call_server/src/main.rs b/crates/ptth_multi_call_server/src/main.rs index dd14ce0..343f5bd 100644 --- a/crates/ptth_multi_call_server/src/main.rs +++ b/crates/ptth_multi_call_server/src/main.rs @@ -5,24 +5,32 @@ use std::{ use tokio::sync::watch; +mod download; +mod ulid; + #[derive (Clone, Copy, Debug, PartialEq)] enum Subcommand { + Download, PtthServer, PtthFileServer, PtthQuicEndServer, + Ulid, } #[tokio::main] async fn main () -> anyhow::Result <()> { + use Subcommand::*; + tracing_subscriber::fmt::init (); let args = Vec::from_iter (std::env::args_os ()); let (subcommand, args) = parse_args (&args)?; match subcommand { - Subcommand::PtthServer => ptth_server::executable::main (&args).await, - Subcommand::PtthFileServer => ptth_file_server::main (&args).await, - Subcommand::PtthQuicEndServer => { + Download => download::main (&args).await, + PtthServer => ptth_server::executable::main (&args).await, + PtthFileServer => ptth_file_server::main (&args).await, + PtthQuicEndServer => { let (shutdown_tx, shutdown_rx) = watch::channel (false); ctrlc::set_handler (move || { @@ -33,6 +41,7 @@ async fn main () -> anyhow::Result <()> { Ok (()) } + Ulid => ulid::main (&args).await, } } @@ -41,9 +50,11 @@ fn parse_subcommand (arg: &str) -> Option use Subcommand::*; let map = vec! [ + ("download", Download), ("ptth_server", PtthServer), ("ptth_file_server", PtthFileServer), ("ptth_quic_end_server", PtthQuicEndServer), + ("ulid", Ulid), ]; let arg = arg.strip_suffix (".exe").unwrap_or (arg); diff --git a/crates/ptth_multi_call_server/src/ulid.rs b/crates/ptth_multi_call_server/src/ulid.rs new file mode 100644 index 0000000..d22a7a7 --- /dev/null +++ b/crates/ptth_multi_call_server/src/ulid.rs @@ -0,0 +1,12 @@ +use std::{ + ffi::OsString, +}; + +use anyhow::Result; + +pub async fn main (args: &[OsString]) -> Result <()> +{ + println! ("{}", rusty_ulid::generate_ulid_string ()); + + Ok (()) +} diff --git a/crates/ptth_server/Cargo.toml b/crates/ptth_server/Cargo.toml index 7506a76..d7d2b43 100644 --- a/crates/ptth_server/Cargo.toml +++ b/crates/ptth_server/Cargo.toml @@ -13,6 +13,11 @@ default-run = "ptth_server" [dependencies] +# Cookie 01FYZ3SDP2XABT7W19ACQVYKXT +# Dependencies should be in sync because ptth_multi_call_server intentionally +# tries to re-use as much code as possible between all of its subcommands, +# including ptth_server and ptth_file_server. + aho-corasick = "0.7.15" anyhow = "1.0.38" arc-swap = "1.2.0" diff --git a/crates/ptth_server/src/lib.rs b/crates/ptth_server/src/lib.rs index 542adb7..4f8e26a 100644 --- a/crates/ptth_server/src/lib.rs +++ b/crates/ptth_server/src/lib.rs @@ -361,6 +361,9 @@ impl State { let mut headers = reqwest::header::HeaderMap::new (); headers.insert ("X-ApiKey", config_file.api_key.try_into ().map_err (ServerError::ApiKeyInvalid)?); + // Cookie 01FYZ3W64SM6KYNP48J6EWSCEF + // Try to keep the Clients similar here + let client = Client::builder () .default_headers (headers) .connect_timeout (Duration::from_secs (30)) diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 094d6ad..0000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -1.55.0