From 258c2212381cfa16b6216b09847aeab400a73b90 Mon Sep 17 00:00:00 2001 From: Nikolay Govorov Date: Fri, 16 Jan 2026 23:47:04 +0000 Subject: Rename 'upstream' to 'proxy' module, update deps --- Cargo.lock | 224 ++++++++++++++++++++++++++++++++++++-------- Cargo.toml | 66 +++++++++---- src/backends/zig.rs | 8 +- src/main.rs | 10 +- src/proxy.rs | 60 ++++++++++++ src/upstream.rs | 60 ------------ 6 files changed, 303 insertions(+), 125 deletions(-) create mode 100644 src/proxy.rs delete mode 100644 src/upstream.rs diff --git a/Cargo.lock b/Cargo.lock index e3c104a..466689b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -207,17 +207,33 @@ checksum = "fef252edff26ddba56bbcdf2ee3307b8129acb86f5749b68990c168a6fcc9c76" dependencies = [ "axum", "axum-core", + "axum-macros", "bytes", + "fastrand", + "form_urlencoded", "futures-core", "futures-util", + "headers", "http", "http-body", "http-body-util", "mime", + "multer", + "percent-encoding", "pin-project-lite", + "prost", + "rustversion", + "serde_core", + "serde_html_form", + "serde_json", + "serde_path_to_error", + "tokio", + "tokio-stream", + "tokio-util", "tower-layer", "tower-service", "tracing", + "typed-json", ] [[package]] @@ -438,9 +454,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.52" +version = "1.2.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd4932aefd12402b36c60956a4fe0035421f544799057659ff86f923657aada3" +checksum = "755d2fce177175ffca841e9a06afdb2c4ab0f593d53b4dee48147dfaade85932" dependencies = [ "find-msvc-tools", "jobserver", @@ -478,13 +494,14 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chrono" -version = "0.4.42" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" dependencies = [ "iana-time-zone", "js-sys", "num-traits", + "serde", "wasm-bindgen", "windows-link", ] @@ -525,9 +542,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.6" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" +checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32" [[package]] name = "clru" @@ -903,9 +920,9 @@ dependencies = [ [[package]] name = "find-msvc-tools" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f449e6c6c08c865631d4890cfacf252b3d396c9bcc83adb6623cdb02a8336c41" +checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db" [[package]] name = "fixedbitset" @@ -1945,6 +1962,40 @@ dependencies = [ "hashbrown 0.15.5", ] +[[package]] +name = "hdrhistogram" +version = "7.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d" +dependencies = [ + "byteorder", + "num-traits", +] + +[[package]] +name = "headers" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3314d5adb5d94bcdf56771f2e50dbbc80bb4bdf88967526706205ac9eff24eb" +dependencies = [ + "base64", + "bytes", + "headers-core", + "http", + "httpdate", + "mime", + "sha1", +] + +[[package]] +name = "headers-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54b4a22553d4242c49fddb9ba998a99962b5cc6f22cb5a3482bec22522403ce4" +dependencies = [ + "http", +] + [[package]] name = "heapless" version = "0.8.0" @@ -2119,9 +2170,12 @@ dependencies = [ "percent-encoding", "pin-project-lite", "socket2", + "system-configuration", "tokio", + "tower-layer", "tower-service", "tracing", + "windows-registry", ] [[package]] @@ -2292,6 +2346,15 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.17" @@ -2373,9 +2436,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.83" +version = "0.3.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8" +checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3" dependencies = [ "once_cell", "wasm-bindgen", @@ -2942,6 +3005,29 @@ dependencies = [ "parking_lot", ] +[[package]] +name = "prost" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ea70524a2f82d518bce41317d0fae74151505651af45faf1ffbd6fd33f0568" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "quick-xml" version = "0.37.5" @@ -3195,9 +3281,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.13.2" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e6f2ab2928ca4291b86736a8bd920a277a399bba1589409d72154ff87c1282" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" dependencies = [ "zeroize", ] @@ -3231,9 +3317,9 @@ checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" [[package]] name = "rustls-webpki" -version = "0.103.8" +version = "0.103.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" dependencies = [ "ring", "rustls-pki-types", @@ -3395,6 +3481,19 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_html_form" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2f2d7ff8a2140333718bb329f5c40fc5f0865b84c426183ce14c97d2ab8154f" +dependencies = [ + "form_urlencoded", + "indexmap", + "itoa", + "ryu", + "serde_core", +] + [[package]] name = "serde_json" version = "1.0.149" @@ -3913,6 +4012,27 @@ dependencies = [ "syn", ] +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation 0.9.4", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tame-index" version = "0.26.0" @@ -4036,30 +4156,30 @@ dependencies = [ [[package]] name = "time" -version = "0.3.44" +version = "0.3.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" +checksum = "f9e442fc33d7fdb45aa9bfeb312c095964abdf596f7567261062b2a7107aaabd" dependencies = [ "deranged", "itoa", "num-conv", "powerfmt", - "serde", + "serde_core", "time-core", "time-macros", ] [[package]] name = "time-core" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" +checksum = "8b36ee98fd31ec7426d599183e8fe26932a8dc1fb76ddb6214d05493377d34ca" [[package]] name = "time-macros" -version = "0.2.24" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" +checksum = "71e552d1249bf61ac2a52db88179fd0673def1e1ad8243a00d9ec9ed71fee3dd" dependencies = [ "num-conv", "time-core", @@ -4219,9 +4339,13 @@ checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" dependencies = [ "futures-core", "futures-util", + "hdrhistogram", + "indexmap", "pin-project-lite", + "slab", "sync_wrapper", "tokio", + "tokio-util", "tower-layer", "tower-service", "tracing", @@ -4357,6 +4481,16 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea3136b675547379c4bd395ca6b938e5ad3c3d20fad76e7fe85f9e0d011419c" +[[package]] +name = "typed-json" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6024a8d0025400b3f6b189366e9aa92012cf9c4fe1cd2620848dd61425c49eed" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "typenum" version = "1.19.0" @@ -4496,9 +4630,9 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasip2" -version = "1.0.1+wasi-0.2.4" +version = "1.0.2+wasi-0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" dependencies = [ "wit-bindgen", ] @@ -4511,9 +4645,9 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.106" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd" +checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566" dependencies = [ "cfg-if", "once_cell", @@ -4524,11 +4658,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.56" +version = "0.4.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836d9622d604feee9e5de25ac10e3ea5f2d65b41eac0d9ce72eb5deae707ce7c" +checksum = "70a6e77fd0ae8029c9ea0063f87c46fde723e7d887703d74ad2616d792e51e6f" dependencies = [ "cfg-if", + "futures-util", "js-sys", "once_cell", "wasm-bindgen", @@ -4537,9 +4672,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.106" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3" +checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4547,9 +4682,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.106" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40" +checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55" dependencies = [ "bumpalo", "proc-macro2", @@ -4560,18 +4695,18 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.106" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4" +checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12" dependencies = [ "unicode-ident", ] [[package]] name = "web-sys" -version = "0.3.83" +version = "0.3.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac" +checksum = "312e32e551d92129218ea9a2452120f4aabc03529ef03e4d0d82fb2780608598" dependencies = [ "js-sys", "wasm-bindgen", @@ -4668,6 +4803,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link", + "windows-result", + "windows-strings", +] + [[package]] name = "windows-result" version = "0.4.1" @@ -4985,9 +5131,9 @@ dependencies = [ [[package]] name = "wit-bindgen" -version = "0.46.0" +version = "0.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" [[package]] name = "writeable" @@ -5125,9 +5271,9 @@ checksum = "40990edd51aae2c2b6907af74ffb635029d5788228222c4bb811e9351c0caad3" [[package]] name = "zmij" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac93432f5b761b22864c774aac244fa5c0fd877678a4c37ebf6cf42208f9c9ec" +checksum = "bd8f3f50b848df28f887acb68e41201b5aea6bc8a8dacc00fb40635ff9a72fea" [[package]] name = "zorian" diff --git a/Cargo.toml b/Cargo.toml index 6a541e1..f157487 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,30 +9,58 @@ homepage = "https://pkg.earth" repository = "https://github.com/mrdimidium/Zorian" [dependencies] -axum = { version = "0.8.8", features = ["http2", "macros", "multipart"] } -axum-extra = "0.12.5" -bytes = "1.11.0" -chrono = "0.4" -crc32fast = "1.4.2" +axum = { version = "0.8", features = ["http2", "macros", "multipart"] } +axum-extra = { version = "0.12", features = [ + "async-read-body", + "attachment", + "cached", + "erased-json", + "error-response", + "file-stream", + "form", + "handler", + "json-deserializer", + "json-lines", + "middleware", + "multipart", + "optional-path", + "protobuf", + "query", + "routing", + "tracing", + "typed-header", + "typed-routing", + "with-rejection", +] } +bytes = "1.11" +chrono = { version = "0.4", features = ["serde"] } +crc32fast = "1.5" hex = "0.4" -http-body-util = "0.1.3" -hyper = "1.8.1" -hyper-tls = "0.6.0" -hyper-util = { version = "0.1.19", features = ["client", "http1", "http2", "tokio"] } -minijinja = "2.14.0" +http-body-util = "0.1" +hyper = "1.8" +hyper-tls = "0.6" +hyper-util = { version = "0.1", features = ["full"] } +minijinja = "2.14" semver = "1.0" serde = { version = "1.0", features = ["derive"] } -sqlx = { version = "0.8.6", features = ["sqlite", "runtime-tokio", "macros", "derive", "chrono", "json"] } +sqlx = { version = "0.8", features = [ + "sqlite", + "runtime-tokio", + "macros", + "derive", + "chrono", + "json", +] } thiserror = "2.0" -tokio = { version = "1.49.0", features = ["full"] } -toml = "0.9.8" -tower = "0.5.3" -tower-http = { version = "0.6.8", features = ["full"] } +tokio = { version = "1.49", features = ["full"] } +toml = "0.9" +tower = { version = "0.5", features = ["full"] } +tower-http = { version = "0.6", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } -uuid = { version = "1.19.0", features = ["v4","v5"] } +uuid = { version = "1.19", features = ["v4", "v5"] } [dev-dependencies] -cargo-deny = "0.19.0" -cargo-llvm-cov = "0.6.23" -tempfile = "3" +cargo-deny = "0.19" +cargo-llvm-cov = "0.6" +tempfile = "3.24" diff --git a/src/backends/zig.rs b/src/backends/zig.rs index 44ac3bc..ed22326 100644 --- a/src/backends/zig.rs +++ b/src/backends/zig.rs @@ -9,8 +9,8 @@ use thiserror::Error; use tracing::error; use crate::config; +use crate::proxy; use crate::storage; -use crate::upstream; #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum Archive { @@ -150,14 +150,14 @@ impl<'a> Tarball<'a> { pub struct ZigController { config: Arc, storage: Arc, - upstream: Arc, + upstream: Arc, } impl ZigController { pub fn new( config: Arc, storage: Arc, - upstream: Arc, + upstream: Arc, ) -> Self { Self { config, @@ -195,7 +195,7 @@ impl ZigController { let entry = controller .upstream - .fetch(upstream::DownloadRequest { url }) + .fetch(proxy::DownloadRequest { url }) .await?; match controller.storage.put("zig", &filename, &entry.bytes).await { diff --git a/src/main.rs b/src/main.rs index c8f593a..1aa8951 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,8 @@ mod backends; mod config; +mod proxy; mod storage; -mod upstream; use std::future::Future; use std::path::PathBuf; @@ -93,7 +93,7 @@ async fn main() { }); let storage = Arc::new(storage::StorageService::new(config.clone()).await.unwrap()); - let upstream = Arc::new(upstream::UpstreamService::new()); + let upstream = Arc::new(proxy::ProxyService::new()); let web_controller = Arc::new(WebController::default()); let zig_controller = Arc::new(ZigController::new( @@ -167,7 +167,11 @@ where } fn call(&mut self, req: Request) -> Self::Future { - Box::pin(log_request(self.inner.clone(), req)) + let clone = self.inner.clone(); + + // take the service that was ready + let inner = std::mem::replace(&mut self.inner, clone); + Box::pin(async move { log_request(inner, req).await }) } } diff --git a/src/proxy.rs b/src/proxy.rs new file mode 100644 index 0000000..444ffaa --- /dev/null +++ b/src/proxy.rs @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-License-Identifier: AGPL-3.0-or-later + +use bytes::Bytes; +use http_body_util::{BodyExt, Empty}; +use hyper::{Request, http}; +use hyper_tls::HttpsConnector; +use hyper_util::client::legacy::{Client, connect::HttpConnector}; +use hyper_util::rt::TokioExecutor; + +#[derive(Clone)] +pub struct DownloadRequest { + pub url: String, +} + +#[derive(Clone)] +pub struct File { + pub bytes: Bytes, +} + +pub struct ProxyService { + client: Client, Empty>, +} + +impl ProxyService { + pub fn new() -> Self { + let https = HttpsConnector::new(); + let client = Client::builder(TokioExecutor::new()).build(https); + Self { client } + } + + pub async fn fetch(&self, request: DownloadRequest) -> Result { + let request = Request::builder() + .method(http::Method::GET) + .uri(&request.url) + .header(http::header::USER_AGENT, "zorian/0.1") + .body(Empty::::new()) + .unwrap(); + + let response = self + .client + .request(request) + .await + .map_err(|_| http::StatusCode::GATEWAY_TIMEOUT)?; + + let (parts, body) = response.into_parts(); + let status = parts.status; + if !status.is_success() { + return Err(status); + } + + let bytes = body + .collect() + .await + .map_err(|_| http::StatusCode::GATEWAY_TIMEOUT)? + .to_bytes(); + + Ok(File { bytes }) + } +} diff --git a/src/upstream.rs b/src/upstream.rs deleted file mode 100644 index da25a7d..0000000 --- a/src/upstream.rs +++ /dev/null @@ -1,60 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov -// SPDX-License-Identifier: AGPL-3.0-or-later - -use bytes::Bytes; -use http_body_util::{BodyExt, Empty}; -use hyper::{Request, http}; -use hyper_tls::HttpsConnector; -use hyper_util::client::legacy::{Client, connect::HttpConnector}; -use hyper_util::rt::TokioExecutor; - -#[derive(Clone)] -pub struct DownloadRequest { - pub url: String, -} - -#[derive(Clone)] -pub struct File { - pub bytes: Bytes, -} - -pub struct UpstreamService { - client: Client, Empty>, -} - -impl UpstreamService { - pub fn new() -> Self { - let https = HttpsConnector::new(); - let client = Client::builder(TokioExecutor::new()).build(https); - Self { client } - } - - pub async fn fetch(&self, request: DownloadRequest) -> Result { - let request = Request::builder() - .method(http::Method::GET) - .uri(&request.url) - .header(http::header::USER_AGENT, "zorian/0.1") - .body(Empty::::new()) - .unwrap(); - - let response = self - .client - .request(request) - .await - .map_err(|_| http::StatusCode::GATEWAY_TIMEOUT)?; - - let (parts, body) = response.into_parts(); - let status = parts.status; - if !status.is_success() { - return Err(status); - } - - let bytes = body - .collect() - .await - .map_err(|_| http::StatusCode::GATEWAY_TIMEOUT)? - .to_bytes(); - - Ok(File { bytes }) - } -} -- Gilti