From b187ac7850680d2586402ec05ab97bd93832eeb4 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 17 Oct 2023 07:13:43 +1100 Subject: [PATCH] feat(connlib): gzip encode log files (#2345) Resolves: #2342. Co-authored-by: Jamil --- rust/Cargo.lock | 33 ++++++++++++++++++++++ rust/connlib/clients/shared/Cargo.toml | 1 + rust/connlib/clients/shared/src/control.rs | 8 +++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index d50d2cb83..54766f413 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -281,6 +281,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "async-compression" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f658e2baef915ba0f26f1f7c42bfb8e12f532a01f449a090ded75ae7a07e9ba2" +dependencies = [ + "flate2", + "futures-core", + "memchr", + "pin-project-lite", + "tokio", +] + [[package]] name = "async-trait" version = "0.1.73" @@ -792,6 +805,7 @@ name = "connlib-client-shared" version = "1.20231001.0" dependencies = [ "anyhow", + "async-compression", "async-trait", "backoff", "chrono", @@ -916,6 +930,15 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "crossbeam-channel" version = "0.5.8" @@ -1295,6 +1318,16 @@ dependencies = [ "wintun", ] +[[package]] +name = "flate2" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" diff --git a/rust/connlib/clients/shared/Cargo.toml b/rust/connlib/clients/shared/Cargo.toml index bd2dd9235..14f9f904e 100644 --- a/rust/connlib/clients/shared/Cargo.toml +++ b/rust/connlib/clients/shared/Cargo.toml @@ -26,6 +26,7 @@ url = { version = "2.4.1", features = ["serde"] } time = { version = "0.3.29", features = ["formatting"] } reqwest = { version = "0.11.22", default-features = false, features = ["stream", "rustls-tls"] } tokio-tungstenite = { version = "0.20", default-features = false, features = ["connect", "handshake", "rustls-tls-webpki-roots"] } +async-compression = { version = "0.4.3", features = ["tokio", "gzip"] } [target.'cfg(target_os = "android")'.dependencies] tracing = { workspace = true, features = ["std", "attributes"] } diff --git a/rust/connlib/clients/shared/src/control.rs b/rust/connlib/clients/shared/src/control.rs index ed22a1f03..250cd11c9 100644 --- a/rust/connlib/clients/shared/src/control.rs +++ b/rust/connlib/clients/shared/src/control.rs @@ -1,3 +1,4 @@ +use async_compression::tokio::bufread::GzipEncoder; use std::path::PathBuf; use std::{io, sync::Arc}; @@ -15,6 +16,8 @@ use connlib_shared::{ use async_trait::async_trait; use firezone_tunnel::{ClientState, ControlSignal, Request, Tunnel}; +use reqwest::header::{CONTENT_ENCODING, CONTENT_TYPE}; +use tokio::io::BufReader; use tokio::sync::Mutex; use tokio_util::codec::{BytesCodec, FramedRead}; use url::Url; @@ -301,10 +304,13 @@ async fn upload(path: PathBuf, url: Url) -> io::Result<()> { tracing::info!(path = %path.display(), %url, "Uploading log file"); let file = tokio::fs::File::open(&path).await?; + let response = reqwest::Client::new() .put(url) + .header(CONTENT_TYPE, "text/plain") + .header(CONTENT_ENCODING, "gzip") .body(reqwest::Body::wrap_stream(FramedRead::new( - file, + GzipEncoder::new(BufReader::new(file)), BytesCodec::default(), ))) .send()