From 2b437c65fb3091c74a028edd39e31676d2dda09d Mon Sep 17 00:00:00 2001 From: Ara Sadoyan Date: Tue, 27 Jan 2026 16:19:51 +0100 Subject: [PATCH] Performance improvement. String removal from hot paths. --- Cargo.lock | 616 +++++++++++++++++++++++---------------- Cargo.toml | 16 +- src/utils/auth.rs | 11 +- src/utils/httpclient.rs | 33 +-- src/utils/kuberconsul.rs | 18 +- src/utils/parceyaml.rs | 17 +- src/utils/structs.rs | 10 +- src/utils/tools.rs | 16 +- src/web/proxyhttp.rs | 82 ++++-- 9 files changed, 461 insertions(+), 358 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 47c7ae8..ee5ffe3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -262,9 +262,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "aws-lc-rs" -version = "1.13.3" +version = "1.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c953fe1ba023e6b7730c0d4b031d06f267f23a46167dcbd40316644b10a17ba" +checksum = "7b7b6141e96a8c160799cc2d5adecd5cbbe5054cb8c7c4af53da0f83bb7ad256" dependencies = [ "aws-lc-sys", "untrusted 0.7.1", @@ -273,11 +273,10 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.30.0" +version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbfd150b5dbdb988bcc8fb1fe787eb6b7ee6180ca24da683b61ea5405f3d43ff" +checksum = "5c34dda4df7017c8db52132f0f8a2e0f8161649d15723ed63fc00c82d0f2081a" dependencies = [ - "bindgen", "cc", "cmake", "dunce", @@ -286,9 +285,9 @@ dependencies = [ [[package]] name = "axum" -version = "0.8.7" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b098575ebe77cb6d14fc7f32749631a6e44edbef6b796f89b020e99ba20d425" +checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8" dependencies = [ "axum-core", "bytes", @@ -375,9 +374,9 @@ dependencies = [ [[package]] name = "base16ct" -version = "0.3.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b59d472eab27ade8d770dcb11da7201c11234bef9f82ce7aa517be028d462b" +checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6" [[package]] name = "base64" @@ -385,29 +384,6 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" -[[package]] -name = "bindgen" -version = "0.69.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" -dependencies = [ - "bitflags 2.8.0", - "cexpr", - "clang-sys", - "itertools", - "lazy_static", - "lazycell", - "log", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn 2.0.100", - "which", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -497,23 +473,21 @@ checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "cc" -version = "1.2.10" +version = "1.2.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13208fcbb66eaeffe09b99fffbe1af420f00a7b35aa99ad683dfc1aa76145229" +checksum = "6354c81bbfd62d9cfa9cb3c773c2b7b2a3a482d569de977fd0e961f6e7c00583" dependencies = [ + "find-msvc-tools", "jobserver", "libc", "shlex", ] [[package]] -name = "cexpr" -version = "0.6.0" +name = "cesu8" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" [[package]] name = "cf-rustracing" @@ -575,17 +549,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "clang-sys" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "clap" version = "3.2.25" @@ -627,9 +590,9 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.52" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c682c223677e0e5b6b7f63a64b9351844c3f1b1678a68b7ee617e30fb082620e" +checksum = "75443c44cd6b379beb8c5b45d85d0773baf31cce901fe7bb252f4eff3008ef7d" dependencies = [ "cc", ] @@ -640,6 +603,16 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -650,6 +623,16 @@ dependencies = [ "libc", ] +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -877,20 +860,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] -name = "errno" -version = "0.3.10" +name = "find-msvc-tools" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" -dependencies = [ - "libc", - "windows-sys 0.59.0", -] - -[[package]] -name = "fastrand" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db" [[package]] name = "flate2" @@ -955,15 +928,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" -[[package]] -name = "fsevent-sys" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" -dependencies = [ - "libc", -] - [[package]] name = "futures" version = "0.3.31" @@ -1070,8 +1034,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -1081,8 +1047,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.13.3+wasi-0.2.2", + "wasm-bindgen", "windows-targets 0.52.6", ] @@ -1092,12 +1060,6 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" -[[package]] -name = "glob" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" - [[package]] name = "h2" version = "0.4.12" @@ -1161,15 +1123,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "home" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" -dependencies = [ - "windows-sys 0.61.0", -] - [[package]] name = "hostname" version = "0.3.1" @@ -1183,12 +1136,11 @@ dependencies = [ [[package]] name = "http" -version = "1.2.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" dependencies = [ "bytes", - "fnv", "itoa", ] @@ -1295,22 +1247,6 @@ dependencies = [ "tower-service", ] -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - [[package]] name = "hyper-util" version = "0.1.19" @@ -1538,15 +1474,6 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.14" @@ -1577,6 +1504,28 @@ dependencies = [ "syn 2.0.100", ] +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys", + "log", + "thiserror 1.0.69", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + [[package]] name = "jobserver" version = "0.1.32" @@ -1598,9 +1547,9 @@ dependencies = [ [[package]] name = "jsonwebtoken" -version = "10.2.0" +version = "10.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c76e1c7d7df3e34443b3621b459b066a7b79644f059fc8b2db7070c825fd417e" +checksum = "0529410abe238729a60b108898784df8984c87f6054c9c4fcacc47e4803c1ce1" dependencies = [ "aws-lc-rs", "base64", @@ -1639,28 +1588,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "libc" version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" -[[package]] -name = "libloading" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" -dependencies = [ - "cfg-if", - "windows-link 0.2.0", -] - [[package]] name = "libmimalloc-sys" version = "0.1.44" @@ -1687,18 +1620,6 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" -[[package]] -name = "linux-raw-sys" -version = "0.4.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" - -[[package]] -name = "linux-raw-sys" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" - [[package]] name = "litemap" version = "0.7.4" @@ -1742,6 +1663,12 @@ dependencies = [ "hashbrown 0.15.2", ] +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + [[package]] name = "match_cfg" version = "0.1.0" @@ -1821,23 +1748,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "native-tls" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "neli" version = "0.6.5" @@ -1899,27 +1809,31 @@ dependencies = [ [[package]] name = "notify" -version = "8.2.0" +version = "9.0.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d3d07927151ff8575b7087f245456e549fea62edf0ec4e565a5ee50c8402bc3" +checksum = "6d1f660da45085290c8c3cfde8e99b5992afd363f574e25d61692c27814e7a16" dependencies = [ "bitflags 2.8.0", - "fsevent-sys", "inotify", "kqueue", "libc", "log", "mio", "notify-types", + "objc2-core-foundation", + "objc2-core-services", "walkdir", - "windows-sys 0.60.2", + "windows-sys 0.61.0", ] [[package]] name = "notify-types" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d" +checksum = "42b8cfee0e339a0337359f3c88165702ac6e600dc01c0cc9579a92d62b08477a" +dependencies = [ + "bitflags 2.8.0", +] [[package]] name = "num-bigint" @@ -1964,6 +1878,25 @@ dependencies = [ "objc2-encode", ] +[[package]] +name = "objc2-core-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" +dependencies = [ + "bitflags 2.8.0", +] + +[[package]] +name = "objc2-core-services" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583300ad934cba24ff5292aee751ecc070f7ca6b39a574cc21b7b5e588e06a0b" +dependencies = [ + "libc", + "objc2-core-foundation", +] + [[package]] name = "objc2-encode" version = "4.1.0" @@ -2026,6 +1959,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + [[package]] name = "openssl-src" version = "300.5.0+3.5.0" @@ -2205,7 +2144,7 @@ dependencies = [ "log", "nix 0.24.3", "once_cell", - "openssl-probe", + "openssl-probe 0.1.6", "parking_lot", "percent-encoding", "pingora-error", @@ -2433,16 +2372,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "prettyplease" -version = "0.2.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6837b9e10d61f45f987d50808f83d1ee3d206c66acf650c3e4ae2e1f6ddedf55" -dependencies = [ - "proc-macro2", - "syn 2.0.100", -] - [[package]] name = "privdrop" version = "0.5.6" @@ -2542,6 +2471,62 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror 2.0.12", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" +dependencies = [ + "aws-lc-rs", + "bytes", + "getrandom 0.3.1", + "lru-slab", + "rand 0.9.2", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror 2.0.12", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.60.2", +] + [[package]] name = "quote" version = "1.0.38" @@ -2558,10 +2543,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", + "rand_chacha 0.3.1", "rand_core 0.6.4", ] +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.5", +] + [[package]] name = "rand" version = "0.10.0-rc.5" @@ -2583,6 +2578,16 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", +] + [[package]] name = "rand_core" version = "0.6.4" @@ -2592,6 +2597,15 @@ dependencies = [ "getrandom 0.2.15", ] +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.1", +] + [[package]] name = "rand_core" version = "0.10.0-rc-2" @@ -2638,9 +2652,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "reqwest" -version = "0.12.25" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eff9328d40131d43bd911d42d79eb6a47312002a4daefc9e37f17e74a7701a" +checksum = "04e9018c9d814e5f30cc16a0f03271aeab3571e609612d9fe78c1aa8d11c2f62" dependencies = [ "base64", "bytes", @@ -2653,21 +2667,21 @@ dependencies = [ "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "js-sys", "log", "mime", - "native-tls", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pki-types", + "rustls-platform-verifier", "serde", "serde_json", - "serde_urlencoded", "sync_wrapper", "tokio", - "tokio-native-tls", + "tokio-rustls", "tokio-util", "tower", "tower-http", @@ -2733,9 +2747,9 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc-hash" -version = "1.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" [[package]] name = "rusticata-macros" @@ -2746,38 +2760,13 @@ dependencies = [ "nom", ] -[[package]] -name = "rustix" -version = "0.38.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" -dependencies = [ - "bitflags 2.8.0", - "errno", - "libc", - "linux-raw-sys 0.4.15", - "windows-sys 0.52.0", -] - -[[package]] -name = "rustix" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" -dependencies = [ - "bitflags 2.8.0", - "errno", - "libc", - "linux-raw-sys 0.9.4", - "windows-sys 0.59.0", -] - [[package]] name = "rustls" version = "0.23.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "730944ca083c1c233a75c09f199e973ca499344a2b7ba9e755c457e86fb4a321" dependencies = [ + "aws-lc-rs", "once_cell", "rustls-pki-types", "rustls-webpki", @@ -2785,6 +2774,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-native-certs" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63" +dependencies = [ + "openssl-probe 0.2.1", + "rustls-pki-types", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "2.2.0" @@ -2799,6 +2800,36 @@ name = "rustls-pki-types" version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" +dependencies = [ + "web-time", +] + +[[package]] +name = "rustls-platform-verifier" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784" +dependencies = [ + "core-foundation 0.10.1", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.0", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" [[package]] name = "rustls-webpki" @@ -2806,6 +2837,7 @@ version = "0.103.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a72fe2bcf7a6ac6fd7d0b9e5cb68aeb7d4c0a0271730218b3e92d43b4eb435" dependencies = [ + "aws-lc-rs", "ring", "rustls-pki-types", "untrusted 0.9.0", @@ -2849,12 +2881,12 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "security-framework" -version = "2.11.1" +version = "3.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +checksum = "b3297343eaf830f66ede390ea39da1d462b6b0c1b000f420d0a83f898bbbe6ef" dependencies = [ "bitflags 2.8.0", - "core-foundation", + "core-foundation 0.10.1", "core-foundation-sys", "libc", "security-framework-sys", @@ -2862,9 +2894,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.14.0" +version = "2.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32" +checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" dependencies = [ "core-foundation-sys", "libc", @@ -2902,14 +2934,15 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.140" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "itoa", "memchr", - "ryu", "serde", + "serde_core", + "zmij", ] [[package]] @@ -3131,7 +3164,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ "bitflags 2.8.0", - "core-foundation", + "core-foundation 0.9.4", "system-configuration-sys", ] @@ -3145,19 +3178,6 @@ dependencies = [ "libc", ] -[[package]] -name = "tempfile" -version = "3.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" -dependencies = [ - "fastrand", - "getrandom 0.3.1", - "once_cell", - "rustix 1.0.7", - "windows-sys 0.59.0", -] - [[package]] name = "termcolor" version = "1.4.1" @@ -3274,6 +3294,21 @@ dependencies = [ "zerovec", ] +[[package]] +name = "tinyvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.48.0" @@ -3302,16 +3337,6 @@ dependencies = [ "syn 2.0.100", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-openssl" version = "0.6.5" @@ -3727,15 +3752,22 @@ dependencies = [ ] [[package]] -name = "which" -version = "4.4.2" +name = "web-time" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" dependencies = [ - "either", - "home", - "once_cell", - "rustix 0.38.44", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-root-certs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36a29fc0408b113f68cf32637857ab740edfafdf460c326cd2afaa2d84cc05dc" +dependencies = [ + "rustls-pki-types", ] [[package]] @@ -3810,6 +3842,15 @@ dependencies = [ "windows-link 0.1.3", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -3855,6 +3896,21 @@ dependencies = [ "windows-link 0.2.0", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -3903,6 +3959,12 @@ dependencies = [ "windows_x86_64_msvc 0.53.0", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -3921,6 +3983,12 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" @@ -3939,6 +4007,12 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.48.5" @@ -3969,6 +4043,12 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.48.5" @@ -3987,6 +4067,12 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" @@ -4005,6 +4091,12 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" @@ -4023,6 +4115,12 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" @@ -4182,6 +4280,12 @@ dependencies = [ "syn 2.0.100", ] +[[package]] +name = "zmij" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02aae0f83f69aafc94776e879363e9771d7ecbffe2c7fbb6c14c5e00dfe88439" + [[package]] name = "zstd" version = "0.13.2" diff --git a/Cargo.toml b/Cargo.toml index bf1b0cd..c8ceb85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,20 +23,20 @@ async-trait = "0.1.89" env_logger = "0.11.8" log = "0.4.29" futures = "0.3.31" -notify = "8.2.0" -axum = { version = "0.8.7" } +notify = "9.0.0-rc.1" +axum = { version = "0.8.8" } axum-server = { version = "0.8.0", features = ["tls-openssl"] } -reqwest = { version = "0.12.25", features = ["json", "native-tls-alpn", "stream"] } +reqwest = { version = "0.13.1", features = ["json", "stream"] } #reqwest = { version = "0.12.15", features = ["json", "rustls-tls"] } #reqwest = { version = "0.12.15", default-features = false, features = ["rustls-tls", "json"] } serde_yaml = "0.9.34-deprecated" rand = "0.10.0-rc.5" base64 = "0.22.1" -jsonwebtoken = { version = "10.2.0", features = ["aws_lc_rs"] } +jsonwebtoken = { version = "10.3.0", features = ["aws_lc_rs"] } tonic = "0.14.2" sha2 = { version = "0.11.0-rc.3", default-features = false } -base16ct = { version = "0.3.0", features = ["alloc"] } +base16ct = { version = "1.0.0", features = ["alloc"] } urlencoding = "2.1.3" arc-swap = "1.7.1" mimalloc = { version = "0.1.48", default-features = false } @@ -49,9 +49,9 @@ once_cell = "1.21.3" privdrop = "0.5.6" ctrlc = "3.5.1" port_check = "0.3.0" -serde_json = "1.0.140" -http = "1.2.0" -#moka = { version = "0.12.10", features = ["sync"] } +serde_json = "1.0.149" +http = "1.4.0" +#moka = { version = "0.12.12", features = ["sync"] } #rustls = { version = "0.23.27", features = ["ring"] } #hickory-client = { version = "0.25.2" } #openssl = "0.10.73" diff --git a/src/utils/auth.rs b/src/utils/auth.rs index adcdacf..afdfe7a 100644 --- a/src/utils/auth.rs +++ b/src/utils/auth.rs @@ -3,6 +3,7 @@ use base64::engine::general_purpose::STANDARD; use base64::Engine; use pingora_proxy::Session; use std::collections::HashMap; +use std::sync::Arc; use urlencoding::decode; trait AuthValidator { @@ -56,18 +57,18 @@ fn validate(auth: &dyn AuthValidator, session: &Session) -> bool { auth.validate(session) } -pub fn authenticate(c: &[String], session: &Session) -> bool { - match c[0].as_str() { +pub fn authenticate(c: &[Arc], session: &Session) -> bool { + match &*c[0] { "basic" => { - let auth = BasicAuth(c[1].as_str().into()); + let auth = BasicAuth(&*c[1]); validate(&auth, session) } "apikey" => { - let auth = ApiKeyAuth(c[1].as_str().into()); + let auth = ApiKeyAuth(&*c[1]); validate(&auth, session) } "jwt" => { - let auth = JwtAuth(c[1].as_str().into()); + let auth = JwtAuth(&*c[1]); validate(&auth, session) } _ => { diff --git a/src/utils/httpclient.rs b/src/utils/httpclient.rs index 12c9b53..ed1c850 100644 --- a/src/utils/httpclient.rs +++ b/src/utils/httpclient.rs @@ -7,7 +7,7 @@ use std::sync::atomic::AtomicUsize; use std::sync::Arc; use std::time::Duration; -pub async fn for_consul(url: String, token: Option, conf: &ServiceMapping) -> Option>, AtomicUsize)>> { +pub async fn for_consul(url: String, token: Option, conf: &ServiceMapping) -> Option, (Vec>, AtomicUsize)>> { let client = Client::builder().timeout(Duration::from_secs(2)).danger_accept_invalid_certs(true).build().ok()?; let mut headers = HeaderMap::new(); if let Some(token) = token { @@ -20,7 +20,7 @@ pub async fn for_consul(url: String, token: Option, conf: &ServiceMappin return None; } let mut inner_vec = Vec::new(); - let upstreams: DashMap>, AtomicUsize)> = DashMap::new(); + let upstreams: DashMap, (Vec>, AtomicUsize)> = DashMap::new(); let endpoints: Vec = resp.json().await.ok()?; for subsets in endpoints { // let addr = subsets.tagged_addresses.get("lan_ipv4").unwrap().address.clone(); @@ -42,7 +42,7 @@ pub async fn for_consul(url: String, token: Option, conf: &ServiceMappin Some(upstreams) } -pub async fn for_kuber(url: &str, token: &str, conf: &ServiceMapping) -> Option>, AtomicUsize)>> { +pub async fn for_kuber(url: &str, token: &str, conf: &ServiceMapping) -> Option, (Vec>, AtomicUsize)>> { let to = Duration::from_secs(10); let client = Client::builder().timeout(Duration::from_secs(10)).danger_accept_invalid_certs(true).build().ok()?; let resp = client.get(url).timeout(to).bearer_auth(token).send().await.ok()?; @@ -51,33 +51,8 @@ pub async fn for_kuber(url: &str, token: &str, conf: &ServiceMapping) -> Option< return None; } let endpoints: KubeEndpoints = resp.json().await.ok()?; - // let endpoints: KubeEndpointsList = resp.json().await.ok()?; - let upstreams: DashMap>, AtomicUsize)> = DashMap::new(); - // for endpoints in endpoints.items { - // if let Some(subsets) = endpoints.subsets { - // for subset in subsets { - // if let (Some(addresses), Some(ports)) = (subset.addresses, subset.ports) { - // let mut inner_vec = Vec::new(); - // for addr in addresses { - // for port in &ports { - // let to_add = Arc::from(InnerMap { - // address: addr.ip.parse().unwrap(), - // port: port.port.clone(), - // is_ssl: false, - // is_http2: false, - // to_https: conf.to_https.unwrap_or(false), - // rate_limit: conf.rate_limit, - // healthcheck: None, - // }); - // inner_vec.push(to_add); - // } - // } - // match_path(&conf, &upstreams, inner_vec.clone()); - // } - // } - // } - // } + let upstreams: DashMap, (Vec>, AtomicUsize)> = DashMap::new(); if let Some(subsets) = endpoints.subsets { for subset in subsets { diff --git a/src/utils/kuberconsul.rs b/src/utils/kuberconsul.rs index 6a08ccc..5ccb5ad 100644 --- a/src/utils/kuberconsul.rs +++ b/src/utils/kuberconsul.rs @@ -56,28 +56,28 @@ pub struct ConsulTaggedAddress { #[serde(rename = "Port")] pub port: u16, } -pub fn list_to_upstreams(lt: Option>, AtomicUsize)>>, upstreams: &UpstreamsDashMap, i: &ServiceMapping) { +pub fn list_to_upstreams(lt: Option, (Vec>, AtomicUsize)>>, upstreams: &UpstreamsDashMap, i: &ServiceMapping) { if let Some(list) = lt { - match upstreams.get(&i.hostname.clone()) { + match upstreams.get(&*i.hostname.clone()) { Some(upstr) => { for (k, v) in list { - upstr.value().insert(k, v); + upstr.value().insert(Arc::from(k.to_owned()), v); } } None => { - upstreams.insert(i.hostname.clone(), list); + upstreams.insert(Arc::from(i.hostname.clone()), list); } }; } } -pub fn match_path(conf: &ServiceMapping, upstreams: &DashMap>, AtomicUsize)>, values: Vec>) { +pub fn match_path(conf: &ServiceMapping, upstreams: &DashMap, (Vec>, AtomicUsize)>, values: Vec>) { match conf.path { Some(ref p) => { - upstreams.insert(p.to_string(), (values, AtomicUsize::new(0))); + upstreams.insert(Arc::from(p.clone()), (values, AtomicUsize::new(0))); } None => { - upstreams.insert("/".to_string(), (values, AtomicUsize::new(0))); + upstreams.insert(Arc::from("/"), (values, AtomicUsize::new(0))); } } } @@ -134,7 +134,7 @@ impl ServiceDiscovery for KubernetesDiscovery { // header_list.insert(Arc::from(path.as_str()), hl); // header_list.insert(Arc::from(i.path).unwrap_or(Arc::from("/")).as_str(), hl); - config.client_headers.insert(service.hostname.clone(), header_list); + config.client_headers.insert(Arc::from(service.hostname.clone()), header_list); } let url = format!("https://{}/api/v1/namespaces/{}/endpoints/{}", server, namespace, service.hostname); // let url = format!("https://{}/api/v1/namespaces/{}/endpoints?labelSelector=app", server, namespace); @@ -196,7 +196,7 @@ impl ServiceDiscovery for ConsulDiscovery { } } // header_list.insert(i.path.clone().unwrap_or("/".to_string()), hl); - config.client_headers.insert(i.hostname.clone(), header_list); + config.client_headers.insert(Arc::from(i.hostname.clone()), header_list); } let pref = ss.clone() + &i.upstream; diff --git a/src/utils/parceyaml.rs b/src/utils/parceyaml.rs index 6b56ee6..8f7f24c 100644 --- a/src/utils/parceyaml.rs +++ b/src/utils/parceyaml.rs @@ -77,7 +77,7 @@ async fn populate_headers_and_auth(config: &mut Configuration, parsed: &Config) } let global_headers: DashMap, Vec<(Arc, Arc)>> = DashMap::new(); global_headers.insert(Arc::from("/"), ch); - config.client_headers.insert("GLOBAL_CLIENT_HEADERS".to_string(), global_headers); + config.client_headers.insert(Arc::from("GLOBAL_CLIENT_HEADERS"), global_headers); let mut sh: Vec<(Arc, Arc)> = Vec::new(); sh.push((Arc::from("X-Proxy-Server"), Arc::from("Aralez"))); @@ -90,7 +90,7 @@ async fn populate_headers_and_auth(config: &mut Configuration, parsed: &Config) } let server_global_headers: DashMap, Vec<(Arc, Arc)>> = DashMap::new(); server_global_headers.insert(Arc::from("/"), sh); - config.server_headers.insert("GLOBAL_SERVER_HEADERS".to_string(), server_global_headers); + config.server_headers.insert(Arc::from("GLOBAL_SERVER_HEADERS"), server_global_headers); config.extraparams.sticky_sessions = parsed.sticky_sessions; config.extraparams.to_https = parsed.to_https; @@ -103,7 +103,10 @@ async fn populate_headers_and_auth(config: &mut Configuration, parsed: &Config) if let Some(auth) = &parsed.authorization { let name = auth.get("type").unwrap_or(&"".to_string()).to_string(); let creds = auth.get("creds").unwrap_or(&"".to_string()).to_string(); - config.extraparams.authentication.insert("authorization".to_string(), vec![name, creds]); + config + .extraparams + .authentication + .insert(Arc::from("authorization"), vec![Arc::from(name), Arc::from(creds)]); } else { config.extraparams.authentication = DashMap::new(); } @@ -144,11 +147,11 @@ async fn populate_file_upstreams(config: &mut Configuration, parsed: &Config) { } } } - path_map.insert(path.clone(), (server_list, AtomicUsize::new(0))); + path_map.insert(Arc::from(path.clone()), (server_list, AtomicUsize::new(0))); } - config.client_headers.insert(hostname.clone(), client_header_list); - config.server_headers.insert(hostname.clone(), server_header_list); - imtdashmap.insert(hostname.clone(), path_map); + config.client_headers.insert(Arc::from(hostname.clone()), client_header_list); + config.server_headers.insert(Arc::from(hostname.clone()), server_header_list); + imtdashmap.insert(Arc::from(hostname.clone()), path_map); } if is_first_run() { diff --git a/src/utils/structs.rs b/src/utils/structs.rs index 80d30d7..706cf9c 100644 --- a/src/utils/structs.rs +++ b/src/utils/structs.rs @@ -5,10 +5,10 @@ use std::net::IpAddr; use std::sync::atomic::AtomicUsize; use std::sync::Arc; -pub type UpstreamsDashMap = DashMap>, AtomicUsize)>>; +pub type UpstreamsDashMap = DashMap, DashMap, (Vec>, AtomicUsize)>>; -pub type UpstreamsIdMap = DashMap>; -pub type Headers = DashMap, Vec<(Arc, Arc)>>>; +pub type UpstreamsIdMap = DashMap, Arc>; +pub type Headers = DashMap, DashMap, Vec<(Arc, Arc)>>>; #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct ServiceMapping { @@ -21,13 +21,11 @@ pub struct ServiceMapping { pub server_headers: Option>, } -// pub type Services = DashMap)>>; - #[derive(Clone, Debug, Default)] pub struct Extraparams { pub sticky_sessions: bool, pub to_https: Option, - pub authentication: DashMap>, + pub authentication: DashMap, Vec>>, pub rate_limit: Option, } #[derive(Clone, Default, Debug, Serialize, Deserialize)] diff --git a/src/utils/tools.rs b/src/utils/tools.rs index 7facbb7..fb20468 100644 --- a/src/utils/tools.rs +++ b/src/utils/tools.rs @@ -169,8 +169,8 @@ pub fn clone_idmap_into(original: &UpstreamsDashMap, cloned: &UpstreamsIdMap) { rate_limit: None, healthcheck: None, }; - cloned.insert(id, Arc::from(to_add)); - cloned.insert(hh, Arc::from(x.to_owned())); + cloned.insert(Arc::from(id.as_str()), Arc::from(to_add)); + cloned.insert(Arc::from(hh.as_str()), Arc::from(x.to_owned())); } new_inner_map.insert(path.clone(), new_vec); } @@ -282,7 +282,7 @@ pub fn upstreams_to_json(upstreams: &UpstreamsDashMap) -> serde_json::Result serde_json::Result = configured_backends .iter() .map(|backend| { - let alive = if let Some(host_map) = current.get(&hostname) { - if let Some(path_entry) = host_map.get(&path) { + let alive = if let Some(host_map) = current.get(&*hostname) { + if let Some(path_entry) = host_map.get(&*path) { let list = &path_entry.value().0; // Vec> list.iter().any(|b| b.address == backend.address && b.port == backend.port) } else { @@ -331,7 +331,7 @@ pub fn upstreams_liveness_json(configured: &UpstreamsDashMap, current: &Upstream .collect(); paths_json.insert( - path, + path.to_string(), json!({ "backends": backends_json }), diff --git a/src/web/proxyhttp.rs b/src/web/proxyhttp.rs index 47258d9..6f60655 100644 --- a/src/web/proxyhttp.rs +++ b/src/web/proxyhttp.rs @@ -50,7 +50,6 @@ impl ProxyHttp for LB { fn new_ctx(&self) -> Self::CTX { Context { backend_id: Arc::from(""), - // backend_id: Arc::new((IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0, false)), to_https: false, redirect_to: Arc::from(""), start_time: Instant::now(), @@ -64,7 +63,7 @@ impl ProxyHttp for LB { let ep = _ctx.extraparams.as_ref(); if let Some(auth) = ep.authentication.get("authorization") { - let authenticated = authenticate(&auth.value(), &session); + let authenticated = authenticate(auth.value(), &session); if !authenticated { let _ = session.respond_error(401).await; warn!("Forbidden: {:?}, {}", session.client_addr(), session.req_header().uri.path()); @@ -72,7 +71,7 @@ impl ProxyHttp for LB { } }; - let hostname = return_header_host(&session); + let hostname = return_header_host_from_upstream(session, &self.ump_upst); _ctx.hostname = hostname; let mut backend_id = None; @@ -235,33 +234,56 @@ impl ProxyHttp for LB { } } -fn return_header_host(session: &Session) -> Option> { - if session.is_http2() { - match session.req_header().uri.host() { - Some(host) => Option::from(Arc::from(host)), - None => None, - } - } else { - match session.req_header().headers.get("host") { - Some(host) => { - let header_host: &str = host.to_str().unwrap().split_once(':').map_or(host.to_str().unwrap(), |(h, _)| h); - Option::from(Arc::::from(header_host)) - } - None => None, - } - } -} +// use moka::sync::Cache; +// Using Moka for a high-concurrency, size-limited cache +// static HOST_CACHE: Lazy>> = Lazy::new(|| { +// Cache::builder() +// .max_capacity(10_000) // Limits memory usage if attacked +// .build() +// }); +// fn return_header_host_cached(session: &Session) -> Option> { +// let host_str = if session.is_http2() { +// session.req_header().uri.host()? +// } else { +// let h = session.req_header().headers.get("host")?.to_str().ok()?; +// h.split_once(':').map_or(h, |(host, _)| host) +// }; +// HOST_CACHE +// .get_with(host_str.to_string(), || { +// Arc::from(host_str) +// }) +// .into() +// } -#[allow(dead_code)] -fn return_str_host<'a>(session: &'a Session) -> Option<&'a str> { - if session.is_http2() { - session.req_header().uri.host() +// use dashmap::DashMap; +// A simple cache to reuse Arcs for common hostnames +// static HOST_CACHE: Lazy>> = Lazy::new(|| DashMap::with_capacity(200)); +// +// fn return_header_host_cached(session: &Session) -> Option> { +// let host_str = if session.is_http2() { +// session.req_header().uri.host()? +// } else { +// let h = session.req_header().headers.get("host")?.to_str().ok()?; +// h.split_once(':').map_or(h, |(host, _)| host) +// }; +// +// // Fast path: check if we already have an Arc for this host +// if let Some(arc) = HOST_CACHE.get(host_str) { +// return Some(arc.clone()); // Only an atomic increment! +// } +// +// // Slow path: create new Arc and cache it +// let new_arc: Arc = Arc::from(host_str); +// HOST_CACHE.insert(host_str.to_string(), new_arc.clone()); +// Some(new_arc) +// } + +fn return_header_host_from_upstream(session: &Session, ump_upst: &UpstreamsDashMap) -> Option> { + let host_str = if session.is_http2() { + session.req_header().uri.host()? } else { - session - .req_header() - .headers - .get("host") - .and_then(|h| h.to_str().ok()) - .map(|h| h.split_once(':').map_or(h, |(host, _)| host)) - } + let h = session.req_header().headers.get("host")?.to_str().ok()?; + h.split_once(':').map_or(h, |(host, _)| host) + }; + ump_upst.get(host_str).map(|entry| entry.key().clone()) }