From 6141fe71a59495faec34cd7444be426a5010ee3a Mon Sep 17 00:00:00 2001 From: Skye Date: Thu, 26 Sep 2024 15:51:21 +0900 Subject: [PATCH] halfway done s2n-quic rewrite --- Cargo.lock | 818 ++++++++++++++++++++++++++++++++++++------------- Cargo.toml | 5 +- src/main.rs | 135 +++++--- src/routing.rs | 17 +- 4 files changed, 705 insertions(+), 270 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0bbdc22..a46cc4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,18 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.2" @@ -26,6 +38,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + [[package]] name = "anyhow" version = "1.0.79" @@ -46,12 +64,46 @@ dependencies = [ "syn", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "aws-lc-rs" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f95446d919226d587817a7d21379e6eb099b97b45110a7f272a444ca5c54070" +dependencies = [ + "aws-lc-sys", + "mirai-annotations", + "paste", + "untrusted 0.7.1", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3ddc4a5b231dd6958b140ff3151b6412b3f4321fab354f399eec8f14b06df62" +dependencies = [ + "bindgen", + "cc", + "cmake", + "dunce", + "fs_extra", + "libc", + "paste", +] + [[package]] name = "axum" version = "0.6.20" @@ -122,6 +174,35 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "bitflags 2.4.2", + "cexpr", + "clang-sys", + "itertools", + "lazy_static", + "lazycell", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", + "which", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -135,10 +216,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] -name = "bumpalo" -version = "3.14.0" +name = "byteorder" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" @@ -148,11 +229,22 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cc" -version = "1.0.83" +version = "1.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" dependencies = [ + "jobserver", "libc", + "shlex", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", ] [[package]] @@ -162,20 +254,53 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "core-foundation" -version = "0.9.4" +name = "clang-sys" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" dependencies = [ - "core-foundation-sys", + "glob", "libc", + "libloading", +] + +[[package]] +name = "cmake" +version = "0.1.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb1e43aa7fd152b1f968787f7dbcdeb306d1867ff373c69955211876c053f91a" +dependencies = [ + "cc", ] [[package]] -name = "core-foundation-sys" -version = "0.8.6" +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "cuckoofilter" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b810a8449931679f64cd7eef1bbd0fa315801b6d5d9cdc1ace2804d6529eee18" +dependencies = [ + "byteorder", + "fnv", + "rand 0.7.3", +] + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "either" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "env_logger" @@ -215,6 +340,26 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.30" @@ -222,6 +367,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -230,6 +376,29 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + [[package]] name = "futures-task" version = "0.3.30" @@ -242,10 +411,27 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ + "futures-channel", "futures-core", + "futures-io", + "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", ] [[package]] @@ -256,7 +442,7 @@ checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -265,12 +451,49 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "hash_hasher" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74721d007512d0cb3338cd20f0654ac913920061a4c4d0d8708edb3f2a698c0c" + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", +] + [[package]] name = "hermit-abi" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3" +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" version = "0.2.11" @@ -344,6 +567,15 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "intrusive-collections" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "189d0897e4cbe8c75efedf3502c18c887b05046e59d28404d4d8e46cbc4d1e86" +dependencies = [ + "memoffset", +] + [[package]] name = "is-terminal" version = "0.4.10" @@ -355,6 +587,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[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.10" @@ -362,20 +603,48 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] -name = "js-sys" -version = "0.3.67" +name = "jobserver" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" dependencies = [ - "wasm-bindgen", + "libc", ] +[[package]] +name = "lazy_static" +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.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libloading" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +dependencies = [ + "cfg-if", + "windows-targets 0.52.0", +] + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -410,12 +679,27 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + [[package]] name = "mime" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.2" @@ -432,10 +716,55 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.48.0", ] +[[package]] +name = "mirai-annotations" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9be0862c1b3f26a88803c4a49de6889c10e608b3ee9344e6ef5b45fb37ad3d1" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -461,12 +790,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - [[package]] name = "parking_lot" version = "0.12.1" @@ -490,6 +813,12 @@ dependencies = [ "windows-targets 0.48.5", ] +[[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" @@ -534,6 +863,16 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "prettyplease" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d3928fb5db768cb86f891ff014f0144589297e3c6a1aba6ed7cecfdace270c7" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" version = "1.0.78" @@ -554,10 +893,9 @@ dependencies = [ "idna", "log", "parking_lot", - "quinn", - "rand", - "rustls", - "rustls-pemfile", + "rand 0.8.5", + "rustls-pemfile 1.0.4", + "s2n-quic", "serde", "serde_json", "thiserror", @@ -565,81 +903,65 @@ dependencies = [ ] [[package]] -name = "quinn" -version = "0.10.2" +name = "quote" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cc2c5017e4b43d5995dcea317bc46c1e09404c0a9664d2908f7f02dfe943d75" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ - "bytes", - "pin-project-lite", - "quinn-proto", - "quinn-udp", - "rustc-hash", - "rustls", - "thiserror", - "tokio", - "tracing", + "proc-macro2", ] [[package]] -name = "quinn-proto" -version = "0.10.6" +name = "rand" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "141bf7dfde2fbc246bfd3fe12f2455aa24b0fbd9af535d8c86c7bd1381ff2b1a" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "bytes", - "rand", - "ring 0.16.20", - "rustc-hash", - "rustls", - "rustls-native-certs", - "slab", - "thiserror", - "tinyvec", - "tracing", + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", ] [[package]] -name = "quinn-udp" -version = "0.4.1" +name = "rand" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "055b4e778e8feb9f93c4e439f71dc2156ef13360b432b799e179a8c4cdf0b1d7" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "bytes", "libc", - "socket2", - "tracing", - "windows-sys 0.48.0", + "rand_chacha 0.3.1", + "rand_core 0.6.4", ] [[package]] -name = "quote" -version = "1.0.35" +name = "rand_chacha" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ - "proc-macro2", + "ppv-lite86", + "rand_core 0.5.1", ] [[package]] -name = "rand" -version = "0.8.5" +name = "rand_chacha" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "libc", - "rand_chacha", - "rand_core", + "ppv-lite86", + "rand_core 0.6.4", ] [[package]] -name = "rand_chacha" -version = "0.3.1" +name = "rand_core" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "ppv-lite86", - "rand_core", + "getrandom 0.1.16", ] [[package]] @@ -648,7 +970,16 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.12", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", ] [[package]] @@ -689,21 +1020,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" -[[package]] -name = "ring" -version = "0.16.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin 0.5.2", - "untrusted 0.7.1", - "web-sys", - "winapi", -] - [[package]] name = "ring" version = "0.17.7" @@ -711,9 +1027,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" dependencies = [ "cc", - "getrandom", + "getrandom 0.2.12", "libc", - "spin 0.9.8", + "spin", "untrusted 0.9.0", "windows-sys 0.48.0", ] @@ -745,44 +1061,53 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.10" +version = "0.23.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ + "aws-lc-rs", "log", - "ring 0.17.7", + "once_cell", + "rustls-pki-types", "rustls-webpki", - "sct", + "subtle", + "zeroize", ] [[package]] -name = "rustls-native-certs" -version = "0.6.3" +name = "rustls-pemfile" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "openssl-probe", - "rustls-pemfile", - "schannel", - "security-framework", + "base64 0.21.7", ] [[package]] name = "rustls-pemfile" -version = "1.0.4" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" dependencies = [ - "base64", + "base64 0.22.1", + "rustls-pki-types", ] +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + [[package]] name = "rustls-webpki" -version = "0.101.7" +version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ - "ring 0.17.7", + "aws-lc-rs", + "ring", + "rustls-pki-types", "untrusted 0.9.0", ] @@ -799,53 +1124,129 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] -name = "schannel" -version = "0.1.23" +name = "s2n-codec" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +checksum = "850377b1f41a7ab9f503fc24676f83348a123e0d38cb46b6b05148bb37fdd641" dependencies = [ - "windows-sys 0.52.0", + "byteorder", + "bytes", + "zerocopy", ] [[package]] -name = "scopeguard" -version = "1.2.0" +name = "s2n-quic" +version = "1.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +checksum = "9001e28ac66b347fd7da74d32d1b47f2e8f21dbe5d6168764e19d1f7c94abf5b" +dependencies = [ + "bytes", + "cfg-if", + "cuckoofilter", + "futures", + "hash_hasher", + "rand 0.8.5", + "rand_chacha 0.3.1", + "s2n-codec", + "s2n-quic-core", + "s2n-quic-crypto", + "s2n-quic-platform", + "s2n-quic-rustls", + "s2n-quic-transport", + "tokio", + "zerocopy", + "zeroize", +] [[package]] -name = "sct" -version = "0.7.1" +name = "s2n-quic-core" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +checksum = "3812c691786fce11b953923a018a8aa06dea3723bb2a2393fb3ed257e9c34284" dependencies = [ - "ring 0.17.7", - "untrusted 0.9.0", + "atomic-waker", + "byteorder", + "bytes", + "cfg-if", + "crossbeam-utils", + "hex-literal", + "num-rational", + "num-traits", + "once_cell", + "pin-project-lite", + "s2n-codec", + "subtle", + "zerocopy", ] [[package]] -name = "security-framework" -version = "2.9.2" +name = "s2n-quic-crypto" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +checksum = "79a44934ca63a71fc0a8c4358ece9700340bb951c52f5fdc98f96eb09e9eecdd" dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", + "aws-lc-rs", + "cfg-if", + "lazy_static", + "ring", + "s2n-codec", + "s2n-quic-core", + "zeroize", ] [[package]] -name = "security-framework-sys" -version = "2.9.1" +name = "s2n-quic-platform" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +checksum = "d144224056280cffc36729d852a16fea0a7e753c3b6f17da463bbb732468f4d0" dependencies = [ - "core-foundation-sys", + "cfg-if", + "futures", + "lazy_static", "libc", + "s2n-quic-core", + "socket2", + "tokio", ] +[[package]] +name = "s2n-quic-rustls" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c973d29e9b6669473f205b47d015480d7e79b103dfbd1c789184d9adc31af05" +dependencies = [ + "bytes", + "rustls", + "rustls-pemfile 2.1.3", + "s2n-codec", + "s2n-quic-core", + "s2n-quic-crypto", +] + +[[package]] +name = "s2n-quic-transport" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f55bcf34cd3fce8b1852d2d7c4e0f5a0f98d081afeaddd37ef839b8898be8d" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "hashbrown", + "intrusive-collections", + "once_cell", + "s2n-codec", + "s2n-quic-core", + "siphasher", + "smallvec", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "serde" version = "1.0.196" @@ -899,6 +1300,18 @@ dependencies = [ "serde", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + [[package]] name = "slab" version = "0.4.9" @@ -926,15 +1339,15 @@ dependencies = [ [[package]] name = "spin" -version = "0.5.2" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] -name = "spin" -version = "0.9.8" +name = "subtle" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -1061,21 +1474,9 @@ checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", "pin-project-lite", - "tracing-attributes", "tracing-core", ] -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tracing-core" version = "0.1.32" @@ -1124,6 +1525,12 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "want" version = "0.3.1" @@ -1135,72 +1542,26 @@ dependencies = [ [[package]] name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] -name = "wasm-bindgen" -version = "0.2.90" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "wasm-bindgen-backend" -version = "0.2.90" +name = "which" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" dependencies = [ - "bumpalo", - "log", + "either", + "home", "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.90" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.90" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.90" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" - -[[package]] -name = "web-sys" -version = "0.3.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" -dependencies = [ - "js-sys", - "wasm-bindgen", + "rustix", ] [[package]] @@ -1365,3 +1726,44 @@ name = "windows_x86_64_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + +[[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", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index f239e15..d5185b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,10 +14,9 @@ env_logger = "0.10.0" idna = "0.4.0" log = "0.4.19" parking_lot = "0.12.1" -quinn = "0.10.1" rand = "0.8.5" -rustls = "0.21.9" rustls-pemfile = "1.0.2" +s2n-quic = { version = "1.46.0", default-features = false, features = ["provider-address-token-default", "provider-tls-rustls"] } serde = { version = "1.0.164", features = ["derive"] } serde_json = "1.0.97" thiserror = "1.0.40" @@ -25,4 +24,4 @@ tokio = { version = "1.28.2", features = ["rt-multi-thread", "fs", "macros", "io [profile.release] lto = "fat" -debug = "full" \ No newline at end of file +debug = "full" diff --git a/src/main.rs b/src/main.rs index 1e5669e..e452277 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ #![allow(clippy::cast_possible_truncation)] #![allow(clippy::cast_possible_wrap)] -use std::{convert::Infallible, net::SocketAddr, sync::Arc, time::Duration}; +use std::{convert::Infallible, io::ErrorKind, net::SocketAddr, sync::Arc, time::Duration}; use anyhow::{anyhow, Context}; use axum::{ @@ -11,17 +11,17 @@ use axum::{ }; use log::{error, info}; use netty::{Handshake, ReadError}; -use quinn::{Connecting, ConnectionError, Endpoint, ServerConfig, TransportConfig}; use routing::RoutingTable; -use rustls::{Certificate, PrivateKey}; +use s2n_quic::{connection::Error as ConnectionError, Connection, Server}; use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, net::TcpStream, + task::{JoinError, JoinSet}, }; use crate::{ netty::{ReadExt, WriteExt}, - proto::{ClientboundControlMessage, ServerboundControlMessage}, + proto::{ClientboundControlMessage, ServerboundControlMessage}, routing::RouterRequest, }; mod netty; @@ -107,80 +107,116 @@ async fn main() -> anyhow::Result<()> { } async fn try_handle_quic( - connection: Connecting, + connection: Connection, routing_table: &RoutingTable, ) -> anyhow::Result<()> { - let connection = connection.await?; info!( "QUIClime connection established to: {}", - connection.remote_address() + connection.remote_addr()? ); - let (mut send_control, mut recv_control) = connection.accept_bi().await?; - info!("Control channel open: {}", connection.remote_address()); + let mut control = connection + .accept_bidirectional_stream() + .await? + .ok_or(anyhow!( + "Connection closed while waiting for control channel" + ))?; + info!("Control channel open: {}", connection.remote_addr()?); let mut handle = loop { - let mut buf = vec![0u8; recv_control.read_u8().await? as _]; - recv_control.read_exact(&mut buf).await?; + let mut buf = vec![0u8; control.read_u8().await? as _]; + control.read_exact(&mut buf).await?; if let Ok(parsed) = serde_json::from_slice(&buf) { match parsed { ServerboundControlMessage::RequestDomainAssignment => { let handle = routing_table.register(); info!( "Domain assigned to {}: {}", - connection.remote_address(), + connection.remote_addr()?, handle.domain() ); let response = serde_json::to_vec(&ClientboundControlMessage::DomainAssignmentComplete { domain: handle.domain().to_string(), })?; - send_control.write_all(&[response.len() as u8]).await?; - send_control.write_all(&response).await?; + control.write_all(&[response.len() as u8]).await?; + control.write_all(&response).await?; break handle; } } } let response = serde_json::to_vec(&ClientboundControlMessage::UnknownMessage)?; - send_control.write_all(&[response.len() as u8]).await?; - send_control.write_all(&response).await?; + control.write_all(&[response.len() as u8]).await?; + control.write_all(&response).await?; }; - - tokio::select! { - e = connection.closed() => { - match e { - ConnectionError::ConnectionClosed(_) - | ConnectionError::ApplicationClosed(_) - | ConnectionError::LocallyClosed => Ok(()), - e => Err(e.into()), - } - }, - r = async { - while let Some(remote) = handle.next().await { - match remote { - routing::RouterRequest::RouteRequest(remote) => { - let pair = connection.open_bi().await; - if let Err(ConnectionError::ApplicationClosed(_)) = pair { - break; - } else if let Err(ConnectionError::ConnectionClosed(_)) = pair { - break; - } - remote.send(pair?).map_err(|e| anyhow::anyhow!("{:?}", e))?; - } - routing::RouterRequest::BroadcastRequest(message) => { - let response = - serde_json::to_vec(&ClientboundControlMessage::RequestMessageBroadcast { - message, - })?; - send_control.write_all(&[response.len() as u8]).await?; - send_control.write_all(&response).await?; + let mut set = JoinSet::new(); + let (control_message_queue, mut control_message_queue_recv) = tokio::sync::mpsc::unbounded_channel(); + let (mut control_recv, mut control_send) = control.split(); + let send_task = tokio::spawn(async move { + while let Some(event) = control_message_queue_recv.recv().await { + let response = serde_json::to_vec(&event)?; + control_send.write_all(&[response.len() as u8]).await?; + control_send.write_all(&response).await?; + } + Ok::<_, tokio::io::Error>(()) + }); + let control_message_queue_ref = &control_message_queue; + set.spawn(async move { + loop { + let mut buf = vec![0u8; control_recv.read_u8().await? as _]; + control_recv.read_exact(&mut buf).await?; + control_message_queue_ref.send(ClientboundControlMessage::UnknownMessage); + } + Ok::<_, tokio::io::Error>(()) + }); + enum Event { + RouterEvent(RouterRequest), + TaskSet(Result, JoinError>) + } + while let Some(remote) = tokio::select! { + v = handle.next() => v.map(Event::RouterEvent), + v = set.join_next() => v.map(Event::TaskSet), + } { + match remote { + Event::RouterEvent(RouterRequest::RouteRequest((handshake, mut client_stream))) => { + let stream = connection.open_bidirectional_stream().await; + set.spawn(async move { + if let Err( + ConnectionError::Transport { .. } + | ConnectionError::Application { .. } + | ConnectionError::EndpointClosing { .. } + | ConnectionError::ImmediateClose { .. }, + ) = stream + { + Ok(()) + } else { + let mut stream = stream?; + handshake.send(&mut stream).await?; + tokio::io::copy_bidirectional(&mut stream, &mut client_stream).await?; + Ok::<_, tokio::io::Error>(()) } + }); + } + Event::RouterEvent(RouterRequest::BroadcastRequest(message)) => { + control_message_queue.send(ClientboundControlMessage::RequestMessageBroadcast { + message, + }); + } + Event::TaskSet(Ok(Ok(()))) => {} + Event::TaskSet(Ok(Err(e))) => { + if e.kind() != ErrorKind::UnexpectedEof { + error!("Error in task: {e:?}") } } - Ok(()) - } => r + Event::TaskSet(Err(e)) => { + error!("Error in task: {e:?}") + } + + } } + send_task.abort(); + Ok(()) } -async fn handle_quic(connection: Connecting, routing_table: &RoutingTable) { +async fn handle_quic(connection: Connection, routing_table: &RoutingTable) { if let Err(e) = try_handle_quic(connection, routing_table).await { error!("Error handling QUIClime connection: {}", e); }; @@ -188,7 +224,7 @@ async fn handle_quic(connection: Connecting, routing_table: &RoutingTable) { } async fn listen_quic( - endpoint: &'static Endpoint, + mut endpoint: Server, routing_table: &'static RoutingTable, ) -> anyhow::Result { while let Some(connection) = endpoint.accept().await { @@ -198,7 +234,6 @@ async fn listen_quic( } async fn listen_control( - endpoint: &'static Endpoint, routing_table: &'static RoutingTable, ) -> anyhow::Result { let app = axum::Router::new() diff --git a/src/routing.rs b/src/routing.rs index 4239f7f..787198b 100644 --- a/src/routing.rs +++ b/src/routing.rs @@ -1,20 +1,21 @@ use log::info; use log::warn; use parking_lot::RwLock; -use quinn::RecvStream; -use quinn::SendStream; use rand::prelude::*; use std::collections::HashMap; +use tokio::net::TcpStream; use tokio::sync::mpsc; use tokio::sync::oneshot; +use crate::netty::Handshake; + #[derive(Debug)] pub enum RouterRequest { - RouteRequest(RouterCallback), + RouteRequest(RouterConnection), BroadcastRequest(String), } -type RouterCallback = oneshot::Sender<(SendStream, RecvStream)>; +type RouterConnection = (Handshake, TcpStream); type RouteRequestReceiver = mpsc::UnboundedSender; #[allow(clippy::module_name_repetitions)] @@ -44,14 +45,12 @@ impl RoutingTable { } } - pub async fn route(&self, domain: &str) -> Option<(SendStream, RecvStream)> { - let (send, recv) = oneshot::channel(); + pub fn route(&self, domain: &str, conn: RouterConnection) -> Option<()> { self.table .read() .get(domain)? - .send(RouterRequest::RouteRequest(send)) - .ok()?; - recv.await.ok() + .send(RouterRequest::RouteRequest(conn)) + .ok() } pub fn register(&self) -> RoutingHandle {