From 349b25951755cdf7409764534d308b5a06bc65f4 Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 12 Nov 2024 19:35:50 -0500 Subject: [PATCH 01/27] start the exodusssss --- Cargo.lock | 357 ++++++++++++------ Cargo.toml | 2 +- iroh-netcheck/Cargo.toml | 128 +++++++ iroh-netcheck/src/defaults.rs | 166 ++++++++ .../netcheck.rs => iroh-netcheck/src/lib.rs | 4 +- .../netcheck => iroh-netcheck/src}/metrics.rs | 0 iroh-netcheck/src/relay_map.rs | 154 ++++++++ .../src}/reportgen.rs | 0 .../src}/reportgen/hairpin.rs | 19 +- .../src}/reportgen/probes.rs | 2 +- 10 files changed, 703 insertions(+), 129 deletions(-) create mode 100644 iroh-netcheck/Cargo.toml create mode 100644 iroh-netcheck/src/defaults.rs rename iroh-net/src/netcheck.rs => iroh-netcheck/src/lib.rs (99%) rename {iroh-net/src/netcheck => iroh-netcheck/src}/metrics.rs (100%) create mode 100644 iroh-netcheck/src/relay_map.rs rename {iroh-net/src/netcheck => iroh-netcheck/src}/reportgen.rs (100%) rename {iroh-net/src/netcheck => iroh-netcheck/src}/reportgen/hairpin.rs (95%) rename {iroh-net/src/netcheck => iroh-netcheck/src}/reportgen/probes.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 2c1056784d..3dd47f4984 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,9 +65,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.18" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9" [[package]] name = "android-tzdata" @@ -175,7 +175,7 @@ dependencies = [ "nom", "num-traits", "rusticata-macros", - "thiserror 1.0.68", + "thiserror 1.0.69", "time", ] @@ -270,9 +270,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "axum" -version = "0.7.7" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "504e3947307ac8326a5437504c517c4b56716c9d98fac0028c2acc7ca47d70ae" +checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" dependencies = [ "async-trait", "axum-core", @@ -392,7 +392,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1f7a89a8ee5889d2593ae422ce6e1bb03e48a0e8a16e4fa0882dfcbe7e182ef" dependencies = [ "bytes", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "genawaiter", "iroh-blake3", "iroh-io", @@ -658,9 +658,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" +checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" dependencies = [ "clap_builder", "clap_derive", @@ -668,9 +668,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" dependencies = [ "anstream", "anstyle", @@ -692,9 +692,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" [[package]] name = "clipboard-win" @@ -741,14 +741,14 @@ dependencies = [ [[package]] name = "comfy-table" -version = "7.1.1" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b34115915337defe99b2aff5c2ce6771e5fbc4079f4b506301f5cf394c8452f7" +checksum = "24f165e7b643266ea80cb858aed492ad9280e3e05ce24d4a99d7d7b889b6a4d9" dependencies = [ - "crossterm", + "crossterm 0.28.1", "strum 0.26.3", "strum_macros 0.26.4", - "unicode-width", + "unicode-width 0.2.0", ] [[package]] @@ -782,7 +782,7 @@ dependencies = [ "encode_unicode", "lazy_static", "libc", - "unicode-width", + "unicode-width 0.1.14", "windows-sys 0.52.0", ] @@ -826,9 +826,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "0ca741a962e1b0bff6d724a1a0958b686406e853bb14061f218562e1896f95e6" dependencies = [ "libc", ] @@ -940,6 +940,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "crossterm" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" +dependencies = [ + "bitflags 2.6.0", + "crossterm_winapi", + "parking_lot", + "rustix", + "winapi", +] + [[package]] name = "crossterm_winapi" version = "0.9.1" @@ -1167,7 +1180,7 @@ dependencies = [ "console", "shell-words", "tempfile", - "thiserror 1.0.68", + "thiserror 1.0.69", "zeroize", ] @@ -1528,9 +1541,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" [[package]] name = "fd-lock" @@ -1605,7 +1618,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8835f84f38484cc86f110a805655697908257fb9a7af005234060891557198e9" dependencies = [ "nonempty", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -1700,11 +1713,11 @@ dependencies = [ [[package]] name = "futures-lite" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f1fa2f9765705486b33fd2acf1577f8ec449c2ba1f318ae5447697b7c08d210" +checksum = "cef40d21ae2c515b51041df9ed313ed21e572df340ea58a922a0aefe7e8891a1" dependencies = [ - "fastrand 2.1.1", + "fastrand 2.2.0", "futures-core", "futures-io", "parking", @@ -2013,7 +2026,7 @@ dependencies = [ "ipnet", "once_cell", "rand", - "thiserror 1.0.68", + "thiserror 1.0.69", "tinyvec", "tokio", "tracing", @@ -2043,7 +2056,7 @@ dependencies = [ "rustls", "rustls-pemfile", "serde", - "thiserror 1.0.68", + "thiserror 1.0.69", "time", "tinyvec", "tokio", @@ -2069,7 +2082,7 @@ dependencies = [ "lru-cache", "parking_lot", "serde", - "thiserror 1.0.68", + "thiserror 1.0.69", "tokio", "tracing", ] @@ -2092,7 +2105,7 @@ dependencies = [ "rustls", "serde", "smallvec", - "thiserror 1.0.68", + "thiserror 1.0.69", "tokio", "tokio-rustls", "tracing", @@ -2116,7 +2129,7 @@ dependencies = [ "prefix-trie", "rustls", "serde", - "thiserror 1.0.68", + "thiserror 1.0.69", "time", "tokio", "tokio-rustls", @@ -2542,16 +2555,16 @@ dependencies = [ [[package]] name = "indicatif" -version = "0.17.8" +version = "0.17.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "763a5a8f45087d6bcea4222e7b72c291a054edf80e4ef6efd2a4979878c7bea3" +checksum = "cbf675b85ed934d3c67b5c5469701eec7db22689d0a2139d856e0925fa28b281" dependencies = [ "console", - "instant", "number_prefix", "portable-atomic", "tokio", - "unicode-width", + "unicode-width 0.2.0", + "web-time", ] [[package]] @@ -2615,7 +2628,7 @@ dependencies = [ "console", "derive_more", "futures-buffered", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "futures-util", "genawaiter", "indicatif", @@ -2648,7 +2661,7 @@ dependencies = [ "tempfile", "testdir", "testresult", - "thiserror 1.0.68", + "thiserror 1.0.69", "tokio", "tokio-stream", "tokio-util", @@ -2682,7 +2695,7 @@ dependencies = [ "serde_json", "serde_test", "ssh-key", - "thiserror 1.0.68", + "thiserror 1.0.69", "ttl_cache", "url", "zeroize", @@ -2715,7 +2728,7 @@ dependencies = [ "console", "derive_more", "futures-buffered", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "futures-util", "genawaiter", "hashlink", @@ -2767,13 +2780,13 @@ dependencies = [ "colored", "comfy-table", "console", - "crossterm", + "crossterm 0.27.0", "derive_more", "dialoguer", "dirs-next", "duct", "futures-buffered", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "futures-util", "hex", "human-time", @@ -2803,7 +2816,7 @@ dependencies = [ "strum 0.26.3", "tempfile", "testdir", - "thiserror 1.0.68", + "thiserror 1.0.69", "time", "tokio", "tokio-util", @@ -2828,7 +2841,7 @@ dependencies = [ "clap", "derive_more", "dirs-next", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "governor", "hickory-proto 0.25.0-alpha.2", "hickory-resolver", @@ -2879,7 +2892,7 @@ dependencies = [ "dialoguer", "ed25519-dalek", "futures-buffered", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "futures-util", "hex", "indicatif", @@ -2925,7 +2938,7 @@ dependencies = [ "derive_more", "ed25519-dalek", "futures-concurrency", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "futures-util", "hex", "indexmap 2.6.0", @@ -2955,7 +2968,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17e302c5ad649c6a7aa9ae8468e1c4dc2469321af0c6de7341c1be1bdaab434b" dependencies = [ "bytes", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "pin-project", "smallvec", "tokio", @@ -2998,7 +3011,7 @@ dependencies = [ "duct", "futures-buffered", "futures-concurrency", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "futures-sink", "futures-util", "genawaiter", @@ -3053,7 +3066,7 @@ dependencies = [ "surge-ping", "swarm-discovery", "testresult", - "thiserror 1.0.68", + "thiserror 1.0.69", "time", "tokio", "tokio-rustls", @@ -3080,7 +3093,7 @@ dependencies = [ "anyhow", "bytes", "clap", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "hdrhistogram", "iroh-metrics", "iroh-net", @@ -3093,6 +3106,98 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "iroh-netcheck" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "backoff", + "base64 0.22.1", + "bytes", + "cc", + "clap", + "criterion", + "crypto_box", + "der", + "derive_more", + "duct", + "futures-buffered", + "futures-concurrency", + "futures-lite 2.5.0", + "futures-sink", + "futures-util", + "genawaiter", + "governor", + "hex", + "hickory-proto 0.25.0-alpha.2", + "hickory-resolver", + "hostname", + "http 1.1.0", + "http-body-util", + "hyper", + "hyper-util", + "igd-next", + "iroh-base", + "iroh-metrics", + "iroh-quinn", + "iroh-quinn-proto", + "iroh-quinn-udp", + "iroh-relay", + "iroh-test", + "libc", + "mainline", + "netdev", + "netlink-packet-core", + "netlink-packet-route", + "netlink-sys", + "netwatch", + "num_enum", + "once_cell", + "parking_lot", + "pin-project", + "pkarr", + "portmapper", + "postcard", + "pretty_assertions", + "rand", + "rand_chacha", + "rcgen 0.12.1", + "regex", + "reqwest", + "ring", + "rtnetlink", + "rustls", + "rustls-webpki", + "serde", + "serde_json", + "smallvec", + "socket2", + "strum 0.26.3", + "stun-rs", + "surge-ping", + "swarm-discovery", + "testresult", + "thiserror 1.0.69", + "time", + "tokio", + "tokio-rustls", + "tokio-stream", + "tokio-tungstenite", + "tokio-tungstenite-wasm", + "tokio-util", + "tracing", + "tracing-subscriber", + "tungstenite", + "url", + "watchable", + "webpki-roots", + "windows 0.51.1", + "wmi", + "x509-parser", + "z32", +] + [[package]] name = "iroh-quinn" version = "0.12.0" @@ -3106,7 +3211,7 @@ dependencies = [ "rustc-hash", "rustls", "socket2", - "thiserror 1.0.68", + "thiserror 1.0.69", "tokio", "tracing", ] @@ -3124,7 +3229,7 @@ dependencies = [ "rustls", "rustls-platform-verifier", "slab", - "thiserror 1.0.68", + "thiserror 1.0.69", "tinyvec", "tracing", ] @@ -3154,7 +3259,7 @@ dependencies = [ "derive_more", "duct", "futures-buffered", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "futures-sink", "futures-util", "governor", @@ -3190,7 +3295,7 @@ dependencies = [ "smallvec", "socket2", "stun-rs", - "thiserror 1.0.68", + "thiserror 1.0.69", "time", "tokio", "tokio-rustls", @@ -3213,7 +3318,7 @@ dependencies = [ "anyhow", "clap", "futures-buffered", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "futures-util", "iroh-net", "tokio", @@ -3292,7 +3397,7 @@ dependencies = [ "combine", "jni-sys", "log", - "thiserror 1.0.68", + "thiserror 1.0.69", "walkdir", ] @@ -3322,9 +3427,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.161" +version = "0.2.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" [[package]] name = "libm" @@ -3429,7 +3534,7 @@ dependencies = [ "serde_bencode", "serde_bytes", "sha1_smol", - "thiserror 1.0.68", + "thiserror 1.0.69", "tracing", ] @@ -3589,7 +3694,7 @@ dependencies = [ "anyhow", "byteorder", "paste", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -3603,7 +3708,7 @@ dependencies = [ "log", "netlink-packet-core", "netlink-sys", - "thiserror 1.0.68", + "thiserror 1.0.69", "tokio", ] @@ -3627,7 +3732,7 @@ dependencies = [ "anyhow", "bytes", "derive_more", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "futures-sink", "futures-util", "libc", @@ -3639,7 +3744,7 @@ dependencies = [ "rtnetlink", "serde", "socket2", - "thiserror 1.0.68", + "thiserror 1.0.69", "time", "tokio", "tokio-util", @@ -4049,7 +4154,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879952a81a83930934cbf1786752d6dedc3b1f29e8f8fb2ad1d0a36f377cf442" dependencies = [ "memchr", - "thiserror 1.0.68", + "thiserror 1.0.69", "ucd-trie", ] @@ -4137,7 +4242,7 @@ dependencies = [ "rand", "self_cell", "simple-dns", - "thiserror 1.0.68", + "thiserror 1.0.69", "tracing", "ureq", "wasm-bindgen", @@ -4262,7 +4367,7 @@ dependencies = [ "base64 0.22.1", "bytes", "derive_more", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "futures-util", "igd-next", "iroh-metrics", @@ -4275,7 +4380,7 @@ dependencies = [ "serde", "smallvec", "socket2", - "thiserror 1.0.68", + "thiserror 1.0.69", "time", "tokio", "tokio-util", @@ -4515,7 +4620,7 @@ dependencies = [ "derive_more", "educe", "flume", - "futures-lite 2.4.0", + "futures-lite 2.5.0", "futures-sink", "futures-util", "hex", @@ -4549,9 +4654,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quinn" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +checksum = "62e96808277ec6f97351a2380e6c25114bc9e67037775464979f3037c92d05ef" dependencies = [ "bytes", "pin-project-lite", @@ -4560,26 +4665,29 @@ dependencies = [ "rustc-hash", "rustls", "socket2", - "thiserror 1.0.68", + "thiserror 2.0.3", "tokio", "tracing", ] [[package]] name = "quinn-proto" -version = "0.11.8" +version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +checksum = "a2fe5ef3495d7d2e377ff17b1a8ce2ee2ec2a18cde8b6ad6619d65d0701c135d" dependencies = [ "bytes", + "getrandom", "rand", "ring", "rustc-hash", "rustls", + "rustls-pki-types", "slab", - "thiserror 1.0.68", + "thiserror 2.0.3", "tinyvec", "tracing", + "web-time", ] [[package]] @@ -4685,7 +4793,7 @@ dependencies = [ "bitflags 2.6.0", "cassowary", "compact_str", - "crossterm", + "crossterm 0.27.0", "itertools 0.12.1", "lru", "paste", @@ -4693,7 +4801,7 @@ dependencies = [ "strum 0.26.3", "unicode-segmentation", "unicode-truncate", - "unicode-width", + "unicode-width 0.1.14", ] [[package]] @@ -4785,7 +4893,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -4810,9 +4918,9 @@ dependencies = [ [[package]] name = "reflink-copy" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc31414597d1cd7fdd2422798b7652a6329dda0fe0219e6335a13d5bcaa9aeb6" +checksum = "17400ed684c3a0615932f00c271ae3eea13e47056a1455821995122348ab6438" dependencies = [ "cfg-if", "rustix", @@ -4827,7 +4935,7 @@ checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.8", + "regex-automata 0.4.9", "regex-syntax 0.8.5", ] @@ -4842,9 +4950,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -4981,7 +5089,7 @@ dependencies = [ "netlink-proto", "netlink-sys", "nix 0.26.4", - "thiserror 1.0.68", + "thiserror 1.0.69", "tokio", ] @@ -5017,9 +5125,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.39" +version = "0.38.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375116bee2be9ed569afe2154ea6a99dfdffd257f533f187498c2a8f5feaf4ee" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" dependencies = [ "bitflags 2.6.0", "errno", @@ -5030,9 +5138,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.16" +version = "0.23.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" +checksum = "7f1a745511c54ba6d4465e8d5dfbd81b45791756de28d4981af70d6dca128f1e" dependencies = [ "log", "once_cell", @@ -5070,6 +5178,9 @@ name = "rustls-pki-types" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" +dependencies = [ + "web-time", +] [[package]] name = "rustls-platform-verifier" @@ -5145,7 +5256,7 @@ dependencies = [ "radix_trie", "scopeguard", "unicode-segmentation", - "unicode-width", + "unicode-width 0.1.14", "utf8parse", "winapi", ] @@ -5176,9 +5287,9 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" dependencies = [ "windows-sys 0.59.0", ] @@ -5225,9 +5336,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.12.0" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" dependencies = [ "core-foundation-sys", "libc", @@ -5250,9 +5361,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] @@ -5287,9 +5398,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", @@ -5298,9 +5409,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.132" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", "memchr", @@ -5757,7 +5868,7 @@ dependencies = [ "pnet_packet", "rand", "socket2", - "thiserror 1.0.68", + "thiserror 1.0.69", "tokio", "tracing", ] @@ -5873,12 +5984,12 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", - "fastrand 2.1.1", + "fastrand 2.2.0", "once_cell", "rustix", "windows-sys 0.59.0", @@ -5906,11 +6017,11 @@ checksum = "614b328ff036a4ef882c61570f72918f7e9c5bee1da33f8e7f91e01daee7e56c" [[package]] name = "thiserror" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl 1.0.68", + "thiserror-impl 1.0.69", ] [[package]] @@ -5924,9 +6035,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", @@ -6083,7 +6194,7 @@ dependencies = [ "rustls", "serde", "serde_json", - "thiserror 1.0.68", + "thiserror 1.0.69", "time", "tokio", "tokio-rustls", @@ -6142,7 +6253,7 @@ dependencies = [ "http 1.1.0", "httparse", "js-sys", - "thiserror 1.0.68", + "thiserror 1.0.69", "tokio", "tokio-tungstenite", "wasm-bindgen", @@ -6271,7 +6382,7 @@ dependencies = [ "governor", "http 1.1.0", "pin-project", - "thiserror 1.0.68", + "thiserror 1.0.69", "tower 0.4.13", "tracing", ] @@ -6295,7 +6406,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf" dependencies = [ "crossbeam-channel", - "thiserror 1.0.68", + "thiserror 1.0.69", "time", "tracing-subscriber", ] @@ -6390,7 +6501,7 @@ dependencies = [ "log", "rand", "sha1", - "thiserror 1.0.68", + "thiserror 1.0.69", "url", "utf-8", ] @@ -6457,7 +6568,7 @@ checksum = "b3644627a5af5fa321c95b9b235a72fd24cd29c648c2c379431e6628655627bf" dependencies = [ "itertools 0.13.0", "unicode-segmentation", - "unicode-width", + "unicode-width 0.1.14", ] [[package]] @@ -6466,6 +6577,12 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +[[package]] +name = "unicode-width" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" + [[package]] name = "unicode-xid" version = "0.2.6" @@ -6673,7 +6790,7 @@ dependencies = [ "event-listener 4.0.3", "futures-util", "parking_lot", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -6686,6 +6803,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webpki-roots" version = "0.26.6" @@ -7032,7 +7159,7 @@ dependencies = [ "futures", "log", "serde", - "thiserror 1.0.68", + "thiserror 1.0.69", "windows 0.58.0", "windows-core 0.58.0", ] @@ -7062,7 +7189,7 @@ dependencies = [ "nom", "oid-registry", "rusticata-macros", - "thiserror 1.0.68", + "thiserror 1.0.69", "time", ] diff --git a/Cargo.toml b/Cargo.toml index 2f995ba8f6..fb67d6f5dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ "iroh-relay", "iroh-router", "net-tools/netwatch", - "net-tools/portmapper", + "net-tools/portmapper", "iroh-netcheck", ] resolver = "2" diff --git a/iroh-netcheck/Cargo.toml b/iroh-netcheck/Cargo.toml new file mode 100644 index 0000000000..52cb6b3882 --- /dev/null +++ b/iroh-netcheck/Cargo.toml @@ -0,0 +1,128 @@ +[package] +name = "iroh-netcheck" +version = "0.1.0" +edition = "2021" + +# Sadly this also needs to be updated in .github/workflows/ci.yml +rust-version = "1.76" + +[lints] +workspace = true + +[dependencies] +cc = "=1.1.31" # enforce cc version, because of https://github.com/rust-lang/cc-rs/issues/1278 + +anyhow = { version = "1" } +axum = { version = "0.7.4", optional = true } +backoff = "0.4.0" +base64 = "0.22.1" +bytes = "1.7" +clap = { version = "4", features = ["derive"], optional = true } +der = { version = "0.7", features = ["alloc", "derive"] } +derive_more = { version = "1.0.0", features = ["debug", "display", "from", "try_into", "deref"] } +futures-buffered = "0.2.8" +futures-concurrency = "7.6.0" +futures-lite = "2.3" +futures-sink = "0.3.25" +futures-util = "0.3.25" +governor = "0.6.0" +hex = "0.4.3" +hickory-proto = "=0.25.0-alpha.2" +hickory-resolver = "=0.25.0-alpha.2" +hostname = "0.3.1" +http = "1" +http-body-util = "0.1.0" +hyper = { version = "1", features = ["server", "client", "http1"] } +hyper-util = "0.1.1" +igd-next = { version = "0.15.1", features = ["aio_tokio"] } +iroh-base = { version = "0.28.0", features = ["key"] } +iroh-relay = { version = "0.28", path = "../iroh-relay" } +libc = "0.2.139" +netdev = "0.30.0" +netwatch = { version = "0.1.0", path = "../net-tools/netwatch" } +num_enum = "0.7" +once_cell = "1.18.0" +parking_lot = "0.12.1" +pin-project = "1" +pkarr = { version = "2", default-features = false, features = ["async", "relay"] } +portmapper = { version = "0.1.0", path = "../net-tools/portmapper" } +postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] } +quinn = { package = "iroh-quinn", version = "0.12.0" } +quinn-proto = { package = "iroh-quinn-proto", version = "0.12.0" } +quinn-udp = { package = "iroh-quinn-udp", version = "0.5.5" } +rand = "0.8" +rcgen = "0.12" +regex = { version = "1.7.1", optional = true } +reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] } +ring = "0.17" +rustls = { version = "0.23", default-features = false, features = ["ring"] } +serde = { version = "1", features = ["derive", "rc"] } +smallvec = "1.11.1" +socket2 = "0.5.3" +stun-rs = "0.1.5" +surge-ping = "0.8.0" +thiserror = "1" +time = "0.3.20" +tokio = { version = "1", features = ["io-util", "macros", "sync", "rt", "net", "fs", "io-std", "signal", "process"] } +tokio-rustls = { version = "0.26", default-features = false, features = ["logging", "ring"] } +tokio-stream = { version = "0.1.15" } +tokio-tungstenite = "0.21" +tokio-tungstenite-wasm = "0.3" +tokio-util = { version = "0.7.12", features = ["io-util", "io", "codec", "rt"] } +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter"], optional = true } +tungstenite = "0.21" +url = { version = "2.4", features = ["serde"] } +watchable = "1.1.2" +webpki = { package = "rustls-webpki", version = "0.102" } +webpki-roots = "0.26" +x509-parser = "0.16" +z32 = "1.0.3" + +# metrics +iroh-metrics = { version = "0.28.0", default-features = false } +strum = { version = "0.26.2", features = ["derive"] } + +# local-swarm-discovery +swarm-discovery = { version = "0.2.1", optional = true } + +# dht_discovery +genawaiter = { version = "0.99.1", features = ["futures03"], optional = true } + +[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] +netlink-packet-core = "0.7.0" +netlink-packet-route = "0.17.0" +netlink-sys = "0.8.5" +rtnetlink = "0.13.0" + +[target.'cfg(target_os = "windows")'.dependencies] +wmi = "0.13" +windows = { version = "0.51", features = ["Win32_NetworkManagement_IpHelper", "Win32_Foundation", "Win32_NetworkManagement_Ndis", "Win32_Networking_WinSock"] } + +[dev-dependencies] +axum = { version = "0.7.4" } +clap = { version = "4", features = ["derive"] } +criterion = "0.5.1" +crypto_box = { version = "0.9.1", features = ["serde", "chacha20"] } +pretty_assertions = "1.4" +rand_chacha = "0.3.1" +tokio = { version = "1", features = ["io-util", "sync", "rt", "net", "fs", "macros", "time", "test-util"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } +iroh-test = "0.28.0" +serde_json = "1.0.107" +testresult = "0.4.0" +mainline = "2.0.1" + +[build-dependencies] +duct = "0.13.6" + +[features] +default = ["metrics", "discovery-pkarr-dht"] +metrics = ["iroh-metrics/metrics"] +test-utils = ["iroh-relay/test-utils", "iroh-relay/server", "dep:axum"] +discovery-local-network = ["dep:swarm-discovery"] +discovery-pkarr-dht = ["pkarr/dht", "dep:genawaiter"] + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "iroh_docsrs"] diff --git a/iroh-netcheck/src/defaults.rs b/iroh-netcheck/src/defaults.rs new file mode 100644 index 0000000000..6765e52131 --- /dev/null +++ b/iroh-netcheck/src/defaults.rs @@ -0,0 +1,166 @@ +//! Default values used in netcheck. + +use url::Url; + +use crate::{RelayMap, RelayNode}; + +/// The default STUN port used by the Relay server. +/// +/// The STUN port as defined by [RFC 8489]() +pub const DEFAULT_STUN_PORT: u16 = 3478; + +/// The default HTTP port used by the Relay server. +pub const DEFAULT_HTTP_PORT: u16 = 80; + +/// The default HTTPS port used by the Relay server. +pub const DEFAULT_HTTPS_PORT: u16 = 443; + +/// The default metrics port used by the Relay server. +pub const DEFAULT_METRICS_PORT: u16 = 9090; + +/// Production configuration. +pub mod prod { + use super::*; + + /// Hostname of the default NA relay. + pub const NA_RELAY_HOSTNAME: &str = "use1-1.relay.iroh.network."; + /// Hostname of the default EU relay. + pub const EU_RELAY_HOSTNAME: &str = "euw1-1.relay.iroh.network."; + /// Hostname of the default Asia-Pacific relay. + pub const AP_RELAY_HOSTNAME: &str = "aps1-1.relay.iroh.network."; + + /// Get the default [`RelayMap`]. + pub fn default_relay_map() -> RelayMap { + RelayMap::from_nodes([ + default_na_relay_node(), + default_eu_relay_node(), + default_ap_relay_node(), + ]) + .expect("default nodes invalid") + } + + /// Get the default [`RelayNode`] for NA. + pub fn default_na_relay_node() -> RelayNode { + // The default NA relay server run by number0. + let url: Url = format!("https://{NA_RELAY_HOSTNAME}") + .parse() + .expect("default url"); + RelayNode { + url: url.into(), + stun_only: false, + stun_port: DEFAULT_STUN_PORT, + } + } + + /// Get the default [`RelayNode`] for EU. + pub fn default_eu_relay_node() -> RelayNode { + // The default EU relay server run by number0. + let url: Url = format!("https://{EU_RELAY_HOSTNAME}") + .parse() + .expect("default_url"); + RelayNode { + url: url.into(), + stun_only: false, + stun_port: DEFAULT_STUN_PORT, + } + } + + /// Get the default [`RelayNode`] for Asia-Pacific + pub fn default_ap_relay_node() -> RelayNode { + // The default Asia-Pacific relay server run by number0. + let url: Url = format!("https://{AP_RELAY_HOSTNAME}") + .parse() + .expect("default_url"); + RelayNode { + url: url.into(), + stun_only: false, + stun_port: DEFAULT_STUN_PORT, + } + } +} + +/// Staging configuration. +/// +/// Used by tests and might have incompatible changes deployed +/// +/// Note: we have staging servers in EU and NA, but no corresponding staging server for AP at this time. +pub mod staging { + use super::*; + + /// Hostname of the default NA relay. + pub const NA_RELAY_HOSTNAME: &str = "staging-use1-1.relay.iroh.network."; + /// Hostname of the default EU relay. + pub const EU_RELAY_HOSTNAME: &str = "staging-euw1-1.relay.iroh.network."; + + /// Get the default [`RelayMap`]. + pub fn default_relay_map() -> RelayMap { + RelayMap::from_nodes([default_na_relay_node(), default_eu_relay_node()]) + .expect("default nodes invalid") + } + + /// Get the default [`RelayNode`] for NA. + pub fn default_na_relay_node() -> RelayNode { + // The default NA relay server run by number0. + let url: Url = format!("https://{NA_RELAY_HOSTNAME}") + .parse() + .expect("default url"); + RelayNode { + url: url.into(), + stun_only: false, + stun_port: DEFAULT_STUN_PORT, + } + } + + /// Get the default [`RelayNode`] for EU. + pub fn default_eu_relay_node() -> RelayNode { + // The default EU relay server run by number0. + let url: Url = format!("https://{EU_RELAY_HOSTNAME}") + .parse() + .expect("default_url"); + RelayNode { + url: url.into(), + stun_only: false, + stun_port: DEFAULT_STUN_PORT, + } + } +} + +/// Contains all timeouts that we use in `iroh-net`. +pub(crate) mod timeouts { + use std::time::Duration; + + // Timeouts for netcheck + + /// Maximum duration to wait for a netcheck report. + pub(crate) const NETCHECK_REPORT_TIMEOUT: Duration = Duration::from_secs(10); + + /// The maximum amount of time netcheck will spend gathering a single report. + pub(crate) const OVERALL_REPORT_TIMEOUT: Duration = Duration::from_secs(5); + + /// The total time we wait for all the probes. + /// + /// This includes the STUN, ICMP and HTTPS probes, which will all + /// start at different times based on the ProbePlan. + pub(crate) const PROBES_TIMEOUT: Duration = Duration::from_secs(3); + + /// How long to await for a captive-portal result. + /// + /// This delay is chosen so it starts after good-working STUN probes + /// would have finished, but not too long so the delay is bearable if + /// STUN is blocked. + pub(crate) const CAPTIVE_PORTAL_DELAY: Duration = Duration::from_millis(200); + + /// Timeout for captive portal checks + /// + /// Must be lower than [`OVERALL_REPORT_TIMEOUT`] minus + /// [`CAPTIVE_PORTAL_DELAY`]. + pub(crate) const CAPTIVE_PORTAL_TIMEOUT: Duration = Duration::from_secs(2); + + pub(crate) const DNS_TIMEOUT: Duration = Duration::from_secs(3); + + /// The amount of time we wait for a hairpinned packet to come back. + pub(crate) const HAIRPIN_CHECK_TIMEOUT: Duration = Duration::from_millis(100); + + /// Default Pinger timeout + pub(crate) const DEFAULT_PINGER_TIMEOUT: Duration = Duration::from_secs(5); +} diff --git a/iroh-net/src/netcheck.rs b/iroh-netcheck/src/lib.rs similarity index 99% rename from iroh-net/src/netcheck.rs rename to iroh-netcheck/src/lib.rs index 54994c2a0b..70037367ef 100644 --- a/iroh-net/src/netcheck.rs +++ b/iroh-netcheck/src/lib.rs @@ -26,9 +26,11 @@ use tokio::{ use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle}; use tracing::{debug, error, info_span, trace, warn, Instrument}; -use crate::{RelayMap, RelayUrl}; +pub(crate) use relay_map::{RelayMap, RelayMode, RelayNode, RelayUrl}; +pub mod defaults; mod metrics; +mod relay_map; mod reportgen; pub use metrics::Metrics; diff --git a/iroh-net/src/netcheck/metrics.rs b/iroh-netcheck/src/metrics.rs similarity index 100% rename from iroh-net/src/netcheck/metrics.rs rename to iroh-netcheck/src/metrics.rs diff --git a/iroh-netcheck/src/relay_map.rs b/iroh-netcheck/src/relay_map.rs new file mode 100644 index 0000000000..9da1cab425 --- /dev/null +++ b/iroh-netcheck/src/relay_map.rs @@ -0,0 +1,154 @@ +// this needs to live somewhere +use std::{collections::BTreeMap, fmt, sync::Arc}; + +use anyhow::{ensure, Result}; +pub use iroh_relay::RelayUrl; +use serde::{Deserialize, Serialize}; + +use crate::defaults::DEFAULT_STUN_PORT; + +/// Configuration of the relay servers for an [`Endpoint`]. +/// +/// [`Endpoint`]: crate::endpoint::Endpoint +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum RelayMode { + /// Disable relay servers completely. + Disabled, + /// Use the default relay map, with production relay servers from n0. + /// + /// See [`crate::defaults::prod`] for the severs used. + Default, + /// Use the staging relay servers from n0. + Staging, + /// Use a custom relay map. + Custom(RelayMap), +} + +impl RelayMode { + /// Returns the relay map for this mode. + pub fn relay_map(&self) -> RelayMap { + match self { + RelayMode::Disabled => RelayMap::empty(), + RelayMode::Default => crate::defaults::prod::default_relay_map(), + RelayMode::Staging => crate::defaults::staging::default_relay_map(), + RelayMode::Custom(relay_map) => relay_map.clone(), + } + } +} + +/// Configuration of all the relay servers that can be used. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct RelayMap { + /// A map of the different relay IDs to the [`RelayNode`] information + nodes: Arc>>, +} + +impl RelayMap { + /// Returns the sorted relay URLs. + pub fn urls(&self) -> impl Iterator { + self.nodes.keys() + } + + /// Create an empty relay map. + pub fn empty() -> Self { + Self { + nodes: Default::default(), + } + } + + /// Returns an `Iterator` over all known nodes. + pub fn nodes(&self) -> impl Iterator> { + self.nodes.values() + } + + /// Is this a known node? + pub fn contains_node(&self, url: &RelayUrl) -> bool { + self.nodes.contains_key(url) + } + + /// Get the given node. + pub fn get_node(&self, url: &RelayUrl) -> Option<&Arc> { + self.nodes.get(url) + } + + /// How many nodes are known? + pub fn len(&self) -> usize { + self.nodes.len() + } + + /// Are there any nodes in this map? + pub fn is_empty(&self) -> bool { + self.nodes.is_empty() + } + + /// Creates a new [`RelayMap`] with a single relay server configured. + /// + /// Allows to set a custom STUN port and different IP addresses for IPv4 and IPv6. + /// If IP addresses are provided, no DNS lookup will be performed. + pub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self { + let mut nodes = BTreeMap::new(); + nodes.insert( + url.clone(), + RelayNode { + url, + stun_only: false, + stun_port, + } + .into(), + ); + + RelayMap { + nodes: Arc::new(nodes), + } + } + + /// Returns a [`RelayMap`] from a [`RelayUrl`]. + /// + /// This will use the default STUN port and IP addresses resolved from the URL's host name via DNS. + /// relay nodes are specified at <../../docs/relay_nodes.md> + pub fn from_url(url: RelayUrl) -> Self { + Self::default_from_node(url, DEFAULT_STUN_PORT) + } + + /// Constructs the [`RelayMap`] from an iterator of [`RelayNode`]s. + pub fn from_nodes(value: impl IntoIterator) -> Result { + let mut map = BTreeMap::new(); + for node in value.into_iter() { + ensure!(!map.contains_key(&node.url), "Duplicate node url"); + map.insert(node.url.clone(), node.into()); + } + Ok(RelayMap { nodes: map.into() }) + } +} + +impl fmt::Display for RelayMap { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&self, f) + } +} + +/// Information on a specific relay server. +/// +/// Includes the Url where it can be dialed. +// Please note that this is documented in the `iroh.computer` repository under +// `src/app/docs/reference/config/page.mdx`. Any changes to this need to be updated there. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Ord)] +pub struct RelayNode { + /// The [`RelayUrl`] where this relay server can be dialed. + pub url: RelayUrl, + /// Whether this relay server should only be used for STUN requests. + /// + /// This essentially allows you to use a normal STUN server as a relay node, no relay + /// functionality is used. + pub stun_only: bool, + /// The stun port of the relay server. + /// + /// Setting this to `0` means the default STUN port is used. + pub stun_port: u16, +} + +impl fmt::Display for RelayNode { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.url) + } +} diff --git a/iroh-net/src/netcheck/reportgen.rs b/iroh-netcheck/src/reportgen.rs similarity index 100% rename from iroh-net/src/netcheck/reportgen.rs rename to iroh-netcheck/src/reportgen.rs diff --git a/iroh-net/src/netcheck/reportgen/hairpin.rs b/iroh-netcheck/src/reportgen/hairpin.rs similarity index 95% rename from iroh-net/src/netcheck/reportgen/hairpin.rs rename to iroh-netcheck/src/reportgen/hairpin.rs index b2a3fc806c..74a1399450 100644 --- a/iroh-net/src/netcheck/reportgen/hairpin.rs +++ b/iroh-netcheck/src/reportgen/hairpin.rs @@ -21,10 +21,8 @@ use tokio::{sync::oneshot, time::Instant}; use tokio_util::task::AbortOnDropHandle; use tracing::{debug, error, info_span, trace, warn, Instrument}; -use crate::{ - defaults::timeouts::HAIRPIN_CHECK_TIMEOUT, - netcheck::{self, reportgen, Inflight}, -}; +use crate::defaults::timeouts::HAIRPIN_CHECK_TIMEOUT; +use crate::{self, reportgen, Inflight}; /// Handle to the hairpin actor. /// @@ -36,7 +34,7 @@ pub(super) struct Client { } impl Client { - pub(super) fn new(netcheck: netcheck::Addr, reportgen: reportgen::Addr) -> Self { + pub(super) fn new(netcheck: Addr, reportgen: reportgen::Addr) -> Self { let (addr, msg_rx) = oneshot::channel(); let actor = Actor { @@ -84,7 +82,7 @@ enum Message { #[derive(Debug)] struct Actor { msg_rx: oneshot::Receiver, - netcheck: netcheck::Addr, + netcheck: Addr, reportgen: reportgen::Addr, } @@ -119,7 +117,7 @@ impl Actor { }; let (msg_response_tx, msg_response_rx) = oneshot::channel(); self.netcheck - .send(netcheck::Message::InFlightStun(inflight, msg_response_tx)) + .send(Message::InFlightStun(inflight, msg_response_tx)) .await .context("netcheck actor gone")?; msg_response_rx.await.context("netcheck actor died")?; @@ -203,7 +201,7 @@ mod tests { // Setup fake netcheck and reportstate actors, hairpinning interacts with them. let (netcheck_tx, mut netcheck_rx) = mpsc::channel(32); - let netcheck_addr = netcheck::Addr { + let netcheck_addr = Addr { sender: netcheck_tx, }; let (reportstate_tx, mut reportstate_rx) = mpsc::channel(32); @@ -230,8 +228,7 @@ mod tests { // back the STUN request once it arrives. let dummy_netcheck = tokio::spawn( async move { - let netcheck::Message::InFlightStun(inflight, resp_tx) = - netcheck_rx.recv().await.unwrap() + let Message::InFlightStun(inflight, resp_tx) = netcheck_rx.recv().await.unwrap() else { panic!("Wrong message received"); }; @@ -278,7 +275,7 @@ mod tests { // Setup fake netcheck and reportstate actors, hairpinning interacts with them. let (netcheck_tx, _netcheck_rx) = mpsc::channel(32); - let netcheck_addr = netcheck::Addr { + let netcheck_addr = Addr { sender: netcheck_tx, }; let (reportstate_tx, _reportstate_rx) = mpsc::channel(32); diff --git a/iroh-net/src/netcheck/reportgen/probes.rs b/iroh-netcheck/src/reportgen/probes.rs similarity index 99% rename from iroh-net/src/netcheck/reportgen/probes.rs rename to iroh-netcheck/src/reportgen/probes.rs index f2cd400aad..59b5e52274 100644 --- a/iroh-net/src/netcheck/reportgen/probes.rs +++ b/iroh-netcheck/src/reportgen/probes.rs @@ -10,7 +10,7 @@ use anyhow::{ensure, Result}; use netwatch::interfaces; use tokio::time::Duration; -use crate::{netcheck::Report, RelayMap, RelayNode, RelayUrl}; +use crate::{RelayMap, RelayNode, RelayUrl, Report}; /// The retransmit interval used when netcheck first runs. /// From b4a4df61e719ace5edfbd68deb4328f27e3bdc49 Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 12 Nov 2024 19:56:00 -0500 Subject: [PATCH 02/27] move ping in --- iroh-net/src/lib.rs | 2 -- iroh-netcheck/src/lib.rs | 1 + {iroh-net => iroh-netcheck}/src/ping.rs | 0 3 files changed, 1 insertion(+), 2 deletions(-) rename {iroh-net => iroh-netcheck}/src/ping.rs (100%) diff --git a/iroh-net/src/lib.rs b/iroh-net/src/lib.rs index dcb1441120..00a922646d 100644 --- a/iroh-net/src/lib.rs +++ b/iroh-net/src/lib.rs @@ -241,8 +241,6 @@ pub mod dns; pub mod endpoint; mod magicsock; pub mod metrics; -pub mod netcheck; -pub mod ping; mod relay_map; pub mod ticket; pub mod tls; diff --git a/iroh-netcheck/src/lib.rs b/iroh-netcheck/src/lib.rs index 70037367ef..7fddd0d8c0 100644 --- a/iroh-netcheck/src/lib.rs +++ b/iroh-netcheck/src/lib.rs @@ -30,6 +30,7 @@ pub(crate) use relay_map::{RelayMap, RelayMode, RelayNode, RelayUrl}; pub mod defaults; mod metrics; +mod ping; mod relay_map; mod reportgen; diff --git a/iroh-net/src/ping.rs b/iroh-netcheck/src/ping.rs similarity index 100% rename from iroh-net/src/ping.rs rename to iroh-netcheck/src/ping.rs From 3e278dd889379406e6e2db0d63d847a2dbbae749 Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 12 Nov 2024 20:40:38 -0500 Subject: [PATCH 03/27] temporarily do gross 'use crate::self as netcheck' --- iroh-net/src/magicsock.rs | 3 ++- iroh-netcheck/src/reportgen.rs | 10 +++++++--- iroh-netcheck/src/reportgen/hairpin.rs | 15 ++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/iroh-net/src/magicsock.rs b/iroh-net/src/magicsock.rs index 446faafee7..c787b78357 100644 --- a/iroh-net/src/magicsock.rs +++ b/iroh-net/src/magicsock.rs @@ -60,13 +60,14 @@ use self::{ udp_conn::UdpConn, }; use crate::{ + self as netcheck, defaults::timeouts::NETCHECK_REPORT_TIMEOUT, disco::{self, CallMeMaybe, SendAddr}, discovery::{Discovery, DiscoveryItem}, dns::DnsResolver, endpoint::NodeAddr, key::{PublicKey, SecretKey, SharedSecret}, - netcheck, AddrInfo, RelayMap, RelayUrl, + AddrInfo, RelayMap, RelayUrl, }; mod metrics; diff --git a/iroh-netcheck/src/reportgen.rs b/iroh-netcheck/src/reportgen.rs index 8e843b1a9b..9349845ab7 100644 --- a/iroh-netcheck/src/reportgen.rs +++ b/iroh-netcheck/src/reportgen.rs @@ -40,13 +40,17 @@ use url::Host; use super::NetcheckMetrics; use crate::{ + self as netcheck, defaults::DEFAULT_STUN_PORT, - dns::{DnsResolver, ResolverExt}, - netcheck::{self, Report}, + // dns::{DnsResolver, ResolverExt}, ping::{PingError, Pinger}, util::MaybeFuture, - RelayMap, RelayNode, RelayUrl, + RelayMap, + RelayNode, + RelayUrl, + Report, }; +use hickory_resolver::TokioAsyncResolver as DnsResolver; mod hairpin; mod probes; diff --git a/iroh-netcheck/src/reportgen/hairpin.rs b/iroh-netcheck/src/reportgen/hairpin.rs index 74a1399450..47a2830916 100644 --- a/iroh-netcheck/src/reportgen/hairpin.rs +++ b/iroh-netcheck/src/reportgen/hairpin.rs @@ -22,7 +22,7 @@ use tokio_util::task::AbortOnDropHandle; use tracing::{debug, error, info_span, trace, warn, Instrument}; use crate::defaults::timeouts::HAIRPIN_CHECK_TIMEOUT; -use crate::{self, reportgen, Inflight}; +use crate::{self as netcheck, reportgen, Inflight}; /// Handle to the hairpin actor. /// @@ -34,7 +34,7 @@ pub(super) struct Client { } impl Client { - pub(super) fn new(netcheck: Addr, reportgen: reportgen::Addr) -> Self { + pub(super) fn new(netcheck: netcheck::Addr, reportgen: reportgen::Addr) -> Self { let (addr, msg_rx) = oneshot::channel(); let actor = Actor { @@ -82,7 +82,7 @@ enum Message { #[derive(Debug)] struct Actor { msg_rx: oneshot::Receiver, - netcheck: Addr, + netcheck: netcheck::Addr, reportgen: reportgen::Addr, } @@ -117,7 +117,7 @@ impl Actor { }; let (msg_response_tx, msg_response_rx) = oneshot::channel(); self.netcheck - .send(Message::InFlightStun(inflight, msg_response_tx)) + .send(netcheck::Message::InFlightStun(inflight, msg_response_tx)) .await .context("netcheck actor gone")?; msg_response_rx.await.context("netcheck actor died")?; @@ -201,7 +201,7 @@ mod tests { // Setup fake netcheck and reportstate actors, hairpinning interacts with them. let (netcheck_tx, mut netcheck_rx) = mpsc::channel(32); - let netcheck_addr = Addr { + let netcheck_addr = netcheck::Addr { sender: netcheck_tx, }; let (reportstate_tx, mut reportstate_rx) = mpsc::channel(32); @@ -228,7 +228,8 @@ mod tests { // back the STUN request once it arrives. let dummy_netcheck = tokio::spawn( async move { - let Message::InFlightStun(inflight, resp_tx) = netcheck_rx.recv().await.unwrap() + let netcheck::Message::InFlightStun(inflight, resp_tx) = + netcheck_rx.recv().await.unwrap() else { panic!("Wrong message received"); }; @@ -275,7 +276,7 @@ mod tests { // Setup fake netcheck and reportstate actors, hairpinning interacts with them. let (netcheck_tx, _netcheck_rx) = mpsc::channel(32); - let netcheck_addr = Addr { + let netcheck_addr = netcheck::Addr { sender: netcheck_tx, }; let (reportstate_tx, _reportstate_rx) = mpsc::channel(32); From 2eee98c797cb751aeeae03dc7c21a11a168bfb2c Mon Sep 17 00:00:00 2001 From: Diva M Date: Thu, 14 Nov 2024 00:08:29 -0500 Subject: [PATCH 04/27] start dealing with dns, again --- iroh-netcheck/src/dns.rs | 228 +++++++++++++++++++++++++++++++++ iroh-netcheck/src/lib.rs | 1 + iroh-netcheck/src/reportgen.rs | 56 ++++---- 3 files changed, 263 insertions(+), 22 deletions(-) create mode 100644 iroh-netcheck/src/dns.rs diff --git a/iroh-netcheck/src/dns.rs b/iroh-netcheck/src/dns.rs new file mode 100644 index 0000000000..fe07433157 --- /dev/null +++ b/iroh-netcheck/src/dns.rs @@ -0,0 +1,228 @@ +use std::fmt::Write; +use std::net::IpAddr; + +use anyhow::Result; +use futures_lite::{Future, StreamExt}; +use hickory_resolver::{IntoName, TokioAsyncResolver}; + +use crate::defaults::timeouts::DNS_TIMEOUT; + +/// Delay used to perform staggered dns queries. +const DNS_STAGGERING_MS: &[u64] = &[200, 300]; + +/// Extension trait to [`TokioAsyncResolver`]. +pub trait ResolverExt { + /// Perform an ipv4 lookup with a timeout. + fn lookup_ipv4( + &self, + host: N, + ) -> impl Future>>; + + /// Perform an ipv6 lookup with a timeout. + fn lookup_ipv6( + &self, + host: N, + ) -> impl Future>>; + + /// Race an ipv4 and ipv6 lookup with a timeout. + fn lookup_ipv4_ipv6( + &self, + host: N, + ) -> impl Future>>; + + /// Perform an ipv4 lookup with a timeout in a staggered fashion. + /// + /// From the moment this function is called, each lookup is scheduled after the delays in + /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls + /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. The + /// result of the first successful call is returned, or a summary of all errors otherwise. + fn lookup_ipv4_staggered( + &self, + host: N, + ) -> impl Future>>; + + /// Perform an ipv6 lookup with a timeout in a staggered fashion. + /// + /// From the moment this function is called, each lookup is scheduled after the delays in + /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls + /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. The + /// result of the first successful call is returned, or a summary of all errors otherwise. + fn lookup_ipv6_staggered( + &self, + host: N, + ) -> impl Future>>; + + /// Race an ipv4 and ipv6 lookup with a timeout in a staggered fashion. + /// + /// From the moment this function is called, each lookup is scheduled after the delays in + /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls + /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied as stated in + /// [`Self::lookup_ipv4_ipv6`]. The result of the first successful call is returned, or a + /// summary of all errors otherwise. + // TODO(@divma): adjust docs + fn lookup_ipv4_ipv6_staggered( + &self, + host: N, + ) -> impl Future>>; +} + +impl ResolverExt for TokioAsyncResolver { + async fn lookup_ipv4(&self, host: N) -> Result> { + let addrs = tokio::time::timeout(DNS_TIMEOUT, self.ipv4_lookup(host)).await??; + Ok(addrs.into_iter().map(|ip| IpAddr::V4(ip.0))) + } + + async fn lookup_ipv6(&self, host: N) -> Result> { + let addrs = tokio::time::timeout(DNS_TIMEOUT, self.ipv6_lookup(host)).await??; + Ok(addrs.into_iter().map(|ip| IpAddr::V6(ip.0))) + } + + /// Resolve IPv4 and IPv6 in parallel. + /// + /// `LookupIpStrategy::Ipv4AndIpv6` will wait for ipv6 resolution timeout, even if it is + /// not usable on the stack, so we manually query both lookups concurrently and time them out + /// individually. + async fn lookup_ipv4_ipv6( + &self, + host: N, + ) -> Result> { + let res = tokio::join!(self.lookup_ipv4(host.clone()), self.lookup_ipv6(host)); + + match res { + (Ok(ipv4), Ok(ipv6)) => Ok(LookupIter::Both(ipv4.chain(ipv6))), + (Ok(ipv4), Err(_)) => Ok(LookupIter::Ipv4(ipv4)), + (Err(_), Ok(ipv6)) => Ok(LookupIter::Ipv6(ipv6)), + (Err(ipv4_err), Err(ipv6_err)) => { + anyhow::bail!("Ipv4: {:?}, Ipv6: {:?}", ipv4_err, ipv6_err) + } + } + } + + /// Perform an ipv4 lookup with a timeout in a staggered fashion. + /// + /// From the moment this function is called, each lookup is scheduled after the delays in + /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls + /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. The + /// result of the first successful call is returned, or a summary of all errors otherwise. + async fn lookup_ipv4_staggered( + &self, + host: N, + ) -> Result> { + let f = || self.lookup_ipv4(host.clone()); + stagger_call(f, DNS_STAGGERING_MS).await + } + + /// Perform an ipv6 lookup with a timeout in a staggered fashion. + /// + /// From the moment this function is called, each lookup is scheduled after the delays in + /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls + /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. The + /// result of the first successful call is returned, or a summary of all errors otherwise. + async fn lookup_ipv6_staggered( + &self, + host: N, + ) -> Result> { + let f = || self.lookup_ipv6(host.clone()); + stagger_call(f, DNS_STAGGERING_MS).await + } + + /// Race an ipv4 and ipv6 lookup with a timeout in a staggered fashion. + /// + /// From the moment this function is called, each lookup is scheduled after the delays in + /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls + /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied as stated in + /// [`Self::lookup_ipv4_ipv6`]. The result of the first successful call is returned, or a + /// summary of all errors otherwise. + async fn lookup_ipv4_ipv6_staggered( + &self, + host: N, + ) -> Result> { + let f = || self.lookup_ipv4_ipv6(host.clone()); + stagger_call(f, DNS_STAGGERING_MS).await + } +} + +/// Helper enum to give a unified type to the iterators of [`ResolverExt::lookup_ipv4_ipv6`]. +enum LookupIter { + Ipv4(A), + Ipv6(B), + Both(std::iter::Chain), +} + +impl, B: Iterator> Iterator for LookupIter { + type Item = IpAddr; + + fn next(&mut self) -> Option { + match self { + LookupIter::Ipv4(iter) => iter.next(), + LookupIter::Ipv6(iter) => iter.next(), + LookupIter::Both(iter) => iter.next(), + } + } +} + +/// Staggers calls to the future F with the given delays. +/// +/// The first call is performed immediately. The first call to succeed generates an Ok result +/// ignoring any previous error. If all calls fail, an error summarizing all errors is returned. +async fn stagger_call Fut, Fut: Future>>( + f: F, + delays_ms: &[u64], +) -> Result { + let mut calls = futures_buffered::FuturesUnorderedBounded::new(delays_ms.len() + 1); + // NOTE: we add the 0 delay here to have a uniform set of futures. This is more performant than + // using alternatives that allow futures of different types. + for delay in std::iter::once(&0u64).chain(delays_ms) { + let delay = std::time::Duration::from_millis(*delay); + let fut = f(); + let staggered_fut = async move { + tokio::time::sleep(delay).await; + fut.await + }; + calls.push(staggered_fut) + } + + let mut errors = vec![]; + while let Some(call_result) = calls.next().await { + match call_result { + Ok(t) => return Ok(t), + Err(e) => errors.push(e), + } + } + + anyhow::bail!( + "no calls succeed: [ {}]", + errors.into_iter().fold(String::new(), |mut summary, e| { + write!(summary, "{e} ").expect("infallible"); + summary + }) + ) +} + +#[cfg(test)] +pub(crate) mod tests { + use std::sync::atomic::AtomicUsize; + use std::time::Duration; + + use super::*; + const TIMEOUT: Duration = Duration::from_secs(5); + const STAGGERING_DELAYS: &[u64] = &[200, 300]; + + #[tokio::test] + async fn stagger_basic() { + let _logging = iroh_test::logging::setup(); + const CALL_RESULTS: &[Result] = &[Err(2), Ok(3), Ok(5), Ok(7)]; + static DONE_CALL: AtomicUsize = AtomicUsize::new(0); + let f = || { + let r_pos = DONE_CALL.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + async move { + tracing::info!(r_pos, "call"); + CALL_RESULTS[r_pos].map_err(|e| anyhow::anyhow!("{e}")) + } + }; + + let delays = [1000, 15]; + let result = stagger_call(f, &delays).await.unwrap(); + assert_eq!(result, 5) + } +} diff --git a/iroh-netcheck/src/lib.rs b/iroh-netcheck/src/lib.rs index 7fddd0d8c0..aa999f0870 100644 --- a/iroh-netcheck/src/lib.rs +++ b/iroh-netcheck/src/lib.rs @@ -29,6 +29,7 @@ use tracing::{debug, error, info_span, trace, warn, Instrument}; pub(crate) use relay_map::{RelayMap, RelayMode, RelayNode, RelayUrl}; pub mod defaults; +mod dns; mod metrics; mod ping; mod relay_map; diff --git a/iroh-netcheck/src/reportgen.rs b/iroh-netcheck/src/reportgen.rs index 9349845ab7..fa2f812f77 100644 --- a/iroh-netcheck/src/reportgen.rs +++ b/iroh-netcheck/src/reportgen.rs @@ -21,10 +21,11 @@ use std::{ net::{IpAddr, SocketAddr}, pin::Pin, sync::Arc, + task::{Context, Poll}, time::Duration, }; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{anyhow, bail, Context as _, Result}; use iroh_metrics::inc; use iroh_relay::{http::RELAY_PROBE_PATH, protos::stun}; use netwatch::{interfaces, UdpSocket}; @@ -42,13 +43,9 @@ use super::NetcheckMetrics; use crate::{ self as netcheck, defaults::DEFAULT_STUN_PORT, - // dns::{DnsResolver, ResolverExt}, + dns::ResolverExt, ping::{PingError, Pinger}, - util::MaybeFuture, - RelayMap, - RelayNode, - RelayUrl, - Report, + RelayMap, RelayNode, RelayUrl, Report, }; use hickory_resolver::TokioAsyncResolver as DnsResolver; @@ -58,15 +55,11 @@ mod probes; use probes::{Probe, ProbePlan, ProbeProto}; use crate::defaults::timeouts::{ - CAPTIVE_PORTAL_DELAY, CAPTIVE_PORTAL_TIMEOUT, DNS_TIMEOUT, OVERALL_REPORT_TIMEOUT, - PROBES_TIMEOUT, + CAPTIVE_PORTAL_DELAY, CAPTIVE_PORTAL_TIMEOUT, OVERALL_REPORT_TIMEOUT, PROBES_TIMEOUT, }; const ENOUGH_NODES: usize = 3; -/// Delay used to perform staggered dns queries. -const DNS_STAGGERING_MS: &[u64] = &[200, 300]; - /// Holds the state for a single invocation of [`netcheck::Client::get_report`]. /// /// Dropping this will cancel the actor and stop the report generation. @@ -900,7 +893,7 @@ async fn check_captive_portal( // Ideally we would try to resolve **both** IPv4 and IPv6 rather than purely race // them. But our resolver doesn't support that yet. let addrs: Vec<_> = dns_resolver - .lookup_ipv4_ipv6_staggered(domain, DNS_TIMEOUT, DNS_STAGGERING_MS) + .lookup_ipv4_ipv6_staggered(domain) .await? .map(|ipaddr| SocketAddr::new(ipaddr, 0)) .collect(); @@ -963,10 +956,7 @@ async fn get_relay_addr( ProbeProto::StunIpv4 | ProbeProto::IcmpV4 => match relay_node.url.host() { Some(url::Host::Domain(hostname)) => { debug!(?proto, %hostname, "Performing DNS A lookup for relay addr"); - match dns_resolver - .lookup_ipv4_staggered(hostname, DNS_TIMEOUT, DNS_STAGGERING_MS) - .await - { + match dns_resolver.lookup_ipv4_staggered(hostname).await { Ok(mut addrs) => addrs .next() .map(|ip| ip.to_canonical()) @@ -983,10 +973,7 @@ async fn get_relay_addr( ProbeProto::StunIpv6 | ProbeProto::IcmpV6 => match relay_node.url.host() { Some(url::Host::Domain(hostname)) => { debug!(?proto, %hostname, "Performing DNS AAAA lookup for relay addr"); - match dns_resolver - .lookup_ipv6_staggered(hostname, DNS_TIMEOUT, DNS_STAGGERING_MS) - .await - { + match dns_resolver.lookup_ipv6_staggered(hostname).await { Ok(mut addrs) => addrs .next() .map(|ip| ip.to_canonical()) @@ -1071,7 +1058,7 @@ async fn measure_https_latency( // but staggered for reliability. Ideally this tries to resolve **both** IPv4 and // IPv6 though. But our resolver does not have a function for that yet. let addrs: Vec<_> = dns_resolver - .lookup_ipv4_ipv6_staggered(domain, DNS_TIMEOUT, DNS_STAGGERING_MS) + .lookup_ipv4_ipv6_staggered(domain) .await? .map(|ipaddr| SocketAddr::new(ipaddr, 0)) .collect(); @@ -1175,6 +1162,31 @@ fn update_report(report: &mut Report, probe_report: ProbeReport) { .or(probe_report.icmpv6); } +/// Resolves to pending if the inner is `None`. +#[derive(Debug)] +pub(crate) struct MaybeFuture { + /// Future to be polled. + pub inner: Option, +} + +// NOTE: explicit implementation to bypass derive unnecessary bounds +impl Default for MaybeFuture { + fn default() -> Self { + MaybeFuture { inner: None } + } +} + +impl Future for MaybeFuture { + type Output = T::Output; + + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + match self.inner { + Some(ref mut t) => Pin::new(t).poll(cx), + None => Poll::Pending, + } + } +} + #[cfg(test)] mod tests { use std::net::{Ipv4Addr, Ipv6Addr}; From 829b51a16dd39d93db34ca6b3d527bb36a8856f5 Mon Sep 17 00:00:00 2001 From: Diva M Date: Fri, 15 Nov 2024 22:25:32 -0500 Subject: [PATCH 05/27] move relay map and node to base; fix dns stuff --- iroh-base/Cargo.toml | 3 +- iroh-base/src/lib.rs | 4 + iroh-base/src/node_addr.rs | 123 +----------------- {iroh-net => iroh-base}/src/relay_map.rs | 34 +---- iroh-base/src/relay_url.rs | 121 ++++++++++++++++++ iroh-net/src/endpoint.rs | 31 ++++- iroh-net/src/lib.rs | 5 +- iroh-net/src/metrics.rs | 3 +- iroh-netcheck/Cargo.toml | 2 + iroh-netcheck/src/dns.rs | 56 +++++++++ iroh-netcheck/src/lib.rs | 15 ++- iroh-netcheck/src/relay_map.rs | 154 ----------------------- iroh-netcheck/src/reportgen.rs | 2 +- iroh-netcheck/src/reportgen/probes.rs | 2 +- 14 files changed, 235 insertions(+), 320 deletions(-) rename {iroh-net => iroh-base}/src/relay_map.rs (79%) create mode 100644 iroh-base/src/relay_url.rs delete mode 100644 iroh-netcheck/src/relay_map.rs diff --git a/iroh-base/Cargo.toml b/iroh-base/Cargo.toml index 22945ad860..c56a88e114 100644 --- a/iroh-base/Cargo.toml +++ b/iroh-base/Cargo.toml @@ -47,12 +47,13 @@ serde_json = "1.0.107" serde_test = "1.0.176" [features] -default = ["hash", "base32"] +default = ["hash", "base32", "relay"] hash = ["dep:blake3", "dep:data-encoding", "dep:postcard", "dep:derive_more", "base32"] base32 = ["dep:data-encoding", "dep:postcard"] redb = ["dep:redb"] key = ["dep:ed25519-dalek", "dep:once_cell", "dep:rand", "dep:rand_core", "dep:ssh-key", "dep:ttl_cache", "dep:aead", "dep:crypto_box", "dep:zeroize", "dep:url", "dep:derive_more", "dep:getrandom"] wasm = ["getrandom?/js"] +relay = [] [package.metadata.docs.rs] all-features = true diff --git a/iroh-base/src/lib.rs b/iroh-base/src/lib.rs index 2c8ec03fdc..1c0b2ce748 100644 --- a/iroh-base/src/lib.rs +++ b/iroh-base/src/lib.rs @@ -13,6 +13,10 @@ pub mod key; #[cfg(feature = "key")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "key")))] pub mod node_addr; +#[cfg(feature = "relay")] +#[cfg_attr(iroh_docsrs, doc(cfg(feature = "relay")))] +pub mod relay_map; +mod relay_url; #[cfg(feature = "base32")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "base32")))] pub mod ticket; diff --git a/iroh-base/src/node_addr.rs b/iroh-base/src/node_addr.rs index 346e3f525a..e7f959148c 100644 --- a/iroh-base/src/node_addr.rs +++ b/iroh-base/src/node_addr.rs @@ -6,14 +6,14 @@ //! //! The primary way of addressing a node is by using the [`NodeAddr`]. -use std::{collections::BTreeSet, fmt, net::SocketAddr, ops::Deref, str::FromStr}; +use std::{collections::BTreeSet, net::SocketAddr}; -use anyhow::Context; use serde::{Deserialize, Serialize}; -use url::Url; use crate::key::{NodeId, PublicKey}; +pub use crate::relay_url::RelayUrl; + /// Network-level addressing information for an iroh-net node. /// /// This combines a node's identifier with network-level addressing information of how to @@ -199,120 +199,3 @@ pub enum AddrInfoOptions { /// Includes the Node ID and the direct addresses. Addresses, } - -/// A URL identifying a relay server. -/// -/// This is but a wrapper around [`Url`], with a few custom tweaks: -/// -/// - A relay URL is never a relative URL, so an implicit `.` is added at the end of the -/// domain name if missing. -/// -/// - [`fmt::Debug`] is implemented so it prints the URL rather than the URL struct fields. -/// Useful when logging e.g. `Option`. -/// -/// To create a [`RelayUrl`] use the `From` implementation. -#[derive( - Clone, derive_more::Display, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, -)] -pub struct RelayUrl(Url); - -impl From for RelayUrl { - fn from(mut url: Url) -> Self { - if let Some(domain) = url.domain() { - if !domain.ends_with('.') { - let domain = String::from(domain) + "."; - - // This can fail, though it is unlikely the resulting URL is usable as a - // relay URL, probably it has the wrong scheme or is not a base URL or the - // like. We don't do full URL validation however, so just silently leave - // this bad URL in place. Something will fail later. - url.set_host(Some(&domain)).ok(); - } - } - Self(url) - } -} - -/// Support for parsing strings directly. -/// -/// If you need more control over the error first create a [`Url`] and use [`RelayUrl::from`] -/// instead. -impl FromStr for RelayUrl { - type Err = anyhow::Error; - - fn from_str(s: &str) -> Result { - let inner = Url::from_str(s).context("invalid URL")?; - Ok(RelayUrl::from(inner)) - } -} - -impl From for Url { - fn from(value: RelayUrl) -> Self { - value.0 - } -} - -/// Dereferences to the wrapped [`Url`]. -/// -/// Note that [`DerefMut`] is not implemented on purpose, so this type has more flexibility -/// to change the inner later. -/// -/// [`DerefMut`]: std::ops::DerefMut -impl Deref for RelayUrl { - type Target = Url; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl fmt::Debug for RelayUrl { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_tuple("RelayUrl") - .field(&DbgStr(self.0.as_str())) - .finish() - } -} - -/// Helper struct to format a &str without allocating a String. -/// -/// Maybe this is entirely unneeded and the compiler would be smart enough to never allocate -/// the String anyway. Who knows. Writing this was faster than checking the assembler -/// output. -struct DbgStr<'a>(&'a str); - -impl<'a> fmt::Debug for DbgStr<'a> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, r#""{}""#, self.0) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_relay_url_debug_display() { - let url = RelayUrl::from(Url::parse("https://example.com").unwrap()); - - assert_eq!(format!("{url:?}"), r#"RelayUrl("https://example.com./")"#); - - assert_eq!(format!("{url}"), "https://example.com./"); - } - - #[test] - fn test_relay_url_absolute() { - let url = RelayUrl::from(Url::parse("https://example.com").unwrap()); - - assert_eq!(url.domain(), Some("example.com.")); - - let url1 = RelayUrl::from(Url::parse("https://example.com.").unwrap()); - assert_eq!(url, url1); - - let url2 = RelayUrl::from(Url::parse("https://example.com./").unwrap()); - assert_eq!(url, url2); - - let url3 = RelayUrl::from(Url::parse("https://example.com/").unwrap()); - assert_eq!(url, url3); - } -} diff --git a/iroh-net/src/relay_map.rs b/iroh-base/src/relay_map.rs similarity index 79% rename from iroh-net/src/relay_map.rs rename to iroh-base/src/relay_map.rs index 727ccf61c2..4a01d17c2e 100644 --- a/iroh-net/src/relay_map.rs +++ b/iroh-base/src/relay_map.rs @@ -2,40 +2,14 @@ use std::{collections::BTreeMap, fmt, sync::Arc}; +pub use crate::relay_url::RelayUrl; use anyhow::{ensure, Result}; -pub use iroh_relay::RelayUrl; use serde::{Deserialize, Serialize}; -use crate::defaults::DEFAULT_STUN_PORT; - -/// Configuration of the relay servers for an [`Endpoint`]. +/// The default STUN port used by the Relay server. /// -/// [`Endpoint`]: crate::endpoint::Endpoint -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum RelayMode { - /// Disable relay servers completely. - Disabled, - /// Use the default relay map, with production relay servers from n0. - /// - /// See [`crate::defaults::prod`] for the severs used. - Default, - /// Use the staging relay servers from n0. - Staging, - /// Use a custom relay map. - Custom(RelayMap), -} - -impl RelayMode { - /// Returns the relay map for this mode. - pub fn relay_map(&self) -> RelayMap { - match self { - RelayMode::Disabled => RelayMap::empty(), - RelayMode::Default => crate::defaults::prod::default_relay_map(), - RelayMode::Staging => crate::defaults::staging::default_relay_map(), - RelayMode::Custom(relay_map) => relay_map.clone(), - } - } -} +/// The STUN port as defined by [RFC 8489]() +const DEFAULT_STUN_PORT: u16 = 3478; /// Configuration of all the relay servers that can be used. #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/iroh-base/src/relay_url.rs b/iroh-base/src/relay_url.rs new file mode 100644 index 0000000000..fb828e8bf1 --- /dev/null +++ b/iroh-base/src/relay_url.rs @@ -0,0 +1,121 @@ +use std::{fmt, ops::Deref, str::FromStr}; + +use anyhow::Context; +use serde::{Deserialize, Serialize}; +use url::Url; +/// A URL identifying a relay server. +/// +/// This is but a wrapper around [`Url`], with a few custom tweaks: +/// +/// - A relay URL is never a relative URL, so an implicit `.` is added at the end of the +/// domain name if missing. +/// +/// - [`fmt::Debug`] is implemented so it prints the URL rather than the URL struct fields. +/// Useful when logging e.g. `Option`. +/// +/// To create a [`RelayUrl`] use the `From` implementation. +#[derive( + Clone, derive_more::Display, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, +)] +pub struct RelayUrl(Url); + +impl From for RelayUrl { + fn from(mut url: Url) -> Self { + if let Some(domain) = url.domain() { + if !domain.ends_with('.') { + let domain = String::from(domain) + "."; + + // This can fail, though it is unlikely the resulting URL is usable as a + // relay URL, probably it has the wrong scheme or is not a base URL or the + // like. We don't do full URL validation however, so just silently leave + // this bad URL in place. Something will fail later. + url.set_host(Some(&domain)).ok(); + } + } + Self(url) + } +} + +/// Support for parsing strings directly. +/// +/// If you need more control over the error first create a [`Url`] and use [`RelayUrl::from`] +/// instead. +impl FromStr for RelayUrl { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + let inner = Url::from_str(s).context("invalid URL")?; + Ok(RelayUrl::from(inner)) + } +} + +impl From for Url { + fn from(value: RelayUrl) -> Self { + value.0 + } +} + +/// Dereferences to the wrapped [`Url`]. +/// +/// Note that [`DerefMut`] is not implemented on purpose, so this type has more flexibility +/// to change the inner later. +/// +/// [`DerefMut`]: std::ops::DerefMut +impl Deref for RelayUrl { + type Target = Url; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl fmt::Debug for RelayUrl { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("RelayUrl") + .field(&DbgStr(self.0.as_str())) + .finish() + } +} + +/// Helper struct to format a &str without allocating a String. +/// +/// Maybe this is entirely unneeded and the compiler would be smart enough to never allocate +/// the String anyway. Who knows. Writing this was faster than checking the assembler +/// output. +struct DbgStr<'a>(&'a str); + +impl<'a> fmt::Debug for DbgStr<'a> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, r#""{}""#, self.0) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_relay_url_debug_display() { + let url = RelayUrl::from(Url::parse("https://example.com").unwrap()); + + assert_eq!(format!("{url:?}"), r#"RelayUrl("https://example.com./")"#); + + assert_eq!(format!("{url}"), "https://example.com./"); + } + + #[test] + fn test_relay_url_absolute() { + let url = RelayUrl::from(Url::parse("https://example.com").unwrap()); + + assert_eq!(url.domain(), Some("example.com.")); + + let url1 = RelayUrl::from(Url::parse("https://example.com.").unwrap()); + assert_eq!(url, url1); + + let url2 = RelayUrl::from(Url::parse("https://example.com./").unwrap()); + assert_eq!(url, url2); + + let url3 = RelayUrl::from(Url::parse("https://example.com/").unwrap()); + assert_eq!(url, url3); + } +} diff --git a/iroh-net/src/endpoint.rs b/iroh-net/src/endpoint.rs index 8ffcbeba8a..091cda7f18 100644 --- a/iroh-net/src/endpoint.rs +++ b/iroh-net/src/endpoint.rs @@ -24,6 +24,7 @@ use std::{ use anyhow::{anyhow, bail, Context, Result}; use derive_more::Debug; use futures_lite::{Stream, StreamExt}; +use iroh_base::relay_map::RelayMap; use pin_project::pin_project; use tokio_util::sync::{CancellationToken, WaitForCancellationFuture}; use tracing::{debug, instrument, trace, warn}; @@ -36,7 +37,7 @@ use crate::{ dns::{default_resolver, DnsResolver}, key::{PublicKey, SecretKey}, magicsock::{self, Handle, QuicMappedAddr}, - tls, NodeId, RelayMode, RelayUrl, + tls, NodeId, RelayUrl, }; mod rtt_actor; @@ -1356,6 +1357,34 @@ fn proxy_url_from_env() -> Option { None } +/// Configuration of the relay servers for an [`Endpoint`]. +/// +/// [`Endpoint`]: crate::endpoint::Endpoint +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum RelayMode { + /// Disable relay servers completely. + Disabled, + /// Use the default relay map, with production relay servers from n0. + /// + /// See [`crate::defaults::prod`] for the severs used. + Default, + /// Use the staging relay servers from n0. + Staging, + /// Use a custom relay map. + Custom(RelayMap), +} + +impl RelayMode { + /// Returns the relay map for this mode. + pub fn relay_map(&self) -> RelayMap { + match self { + RelayMode::Disabled => RelayMap::empty(), + RelayMode::Default => crate::defaults::prod::default_relay_map(), + RelayMode::Staging => crate::defaults::staging::default_relay_map(), + RelayMode::Custom(relay_map) => relay_map.clone(), + } + } +} /// Environment variable to force the use of staging relays. #[cfg_attr(iroh_docsrs, doc(cfg(not(test))))] diff --git a/iroh-net/src/lib.rs b/iroh-net/src/lib.rs index 00a922646d..258bddbc41 100644 --- a/iroh-net/src/lib.rs +++ b/iroh-net/src/lib.rs @@ -241,16 +241,15 @@ pub mod dns; pub mod endpoint; mod magicsock; pub mod metrics; -mod relay_map; pub mod ticket; pub mod tls; pub(crate) mod util; -pub use endpoint::{AddrInfo, Endpoint, NodeAddr}; +pub use endpoint::{AddrInfo, Endpoint, NodeAddr, RelayMode}; +pub use iroh_base::relay_map::{RelayMap, RelayNode, RelayUrl}; pub use iroh_base::{key, key::NodeId}; pub use iroh_relay as relay; -pub use relay_map::{RelayMap, RelayMode, RelayNode, RelayUrl}; #[cfg(any(test, feature = "test-utils"))] #[cfg_attr(iroh_docsrs, doc(cfg(any(test, feature = "test-utils"))))] diff --git a/iroh-net/src/metrics.rs b/iroh-net/src/metrics.rs index 655cfe4476..99603c968b 100644 --- a/iroh-net/src/metrics.rs +++ b/iroh-net/src/metrics.rs @@ -4,4 +4,5 @@ pub use iroh_relay::server::Metrics as RelayMetrics; pub use portmapper::Metrics as PortmapMetrics; -pub use crate::{magicsock::Metrics as MagicsockMetrics, netcheck::Metrics as NetcheckMetrics}; +pub use crate::magicsock::Metrics as MagicsockMetrics; +pub use netcheck::Metrics as NetcheckMetrics; diff --git a/iroh-netcheck/Cargo.toml b/iroh-netcheck/Cargo.toml index 52cb6b3882..11272d82e4 100644 --- a/iroh-netcheck/Cargo.toml +++ b/iroh-netcheck/Cargo.toml @@ -112,6 +112,8 @@ iroh-test = "0.28.0" serde_json = "1.0.107" testresult = "0.4.0" mainline = "2.0.1" +iroh-relay = { version = "0.28", path = "../iroh-relay", features = ["test-utils", "server"] } + [build-dependencies] duct = "0.13.6" diff --git a/iroh-netcheck/src/dns.rs b/iroh-netcheck/src/dns.rs index fe07433157..0953588b84 100644 --- a/iroh-netcheck/src/dns.rs +++ b/iroh-netcheck/src/dns.rs @@ -201,13 +201,69 @@ async fn stagger_call Fut, Fut: Future>>( #[cfg(test)] pub(crate) mod tests { + use std::net::Ipv6Addr; use std::sync::atomic::AtomicUsize; use std::time::Duration; + use once_cell::sync::Lazy; + use super::*; const TIMEOUT: Duration = Duration::from_secs(5); const STAGGERING_DELAYS: &[u64] = &[200, 300]; + static DNS_RESOLVER: Lazy = + Lazy::new(|| create_default_resolver().expect("unable to create DNS resolver")); + + /// Get the DNS resolver used within iroh-net. + pub fn resolver() -> &'static TokioAsyncResolver { + Lazy::force(&DNS_RESOLVER) + } + + /// Deprecated IPv6 site-local anycast addresses still configured by windows. + /// + /// Windows still configures these site-local addresses as soon even as an IPv6 loopback + /// interface is configured. We do not want to use these DNS servers, the chances of them + /// being usable are almost always close to zero, while the chance of DNS configuration + /// **only** relying on these servers and not also being configured normally are also almost + /// zero. The chance of the DNS resolver accidentally trying one of these and taking a + /// bunch of timeouts to figure out they're no good are on the other hand very high. + const WINDOWS_BAD_SITE_LOCAL_DNS_SERVERS: [IpAddr; 3] = [ + IpAddr::V6(Ipv6Addr::new(0xfec0, 0, 0, 0xffff, 0, 0, 0, 1)), + IpAddr::V6(Ipv6Addr::new(0xfec0, 0, 0, 0xffff, 0, 0, 0, 2)), + IpAddr::V6(Ipv6Addr::new(0xfec0, 0, 0, 0xffff, 0, 0, 0, 3)), + ]; + + /// Get resolver to query MX records. + /// + /// We first try to read the system's resolver from `/etc/resolv.conf`. + /// This does not work at least on some Androids, therefore we fallback + /// to the default `ResolverConfig` which uses eg. to google's `8.8.8.8` or `8.8.4.4`. + fn create_default_resolver() -> Result { + let (system_config, mut options) = + hickory_resolver::system_conf::read_system_conf().unwrap_or_default(); + + // Copy all of the system config, but strip the bad windows nameservers. Unfortunately + // there is no easy way to do this. + let mut config = hickory_resolver::config::ResolverConfig::new(); + if let Some(name) = system_config.domain() { + config.set_domain(name.clone()); + } + for name in system_config.search() { + config.add_search(name.clone()); + } + for nameserver_cfg in system_config.name_servers() { + if !WINDOWS_BAD_SITE_LOCAL_DNS_SERVERS.contains(&nameserver_cfg.socket_addr.ip()) { + config.add_name_server(nameserver_cfg.clone()); + } + } + + // see [`ResolverExt::lookup_ipv4_ipv6`] for info on why we avoid `LookupIpStrategy::Ipv4AndIpv6` + options.ip_strategy = hickory_resolver::config::LookupIpStrategy::Ipv4thenIpv6; + + let resolver = hickory_resolver::AsyncResolver::tokio(config, options); + Ok(resolver) + } + #[tokio::test] async fn stagger_basic() { let _logging = iroh_test::logging::setup(); diff --git a/iroh-netcheck/src/lib.rs b/iroh-netcheck/src/lib.rs index aa999f0870..2ca0f86db9 100644 --- a/iroh-netcheck/src/lib.rs +++ b/iroh-netcheck/src/lib.rs @@ -26,13 +26,12 @@ use tokio::{ use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle}; use tracing::{debug, error, info_span, trace, warn, Instrument}; -pub(crate) use relay_map::{RelayMap, RelayMode, RelayNode, RelayUrl}; +use iroh_base::relay_map::{RelayMap, RelayNode, RelayUrl}; pub mod defaults; mod dns; mod metrics; mod ping; -mod relay_map; mod reportgen; pub use metrics::Metrics; @@ -960,7 +959,7 @@ mod tests { let (stun_addr, stun_stats, _cleanup_guard) = stun_utils::serve("127.0.0.1".parse().unwrap()).await?; - let resolver = crate::dns::default_resolver(); + let resolver = crate::dns::tests::resolver(); let mut client = Client::new(None, resolver.clone())?; let dm = stun_utils::relay_map_of([stun_addr].into_iter()); @@ -1005,8 +1004,8 @@ mod tests { let dm = stun_utils::relay_map_of_opts([(stun_addr, false)].into_iter()); // Now create a client and generate a report. - let resolver = crate::dns::default_resolver().clone(); - let mut client = Client::new(None, resolver)?; + let resolver = crate::dns::tests::resolver(); + let mut client = Client::new(None, resolver.clone())?; let r = client.get_report(dm, None, None).await?; let mut r: Report = (*r).clone(); @@ -1206,10 +1205,10 @@ mod tests { want_relay: Some(relay_url(2)), // 2 got fast enough }, ]; + let resolver = crate::dns::tests::resolver(); for mut tt in tests { println!("test: {}", tt.name); - let resolver = crate::dns::default_resolver().clone(); - let mut actor = Actor::new(None, resolver).unwrap(); + let mut actor = Actor::new(None, resolver.clone()).unwrap(); for s in &mut tt.steps { // trigger the timer time::advance(Duration::from_secs(s.after)).await; @@ -1243,7 +1242,7 @@ mod tests { let dm = stun_utils::relay_map_of([stun_addr].into_iter()); dbg!(&dm); - let resolver = crate::dns::default_resolver().clone(); + let resolver = crate::dns::tests::resolver().clone(); let mut client = Client::new(None, resolver)?; // Set up an external socket to send STUN requests from, this will be discovered as diff --git a/iroh-netcheck/src/relay_map.rs b/iroh-netcheck/src/relay_map.rs deleted file mode 100644 index 9da1cab425..0000000000 --- a/iroh-netcheck/src/relay_map.rs +++ /dev/null @@ -1,154 +0,0 @@ -// this needs to live somewhere -use std::{collections::BTreeMap, fmt, sync::Arc}; - -use anyhow::{ensure, Result}; -pub use iroh_relay::RelayUrl; -use serde::{Deserialize, Serialize}; - -use crate::defaults::DEFAULT_STUN_PORT; - -/// Configuration of the relay servers for an [`Endpoint`]. -/// -/// [`Endpoint`]: crate::endpoint::Endpoint -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum RelayMode { - /// Disable relay servers completely. - Disabled, - /// Use the default relay map, with production relay servers from n0. - /// - /// See [`crate::defaults::prod`] for the severs used. - Default, - /// Use the staging relay servers from n0. - Staging, - /// Use a custom relay map. - Custom(RelayMap), -} - -impl RelayMode { - /// Returns the relay map for this mode. - pub fn relay_map(&self) -> RelayMap { - match self { - RelayMode::Disabled => RelayMap::empty(), - RelayMode::Default => crate::defaults::prod::default_relay_map(), - RelayMode::Staging => crate::defaults::staging::default_relay_map(), - RelayMode::Custom(relay_map) => relay_map.clone(), - } - } -} - -/// Configuration of all the relay servers that can be used. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct RelayMap { - /// A map of the different relay IDs to the [`RelayNode`] information - nodes: Arc>>, -} - -impl RelayMap { - /// Returns the sorted relay URLs. - pub fn urls(&self) -> impl Iterator { - self.nodes.keys() - } - - /// Create an empty relay map. - pub fn empty() -> Self { - Self { - nodes: Default::default(), - } - } - - /// Returns an `Iterator` over all known nodes. - pub fn nodes(&self) -> impl Iterator> { - self.nodes.values() - } - - /// Is this a known node? - pub fn contains_node(&self, url: &RelayUrl) -> bool { - self.nodes.contains_key(url) - } - - /// Get the given node. - pub fn get_node(&self, url: &RelayUrl) -> Option<&Arc> { - self.nodes.get(url) - } - - /// How many nodes are known? - pub fn len(&self) -> usize { - self.nodes.len() - } - - /// Are there any nodes in this map? - pub fn is_empty(&self) -> bool { - self.nodes.is_empty() - } - - /// Creates a new [`RelayMap`] with a single relay server configured. - /// - /// Allows to set a custom STUN port and different IP addresses for IPv4 and IPv6. - /// If IP addresses are provided, no DNS lookup will be performed. - pub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self { - let mut nodes = BTreeMap::new(); - nodes.insert( - url.clone(), - RelayNode { - url, - stun_only: false, - stun_port, - } - .into(), - ); - - RelayMap { - nodes: Arc::new(nodes), - } - } - - /// Returns a [`RelayMap`] from a [`RelayUrl`]. - /// - /// This will use the default STUN port and IP addresses resolved from the URL's host name via DNS. - /// relay nodes are specified at <../../docs/relay_nodes.md> - pub fn from_url(url: RelayUrl) -> Self { - Self::default_from_node(url, DEFAULT_STUN_PORT) - } - - /// Constructs the [`RelayMap`] from an iterator of [`RelayNode`]s. - pub fn from_nodes(value: impl IntoIterator) -> Result { - let mut map = BTreeMap::new(); - for node in value.into_iter() { - ensure!(!map.contains_key(&node.url), "Duplicate node url"); - map.insert(node.url.clone(), node.into()); - } - Ok(RelayMap { nodes: map.into() }) - } -} - -impl fmt::Display for RelayMap { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(&self, f) - } -} - -/// Information on a specific relay server. -/// -/// Includes the Url where it can be dialed. -// Please note that this is documented in the `iroh.computer` repository under -// `src/app/docs/reference/config/page.mdx`. Any changes to this need to be updated there. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Ord)] -pub struct RelayNode { - /// The [`RelayUrl`] where this relay server can be dialed. - pub url: RelayUrl, - /// Whether this relay server should only be used for STUN requests. - /// - /// This essentially allows you to use a normal STUN server as a relay node, no relay - /// functionality is used. - pub stun_only: bool, - /// The stun port of the relay server. - /// - /// Setting this to `0` means the default STUN port is used. - pub stun_port: u16, -} - -impl fmt::Display for RelayNode { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.url) - } -} diff --git a/iroh-netcheck/src/reportgen.rs b/iroh-netcheck/src/reportgen.rs index fa2f812f77..4f9a6ddc65 100644 --- a/iroh-netcheck/src/reportgen.rs +++ b/iroh-netcheck/src/reportgen.rs @@ -1445,7 +1445,7 @@ mod tests { async fn test_measure_https_latency() -> TestResult { let _logging_guard = iroh_test::logging::setup(); let (server, relay) = test_utils::relay().await; - let dns_resolver = crate::dns::resolver(); + let dns_resolver = crate::dns::tests::resolver(); tracing::info!(relay_url = ?relay.url , "RELAY_URL"); let (latency, ip) = measure_https_latency(dns_resolver, &relay, server.certificates()).await?; diff --git a/iroh-netcheck/src/reportgen/probes.rs b/iroh-netcheck/src/reportgen/probes.rs index 59b5e52274..0cf22b3c6c 100644 --- a/iroh-netcheck/src/reportgen/probes.rs +++ b/iroh-netcheck/src/reportgen/probes.rs @@ -473,7 +473,7 @@ mod tests { use pretty_assertions::assert_eq; use super::*; - use crate::netcheck::{test_utils, RelayLatencies}; + use crate::{test_utils, RelayLatencies}; /// Shorthand which declares a new ProbeSet. /// From 385b3c6e33c7056a850773ebbedf6b89df817766 Mon Sep 17 00:00:00 2001 From: Diva M Date: Fri, 15 Nov 2024 22:48:23 -0500 Subject: [PATCH 06/27] use netcheck as a crate --- Cargo.lock | 2 ++ iroh-cli/Cargo.toml | 1 + iroh-cli/src/commands/doctor.rs | 1 - iroh-net/Cargo.toml | 1 + iroh-net/src/magicsock.rs | 1 - iroh-net/src/magicsock/udp_conn.rs | 2 +- iroh-netcheck/src/defaults.rs | 5 +---- iroh-netcheck/src/dns.rs | 2 +- iroh-netcheck/src/lib.rs | 8 ++++---- 9 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3dd47f4984..aea42017ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2796,6 +2796,7 @@ dependencies = [ "iroh-docs", "iroh-gossip", "iroh-metrics", + "iroh-netcheck", "nix 0.27.1", "parking_lot", "pkarr", @@ -3028,6 +3029,7 @@ dependencies = [ "iroh-base", "iroh-metrics", "iroh-net", + "iroh-netcheck", "iroh-quinn", "iroh-quinn-proto", "iroh-quinn-udp", diff --git a/iroh-cli/Cargo.toml b/iroh-cli/Cargo.toml index b1d797440d..434bad536d 100644 --- a/iroh-cli/Cargo.toml +++ b/iroh-cli/Cargo.toml @@ -45,6 +45,7 @@ iroh-blobs = { version = "0.28.1", features = ["cli"] } iroh-docs = { version = "0.28.0", features = ["cli"] } iroh-gossip = { version = "0.28.1", features = ["cli"] } iroh-metrics = { version = "0.28.0" } +netcheck = { package = "iroh-netcheck", path = "../iroh-netcheck", version = "0.1" } parking_lot = "0.12.1" pkarr = { version = "2.2.0", default-features = false } portable-atomic = "1" diff --git a/iroh-cli/src/commands/doctor.rs b/iroh-cli/src/commands/doctor.rs index 77abd0a97f..bc1418ed7b 100644 --- a/iroh-cli/src/commands/doctor.rs +++ b/iroh-cli/src/commands/doctor.rs @@ -37,7 +37,6 @@ use iroh::{ endpoint::{self, Connection, ConnectionTypeStream, RecvStream, RemoteInfo, SendStream}, key::{PublicKey, SecretKey}, metrics::MagicsockMetrics, - netcheck, ticket::NodeTicket, Endpoint, NodeAddr, NodeId, RelayMap, RelayMode, RelayUrl, }, diff --git a/iroh-net/Cargo.toml b/iroh-net/Cargo.toml index c47409976d..075bb52f92 100644 --- a/iroh-net/Cargo.toml +++ b/iroh-net/Cargo.toml @@ -114,6 +114,7 @@ webpki = { package = "rustls-webpki", version = "0.102" } webpki-roots = "0.26" x509-parser = "0.16" z32 = "1.0.3" +netcheck = { package = "iroh-netcheck", path = "../iroh-netcheck", version = "0.1" } # metrics iroh-metrics = { version = "0.28.0", default-features = false } diff --git a/iroh-net/src/magicsock.rs b/iroh-net/src/magicsock.rs index c787b78357..02b5a4c640 100644 --- a/iroh-net/src/magicsock.rs +++ b/iroh-net/src/magicsock.rs @@ -60,7 +60,6 @@ use self::{ udp_conn::UdpConn, }; use crate::{ - self as netcheck, defaults::timeouts::NETCHECK_REPORT_TIMEOUT, disco::{self, CallMeMaybe, SendAddr}, discovery::{Discovery, DiscoveryItem}, diff --git a/iroh-net/src/magicsock/udp_conn.rs b/iroh-net/src/magicsock/udp_conn.rs index c176ae8144..a3370176e6 100644 --- a/iroh-net/src/magicsock/udp_conn.rs +++ b/iroh-net/src/magicsock/udp_conn.rs @@ -231,7 +231,7 @@ mod tests { #[tokio::test] async fn test_rebinding_conn_send_recv_ipv6() -> Result<()> { let _guard = iroh_test::logging::setup(); - if !crate::netcheck::os_has_ipv6() { + if !netcheck::os_has_ipv6() { return Ok(()); } rebinding_conn_send_recv(IpFamily::V6).await diff --git a/iroh-netcheck/src/defaults.rs b/iroh-netcheck/src/defaults.rs index 6765e52131..83d4fb6237 100644 --- a/iroh-netcheck/src/defaults.rs +++ b/iroh-netcheck/src/defaults.rs @@ -125,15 +125,12 @@ pub mod staging { } } -/// Contains all timeouts that we use in `iroh-net`. +/// Contains all timeouts that we use in `iroh-netcheck`. pub(crate) mod timeouts { use std::time::Duration; // Timeouts for netcheck - /// Maximum duration to wait for a netcheck report. - pub(crate) const NETCHECK_REPORT_TIMEOUT: Duration = Duration::from_secs(10); - /// The maximum amount of time netcheck will spend gathering a single report. pub(crate) const OVERALL_REPORT_TIMEOUT: Duration = Duration::from_secs(5); diff --git a/iroh-netcheck/src/dns.rs b/iroh-netcheck/src/dns.rs index 0953588b84..d0176bfe0c 100644 --- a/iroh-netcheck/src/dns.rs +++ b/iroh-netcheck/src/dns.rs @@ -214,7 +214,7 @@ pub(crate) mod tests { static DNS_RESOLVER: Lazy = Lazy::new(|| create_default_resolver().expect("unable to create DNS resolver")); - /// Get the DNS resolver used within iroh-net. + /// Get a DNS resolver suitable for testing. pub fn resolver() -> &'static TokioAsyncResolver { Lazy::force(&DNS_RESOLVER) } diff --git a/iroh-netcheck/src/lib.rs b/iroh-netcheck/src/lib.rs index 2ca0f86db9..19f9df331f 100644 --- a/iroh-netcheck/src/lib.rs +++ b/iroh-netcheck/src/lib.rs @@ -224,7 +224,7 @@ impl Client { /// /// Unlike the client itself the returned [`Addr`] does not own the actor task, it only /// allows sending messages to the actor. - pub(crate) fn addr(&self) -> Addr { + pub fn addr(&self) -> Addr { self.addr.clone() } @@ -334,7 +334,7 @@ pub(crate) enum Message { /// Unlike [`Client`] this is the raw channel to send messages over. Keeping this alive /// will not keep the actor alive, which makes this handy to pass to internal tasks. #[derive(Debug, Clone)] -pub(crate) struct Addr { +pub struct Addr { sender: mpsc::Sender, } @@ -768,7 +768,7 @@ async fn recv_stun_once(sock: &UdpSocket, buf: &mut [u8], actor_addr: &Addr) -> } /// Test if IPv6 works at all, or if it's been hard disabled at the OS level. -pub(crate) fn os_has_ipv6() -> bool { +pub fn os_has_ipv6() -> bool { UdpSocket::bind_local_v6(0).is_ok() } @@ -1257,7 +1257,7 @@ mod tests { info!(addr=?sock.local_addr().unwrap(), "Using local addr"); let task = { let sock = sock.clone(); - let addr = client.addr(); + let addr = client.addr.clone(); tokio::spawn( async move { let mut buf = BytesMut::zeroed(64 << 10); From 82f8079b909f05ea3dda872010cdb7ef4d24a490 Mon Sep 17 00:00:00 2001 From: Diva M Date: Fri, 15 Nov 2024 22:56:07 -0500 Subject: [PATCH 07/27] fix warns --- iroh-net/src/defaults.rs | 30 ------------------------------ iroh-netcheck/src/dns.rs | 3 --- 2 files changed, 33 deletions(-) diff --git a/iroh-net/src/defaults.rs b/iroh-net/src/defaults.rs index 1d822c12e0..111473d977 100644 --- a/iroh-net/src/defaults.rs +++ b/iroh-net/src/defaults.rs @@ -134,34 +134,4 @@ pub(crate) mod timeouts { /// Maximum duration to wait for a netcheck report. pub(crate) const NETCHECK_REPORT_TIMEOUT: Duration = Duration::from_secs(10); - - /// The maximum amount of time netcheck will spend gathering a single report. - pub(crate) const OVERALL_REPORT_TIMEOUT: Duration = Duration::from_secs(5); - - /// The total time we wait for all the probes. - /// - /// This includes the STUN, ICMP and HTTPS probes, which will all - /// start at different times based on the ProbePlan. - pub(crate) const PROBES_TIMEOUT: Duration = Duration::from_secs(3); - - /// How long to await for a captive-portal result. - /// - /// This delay is chosen so it starts after good-working STUN probes - /// would have finished, but not too long so the delay is bearable if - /// STUN is blocked. - pub(crate) const CAPTIVE_PORTAL_DELAY: Duration = Duration::from_millis(200); - - /// Timeout for captive portal checks - /// - /// Must be lower than [`OVERALL_REPORT_TIMEOUT`] minus - /// [`CAPTIVE_PORTAL_DELAY`]. - pub(crate) const CAPTIVE_PORTAL_TIMEOUT: Duration = Duration::from_secs(2); - - pub(crate) const DNS_TIMEOUT: Duration = Duration::from_secs(3); - - /// The amount of time we wait for a hairpinned packet to come back. - pub(crate) const HAIRPIN_CHECK_TIMEOUT: Duration = Duration::from_millis(100); - - /// Default Pinger timeout - pub(crate) const DEFAULT_PINGER_TIMEOUT: Duration = Duration::from_secs(5); } diff --git a/iroh-netcheck/src/dns.rs b/iroh-netcheck/src/dns.rs index d0176bfe0c..0fc8ba1ec9 100644 --- a/iroh-netcheck/src/dns.rs +++ b/iroh-netcheck/src/dns.rs @@ -203,13 +203,10 @@ async fn stagger_call Fut, Fut: Future>>( pub(crate) mod tests { use std::net::Ipv6Addr; use std::sync::atomic::AtomicUsize; - use std::time::Duration; use once_cell::sync::Lazy; use super::*; - const TIMEOUT: Duration = Duration::from_secs(5); - const STAGGERING_DELAYS: &[u64] = &[200, 300]; static DNS_RESOLVER: Lazy = Lazy::new(|| create_default_resolver().expect("unable to create DNS resolver")); From 9baf0f5c090eca3fcf662fb12a373d72bdb6b2d6 Mon Sep 17 00:00:00 2001 From: Diva M Date: Fri, 15 Nov 2024 22:58:13 -0500 Subject: [PATCH 08/27] fmt --- iroh-base/src/node_addr.rs | 1 - iroh-base/src/relay_map.rs | 3 ++- iroh-net/src/lib.rs | 7 +++++-- iroh-net/src/metrics.rs | 2 +- iroh-netcheck/src/dns.rs | 6 ++---- iroh-netcheck/src/lib.rs | 3 +-- iroh-netcheck/src/reportgen.rs | 2 +- iroh-netcheck/src/reportgen/hairpin.rs | 3 +-- 8 files changed, 13 insertions(+), 14 deletions(-) diff --git a/iroh-base/src/node_addr.rs b/iroh-base/src/node_addr.rs index e7f959148c..c084f15f55 100644 --- a/iroh-base/src/node_addr.rs +++ b/iroh-base/src/node_addr.rs @@ -11,7 +11,6 @@ use std::{collections::BTreeSet, net::SocketAddr}; use serde::{Deserialize, Serialize}; use crate::key::{NodeId, PublicKey}; - pub use crate::relay_url::RelayUrl; /// Network-level addressing information for an iroh-net node. diff --git a/iroh-base/src/relay_map.rs b/iroh-base/src/relay_map.rs index 4a01d17c2e..fd698accb4 100644 --- a/iroh-base/src/relay_map.rs +++ b/iroh-base/src/relay_map.rs @@ -2,10 +2,11 @@ use std::{collections::BTreeMap, fmt, sync::Arc}; -pub use crate::relay_url::RelayUrl; use anyhow::{ensure, Result}; use serde::{Deserialize, Serialize}; +pub use crate::relay_url::RelayUrl; + /// The default STUN port used by the Relay server. /// /// The STUN port as defined by [RFC 8489]() diff --git a/iroh-net/src/lib.rs b/iroh-net/src/lib.rs index 258bddbc41..478fb69e53 100644 --- a/iroh-net/src/lib.rs +++ b/iroh-net/src/lib.rs @@ -247,8 +247,11 @@ pub mod tls; pub(crate) mod util; pub use endpoint::{AddrInfo, Endpoint, NodeAddr, RelayMode}; -pub use iroh_base::relay_map::{RelayMap, RelayNode, RelayUrl}; -pub use iroh_base::{key, key::NodeId}; +pub use iroh_base::{ + key, + key::NodeId, + relay_map::{RelayMap, RelayNode, RelayUrl}, +}; pub use iroh_relay as relay; #[cfg(any(test, feature = "test-utils"))] diff --git a/iroh-net/src/metrics.rs b/iroh-net/src/metrics.rs index 99603c968b..91c2a5c8dd 100644 --- a/iroh-net/src/metrics.rs +++ b/iroh-net/src/metrics.rs @@ -2,7 +2,7 @@ #[cfg(feature = "test-utils")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "test-utils")))] pub use iroh_relay::server::Metrics as RelayMetrics; +pub use netcheck::Metrics as NetcheckMetrics; pub use portmapper::Metrics as PortmapMetrics; pub use crate::magicsock::Metrics as MagicsockMetrics; -pub use netcheck::Metrics as NetcheckMetrics; diff --git a/iroh-netcheck/src/dns.rs b/iroh-netcheck/src/dns.rs index 0fc8ba1ec9..74a0341643 100644 --- a/iroh-netcheck/src/dns.rs +++ b/iroh-netcheck/src/dns.rs @@ -1,5 +1,4 @@ -use std::fmt::Write; -use std::net::IpAddr; +use std::{fmt::Write, net::IpAddr}; use anyhow::Result; use futures_lite::{Future, StreamExt}; @@ -201,8 +200,7 @@ async fn stagger_call Fut, Fut: Future>>( #[cfg(test)] pub(crate) mod tests { - use std::net::Ipv6Addr; - use std::sync::atomic::AtomicUsize; + use std::{net::Ipv6Addr, sync::atomic::AtomicUsize}; use once_cell::sync::Lazy; diff --git a/iroh-netcheck/src/lib.rs b/iroh-netcheck/src/lib.rs index 19f9df331f..b706999c70 100644 --- a/iroh-netcheck/src/lib.rs +++ b/iroh-netcheck/src/lib.rs @@ -16,6 +16,7 @@ use std::{ use anyhow::{anyhow, Context as _, Result}; use bytes::Bytes; use hickory_resolver::TokioAsyncResolver as DnsResolver; +use iroh_base::relay_map::{RelayMap, RelayNode, RelayUrl}; use iroh_metrics::inc; use iroh_relay::protos::stun; use netwatch::{IpFamily, UdpSocket}; @@ -26,8 +27,6 @@ use tokio::{ use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle}; use tracing::{debug, error, info_span, trace, warn, Instrument}; -use iroh_base::relay_map::{RelayMap, RelayNode, RelayUrl}; - pub mod defaults; mod dns; mod metrics; diff --git a/iroh-netcheck/src/reportgen.rs b/iroh-netcheck/src/reportgen.rs index 4f9a6ddc65..08280a41ba 100644 --- a/iroh-netcheck/src/reportgen.rs +++ b/iroh-netcheck/src/reportgen.rs @@ -26,6 +26,7 @@ use std::{ }; use anyhow::{anyhow, bail, Context as _, Result}; +use hickory_resolver::TokioAsyncResolver as DnsResolver; use iroh_metrics::inc; use iroh_relay::{http::RELAY_PROBE_PATH, protos::stun}; use netwatch::{interfaces, UdpSocket}; @@ -47,7 +48,6 @@ use crate::{ ping::{PingError, Pinger}, RelayMap, RelayNode, RelayUrl, Report, }; -use hickory_resolver::TokioAsyncResolver as DnsResolver; mod hairpin; mod probes; diff --git a/iroh-netcheck/src/reportgen/hairpin.rs b/iroh-netcheck/src/reportgen/hairpin.rs index 47a2830916..ad1e51f45d 100644 --- a/iroh-netcheck/src/reportgen/hairpin.rs +++ b/iroh-netcheck/src/reportgen/hairpin.rs @@ -21,8 +21,7 @@ use tokio::{sync::oneshot, time::Instant}; use tokio_util::task::AbortOnDropHandle; use tracing::{debug, error, info_span, trace, warn, Instrument}; -use crate::defaults::timeouts::HAIRPIN_CHECK_TIMEOUT; -use crate::{self as netcheck, reportgen, Inflight}; +use crate::{self as netcheck, defaults::timeouts::HAIRPIN_CHECK_TIMEOUT, reportgen, Inflight}; /// Handle to the hairpin actor. /// From c6ed4d935a40be8ea1bdbf71d7dc2b73c468fd14 Mon Sep 17 00:00:00 2001 From: Diva M Date: Sat, 16 Nov 2024 11:59:28 -0500 Subject: [PATCH 09/27] reduce deps, supposedly --- Cargo.lock | 62 ------------------ iroh-netcheck/Cargo.toml | 112 +++++---------------------------- iroh-netcheck/src/lib.rs | 18 ++++-- iroh-netcheck/src/reportgen.rs | 10 ++- 4 files changed, 34 insertions(+), 168 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aea42017ed..34465f0e39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3113,91 +3113,29 @@ name = "iroh-netcheck" version = "0.1.0" dependencies = [ "anyhow", - "axum", - "backoff", - "base64 0.22.1", "bytes", - "cc", - "clap", - "criterion", - "crypto_box", - "der", "derive_more", - "duct", "futures-buffered", - "futures-concurrency", "futures-lite 2.5.0", - "futures-sink", - "futures-util", - "genawaiter", - "governor", - "hex", - "hickory-proto 0.25.0-alpha.2", "hickory-resolver", - "hostname", - "http 1.1.0", - "http-body-util", - "hyper", - "hyper-util", - "igd-next", "iroh-base", "iroh-metrics", - "iroh-quinn", - "iroh-quinn-proto", - "iroh-quinn-udp", "iroh-relay", "iroh-test", - "libc", - "mainline", - "netdev", - "netlink-packet-core", - "netlink-packet-route", - "netlink-sys", "netwatch", - "num_enum", "once_cell", - "parking_lot", - "pin-project", - "pkarr", "portmapper", - "postcard", "pretty_assertions", "rand", - "rand_chacha", - "rcgen 0.12.1", - "regex", "reqwest", - "ring", - "rtnetlink", "rustls", - "rustls-webpki", - "serde", - "serde_json", - "smallvec", - "socket2", - "strum 0.26.3", - "stun-rs", "surge-ping", - "swarm-discovery", "testresult", "thiserror 1.0.69", - "time", "tokio", - "tokio-rustls", - "tokio-stream", - "tokio-tungstenite", - "tokio-tungstenite-wasm", "tokio-util", "tracing", - "tracing-subscriber", - "tungstenite", "url", - "watchable", - "webpki-roots", - "windows 0.51.1", - "wmi", - "x509-parser", - "z32", ] [[package]] diff --git a/iroh-netcheck/Cargo.toml b/iroh-netcheck/Cargo.toml index 11272d82e4..68c6356259 100644 --- a/iroh-netcheck/Cargo.toml +++ b/iroh-netcheck/Cargo.toml @@ -10,120 +10,38 @@ rust-version = "1.76" workspace = true [dependencies] -cc = "=1.1.31" # enforce cc version, because of https://github.com/rust-lang/cc-rs/issues/1278 - -anyhow = { version = "1" } -axum = { version = "0.7.4", optional = true } -backoff = "0.4.0" -base64 = "0.22.1" +anyhow = "1" bytes = "1.7" -clap = { version = "4", features = ["derive"], optional = true } -der = { version = "0.7", features = ["alloc", "derive"] } -derive_more = { version = "1.0.0", features = ["debug", "display", "from", "try_into", "deref"] } +derive_more = { version = "1.0.0", features = ["display"] } futures-buffered = "0.2.8" -futures-concurrency = "7.6.0" futures-lite = "2.3" -futures-sink = "0.3.25" -futures-util = "0.3.25" -governor = "0.6.0" -hex = "0.4.3" -hickory-proto = "=0.25.0-alpha.2" hickory-resolver = "=0.25.0-alpha.2" -hostname = "0.3.1" -http = "1" -http-body-util = "0.1.0" -hyper = { version = "1", features = ["server", "client", "http1"] } -hyper-util = "0.1.1" -igd-next = { version = "0.15.1", features = ["aio_tokio"] } -iroh-base = { version = "0.28.0", features = ["key"] } +iroh-base = { version = "0.28.0", default-features = false, features = ["relay"] } +iroh-metrics = { version = "0.28.0", default-features = false, optional = true } iroh-relay = { version = "0.28", path = "../iroh-relay" } -libc = "0.2.139" -netdev = "0.30.0" netwatch = { version = "0.1.0", path = "../net-tools/netwatch" } -num_enum = "0.7" -once_cell = "1.18.0" -parking_lot = "0.12.1" -pin-project = "1" -pkarr = { version = "2", default-features = false, features = ["async", "relay"] } portmapper = { version = "0.1.0", path = "../net-tools/portmapper" } -postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] } -quinn = { package = "iroh-quinn", version = "0.12.0" } -quinn-proto = { package = "iroh-quinn-proto", version = "0.12.0" } -quinn-udp = { package = "iroh-quinn-udp", version = "0.5.5" } rand = "0.8" -rcgen = "0.12" -regex = { version = "1.7.1", optional = true } -reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] } -ring = "0.17" -rustls = { version = "0.23", default-features = false, features = ["ring"] } -serde = { version = "1", features = ["derive", "rc"] } -smallvec = "1.11.1" -socket2 = "0.5.3" -stun-rs = "0.1.5" +reqwest = { version = "0.12", default-features = false } +rustls = { version = "0.23", default-features = false } surge-ping = "0.8.0" thiserror = "1" -time = "0.3.20" -tokio = { version = "1", features = ["io-util", "macros", "sync", "rt", "net", "fs", "io-std", "signal", "process"] } -tokio-rustls = { version = "0.26", default-features = false, features = ["logging", "ring"] } -tokio-stream = { version = "0.1.15" } -tokio-tungstenite = "0.21" -tokio-tungstenite-wasm = "0.3" -tokio-util = { version = "0.7.12", features = ["io-util", "io", "codec", "rt"] } +tokio = { version = "1", default-features = false } +tokio-util = { version = "0.7.12", default-features = false } tracing = "0.1" -tracing-subscriber = { version = "0.3", features = ["env-filter"], optional = true } -tungstenite = "0.21" -url = { version = "2.4", features = ["serde"] } -watchable = "1.1.2" -webpki = { package = "rustls-webpki", version = "0.102" } -webpki-roots = "0.26" -x509-parser = "0.16" -z32 = "1.0.3" - -# metrics -iroh-metrics = { version = "0.28.0", default-features = false } -strum = { version = "0.26.2", features = ["derive"] } - -# local-swarm-discovery -swarm-discovery = { version = "0.2.1", optional = true } - -# dht_discovery -genawaiter = { version = "0.99.1", features = ["futures03"], optional = true } - -[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] -netlink-packet-core = "0.7.0" -netlink-packet-route = "0.17.0" -netlink-sys = "0.8.5" -rtnetlink = "0.13.0" - -[target.'cfg(target_os = "windows")'.dependencies] -wmi = "0.13" -windows = { version = "0.51", features = ["Win32_NetworkManagement_IpHelper", "Win32_Foundation", "Win32_NetworkManagement_Ndis", "Win32_Networking_WinSock"] } +url = { version = "2.4" } [dev-dependencies] -axum = { version = "0.7.4" } -clap = { version = "4", features = ["derive"] } -criterion = "0.5.1" -crypto_box = { version = "0.9.1", features = ["serde", "chacha20"] } -pretty_assertions = "1.4" -rand_chacha = "0.3.1" -tokio = { version = "1", features = ["io-util", "sync", "rt", "net", "fs", "macros", "time", "test-util"] } -tracing-subscriber = { version = "0.3", features = ["env-filter"] } +iroh-relay = { version = "0.28", path = "../iroh-relay", features = ["test-utils", "server"] } iroh-test = "0.28.0" -serde_json = "1.0.107" +once_cell = "1.18.0" +pretty_assertions = "1.4" testresult = "0.4.0" -mainline = "2.0.1" -iroh-relay = { version = "0.28", path = "../iroh-relay", features = ["test-utils", "server"] } - - -[build-dependencies] -duct = "0.13.6" +tokio = { version = "1", default-features = false, features = ["test-util"] } [features] -default = ["metrics", "discovery-pkarr-dht"] -metrics = ["iroh-metrics/metrics"] -test-utils = ["iroh-relay/test-utils", "iroh-relay/server", "dep:axum"] -discovery-local-network = ["dep:swarm-discovery"] -discovery-pkarr-dht = ["pkarr/dht", "dep:genawaiter"] +default = ["metrics"] +metrics = ["dep:iroh-metrics"] [package.metadata.docs.rs] all-features = true diff --git a/iroh-netcheck/src/lib.rs b/iroh-netcheck/src/lib.rs index b706999c70..791b3e256a 100644 --- a/iroh-netcheck/src/lib.rs +++ b/iroh-netcheck/src/lib.rs @@ -17,6 +17,7 @@ use anyhow::{anyhow, Context as _, Result}; use bytes::Bytes; use hickory_resolver::TokioAsyncResolver as DnsResolver; use iroh_base::relay_map::{RelayMap, RelayNode, RelayUrl}; +#[cfg(feature = "metrics")] use iroh_metrics::inc; use iroh_relay::protos::stun; use netwatch::{IpFamily, UdpSocket}; @@ -29,12 +30,13 @@ use tracing::{debug, error, info_span, trace, warn, Instrument}; pub mod defaults; mod dns; +#[cfg(feature = "metrics")] mod metrics; mod ping; mod reportgen; +#[cfg(feature = "metrics")] pub use metrics::Metrics; -use Metrics as NetcheckMetrics; const FULL_REPORT_INTERVAL: Duration = Duration::from_secs(5 * 60); @@ -356,7 +358,8 @@ impl Addr { payload, from_addr: src, }) { - inc!(NetcheckMetrics, stun_packets_dropped); + #[cfg(feature = "metrics")] + inc!(Metrics, stun_packets_dropped); warn!("dropping stun packet from {}", src); } } @@ -512,9 +515,11 @@ impl Actor { self.reports.last = None; // causes ProbePlan::new below to do a full (initial) plan self.reports.next_full = false; self.reports.last_full = now; - inc!(NetcheckMetrics, reports_full); + #[cfg(feature = "metrics")] + inc!(Metrics, reports_full); } - inc!(NetcheckMetrics, reports); + #[cfg(feature = "metrics")] + inc!(Metrics, reports); let actor = reportgen::Client::new( self.addr(), @@ -558,12 +563,13 @@ impl Actor { return; } + #[cfg(feature = "metrics")] match &src { SocketAddr::V4(_) => { - inc!(NetcheckMetrics, stun_packets_recv_ipv4); + inc!(Metrics, stun_packets_recv_ipv4); } SocketAddr::V6(_) => { - inc!(NetcheckMetrics, stun_packets_recv_ipv6); + inc!(Metrics, stun_packets_recv_ipv6); } } diff --git a/iroh-netcheck/src/reportgen.rs b/iroh-netcheck/src/reportgen.rs index 08280a41ba..e77b6f7880 100644 --- a/iroh-netcheck/src/reportgen.rs +++ b/iroh-netcheck/src/reportgen.rs @@ -27,6 +27,7 @@ use std::{ use anyhow::{anyhow, bail, Context as _, Result}; use hickory_resolver::TokioAsyncResolver as DnsResolver; +#[cfg(feature = "metrics")] use iroh_metrics::inc; use iroh_relay::{http::RELAY_PROBE_PATH, protos::stun}; use netwatch::{interfaces, UdpSocket}; @@ -40,7 +41,8 @@ use tokio_util::task::AbortOnDropHandle; use tracing::{debug, debug_span, error, info_span, trace, warn, Instrument, Span}; use url::Host; -use super::NetcheckMetrics; +#[cfg(feature = "metrics")] +use crate::Metrics; use crate::{ self as netcheck, defaults::DEFAULT_STUN_PORT, @@ -807,10 +809,12 @@ async fn run_stun_probe( if matches!(probe, Probe::StunIpv4 { .. }) { result.ipv4_can_send = true; - inc!(NetcheckMetrics, stun_packets_sent_ipv4); + #[cfg(feature = "metrics")] + inc!(Metrics, stun_packets_sent_ipv4); } else { result.ipv6_can_send = true; - inc!(NetcheckMetrics, stun_packets_sent_ipv6); + #[cfg(feature = "metrics")] + inc!(Metrics, stun_packets_sent_ipv6); } let (delay, addr) = stun_rx .await From 4efedc81c56797027358e70df5b6fa76dffe43a3 Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 19 Nov 2024 11:06:11 -0500 Subject: [PATCH 10/27] fix iroh-base relay feature deps --- iroh-base/Cargo.toml | 2 +- iroh-base/src/lib.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iroh-base/Cargo.toml b/iroh-base/Cargo.toml index c56a88e114..f2b7fc1d0e 100644 --- a/iroh-base/Cargo.toml +++ b/iroh-base/Cargo.toml @@ -53,7 +53,7 @@ base32 = ["dep:data-encoding", "dep:postcard"] redb = ["dep:redb"] key = ["dep:ed25519-dalek", "dep:once_cell", "dep:rand", "dep:rand_core", "dep:ssh-key", "dep:ttl_cache", "dep:aead", "dep:crypto_box", "dep:zeroize", "dep:url", "dep:derive_more", "dep:getrandom"] wasm = ["getrandom?/js"] -relay = [] +relay = ["dep:url", "dep:derive_more"] [package.metadata.docs.rs] all-features = true diff --git a/iroh-base/src/lib.rs b/iroh-base/src/lib.rs index 1c0b2ce748..5445bf898f 100644 --- a/iroh-base/src/lib.rs +++ b/iroh-base/src/lib.rs @@ -16,6 +16,7 @@ pub mod node_addr; #[cfg(feature = "relay")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "relay")))] pub mod relay_map; +#[cfg(any(feature = "relay", feature = "key"))] mod relay_url; #[cfg(feature = "base32")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "base32")))] From 9f6fbb9ee4fe7596894985825ee63f44797b049b Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 19 Nov 2024 12:05:00 -0500 Subject: [PATCH 11/27] reduce lockfile diff --- Cargo.lock | 269 +++++++++++++++++++++++------------------------------ 1 file changed, 117 insertions(+), 152 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 34465f0e39..b9214a4dfb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,9 +65,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.20" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "android-tzdata" @@ -175,7 +175,7 @@ dependencies = [ "nom", "num-traits", "rusticata-macros", - "thiserror 1.0.69", + "thiserror 1.0.68", "time", ] @@ -270,9 +270,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "axum" -version = "0.7.9" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" +checksum = "504e3947307ac8326a5437504c517c4b56716c9d98fac0028c2acc7ca47d70ae" dependencies = [ "async-trait", "axum-core", @@ -392,7 +392,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1f7a89a8ee5889d2593ae422ce6e1bb03e48a0e8a16e4fa0882dfcbe7e182ef" dependencies = [ "bytes", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "genawaiter", "iroh-blake3", "iroh-io", @@ -658,9 +658,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.21" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", "clap_derive", @@ -668,9 +668,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.21" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" dependencies = [ "anstream", "anstyle", @@ -692,9 +692,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.3" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "clipboard-win" @@ -741,14 +741,14 @@ dependencies = [ [[package]] name = "comfy-table" -version = "7.1.3" +version = "7.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24f165e7b643266ea80cb858aed492ad9280e3e05ce24d4a99d7d7b889b6a4d9" +checksum = "b34115915337defe99b2aff5c2ce6771e5fbc4079f4b506301f5cf394c8452f7" dependencies = [ - "crossterm 0.28.1", + "crossterm", "strum 0.26.3", "strum_macros 0.26.4", - "unicode-width 0.2.0", + "unicode-width", ] [[package]] @@ -782,7 +782,7 @@ dependencies = [ "encode_unicode", "lazy_static", "libc", - "unicode-width 0.1.14", + "unicode-width", "windows-sys 0.52.0", ] @@ -826,9 +826,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.15" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca741a962e1b0bff6d724a1a0958b686406e853bb14061f218562e1896f95e6" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -940,19 +940,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "crossterm" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" -dependencies = [ - "bitflags 2.6.0", - "crossterm_winapi", - "parking_lot", - "rustix", - "winapi", -] - [[package]] name = "crossterm_winapi" version = "0.9.1" @@ -1180,7 +1167,7 @@ dependencies = [ "console", "shell-words", "tempfile", - "thiserror 1.0.69", + "thiserror 1.0.68", "zeroize", ] @@ -1541,9 +1528,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.2.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "fd-lock" @@ -1618,7 +1605,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8835f84f38484cc86f110a805655697908257fb9a7af005234060891557198e9" dependencies = [ "nonempty", - "thiserror 1.0.69", + "thiserror 1.0.68", ] [[package]] @@ -1713,11 +1700,11 @@ dependencies = [ [[package]] name = "futures-lite" -version = "2.5.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cef40d21ae2c515b51041df9ed313ed21e572df340ea58a922a0aefe7e8891a1" +checksum = "3f1fa2f9765705486b33fd2acf1577f8ec449c2ba1f318ae5447697b7c08d210" dependencies = [ - "fastrand 2.2.0", + "fastrand 2.1.1", "futures-core", "futures-io", "parking", @@ -2026,7 +2013,7 @@ dependencies = [ "ipnet", "once_cell", "rand", - "thiserror 1.0.69", + "thiserror 1.0.68", "tinyvec", "tokio", "tracing", @@ -2056,7 +2043,7 @@ dependencies = [ "rustls", "rustls-pemfile", "serde", - "thiserror 1.0.69", + "thiserror 1.0.68", "time", "tinyvec", "tokio", @@ -2082,7 +2069,7 @@ dependencies = [ "lru-cache", "parking_lot", "serde", - "thiserror 1.0.69", + "thiserror 1.0.68", "tokio", "tracing", ] @@ -2105,7 +2092,7 @@ dependencies = [ "rustls", "serde", "smallvec", - "thiserror 1.0.69", + "thiserror 1.0.68", "tokio", "tokio-rustls", "tracing", @@ -2129,7 +2116,7 @@ dependencies = [ "prefix-trie", "rustls", "serde", - "thiserror 1.0.69", + "thiserror 1.0.68", "time", "tokio", "tokio-rustls", @@ -2555,16 +2542,16 @@ dependencies = [ [[package]] name = "indicatif" -version = "0.17.9" +version = "0.17.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf675b85ed934d3c67b5c5469701eec7db22689d0a2139d856e0925fa28b281" +checksum = "763a5a8f45087d6bcea4222e7b72c291a054edf80e4ef6efd2a4979878c7bea3" dependencies = [ "console", + "instant", "number_prefix", "portable-atomic", "tokio", - "unicode-width 0.2.0", - "web-time", + "unicode-width", ] [[package]] @@ -2628,7 +2615,7 @@ dependencies = [ "console", "derive_more", "futures-buffered", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "futures-util", "genawaiter", "indicatif", @@ -2661,7 +2648,7 @@ dependencies = [ "tempfile", "testdir", "testresult", - "thiserror 1.0.69", + "thiserror 1.0.68", "tokio", "tokio-stream", "tokio-util", @@ -2695,7 +2682,7 @@ dependencies = [ "serde_json", "serde_test", "ssh-key", - "thiserror 1.0.69", + "thiserror 1.0.68", "ttl_cache", "url", "zeroize", @@ -2728,7 +2715,7 @@ dependencies = [ "console", "derive_more", "futures-buffered", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "futures-util", "genawaiter", "hashlink", @@ -2780,13 +2767,13 @@ dependencies = [ "colored", "comfy-table", "console", - "crossterm 0.27.0", + "crossterm", "derive_more", "dialoguer", "dirs-next", "duct", "futures-buffered", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "futures-util", "hex", "human-time", @@ -2817,7 +2804,7 @@ dependencies = [ "strum 0.26.3", "tempfile", "testdir", - "thiserror 1.0.69", + "thiserror 1.0.68", "time", "tokio", "tokio-util", @@ -2842,7 +2829,7 @@ dependencies = [ "clap", "derive_more", "dirs-next", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "governor", "hickory-proto 0.25.0-alpha.2", "hickory-resolver", @@ -2893,7 +2880,7 @@ dependencies = [ "dialoguer", "ed25519-dalek", "futures-buffered", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "futures-util", "hex", "indicatif", @@ -2939,7 +2926,7 @@ dependencies = [ "derive_more", "ed25519-dalek", "futures-concurrency", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "futures-util", "hex", "indexmap 2.6.0", @@ -2969,7 +2956,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17e302c5ad649c6a7aa9ae8468e1c4dc2469321af0c6de7341c1be1bdaab434b" dependencies = [ "bytes", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "pin-project", "smallvec", "tokio", @@ -3012,7 +2999,7 @@ dependencies = [ "duct", "futures-buffered", "futures-concurrency", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "futures-sink", "futures-util", "genawaiter", @@ -3068,7 +3055,7 @@ dependencies = [ "surge-ping", "swarm-discovery", "testresult", - "thiserror 1.0.69", + "thiserror 1.0.68", "time", "tokio", "tokio-rustls", @@ -3095,7 +3082,7 @@ dependencies = [ "anyhow", "bytes", "clap", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "hdrhistogram", "iroh-metrics", "iroh-net", @@ -3116,7 +3103,7 @@ dependencies = [ "bytes", "derive_more", "futures-buffered", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "hickory-resolver", "iroh-base", "iroh-metrics", @@ -3131,7 +3118,7 @@ dependencies = [ "rustls", "surge-ping", "testresult", - "thiserror 1.0.69", + "thiserror 1.0.68", "tokio", "tokio-util", "tracing", @@ -3151,7 +3138,7 @@ dependencies = [ "rustc-hash", "rustls", "socket2", - "thiserror 1.0.69", + "thiserror 1.0.68", "tokio", "tracing", ] @@ -3169,7 +3156,7 @@ dependencies = [ "rustls", "rustls-platform-verifier", "slab", - "thiserror 1.0.69", + "thiserror 1.0.68", "tinyvec", "tracing", ] @@ -3199,7 +3186,7 @@ dependencies = [ "derive_more", "duct", "futures-buffered", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "futures-sink", "futures-util", "governor", @@ -3235,7 +3222,7 @@ dependencies = [ "smallvec", "socket2", "stun-rs", - "thiserror 1.0.69", + "thiserror 1.0.68", "time", "tokio", "tokio-rustls", @@ -3258,7 +3245,7 @@ dependencies = [ "anyhow", "clap", "futures-buffered", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "futures-util", "iroh-net", "tokio", @@ -3337,7 +3324,7 @@ dependencies = [ "combine", "jni-sys", "log", - "thiserror 1.0.69", + "thiserror 1.0.68", "walkdir", ] @@ -3367,9 +3354,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.164" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libm" @@ -3474,7 +3461,7 @@ dependencies = [ "serde_bencode", "serde_bytes", "sha1_smol", - "thiserror 1.0.69", + "thiserror 1.0.68", "tracing", ] @@ -3634,7 +3621,7 @@ dependencies = [ "anyhow", "byteorder", "paste", - "thiserror 1.0.69", + "thiserror 1.0.68", ] [[package]] @@ -3648,7 +3635,7 @@ dependencies = [ "log", "netlink-packet-core", "netlink-sys", - "thiserror 1.0.69", + "thiserror 1.0.68", "tokio", ] @@ -3672,7 +3659,7 @@ dependencies = [ "anyhow", "bytes", "derive_more", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "futures-sink", "futures-util", "libc", @@ -3684,7 +3671,7 @@ dependencies = [ "rtnetlink", "serde", "socket2", - "thiserror 1.0.69", + "thiserror 1.0.68", "time", "tokio", "tokio-util", @@ -4094,7 +4081,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879952a81a83930934cbf1786752d6dedc3b1f29e8f8fb2ad1d0a36f377cf442" dependencies = [ "memchr", - "thiserror 1.0.69", + "thiserror 1.0.68", "ucd-trie", ] @@ -4182,7 +4169,7 @@ dependencies = [ "rand", "self_cell", "simple-dns", - "thiserror 1.0.69", + "thiserror 1.0.68", "tracing", "ureq", "wasm-bindgen", @@ -4307,7 +4294,7 @@ dependencies = [ "base64 0.22.1", "bytes", "derive_more", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "futures-util", "igd-next", "iroh-metrics", @@ -4320,7 +4307,7 @@ dependencies = [ "serde", "smallvec", "socket2", - "thiserror 1.0.69", + "thiserror 1.0.68", "time", "tokio", "tokio-util", @@ -4560,7 +4547,7 @@ dependencies = [ "derive_more", "educe", "flume", - "futures-lite 2.5.0", + "futures-lite 2.4.0", "futures-sink", "futures-util", "hex", @@ -4594,9 +4581,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quinn" -version = "0.11.6" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62e96808277ec6f97351a2380e6c25114bc9e67037775464979f3037c92d05ef" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" dependencies = [ "bytes", "pin-project-lite", @@ -4605,29 +4592,26 @@ dependencies = [ "rustc-hash", "rustls", "socket2", - "thiserror 2.0.3", + "thiserror 1.0.68", "tokio", "tracing", ] [[package]] name = "quinn-proto" -version = "0.11.9" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2fe5ef3495d7d2e377ff17b1a8ce2ee2ec2a18cde8b6ad6619d65d0701c135d" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" dependencies = [ "bytes", - "getrandom", "rand", "ring", "rustc-hash", "rustls", - "rustls-pki-types", "slab", - "thiserror 2.0.3", + "thiserror 1.0.68", "tinyvec", "tracing", - "web-time", ] [[package]] @@ -4733,7 +4717,7 @@ dependencies = [ "bitflags 2.6.0", "cassowary", "compact_str", - "crossterm 0.27.0", + "crossterm", "itertools 0.12.1", "lru", "paste", @@ -4741,7 +4725,7 @@ dependencies = [ "strum 0.26.3", "unicode-segmentation", "unicode-truncate", - "unicode-width 0.1.14", + "unicode-width", ] [[package]] @@ -4833,7 +4817,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", - "thiserror 1.0.69", + "thiserror 1.0.68", ] [[package]] @@ -4858,9 +4842,9 @@ dependencies = [ [[package]] name = "reflink-copy" -version = "0.1.20" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17400ed684c3a0615932f00c271ae3eea13e47056a1455821995122348ab6438" +checksum = "dc31414597d1cd7fdd2422798b7652a6329dda0fe0219e6335a13d5bcaa9aeb6" dependencies = [ "cfg-if", "rustix", @@ -4875,7 +4859,7 @@ checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.9", + "regex-automata 0.4.8", "regex-syntax 0.8.5", ] @@ -4890,9 +4874,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.9" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -5029,7 +5013,7 @@ dependencies = [ "netlink-proto", "netlink-sys", "nix 0.26.4", - "thiserror 1.0.69", + "thiserror 1.0.68", "tokio", ] @@ -5065,9 +5049,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.41" +version = "0.38.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +checksum = "375116bee2be9ed569afe2154ea6a99dfdffd257f533f187498c2a8f5feaf4ee" dependencies = [ "bitflags 2.6.0", "errno", @@ -5078,9 +5062,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.17" +version = "0.23.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f1a745511c54ba6d4465e8d5dfbd81b45791756de28d4981af70d6dca128f1e" +checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" dependencies = [ "log", "once_cell", @@ -5118,9 +5102,6 @@ name = "rustls-pki-types" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" -dependencies = [ - "web-time", -] [[package]] name = "rustls-platform-verifier" @@ -5196,7 +5177,7 @@ dependencies = [ "radix_trie", "scopeguard", "unicode-segmentation", - "unicode-width 0.1.14", + "unicode-width", "utf8parse", "winapi", ] @@ -5227,9 +5208,9 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.27" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" dependencies = [ "windows-sys 0.59.0", ] @@ -5276,9 +5257,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.12.1" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" dependencies = [ "core-foundation-sys", "libc", @@ -5301,9 +5282,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.215" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] @@ -5338,9 +5319,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", @@ -5349,9 +5330,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.133" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "itoa", "memchr", @@ -5808,7 +5789,7 @@ dependencies = [ "pnet_packet", "rand", "socket2", - "thiserror 1.0.69", + "thiserror 1.0.68", "tokio", "tracing", ] @@ -5924,12 +5905,12 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.14.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", - "fastrand 2.2.0", + "fastrand 2.1.1", "once_cell", "rustix", "windows-sys 0.59.0", @@ -5957,11 +5938,11 @@ checksum = "614b328ff036a4ef882c61570f72918f7e9c5bee1da33f8e7f91e01daee7e56c" [[package]] name = "thiserror" -version = "1.0.69" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" dependencies = [ - "thiserror-impl 1.0.69", + "thiserror-impl 1.0.68", ] [[package]] @@ -5975,9 +5956,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "1.0.69" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" dependencies = [ "proc-macro2", "quote", @@ -6134,7 +6115,7 @@ dependencies = [ "rustls", "serde", "serde_json", - "thiserror 1.0.69", + "thiserror 1.0.68", "time", "tokio", "tokio-rustls", @@ -6193,7 +6174,7 @@ dependencies = [ "http 1.1.0", "httparse", "js-sys", - "thiserror 1.0.69", + "thiserror 1.0.68", "tokio", "tokio-tungstenite", "wasm-bindgen", @@ -6322,7 +6303,7 @@ dependencies = [ "governor", "http 1.1.0", "pin-project", - "thiserror 1.0.69", + "thiserror 1.0.68", "tower 0.4.13", "tracing", ] @@ -6346,7 +6327,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf" dependencies = [ "crossbeam-channel", - "thiserror 1.0.69", + "thiserror 1.0.68", "time", "tracing-subscriber", ] @@ -6441,7 +6422,7 @@ dependencies = [ "log", "rand", "sha1", - "thiserror 1.0.69", + "thiserror 1.0.68", "url", "utf-8", ] @@ -6508,7 +6489,7 @@ checksum = "b3644627a5af5fa321c95b9b235a72fd24cd29c648c2c379431e6628655627bf" dependencies = [ "itertools 0.13.0", "unicode-segmentation", - "unicode-width 0.1.14", + "unicode-width", ] [[package]] @@ -6517,12 +6498,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" -[[package]] -name = "unicode-width" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" - [[package]] name = "unicode-xid" version = "0.2.6" @@ -6730,7 +6705,7 @@ dependencies = [ "event-listener 4.0.3", "futures-util", "parking_lot", - "thiserror 1.0.69", + "thiserror 1.0.68", ] [[package]] @@ -6743,16 +6718,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "web-time" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "webpki-roots" version = "0.26.6" @@ -7099,7 +7064,7 @@ dependencies = [ "futures", "log", "serde", - "thiserror 1.0.69", + "thiserror 1.0.68", "windows 0.58.0", "windows-core 0.58.0", ] @@ -7129,7 +7094,7 @@ dependencies = [ "nom", "oid-registry", "rusticata-macros", - "thiserror 1.0.69", + "thiserror 1.0.68", "time", ] From 9833490ef5eb6d59e580e65b41443894ca46c4fc Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 19 Nov 2024 12:55:34 -0500 Subject: [PATCH 12/27] start self-review --- Cargo.toml | 3 +- iroh-netcheck/src/defaults.rs | 120 ---------------------------------- iroh-netcheck/src/dns.rs | 2 +- iroh-netcheck/src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 123 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fb67d6f5dc..f6c43367cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,8 @@ members = [ "iroh-relay", "iroh-router", "net-tools/netwatch", - "net-tools/portmapper", "iroh-netcheck", + "net-tools/portmapper", + "iroh-netcheck", ] resolver = "2" diff --git a/iroh-netcheck/src/defaults.rs b/iroh-netcheck/src/defaults.rs index 83d4fb6237..3864101ec3 100644 --- a/iroh-netcheck/src/defaults.rs +++ b/iroh-netcheck/src/defaults.rs @@ -1,130 +1,10 @@ //! Default values used in netcheck. -use url::Url; - -use crate::{RelayMap, RelayNode}; - /// The default STUN port used by the Relay server. /// /// The STUN port as defined by [RFC 8489]() pub const DEFAULT_STUN_PORT: u16 = 3478; -/// The default HTTP port used by the Relay server. -pub const DEFAULT_HTTP_PORT: u16 = 80; - -/// The default HTTPS port used by the Relay server. -pub const DEFAULT_HTTPS_PORT: u16 = 443; - -/// The default metrics port used by the Relay server. -pub const DEFAULT_METRICS_PORT: u16 = 9090; - -/// Production configuration. -pub mod prod { - use super::*; - - /// Hostname of the default NA relay. - pub const NA_RELAY_HOSTNAME: &str = "use1-1.relay.iroh.network."; - /// Hostname of the default EU relay. - pub const EU_RELAY_HOSTNAME: &str = "euw1-1.relay.iroh.network."; - /// Hostname of the default Asia-Pacific relay. - pub const AP_RELAY_HOSTNAME: &str = "aps1-1.relay.iroh.network."; - - /// Get the default [`RelayMap`]. - pub fn default_relay_map() -> RelayMap { - RelayMap::from_nodes([ - default_na_relay_node(), - default_eu_relay_node(), - default_ap_relay_node(), - ]) - .expect("default nodes invalid") - } - - /// Get the default [`RelayNode`] for NA. - pub fn default_na_relay_node() -> RelayNode { - // The default NA relay server run by number0. - let url: Url = format!("https://{NA_RELAY_HOSTNAME}") - .parse() - .expect("default url"); - RelayNode { - url: url.into(), - stun_only: false, - stun_port: DEFAULT_STUN_PORT, - } - } - - /// Get the default [`RelayNode`] for EU. - pub fn default_eu_relay_node() -> RelayNode { - // The default EU relay server run by number0. - let url: Url = format!("https://{EU_RELAY_HOSTNAME}") - .parse() - .expect("default_url"); - RelayNode { - url: url.into(), - stun_only: false, - stun_port: DEFAULT_STUN_PORT, - } - } - - /// Get the default [`RelayNode`] for Asia-Pacific - pub fn default_ap_relay_node() -> RelayNode { - // The default Asia-Pacific relay server run by number0. - let url: Url = format!("https://{AP_RELAY_HOSTNAME}") - .parse() - .expect("default_url"); - RelayNode { - url: url.into(), - stun_only: false, - stun_port: DEFAULT_STUN_PORT, - } - } -} - -/// Staging configuration. -/// -/// Used by tests and might have incompatible changes deployed -/// -/// Note: we have staging servers in EU and NA, but no corresponding staging server for AP at this time. -pub mod staging { - use super::*; - - /// Hostname of the default NA relay. - pub const NA_RELAY_HOSTNAME: &str = "staging-use1-1.relay.iroh.network."; - /// Hostname of the default EU relay. - pub const EU_RELAY_HOSTNAME: &str = "staging-euw1-1.relay.iroh.network."; - - /// Get the default [`RelayMap`]. - pub fn default_relay_map() -> RelayMap { - RelayMap::from_nodes([default_na_relay_node(), default_eu_relay_node()]) - .expect("default nodes invalid") - } - - /// Get the default [`RelayNode`] for NA. - pub fn default_na_relay_node() -> RelayNode { - // The default NA relay server run by number0. - let url: Url = format!("https://{NA_RELAY_HOSTNAME}") - .parse() - .expect("default url"); - RelayNode { - url: url.into(), - stun_only: false, - stun_port: DEFAULT_STUN_PORT, - } - } - - /// Get the default [`RelayNode`] for EU. - pub fn default_eu_relay_node() -> RelayNode { - // The default EU relay server run by number0. - let url: Url = format!("https://{EU_RELAY_HOSTNAME}") - .parse() - .expect("default_url"); - RelayNode { - url: url.into(), - stun_only: false, - stun_port: DEFAULT_STUN_PORT, - } - } -} - /// Contains all timeouts that we use in `iroh-netcheck`. pub(crate) mod timeouts { use std::time::Duration; diff --git a/iroh-netcheck/src/dns.rs b/iroh-netcheck/src/dns.rs index 74a0341643..4cdb47c1a7 100644 --- a/iroh-netcheck/src/dns.rs +++ b/iroh-netcheck/src/dns.rs @@ -10,7 +10,7 @@ use crate::defaults::timeouts::DNS_TIMEOUT; const DNS_STAGGERING_MS: &[u64] = &[200, 300]; /// Extension trait to [`TokioAsyncResolver`]. -pub trait ResolverExt { +pub(crate) trait ResolverExt { /// Perform an ipv4 lookup with a timeout. fn lookup_ipv4( &self, diff --git a/iroh-netcheck/src/lib.rs b/iroh-netcheck/src/lib.rs index 791b3e256a..362037f8dc 100644 --- a/iroh-netcheck/src/lib.rs +++ b/iroh-netcheck/src/lib.rs @@ -28,7 +28,7 @@ use tokio::{ use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle}; use tracing::{debug, error, info_span, trace, warn, Instrument}; -pub mod defaults; +mod defaults; mod dns; #[cfg(feature = "metrics")] mod metrics; From 71f2231c0155e677ff13a408f7c3d37d0dc1e19a Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 19 Nov 2024 16:02:07 -0500 Subject: [PATCH 13/27] fix doc warnings --- iroh-net/src/endpoint.rs | 3 +-- iroh-netcheck/src/lib.rs | 7 +++---- iroh-netcheck/src/reportgen/probes.rs | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/iroh-net/src/endpoint.rs b/iroh-net/src/endpoint.rs index 091cda7f18..afbd5d58dd 100644 --- a/iroh-net/src/endpoint.rs +++ b/iroh-net/src/endpoint.rs @@ -1357,9 +1357,8 @@ fn proxy_url_from_env() -> Option { None } + /// Configuration of the relay servers for an [`Endpoint`]. -/// -/// [`Endpoint`]: crate::endpoint::Endpoint #[derive(Debug, Clone, PartialEq, Eq)] pub enum RelayMode { /// Disable relay servers completely. diff --git a/iroh-netcheck/src/lib.rs b/iroh-netcheck/src/lib.rs index 362037f8dc..a00a7e4e87 100644 --- a/iroh-netcheck/src/lib.rs +++ b/iroh-netcheck/src/lib.rs @@ -2,9 +2,8 @@ //! //! Netcheck is responsible for finding out the network conditions of the current host, like //! whether it is connected to the internet via IPv4 and/or IPv6, what the NAT situation is -//! etc. -//! -//! Based on +//! etc and reachability to the configured relays. +// Based on use std::{ collections::{BTreeMap, HashMap}, @@ -330,7 +329,7 @@ pub(crate) enum Message { InFlightStun(Inflight, oneshot::Sender<()>), } -/// Sender to the [`Actor`]. +/// Sender to the main service. /// /// Unlike [`Client`] this is the raw channel to send messages over. Keeping this alive /// will not keep the actor alive, which makes this handy to pass to internal tasks. diff --git a/iroh-netcheck/src/reportgen/probes.rs b/iroh-netcheck/src/reportgen/probes.rs index 0cf22b3c6c..714a7199b4 100644 --- a/iroh-netcheck/src/reportgen/probes.rs +++ b/iroh-netcheck/src/reportgen/probes.rs @@ -190,7 +190,7 @@ impl fmt::Display for ProbeSet { /// The [`reportgen`] actor will also abort all the remaining [`ProbeSet`]s once it has /// sufficient information for a report. /// -/// [`reportgen`]: crate::netcheck::reportgen +/// [`reportgen`]: crate::reportgen #[derive(Debug, PartialEq, Eq)] pub(super) struct ProbePlan(BTreeSet); From 0c28d735b0cf69dbc3eaa2d4b1e11ccc7a2135ec Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 19 Nov 2024 16:25:46 -0500 Subject: [PATCH 14/27] fix toml even if it works --- iroh-netcheck/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iroh-netcheck/Cargo.toml b/iroh-netcheck/Cargo.toml index 68c6356259..e2efb91a62 100644 --- a/iroh-netcheck/Cargo.toml +++ b/iroh-netcheck/Cargo.toml @@ -26,7 +26,7 @@ reqwest = { version = "0.12", default-features = false } rustls = { version = "0.23", default-features = false } surge-ping = "0.8.0" thiserror = "1" -tokio = { version = "1", default-features = false } +tokio = { version = "1", default-features = false, features = ["sync", "time", "macros", "rt"] } tokio-util = { version = "0.7.12", default-features = false } tracing = "0.1" url = { version = "2.4" } From fd023a84c7361807ccaa2e3cc22a11e25d0e9784 Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 19 Nov 2024 23:49:31 -0500 Subject: [PATCH 15/27] add README.md --- iroh-netcheck/README.md | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 iroh-netcheck/README.md diff --git a/iroh-netcheck/README.md b/iroh-netcheck/README.md new file mode 100644 index 0000000000..332daa93c1 --- /dev/null +++ b/iroh-netcheck/README.md @@ -0,0 +1,71 @@ +# Iroh Netcheck + +`iroh-netcheck` is a tool for generating detailed reports on network +connectivity and configuration on the current host for nodes powered by [iroh]. +`iroh-netcheck` evaluates key aspects of network performance and behavior, +including NAT traversal capabilities, protocol availability, and relay server +latencies. Key features include: + +- **STUN diagnostics** + + Evaluates the completion of UDP STUN round trips for both IPv4 and IPv6. + Determine the variability of STUN results based on the destination server. + This helps understand the type of NAT for this host's network. + +- **IPv4 and IPv6 connectivity checks** + + Verifies basic connectivity for IPv4 and IPv6, including the ability to bind + sockets and send packets. + +- **ICMP diagnostics** + + Performs ICMP round trips for IPv4 and IPv6 to assess reachability. + +- **Hair-Pinning detection** + + Determines whether the router supports hair-pinning, enabling communication + between devices on the same NATed network via their public IP. + +- **Port Mapping protocol support** + + Detects the presence of port mapping protocols like UPnP, PCP, or NAT-PMP for + enhanced NAT traversal. + +- **Relay Server Latencies** + + Measures latency for the configured relay servers, keeping details about + IPv4-specific, and IPv6-specific measurements. + +- **Global IP Address Discovery** + + Identifies the public (global) IPv4 and IPv6 addresses for the host. + +- **Captive Portal Detection** + + Identifies if the network is using a captive portal to intercept HTTP + traffic. + +- **Preferred Relay Identification** + + Detect the best relay server for use. + +Used in [iroh], created with love by the [n0 team](https://n0.computer/). + +# License + +This project is licensed under either of + + * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or + http://www.apache.org/licenses/LICENSE-2.0) + * MIT license ([LICENSE-MIT](LICENSE-MIT) or + http://opensource.org/licenses/MIT) + +at your option. + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in this project by you, as defined in the Apache-2.0 license, +shall be dual licensed as above, without any additional terms or conditions. + +[iroh]: https://github.com/n0-computer/iroh From bd4f5669bd7a2356aa1cbfacc940dfcbbd803de9 Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 19 Nov 2024 23:53:34 -0500 Subject: [PATCH 16/27] add toml keys --- iroh-netcheck/Cargo.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/iroh-netcheck/Cargo.toml b/iroh-netcheck/Cargo.toml index e2efb91a62..4db0480e39 100644 --- a/iroh-netcheck/Cargo.toml +++ b/iroh-netcheck/Cargo.toml @@ -2,6 +2,12 @@ name = "iroh-netcheck" version = "0.1.0" edition = "2021" +readme = "README.md" +description = "detailed reporting on network conditions" +license = "MIT OR Apache-2.0" +authors = ["n0 team"] +repository = "https://github.com/n0-computer/iroh" +keywords = ["networking"] # Sadly this also needs to be updated in .github/workflows/ci.yml rust-version = "1.76" From b11212c20ee8b0939243d8cb1c223319d540e13b Mon Sep 17 00:00:00 2001 From: Diva M Date: Wed, 20 Nov 2024 10:39:28 -0500 Subject: [PATCH 17/27] netcheck is 28vo --- Cargo.lock | 2 +- iroh-cli/Cargo.toml | 2 +- iroh-net/Cargo.toml | 2 +- iroh-netcheck/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b9214a4dfb..c33cd92d63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3097,7 +3097,7 @@ dependencies = [ [[package]] name = "iroh-netcheck" -version = "0.1.0" +version = "0.28.0" dependencies = [ "anyhow", "bytes", diff --git a/iroh-cli/Cargo.toml b/iroh-cli/Cargo.toml index 434bad536d..2dc1617986 100644 --- a/iroh-cli/Cargo.toml +++ b/iroh-cli/Cargo.toml @@ -45,7 +45,7 @@ iroh-blobs = { version = "0.28.1", features = ["cli"] } iroh-docs = { version = "0.28.0", features = ["cli"] } iroh-gossip = { version = "0.28.1", features = ["cli"] } iroh-metrics = { version = "0.28.0" } -netcheck = { package = "iroh-netcheck", path = "../iroh-netcheck", version = "0.1" } +netcheck = { package = "iroh-netcheck", path = "../iroh-netcheck", version = "0.28" } parking_lot = "0.12.1" pkarr = { version = "2.2.0", default-features = false } portable-atomic = "1" diff --git a/iroh-net/Cargo.toml b/iroh-net/Cargo.toml index 075bb52f92..cf6af38f60 100644 --- a/iroh-net/Cargo.toml +++ b/iroh-net/Cargo.toml @@ -114,7 +114,7 @@ webpki = { package = "rustls-webpki", version = "0.102" } webpki-roots = "0.26" x509-parser = "0.16" z32 = "1.0.3" -netcheck = { package = "iroh-netcheck", path = "../iroh-netcheck", version = "0.1" } +netcheck = { package = "iroh-netcheck", path = "../iroh-netcheck", version = "0.28" } # metrics iroh-metrics = { version = "0.28.0", default-features = false } diff --git a/iroh-netcheck/Cargo.toml b/iroh-netcheck/Cargo.toml index 4db0480e39..9d998ac2c3 100644 --- a/iroh-netcheck/Cargo.toml +++ b/iroh-netcheck/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iroh-netcheck" -version = "0.1.0" +version = "0.28.0" edition = "2021" readme = "README.md" description = "detailed reporting on network conditions" From 92c05bb121fa8c3e663e34871b406293c3b4f29d Mon Sep 17 00:00:00 2001 From: Diva M Date: Wed, 20 Nov 2024 11:11:52 -0500 Subject: [PATCH 18/27] add crate to ci with new name --- .github/workflows/ci.yml | 2 +- .github/workflows/tests.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4971c5d49..95a4e2e553 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -190,7 +190,7 @@ jobs: # uses: obi1kenobi/cargo-semver-checks-action@v2 uses: n0-computer/cargo-semver-checks-action@feat-baseline with: - package: iroh, iroh-base, iroh-cli, iroh-dns-server, iroh-metrics, iroh-net, iroh-net-bench, iroh-router, netwatch, portmapper, iroh-relay + package: iroh, iroh-base, iroh-cli, iroh-dns-server, iroh-metrics, iroh-net, iroh-net-bench, iroh-router, netwatch, portmapper, iroh-relay, net-report baseline-rev: ${{ env.HEAD_COMMIT_SHA }} use-cache: false diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 5640af42c9..a271e814c8 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -23,7 +23,7 @@ env: RUSTFLAGS: -Dwarnings RUSTDOCFLAGS: -Dwarnings SCCACHE_CACHE_SIZE: "50G" - CRATES_LIST: "iroh,iroh-metrics,iroh-net,iroh-net-bench,iroh-test,iroh-cli,iroh-dns-server,iroh-router,netwatch,portmapper,iroh-relay" + CRATES_LIST: "iroh,iroh-metrics,iroh-net,iroh-net-bench,iroh-test,iroh-cli,iroh-dns-server,iroh-router,netwatch,portmapper,iroh-relay,net-report" IROH_FORCE_STAGING_RELAYS: "1" jobs: From 984f13b751b4005fee0ce994c4ba61c2ac1193a7 Mon Sep 17 00:00:00 2001 From: Diva M Date: Wed, 20 Nov 2024 11:13:59 -0500 Subject: [PATCH 19/27] mass renaming to net-report --- iroh-cli/src/commands/doctor.rs | 2 +- iroh-net/src/defaults.rs | 4 +- iroh-net/src/magicsock.rs | 50 +++++++++++------------ iroh-net/src/magicsock/udp_conn.rs | 2 +- iroh-net/src/metrics.rs | 2 +- iroh-netcheck/src/defaults.rs | 8 ++-- iroh-netcheck/src/lib.rs | 44 ++++++++++---------- iroh-netcheck/src/metrics.rs | 6 +-- iroh-netcheck/src/ping.rs | 4 +- iroh-netcheck/src/reportgen.rs | 56 +++++++++++++------------- iroh-netcheck/src/reportgen/hairpin.rs | 56 +++++++++++++------------- iroh-netcheck/src/reportgen/probes.rs | 6 +-- iroh-relay/src/server.rs | 4 +- 13 files changed, 122 insertions(+), 122 deletions(-) diff --git a/iroh-cli/src/commands/doctor.rs b/iroh-cli/src/commands/doctor.rs index bc1418ed7b..2cbb00d42f 100644 --- a/iroh-cli/src/commands/doctor.rs +++ b/iroh-cli/src/commands/doctor.rs @@ -347,7 +347,7 @@ async fn report( ) -> anyhow::Result<()> { let port_mapper = portmapper::Client::default(); let dns_resolver = default_resolver().clone(); - let mut client = netcheck::Client::new(Some(port_mapper), dns_resolver)?; + let mut client = net_report::Client::new(Some(port_mapper), dns_resolver)?; let dm = match stun_host { Some(host_name) => { diff --git a/iroh-net/src/defaults.rs b/iroh-net/src/defaults.rs index 111473d977..791f569d1a 100644 --- a/iroh-net/src/defaults.rs +++ b/iroh-net/src/defaults.rs @@ -130,8 +130,8 @@ pub mod staging { pub(crate) mod timeouts { use std::time::Duration; - // Timeouts for netcheck + // Timeouts for net_report - /// Maximum duration to wait for a netcheck report. + /// Maximum duration to wait for a net_report report. pub(crate) const NETCHECK_REPORT_TIMEOUT: Duration = Duration::from_secs(10); } diff --git a/iroh-net/src/magicsock.rs b/iroh-net/src/magicsock.rs index 02b5a4c640..e901433fa4 100644 --- a/iroh-net/src/magicsock.rs +++ b/iroh-net/src/magicsock.rs @@ -203,7 +203,7 @@ pub(crate) struct MagicSock { closing: AtomicBool, /// Close was called. closed: AtomicBool, - /// If the last netcheck report, reports IPv6 to be available. + /// If the last net_report report, reports IPv6 to be available. ipv6_reported: Arc, /// None (or zero nodes) means relay is disabled. @@ -217,7 +217,7 @@ pub(crate) struct MagicSock { /// UDP IPv6 socket pconn6: Option, /// Netcheck client - net_checker: netcheck::Addr, + net_checker: net_report::Addr, /// The state for an active DiscoKey. disco_secrets: DiscoSecrets, @@ -1217,7 +1217,7 @@ impl MagicSock { /// Sends the call-me-maybe DISCO message, queuing if addresses are too stale. /// /// To send the call-me-maybe message, we need to know our current direct addresses. If - /// this information is too stale, the call-me-maybe is queued while a netcheck run is + /// this information is too stale, the call-me-maybe is queued while a net_report run is /// scheduled. Once this run finishes, the call-me-maybe will be sent. fn send_or_queue_call_me_maybe(&self, url: &RelayUrl, dst_node: NodeId) { match self.direct_addrs.fresh_enough() { @@ -1305,7 +1305,7 @@ impl DiscoMessageSource { } } -/// Manages currently running direct addr discovery, aka netcheck runs. +/// Manages currently running direct addr discovery, aka net_report runs. /// /// Invariants: /// - only one direct addr update must be running at a time @@ -1405,7 +1405,7 @@ impl Handle { let ipv4_addr = pconn4.local_addr()?; let ipv6_addr = pconn6.as_ref().and_then(|c| c.local_addr().ok()); - let net_checker = netcheck::Client::new(Some(port_mapper.clone()), dns_resolver.clone())?; + let net_checker = net_report::Client::new(Some(port_mapper.clone()), dns_resolver.clone())?; let (actor_sender, actor_receiver) = mpsc::channel(256); let (relay_actor_sender, relay_actor_receiver) = mpsc::channel(256); @@ -1699,7 +1699,7 @@ enum ActorMessage { Shutdown, ReceiveRelay(RelayReadResult), EndpointPingExpired(usize, stun_rs::TransactionId), - NetcheckReport(Result>>, &'static str), + NetcheckReport(Result>>, &'static str), NetworkChange, #[cfg(test)] ForceNetworkChange(bool), @@ -1731,7 +1731,7 @@ struct Actor { no_v4_send: bool, /// The prober that discovers local network conditions, including the closest relay relay and NAT mappings. - net_checker: netcheck::Client, + net_checker: net_report::Client, network_monitor: netmon::Monitor, } @@ -1922,10 +1922,10 @@ impl Actor { ActorMessage::NetcheckReport(report, why) => { match report { Ok(report) => { - self.handle_netcheck_report(report).await; + self.handle_net_report_report(report).await; } Err(err) => { - warn!("failed to generate netcheck report for: {}: {:?}", why, err); + warn!("failed to generate net_report report for: {}: {:?}", why, err); } } self.finalize_direct_addrs_update(why); @@ -1997,7 +1997,7 @@ impl Actor { /// Refreshes knowledge about our direct addresses. /// - /// In other words, this triggers a netcheck run. + /// In other words, this triggers a net_report run. /// /// Note that invoking this is managed by the [`DirectAddrUpdateState`] and this should /// never be invoked directly. Some day this will be refactored to not allow this easy @@ -2017,9 +2017,9 @@ impl Actor { /// direct addresses from: /// /// - The portmapper. - /// - A netcheck report. + /// - A net_report report. /// - The local interfaces IP addresses. - fn update_direct_addresses(&mut self, netcheck_report: Option>) { + fn update_direct_addresses(&mut self, net_report_report: Option>) { let portmap_watcher = self.port_mapper.watch_external_address(); // We only want to have one DirectAddr for each SocketAddr we have. So we store @@ -2036,9 +2036,9 @@ impl Actor { self.set_net_info_have_port_map(); } - // Next add STUN addresses from the netcheck report. - if let Some(netcheck_report) = netcheck_report { - if let Some(global_v4) = netcheck_report.global_v4 { + // Next add STUN addresses from the net_report report. + if let Some(net_report_report) = net_report_report { + if let Some(global_v4) = net_report_report.global_v4 { addrs .entry(global_v4.into()) .or_insert(DirectAddrType::Stun); @@ -2048,7 +2048,7 @@ impl Actor { // port mapping on their router to the same explicit // port that we are running with. Worst case it's an invalid candidate mapping. let port = self.msock.port.load(Ordering::Relaxed); - if netcheck_report + if net_report_report .mapping_varies_by_dest_ip .unwrap_or_default() && port != 0 @@ -2060,7 +2060,7 @@ impl Actor { .or_insert(DirectAddrType::Stun4LocalPort); } } - if let Some(global_v6) = netcheck_report.global_v6 { + if let Some(global_v6) = net_report_report.global_v6 { addrs .entry(global_v6.into()) .or_insert(DirectAddrType::Stun); @@ -2185,7 +2185,7 @@ impl Actor { self.net_info_last = Some(ni); } - /// Calls netcheck. + /// Calls net_report. /// /// Note that invoking this is managed by [`DirectAddrUpdateState`] via /// [`Actor::refresh_direct_addrs`] and this should never be invoked directly. Some day @@ -2193,7 +2193,7 @@ impl Actor { #[instrument(level = "debug", skip_all)] async fn update_net_info(&mut self, why: &'static str) { if self.msock.relay_map.is_empty() { - debug!("skipping netcheck, empty RelayMap"); + debug!("skipping net_report, empty RelayMap"); self.msg_sender .send(ActorMessage::NetcheckReport(Ok(None), why)) .await @@ -2205,7 +2205,7 @@ impl Actor { let pconn4 = Some(self.pconn4.as_socket()); let pconn6 = self.pconn6.as_ref().map(|p| p.as_socket()); - debug!("requesting netcheck report"); + debug!("requesting net_report report"); match self .net_checker .get_report_channel(relay_map, pconn4, pconn6) @@ -2218,8 +2218,8 @@ impl Actor { let report: anyhow::Result<_> = match report { Ok(Ok(Ok(report))) => Ok(Some(report)), Ok(Ok(Err(err))) => Err(err), - Ok(Err(_)) => Err(anyhow!("netcheck report not received")), - Err(err) => Err(anyhow!("netcheck report timeout: {:?}", err)), + Ok(Err(_)) => Err(anyhow!("net_report report not received")), + Err(err) => Err(anyhow!("net_report report timeout: {:?}", err)), }; msg_sender .send(ActorMessage::NetcheckReport(report, why)) @@ -2230,13 +2230,13 @@ impl Actor { }); } Err(err) => { - warn!("unable to start netcheck generation: {:?}", err); + warn!("unable to start net_report generation: {:?}", err); self.finalize_direct_addrs_update(why); } } } - async fn handle_netcheck_report(&mut self, report: Option>) { + async fn handle_net_report_report(&mut self, report: Option>) { if let Some(ref report) = report { self.msock .ipv6_reported @@ -2311,7 +2311,7 @@ impl Actor { true } - /// Returns a deterministic relay node to connect to. This is only used if netcheck + /// Returns a deterministic relay node to connect to. This is only used if net_report /// couldn't find the nearest one, for instance, if UDP is blocked and thus STUN /// latency checks aren't working. /// diff --git a/iroh-net/src/magicsock/udp_conn.rs b/iroh-net/src/magicsock/udp_conn.rs index a3370176e6..2c23d44f5b 100644 --- a/iroh-net/src/magicsock/udp_conn.rs +++ b/iroh-net/src/magicsock/udp_conn.rs @@ -231,7 +231,7 @@ mod tests { #[tokio::test] async fn test_rebinding_conn_send_recv_ipv6() -> Result<()> { let _guard = iroh_test::logging::setup(); - if !netcheck::os_has_ipv6() { + if !net_report::os_has_ipv6() { return Ok(()); } rebinding_conn_send_recv(IpFamily::V6).await diff --git a/iroh-net/src/metrics.rs b/iroh-net/src/metrics.rs index 91c2a5c8dd..ef4e40fcd4 100644 --- a/iroh-net/src/metrics.rs +++ b/iroh-net/src/metrics.rs @@ -2,7 +2,7 @@ #[cfg(feature = "test-utils")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "test-utils")))] pub use iroh_relay::server::Metrics as RelayMetrics; -pub use netcheck::Metrics as NetcheckMetrics; +pub use net_report::Metrics as NetcheckMetrics; pub use portmapper::Metrics as PortmapMetrics; pub use crate::magicsock::Metrics as MagicsockMetrics; diff --git a/iroh-netcheck/src/defaults.rs b/iroh-netcheck/src/defaults.rs index 3864101ec3..e40ae1e72a 100644 --- a/iroh-netcheck/src/defaults.rs +++ b/iroh-netcheck/src/defaults.rs @@ -1,17 +1,17 @@ -//! Default values used in netcheck. +//! Default values used in net_report. /// The default STUN port used by the Relay server. /// /// The STUN port as defined by [RFC 8489]() pub const DEFAULT_STUN_PORT: u16 = 3478; -/// Contains all timeouts that we use in `iroh-netcheck`. +/// Contains all timeouts that we use in `iroh-net_report`. pub(crate) mod timeouts { use std::time::Duration; - // Timeouts for netcheck + // Timeouts for net_report - /// The maximum amount of time netcheck will spend gathering a single report. + /// The maximum amount of time net_report will spend gathering a single report. pub(crate) const OVERALL_REPORT_TIMEOUT: Duration = Duration::from_secs(5); /// The total time we wait for all the probes. diff --git a/iroh-netcheck/src/lib.rs b/iroh-netcheck/src/lib.rs index a00a7e4e87..f21c2d6ca3 100644 --- a/iroh-netcheck/src/lib.rs +++ b/iroh-netcheck/src/lib.rs @@ -3,7 +3,7 @@ //! Netcheck is responsible for finding out the network conditions of the current host, like //! whether it is connected to the internet via IPv4 and/or IPv6, what the NAT situation is //! etc and reachability to the configured relays. -// Based on +// Based on use std::{ collections::{BTreeMap, HashMap}, @@ -48,7 +48,7 @@ const FULL_REPORT_INTERVAL: Duration = Duration::from_secs(5 * 60); /// default which will never be used. const DEFAULT_MAX_LATENCY: Duration = Duration::from_millis(100); -/// A netcheck report. +/// A net_report report. /// /// Can be obtained by calling [`Client::get_report`]. #[derive(Default, Debug, PartialEq, Eq, Clone)] @@ -159,15 +159,15 @@ impl RelayLatencies { } } -/// Client to run netchecks. +/// Client to run net_reports. /// -/// Creating this creates a netcheck actor which runs in the background. Most of the time +/// Creating this creates a net_report actor which runs in the background. Most of the time /// it is idle unless [`Client::get_report`] is called, which is the main interface. /// /// The [`Client`] struct can be cloned and results multiple handles to the running actor. /// If all [`Client`]s are dropped the actor stops running. /// -/// While running the netcheck actor expects to be passed all received stun packets using +/// While running the net_report actor expects to be passed all received stun packets using /// `Addr::receive_stun_packet`. #[derive(Debug)] pub struct Client { @@ -204,7 +204,7 @@ impl Default for Reports { } impl Client { - /// Creates a new netcheck client. + /// Creates a new net_report client. /// /// This starts a connected actor in the background. Once the client is dropped it will /// stop running. @@ -212,7 +212,7 @@ impl Client { let mut actor = Actor::new(port_mapper, dns_resolver)?; let addr = actor.addr(); let task = - tokio::spawn(async move { actor.run().await }.instrument(info_span!("netcheck.actor"))); + tokio::spawn(async move { actor.run().await }.instrument(info_span!("net_report.actor"))); let drop_guard = AbortOnDropHandle::new(task); Ok(Client { addr, @@ -228,7 +228,7 @@ impl Client { self.addr.clone() } - /// Runs a netcheck, returning the report. + /// Runs a net_report, returning the report. /// /// It may not be called concurrently with itself, `&mut self` takes care of that. /// @@ -289,9 +289,9 @@ pub(crate) struct Inflight { /// Messages to send to the [`Actor`]. #[derive(Debug)] pub(crate) enum Message { - /// Run a netcheck. + /// Run a net_report. /// - /// Only one netcheck can be run at a time, trying to run multiple concurrently will + /// Only one net_report can be run at a time, trying to run multiple concurrently will /// fail. RunCheck { /// The relay configuration. @@ -339,15 +339,15 @@ pub struct Addr { } impl Addr { - /// Pass a received STUN packet to the netchecker. + /// Pass a received STUN packet to the net_reporter. /// /// Normally the UDP sockets to send STUN messages from are passed in so that STUN /// packets are sent from the sockets that carry the real traffic. However because /// these sockets carry real traffic they will also receive non-STUN traffic, thus the - /// netcheck actor does not read from the sockets directly. If you receive a STUN + /// net_report actor does not read from the sockets directly. If you receive a STUN /// packet on the socket you should pass it to this method. /// - /// It is safe to call this even when the netcheck actor does not currently have any + /// It is safe to call this even when the net_report actor does not currently have any /// in-flight STUN probes. The actor will simply ignore any stray STUN packets. /// /// There is an implicit queue here which may drop packets if the actor does not keep up @@ -365,12 +365,12 @@ impl Addr { async fn send(&self, msg: Message) -> Result<(), mpsc::error::SendError> { self.sender.send(msg).await.inspect_err(|_| { - error!("netcheck actor lost"); + error!("net_report actor lost"); }) } } -/// The netcheck actor. +/// The net_report actor. /// /// This actor runs for the entire duration there's a [`Client`] connected. #[derive(Debug)] @@ -439,7 +439,7 @@ impl Actor { /// It will now run and handle messages. Once the connected [`Client`] (including all /// its clones) is dropped this will terminate. async fn run(&mut self) { - debug!("netcheck actor starting"); + debug!("net_report actor starting"); while let Some(msg) = self.receiver.recv().await { trace!(?msg, "handling message"); match msg { @@ -503,7 +503,7 @@ impl Actor { || now.duration_since(self.reports.last_full) > FULL_REPORT_INTERVAL; // If the last report had a captive portal and reported no UDP access, - // it's possible that we didn't get a useful netcheck due to the + // it's possible that we didn't get a useful net_report due to the // captive portal blocking us. If so, make this report a full (non-incremental) one. if !do_full { if let Some(ref last) = self.reports.last { @@ -694,12 +694,12 @@ impl Actor { } } -/// State the netcheck actor needs for an in-progress report generation. +/// State the net_report actor needs for an in-progress report generation. #[derive(Debug)] struct ReportRun { /// The handle of the [`reportgen`] actor, cancels the actor on drop. _reportgen: reportgen::Client, - /// Drop guard to optionally kill workers started by netcheck to support reportgen. + /// Drop guard to optionally kill workers started by net_report to support reportgen. _drop_guard: tokio_util::sync::DropGuard, /// Where to send the completed report. report_tx: oneshot::Sender>>, @@ -1251,9 +1251,9 @@ mod tests { // Set up an external socket to send STUN requests from, this will be discovered as // our public socket address by STUN. We send back any packets received on this - // socket to the netcheck client using Client::receive_stun_packet. Once we sent + // socket to the net_report client using Client::receive_stun_packet. Once we sent // the hairpin STUN request (from a different randomly bound socket) we are sending - // it to this socket, which is forwarnding it back to our netcheck client, because + // it to this socket, which is forwarnding it back to our net_report client, because // this dumb implementation just forwards anything even if it would be garbage. // Thus hairpinning detection will declare hairpinning to work. let sock = UdpSocket::bind_local(IpFamily::V4, 0)?; @@ -1270,7 +1270,7 @@ mod tests { info!( addr=?sock.local_addr().unwrap(), %count, - "Forwarding payload to netcheck client", + "Forwarding payload to net_report client", ); let payload = buf.split_to(count).freeze(); addr.receive_stun_packet(payload, src); diff --git a/iroh-netcheck/src/metrics.rs b/iroh-netcheck/src/metrics.rs index f3891d4792..331d9284a2 100644 --- a/iroh-netcheck/src/metrics.rs +++ b/iroh-netcheck/src/metrics.rs @@ -26,14 +26,14 @@ impl Default for Metrics { stun_packets_sent_ipv6: Counter::new("Number of IPv6 STUN packets sent"), stun_packets_recv_ipv4: Counter::new("Number of IPv4 STUN packets received"), stun_packets_recv_ipv6: Counter::new("Number of IPv6 STUN packets received"), - reports: Counter::new("Number of reports executed by netcheck, including full reports"), - reports_full: Counter::new("Number of full reports executed by netcheck"), + reports: Counter::new("Number of reports executed by net_report, including full reports"), + reports_full: Counter::new("Number of full reports executed by net_report"), } } } impl Metric for Metrics { fn name() -> &'static str { - "netcheck" + "net_report" } } diff --git a/iroh-netcheck/src/ping.rs b/iroh-netcheck/src/ping.rs index 871fbe2376..159e7103a6 100644 --- a/iroh-netcheck/src/ping.rs +++ b/iroh-netcheck/src/ping.rs @@ -90,7 +90,7 @@ impl Pinger { let ident = PingIdentifier(rand::random()); debug!(%addr, %ident, "Creating pinger"); let mut pinger = client.pinger(addr, ident).await; - pinger.timeout(DEFAULT_TIMEOUT); // todo: timeout too large for netcheck + pinger.timeout(DEFAULT_TIMEOUT); // todo: timeout too large for net_report match pinger.ping(PingSequence(0), data).await? { (IcmpPacket::V4(packet), dur) => { debug!( @@ -157,7 +157,7 @@ mod tests { Ok(()) } - // See netcheck::reportgen::tests::test_icmp_probe_eu_relay for permissions to ping. + // See net_report::reportgen::tests::test_icmp_probe_eu_relay for permissions to ping. #[tokio::test] async fn test_ping_localhost() { let _guard = iroh_test::logging::setup(); diff --git a/iroh-netcheck/src/reportgen.rs b/iroh-netcheck/src/reportgen.rs index e77b6f7880..307a806777 100644 --- a/iroh-netcheck/src/reportgen.rs +++ b/iroh-netcheck/src/reportgen.rs @@ -1,4 +1,4 @@ -//! The reportgen actor is responsible for generating a single netcheck report. +//! The reportgen actor is responsible for generating a single net_report report. //! //! It is implemented as an actor with [`Client`] as handle. //! @@ -14,7 +14,7 @@ //! - Loops driving the futures and handling actor messages: //! - Disables futures as they are completed or aborted. //! - Stop if there are no outstanding tasks/futures, or on timeout. -//! - Sends the completed report to the netcheck actor. +//! - Sends the completed report to the net_report actor. use std::{ future::Future, @@ -44,7 +44,7 @@ use url::Host; #[cfg(feature = "metrics")] use crate::Metrics; use crate::{ - self as netcheck, + self as net_report, defaults::DEFAULT_STUN_PORT, dns::ResolverExt, ping::{PingError, Pinger}, @@ -62,7 +62,7 @@ use crate::defaults::timeouts::{ const ENOUGH_NODES: usize = 3; -/// Holds the state for a single invocation of [`netcheck::Client::get_report`]. +/// Holds the state for a single invocation of [`net_report::Client::get_report`]. /// /// Dropping this will cancel the actor and stop the report generation. #[derive(Debug)] @@ -77,7 +77,7 @@ impl Client { /// The actor starts running immediately and only generates a single report, after which /// it shuts down. Dropping this handle will abort the actor. pub(super) fn new( - netcheck: netcheck::Addr, + net_report: net_report::Addr, last_report: Option>, port_mapper: Option, relay_map: RelayMap, @@ -92,14 +92,14 @@ impl Client { let mut actor = Actor { msg_tx, msg_rx, - netcheck: netcheck.clone(), + net_report: net_report.clone(), last_report, port_mapper, relay_map, stun_sock4, stun_sock6, report: Report::default(), - hairpin_actor: hairpin::Client::new(netcheck, addr), + hairpin_actor: hairpin::Client::new(net_report, addr), outstanding_tasks: OutstandingTasks::default(), dns_resolver, }; @@ -157,8 +157,8 @@ struct Actor { msg_tx: mpsc::Sender, /// The receiver of the message channel. msg_rx: mpsc::Receiver, - /// The address of the netcheck actor. - netcheck: super::Addr, + /// The address of the net_report actor. + net_report: super::Addr, // Provided state /// The previous report, if it exists. @@ -196,8 +196,8 @@ impl Actor { match self.run_inner().await { Ok(_) => debug!("reportgen actor finished"), Err(err) => { - self.netcheck - .send(netcheck::Message::ReportAborted { err }) + self.net_report + .send(net_report::Message::ReportAborted { err }) .await .ok(); } @@ -215,7 +215,7 @@ impl Actor { /// - Drives all the above futures. /// - Receives actor messages (sent by those futures). /// - Updates the report, cancels unneeded futures. - /// - Sends the report to the netcheck actor. + /// - Sends the report to the net_report actor. async fn run_inner(&mut self) -> Result<()> { debug!( port_mapper = %self.port_mapper.is_some(), @@ -307,9 +307,9 @@ impl Actor { drop(probes); } - debug!("Sending report to netcheck actor"); - self.netcheck - .send(netcheck::Message::ReportReady { + debug!("Sending report to net_report actor"); + self.net_report + .send(net_report::Message::ReportReady { report: Box::new(self.report.clone()), }) .await?; @@ -546,7 +546,7 @@ impl Actor { let stun_sock6 = self.stun_sock6.clone(); let relay_node = probe.node().clone(); let probe = probe.clone(); - let netcheck = self.netcheck.clone(); + let net_report = self.net_report.clone(); let pinger = pinger.clone(); let dns_resolver = self.dns_resolver.clone(); @@ -557,7 +557,7 @@ impl Actor { stun_sock6, relay_node, probe.clone(), - netcheck, + net_report, pinger, dns_resolver, ) @@ -678,7 +678,7 @@ async fn run_probe( stun_sock6: Option>, relay_node: Arc, probe: Probe, - netcheck: netcheck::Addr, + net_report: net_report::Addr, pinger: Pinger, dns_resolver: DnsResolver, ) -> Result { @@ -729,7 +729,7 @@ async fn run_probe( }; match maybe_sock { Some(sock) => { - result = run_stun_probe(sock, relay_addr, netcheck, probe).await?; + result = run_stun_probe(sock, relay_addr, net_report, probe).await?; } None => { return Err(ProbeError::AbortSet( @@ -772,7 +772,7 @@ async fn run_probe( async fn run_stun_probe( sock: &Arc, relay_addr: SocketAddr, - netcheck: netcheck::Addr, + net_report: net_report::Addr, probe: Probe, ) -> Result { match probe.proto() { @@ -783,12 +783,12 @@ async fn run_stun_probe( let txid = stun::TransactionId::default(); let req = stun::request(txid); - // Setup netcheck to give us back the incoming STUN response. + // Setup net_report to give us back the incoming STUN response. let (stun_tx, stun_rx) = oneshot::channel(); let (inflight_ready_tx, inflight_ready_rx) = oneshot::channel(); - netcheck - .send(netcheck::Message::InFlightStun( - netcheck::Inflight { + net_report + .send(net_report::Message::InFlightStun( + net_report::Inflight { txn: txid, start: Instant::now(), s: stun_tx, @@ -1104,7 +1104,7 @@ async fn measure_https_latency( } } -/// Updates a netcheck [`Report`] with a new [`ProbeReport`]. +/// Updates a net_report [`Report`] with a new [`ProbeReport`]. fn update_report(report: &mut Report, probe_report: ProbeReport) { let relay_node = probe_report.probe.node(); if let Some(latency) = probe_report.latency { @@ -1358,11 +1358,11 @@ mod tests { // // Build the test binary: // - // cargo nextest run -p iroh_net netcheck::reportgen::tests --no-run + // cargo nextest run -p iroh_net net_report::reportgen::tests --no-run // // Find out the test binary location: // - // cargo nextest list --message-format json -p iroh-net netcheck::reportgen::tests \ + // cargo nextest list --message-format json -p iroh-net net_report::reportgen::tests \ // | jq '."rust-suites"."iroh-net"."binary-path"' | tr -d \" // // Set the CAP_NET_RAW permission, note that nextest runs each test in a child process @@ -1372,7 +1372,7 @@ mod tests { // // Finally run the test: // - // cargo nextest run -p iroh_net netcheck::reportgen::tests + // cargo nextest run -p iroh_net net_report::reportgen::tests // // This allows the pinger to create a SOCK_RAW socket for IPPROTO_ICMP. // diff --git a/iroh-netcheck/src/reportgen/hairpin.rs b/iroh-netcheck/src/reportgen/hairpin.rs index ad1e51f45d..9c7d6d5999 100644 --- a/iroh-netcheck/src/reportgen/hairpin.rs +++ b/iroh-netcheck/src/reportgen/hairpin.rs @@ -6,7 +6,7 @@ //! - binds socket //! - sends traffic from it's socket to trick some routers //! - When requested performs the hairpin probe. -//! - result is sent to netcheck actor addr. +//! - result is sent to net_report actor addr. //! - Shuts down //! //! Note it will only perform a single hairpin check before shutting down. Any further @@ -21,7 +21,7 @@ use tokio::{sync::oneshot, time::Instant}; use tokio_util::task::AbortOnDropHandle; use tracing::{debug, error, info_span, trace, warn, Instrument}; -use crate::{self as netcheck, defaults::timeouts::HAIRPIN_CHECK_TIMEOUT, reportgen, Inflight}; +use crate::{self as net_report, defaults::timeouts::HAIRPIN_CHECK_TIMEOUT, reportgen, Inflight}; /// Handle to the hairpin actor. /// @@ -33,12 +33,12 @@ pub(super) struct Client { } impl Client { - pub(super) fn new(netcheck: netcheck::Addr, reportgen: reportgen::Addr) -> Self { + pub(super) fn new(net_report: net_report::Addr, reportgen: reportgen::Addr) -> Self { let (addr, msg_rx) = oneshot::channel(); let actor = Actor { msg_rx, - netcheck, + net_report, reportgen, }; @@ -81,7 +81,7 @@ enum Message { #[derive(Debug)] struct Actor { msg_rx: oneshot::Receiver, - netcheck: netcheck::Addr, + net_report: net_report::Addr, reportgen: reportgen::Addr, } @@ -115,11 +115,11 @@ impl Actor { s: stun_tx, }; let (msg_response_tx, msg_response_rx) = oneshot::channel(); - self.netcheck - .send(netcheck::Message::InFlightStun(inflight, msg_response_tx)) + self.net_report + .send(net_report::Message::InFlightStun(inflight, msg_response_tx)) .await - .context("netcheck actor gone")?; - msg_response_rx.await.context("netcheck actor died")?; + .context("net_report actor gone")?; + msg_response_rx.await.context("net_report actor died")?; if let Err(err) = socket.send_to(&stun::request(txn), dst).await { warn!(%dst, "failed to send hairpin check"); @@ -129,7 +129,7 @@ impl Actor { let now = Instant::now(); let hairpinning_works = match tokio::time::timeout(HAIRPIN_CHECK_TIMEOUT, stun_rx).await { Ok(Ok(_)) => true, - Ok(Err(_)) => bail!("netcheck actor dropped stun response channel"), + Ok(Err(_)) => bail!("net_report actor dropped stun response channel"), Err(_) => false, // Elapsed }; debug!( @@ -163,7 +163,7 @@ impl Actor { socket .send_to( - b"tailscale netcheck; see https://github.com/tailscale/tailscale/issues/188", + b"tailscale net_report; see https://github.com/tailscale/tailscale/issues/188", documentation_ip, ) .await?; @@ -198,10 +198,10 @@ mod tests { async fn test_hairpin(hairpinning_works: bool) { let _guard = iroh_test::logging::setup(); - // Setup fake netcheck and reportstate actors, hairpinning interacts with them. - let (netcheck_tx, mut netcheck_rx) = mpsc::channel(32); - let netcheck_addr = netcheck::Addr { - sender: netcheck_tx, + // Setup fake net_report and reportstate actors, hairpinning interacts with them. + let (net_report_tx, mut net_report_rx) = mpsc::channel(32); + let net_report_addr = net_report::Addr { + sender: net_report_tx, }; let (reportstate_tx, mut reportstate_rx) = mpsc::channel(32); let reportstate_addr = reportgen::Addr { @@ -209,7 +209,7 @@ mod tests { }; // Create hairpin actor - let mut actor = Client::new(netcheck_addr, reportstate_addr); + let mut actor = Client::new(net_report_addr, reportstate_addr); // Hairpinning works by asking the hairpin actor to send a STUN request to our // discovered public address. If the router returns it hairpinning works. We @@ -223,12 +223,12 @@ mod tests { }; actor.start_check(ipp_v4); - // This bit is our dummy netcheck actor: it handles the inflight request and sends + // This bit is our dummy net_report actor: it handles the inflight request and sends // back the STUN request once it arrives. - let dummy_netcheck = tokio::spawn( + let dummy_net_report = tokio::spawn( async move { - let netcheck::Message::InFlightStun(inflight, resp_tx) = - netcheck_rx.recv().await.unwrap() + let net_report::Message::InFlightStun(inflight, resp_tx) = + net_report_rx.recv().await.unwrap() else { panic!("Wrong message received"); }; @@ -255,7 +255,7 @@ mod tests { tokio::time::sleep(HAIRPIN_CHECK_TIMEOUT * 8).await; } } - .instrument(info_span!("dummy-netcheck")), + .instrument(info_span!("dummy-net_report")), ); // Next we expect our dummy reportstate to receive the result. @@ -265,18 +265,18 @@ mod tests { None => panic!("reportstate mpsc has no senders"), } - // Cleanup: our dummy netcheck actor should finish - dummy_netcheck.await.expect("error in dummy netcheck actor"); + // Cleanup: our dummy net_report actor should finish + dummy_net_report.await.expect("error in dummy net_report actor"); } #[tokio::test] async fn test_client_drop() { let _guard = iroh_test::logging::setup(); - // Setup fake netcheck and reportstate actors, hairpinning interacts with them. - let (netcheck_tx, _netcheck_rx) = mpsc::channel(32); - let netcheck_addr = netcheck::Addr { - sender: netcheck_tx, + // Setup fake net_report and reportstate actors, hairpinning interacts with them. + let (net_report_tx, _net_report_rx) = mpsc::channel(32); + let net_report_addr = net_report::Addr { + sender: net_report_tx, }; let (reportstate_tx, _reportstate_rx) = mpsc::channel(32); let reportstate_addr = reportgen::Addr { @@ -284,7 +284,7 @@ mod tests { }; // Create hairpin actor - let mut client = Client::new(netcheck_addr, reportstate_addr); + let mut client = Client::new(net_report_addr, reportstate_addr); // Save the addr, drop the client let addr = client.addr.take(); diff --git a/iroh-netcheck/src/reportgen/probes.rs b/iroh-netcheck/src/reportgen/probes.rs index 714a7199b4..08bbe1163b 100644 --- a/iroh-netcheck/src/reportgen/probes.rs +++ b/iroh-netcheck/src/reportgen/probes.rs @@ -12,7 +12,7 @@ use tokio::time::Duration; use crate::{RelayMap, RelayNode, RelayUrl, Report}; -/// The retransmit interval used when netcheck first runs. +/// The retransmit interval used when net_report first runs. /// /// We have no past context to work with, and we want answers relatively quickly, so it's /// biased slightly more aggressive than [`DEFAULT_ACTIVE_RETRANSMIT_DELAY`]. A few extra @@ -36,7 +36,7 @@ const DEFAULT_ACTIVE_RETRANSMIT_DELAY: Duration = Duration::from_millis(200); /// time. const ACTIVE_RETRANSMIT_EXTRA_DELAY: Duration = Duration::from_millis(50); -/// The number of fastest relays to periodically re-query during incremental netcheck +/// The number of fastest relays to periodically re-query during incremental net_report /// reports. (During a full report, all relay servers are scanned.) const NUM_INCREMENTAL_RELAYS: usize = 3; @@ -269,7 +269,7 @@ impl ProbePlan { plan } - /// Creates a follow up probe plan using a previous netcheck report. + /// Creates a follow up probe plan using a previous net_report report. pub(super) fn with_last_report( relay_map: &RelayMap, if_state: &interfaces::State, diff --git a/iroh-relay/src/server.rs b/iroh-relay/src/server.rs index bbe16fe090..6f32da2863 100644 --- a/iroh-relay/src/server.rs +++ b/iroh-relay/src/server.rs @@ -12,8 +12,8 @@ //! The relay server hosts the following services: //! //! - HTTPS `/relay`: The main URL endpoint to which clients connect and sends traffic over. -//! - HTTPS `/ping`: Used for netcheck probes. -//! - HTTPS `/generate_204`: Used for netcheck probes. +//! - HTTPS `/ping`: Used for net_report probes. +//! - HTTPS `/generate_204`: Used for net_report probes. //! - STUN: UDP port for STUN requests/responses. use std::{fmt, future::Future, net::SocketAddr, pin::Pin, sync::Arc}; From b81463b4e5d242b5006fa871eb577a39b774bf1e Mon Sep 17 00:00:00 2001 From: Diva M Date: Wed, 20 Nov 2024 11:15:33 -0500 Subject: [PATCH 20/27] include net_check on renaming --- iroh-net/src/magicsock.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/iroh-net/src/magicsock.rs b/iroh-net/src/magicsock.rs index e901433fa4..342c203115 100644 --- a/iroh-net/src/magicsock.rs +++ b/iroh-net/src/magicsock.rs @@ -217,7 +217,7 @@ pub(crate) struct MagicSock { /// UDP IPv6 socket pconn6: Option, /// Netcheck client - net_checker: net_report::Addr, + net_reporter: net_report::Addr, /// The state for an active DiscoKey. disco_secrets: DiscoSecrets, @@ -716,7 +716,7 @@ impl MagicSock { let packet_is_quic = if stun::is(packet) { trace!(src = %meta.addr, len = %meta.stride, "UDP recv: stun packet"); let packet2 = Bytes::copy_from_slice(packet); - self.net_checker.receive_stun_packet(packet2, meta.addr); + self.net_reporter.receive_stun_packet(packet2, meta.addr); false } else if let Some((sender, sealed_box)) = disco::source_and_box(packet) { // Disco? @@ -1405,7 +1405,7 @@ impl Handle { let ipv4_addr = pconn4.local_addr()?; let ipv6_addr = pconn6.as_ref().and_then(|c| c.local_addr().ok()); - let net_checker = net_report::Client::new(Some(port_mapper.clone()), dns_resolver.clone())?; + let net_reporter = net_report::Client::new(Some(port_mapper.clone()), dns_resolver.clone())?; let (actor_sender, actor_receiver) = mpsc::channel(256); let (relay_actor_sender, relay_actor_receiver) = mpsc::channel(256); @@ -1432,7 +1432,7 @@ impl Handle { my_relay: Default::default(), pconn4: pconn4.clone(), pconn6: pconn6.clone(), - net_checker: net_checker.addr(), + net_reporter: net_reporter.addr(), disco_secrets: DiscoSecrets::default(), node_map, relay_actor_sender: relay_actor_sender.clone(), @@ -1483,7 +1483,7 @@ impl Handle { pconn4, pconn6, no_v4_send: false, - net_checker, + net_reporter, network_monitor, }; @@ -1731,7 +1731,7 @@ struct Actor { no_v4_send: bool, /// The prober that discovers local network conditions, including the closest relay relay and NAT mappings. - net_checker: net_report::Client, + net_reporter: net_report::Client, network_monitor: netmon::Monitor, } @@ -2207,7 +2207,7 @@ impl Actor { debug!("requesting net_report report"); match self - .net_checker + .net_reporter .get_report_channel(relay_map, pconn4, pconn6) .await { From 61bcc3805354de4b1aa1732717860262053308a7 Mon Sep 17 00:00:00 2001 From: Diva M Date: Wed, 20 Nov 2024 11:34:30 -0500 Subject: [PATCH 21/27] finish renaming --- .github/workflows/ci.yml | 2 +- .github/workflows/tests.yaml | 2 +- Cargo.lock | 6 +++--- Cargo.toml | 2 +- iroh-cli/Cargo.toml | 2 +- {iroh-netcheck => iroh-net-report}/Cargo.toml | 2 +- {iroh-netcheck => iroh-net-report}/README.md | 6 +++--- {iroh-netcheck => iroh-net-report}/src/defaults.rs | 0 {iroh-netcheck => iroh-net-report}/src/dns.rs | 0 {iroh-netcheck => iroh-net-report}/src/lib.rs | 0 {iroh-netcheck => iroh-net-report}/src/metrics.rs | 0 {iroh-netcheck => iroh-net-report}/src/ping.rs | 0 {iroh-netcheck => iroh-net-report}/src/reportgen.rs | 0 {iroh-netcheck => iroh-net-report}/src/reportgen/hairpin.rs | 0 {iroh-netcheck => iroh-net-report}/src/reportgen/probes.rs | 0 iroh-net/Cargo.toml | 2 +- 16 files changed, 12 insertions(+), 12 deletions(-) rename {iroh-netcheck => iroh-net-report}/Cargo.toml (98%) rename {iroh-netcheck => iroh-net-report}/README.md (92%) rename {iroh-netcheck => iroh-net-report}/src/defaults.rs (100%) rename {iroh-netcheck => iroh-net-report}/src/dns.rs (100%) rename {iroh-netcheck => iroh-net-report}/src/lib.rs (100%) rename {iroh-netcheck => iroh-net-report}/src/metrics.rs (100%) rename {iroh-netcheck => iroh-net-report}/src/ping.rs (100%) rename {iroh-netcheck => iroh-net-report}/src/reportgen.rs (100%) rename {iroh-netcheck => iroh-net-report}/src/reportgen/hairpin.rs (100%) rename {iroh-netcheck => iroh-net-report}/src/reportgen/probes.rs (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95a4e2e553..68d5c72f6a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -190,7 +190,7 @@ jobs: # uses: obi1kenobi/cargo-semver-checks-action@v2 uses: n0-computer/cargo-semver-checks-action@feat-baseline with: - package: iroh, iroh-base, iroh-cli, iroh-dns-server, iroh-metrics, iroh-net, iroh-net-bench, iroh-router, netwatch, portmapper, iroh-relay, net-report + package: iroh, iroh-base, iroh-cli, iroh-dns-server, iroh-metrics, iroh-net, iroh-net-bench, iroh-router, netwatch, portmapper, iroh-relay, iroh-net-report baseline-rev: ${{ env.HEAD_COMMIT_SHA }} use-cache: false diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a271e814c8..dd1a7d0c8e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -23,7 +23,7 @@ env: RUSTFLAGS: -Dwarnings RUSTDOCFLAGS: -Dwarnings SCCACHE_CACHE_SIZE: "50G" - CRATES_LIST: "iroh,iroh-metrics,iroh-net,iroh-net-bench,iroh-test,iroh-cli,iroh-dns-server,iroh-router,netwatch,portmapper,iroh-relay,net-report" + CRATES_LIST: "iroh,iroh-metrics,iroh-net,iroh-net-bench,iroh-test,iroh-cli,iroh-dns-server,iroh-router,netwatch,portmapper,iroh-relay,iroh-net-report" IROH_FORCE_STAGING_RELAYS: "1" jobs: diff --git a/Cargo.lock b/Cargo.lock index c33cd92d63..8780141c82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2783,7 +2783,7 @@ dependencies = [ "iroh-docs", "iroh-gossip", "iroh-metrics", - "iroh-netcheck", + "iroh-net-report", "nix 0.27.1", "parking_lot", "pkarr", @@ -3016,7 +3016,7 @@ dependencies = [ "iroh-base", "iroh-metrics", "iroh-net", - "iroh-netcheck", + "iroh-net-report", "iroh-quinn", "iroh-quinn-proto", "iroh-quinn-udp", @@ -3096,7 +3096,7 @@ dependencies = [ ] [[package]] -name = "iroh-netcheck" +name = "iroh-net-report" version = "0.28.0" dependencies = [ "anyhow", diff --git a/Cargo.toml b/Cargo.toml index f6c43367cf..e569b88174 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ members = [ "iroh-router", "net-tools/netwatch", "net-tools/portmapper", - "iroh-netcheck", + "iroh-net-report", ] resolver = "2" diff --git a/iroh-cli/Cargo.toml b/iroh-cli/Cargo.toml index 2dc1617986..823be3df66 100644 --- a/iroh-cli/Cargo.toml +++ b/iroh-cli/Cargo.toml @@ -45,7 +45,7 @@ iroh-blobs = { version = "0.28.1", features = ["cli"] } iroh-docs = { version = "0.28.0", features = ["cli"] } iroh-gossip = { version = "0.28.1", features = ["cli"] } iroh-metrics = { version = "0.28.0" } -netcheck = { package = "iroh-netcheck", path = "../iroh-netcheck", version = "0.28" } +net-report = { package = "iroh-net-report", path = "../iroh-net-report", version = "0.28" } parking_lot = "0.12.1" pkarr = { version = "2.2.0", default-features = false } portable-atomic = "1" diff --git a/iroh-netcheck/Cargo.toml b/iroh-net-report/Cargo.toml similarity index 98% rename from iroh-netcheck/Cargo.toml rename to iroh-net-report/Cargo.toml index 9d998ac2c3..d7367a8a97 100644 --- a/iroh-netcheck/Cargo.toml +++ b/iroh-net-report/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "iroh-netcheck" +name = "iroh-net-report" version = "0.28.0" edition = "2021" readme = "README.md" diff --git a/iroh-netcheck/README.md b/iroh-net-report/README.md similarity index 92% rename from iroh-netcheck/README.md rename to iroh-net-report/README.md index 332daa93c1..c6ea20383a 100644 --- a/iroh-netcheck/README.md +++ b/iroh-net-report/README.md @@ -1,8 +1,8 @@ -# Iroh Netcheck +# Iroh Net Report -`iroh-netcheck` is a tool for generating detailed reports on network +`iroh-net-report` is a tool for generating detailed reports on network connectivity and configuration on the current host for nodes powered by [iroh]. -`iroh-netcheck` evaluates key aspects of network performance and behavior, +`iroh-net-report` evaluates key aspects of network performance and behavior, including NAT traversal capabilities, protocol availability, and relay server latencies. Key features include: diff --git a/iroh-netcheck/src/defaults.rs b/iroh-net-report/src/defaults.rs similarity index 100% rename from iroh-netcheck/src/defaults.rs rename to iroh-net-report/src/defaults.rs diff --git a/iroh-netcheck/src/dns.rs b/iroh-net-report/src/dns.rs similarity index 100% rename from iroh-netcheck/src/dns.rs rename to iroh-net-report/src/dns.rs diff --git a/iroh-netcheck/src/lib.rs b/iroh-net-report/src/lib.rs similarity index 100% rename from iroh-netcheck/src/lib.rs rename to iroh-net-report/src/lib.rs diff --git a/iroh-netcheck/src/metrics.rs b/iroh-net-report/src/metrics.rs similarity index 100% rename from iroh-netcheck/src/metrics.rs rename to iroh-net-report/src/metrics.rs diff --git a/iroh-netcheck/src/ping.rs b/iroh-net-report/src/ping.rs similarity index 100% rename from iroh-netcheck/src/ping.rs rename to iroh-net-report/src/ping.rs diff --git a/iroh-netcheck/src/reportgen.rs b/iroh-net-report/src/reportgen.rs similarity index 100% rename from iroh-netcheck/src/reportgen.rs rename to iroh-net-report/src/reportgen.rs diff --git a/iroh-netcheck/src/reportgen/hairpin.rs b/iroh-net-report/src/reportgen/hairpin.rs similarity index 100% rename from iroh-netcheck/src/reportgen/hairpin.rs rename to iroh-net-report/src/reportgen/hairpin.rs diff --git a/iroh-netcheck/src/reportgen/probes.rs b/iroh-net-report/src/reportgen/probes.rs similarity index 100% rename from iroh-netcheck/src/reportgen/probes.rs rename to iroh-net-report/src/reportgen/probes.rs diff --git a/iroh-net/Cargo.toml b/iroh-net/Cargo.toml index cf6af38f60..d84d95e754 100644 --- a/iroh-net/Cargo.toml +++ b/iroh-net/Cargo.toml @@ -114,7 +114,7 @@ webpki = { package = "rustls-webpki", version = "0.102" } webpki-roots = "0.26" x509-parser = "0.16" z32 = "1.0.3" -netcheck = { package = "iroh-netcheck", path = "../iroh-netcheck", version = "0.28" } +net-report = { package = "iroh-net-report", path = "../iroh-net-report", version = "0.28" } # metrics iroh-metrics = { version = "0.28.0", default-features = false } From 8017587176dd965b6549cdc4ea14aad095638ad1 Mon Sep 17 00:00:00 2001 From: Diva M Date: Wed, 20 Nov 2024 11:41:09 -0500 Subject: [PATCH 22/27] make fmt --- iroh-net-report/src/lib.rs | 5 +++-- iroh-net-report/src/metrics.rs | 4 +++- iroh-net-report/src/reportgen/hairpin.rs | 4 +++- iroh-net/src/magicsock.rs | 8 ++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/iroh-net-report/src/lib.rs b/iroh-net-report/src/lib.rs index f21c2d6ca3..b496922c6b 100644 --- a/iroh-net-report/src/lib.rs +++ b/iroh-net-report/src/lib.rs @@ -211,8 +211,9 @@ impl Client { pub fn new(port_mapper: Option, dns_resolver: DnsResolver) -> Result { let mut actor = Actor::new(port_mapper, dns_resolver)?; let addr = actor.addr(); - let task = - tokio::spawn(async move { actor.run().await }.instrument(info_span!("net_report.actor"))); + let task = tokio::spawn( + async move { actor.run().await }.instrument(info_span!("net_report.actor")), + ); let drop_guard = AbortOnDropHandle::new(task); Ok(Client { addr, diff --git a/iroh-net-report/src/metrics.rs b/iroh-net-report/src/metrics.rs index 331d9284a2..e68daff12e 100644 --- a/iroh-net-report/src/metrics.rs +++ b/iroh-net-report/src/metrics.rs @@ -26,7 +26,9 @@ impl Default for Metrics { stun_packets_sent_ipv6: Counter::new("Number of IPv6 STUN packets sent"), stun_packets_recv_ipv4: Counter::new("Number of IPv4 STUN packets received"), stun_packets_recv_ipv6: Counter::new("Number of IPv6 STUN packets received"), - reports: Counter::new("Number of reports executed by net_report, including full reports"), + reports: Counter::new( + "Number of reports executed by net_report, including full reports", + ), reports_full: Counter::new("Number of full reports executed by net_report"), } } diff --git a/iroh-net-report/src/reportgen/hairpin.rs b/iroh-net-report/src/reportgen/hairpin.rs index 9c7d6d5999..9b50e29879 100644 --- a/iroh-net-report/src/reportgen/hairpin.rs +++ b/iroh-net-report/src/reportgen/hairpin.rs @@ -266,7 +266,9 @@ mod tests { } // Cleanup: our dummy net_report actor should finish - dummy_net_report.await.expect("error in dummy net_report actor"); + dummy_net_report + .await + .expect("error in dummy net_report actor"); } #[tokio::test] diff --git a/iroh-net/src/magicsock.rs b/iroh-net/src/magicsock.rs index 342c203115..2676bd7949 100644 --- a/iroh-net/src/magicsock.rs +++ b/iroh-net/src/magicsock.rs @@ -1405,7 +1405,8 @@ impl Handle { let ipv4_addr = pconn4.local_addr()?; let ipv6_addr = pconn6.as_ref().and_then(|c| c.local_addr().ok()); - let net_reporter = net_report::Client::new(Some(port_mapper.clone()), dns_resolver.clone())?; + let net_reporter = + net_report::Client::new(Some(port_mapper.clone()), dns_resolver.clone())?; let (actor_sender, actor_receiver) = mpsc::channel(256); let (relay_actor_sender, relay_actor_receiver) = mpsc::channel(256); @@ -1925,7 +1926,10 @@ impl Actor { self.handle_net_report_report(report).await; } Err(err) => { - warn!("failed to generate net_report report for: {}: {:?}", why, err); + warn!( + "failed to generate net_report report for: {}: {:?}", + why, err + ); } } self.finalize_direct_addrs_update(why); From 5d34415e3efbf41db3f1af1d8fe587787e29df04 Mon Sep 17 00:00:00 2001 From: Diva M Date: Wed, 20 Nov 2024 11:51:50 -0500 Subject: [PATCH 23/27] address TODO missed before --- iroh-net-report/src/dns.rs | 50 ++++++++++++-------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/iroh-net-report/src/dns.rs b/iroh-net-report/src/dns.rs index 4cdb47c1a7..17ac6855da 100644 --- a/iroh-net-report/src/dns.rs +++ b/iroh-net-report/src/dns.rs @@ -7,34 +7,34 @@ use hickory_resolver::{IntoName, TokioAsyncResolver}; use crate::defaults::timeouts::DNS_TIMEOUT; /// Delay used to perform staggered dns queries. -const DNS_STAGGERING_MS: &[u64] = &[200, 300]; +pub(crate) const DNS_STAGGERING_MS: &[u64] = &[200, 300]; /// Extension trait to [`TokioAsyncResolver`]. pub(crate) trait ResolverExt { - /// Perform an ipv4 lookup with a timeout. + /// Perform an ipv4 lookup. fn lookup_ipv4( &self, host: N, ) -> impl Future>>; - /// Perform an ipv6 lookup with a timeout. + /// Perform an ipv6 lookup. fn lookup_ipv6( &self, host: N, ) -> impl Future>>; - /// Race an ipv4 and ipv6 lookup with a timeout. + /// Race an ipv4 and ipv6. fn lookup_ipv4_ipv6( &self, host: N, ) -> impl Future>>; - /// Perform an ipv4 lookup with a timeout in a staggered fashion. + /// Perform an ipv4 lookup in a staggered fashion. /// /// From the moment this function is called, each lookup is scheduled after the delays in - /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls - /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. The - /// result of the first successful call is returned, or a summary of all errors otherwise. + /// [`DNS_STAGGERING_MS`] with the first call being done immediately. `[200ms, 300ms]` results + /// in calls at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. + /// The result of the first successful call is returned, or a summary of all errors otherwise. fn lookup_ipv4_staggered( &self, host: N, @@ -43,22 +43,21 @@ pub(crate) trait ResolverExt { /// Perform an ipv6 lookup with a timeout in a staggered fashion. /// /// From the moment this function is called, each lookup is scheduled after the delays in - /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls - /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. The - /// result of the first successful call is returned, or a summary of all errors otherwise. + /// [`DNS_STAGGERING_MS`] with the first call being done immediately. `[200ms, 300ms]` results + /// in calls at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. + /// The result of the first successful call is returned, or a summary of all errors otherwise. fn lookup_ipv6_staggered( &self, host: N, ) -> impl Future>>; - /// Race an ipv4 and ipv6 lookup with a timeout in a staggered fashion. + /// Race an ipv4 and ipv6 lookup in a staggered fashion. /// /// From the moment this function is called, each lookup is scheduled after the delays in - /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls - /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied as stated in + /// [`DNS_STAGGERING_MS`] with the first call being done immediately. `[200ms, 300ms]` results + /// in calls at T+0ms, T+200ms and T+300ms. The [`DNS_TIMEOUT`] is applied as stated in /// [`Self::lookup_ipv4_ipv6`]. The result of the first successful call is returned, or a /// summary of all errors otherwise. - // TODO(@divma): adjust docs fn lookup_ipv4_ipv6_staggered( &self, host: N, @@ -81,6 +80,8 @@ impl ResolverExt for TokioAsyncResolver { /// `LookupIpStrategy::Ipv4AndIpv6` will wait for ipv6 resolution timeout, even if it is /// not usable on the stack, so we manually query both lookups concurrently and time them out /// individually. + /// + /// See [`ResolverExt::lookup_ipv4_ipv6`]. async fn lookup_ipv4_ipv6( &self, host: N, @@ -97,12 +98,6 @@ impl ResolverExt for TokioAsyncResolver { } } - /// Perform an ipv4 lookup with a timeout in a staggered fashion. - /// - /// From the moment this function is called, each lookup is scheduled after the delays in - /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls - /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. The - /// result of the first successful call is returned, or a summary of all errors otherwise. async fn lookup_ipv4_staggered( &self, host: N, @@ -111,12 +106,6 @@ impl ResolverExt for TokioAsyncResolver { stagger_call(f, DNS_STAGGERING_MS).await } - /// Perform an ipv6 lookup with a timeout in a staggered fashion. - /// - /// From the moment this function is called, each lookup is scheduled after the delays in - /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls - /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. The - /// result of the first successful call is returned, or a summary of all errors otherwise. async fn lookup_ipv6_staggered( &self, host: N, @@ -125,13 +114,6 @@ impl ResolverExt for TokioAsyncResolver { stagger_call(f, DNS_STAGGERING_MS).await } - /// Race an ipv4 and ipv6 lookup with a timeout in a staggered fashion. - /// - /// From the moment this function is called, each lookup is scheduled after the delays in - /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls - /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied as stated in - /// [`Self::lookup_ipv4_ipv6`]. The result of the first successful call is returned, or a - /// summary of all errors otherwise. async fn lookup_ipv4_ipv6_staggered( &self, host: N, From 0ae2f48c8995474a6179d58f7934b7c5fb71e7b5 Mon Sep 17 00:00:00 2001 From: Diva M Date: Wed, 20 Nov 2024 12:01:06 -0500 Subject: [PATCH 24/27] revert a change, double down in another --- iroh-net-report/src/lib.rs | 2 +- iroh-net-report/src/reportgen/hairpin.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iroh-net-report/src/lib.rs b/iroh-net-report/src/lib.rs index b496922c6b..54602972d7 100644 --- a/iroh-net-report/src/lib.rs +++ b/iroh-net-report/src/lib.rs @@ -3,7 +3,7 @@ //! Netcheck is responsible for finding out the network conditions of the current host, like //! whether it is connected to the internet via IPv4 and/or IPv6, what the NAT situation is //! etc and reachability to the configured relays. -// Based on +// Based on use std::{ collections::{BTreeMap, HashMap}, diff --git a/iroh-net-report/src/reportgen/hairpin.rs b/iroh-net-report/src/reportgen/hairpin.rs index 9b50e29879..dc730a7c9a 100644 --- a/iroh-net-report/src/reportgen/hairpin.rs +++ b/iroh-net-report/src/reportgen/hairpin.rs @@ -163,7 +163,7 @@ impl Actor { socket .send_to( - b"tailscale net_report; see https://github.com/tailscale/tailscale/issues/188", + b"net_report; see https://github.com/tailscale/tailscale/issues/188", documentation_ip, ) .await?; From 38eecd51b057f6cc98563d2e5f2e6ef2cdaa6497 Mon Sep 17 00:00:00 2001 From: Diva M Date: Wed, 20 Nov 2024 12:27:23 -0500 Subject: [PATCH 25/27] add license files --- iroh-net-report/LICENSE-BSD3 | 30 ++++++++++++++++++++++++++++++ iroh-net/LICENSE-BSD3 | 7 +------ iroh-relay/LICENSE-BSD3 | 30 ++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 iroh-net-report/LICENSE-BSD3 create mode 100644 iroh-relay/LICENSE-BSD3 diff --git a/iroh-net-report/LICENSE-BSD3 b/iroh-net-report/LICENSE-BSD3 new file mode 100644 index 0000000000..94d6e6abce --- /dev/null +++ b/iroh-net-report/LICENSE-BSD3 @@ -0,0 +1,30 @@ +Parts of the code has been derived from tailscale, which is under the following license. + +BSD 3-Clause License + +Copyright (c) 2020 Tailscale Inc & AUTHORS. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/iroh-net/LICENSE-BSD3 b/iroh-net/LICENSE-BSD3 index 4b02691c20..c893b731d3 100644 --- a/iroh-net/LICENSE-BSD3 +++ b/iroh-net/LICENSE-BSD3 @@ -1,12 +1,7 @@ Parts of the code has been derived from tailscale, which is under the following license. Specifically the following files are most relevant -- ./src/derp** - ./src/magicsock** -- ./src/netcheck** -- ./src/disco.rs -- ./src/stun.rs - BSD 3-Clause License @@ -35,4 +30,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/iroh-relay/LICENSE-BSD3 b/iroh-relay/LICENSE-BSD3 new file mode 100644 index 0000000000..94d6e6abce --- /dev/null +++ b/iroh-relay/LICENSE-BSD3 @@ -0,0 +1,30 @@ +Parts of the code has been derived from tailscale, which is under the following license. + +BSD 3-Clause License + +Copyright (c) 2020 Tailscale Inc & AUTHORS. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From a9520a8a3795a0ad530b9a332b7b48827661b21e Mon Sep 17 00:00:00 2001 From: Diva M Date: Wed, 20 Nov 2024 13:25:59 -0500 Subject: [PATCH 26/27] NetReport --- iroh-net-report/src/lib.rs | 2 +- iroh-net/bench/src/bin/bulk.rs | 6 +++--- iroh-net/src/magicsock.rs | 12 ++++++------ iroh-net/src/metrics.rs | 2 +- iroh/src/metrics.rs | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/iroh-net-report/src/lib.rs b/iroh-net-report/src/lib.rs index 54602972d7..cd094cbbd6 100644 --- a/iroh-net-report/src/lib.rs +++ b/iroh-net-report/src/lib.rs @@ -1,6 +1,6 @@ //! Checks the network conditions from the current host. //! -//! Netcheck is responsible for finding out the network conditions of the current host, like +//! NetReport is responsible for finding out the network conditions of the current host, like //! whether it is connected to the internet via IPv4 and/or IPv6, what the NAT situation is //! etc and reachability to the configured relays. // Based on diff --git a/iroh-net/bench/src/bin/bulk.rs b/iroh-net/bench/src/bin/bulk.rs index e5280198b2..83f039439d 100644 --- a/iroh-net/bench/src/bin/bulk.rs +++ b/iroh-net/bench/src/bin/bulk.rs @@ -36,7 +36,7 @@ pub fn run_iroh(opt: Opt) -> Result<()> { iroh_metrics::core::Core::try_init(|reg, metrics| { use iroh_metrics::core::Metric; metrics.insert(iroh_net::metrics::MagicsockMetrics::new(reg)); - metrics.insert(iroh_net::metrics::NetcheckMetrics::new(reg)); + metrics.insert(iroh_net::metrics::NetReportMetrics::new(reg)); metrics.insert(iroh_net::metrics::PortmapMetrics::new(reg)); #[cfg(feature = "local-relay")] if opt.with_relay { @@ -113,8 +113,8 @@ pub fn run_iroh(opt: Opt) -> Result<()> { core.get_collector::(), ); collect_and_print( - "NetcheckMetrics", - core.get_collector::(), + "NetReportMetrics", + core.get_collector::(), ); collect_and_print( "PortmapMetrics", diff --git a/iroh-net/src/magicsock.rs b/iroh-net/src/magicsock.rs index 2676bd7949..3cca260dc7 100644 --- a/iroh-net/src/magicsock.rs +++ b/iroh-net/src/magicsock.rs @@ -216,7 +216,7 @@ pub(crate) struct MagicSock { pconn4: UdpConn, /// UDP IPv6 socket pconn6: Option, - /// Netcheck client + /// NetReport client net_reporter: net_report::Addr, /// The state for an active DiscoKey. disco_secrets: DiscoSecrets, @@ -1700,7 +1700,7 @@ enum ActorMessage { Shutdown, ReceiveRelay(RelayReadResult), EndpointPingExpired(usize, stun_rs::TransactionId), - NetcheckReport(Result>>, &'static str), + NetReport(Result>>, &'static str), NetworkChange, #[cfg(test)] ForceNetworkChange(bool), @@ -1920,7 +1920,7 @@ impl Actor { ActorMessage::EndpointPingExpired(id, txid) => { self.msock.node_map.notify_ping_timeout(id, txid); } - ActorMessage::NetcheckReport(report, why) => { + ActorMessage::NetReport(report, why) => { match report { Ok(report) => { self.handle_net_report_report(report).await; @@ -2199,7 +2199,7 @@ impl Actor { if self.msock.relay_map.is_empty() { debug!("skipping net_report, empty RelayMap"); self.msg_sender - .send(ActorMessage::NetcheckReport(Ok(None), why)) + .send(ActorMessage::NetReport(Ok(None), why)) .await .ok(); return; @@ -2226,10 +2226,10 @@ impl Actor { Err(err) => Err(anyhow!("net_report report timeout: {:?}", err)), }; msg_sender - .send(ActorMessage::NetcheckReport(report, why)) + .send(ActorMessage::NetReport(report, why)) .await .ok(); - // The receiver of the NetcheckReport message will call + // The receiver of the NetReport message will call // .finalize_direct_addrs_update(). }); } diff --git a/iroh-net/src/metrics.rs b/iroh-net/src/metrics.rs index ef4e40fcd4..e168a56a7a 100644 --- a/iroh-net/src/metrics.rs +++ b/iroh-net/src/metrics.rs @@ -2,7 +2,7 @@ #[cfg(feature = "test-utils")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "test-utils")))] pub use iroh_relay::server::Metrics as RelayMetrics; -pub use net_report::Metrics as NetcheckMetrics; +pub use net_report::Metrics as NetReportMetrics; pub use portmapper::Metrics as PortmapMetrics; pub use crate::magicsock::Metrics as MagicsockMetrics; diff --git a/iroh/src/metrics.rs b/iroh/src/metrics.rs index e2db02c57e..33f7551f81 100644 --- a/iroh/src/metrics.rs +++ b/iroh/src/metrics.rs @@ -71,7 +71,7 @@ pub fn try_init_metrics_collection() -> std::io::Result<()> { metrics.insert(crate::metrics::Metrics::new(reg)); metrics.insert(iroh_docs::metrics::Metrics::new(reg)); metrics.insert(iroh_net::metrics::MagicsockMetrics::new(reg)); - metrics.insert(iroh_net::metrics::NetcheckMetrics::new(reg)); + metrics.insert(iroh_net::metrics::NetReportMetrics::new(reg)); metrics.insert(iroh_net::metrics::PortmapMetrics::new(reg)); }) } @@ -92,7 +92,7 @@ pub fn get_metrics() -> anyhow::Result> { &mut map, ); collect( - core.get_collector::(), + core.get_collector::(), &mut map, ); collect( From be83843a68fc4442b77848e7bcdeb27a3ef34864 Mon Sep 17 00:00:00 2001 From: Diva M Date: Thu, 21 Nov 2024 12:42:33 -0500 Subject: [PATCH 27/27] rename const --- iroh-net/src/defaults.rs | 4 ++-- iroh-net/src/magicsock.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iroh-net/src/defaults.rs b/iroh-net/src/defaults.rs index 791f569d1a..799dc078f3 100644 --- a/iroh-net/src/defaults.rs +++ b/iroh-net/src/defaults.rs @@ -132,6 +132,6 @@ pub(crate) mod timeouts { // Timeouts for net_report - /// Maximum duration to wait for a net_report report. - pub(crate) const NETCHECK_REPORT_TIMEOUT: Duration = Duration::from_secs(10); + /// Maximum duration to wait for a net_report. + pub(crate) const NET_REPORT_TIMEOUT: Duration = Duration::from_secs(10); } diff --git a/iroh-net/src/magicsock.rs b/iroh-net/src/magicsock.rs index 3cca260dc7..f4870f8377 100644 --- a/iroh-net/src/magicsock.rs +++ b/iroh-net/src/magicsock.rs @@ -60,7 +60,7 @@ use self::{ udp_conn::UdpConn, }; use crate::{ - defaults::timeouts::NETCHECK_REPORT_TIMEOUT, + defaults::timeouts::NET_REPORT_TIMEOUT, disco::{self, CallMeMaybe, SendAddr}, discovery::{Discovery, DiscoveryItem}, dns::DnsResolver, @@ -2218,7 +2218,7 @@ impl Actor { Ok(rx) => { let msg_sender = self.msg_sender.clone(); tokio::task::spawn(async move { - let report = time::timeout(NETCHECK_REPORT_TIMEOUT, rx).await; + let report = time::timeout(NET_REPORT_TIMEOUT, rx).await; let report: anyhow::Result<_> = match report { Ok(Ok(Ok(report))) => Ok(Some(report)), Ok(Ok(Err(err))) => Err(err),