diff --git a/Cargo.toml b/Cargo.toml index 440e284..5ef4f3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ aho-corasick = "0.7.14" base64 = "0.12.3" blake3 = "0.3.7" chrono = "0.4.19" -dashmap = "3.11.10" futures = "0.3.7" handlebars = "3.5.1" http = "0.2.1" @@ -30,7 +29,6 @@ reqwest = { version = "0.10.8", features = ["stream"] } rmp-serde = "0.14.4" serde = {version = "1.0.117", features = ["derive"]} structopt = "0.3.20" -thiserror = "1.0.22" tokio = { version = "0.2.22", features = ["full"] } tracing = "0.1.21" tracing-futures = "0.2.4" @@ -41,6 +39,7 @@ url = "2.2.0" always_equal = { path = "crates/always_equal" } ptth_core = { path = "crates/ptth_core" } +ptth_relay = { path = "crates/ptth_relay" } [workspace] diff --git a/crates/ptth_core/src/lib.rs b/crates/ptth_core/src/lib.rs index 2cc81b7..dd92c18 100644 --- a/crates/ptth_core/src/lib.rs +++ b/crates/ptth_core/src/lib.rs @@ -2,6 +2,13 @@ pub mod graceful_shutdown; pub mod http_serde; pub mod prelude; +// It's easier if the server can stream its response body +// back to the relay un-changed inside its request body +// So we wrap the server's actual response head +// (status code, headers, etc.) in this one header field. + +pub const PTTH_MAGIC_HEADER: &str = "X-PTTH-2LJYXWC4"; + // The arguments are in order so they are in order overall: // e.g. prefix_match ("/prefix", "/prefix/middle/suffix") -> "/middle/suffix" diff --git a/crates/ptth_relay/Cargo.toml b/crates/ptth_relay/Cargo.toml new file mode 100644 index 0000000..938364f --- /dev/null +++ b/crates/ptth_relay/Cargo.toml @@ -0,0 +1,30 @@ +[package] + +name = "ptth_relay" +version = "0.1.0" +authors = ["Trish"] +edition = "2018" +license = "AGPL-3.0" + +[dependencies] + +base64 = "0.12.3" +blake3 = "0.3.7" +chrono = "0.4.19" +dashmap = "3.11.10" +futures = "0.3.7" +handlebars = "3.5.1" +http = "0.2.1" +hyper = "0.13.8" +itertools = "0.9.0" +rmp-serde = "0.14.4" +serde = {version = "1.0.117", features = ["derive"]} +thiserror = "1.0.22" +tokio = { version = "0.2.22", features = ["full"] } +toml = "0.5.7" +tracing = "0.1.21" +tracing-futures = "0.2.4" +tracing-subscriber = "0.2.15" +ulid = "0.4.1" + +ptth_core = { path = "../ptth_core" } diff --git a/src/relay/config.rs b/crates/ptth_relay/src/config.rs similarity index 100% rename from src/relay/config.rs rename to crates/ptth_relay/src/config.rs diff --git a/src/relay/git_version.rs b/crates/ptth_relay/src/git_version.rs similarity index 100% rename from src/relay/git_version.rs rename to crates/ptth_relay/src/git_version.rs diff --git a/src/relay/mod.rs b/crates/ptth_relay/src/lib.rs similarity index 99% rename from src/relay/mod.rs rename to crates/ptth_relay/src/lib.rs index 3dd53ac..306ebff 100644 --- a/src/relay/mod.rs +++ b/crates/ptth_relay/src/lib.rs @@ -256,7 +256,7 @@ async fn handle_http_response ( -> Response
{ let (parts, mut body) = req.into_parts (); - let resp_parts: http_serde::ResponseParts = rmp_serde::from_read_ref (&base64::decode (parts.headers.get (crate::PTTH_MAGIC_HEADER).unwrap ()).unwrap ()).unwrap (); + let resp_parts: http_serde::ResponseParts = rmp_serde::from_read_ref (&base64::decode (parts.headers.get (ptth_core::PTTH_MAGIC_HEADER).unwrap ()).unwrap ()).unwrap (); // Intercept the body packets here so we can check when the stream // ends or errors out diff --git a/src/bin/ptth_relay.rs b/crates/ptth_relay/src/main.rs similarity index 83% rename from src/bin/ptth_relay.rs rename to crates/ptth_relay/src/main.rs index 112c665..663ae44 100644 --- a/src/bin/ptth_relay.rs +++ b/crates/ptth_relay/src/main.rs @@ -11,10 +11,11 @@ use tracing_subscriber::{ EnvFilter, }; -use ptth::relay; -use ptth::relay::{ +use ptth_relay::{ Config, + git_version::GIT_VERSION, RelayState, + run_relay, }; #[tokio::main] @@ -28,12 +29,12 @@ async fn main () -> Result <(), Box