Compare commits
No commits in common. "cffb888ac846d6e2971214ef2d3e593476a440bc" and "931ad6d81b67cbfc62a9d20da7e641de33e2cac8" have entirely different histories.
cffb888ac8
...
931ad6d81b
|
@ -584,12 +584,6 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hex"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "0.2.5"
|
version = "0.2.5"
|
||||||
|
@ -1209,14 +1203,9 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"ctrlc",
|
"ctrlc",
|
||||||
"futures-util",
|
|
||||||
"hex",
|
|
||||||
"ptth_file_server",
|
"ptth_file_server",
|
||||||
"ptth_server",
|
"ptth_server",
|
||||||
"quic_demo",
|
"quic_demo",
|
||||||
"reqwest",
|
|
||||||
"rusty_ulid",
|
|
||||||
"sha2",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
@ -1785,9 +1774,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.9.9"
|
version = "0.9.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
|
checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"block-buffer 0.9.0",
|
"block-buffer 0.9.0",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
|
|
@ -6,26 +6,11 @@ edition = "2018"
|
||||||
license = "AGPL-3.0"
|
license = "AGPL-3.0"
|
||||||
|
|
||||||
[dependencies]
|
[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"
|
anyhow = "1.0.38"
|
||||||
ctrlc = "3.2.1"
|
ctrlc = "3.2.1"
|
||||||
futures-util = "0.3.9"
|
|
||||||
hex = "0.4.3"
|
|
||||||
ptth_file_server = { path = "../ptth_file_server_bin" }
|
ptth_file_server = { path = "../ptth_file_server_bin" }
|
||||||
ptth_server = { path = "../ptth_server" }
|
ptth_server = { path = "../ptth_server" }
|
||||||
quic_demo = { path = "../../prototypes/quic_demo" }
|
quic_demo = { path = "../../prototypes/quic_demo" }
|
||||||
rusty_ulid = "0.10.1"
|
|
||||||
sha2 = "0.9.8"
|
|
||||||
tokio = { version = "1.8.1", features = ["full"] }
|
tokio = { version = "1.8.1", features = ["full"] }
|
||||||
tracing-subscriber = "0.2.16"
|
tracing-subscriber = "0.2.16"
|
||||||
tracing = "0.1.25"
|
tracing = "0.1.25"
|
||||||
|
|
||||||
[dependencies.reqwest]
|
|
||||||
version = "0.11.1"
|
|
||||||
default-features = false
|
|
||||||
features = ["stream", "rustls-tls", "hyper-rustls"]
|
|
||||||
|
|
|
@ -1,122 +0,0 @@
|
||||||
use std::{
|
|
||||||
ffi::OsString,
|
|
||||||
io::{
|
|
||||||
self,
|
|
||||||
Write,
|
|
||||||
},
|
|
||||||
time::Duration,
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{
|
|
||||||
anyhow,
|
|
||||||
bail,
|
|
||||||
};
|
|
||||||
|
|
||||||
use futures_util::StreamExt;
|
|
||||||
|
|
||||||
use reqwest::{
|
|
||||||
StatusCode,
|
|
||||||
};
|
|
||||||
|
|
||||||
use sha2::{
|
|
||||||
Digest,
|
|
||||||
Sha512,
|
|
||||||
};
|
|
||||||
|
|
||||||
use tokio::{
|
|
||||||
sync::mpsc,
|
|
||||||
task::{
|
|
||||||
spawn,
|
|
||||||
spawn_blocking,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub async fn main (args: &[OsString]) -> anyhow::Result <()> {
|
|
||||||
let mut url = None;
|
|
||||||
let mut expected_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"),
|
|
||||||
"--expect-sha512" => {
|
|
||||||
let expected = args.next ().ok_or_else (|| anyhow! ("--expect-sha512 needs an argument"))?;
|
|
||||||
expected_sha512 = Some (expected.to_str ().ok_or_else (|| anyhow! ("--expect-sha512's argument must be valid Unicode"))?);
|
|
||||||
}
|
|
||||||
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 ()?;
|
|
||||||
|
|
||||||
let resp = client.get (url)
|
|
||||||
.send ().await?;
|
|
||||||
|
|
||||||
if resp.status () != StatusCode::OK {
|
|
||||||
bail! ("Expected 200 OK, got {}", resp.status ());
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut resp_stream = resp.bytes_stream ();
|
|
||||||
|
|
||||||
// The hasher is owned by a task because it makes ownership simpler
|
|
||||||
let (mut hash_tx, mut hash_rx) = mpsc::channel (1);
|
|
||||||
|
|
||||||
let hasher_task = spawn_blocking (move || {
|
|
||||||
let mut hasher = Sha512::new ();
|
|
||||||
|
|
||||||
while let Some (chunk) = tokio::runtime::Handle::current ().block_on (hash_rx.recv ()) {
|
|
||||||
hasher.update (&chunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
anyhow::Result::<_>::Ok (hasher.finalize ())
|
|
||||||
});
|
|
||||||
|
|
||||||
while let Some (chunk) = resp_stream.next ().await {
|
|
||||||
let chunk = chunk?;
|
|
||||||
|
|
||||||
hash_tx.send (chunk.clone ()).await?;
|
|
||||||
|
|
||||||
{
|
|
||||||
let chunk = chunk.clone ();
|
|
||||||
spawn_blocking (move || {
|
|
||||||
io::stdout ().write_all (&chunk)?;
|
|
||||||
anyhow::Result::<_>::Ok (())
|
|
||||||
}).await??;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
drop (hash_tx);
|
|
||||||
|
|
||||||
let hash = hasher_task.await??;
|
|
||||||
|
|
||||||
let actual_sha512 = hex::encode (&hash);
|
|
||||||
|
|
||||||
match expected_sha512 {
|
|
||||||
None => eprintln! ("Actual SHA512 = {}", actual_sha512),
|
|
||||||
Some (expected) => if ! actual_sha512.starts_with (&expected) {
|
|
||||||
bail! ("Expected SHA512 prefix {}, actual SHA512 {}", expected, actual_sha512);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok (())
|
|
||||||
}
|
|
|
@ -5,32 +5,24 @@ use std::{
|
||||||
|
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
|
|
||||||
mod download;
|
|
||||||
mod ulid;
|
|
||||||
|
|
||||||
#[derive (Clone, Copy, Debug, PartialEq)]
|
#[derive (Clone, Copy, Debug, PartialEq)]
|
||||||
enum Subcommand {
|
enum Subcommand {
|
||||||
Download,
|
|
||||||
PtthServer,
|
PtthServer,
|
||||||
PtthFileServer,
|
PtthFileServer,
|
||||||
PtthQuicEndServer,
|
PtthQuicEndServer,
|
||||||
Ulid,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main () -> anyhow::Result <()> {
|
async fn main () -> anyhow::Result <()> {
|
||||||
use Subcommand::*;
|
|
||||||
|
|
||||||
tracing_subscriber::fmt::init ();
|
tracing_subscriber::fmt::init ();
|
||||||
|
|
||||||
let args = Vec::from_iter (std::env::args_os ());
|
let args = Vec::from_iter (std::env::args_os ());
|
||||||
|
|
||||||
let (subcommand, args) = parse_args (&args)?;
|
let (subcommand, args) = parse_args (&args)?;
|
||||||
match subcommand {
|
match subcommand {
|
||||||
Download => download::main (&args).await,
|
Subcommand::PtthServer => ptth_server::executable::main (&args).await,
|
||||||
PtthServer => ptth_server::executable::main (&args).await,
|
Subcommand::PtthFileServer => ptth_file_server::main (&args).await,
|
||||||
PtthFileServer => ptth_file_server::main (&args).await,
|
Subcommand::PtthQuicEndServer => {
|
||||||
PtthQuicEndServer => {
|
|
||||||
let (shutdown_tx, shutdown_rx) = watch::channel (false);
|
let (shutdown_tx, shutdown_rx) = watch::channel (false);
|
||||||
|
|
||||||
ctrlc::set_handler (move || {
|
ctrlc::set_handler (move || {
|
||||||
|
@ -41,7 +33,6 @@ async fn main () -> anyhow::Result <()> {
|
||||||
|
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
Ulid => ulid::main (&args).await,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,11 +41,9 @@ fn parse_subcommand (arg: &str) -> Option <Subcommand>
|
||||||
use Subcommand::*;
|
use Subcommand::*;
|
||||||
|
|
||||||
let map = vec! [
|
let map = vec! [
|
||||||
("download", Download),
|
|
||||||
("ptth_server", PtthServer),
|
("ptth_server", PtthServer),
|
||||||
("ptth_file_server", PtthFileServer),
|
("ptth_file_server", PtthFileServer),
|
||||||
("ptth_quic_end_server", PtthQuicEndServer),
|
("ptth_quic_end_server", PtthQuicEndServer),
|
||||||
("ulid", Ulid),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let arg = arg.strip_suffix (".exe").unwrap_or (arg);
|
let arg = arg.strip_suffix (".exe").unwrap_or (arg);
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
use std::{
|
|
||||||
ffi::OsString,
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
|
|
||||||
pub async fn main (args: &[OsString]) -> Result <()>
|
|
||||||
{
|
|
||||||
println! ("{}", rusty_ulid::generate_ulid_string ());
|
|
||||||
|
|
||||||
Ok (())
|
|
||||||
}
|
|
|
@ -13,11 +13,6 @@ default-run = "ptth_server"
|
||||||
|
|
||||||
[dependencies]
|
[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"
|
aho-corasick = "0.7.15"
|
||||||
anyhow = "1.0.38"
|
anyhow = "1.0.38"
|
||||||
arc-swap = "1.2.0"
|
arc-swap = "1.2.0"
|
||||||
|
|
|
@ -361,9 +361,6 @@ impl State {
|
||||||
let mut headers = reqwest::header::HeaderMap::new ();
|
let mut headers = reqwest::header::HeaderMap::new ();
|
||||||
headers.insert ("X-ApiKey", config_file.api_key.try_into ().map_err (ServerError::ApiKeyInvalid)?);
|
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 ()
|
let client = Client::builder ()
|
||||||
.default_headers (headers)
|
.default_headers (headers)
|
||||||
.connect_timeout (Duration::from_secs (30))
|
.connect_timeout (Duration::from_secs (30))
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
1.55.0
|
Loading…
Reference in New Issue