From caf438d6bc9421c928eed8bf9395650c91f75bdf Mon Sep 17 00:00:00 2001 From: Asmir Avdicevic Date: Wed, 11 Dec 2024 13:43:30 +0100 Subject: [PATCH] CRs --- Cargo.lock | 180 +++++++++++++++--------------- iroh-relay/src/main.rs | 5 +- iroh-relay/src/server/resolver.rs | 35 +++++- 3 files changed, 124 insertions(+), 96 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aef531a08bd..75771cf861a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -496,9 +496,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.2.2" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" +checksum = "27f657647bcff5394bf56c7317665bbf790a137a50eaaa5c6bfbb9e27a518f2d" dependencies = [ "jobserver", "libc", @@ -545,9 +545,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" dependencies = [ "android-tzdata", "iana-time-zone", @@ -607,9 +607,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.22" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69371e34337c4c984bbe322360c2547210bf632eb2814bbe78a6e87a2935bd2b" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" dependencies = [ "clap_builder", "clap_derive", @@ -617,9 +617,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.22" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e24c1b4099818523236a8ca881d2b45db98dadfb4625cf6608c12069fcbbde1" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" dependencies = [ "anstream", "anstyle", @@ -641,9 +641,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "cmake" @@ -1286,9 +1286,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "ff" @@ -1457,7 +1457,7 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cef40d21ae2c515b51041df9ed313ed21e572df340ea58a922a0aefe7e8891a1" dependencies = [ - "fastrand 2.2.0", + "fastrand 2.3.0", "futures-core", "futures-io", "parking", @@ -1733,14 +1733,14 @@ dependencies = [ "futures-io", "futures-util", "h2", - "http 1.1.0", + "http 1.2.0", "idna", "ipnet", "once_cell", "rand", "rustls", "serde", - "thiserror 2.0.3", + "thiserror 2.0.6", "tinyvec", "tokio", "tokio-rustls", @@ -1766,7 +1766,7 @@ dependencies = [ "rustls", "serde", "smallvec", - "thiserror 2.0.3", + "thiserror 2.0.6", "tokio", "tokio-rustls", "tracing", @@ -1787,12 +1787,12 @@ dependencies = [ "h2", "hickory-proto", "hickory-resolver", - "http 1.1.0", + "http 1.2.0", "ipnet", "prefix-trie", "rustls", "serde", - "thiserror 2.0.3", + "thiserror 2.0.6", "time", "tokio", "tokio-rustls", @@ -1821,9 +1821,9 @@ dependencies = [ [[package]] name = "hmac-sha256" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3688e69b38018fec1557254f64c8dc2cc8ec502890182f395dbb0aa997aa5735" +checksum = "4a8575493d277c9092b988c780c94737fb9fd8651a1001e16bee3eccfc1baedb" [[package]] name = "home" @@ -2313,7 +2313,7 @@ dependencies = [ "surge-ping", "swarm-discovery", "testresult", - "thiserror 2.0.4", + "thiserror 2.0.6", "time", "tokio", "tokio-rustls", @@ -2356,7 +2356,7 @@ dependencies = [ "serde_json", "serde_test", "ssh-key", - "thiserror 2.0.4", + "thiserror 2.0.6", "ttl_cache", "url", "zeroize", @@ -2413,7 +2413,8 @@ dependencies = [ "governor 0.6.3", "hickory-resolver", "hickory-server", - "http 1.1.0", + "http 1.2.0", + "humantime-serde", "iroh", "iroh-metrics", "iroh-test 0.29.0", @@ -2597,7 +2598,7 @@ dependencies = [ "socket2", "stun-rs", "testresult", - "thiserror 2.0.4", + "thiserror 2.0.6", "time", "tokio", "tokio-rustls", @@ -2706,9 +2707,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.74" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a865e038f7f6ed956f788f0d7d60c541fff74c7bd74272c5d4cf15c63743e705" +checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" dependencies = [ "once_cell", "wasm-bindgen", @@ -2731,9 +2732,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.167" +version = "0.2.168" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" +checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" [[package]] name = "libloading" @@ -3037,9 +3038,9 @@ dependencies = [ [[package]] name = "netlink-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416060d346fbaf1f23f9512963e3e878f1a78e707cb699ba9215761754244307" +checksum = "16c903aa70590cb93691bf97a767c8d1d6122d2cc9070433deb3bbf36ce8bd23" dependencies = [ "bytes", "futures", @@ -3072,7 +3073,7 @@ dependencies = [ "rtnetlink 0.14.1", "serde", "socket2", - "thiserror 2.0.4", + "thiserror 2.0.6", "time", "tokio", "tokio-util", @@ -3400,20 +3401,20 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.14" +version = "2.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879952a81a83930934cbf1786752d6dedc3b1f29e8f8fb2ad1d0a36f377cf442" +checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" dependencies = [ "memchr", - "thiserror 1.0.69", + "thiserror 2.0.6", "ucd-trie", ] [[package]] name = "pest_derive" -version = "2.7.14" +version = "2.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d214365f632b123a47fd913301e14c946c61d1c183ee245fa76eb752e59a02dd" +checksum = "816518421cfc6887a0d62bf441b6ffb4536fcc926395a69e1a85852d4363f57e" dependencies = [ "pest", "pest_generator", @@ -3421,9 +3422,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.14" +version = "2.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb55586734301717aea2ac313f50b2eb8f60d2fc3dc01d190eefa2e625f60c4e" +checksum = "7d1396fd3a870fc7838768d171b4616d5c91f6cc25e377b673d714567d99377b" dependencies = [ "pest", "pest_meta", @@ -3434,9 +3435,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.7.14" +version = "2.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75da2a70cf4d9cb76833c990ac9cd3923c9a8905a8929789ce347c84564d03d" +checksum = "e1e58089ea25d717bfd31fb534e4f3afcc2cc569c70de3e239778991ea3b7dea" dependencies = [ "once_cell", "pest", @@ -3631,7 +3632,7 @@ dependencies = [ "serde", "smallvec", "socket2", - "thiserror 2.0.4", + "thiserror 2.0.6", "time", "tokio", "tokio-util", @@ -3878,7 +3879,7 @@ dependencies = [ "rustc-hash 2.1.0", "rustls", "socket2", - "thiserror 2.0.4", + "thiserror 2.0.6", "tokio", "tracing", ] @@ -3897,7 +3898,7 @@ dependencies = [ "rustls", "rustls-pki-types", "slab", - "thiserror 2.0.4", + "thiserror 2.0.6", "tinyvec", "tracing", "web-time", @@ -3905,9 +3906,9 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5a626c6807713b15cac82a6acaccd6043c9a5408c24baae07611fec3f243da" +checksum = "52cd4b1eff68bf27940dd39811292c49e007f4d0b4c357358dc9b0197be6b527" dependencies = [ "cfg_aliases", "libc", @@ -4019,9 +4020,9 @@ dependencies = [ [[package]] name = "redb" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84b1de48a7cf7ba193e81e078d17ee2b786236eed1d3f7c60f8a09545efc4925" +checksum = "a7c2a94325f9c5826b17c42af11067230f503747f870117a28180e85696e21ba" dependencies = [ "libc", ] @@ -4285,15 +4286,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.41" +version = "0.38.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" dependencies = [ "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -4314,14 +4315,14 @@ dependencies = [ [[package]] name = "rustls-cert-file-reader" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b07fb1ad76bcc5f2556e38efb848183eea3eb376afe946a5e24d45993e9c8011" +checksum = "f351eaf1dd003022222d2b1399caac198fefeab45c46b0f98bb03fc7cda9bb27" dependencies = [ "rustls-cert-read", "rustls-pemfile", "rustls-pki-types", - "thiserror 1.0.69", + "thiserror 2.0.6", "tokio", ] @@ -4336,16 +4337,16 @@ dependencies = [ [[package]] name = "rustls-cert-reloadable-resolver" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c79d0e1801489b80611323abe14b8d8be6e9c4f56a86af73949bb03d1c08481c" +checksum = "c85594a2becbced8c66352192c8eea75a44f298acf456593507bc7fa1d837ed3" dependencies = [ "async-trait", "futures-util", "reloadable-state", "rustls", "rustls-cert-read", - "thiserror 1.0.69", + "thiserror 2.0.6", ] [[package]] @@ -4521,9 +4522,9 @@ dependencies = [ [[package]] name = "self_cell" -version = "1.0.4" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a" +checksum = "c2fdfc24bc566f839a2da4c4295b82db7d25a24253867d5c64355abb5799bdbe" [[package]] name = "semver" @@ -4533,9 +4534,9 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" dependencies = [ "serde_derive", ] @@ -4561,9 +4562,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" dependencies = [ "proc-macro2", "quote", @@ -5021,7 +5022,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", - "fastrand 2.2.0", + "fastrand 2.3.0", "once_cell", "rustix", "windows-sys 0.59.0", @@ -5044,11 +5045,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.4" +version = "2.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f49a1853cf82743e3b7950f77e0f4d622ca36cf4317cba00c767838bac8d490" +checksum = "8fec2a1820ebd077e2b90c4df007bebf344cd394098a13c563957d0afc83ea47" dependencies = [ - "thiserror-impl 2.0.4", + "thiserror-impl 2.0.6", ] [[package]] @@ -5064,9 +5065,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.4" +version = "2.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8381894bb3efe0c4acac3ded651301ceee58a15d47c2e34885ed1908ad667061" +checksum = "d65750cab40f4ff1929fb1ba509e9914eb756131cef4210da8d5d700d26f6312" dependencies = [ "proc-macro2", "quote", @@ -5182,12 +5183,11 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.26.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37" dependencies = [ "rustls", - "rustls-pki-types", "tokio", ] @@ -5212,7 +5212,7 @@ dependencies = [ "rustls", "serde", "serde_json", - "thiserror 2.0.4", + "thiserror 2.0.6", "time", "tokio", "tokio-rustls", @@ -5222,9 +5222,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" dependencies = [ "futures-core", "pin-project-lite", @@ -5488,6 +5488,7 @@ dependencies = [ "utf-8", ] +[[package]] name = "typenum" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -5677,9 +5678,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d15e63b4482863c109d70a7b8706c1e364eb6ea449b201a76c5b89cedcec2d5c" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" dependencies = [ "cfg-if", "once_cell", @@ -5688,13 +5689,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d36ef12e3aaca16ddd3f67922bc63e48e953f126de60bd33ccc0101ef9998cd" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", "syn 2.0.90", @@ -5703,9 +5703,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.47" +version = "0.4.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dfaf8f50e5f293737ee323940c7d8b08a66a95a419223d9f41610ca08b0833d" +checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" dependencies = [ "cfg-if", "js-sys", @@ -5716,9 +5716,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "705440e08b42d3e4b36de7d66c944be628d579796b8090bfa3471478a2260051" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -5726,9 +5726,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c9ae5a76e46f4deecd0f0255cc223cfa18dc9b261213b8aa0c7b36f61b3f1d" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", @@ -5739,9 +5739,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ee99da9c5ba11bd675621338ef6fa52296b76b83305e9b6e5c77d4c286d6d49" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" [[package]] name = "watchable" @@ -5757,9 +5757,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.74" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a98bc3c33f0fe7e59ad7cd041b89034fa82a7c2d4365ca538dda6cdaf513863c" +checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" dependencies = [ "js-sys", "wasm-bindgen", @@ -6113,7 +6113,7 @@ dependencies = [ "futures", "log", "serde", - "thiserror 2.0.4", + "thiserror 2.0.6", "windows 0.58.0", "windows-core 0.58.0", ] diff --git a/iroh-relay/src/main.rs b/iroh-relay/src/main.rs index 231f7fec111..f00ceb504fe 100644 --- a/iroh-relay/src/main.rs +++ b/iroh-relay/src/main.rs @@ -26,6 +26,9 @@ use tracing_subscriber::{prelude::*, EnvFilter}; /// The default `http_bind_port` when using `--dev`. const DEV_MODE_HTTP_PORT: u16 = 3340; +/// The default certificate reload interval. +const DEFAULT_CERT_RELOAD_INTERVAL: u64 = 60 * 60 * 24; + /// A relay server for iroh. #[derive(Parser, Debug, Clone)] #[clap(version, about, long_about = None)] @@ -477,7 +480,7 @@ async fn maybe_load_tls( let cert_path = tls.cert_path(); let key_path = tls.key_path(); - let interval = std::time::Duration::from_secs(60 * 60 * 24); + let interval = std::time::Duration::from_secs(DEFAULT_CERT_RELOAD_INTERVAL); let key_reader = rustls_cert_file_reader::FileReader::new( key_path, diff --git a/iroh-relay/src/server/resolver.rs b/iroh-relay/src/server/resolver.rs index 375cdd0fe64..600a8730536 100644 --- a/iroh-relay/src/server/resolver.rs +++ b/iroh-relay/src/server/resolver.rs @@ -6,7 +6,7 @@ use rustls::{ server::{ClientHello, ResolvesServerCert}, sign::CertifiedKey, }; -use tokio::task::JoinHandle; +use tokio_util::task::AbortOnDropHandle; /// A Certificate resolver that reloads the certificate every interval #[derive(Debug)] @@ -14,7 +14,9 @@ pub struct ReloadingResolver { /// The inner reloadable value. reloadable: Arc>, /// The handle to the task that reloads the certificate. - _handle: JoinHandle<()>, + _handle: AbortOnDropHandle<()>, + /// Shutdown signal sender + _shutdown_tx: tokio::sync::oneshot::Sender<()>, } impl ReloadingResolver @@ -28,21 +30,44 @@ where .map_err(|_| anyhow!("Failed to load the certificate"))?; let reloadable = Arc::new(reloadable); + // create a channel to send the shutdown signal + let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel(); + // Spwan a task to reload the certificate every interval. let _reloadable = reloadable.clone(); let _handle = tokio::spawn(async move { let mut interval = tokio::time::interval(interval); - loop { - interval.tick().await; - let _ = _reloadable.reload().await; + tokio::select! { + _ = async { + loop { + interval.tick().await; + let _ = _reloadable.reload().await; + tracing::info!("Reloaded the certificate"); + } + } => {}, + _ = shutdown_rx => { + tracing::info!("Shutdown signal received"); + } } }); + let _handle = AbortOnDropHandle::new(_handle); Ok(Self { reloadable, _handle, + _shutdown_tx: shutdown_tx, }) } + + /// Shutdown the resolver. + pub async fn shutdown(self) { + let _ = self._shutdown_tx.send(()); + } + + /// Reload the certificate. + pub async fn reload(&self) { + let _ = self.reloadable.reload().await; + } } impl ResolvesServerCert for ReloadingResolver