From b503f866b146a8d640460b46a63f1cf61913c57c Mon Sep 17 00:00:00 2001 From: Ara Sadoyan Date: Fri, 7 Feb 2025 15:12:28 +0100 Subject: [PATCH] initial commit --- Cargo.lock | 1497 +++++++++++++++++++++++++++++++++++++++- Cargo.toml | 20 +- src/backup/handler.rs | 54 ++ src/backup/peers.rs | 28 + src/backup/start.rs | 45 ++ src/backup/tcpcache.rs | 113 +++ src/main.rs | 2 +- src/web.rs | 6 +- src/web/proxyhttp.rs | 228 ++++++ src/web/run.rs | 46 -- src/web/start.rs | 66 ++ start.sh | 4 +- 12 files changed, 2047 insertions(+), 62 deletions(-) create mode 100644 src/backup/handler.rs create mode 100644 src/backup/peers.rs create mode 100644 src/backup/start.rs create mode 100644 src/backup/tcpcache.rs create mode 100644 src/web/proxyhttp.rs delete mode 100644 src/web/run.rs create mode 100644 src/web/start.rs diff --git a/Cargo.lock b/Cargo.lock index d4cb536..20080b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,19 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.3" @@ -26,6 +39,27 @@ dependencies = [ "memchr", ] +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -50,6 +84,68 @@ dependencies = [ "winapi", ] +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" +dependencies = [ + "anstyle", + "once_cell", + "windows-sys 0.59.0", +] + +[[package]] +name = "arc-swap" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "async-stream" version = "0.3.6" @@ -72,12 +168,38 @@ dependencies = [ "syn 2.0.96", ] +[[package]] +name = "async-trait" +version = "0.1.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f934833b4b7233644e5848f235df3f57ed8c80f1528a26c3dfa13d2147fa056" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", +] + [[package]] name = "asyncweb" version = "0.1.0" dependencies = [ + "async-trait", "bytes", + "dashmap", + "env_logger", + "futures", + "http-body-util", + "hyper 0.14.32", + "hyper-reverse-proxy", + "hyper-util", + "log", "mini-redis", + "pingora", + "pingora-core", + "pingora-http", + "pingora-load-balancing", + "pingora-proxy", + "rand", "tokio", ] @@ -90,6 +212,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "atty" version = "0.2.14" @@ -134,12 +262,57 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" +[[package]] +name = "blake2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +dependencies = [ + "digest", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "brotli" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d640d25bc63c50fb1f0b545ffd80207d2e10a4c965530809b40ba3386825c391" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "2.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e2e4afe60d7dd600fdd3de8d0f08c2b7ec039712e3b6137ff98b7004e82de4f" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + [[package]] name = "bumpalo" version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.9.0" @@ -152,6 +325,8 @@ version = "1.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13208fcbb66eaeffe09b99fffbe1af420f00a7b35aa99ad683dfc1aa76145229" dependencies = [ + "jobserver", + "libc", "shlex", ] @@ -182,30 +357,395 @@ dependencies = [ "ansi_term", "atty", "bitflags 1.3.2", - "strsim", - "textwrap", + "strsim 0.8.0", + "textwrap 0.11.0", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +dependencies = [ + "atty", + "bitflags 1.3.2", + "clap_derive", + "clap_lex", + "indexmap 1.9.3", + "once_cell", + "strsim 0.10.0", + "termcolor", + "textwrap 0.16.1", +] + +[[package]] +name = "clap_derive" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" +dependencies = [ + "heck 0.4.1", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "cmake" +version = "0.1.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c682c223677e0e5b6b7f63a64b9351844c3f1b1678a68b7ee617e30fb082620e" +dependencies = [ + "cc", +] + +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "core-foundation-sys" version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-queue" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "daemonize" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab8bfdaacb3c887a54d41bdf48d3af8873b3f5566469f8ba21b92057509f116e" +dependencies = [ + "libc", +] + +[[package]] +name = "dashmap" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "hashbrown 0.14.5", + "lock_api", + "once_cell", + "parking_lot_core", +] + +[[package]] +name = "data-encoding" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e60eed09d8c01d3cee5b7d30acb059b76614c918fa0f992e0dd6eeb10daad6f" + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + +[[package]] +name = "env_filter" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcaee3d8e3cfc3fd92428d477bc97fc29ec8716d180c0d74c643bb26166660e0" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "flate2" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" +dependencies = [ + "crc32fast", + "libz-ng-sys", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" + +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + [[package]] name = "futures-core" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap 2.7.1", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccae279728d634d083c00f6099cb58f01cc99c145b84b8be2f6c74618d79922e" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http 1.2.0", + "indexmap 2.7.1", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + [[package]] name = "heck" version = "0.3.3" @@ -215,6 +755,18 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -224,6 +776,172 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi", +] + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http 1.2.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http 1.2.0", + "http-body 1.0.1", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "hyper" +version = "0.14.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.7", + "http 1.2.0", + "http-body 1.0.1", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-reverse-proxy" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc1af9b1b483fb9f33bd1cda26b35eacf902f0d116fcf0d56075ea5e5923b935" +dependencies = [ + "hyper 0.14.32", + "lazy_static", + "unicase", +] + +[[package]] +name = "hyper-util" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.2.0", + "http-body 1.0.1", + "hyper 1.6.0", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + [[package]] name = "iana-time-zone" version = "0.1.61" @@ -247,12 +965,47 @@ dependencies = [ "cc", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" +dependencies = [ + "equivalent", + "hashbrown 0.15.2", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itoa" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.77" @@ -275,6 +1028,22 @@ version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +[[package]] +name = "libz-ng-sys" +version = "1.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cee1488e961a80d172564fd6fcda11d8a4ac6672c06fe008e9213fa60520c2b" +dependencies = [ + "cmake", + "libc", +] + +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "lock_api" version = "0.4.12" @@ -291,6 +1060,21 @@ version = "0.4.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" +[[package]] +name = "lru" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" +dependencies = [ + "hashbrown 0.15.2", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" + [[package]] name = "matchers" version = "0.0.1" @@ -306,6 +1090,15 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + [[package]] name = "mini-redis" version = "0.4.1" @@ -340,7 +1133,19 @@ checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" dependencies = [ "libc", "wasi", - "windows-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "nix" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", + "memoffset", ] [[package]] @@ -367,6 +1172,18 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "openssl-probe" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" + +[[package]] +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" + [[package]] name = "parking_lot" version = "0.12.3" @@ -390,6 +1207,18 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "pin-project" version = "1.1.8" @@ -416,6 +1245,263 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pingora" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79c9fc7098dc3e7d09d2d1647921005be9301cf68536826195dc5369e05124bd" +dependencies = [ + "pingora-core", + "pingora-http", + "pingora-load-balancing", + "pingora-proxy", + "pingora-timeout", +] + +[[package]] +name = "pingora-cache" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35ee62f28526d8d484621e77f8d6a1807f1bd07558a06ab5a204b4834d6be056" +dependencies = [ + "ahash", + "async-trait", + "blake2", + "bytes", + "hex", + "http 1.2.0", + "httparse", + "httpdate", + "indexmap 1.9.3", + "log", + "lru", + "once_cell", + "parking_lot", + "pingora-core", + "pingora-error", + "pingora-header-serde", + "pingora-http", + "pingora-lru", + "pingora-timeout", + "regex", + "rmp", + "rmp-serde", + "rustracing", + "rustracing_jaeger", + "serde", + "strum", + "tokio", +] + +[[package]] +name = "pingora-core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d123320b69bd06e897fc16bd1dde962a7b488c4d2ae825683fbca0198fad8669" +dependencies = [ + "ahash", + "async-trait", + "brotli", + "bytes", + "chrono", + "clap 3.2.25", + "daemonize", + "flate2", + "futures", + "h2 0.4.7", + "http 1.2.0", + "httparse", + "httpdate", + "libc", + "log", + "lru", + "nix", + "once_cell", + "openssl-probe", + "parking_lot", + "percent-encoding", + "pingora-error", + "pingora-http", + "pingora-pool", + "pingora-runtime", + "pingora-timeout", + "prometheus", + "rand", + "regex", + "serde", + "serde_yaml", + "sfv", + "socket2", + "strum", + "strum_macros", + "thread_local", + "tokio", + "tokio-test", + "unicase", + "windows-sys 0.59.0", + "zstd", +] + +[[package]] +name = "pingora-error" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6389511530152c535a554f592ae4a9691b1246cff20eb4564f2a34fc921195c0" + +[[package]] +name = "pingora-header-serde" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcb3f62d852da015e76ced56e93e6d52941679a9825281c90f2897841129e59d" +dependencies = [ + "bytes", + "http 1.2.0", + "httparse", + "pingora-error", + "pingora-http", + "thread_local", + "zstd", + "zstd-safe", +] + +[[package]] +name = "pingora-http" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70202f126056f366549afc804741e12dd9f419cfc79a0063ab15653007a0f4c6" +dependencies = [ + "bytes", + "http 1.2.0", + "pingora-error", +] + +[[package]] +name = "pingora-ketama" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c1bb6c2e11823a05ec9140fc8827f112b8380d78b837535f284e0a98f24cc0a" +dependencies = [ + "crc32fast", +] + +[[package]] +name = "pingora-load-balancing" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84d558167ecb05cea487a6479700390a67fe414724f203e10c3912584a0f2cb1" +dependencies = [ + "arc-swap", + "async-trait", + "derivative", + "fnv", + "futures", + "http 1.2.0", + "log", + "pingora-core", + "pingora-error", + "pingora-http", + "pingora-ketama", + "pingora-runtime", + "rand", + "tokio", +] + +[[package]] +name = "pingora-lru" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb50f65f06c4b81ccb3edcceaa54bb9439608506b0b3b8c048798169a64aad8e" +dependencies = [ + "arrayvec", + "hashbrown 0.15.2", + "parking_lot", + "rand", +] + +[[package]] +name = "pingora-pool" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bacdd5dbdec690d468856d988b170c8bb4ab62e0edefc0f432ba5e326489f421" +dependencies = [ + "crossbeam-queue", + "log", + "lru", + "parking_lot", + "pingora-timeout", + "thread_local", + "tokio", +] + +[[package]] +name = "pingora-proxy" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5031783d6743bd31e4de7d7c7a19e9eecf369174c3cbd8a57eb52bc6bf882d92" +dependencies = [ + "async-trait", + "bytes", + "clap 3.2.25", + "futures", + "h2 0.4.7", + "http 1.2.0", + "log", + "once_cell", + "pingora-cache", + "pingora-core", + "pingora-error", + "pingora-http", + "pingora-timeout", + "regex", + "tokio", +] + +[[package]] +name = "pingora-runtime" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31a7c445ca224630961045684201e3cf8da9af0b01f286ed54ff8b2403aaabff" +dependencies = [ + "once_cell", + "rand", + "thread_local", + "tokio", +] + +[[package]] +name = "pingora-timeout" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685bb8808cc1919c63a06ab14fdac9b84a4887ced49259a5c0adc8bfb2ffe558" +dependencies = [ + "once_cell", + "parking_lot", + "pin-project-lite", + "thread_local", + "tokio", +] + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -449,6 +1535,27 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "prometheus" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d33c28a30771f7f96db69893f78b857f7450d7e0237e9c8fc6427a81bae7ed1" +dependencies = [ + "cfg-if", + "fnv", + "lazy_static", + "memchr", + "parking_lot", + "protobuf", + "thiserror", +] + +[[package]] +name = "protobuf" +version = "2.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" + [[package]] name = "quote" version = "1.0.38" @@ -458,6 +1565,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "redox_syscall" version = "0.5.8" @@ -511,12 +1648,71 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "rmp" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4" +dependencies = [ + "byteorder", + "num-traits", + "paste", +] + +[[package]] +name = "rmp-serde" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + +[[package]] +name = "rust_decimal" +version = "1.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" +dependencies = [ + "arrayvec", + "num-traits", +] + [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustracing" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44822b10c095e574869de2b891e40c724fef42cadaea040d1cd3bdbb13d36a5" +dependencies = [ + "backtrace", + "crossbeam-channel", + "rand", + "trackable 0.2.24", +] + +[[package]] +name = "rustracing_jaeger" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6c2fe9411ef5f43ac773f0e84ad735804c55719346a7aad52de2d9162db97c8" +dependencies = [ + "crossbeam-channel", + "hostname", + "percent-encoding", + "rand", + "rustracing", + "thrift_codec", + "trackable 0.2.24", +] + [[package]] name = "rustversion" version = "1.0.19" @@ -567,6 +1763,29 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_yaml" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b" +dependencies = [ + "indexmap 1.9.3", + "ryu", + "serde", + "yaml-rust", +] + +[[package]] +name = "sfv" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27daf6ed3fc7ffd5ea3ce9f684fe351c47e50f2fdbb6236e2bad0b440dbe408" +dependencies = [ + "data-encoding", + "indexmap 2.7.1", + "rust_decimal", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -591,6 +1810,15 @@ dependencies = [ "libc", ] +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" version = "1.13.2" @@ -604,7 +1832,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -613,13 +1841,19 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "structopt" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" dependencies = [ - "clap", + "clap 2.34.0", "lazy_static", "structopt-derive", ] @@ -630,13 +1864,41 @@ version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ - "heck", + "heck 0.3.3", "proc-macro-error", "proc-macro2", "quote", "syn 1.0.109", ] +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.96", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "1.0.109" @@ -659,6 +1921,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "textwrap" version = "0.11.0" @@ -668,6 +1939,32 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", +] + [[package]] name = "thread_local" version = "1.1.8" @@ -678,6 +1975,16 @@ dependencies = [ "once_cell", ] +[[package]] +name = "thrift_codec" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fb61fb3d0a0af14949f3a6949b2639112e13226647112824f4d081533f9b1a8" +dependencies = [ + "byteorder", + "trackable 0.2.24", +] + [[package]] name = "tokio" version = "1.43.0" @@ -693,7 +2000,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -718,6 +2025,38 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-test" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2468baabc3311435b55dd935f702f42cd1b8abb7e754fb7dfb16bd36aa88f9f7" +dependencies = [ + "async-stream", + "bytes", + "futures-core", + "tokio", + "tokio-stream", +] + +[[package]] +name = "tokio-util" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + [[package]] name = "tracing" version = "0.1.41" @@ -804,10 +2143,57 @@ dependencies = [ ] [[package]] -name = "unicode-ident" -version = "1.0.14" +name = "trackable" +version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" +checksum = "b98abb9e7300b9ac902cc04920945a874c1973e08c310627cc4458c04b70dd32" +dependencies = [ + "trackable 1.3.0", + "trackable_derive", +] + +[[package]] +name = "trackable" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15bd114abb99ef8cee977e517c8f37aee63f184f2d08e3e6ceca092373369ae" +dependencies = [ + "trackable_derive", +] + +[[package]] +name = "trackable_derive" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebeb235c5847e2f82cfe0f07eb971d1e5f6804b18dac2ae16349cc604380f82f" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicase" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" + +[[package]] +name = "unicode-ident" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11cd88e12b17c6494200a9c1b683a04fcac9573ed74cd1b62aeb2727c5592243" [[package]] name = "unicode-segmentation" @@ -821,6 +2207,12 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "valuable" version = "0.1.1" @@ -839,6 +2231,15 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -919,6 +2320,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -943,6 +2353,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -1006,3 +2425,61 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", +] + +[[package]] +name = "zstd" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcf2b778a664581e31e389454a7072dab1647606d44f7feea22cd5abb9c9f3f9" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a3ab4db68cea366acc5c897c7b4d4d1b8994a9cd6e6f841f8964566a419059" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.13+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 6999d9d..e8ae627 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,22 @@ edition = "2021" [dependencies] bytes = "1.9.0" -tokio = "1.43.0" mini-redis = "0.4" - +#async-trait = "0.1" +hyper-reverse-proxy = "0.5" +hyper = { version = "0.14", features = ["full"] } +rand = "0.8.5" +dashmap = "6.1.0" +http-body-util = "0.1" +hyper-util = { version = "0.1", features = ["full"] } +tokio = { version = "1", features = ["full"] } +#pingora = { version = "0.4", features = ["full"] } +pingora = { version = "0.4.0", features = ["lb"] } +pingora-core = { version = "0.4.0" } +pingora-proxy = { version = "0.4.0" } +pingora-load-balancing = { version = "0.4.0" } +pingora-http = { version = "0.4.0" } +async-trait = { version = "0.1.85" } +env_logger = { version = "0.11.6" } +log = "0.4.25" +futures = "0.3.31" diff --git a/src/backup/handler.rs b/src/backup/handler.rs new file mode 100644 index 0000000..9a4da39 --- /dev/null +++ b/src/backup/handler.rs @@ -0,0 +1,54 @@ +use crate::peers::Peers; +use hyper::{Body, Request, Response, StatusCode}; +use std::convert::Infallible; +use std::net::IpAddr; +use std::thread::sleep; +use std::time::Duration; + +pub async fn proxy_http(client_ip: IpAddr, req: Request, db: Peers) -> Result, Infallible> { + let p = db.clone(); + let rurl = req.uri().path(); + let yoyo = req.uri().path().to_string(); // Bad thing, only for debug + let peer = crate::peers::return_peer(p, rurl); + match hyper_reverse_proxy::call(client_ip, peer.as_ref(), req).await { + Ok(response) => { + println!("Peer: {}, Client: {}, Path: {}, Status: {}", peer.as_ref(), client_ip, yoyo, response.status()); + Ok(response) + } + Err(_error) => { + println!("Error: no live peers for: {}", yoyo); + Ok(Response::builder().status(StatusCode::INTERNAL_SERVER_ERROR).body(Body::empty()).unwrap()) + } + } +} + +pub async fn healthcheck(peers: Peers, work: Peers) -> Result, Infallible> { + loop { + println!("Main Peers -> {:?}", peers); + println!("Work Peers -> {:?}", work); + sleep(Duration::from_secs(10)); + + peers.clone().iter().for_each(|peer| { + work.insert(peer.key().clone(), peer.value().clone()); + // work[peer.key()] = peer.value(); + }); + } +} + +// #[tokio::main] +// async fn client_check(url: &str) { +// let url = url.parse::().unwrap(); +// let host = url.host().expect("uri has no host"); +// let port = url.port_u16().unwrap_or(80); +// let address = format!("{}:{}", host, port); +// let stream = TcpStream::connect(address).await.unwrap(); +// let io = TokioIo::new(stream); +// let (mut sender, conn) = hyper::client::conn::http1::handshake(io).await.unwrap(); +// +// // Spawn a task to poll the connection, driving the HTTP state +// tokio::task::spawn(async move { +// if let Err(err) = conn.await { +// println!("Connection failed: {:?}", err); +// } +// }); +// } diff --git a/src/backup/peers.rs b/src/backup/peers.rs new file mode 100644 index 0000000..2437d27 --- /dev/null +++ b/src/backup/peers.rs @@ -0,0 +1,28 @@ +use dashmap::DashMap; +use rand::Rng; +use std::sync::Arc; + +// type Db = Arc, Arc>>>; +pub type Peers = Arc, Vec>>>; + +pub fn add_peers(peers: Peers, path: &str) { + if let Some(mut peers_list) = peers.get_mut(&Arc::from(path)) { + peers_list.push(Arc::from("http://192.168.1.1:8000")); + peers_list.push(Arc::from("http://192.168.1.10:8000")); + } + println!("Adding peers {} -> {:?}", peers.get(path).unwrap().key(), peers.get(path).unwrap().value()); +} +pub fn return_peer(peers: Peers, path: &str) -> Arc { + if let Some(peer_list) = peers.get(&Arc::from(path)) { + let mut rng = rand::thread_rng(); + let r = rng.gen_range(0..peer_list.len()); + + if let Some(selected_peer) = peer_list.get(r) { + selected_peer.clone() + } else { + Arc::from("https://127.0.0.1:8443") + } + } else { + Arc::from("https://127.0.0.1:8443") + } +} diff --git a/src/backup/start.rs b/src/backup/start.rs new file mode 100644 index 0000000..47a66f0 --- /dev/null +++ b/src/backup/start.rs @@ -0,0 +1,45 @@ +use dashmap::DashMap; +use hyper::server::conn::AddrStream; +use hyper::service::{make_service_fn, service_fn}; +use hyper::Server; +use web::handler; +use web::peers; + +#[tokio::main] +async fn main() { + let bind_addr = "0.0.0.0:6193"; + let addr: SocketAddr = bind_addr.parse().expect("Could not parse ip:port."); + + let main_peers: peers::Peers = Arc::new(DashMap::new()); + let work_peers: peers::Peers = Arc::new(DashMap::new()); + + main_peers.insert(Arc::from("/first"), vec![]); + let p = main_peers.clone(); + peers::add_peers(p, "/first"); + + main_peers.insert(Arc::from("/second"), vec![]); + let r = main_peers.clone(); + peers::add_peers(r, "/second"); + + let main_prs = main_peers.clone(); + let work_prs = work_peers.clone(); + tokio::spawn(async move { + let h = handler::healthcheck(main_prs.clone(), work_prs.clone()); + h.await.expect("health check failed"); + // handler::healthcheck(main_prs.clone(), work_prs.clone()).await; + }); + + let make_svc = make_service_fn(|conn: &AddrStream| { + let remote_addr = conn.remote_addr().ip(); + let value = work_peers.clone(); + async move { Ok::<_, Infallible>(service_fn(move |req| handler::proxy_http(remote_addr, req, value.clone()))) } + }); + + let server = Server::bind(&addr).serve(make_svc); + + println!("Running server on {:?}", addr); + + if let Err(e) = server.await { + println!("server error: {}", e); + } +} diff --git a/src/backup/tcpcache.rs b/src/backup/tcpcache.rs new file mode 100644 index 0000000..10e361c --- /dev/null +++ b/src/backup/tcpcache.rs @@ -0,0 +1,113 @@ +/* +use std::collections::HashMap; +use std::sync::Arc; +use tokio::io::{AsyncReadExt, AsyncWriteExt}; +use tokio::net::{TcpListener, TcpStream}; +use tokio::sync::RwLock; + +type Db = Arc, Arc<[u8]>>>>; +const DBG: bool = true; +#[tokio::main] +pub async fn run() { + println!("\n= = = = = = = = ASYNC TOKIO = = = = = = = = =\n"); + if 1 == 1 { + return; + } + let listener = TcpListener::bind("0.0.0.0:6379").await.unwrap(); + println!("Server is running on 0.0.0.0:6379 !\n"); + let hashmap: Db = Arc::new(RwLock::new(HashMap::new())); + loop { + let (socket, _) = listener.accept().await.unwrap(); + let hashmap = hashmap.clone(); + tokio::spawn(async move { + process(socket, hashmap).await; + }); + } +} + +async fn process(mut socket: TcpStream, db: Db) { + let mut buf = vec![0; 1024]; + loop { + let n = socket.read(&mut buf).await.expect("failed to read data from socket"); + match n > 3 { + true => { + if let Some((action, key, value)) = process_data(&buf[..n - 1], b' ') { + let mut map = db.write().await; + match action { + [115, 101, 116] => { + // SET + map.insert(Arc::from(key), Arc::from(value)); + socket.write_all("Done!\n".as_ref()).await.expect("failed to write"); + } + [103, 101, 116] => { + // GET + let t = map.get(&Arc::from(key)); + match t { + Some(t) => { + socket.write_all(t.as_ref()).await.expect("failed to write"); + } + None => { + socket.write_all("Not Found !\n".as_ref()).await.expect("failed to read"); + } + } + } + [100, 101, 108] => { + // DEL + let y = map.remove(&Arc::from(key)); + let mut _mssg = ""; + match y { + Some(_) => { + _mssg = "Deleted !\n"; + } + None => _mssg = "Not Found !\n", + } + socket.write_all(_mssg.as_ref()).await.expect("failed to write"); + } + [98, 121, 101] => { + //BYE + socket.write_all("Bye!: Closing the connection\n".as_ref()).await.expect("failed"); + socket.shutdown().await.expect("shutdown socket error"); + return; + } + _ => socket.write_all("Unknown command: send (get/set/del)\n".as_ref()).await.expect("failed to read"), + } + } + } + false => { + socket.write_all("Only get/set/del commands are accepted\n".as_ref()).await.expect("failed to respond"); + } + } + } +} + +fn process_data(data: &[u8], delim: u8) -> Option<(&[u8], &[u8], &[u8])> { + let action_bytes = &data[..3]; + + if DBG { + match data.get(4..) { + Some(_d) => { + println!(" DEBUG => {} : {} ", std::str::from_utf8(action_bytes).ok()?, std::str::from_utf8(&data[4..]).ok()?); + } + None => println!(" DEBUG => Goodbye"), + } + } + + match action_bytes { + [103, 101, 116] | [100, 101, 108] => { + let key = &data[4..]; + let val = &[]; + return Some((action_bytes, key, val)); + } + [115, 101, 116] => { + if let Some(pos) = data[4..].iter().position(|&b| b == delim) { + let (key_bytes, value_bytes) = data[4..].split_at(pos); + let value_bytes = &value_bytes[1..]; + return Some((action_bytes, key_bytes, value_bytes)); + } + } + _ => return Some((action_bytes, &[], &[])), + } + + None +} +*/ diff --git a/src/main.rs b/src/main.rs index 235e81a..3603ffa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ mod web; fn main() { - web::run::run(); + web::start::run() } diff --git a/src/web.rs b/src/web.rs index 9137f27..87da6ea 100644 --- a/src/web.rs +++ b/src/web.rs @@ -1 +1,5 @@ -pub mod run; +pub mod proxyhttp; +pub mod start; +// pub mod tcpcache; +// pub mod handler; +// pub mod peers; diff --git a/src/web/proxyhttp.rs b/src/web/proxyhttp.rs new file mode 100644 index 0000000..44eda25 --- /dev/null +++ b/src/web/proxyhttp.rs @@ -0,0 +1,228 @@ +use async_trait::async_trait; +use dashmap::DashMap; +use log::{info, warn}; +use pingora::prelude::*; +use pingora_core::prelude::HttpPeer; +use pingora_http::{RequestHeader, ResponseHeader}; +use pingora_proxy::{ProxyHttp, Session}; +use std::any::type_name; +use std::sync::atomic::{AtomicUsize, Ordering}; + +#[allow(dead_code)] +pub fn typeoff(_: T) -> &'static str { + let to = type_name::(); + println!("{:?}", to); + to +} + +// pub struct LB(pub Arc>); +#[allow(dead_code)] +pub struct LB { + // pub load_balancer: Arc>, + // pub upstreams_map: Arc>>, + // pub upstreams_map: Arc>>>, + // upstreams: DashMap, AtomicUsize)>, + // pub upstreams_map: DashMap>, + pub upstreams_map: DashMap, AtomicUsize)>, + // pub upstreams_maps: DashMap>>, +} + +pub trait GetHost { + fn get_host(&self, peer: &str) -> Option<(String, u16)>; + fn set_host(&mut self, peer: &str, host: &str, port: u16); +} + +impl GetHost for LB { + fn get_host(&self, peer: &str) -> Option<(String, u16)> { + // println!("{:?}", self.upstreams_map); + // let entry = self.upstreams_map.get(peer)?; + // let first = entry.value().first()?; + // println!("{:?}", entry.value()); + // Some((first.0.clone(), first.1)) + + let entry = self.upstreams_map.get(peer)?; + let (servers, index) = entry.value(); + + if servers.is_empty() { + return None; + } + + let idx = index.fetch_add(1, Ordering::Relaxed) % servers.len(); + println!("{} {:?} => len: {}, idx: {}", peer, servers[idx], servers.len(), idx); + Some(servers[idx].clone()) + } + + fn set_host(&mut self, peer: &str, host: &str, port: u16) { + // let new_value = vec![(host.to_string(), port)]; + // self.upstreams_map.insert(peer.to_string(), (new_value, AtomicUsize::new(0))); + + let exists = self.upstreams_map.get(peer); + let mut toreturn = vec![]; + match exists { + Some(e) => { + let (ko, _) = e.value(); + let new_value = vec![(host.to_string(), port)]; + for (k, v) in ko.clone().iter() { + toreturn.push((k.to_string(), v.to_owned())); + } + toreturn.push(new_value[0].clone()); + } + None => { + toreturn.push((host.to_string(), port)); + } + } + + println!(" ==> Updating peer list: name => {} | value => {:?}", peer.to_string(), toreturn); + self.upstreams_map.insert(peer.to_string(), (toreturn, AtomicUsize::new(0))); + + // self.upstreams_map.insert(peer.to_string(), toreturn); + + // use std::time::Instant; + // let now = Instant::now(); + // self.get_host(peer); + // let elapsed = now.elapsed(); + // println!("Elapsed: {:.2?}", elapsed); + } +} + +#[async_trait] +impl ProxyHttp for LB { + type CTX = (); + fn new_ctx(&self) -> Self::CTX {} + // async fn upstream_peer(&self, _session: &mut Session, _ctx: &mut ()) -> Result> { + // let upstream = self.load_balancer.select(b"", 256).ok_or_else(|| Error::explain(HTTPStatus(503), "no upstreams"))?; + // let peer = HttpPeer::new(upstream.addr, false, "".to_string()); + // + // let host_name = _session.req_header().headers.get("host"); + // let fo = self.get_host(host_name.unwrap().to_str().unwrap()); + // println!("{:?}", fo); + // + // Ok(Box::new(peer)) + // } + + async fn upstream_peer(&self, session: &mut Session, _ctx: &mut Self::CTX) -> Result> { + let host_name = session.req_header().headers.get("host"); + let ddr = self.get_host(host_name.unwrap().to_str().unwrap()); + match ddr { + Some((host, port)) => { + let peer = Box::new(HttpPeer::new((host, port), false, "".to_string())); + Ok(peer) + } + None => { + println!("Returning default list => {:?}", ("127.0.0.1", 8000)); + let peer = Box::new(HttpPeer::new(("127.0.0.1", 8000), false, "".to_string())); + Ok(peer) + } + } + } + + /* + + async fn upstream_peer(&self, session: &mut Session, _ctx: &mut Self::CTX) -> Result> { + let host_name = session.req_header().headers.get("host").unwrap(); + let addr = self.get_host(host_name.to_str().unwrap()).unwrap(); + info!("connecting to {addr:?}"); + let peer = Box::new(HttpPeer::new(addr, false, "".to_string())); + Ok(peer) + } + */ + async fn request_filter(&self, _session: &mut Session, _ctx: &mut Self::CTX) -> pingora_core::Result + where + Self::CTX: Send + Sync, + { + // if !_session.req_header().uri.path().starts_with("/ping") { + if _session.req_header().uri.path().starts_with("/denied") { + let _ = _session.respond_error(403).await; + info!("Forbidded: {:?}, {}", _session.client_addr(), _session.req_header().uri.path().to_string()); + return Ok(true); + }; + Ok(false) + } + async fn upstream_request_filter(&self, _session: &mut Session, _upstream_request: &mut RequestHeader, _ctx: &mut Self::CTX) -> pingora_core::Result<()> + where + Self::CTX: Send + Sync, + { + let clientip = _session.client_addr(); + match clientip { + Some(ip) => { + let inet = ip.as_inet(); + match inet { + Some(addr) => { + _upstream_request + .insert_header("X-Forwarded-For", addr.to_string().split(':').collect::>()[0]) + .unwrap(); + } + None => warn!("Malformed Client IP: {:?}", inet), + } + } + None => { + warn!("Cannot detect client IP"); + } + } + Ok(()) + } + async fn response_filter(&self, _session: &mut Session, _upstream_response: &mut ResponseHeader, _ctx: &mut Self::CTX) -> pingora_core::Result<()> + where + Self::CTX: Send + Sync, + { + _upstream_response.insert_header("X-Proxied-From", "Fooooooooooooooo").unwrap(); + Ok(()) + } + // async fn logging(&self, session: &mut Session, _e: Option<&pingora::Error>, ctx: &mut Self::CTX) { + // let response_code = session.response_written().map_or(0, |resp| resp.status.as_u16()); + // info!("{}, response code: {response_code}", self.request_summary(session, ctx)); + // } +} + +/* +pub struct SD; + +#[async_trait] +impl ServiceDiscovery for SD { + async fn discover(&self) -> Result<(BTreeSet, HashMap)> { + let addrs = read_upstreams_from_file()?; + + /* + let addr2 = read_upstreams_from_file_d()?; + let mut hmn = HashMap::new(); + for (k, v) in addr2 { + let vl = v + .into_iter() + .map(|addr| Backend { + addr, + weight: 1, + ext: Default::default(), + }) + .collect::>(); + hmn.insert(k, vl); + } + println!("{:?}", hmn); + println!("================== {:?}", addrs); + */ + + let backends = addrs + .into_iter() + .map(|addr| Backend { + addr, + weight: 1, + ext: Default::default(), + }) + .collect::>(); + Ok((backends, HashMap::new())) + } +} + +fn read_upstreams_from_file() -> Result> { + let contents = std::fs::read_to_string("upstreams.txt").map_err(|e| Error::because(ErrorType::InternalError, "reading upstreams file", e))?; + let addrs = contents + .lines() + .filter(|line| !line.trim().is_empty()) + .map(|line| { + line.trim() + .parse::() + .map_err(|e| Error::because(ErrorType::InternalError, "parsing upstream address", e)) + }) + .collect::>>()?; + Ok(addrs) +} +*/ diff --git a/src/web/run.rs b/src/web/run.rs deleted file mode 100644 index 47868b4..0000000 --- a/src/web/run.rs +++ /dev/null @@ -1,46 +0,0 @@ -use bytes::Bytes; -use mini_redis::{Connection, Frame}; -use std::collections::HashMap; -use std::sync::{Arc, Mutex}; -use tokio::net::{TcpListener, TcpStream}; - -type Db = Arc>>; -#[tokio::main] -pub async fn run() { - println!("\n= = = = = = = = ASYNC TOKIO = = = = = = = = =\n"); - let listener = TcpListener::bind("0.0.0.0:6379").await.unwrap(); - println!("Server is running on 0.0.0.0:6379 !\n"); - let db = Arc::new(Mutex::new(HashMap::new())); - loop { - let (socket, _) = listener.accept().await.unwrap(); - let db = db.clone(); - tokio::spawn(async move { - process(socket, db).await; - }); - } -} -async fn process(socket: TcpStream, db: Db) { - use mini_redis::Command::{self, Get, Set}; - let mut connection = Connection::new(socket); - while let Some(frame) = connection.read_frame().await.unwrap() { - let response = match Command::from_frame(frame).unwrap() { - Set(cmd) => { - // println!("{:?}", Command::from_frame(frame).unwrap()); - let mut db = db.lock().unwrap(); - db.insert(cmd.key().to_string(), cmd.value().clone()); - Frame::Simple("OK".to_string()) - } - Get(cmd) => { - let db = db.lock().unwrap(); - if let Some(value) = db.get(cmd.key()) { - println!("{:?}", db); - Frame::Bulk(value.clone()) - } else { - Frame::Null - } - } - cmd => panic!("unimplemented {:?}", cmd), - }; - connection.write_frame(&response).await.unwrap(); - } -} diff --git a/src/web/start.rs b/src/web/start.rs new file mode 100644 index 0000000..26944eb --- /dev/null +++ b/src/web/start.rs @@ -0,0 +1,66 @@ +use crate::web::proxyhttp::{GetHost, LB}; +use dashmap::DashMap; +use pingora_core::server::Server; +use std::sync::atomic::AtomicUsize; +/* +pub fn run1() { + let mut upstreams = LoadBalancer::try_from_iter(vec!["192.168.1.10:8000", "192.168.1.1:8000", "127.0.0.1:8000"]).unwrap(); + env_logger::init(); + let hc = TcpHealthCheck::new(); + upstreams.set_health_check(hc); + upstreams.health_check_frequency = Some(Duration::from_secs(1)); + + let background = background_service("health check", upstreams); + let upstreams = background.task(); + let mut server = Server::new(None).unwrap(); + server.bootstrap(); + + let mut proxy = pingora_proxy::http_proxy_service(&server.configuration, proxyhttp::LB(upstreams)); + + proxy.add_tcp("0.0.0.0:6193"); + server.add_service(background); + server.add_service(proxy); + server.run_forever(); +} +*/ + +pub fn run() { + env_logger::init(); + + let mut server = Server::new(None).unwrap(); + server.bootstrap(); + + // let backends = Backends::new(Box::new(SD)); + // let load_balancer = LoadBalancer::from_backends(backends); + + // load_balancer.set_health_check(TcpHealthCheck::new()); + // load_balancer.health_check_frequency = Some(Duration::from_secs(1)); + // load_balancer.update_frequency = Some(Duration::from_secs(1)); + + // let background = background_service("load balancer", load_balancer); + + let upstreams_map: DashMap, AtomicUsize)> = DashMap::new(); + + let mut ll = LB { + upstreams_map, + // upstreams_maps: DashMap::new(), + }; + add_hosts(&mut ll); + + let mut lb = pingora_proxy::http_proxy_service(&server.configuration, ll); + + lb.add_tcp("0.0.0.0:6193"); + server.add_service(lb); + // server.add_service(background); + + server.run_forever(); +} + +fn add_hosts(lb: &mut LB) { + lb.set_host("myip.netangels.net", "192.168.1.1", 8000); + lb.set_host("myip.netangels.net", "127.0.0.1", 8000); + lb.set_host("myip.netangels.net", "127.0.0.2", 8000); + lb.set_host("polo.netangels.net", "192.168.1.1", 8000); + lb.set_host("polo.netangels.net", "192.168.1.10", 8000); + lb.set_host("glop.netangels.net", "192.168.1.20", 8000); +} diff --git a/start.sh b/start.sh index d5157b6..15b3939 100755 --- a/start.sh +++ b/start.sh @@ -1,4 +1,4 @@ #!/bin/bash - -reflex -d none -r 'src/' -s -- sh -c 'reset && cargo run livelong poem.txt' +export RUST_LOG=INFO +reflex -d none -r 'src/' -s -- sh -c 'reset && cargo run '