Merge branch 'main' of ssh://virtusense-dev.com:2200/Trisha/ptth into main

main
Trisha Lefler 2022-10-25 10:31:08 -05:00
commit 7b9c6c7dc4
27 changed files with 538 additions and 204 deletions

264
Cargo.lock generated
View File

@ -272,7 +272,7 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1a816186fa68d9e426e3cb4ae4dff1fcd8e4a2c34b781bf7a822574a0d0aac8"
dependencies = [
"sct",
"sct 0.6.1",
]
[[package]]
@ -546,14 +546,14 @@ checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
dependencies = [
"cfg-if",
"libc",
"wasi",
"wasi 0.10.0+wasi-snapshot-preview1",
]
[[package]]
name = "h2"
version = "0.3.6"
version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c06815895acec637cd6ed6e9662c935b866d20a106f8361892893a7d9234964"
checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57"
dependencies = [
"bytes",
"fnv",
@ -564,7 +564,7 @@ dependencies = [
"indexmap",
"slab",
"tokio",
"tokio-util",
"tokio-util 0.7.1",
"tracing",
]
@ -620,7 +620,7 @@ checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b"
dependencies = [
"bytes",
"fnv",
"itoa",
"itoa 0.4.8",
]
[[package]]
@ -636,9 +636,9 @@ dependencies = [
[[package]]
name = "httparse"
version = "1.5.1"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503"
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
[[package]]
name = "httpdate"
@ -648,9 +648,9 @@ checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440"
[[package]]
name = "hyper"
version = "0.14.13"
version = "0.14.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15d1cfb9e4f68655fa04c01f59edb405b6074a0f7118ea881e5026e4a1cd8593"
checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac"
dependencies = [
"bytes",
"futures-channel",
@ -661,9 +661,9 @@ dependencies = [
"http-body",
"httparse",
"httpdate",
"itoa",
"itoa 1.0.1",
"pin-project-lite",
"socket2 0.4.2",
"socket2 0.4.4",
"tokio",
"tower-service",
"tracing",
@ -672,17 +672,15 @@ dependencies = [
[[package]]
name = "hyper-rustls"
version = "0.22.1"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64"
checksum = "d87c48c02e0dc5e3b849a2041db3029fd066650f8f717c07bf8ed78ccb895cac"
dependencies = [
"futures-util",
"http",
"hyper",
"log",
"rustls",
"rustls 0.20.4",
"tokio",
"tokio-rustls",
"webpki",
]
[[package]]
@ -719,15 +717,6 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "instant"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd"
dependencies = [
"cfg-if",
]
[[package]]
name = "ipnet"
version = "2.3.1"
@ -749,6 +738,12 @@ version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "itoa"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]]
name = "js-sys"
version = "0.3.55"
@ -766,15 +761,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.103"
version = "0.2.122"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6"
checksum = "ec647867e2bf0772e28c8bcde4f0d19a9216916e890543b5a03ed8ef27b8f259"
[[package]]
name = "lock_api"
version = "0.4.5"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109"
checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b"
dependencies = [
"scopeguard",
]
@ -851,6 +846,20 @@ dependencies = [
"winapi",
]
[[package]]
name = "mio"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9"
dependencies = [
"libc",
"log",
"miow",
"ntapi",
"wasi 0.11.0+wasi-snapshot-preview1",
"winapi",
]
[[package]]
name = "miow"
version = "0.3.7"
@ -982,27 +991,25 @@ dependencies = [
[[package]]
name = "parking_lot"
version = "0.11.2"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.8.5"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
checksum = "995f667a6c822200b0433ac218e05582f0e2efa1b922a3fd2fbaadc5f87bab37"
dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi",
"windows-sys",
]
[[package]]
@ -1236,6 +1243,7 @@ dependencies = [
"ptth_file_server",
"ptth_server",
"quic_demo",
"rand",
"reqwest",
"rusty_ulid",
"sha2",
@ -1407,14 +1415,14 @@ dependencies = [
"futures",
"lazy_static",
"libc",
"mio",
"mio 0.7.13",
"quinn-proto",
"rustls",
"rustls 0.19.1",
"socket2 0.3.19",
"thiserror",
"tokio",
"tracing",
"webpki",
"webpki 0.21.4",
]
[[package]]
@ -1427,13 +1435,13 @@ dependencies = [
"ct-logs",
"rand",
"ring",
"rustls",
"rustls 0.19.1",
"rustls-native-certs",
"slab",
"thiserror",
"tinyvec",
"tracing",
"webpki",
"webpki 0.21.4",
]
[[package]]
@ -1543,15 +1551,16 @@ dependencies = [
[[package]]
name = "reqwest"
version = "0.11.4"
version = "0.11.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22"
checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb"
dependencies = [
"base64",
"bytes",
"encoding_rs",
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"hyper",
@ -1565,12 +1574,15 @@ dependencies = [
"native-tls",
"percent-encoding",
"pin-project-lite",
"rustls",
"rustls 0.20.4",
"rustls-pemfile",
"serde",
"serde_json",
"serde_urlencoded",
"tokio",
"tokio-native-tls",
"tokio-rustls",
"tokio-util 0.6.8",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
@ -1658,8 +1670,20 @@ dependencies = [
"base64",
"log",
"ring",
"sct",
"webpki",
"sct 0.6.1",
"webpki 0.21.4",
]
[[package]]
name = "rustls"
version = "0.20.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fbfeb8d0ddb84706bc597a5574ab8912817c52a397f819e5b614e2265206921"
dependencies = [
"log",
"ring",
"sct 0.7.0",
"webpki 0.22.0",
]
[[package]]
@ -1669,11 +1693,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a07b7c1885bd8ed3831c289b7870b13ef46fe0e856d288c30d9cc17d75a2092"
dependencies = [
"openssl-probe",
"rustls",
"rustls 0.19.1",
"schannel",
"security-framework",
]
[[package]]
name = "rustls-pemfile"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ee86d63972a7c661d1536fefe8c3c8407321c3df668891286de28abcd087360"
dependencies = [
"base64",
]
[[package]]
name = "rusty_ulid"
version = "0.10.1"
@ -1727,6 +1760,16 @@ dependencies = [
"untrusted",
]
[[package]]
name = "sct"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4"
dependencies = [
"ring",
"untrusted",
]
[[package]]
name = "security-framework"
version = "2.3.1"
@ -1776,19 +1819,19 @@ version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8"
dependencies = [
"itoa",
"itoa 0.4.8",
"ryu",
"serde",
]
[[package]]
name = "serde_urlencoded"
version = "0.7.0"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9"
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
dependencies = [
"form_urlencoded",
"itoa",
"itoa 1.0.1",
"ryu",
"serde",
]
@ -1861,9 +1904,9 @@ dependencies = [
[[package]]
name = "socket2"
version = "0.4.2"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516"
checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0"
dependencies = [
"libc",
"winapi",
@ -1975,7 +2018,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
@ -1996,29 +2039,29 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.12.0"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc"
checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee"
dependencies = [
"autocfg",
"bytes",
"libc",
"memchr",
"mio",
"mio 0.8.2",
"num_cpus",
"once_cell",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2 0.4.4",
"tokio-macros",
"winapi",
]
[[package]]
name = "tokio-macros"
version = "1.4.1"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "154794c8f499c2619acd19e839294703e9e32e7630ef5f46ea80d4ef0fbee5eb"
checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7"
dependencies = [
"proc-macro2",
"quote",
@ -2037,13 +2080,13 @@ dependencies = [
[[package]]
name = "tokio-rustls"
version = "0.22.0"
version = "0.23.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6"
checksum = "4151fda0cf2798550ad0b34bcfc9b9dcc2a9d2471c895c68f3a8818e54f2389e"
dependencies = [
"rustls",
"rustls 0.20.4",
"tokio",
"webpki",
"webpki 0.22.0",
]
[[package]]
@ -2071,6 +2114,20 @@ dependencies = [
"tokio",
]
[[package]]
name = "tokio-util"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
"pin-project-lite",
"tokio",
"tracing",
]
[[package]]
name = "toml"
version = "0.5.8"
@ -2310,6 +2367,12 @@ version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.78"
@ -2317,8 +2380,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce"
dependencies = [
"cfg-if",
"serde",
"serde_json",
"wasm-bindgen-macro",
]
@ -2399,12 +2460,22 @@ dependencies = [
]
[[package]]
name = "webpki-roots"
version = "0.21.1"
name = "webpki"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940"
checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd"
dependencies = [
"webpki",
"ring",
"untrusted",
]
[[package]]
name = "webpki-roots"
version = "0.22.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf"
dependencies = [
"webpki 0.22.0",
]
[[package]]
@ -2439,10 +2510,53 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "winreg"
version = "0.7.0"
name = "windows-sys"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69"
checksum = "5acdd78cb4ba54c0045ac14f62d8f94a03d10047904ae2a40afa1e99d8f70825"
dependencies = [
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_msvc"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d"
[[package]]
name = "windows_i686_gnu"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed"
[[package]]
name = "windows_i686_msvc"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956"
[[package]]
name = "windows_x86_64_gnu"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4"
[[package]]
name = "windows_x86_64_msvc"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9"
[[package]]
name = "winreg"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
"winapi",
]

View File

@ -1,8 +1,8 @@
# https://whitfin.io/speeding-up-rust-docker-builds/
# TODO: https://stackoverflow.com/questions/57389547/how-to-define-the-context-for-a-docker-build-as-a-specific-commit-on-one-of-the
# rust:1.50-slim-buster
FROM rust@sha256:5dd85eb0c60bbdea14a6ecba1f6fe4a0f5c878bcf06d2cdfae0aff3a19ed4b10 as build
# rust:1.60-slim-buster
FROM rust@sha256:c0f26a0b299a8a74cd87be0b4bd291d55aa292198bab1bafd906edd8665edb82 as build
WORKDIR /
ENV USER root

View File

@ -1,6 +1,7 @@
#![warn (clippy::pedantic)]
use std::{
collections::*,
ffi::OsString,
net::SocketAddr,
path::{PathBuf},
@ -75,6 +76,7 @@ async fn handle_all (req: Request <Body>, state: Arc <FileServer>)
#[derive (Deserialize)]
struct ConfigFile {
file_server_root: Option <PathBuf>,
file_server_roots: Option <BTreeMap <String, PathBuf>>,
name: Option <String>,
}
@ -82,20 +84,25 @@ pub async fn main (_args: &[OsString]) -> anyhow::Result <()> {
let path = PathBuf::from ("./config/ptth_server.toml");
let file_server_root;
let file_server_roots;
let name;
match load_toml::load::<ConfigFile, _> (&path) {
Ok (config_file) => {
file_server_root = config_file.file_server_root;
file_server_roots = config_file.file_server_roots;
name = config_file.name;
},
_ => {
info! ("No ptth_server.toml file, using default configs");
file_server_root = None;
file_server_roots = None;
name = None;
},
};
let file_server_root = file_server_root.unwrap_or_else (|| PathBuf::from ("."));
let file_server_roots = file_server_roots.unwrap_or_else (|| Default::default ());
let name = name.unwrap_or_else (|| "PTTH File Server".to_string ());
info! ("file_server_root: {:?}", file_server_root);
@ -110,8 +117,13 @@ pub async fn main (_args: &[OsString]) -> anyhow::Result <()> {
file_server::metrics::Interval::monitor (interval_writer).await;
});
let config = file_server::Config {
file_server_root,
file_server_roots,
};
let state = Arc::new (FileServer::new (
file_server_root.unwrap_or_else (|| PathBuf::from (".")),
config,
&PathBuf::new (),
name,
metrics_interval,

View File

@ -19,6 +19,7 @@ hex = "0.4.3"
ptth_file_server = { path = "../ptth_file_server_bin" }
ptth_server = { path = "../ptth_server" }
quic_demo = { path = "../../prototypes/quic_demo" }
rand = "0.8.4"
rusty_ulid = "0.10.1"
sha2 = "0.9.8"
tokio = { version = "1.8.1", features = ["full"] }

View File

@ -0,0 +1,23 @@
use rand::Rng;
pub fn main () {
let wordlist = include_str! ("eff_short_wordlist_1.txt");
let words: Vec <_> = wordlist.split ('\n').take (1253).collect ();
assert_eq! (words.len (), 1253);
assert_eq! (words [0], "acid");
assert_eq! (words [600], "large");
assert_eq! (words [1252], "zoom");
let mut rng = rand::thread_rng ();
let random_words: Vec <&str> = (0..8)
.map (|_| {
words [rng.gen_range (0..words.len ())]
})
.collect ();
let passphrase = random_words.join (" ");
println! ("{}", passphrase);
}

View File

@ -26,7 +26,6 @@ use sha2::{
use tokio::{
sync::mpsc,
task::{
spawn,
spawn_blocking,
},
};
@ -35,7 +34,7 @@ pub async fn main (args: &[OsString]) -> anyhow::Result <()> {
let mut url = None;
let mut expected_sha512 = None;
let mut args = args [1..].into_iter ();
let mut args = args [1..].iter ();
loop {
let arg = match args.next () {
@ -79,7 +78,7 @@ pub async fn main (args: &[OsString]) -> anyhow::Result <()> {
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 (hash_tx, mut hash_rx) = mpsc::channel (1);
let hasher_task = spawn_blocking (move || {
let mut hasher = Sha512::new ();

View File

@ -5,11 +5,13 @@ use std::{
use tokio::sync::watch;
mod diceware;
mod download;
mod ulid;
#[derive (Clone, Copy, Debug, PartialEq)]
enum Subcommand {
Diceware,
Download,
PtthServer,
PtthFileServer,
@ -27,9 +29,13 @@ async fn main () -> anyhow::Result <()> {
let (subcommand, args) = parse_args (&args)?;
match subcommand {
Download => download::main (&args).await,
PtthServer => ptth_server::executable::main (&args).await,
PtthFileServer => ptth_file_server::main (&args).await,
Diceware => {
diceware::main ();
Ok (())
},
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);
@ -37,11 +43,11 @@ async fn main () -> anyhow::Result <()> {
shutdown_tx.send (true).expect ("Couldn't forward Ctrl+C signal");
})?;
tracing::trace! ("Set Ctrl+C handler");
quic_demo::executable_end_server::main (&args, Some (shutdown_rx)).await?;
quic_demo::executable_end_server::main (args, Some (shutdown_rx)).await?;
Ok (())
}
Ulid => ulid::main (&args).await,
Ulid => ulid::main (args).await,
}
}
@ -50,6 +56,7 @@ fn parse_subcommand (arg: &str) -> Option <Subcommand>
use Subcommand::*;
let map = vec! [
("diceware", Diceware),
("download", Download),
("ptth_server", PtthServer),
("ptth_file_server", PtthFileServer),

View File

@ -4,7 +4,7 @@ use std::{
use anyhow::Result;
pub async fn main (args: &[OsString]) -> Result <()>
pub async fn main (_args: &[OsString]) -> Result <()>
{
println! ("{}", rusty_ulid::generate_ulid_string ());

View File

@ -20,7 +20,7 @@ futures = "0.3.7"
futures-util = "0.3.8"
handlebars = "3.5.3"
http = "0.2.3"
hyper = { version = "0.14.4", features = ["http1", "server", "stream", "tcp"] }
hyper = { version = "0.14.20", features = ["http1", "http2", "server", "stream", "tcp"] }
itertools = "0.9.0"
rand = "0.8.3"
rmp-serde = "0.15.5"

View File

@ -143,6 +143,7 @@ pub mod file {
pub scraper_keys: Option <Vec <ScraperKey>>,
pub news_url: Option <String>,
pub hide_audit_log: Option <bool>,
}
}
@ -156,6 +157,7 @@ pub struct Config {
pub servers: HashMap <String, file::Server>,
pub scraper_keys: HashMap <String, ScraperKey>,
pub news_url: Option <String>,
pub hide_audit_log: bool,
}
impl Default for Config {
@ -167,6 +169,7 @@ impl Default for Config {
servers: Default::default (),
scraper_keys: Default::default (),
news_url: None,
hide_audit_log: false,
}
}
}
@ -195,6 +198,7 @@ impl TryFrom <file::Config> for Config {
servers,
scraper_keys,
news_url: f.news_url,
hide_audit_log: f.hide_audit_log.unwrap_or (false),
})
}
}

View File

@ -121,6 +121,9 @@ async fn handle_http_request (
{
use RequestError::*;
let req_id = rusty_ulid::generate_ulid_string ();
debug! ("Created request {}", req_id);
let req_method = req.method.clone ();
if ! state.server_exists (server_name).await {
@ -132,9 +135,14 @@ async fn handle_http_request (
let (tx, rx) = oneshot::channel ();
let tx = relay_state::ResponseRendezvous {
timeout: Instant::now () + Duration::from_secs (120),
tx,
};
let req_id = rusty_ulid::generate_ulid_string ();
trace! ("Created request {}", req_id);
debug! ("Forwarding {}", req_id);
{
let response_rendezvous = state.response_rendezvous.read ().await;
@ -433,6 +441,13 @@ async fn handle_audit_log (
handlebars: Arc <Handlebars <'static>>
) -> Result <Response <Body>, RequestError>
{
{
let cfg = state.config.read ().await;
if cfg.hide_audit_log {
return Ok (error_reply (StatusCode::FORBIDDEN, "Forbidden")?);
}
}
let page = handle_audit_log_internal (state).await;
let s = handlebars.render ("audit_log", &page)?;
@ -781,6 +796,45 @@ pub async fn run_relay (
});
}
// Set a task to periodically sweep and time-out requests where the client
// and server are never going to rendezvous
let state_2 = Arc::clone (&state);
tokio::spawn (async move {
let mut interval = tokio::time::interval (Duration::from_secs (60));
interval.set_missed_tick_behavior (tokio::time::MissedTickBehavior::Skip);
loop {
use std::convert::TryFrom;
use rusty_ulid::Ulid;
interval.tick ().await;
{
let timeout_ms = Utc::now ().timestamp () - 120_000;
if let Ok (timeout_ms) = u64::try_from (timeout_ms) {
let timeout_ulid = Ulid::from_timestamp_with_rng (timeout_ms, &mut rand::thread_rng ()).to_string ();
let mut request_rendezvous = state_2.request_rendezvous.lock ().await;
request_rendezvous.iter_mut ()
.for_each (|(k, v)| {
match v {
RequestRendezvous::ParkedServer (_) => (),
RequestRendezvous::ParkedClients (requests) => requests.retain (|req| req.id.as_str () >= timeout_ulid.as_str ()),
}
});
}
}
{
let now = Instant::now ();
let response_rendezvous = state_2.response_rendezvous.read ().await;
response_rendezvous.retain (|_, v| v.timeout >= now);
}
}
});
let make_svc = make_service_fn (|_conn| {
let state = state.clone ();
let handlebars = handlebars.clone ();
@ -839,7 +893,7 @@ pub async fn run_relay (
std::mem::swap (&mut swapped, &mut response_rendezvous);
for (_, sender) in swapped {
sender.send (Err (ShuttingDown)).ok ();
sender.tx.send (Err (ShuttingDown)).ok ();
}
let mut request_rendezvous = state.request_rendezvous.lock ().await;

View File

@ -61,7 +61,10 @@ pub enum RequestRendezvous {
ParkedServer (oneshot::Sender <Result <http_serde::WrappedRequest, ShuttingDownError>>),
}
type ResponseRendezvous = oneshot::Sender <Result <(http_serde::ResponseParts, Body), ShuttingDownError>>;
pub (crate) struct ResponseRendezvous {
pub timeout: Instant,
pub tx: oneshot::Sender <Result <(http_serde::ResponseParts, Body), ShuttingDownError>>,
}
#[derive (Clone)]
pub struct ServerStatus {

View File

@ -119,6 +119,21 @@ pub async fn v1_server_list (state: &Relay)
}
}
fn get_api_key (headers: &hyper::HeaderMap) -> Option <&str>
{
if let Some (key) = headers.get ("X-ApiKey").and_then (|v| v.to_str ().ok ()) {
return Some (key);
}
if let Some (s) = headers.get ("Authorization").and_then (|v| v.to_str ().ok ()) {
if let Some (key) = s.strip_prefix ("Bearer ") {
return Some (key);
}
}
None
}
#[instrument (level = "trace", skip (req, state))]
async fn api_v1 (
req: Request <Body>,
@ -132,7 +147,7 @@ async fn api_v1 (
AuditEvent,
};
let api_key = req.headers ().get ("X-ApiKey");
let api_key = get_api_key (req.headers ());
let api_key = match api_key {
None => return Ok (error_reply (StatusCode::FORBIDDEN, strings::NO_API_KEY)?),
@ -176,7 +191,10 @@ async fn api_v1 (
path: path_rest.to_string (),
})).await;
if path_rest == "test" {
if path_rest == "metrics" {
Ok (metrics (req, state).await?)
}
else if path_rest == "test" {
Ok (error_reply (StatusCode::OK, "You're valid!")?)
}
else if path_rest == "server_list" {
@ -205,6 +223,65 @@ async fn api_v1 (
}
}
#[instrument (level = "trace", skip (req, state))]
async fn metrics (
req: Request <Body>,
state: &Relay,
)
-> Result <Response <Body>, RequestError>
{
let mut s = String::with_capacity (4 * 1_024);
let mut push_metric = |name, help, kind, value| {
if let Some (help) = help {
s.push_str (format! ("# HELP {} {}\n", name, help).as_str ());
}
s.push_str (format! ("# TYPE {} {}\n", name, kind).as_str ());
s.push_str (format! ("{} {}\n", name, value).as_str ());
};
let request_rendezvous_count = {
let g = state.request_rendezvous.lock ().await;
g.len ()
};
let server_status_count;
let connected_server_count;
let now = Utc::now ();
{
let g = state.server_status.lock ().await;
server_status_count = g.len ();
connected_server_count = g.iter ()
.filter (|(_, s)| now - s.last_seen < chrono::Duration::seconds (60))
.count ();
}
let response_rendezvous_count = {
let g = state.response_rendezvous.read ().await;
g.len ()
};
push_metric ("request_rendezvous_count", None, "gauge", request_rendezvous_count.to_string ());
push_metric ("server_status_count", None, "gauge", server_status_count.to_string ());
push_metric ("connected_server_count", None, "gauge", connected_server_count.to_string ());
push_metric ("response_rendezvous_count", None, "gauge", response_rendezvous_count.to_string ());
#[cfg (target_os = "linux")]
{
if let Some (rss) = tokio::fs::read_to_string ("/proc/self/status").await
.ok ()
.and_then (|s| get_rss_from_status (s.as_str ()))
{
push_metric ("relay_vm_rss", Some ("VmRSS of the relay process, in kB"), "gauge", rss.to_string ());
}
}
Ok (Response::builder ()
.body (Body::from (s))?)
}
#[instrument (level = "trace", skip (req, state))]
pub async fn handle (
req: Request <Body>,
@ -230,6 +307,20 @@ pub async fn handle (
}
}
fn get_rss_from_status (proc_status: &str) -> Option <u64>
{
use std::str::FromStr;
for line in proc_status.lines () {
if let Some (rest) = line.strip_prefix ("VmRSS:\t").and_then (|s| s.strip_suffix (" kB"))
{
return u64::from_str (rest.trim_start ()).ok ();
}
}
None
}
#[cfg (test)]
mod tests {
use std::{
@ -246,8 +337,9 @@ mod tests {
struct TestCase {
// Inputs
path_rest: &'static str,
auth_header: Option <&'static str>,
valid_key: Option <&'static str>,
input_key: Option <&'static str>,
x_api_key: Option <&'static str>,
// Expected
expected_status: StatusCode,
@ -268,9 +360,15 @@ mod tests {
x
}
fn input_key (&self, v: Option <&'static str>) -> Self {
fn auth_header (&self, v: Option <&'static str>) -> Self {
let mut x = self.clone ();
x.input_key = v;
x.auth_header = v;
x
}
fn x_api_key (&self, v: Option <&'static str>) -> Self {
let mut x = self.clone ();
x.x_api_key = v;
x
}
@ -298,13 +396,16 @@ mod tests {
.expected_body (format! ("{}\n", body))
}
async fn test (&self) {
async fn test (&self, name: &str) {
let mut input = Request::builder ()
.method ("GET")
.uri (format! ("http://127.0.0.1:4000/scraper/{}", self.path_rest));
if let Some (input_key) = self.input_key {
input = input.header ("X-ApiKey", input_key);
if let Some (auth_header) = self.auth_header {
input = input.header ("Authorization", auth_header);
}
if let Some (x_api_key) = self.x_api_key {
input = input.header ("X-ApiKey", x_api_key);
}
let input = input.body (Body::empty ()).unwrap ();
@ -331,15 +432,15 @@ mod tests {
expected_headers.insert (*key, (*value).try_into ().expect ("Couldn't convert header value"));
}
assert_eq! (actual_head.status, self.expected_status);
assert_eq! (actual_head.headers, expected_headers);
assert_eq! (actual_head.status, self.expected_status, "{}", name);
assert_eq! (actual_head.headers, expected_headers, "{}", name);
let actual_body = hyper::body::to_bytes (actual_body).await;
let actual_body = actual_body.expect ("Body should be convertible to bytes");
let actual_body = actual_body.to_vec ();
let actual_body = String::from_utf8 (actual_body).expect ("Body should be UTF-8");
assert_eq! (actual_body, self.expected_body);
assert_eq! (actual_body, self.expected_body, "{}", name);
}
}
@ -351,7 +452,8 @@ mod tests {
let base_case = TestCase {
path_rest: "v1/test",
valid_key: Some ("bogus"),
input_key: Some ("bogus"),
auth_header: None,
x_api_key: Some ("bogus"),
expected_status: StatusCode::OK,
expected_headers: vec! [
("content-type", "text/plain"),
@ -359,21 +461,47 @@ mod tests {
expected_body: "You're valid!\n".to_string (),
};
for case in &[
base_case.clone (),
base_case.path_rest ("v9999/test")
.expected (StatusCode::NOT_FOUND, strings::UNKNOWN_API_VERSION),
base_case.valid_key (None)
.expected (StatusCode::FORBIDDEN, strings::FORBIDDEN),
base_case.input_key (Some ("borgus"))
.expected (StatusCode::FORBIDDEN, strings::FORBIDDEN),
base_case.path_rest ("v1/toast")
.expected (StatusCode::NOT_FOUND, strings::UNKNOWN_API_ENDPOINT),
base_case.input_key (None)
.expected (StatusCode::FORBIDDEN, strings::NO_API_KEY),
] {
case.test ().await;
}
base_case
.test ("00").await;
base_case
.path_rest ("v9999/test")
.expected (StatusCode::NOT_FOUND, strings::UNKNOWN_API_VERSION)
.test ("01").await;
base_case
.valid_key (None)
.expected (StatusCode::FORBIDDEN, strings::FORBIDDEN)
.test ("02").await;
base_case
.x_api_key (Some ("borgus"))
.expected (StatusCode::FORBIDDEN, strings::FORBIDDEN)
.test ("03").await;
base_case
.path_rest ("v1/toast")
.expected (StatusCode::NOT_FOUND, strings::UNKNOWN_API_ENDPOINT)
.test ("04").await;
base_case
.x_api_key (None)
.expected (StatusCode::FORBIDDEN, strings::NO_API_KEY)
.test ("05").await;
base_case
.x_api_key (None)
.auth_header (Some ("Bearer bogus"))
.expected (StatusCode::OK, "You're valid!")
.test ("06").await;
});
}
#[test]
fn rss () {
let input = "VmHWM: 584 kB\nVmRSS: 584 kB\nRssAnon: 68 kB\n";
assert_eq! (get_rss_from_status (input), Some (584));
}
}

View File

@ -188,7 +188,7 @@ pub async fn handle_response (
};
// UKAUFFY4 (Send half)
if tx.send (Ok ((resp_parts, body))).is_err () {
if tx.tx.send (Ok ((resp_parts, body))).is_err () {
let msg = "Failed to connect to client";
error! (msg);
return Ok (error_reply (StatusCode::BAD_GATEWAY, msg)?);

View File

@ -39,7 +39,7 @@ serde = {version = "1.0.117", features = ["derive"]}
serde_json = "1.0.60"
structopt = "0.3.20"
thiserror = "1.0.24"
tokio = { version = "1.8.1", features = [] }
tokio = { version = "1.17.0", features = [] }
tokio-stream = "0.1.3"
tracing = "0.1.25"
tracing-futures = "0.2.5"
@ -50,7 +50,7 @@ always_equal = { path = "../always_equal", version = "1.0.0" }
ptth_core = { path = "../ptth_core", version = "2.0.0" }
[dependencies.reqwest]
version = "0.11.1"
version = "0.11.10"
default-features = false
features = ["stream", "rustls-tls", "hyper-rustls"]

File diff suppressed because one or more lines are too long

View File

@ -167,14 +167,16 @@ async fn serve_file (
let content_length = range.end - range.start;
let body = if decision.should_send_body {
debug! ("Sending range {}-{}", range.start, range.end);
trace! ("Sending range {}-{}", range.start, range.end);
let seek = SeekFrom::Start (range.start);
f.seek (seek).await?;
let (tx, rx) = channel (1);
tokio::spawn (async move {
debug! ("stream_file task begin");
stream_file (f, content_length, tx).await;
debug! ("stream_file task end");
});
Some (rx)
@ -219,6 +221,8 @@ async fn serve_file (
response.header ("content-type".into (), b"application/javascript".to_vec ());
}
response.header ("content-length".into (), content_length.to_string ().into_bytes ());
response.content_length = Some (content_length);
if let Some (body) = body {

View File

@ -67,29 +67,25 @@ fn file_server () {
let rt = Runtime::new ().expect ("Can't create runtime");
rt.block_on (async {
let file_server_root = PathBuf::from ("./");
let files_root = PathBuf::from ("./");
let dirs_roots = Default::default ();
let roots = internal::FileRoots {
files: &files_root,
dirs: &dirs_roots,
};
let headers = Default::default ();
{
use internal::Response::*;
use crate::file_server::FileServerError;
let bad_passwords_path = "/files/src/bad_passwords.txt";
for (uri_path, expected) in vec! [
("/", Root),
("/files", NotFound),
("/files/?", InvalidQuery),
("/files/src", Redirect ("src/".to_string ())),
("/files/src/?", InvalidQuery),
(bad_passwords_path, ServeFile (internal::ServeFileParams {
send_body: true,
range: range::ValidParsed {
range: 0..1_048_576,
range_requested: false,
},
file: AlwaysEqual::testing_blank (),
})),
("/files/test/test.md", ServeFile (internal::ServeFileParams {
send_body: true,
range: range::ValidParsed {
@ -100,7 +96,7 @@ fn file_server () {
})),
] {
let resp = internal::serve_all (
&file_server_root,
roots,
Method::Get,
uri_path,
&headers,
@ -117,7 +113,7 @@ fn file_server () {
}),
] {
let resp = internal::serve_all (
&file_server_root,
roots,
Method::Get,
uri_path,
&headers,
@ -126,35 +122,6 @@ fn file_server () {
checker (resp.unwrap_err ());
}
let resp = internal::serve_all (
&file_server_root,
Method::Get,
bad_passwords_path,
&hashmap! {
"range".into () => b"bytes=0-2000000".to_vec (),
},
None
).await;
assert_eq! (resp.expect ("Should be Ok (_)"), RangeNotSatisfiable (1_048_576));
let resp = internal::serve_all (
&file_server_root,
Method::Head,
bad_passwords_path,
&headers,
None
).await;
assert_eq! (resp.expect ("Should be Ok (_)"), ServeFile (internal::ServeFileParams {
send_body: false,
range: range::ValidParsed {
range: 0..1_048_576,
range_requested: false,
},
file: AlwaysEqual::testing_blank (),
}));
}
});
}

View File

@ -180,7 +180,10 @@ SH: Send + FnMut () -> H
let f = handler (parts);
let response = f.await?;
handle_one_req (&state, req_id, response).await
let output = handle_one_req (&state, req_id.clone (), response).await;
debug! ("Req {} task exiting", req_id);
output
});
}
@ -221,6 +224,8 @@ pub struct ConfigFile {
pub client_keys: HashSet <String>,
pub allow_any_client: bool,
pub index_directories: bool,
}
impl ConfigFile {
@ -235,6 +240,7 @@ impl ConfigFile {
throttle_upload: false,
client_keys: Default::default (),
allow_any_client: true,
index_directories: true,
}
}
@ -278,6 +284,7 @@ impl Builder {
throttle_upload: false,
client_keys: Default::default (),
allow_any_client: true,
index_directories: true,
};
Self {
@ -382,6 +389,7 @@ impl State {
let client = Client::builder ()
.default_headers (headers)
.timeout (Duration::from_secs (7 * 86400))
.connect_timeout (Duration::from_secs (30))
.build ().map_err (ServerError::CantBuildHttpClient)?;
@ -455,7 +463,7 @@ impl State {
}
}
debug! ("http_listen {}...", i);
trace! ("http_listen {}...", i);
let http_listen_fut = Self::http_listen (state);
@ -478,7 +486,7 @@ impl State {
Ok (x) => x,
};
debug! ("http_listen {} unwrapped {} requests", i, reqs.len ());
trace! ("http_listen {} unwrapped {} requests", i, reqs.len ());
// Unpack the requests, spawn them into new tasks, then loop back
// around.
@ -506,6 +514,7 @@ impl State {
pub mod executable {
use std::{
collections::*,
path::{Path, PathBuf},
};
use structopt::StructOpt;
@ -540,20 +549,21 @@ pub mod executable {
}
};
let file_server_roots = config_file.file_server_roots
.unwrap_or_else (|| Default::default ());
// `git grep JRY5NXZU` # duplicated code?
let config_file = super::ConfigFile {
name: opt.name.or (config_file.name).ok_or (anyhow::anyhow! ("`name` must be provided in command line or config file"))?,
api_key: config_file.api_key,
relay_url: opt.relay_url.or (config_file.relay_url).ok_or (anyhow::anyhow! ("`--relay-url` must be provided in command line or `relay_url` in config file"))?,
file_server_root: opt.file_server_root.or (config_file.file_server_root).unwrap_or_else (PathBuf::new),
file_server_roots: vec! [
("c", "C:/"),
("d", "D:/"),
].into_iter ()
.map (|(k, v)| (String::from (k), PathBuf::from (v)))
.collect (),
file_server_roots,
throttle_upload: opt.throttle_upload,
allow_any_client: true,
client_keys: Default::default (),
index_directories: config_file.index_directories.unwrap_or (true),
};
if opt.print_tripcode {
@ -606,6 +616,8 @@ pub mod executable {
pub api_key: String,
pub relay_url: Option <String>,
pub file_server_root: Option <PathBuf>,
pub file_server_roots: Option <BTreeMap <String, PathBuf>>,
pub index_directories: Option <bool>,
}
fn gen_and_save_key (path: &Path) -> anyhow::Result <()> {

View File

@ -8,7 +8,7 @@ edition = "2018"
anyhow = "1.0.38"
fltk = "1.3.1"
serde = {version = "1.0.117", features = ["derive"]}
tokio = "1.4.0"
tokio = "1.17.0"
tracing = "0.1.25"
tracing-subscriber = "0.2.16"

View File

@ -57,10 +57,10 @@ fn main ()
let (hit_tx, mut hit_rx) = mpsc::channel (1);
{
let fltk_tx = fltk_tx.clone ();
let fltk_tx = fltk_tx;
rt.spawn (async move {
while let Some (_) = hit_rx.recv ().await {
while hit_rx.recv ().await.is_some () {
fltk_tx.send (Message::Hit);
}
});
@ -89,6 +89,8 @@ fn main ()
},
};
// `git grep JRY5NXZU` # duplicated code?
let config_file = ptth_server::ConfigFile {
name: gui.input_name.value ().to_string (),
api_key: gui.input_api_key.value ().to_string (),
@ -98,6 +100,7 @@ fn main ()
throttle_upload: false,
client_keys: Default::default (),
allow_any_client: true,
index_directories: true,
};
let hit_tx = hit_tx.clone ();

View File

@ -115,7 +115,7 @@ AIABAACAAQAAgAEAAIABAACAAQAAgAEAAIABAACAAQAA" rel="icon" type="image/x-icon" />
{{#each entries}}
<tr>
<td><a class="entry" href="{{this.encoded_file_name}}{{this.trailing_slash}}">
<td><a class="entry" href="./{{this.encoded_file_name}}{{this.trailing_slash}}">
{{this.icon}} {{this.file_name}}{{this.trailing_slash}}</a></td>
<td><span class="grey">{{this.size}}</span></td>
</tr>

View File

@ -96,7 +96,7 @@ impl GuiClient <'_> {
port_idx: usize,
) -> anyhow::Result <()>
{
self.ports [port_idx].open_port (&self.rt, connection_p2_p3)?;
self.ports [port_idx].open_port (self.rt, connection_p2_p3)?;
self.sync_status ();
Ok (())
@ -142,9 +142,9 @@ impl GuiClient <'_> {
return;
}
let mut gui = GuiPort::new (fltk_tx, self.ports.len ());
let gui = GuiPort::new (fltk_tx, self.ports.len ());
ports_col.add (&gui.row);
ports_col.set_size (&mut gui.row, 30);
ports_col.set_size (&gui.row, 30);
let port = Port {
gui,
@ -175,21 +175,21 @@ fn main () -> anyhow::Result <()> {
let mut col = Flex::default ().column ().size_of_parent ();
let mut frame_status = Frame::default ();
col.set_size (&mut frame_status, 30);
let frame_status = Frame::default ();
col.set_size (&frame_status, 30);
{
let mut row = Flex::default ().row ();
let mut l = Frame::default ().with_label ("Server ID");
row.set_size (&mut l, 120);
let mut l = Frame::default ().with_label ("Server port");
row.set_size (&mut l, 80);
let mut l = Frame::default ().with_label ("Local port");
row.set_size (&mut l, 80);
let l = Frame::default ().with_label ("Server ID");
row.set_size (&l, 120);
let l = Frame::default ().with_label ("Server port");
row.set_size (&l, 80);
let l = Frame::default ().with_label ("Local port");
row.set_size (&l, 80);
row.end ();
col.set_size (&mut row, 30);
col.set_size (&row, 30);
}
let mut ports_col = Flex::default ().column ();
@ -198,7 +198,7 @@ fn main () -> anyhow::Result <()> {
let mut but_add_port = Button::default ().with_label ("+");
but_add_port.set_trigger (CallbackTrigger::Release);
but_add_port.emit (fltk_tx, Message::AddPort);
col.set_size (&mut but_add_port, 30);
col.set_size (&but_add_port, 30);
col.end ();
@ -286,11 +286,11 @@ impl GuiPort {
let mut but_open = Button::default ().with_label ("Open");
let mut but_close = Button::default ().with_label ("Close");
row.set_size (&mut input_server_id, 120);
row.set_size (&mut input_server_port, 80);
row.set_size (&mut input_client_port, 80);
row.set_size (&mut but_open, 80);
row.set_size (&mut but_close, 80);
row.set_size (&input_server_id, 120);
row.set_size (&input_server_port, 80);
row.set_size (&input_client_port, 80);
row.set_size (&but_open, 80);
row.set_size (&but_close, 80);
input_client_port.set_value ("");
input_client_port.set_readonly (true);
@ -389,7 +389,7 @@ mod test {
let port = rng.gen_range (tcp_eph_range);
assert_eq! (port, 49408);
for (input, expected) in vec! [
for (input, expected) in [
(("127.0.0.1:4000", "bogus_server", 22), 51168),
// The relay address is explicitly excluded from the eph port
// computation in case I want to support connecting to a server

View File

@ -17,9 +17,13 @@ hyper = { version = "0.14.4", features = ["http1", "server", "stream", "tcp"] }
quinn = "0.7.2"
rand = "0.8.4"
rcgen = "0.8.11"
reqwest = "0.11.4"
rmp-serde = "0.15.5"
structopt = "0.3.20"
tokio = { version = "1.8.1", features = ["full"] }
tracing-subscriber = "0.2.16"
tracing = "0.1.25"
[dependencies.reqwest]
version = "0.11.10"
default-features = false
features = ["stream", "rustls-tls", "hyper-rustls"]

View File

@ -77,7 +77,7 @@ async fn main () -> anyhow::Result <()> {
let (stop_server_tx, stop_server_rx) = oneshot::channel ();
let task_server = {
spawn (async move {
ptth_server::run_server (config_file, stop_server_rx, None, None).await
ptth_server::run_server (config_file, stop_server_rx, None, None, None).await
})
};
@ -99,7 +99,7 @@ async fn main () -> anyhow::Result <()> {
let resp = client.get (&format! ("{}/frontend/servers/{}/files/COPYING", relay_url, server_name))
.send ().await.expect ("Couldn't find license").bytes ().await.expect ("Couldn't find license");
if blake3::hash (&resp) != blake3::Hash::from ([
if blake3::hash (&resp) != [
0xca, 0x02, 0x92, 0x78,
0x9c, 0x0a, 0x0e, 0xcb,
0xa7, 0x06, 0xf4, 0xb3,
@ -109,7 +109,7 @@ async fn main () -> anyhow::Result <()> {
0xc1, 0xd4, 0x32, 0xc5,
0x2c, 0x4a, 0xac, 0x1f,
0x1a, 0xbb, 0xa8, 0xef,
]) {
] {
panic! ("{}", String::from_utf8 (resp.to_vec ()).expect ("???"));
}

View File

@ -45,7 +45,7 @@ async fn testing_client_checks (
.send ();
let resp = tokio::time::timeout (Duration::from_secs (2), req).await.expect ("Request timed out").expect ("Couldn't find license").bytes ().await.expect ("Couldn't find license");
if blake3::hash (&resp) != blake3::Hash::from ([
if blake3::hash (&resp) != [
0xca, 0x02, 0x92, 0x78,
0x9c, 0x0a, 0x0e, 0xcb,
0xa7, 0x06, 0xf4, 0xb3,
@ -55,7 +55,7 @@ async fn testing_client_checks (
0xc1, 0xd4, 0x32, 0xc5,
0x2c, 0x4a, 0xac, 0x1f,
0x1a, 0xbb, 0xa8, 0xef,
]) {
] {
panic! ("{}", String::from_utf8 (resp.to_vec ()).expect ("???"));
}
@ -151,7 +151,7 @@ impl TestingServer {
let (stop_tx, stop_rx) = oneshot::channel ();
let task = {
spawn (async move {
ptth_server::run_server (config_file, stop_rx, None, None).await
ptth_server::run_server (config_file, stop_rx, None, None, None).await
})
};