diff --git a/.dockerignore b/.dockerignore index 473661b..ff2bb43 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,9 @@ -.config* +**/.config* **/.idea **/.vscode github.env Taskfile.yaml +# Rust +target +vdf/generated diff --git a/.gitignore b/.gitignore index 2768a9c..8b8f9ff 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ ceremony-client .env.signers .task node-tmp-* +build + +# Rust +target diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..3282e86 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,39 @@ +# Contributing + +## Testing + +Testing the [`vdf`](./vdf) and [`node`](./node) packages requires linking the +[native VDF](./crates/vdf). The `test.sh` scripts in the respective directories +help with this. + +## Pull Requests + +Contributions are welcome – a new network is rife with opportunities. We are +in the process of updating our JIRA board so that it can be made public. The +repository has basic coding guidelines: + +- 80 character line limit, with the exception where gofmt or the syntax is + impossible to achieve otherwise +- Error wrapping matching function names +- Interface composition and dependency injection with Wire + +## Building release binaries + +The following software is required to build release binaries (assuming MacOS +ARM): + +- [Running from source](README.md#running-from-source) dependencies +- Docker +- [Taskfile](https://taskfile.dev/) + +Then from the repo root use the following commands to build the release binaries +that statically link the [native VDF](./crates/vdf) for the supported platforms: + +```shell +task build_node_arm64_macos +task build_node_arm64_linux +task build_node_amd64_linux +``` + +The output binaries will be in `node/build`. + diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..eee764f --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1201 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + +[[package]] +name = "askama" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b79091df18a97caea757e28cd2d5fda49c6cd4bd01ddffd7ff01ace0c0ad2c28" +dependencies = [ + "askama_derive", + "askama_escape", +] + +[[package]] +name = "askama_derive" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19fe8d6cb13c4714962c072ea496f3392015f0989b1a2847bb4b2d9effd71d83" +dependencies = [ + "askama_parser", + "basic-toml", + "mime", + "mime_guess", + "proc-macro2", + "quote", + "serde", + "syn", +] + +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + +[[package]] +name = "askama_parser" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acb1161c6b64d1c3d83108213c2a2533a342ac225aabd0bda218278c2ddb00c0" +dependencies = [ + "nom", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "basic-toml" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "823388e228f614e9558c6804262db37960ec8821856535f5c3f59913140558f8" +dependencies = [ + "serde", +] + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bit-vec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f59bbe95d4e52a6398ec21238d31577f2b28a9d86807f06ca59d191d8440d0bb" + +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "camino" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0ec6b951b160caa93cc0c7b209e5a3bff7aae9062213451ac99493cd844c239" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24b1f0365a6c6bb4020cd05806fd0d33c44d38046b8bd7f0e40814b9763cabfc" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ciborium" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" + +[[package]] +name = "ciborium-ll" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" +dependencies = [ + "ciborium-io", + "half", +] + +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "classgroup" +version = "0.1.0" +dependencies = [ + "criterion", + "libc", + "num-traits", +] + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "criterion" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "is-terminal", + "itertools", + "num-traits", + "once_cell", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "either" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "fs-err" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88a41f105fe1d5b6b34b2055e3dc59bb79b46b48b2040b9e6c7b4b5de097aa41" +dependencies = [ + "autocfg", +] + +[[package]] +name = "generic-array" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +dependencies = [ + "typenum", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "goblin" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6b4de4a8eb6c46a8c77e1d3be942cb9a8bf073c22374578e5ba4b08ed0ff68" +dependencies = [ + "log", + "plain", + "scroll", +] + +[[package]] +name = "half" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +dependencies = [ + "cfg-if", + "crunchy", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" + +[[package]] +name = "is-terminal" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "oneshot-uniffi" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c548d5c78976f6955d72d0ced18c48ca07030f7a1d4024529fedd7c1c01b29c" + +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + +[[package]] +name = "plotters" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15b6eccb8484002195a3e44fe65a4ce8e93a625797a063735536fd59cb01cf3" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "414cec62c6634ae900ea1c56128dfe87cf63e7caece0852ec76aba307cebadb7" + +[[package]] +name = "plotters-svg" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81b30686a7d9c3e010b84284bdd26a29f2138574f52f5eb6f794fc0ad924e705" +dependencies = [ + "plotters-backend", +] + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scroll" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04c565b551bafbef4157586fa379538366e4385d42082f255bfd96e4fe8519da" +dependencies = [ + "scroll_derive", +] + +[[package]] +name = "scroll_derive" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1db149f81d46d2deba7cd3c50772474707729550221e69588478ebf9ada425ae" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +dependencies = [ + "serde", +] + +[[package]] +name = "serde" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" +dependencies = [ + "block-buffer", + "digest", + "fake-simd", + "opaque-debug", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "uniffi" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21345172d31092fd48c47fd56c53d4ae9e41c4b1f559fb8c38c1ab1685fd919f" +dependencies = [ + "anyhow", + "camino", + "clap", + "uniffi_bindgen", + "uniffi_build", + "uniffi_core", + "uniffi_macros", +] + +[[package]] +name = "uniffi_bindgen" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd992f2929a053829d5875af1eff2ee3d7a7001cb3b9a46cc7895f2caede6940" +dependencies = [ + "anyhow", + "askama", + "camino", + "cargo_metadata", + "clap", + "fs-err", + "glob", + "goblin", + "heck 0.4.1", + "once_cell", + "paste", + "serde", + "toml", + "uniffi_meta", + "uniffi_testing", + "uniffi_udl", +] + +[[package]] +name = "uniffi_build" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "001964dd3682d600084b3aaf75acf9c3426699bc27b65e96bb32d175a31c74e9" +dependencies = [ + "anyhow", + "camino", + "uniffi_bindgen", +] + +[[package]] +name = "uniffi_checksum_derive" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55137c122f712d9330fd985d66fa61bdc381752e89c35708c13ce63049a3002c" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "uniffi_core" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6121a127a3af1665cd90d12dd2b3683c2643c5103281d0fed5838324ca1fad5b" +dependencies = [ + "anyhow", + "bytes", + "camino", + "log", + "once_cell", + "oneshot-uniffi", + "paste", + "static_assertions", +] + +[[package]] +name = "uniffi_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11cf7a58f101fcedafa5b77ea037999b88748607f0ef3a33eaa0efc5392e92e4" +dependencies = [ + "bincode", + "camino", + "fs-err", + "once_cell", + "proc-macro2", + "quote", + "serde", + "syn", + "toml", + "uniffi_build", + "uniffi_meta", +] + +[[package]] +name = "uniffi_meta" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71dc8573a7b1ac4b71643d6da34888273ebfc03440c525121f1b3634ad3417a2" +dependencies = [ + "anyhow", + "bytes", + "siphasher", + "uniffi_checksum_derive", +] + +[[package]] +name = "uniffi_testing" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "118448debffcb676ddbe8c5305fb933ab7e0123753e659a71dc4a693f8d9f23c" +dependencies = [ + "anyhow", + "camino", + "cargo_metadata", + "fs-err", + "once_cell", +] + +[[package]] +name = "uniffi_udl" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "889edb7109c6078abe0e53e9b4070cf74a6b3468d141bdf5ef1bd4d1dc24a1c3" +dependencies = [ + "anyhow", + "uniffi_meta", + "uniffi_testing", + "weedle2", +] + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "vdf" +version = "0.1.0" +dependencies = [ + "bit-vec", + "classgroup", + "criterion", + "hex", + "num-traits", + "sha2", + "uniffi", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "weedle2" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e79c5206e1f43a2306fd64bdb95025ee4228960f2e6c5a8b173f3caaf807741" +dependencies = [ + "nom", +] + +[[package]] +name = "winapi-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..229c039 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,25 @@ +# Copyright 2018 Chia Network Inc and POA Networks Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# and limitations under the License. +[workspace] +members = [ + "crates/vdf", + "crates/classgroup", +] + +[profile.release] +# rpath = false is important to make Go bindings work +rpath = false +lto = true +debug = false +# panic = 'abort' diff --git a/DOCKER-README.md b/DOCKER-README.md index af2159d..457ff76 100644 --- a/DOCKER-README.md +++ b/DOCKER-README.md @@ -6,9 +6,9 @@ The only requirements are `git` (to checkout the repository) and docker (to buil Golang does not have to be installed, the docker image build process uses a build stage that provides the correct Go environment and compiles the node down to one command. -In the repository root folder, where the [Dockerfile](Dockerfile) file is, build the docker image: +In the repository root folder, where the [Dockerfile.source](Dockerfile.source) file is, build the docker image: ```shell -docker build --build-arg GIT_COMMIT=$(git log -1 --format=%h) -t quilibrium -t quilibrium:1.4.16 . +docker build -f Dockerfile.source --build-arg GIT_COMMIT=$(git log -1 --format=%h) -t quilibrium -t quilibrium:1.4.16 . ``` Use latest version instead of `1.4.16`. diff --git a/Dockerfile b/Dockerfile.release similarity index 60% rename from Dockerfile rename to Dockerfile.release index 42fa039..f6f3b2e 100644 --- a/Dockerfile +++ b/Dockerfile.release @@ -1,20 +1,28 @@ FROM golang:1.20.14-alpine3.19 as build +ARG NODE_VERSION +ARG MAX_KEY_ID + ENV GOEXPERIMENT=arenas WORKDIR /opt/ceremonyclient COPY . . -WORKDIR /opt/ceremonyclient/node - -RUN go install ./... -RUN go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest +RUN cp "node/node-${NODE_VERSION}-linux-amd64" "node/node" +RUN cp "node/node-${NODE_VERSION}-linux-amd64.dgst" "node/node.dgst" +RUN for i in $(seq 1 ${MAX_KEY_ID}); do \ + if [ -f node/node-${NODE_VERSION}-linux-amd64.dgst.sig.${i} ]; then \ + cp "node/node-${NODE_VERSION}-linux-amd64.dgst.sig.${i}" "node/node.dgst.sig.${i}"; \ + fi \ + done WORKDIR /opt/ceremonyclient/client RUN go build -o qclient ./main.go +RUN go install github.com/fullstorydev/grpcurl/cmd/grpcurl@v1.9.1 + FROM alpine:3.19 ARG NODE_VERSION @@ -34,10 +42,14 @@ LABEL org.opencontainers.image.source=$GIT_REPO LABEL org.opencontainers.image.ref.name=$GIT_BRANCH LABEL org.opencontainers.image.revision=$GIT_COMMIT -COPY --from=build /go/bin/node /usr/local/bin -COPY --from=build /go/bin/grpcurl /usr/local/bin +COPY --from=build /opt/ceremonyclient/node/node /usr/local/bin +COPY --from=build /opt/ceremonyclient/node/node.dgst /usr/local/bin +COPY --from=build /opt/ceremonyclient/node/node.dgst.sig.* /usr/local/bin + COPY --from=build /opt/ceremonyclient/client/qclient /usr/local/bin +COPY --from=build /go/bin/grpcurl /usr/local/bin + WORKDIR /root ENTRYPOINT ["node"] diff --git a/Dockerfile.source b/Dockerfile.source new file mode 100644 index 0000000..d4c9b72 --- /dev/null +++ b/Dockerfile.source @@ -0,0 +1,71 @@ +FROM golang:1.22.4-bullseye as build-base + +ENV PATH="${PATH}:/root/.cargo/bin/" + +# Install GMP 6.2 (6.3 which MacOS is using only available on Debian unstable) +RUN apt-get update && apt-get install -y \ + libgmp-dev \ + && rm -rf /var/lib/apt/lists/* + +COPY docker/rustup-init.sh /opt/rustup-init.sh + +RUN /opt/rustup-init.sh -y --profile minimal + +# Install uniffi-bindgen-go +RUN cargo install uniffi-bindgen-go --git https://github.com/NordSecurity/uniffi-bindgen-go --tag v0.2.1+v0.25.0 + +FROM build-base as build + +ENV GOEXPERIMENT=arenas +ENV QUILIBRIUM_SIGNATURE_CHECK=false + +WORKDIR /opt/ceremonyclient + +COPY . . + +## Generate Rust bindings for VDF +WORKDIR /opt/ceremonyclient/vdf +RUN ./generate.sh + +# Build and install the node +WORKDIR /opt/ceremonyclient/node + +RUN ./build.sh && cp node /go/bin +RUN go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest + +# Build and install qclient +WORKDIR /opt/ceremonyclient/client + +RUN go build -o qclient ./main.go + +# Allows exporting single binary +FROM scratch AS node +COPY --from=build /go/bin/node /node +ENTRYPOINT [ "/node" ] + +FROM debian:bullseye + +ARG NODE_VERSION +ARG GIT_REPO +ARG GIT_BRANCH +ARG GIT_COMMIT + +ENV GOEXPERIMENT=arenas + +LABEL org.opencontainers.image.title="Quilibrium Network Node" +LABEL org.opencontainers.image.description="Quilibrium is a decentralized alternative to platform as a service providers." +LABEL org.opencontainers.image.version=$NODE_VERSION +LABEL org.opencontainers.image.vendor=Quilibrium +LABEL org.opencontainers.image.url=https://quilibrium.com/ +LABEL org.opencontainers.image.documentation=https://quilibrium.com/docs +LABEL org.opencontainers.image.source=$GIT_REPO +LABEL org.opencontainers.image.ref.name=$GIT_BRANCH +LABEL org.opencontainers.image.revision=$GIT_COMMIT + +COPY --from=build /go/bin/node /usr/local/bin +COPY --from=build /go/bin/grpcurl /usr/local/bin +COPY --from=build /opt/ceremonyclient/client/qclient /usr/local/bin + +WORKDIR /root + +ENTRYPOINT ["node"] diff --git a/README-linux.md b/README-linux.md deleted file mode 100644 index 1880929..0000000 --- a/README-linux.md +++ /dev/null @@ -1,277 +0,0 @@ -# Quilibrium - Dawn - -Quilibrium is a decentralized alternative to platform as a service providers. -This release, mirrored to GitHub, is the Dawn release, which contains the -initial application, the MPC Powers-of-Tau Ceremony. Documentation for the -underlying technology can be found at https://www.quilibrium.com/ - -## Install Requirements - - wget https://:go.dev/dl/go1.20.14.linux-amd64.tar.gz - sudo tar -xvf go1.20.14.linux-amd64.tar.gz - sudo mv go /usr/local - sudo rm go1.20.14.linux-amd64.tar.gz - sudo nano ~/.bashrc - -At the end of the file, add these lines and save the file. - - GOROOT=/usr/local/go - GOPATH=$HOME/go - PATH=$GOPATH/bin:$GOROOT/bin:$PATH - -On command line, run - ~/.bashrc - -Check GO Version - go version - -It must show "go version go.1.20.14 linux/amd64" - -## Configure Linux Network Device Settings - -To optimize throughput and latency for large parallel job typcal of network like Q - - nano /etc/sysctl.conf - -Copy and paste the 3 lines below into the file. The values below are six hundred million. - - #Increase buffer sizes for better network performance - net.core.rmem_max=600000000 - net.core.wmem_max=600000000 - -Save and exit then - sudo sysctl -p - - -## Clone the Repo - - git clone https://github.com/QuilibriumNetwork/ceremonyclient.git - cd ceremonyclient/node - -## Quick Start - -All commands are to be run in the `node/` folder. - -If you have a voucher from the offline ceremony, first run: - - GOEXPERIMENT=arenas go run ./... -import-priv-key `cat /path/to/voucher.hex` - -If you do not, or have already run the above, run: - - GOEXPERIMENT=arenas go run ./... - -## Peer ID - -In order to find the peer id of a running node, execute the following command from the `node/` folder: - - GOEXPERIMENT=arenas go run ./... -peer-id - -The peer id will be printed to stdout. - -## EXPERIMENTAL – gRPC/REST Support - -If you want to enable gRPC/REST, add the following entries to your config.yml: - - sudo nano .config/config.yml - -edit these lines below - - listenGrpcMultiaddr: /ip4/127.0.0.1/tcp/8337 - listenRESTMultiaddr: /ip4/127.0.0.1/tcp/8338 - -Save and exit - -Ensure that port 8337 among other neeeded ports are enabled via firewall. - - sudo ufw enable - sudo ufw allow 8336 - sudo ufw allow 8337 - sudo ufw allow 8338 - sudo ufw status - - -Please note: this interface, while read-only, is unauthenticated and not rate- -limited. It is recommended that you only enable if you are properly controlling -access via firewall or only query via localhost. - -## Token Balance - -In order to query the token balance of a running node, execute the following command from the `node/` folder: - - GOEXPERIMENT=arenas go run ./... -balance - -Or - - GOEXPERIMENT=arenas /root/go/bin/node -balance - -The confirmed token balance will be printed to stdout in QUILs. - -Note that this feature requires that [gRPC support](#experimental--grpcrest-support) is enabled. - -## Build the node binary file - - GOEXPERIMENT=arenas go install ./... - -Thiw will build binary file in /root/go/bin folder - -## Start the Quilibrium Node as a Service - - nano /lib/systemd/system/ceremonyclient.service - -Write the code below - - [Unit] - Description=Ceremony Client Go App Service - - [Service] - Type=simple - Restart=always - RestartSec=5s - WorkingDirectory=/root/ceremonyclient/node - Environment=GOEXPERIMENT=arenas - ExecStart=/root/go/bin/node ./... - - [Install] - WantedBy=multi-user.target - -Save and exit - -To start service run - - service ceremonyclient start - -To stop service run - - service ceremonyclient stop - -To view service logs run - - sudo journalctl -u ceremonyclient.service -f --no-hostname -o cat - -## Upgrading Node - - service ceremonyclient stop - git fetch origin - git merge origin - -Go to ceremonyclient/node folder and run - - GOEXPERIMENT=arenas go clean -v -n -a ./... - rm /root/go/bin/node - GOEXPERIMENT=arenas go install ./... - service ceremonyclient start - -If everything is okay you would see logs when you run - - sudo journalctl -u ceremonyclient.service -f --no-hostname -o cat - -Ensure that your service running correctly. - -## Auto Upgrading Script - -Create a file named update.sh in your server and put the code below. - - - - #!/bin/bash - - # Stop the ceremonyclient service - service ceremonyclient stop - - # Switch to the ~/ceremonyclient directory - cd ~/ceremonyclient - - # Fetch updates from the remote repository - git fetch origin - git merge origin - - # Switch to the ~/ceremonyclient/node directory - cd ~/ceremonyclient/node - - # Clean and reinstall node - GOEXPERIMENT=arenas go clean -v -n -a ./... - rm /root/go/bin/node - GOEXPERIMENT=arenas go install ./... - - # Start the ceremonyclient service - service ceremonyclient start - - - chmod u+x update.sh - -When there is new update, run - ./update.sh - -## Stats Collection - -In order to opt-in to stats collection about the health of the network, edit your `config.yml` in the `node/.config` directory to have a new section under `engine`: - -```yml - -engine: - statsMultiaddr: "/dns/stats.quilibrium.com/tcp/443" - -``` - -## Purpose - -The ceremony application provides a secure reference string (SRS) from which -KZG proofs can be constructed for the network. This yields applicability for a -number of proof systems, in particular for the release after Dawn, the ability -to provide proofs of execution, and proofs of data availability for the network. - -### Rewards - -For participating in a round of the ceremony, nodes will be allocated: - - reward = 161 * log_2(participant_count) QUIL - -### Basic Flow - -Rounds of the ceremony follow the following order: - -- OPEN: Nodes can join in for the round, deferring preference to nodes that -could not join in on the prior round -- IN PROGRESS: The MPC ceremony round is in progress, nodes are engaging in a -logarithmic collection of Multiplication-to-Add Oblivious Transfer circuits, -each sub round producing a new collection of values, until the sub rounds have -completed, producing a collection of public G1 and G2 BLS48-581 points for each -peer. -- FINALIZING: The collection of points are broadcasted, and added together, -producing a singular ceremony transcript contribution. -- VALIDATING: The updated ceremony transcript is validated against the -predecessor, and is confirmed to be the new state, issuing rewards to the -participant set. The next round can begin. - -## Pull Requests - -Contributions are welcome – a new network is rife with opportunities. We are -in the process of updating our JIRA board so that it can be made public. The -repository has basic coding guidelines: - -- 80 character line limit, with the exception where gofmt or the syntax is -impossible to achieve otherwise -- Error wrapping matching function names -- Interface composition and dependency injection with Wire - -## Minimum System Requirements - -For the Dawn phase, a server must have a minimum of 16GB of RAM, preferably -32 GB, 250GB of storage, preferably via SSD, and 50MBps symmetric bandwidth. -For Intel/AMD, the baseline processor is a Skylake processor @ 3.4GHz with 12 -dedicated cores. For ARM, the M1 line of Apple is a good reference. - -With Dusk, these minimum requirements will reduce significantly. - -## License + Interpretation - -Significant portions of Quilibrium's codebase depends on GPL-licensed code, -mandating a minimum license of GPL, however Quilibrium is licensed as AGPL to -accomodate the scenario in which a cloud provider may wish to coopt the network -software. The AGPL allows such providers to do so, provided they are willing -to contribute back the management code that interacts with the protocol and node -software. To provide clarity, our interpretation is with respect to node -provisioning and management tooling for deploying alternative networks, and not -applications which are deployed to the network, mainnet status monitors, or -container deployments of mainnet nodes from the public codebase. - diff --git a/README.md b/README.md index 88e24b9..4e75cbd 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,40 @@ -# Quilibrium - Aurora +# Quilibrium - Betelgeuse Quilibrium is a decentralized alternative to platform as a service providers. -This release, mirrored to GitHub, is the Dawn release, which contains the -initial application, the MPC Powers-of-Tau Ceremony. Documentation for the +This release is part of the phases of the Dusk release, which finalizes with +the full permissionless mainnet in version 2.0. Documentation for the underlying technology can be found at https://www.quilibrium.com/ ## Quick Start -All commands are to be run in the `node/` folder. +Running production nodes from source is no longer recommended given build complexity. Please refer to our release information to obtain the latest version. -If you have a voucher from the offline ceremony, first run: +## Running From Source - GOEXPERIMENT=arenas go run ./... -import-priv-key `cat /path/to/voucher.hex` +Builds are now a hybrid of Rust and Go, so you will need both go 1.22 and latest Rust + Cargo. -If you do not, or have already run the above, run: +### VDF - GOEXPERIMENT=arenas go run ./... +The VDF implementation is now in Rust, and requires GMP to build. On Mac, you can install GMP with brew (`brew install gmp`). On Linux, you will need to find the appropriate package for your distro. -## Peer ID +Install the go plugin for uniffi-rs: -In order to find the peer id of a running node, execute the following command from the `node/` folder: + cargo install uniffi-bindgen-go --git https://github.com/NordSecurity/uniffi-bindgen-go --tag v0.2.1+v0.25.0 - GOEXPERIMENT=arenas go run ./... -peer-id +Be sure to follow the PATH export given by the installer. -The peer id will be printed to stdout. +Build the Rust VDF implementation by navigating to the vdf folder, and run `./generate.sh`. -## EXPERIMENTAL – gRPC/REST Support +### Node + +Because of the Rust interop, be sure you follow the above steps for the VDF before proceeding to this. Navigate to the node folder, and run (making sure to update the path for the repo): + + CGO_LDFLAGS="-L/path/to/ceremonyclient/target/release -lvdf -ldl -lm" \ + CGO_ENABLED=1 \ + GOEXPERIMENT=arenas \ + go run ./... --signature-check=false + +## gRPC/REST Support If you want to enable gRPC/REST, add the following entries to your config.yml: @@ -40,52 +49,11 @@ access via firewall or only query via localhost. In order to query the token balance of a running node, execute the following command from the `node/` folder: - GOEXPERIMENT=arenas go run ./... -balance + ./node-$version-$platform -balance -The confirmed token balance will be printed to stdout in QUILs. +The accumulated token balance will be printed to stdout in QUILs. -Note that this feature requires that [gRPC support](#experimental--grpcrest-support) is enabled. - -## Stats Collection - -In order to opt-in to stats collection about the health of the network, edit your `config.yml` in the `node/.config` directory to have a new section under `engine`: - -```yml - -engine: - statsMultiaddr: "/dns/stats.quilibrium.com/tcp/443" - -``` - -## Purpose - -The ceremony application provides a secure reference string (SRS) from which -KZG proofs can be constructed for the network. This yields applicability for a -number of proof systems, in particular for the release after Dawn, the ability -to provide proofs of execution, and proofs of data availability for the network. - -### Rewards - -For participating in a round of the ceremony, nodes will be allocated: - - reward = 161 * log_2(participant_count) QUIL - -### Basic Flow - -Rounds of the ceremony follow the following order: - -- OPEN: Nodes can join in for the round, deferring preference to nodes that -could not join in on the prior round -- IN PROGRESS: The MPC ceremony round is in progress, nodes are engaging in a -logarithmic collection of Multiplication-to-Add Oblivious Transfer circuits, -each sub round producing a new collection of values, until the sub rounds have -completed, producing a collection of public G1 and G2 BLS48-581 points for each -peer. -- FINALIZING: The collection of points are broadcasted, and added together, -producing a singular ceremony transcript contribution. -- VALIDATING: The updated ceremony transcript is validated against the -predecessor, and is confirmed to be the new state, issuing rewards to the -participant set. The next round can begin. +Note that this feature requires that [gRPC support](#grpcrest-support) is enabled. ## Community Section @@ -96,26 +64,10 @@ This section contains community-built clients, applications, guides, etc
< - A detailed beginners' guide for how to setup a Quilibrium Node, created by [@demipoet](https://www.github.com/demipoet) - [link](https://quilibrium.guide/)
- -## Pull Requests +## Development -Contributions are welcome – a new network is rife with opportunities. We are -in the process of updating our JIRA board so that it can be made public. The -repository has basic coding guidelines: - -- 80 character line limit, with the exception where gofmt or the syntax is -impossible to achieve otherwise -- Error wrapping matching function names -- Interface composition and dependency injection with Wire - -## Minimum System Requirements - -For the Dawn phase, a server must have a minimum of 16GB of RAM, preferably -32 GB, 250GB of storage, preferably via SSD, and 50MBps symmetric bandwidth. -For Intel/AMD, the baseline processor is a Skylake processor @ 3.4GHz with 12 -dedicated cores. For ARM, the M1 line of Apple is a good reference. - -With Dusk, these minimum requirements will reduce significantly. +Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information on +how to contribute to this repository. ## License + Interpretation diff --git a/Taskfile.yaml b/Taskfile.yaml index a2de09e..382429b 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -5,6 +5,9 @@ version: '3' dotenv: - '.env' +env: + DOCKER_BUILDKIT: '1' + vars: VERSION: sh: cat node/config/version.go | grep -A 1 "func GetVersion() \[\]byte {" | grep -Eo '0x[0-9a-fA-F]+' | xargs printf "%d.%d.%d" @@ -14,6 +17,7 @@ vars: sh: git rev-parse --abbrev-ref HEAD GIT_COMMIT: sh: git log -1 --format=%h + MAX_KEY_ID: 17 tasks: status: @@ -24,33 +28,70 @@ tasks: - echo -n "Repo :" && echo " {{.GIT_REPO}}" - echo -n "Branch :" && echo " {{.GIT_BRANCH}}" - echo -n "Commit :" && echo " {{.GIT_COMMIT}}" + - echo -n "Max Key ID:" && echo " {{.MAX_KEY_ID}}" silent: true + + build_node_arm64_macos: + desc: Build the Quilibrium node binary for MacOS ARM. Assumes it's ran from the same platform. Outputs to node/build. + cmds: + - vdf/generate.sh + - node/build.sh -o build/arm64_macos/node - build: - desc: Build the Quilibrium docker image, unless it is already built. + build_node_arm64_linux: + desc: Build the Quilibrium node binary for ARM64 Linux. Outputs to node/build. + cmds: + - docker build --platform linux/arm64 -f Dockerfile.source --output node/build/arm64_linux --target=node . + + build_node_amd64_linux: + desc: Build the Quilibrium node binary for AMD64 Linux. Outputs to node/build. + cmds: + - docker build --platform linux/amd64 -f Dockerfile.source --output node/build/amd64_linux --target=node . + + build:source: + desc: Build the Quilibrium docker image from source. cmds: - | docker build \ + -f Dockerfile.source \ --build-arg NODE_VERSION={{.VERSION}} \ --build-arg GIT_REPO={{.GIT_REPO}} \ --build-arg GIT_BRANCH={{.GIT_BRANCH}} \ --build-arg GIT_COMMIT={{.GIT_COMMIT}} \ - -t ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:{{.VERSION}} \ - -t ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:latest \ + -t ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:{{.VERSION}}-source \ + -t ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:source \ . status: - | docker image inspect \ - ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:{{.VERSION}} \ + ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:{{.VERSION}}-source \ >/dev/null 2>/dev/null - github:login: - desc: Login to GitHub container registry. + build:release: + desc: Build the Quilibrium docker image from release binaries. + aliases: + - build cmds: - - echo $GITHUB_TOKEN | docker login ghcr.io -u $GITHUB_USERNAME --password-stdin + - | + docker build \ + -f Dockerfile.release \ + --build-arg NODE_VERSION={{.VERSION}} \ + --build-arg GIT_REPO={{.GIT_REPO}} \ + --build-arg GIT_BRANCH={{.GIT_BRANCH}} \ + --build-arg GIT_COMMIT={{.GIT_COMMIT}} \ + --build-arg MAX_KEY_ID={{.MAX_KEY_ID}} \ + -t ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:{{.VERSION}}-release \ + -t ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:release \ + . + status: + - | + docker image inspect \ + ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:{{.VERSION}}-release \ + >/dev/null 2>/dev/null docker:login: desc: Login to Docker hub + aliases: + - login cmds: - echo $DOCKER_TOKEN | docker login -u $DOCKER_USERNAME --password-stdin diff --git a/client/go.mod b/client/go.mod index caad573..855be36 100644 --- a/client/go.mod +++ b/client/go.mod @@ -1,6 +1,8 @@ module source.quilibrium.com/quilibrium/monorepo/client -go 1.20 +go 1.21 + +toolchain go1.22.1 replace github.com/libp2p/go-libp2p => ../go-libp2p @@ -11,7 +13,7 @@ replace source.quilibrium.com/quilibrium/monorepo/nekryptology => ../nekryptolog require ( github.com/iden3/go-iden3-crypto v0.0.15 github.com/mr-tron/base58 v1.2.0 - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 ) require ( @@ -20,12 +22,10 @@ require ( github.com/bwesterb/go-ristretto v1.2.3 // indirect github.com/consensys/gnark-crypto v0.5.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/klauspost/cpuid/v2 v2.2.5 // indirect - github.com/minio/sha256-simd v1.0.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/sys v0.17.0 // indirect + golang.org/x/crypto v0.24.0 // indirect + golang.org/x/sys v0.21.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect source.quilibrium.com/quilibrium/monorepo/nekryptology v0.0.0-00010101000000-000000000000 // indirect @@ -33,7 +33,7 @@ require ( require ( github.com/cloudflare/circl v1.3.8 - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/libp2p/go-libp2p v0.33.2 github.com/pkg/errors v0.9.1 @@ -41,6 +41,6 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 // indirect go.uber.org/zap v1.27.0 - google.golang.org/protobuf v1.32.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect source.quilibrium.com/quilibrium/monorepo/node v1.14.17 ) diff --git a/client/go.sum b/client/go.sum index 03655ac..95289c6 100644 --- a/client/go.sum +++ b/client/go.sum @@ -26,40 +26,53 @@ github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iden3/go-iden3-crypto v0.0.15 h1:4MJYlrot1l31Fzlo2sF56u7EVFeHHJkxGXXZCtESgK4= github.com/iden3/go-iden3-crypto v0.0.15/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= +github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= -github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= -github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= +github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE= +github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI= github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= -github.com/multiformats/go-multiaddr v0.11.0 h1:XqGyJ8ufbCE0HmTDwx2kPdsrQ36AGPZNZX6s6xfJH10= +github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= +github.com/multiformats/go-multiaddr v0.12.4 h1:rrKqpY9h+n80EwhhC/kkcunCZZ7URIF8yN1WEUt2Hvc= +github.com/multiformats/go-multiaddr v0.12.4/go.mod h1:sBXrNzucqkFJhvKOiwwLyqamGa/P5EIXNPLovyhQCII= github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g= +github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk= github.com/multiformats/go-multicodec v0.9.0 h1:pb/dlPnzee/Sxv/j4PmkDRxCOi3hXTz3IbPKOXWJkmg= +github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k= github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= +github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= +github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= @@ -69,17 +82,20 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= @@ -89,9 +105,10 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -102,18 +119,19 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= -google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -122,4 +140,5 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI= +lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= diff --git a/crates/classgroup/Cargo.toml b/crates/classgroup/Cargo.toml new file mode 100644 index 0000000..7474010 --- /dev/null +++ b/crates/classgroup/Cargo.toml @@ -0,0 +1,34 @@ +# Copyright 2018 POA Networks Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# and limitations under the License. +[package] +name = "classgroup" +version = "0.1.0" +authors = ["Demi M. Obenour "] +description = """An implementation of class groups in Rust. Uses GMP for arithmetic.""" +keywords = ["classgroup", "vdf"] +repository = "https://github.com/poanetwork/vdf" +license = "Apache-2.0" +edition = "2018" + +[dependencies] +num-traits = "0.2" +libc = "0.2" + +[dev-dependencies] +criterion = ">=0.2" + +[[bench]] +name = "classgroup-bench" +harness = false +path = "bench/bench.rs" diff --git a/crates/classgroup/bench/bench.rs b/crates/classgroup/bench/bench.rs new file mode 100644 index 0000000..8dc7b22 --- /dev/null +++ b/crates/classgroup/bench/bench.rs @@ -0,0 +1,66 @@ +// Copyright 2018 POA Networks Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[macro_use] +extern crate criterion; + +use classgroup::{gmp_classgroup::GmpClassGroup, ClassGroup}; +use criterion::Criterion; +use gmp::mpz::Mpz; +use std::str::FromStr; + +fn bench_square(c: &mut Criterion) { + for _ in 0..2 { + let m_2048 = -Mpz::from_str( + "201493927071865251625903550712920535753645598483515670853547009\ + 878440933309489362800393797428711071833308081461824159206915864\ + 150805748296170245037221957772328044276705571745811271212292422\ + 075849739248257870371300001313586036515879618764093772248760562\ + 386804073478433157526816295216137723803793411828867470089409596\ + 238958950007370719325959579892866588928887249912429688364409867\ + 895510817680171869190054122881274299350947669820596157115994418\ + 034091728887584373727555384075665624624856766441009974642693066\ + 751400054217209981490667208950669417773785631693879782993019167\ + 69407006303085854796535778826115224633447713584423", + ) + .unwrap(); + + let m_1024 = -Mpz::from_str( + "-11208471744389096429663063172516742066731683613191418514476174383781\ + 682509882427394963852743081347678693241523614532942268295868231081182\ + 819214054220080323345750407342623884342617809879459211722505867733607\ + 400509994975706778681543998242335468203860240586171413971485860382901\ + 6409314686266660248501773529803183", + ) + .unwrap(); + let group_1024 = GmpClassGroup::generator_for_discriminant(m_1024); + let group_2048 = GmpClassGroup::generator_for_discriminant(m_2048); + let (group_1024_clone, group_2048_clone) = (group_1024.clone(), group_2048.clone()); + c.bench_function("square 1024", move |b| { + b.iter(|| group_1024_clone.clone().square()) + }); + c.bench_function("multiply 1024", move |b| { + b.iter(|| &group_1024 * &group_1024) + }); + c.bench_function("square 2048", move |b| { + b.iter(|| group_2048_clone.clone().square()) + }); + c.bench_function("multiply 2048", move |b| { + b.iter(|| &group_2048 * &group_2048) + }); + } +} + +criterion_group!(benches, bench_square); +criterion_main!(benches); diff --git a/crates/classgroup/build.rs b/crates/classgroup/build.rs new file mode 100644 index 0000000..a4b0529 --- /dev/null +++ b/crates/classgroup/build.rs @@ -0,0 +1,16 @@ +use std::env; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + + let target = env::var("TARGET").expect("cargo should have set this"); + if target == "aarch64-apple-darwin" { + println!("cargo:rustc-link-search=/opt/homebrew/Cellar/gmp/6.3.0/lib"); + } else if target == "aarch64-unknown-linux-gnu" { + println!("cargo:rustc-link-search=/usr/lib/aarch64-linux-gnu/"); + } else if target == "x86_64-unknown-linux-gnu" { + println!("cargo:rustc-link-search=/usr/lib/x86_64-linux-gnu/"); + } else { + panic!("unsupported target {target}"); + } +} diff --git a/crates/classgroup/src/gmp/ffi.rs b/crates/classgroup/src/gmp/ffi.rs new file mode 100644 index 0000000..d8cc2b1 --- /dev/null +++ b/crates/classgroup/src/gmp/ffi.rs @@ -0,0 +1,7 @@ +use super::mpz::*; + +#[link(name = "gmp", kind = "static")] +extern "C" { + pub fn __gmpz_fdiv_q(q: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr); + pub fn __gmpz_cdiv_q(q: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr); +} diff --git a/crates/classgroup/src/gmp/mod.rs b/crates/classgroup/src/gmp/mod.rs new file mode 100644 index 0000000..a03f391 --- /dev/null +++ b/crates/classgroup/src/gmp/mod.rs @@ -0,0 +1,12 @@ +#![warn(deprecated)] +#![allow(non_camel_case_types)] + +extern crate libc; +extern crate num_traits; + +mod ffi; +pub mod mpz; +pub mod sign; + +#[cfg(test)] +mod test; diff --git a/crates/classgroup/src/gmp/mpz.rs b/crates/classgroup/src/gmp/mpz.rs new file mode 100644 index 0000000..b8a1beb --- /dev/null +++ b/crates/classgroup/src/gmp/mpz.rs @@ -0,0 +1,1035 @@ +#![allow(unsafe_code)] +use libc::{c_char, c_int, c_long, c_ulong, c_void, c_double, size_t, strnlen}; +use super::sign::Sign; +use std::convert::From; +use std::mem::{uninitialized,size_of}; +use std::{fmt, hash}; +use std::cmp::Ordering::{self, Greater, Less, Equal}; +use std::str::FromStr; +use std::error::Error; +use std::ops::{Div, DivAssign, Mul, MulAssign, Add, AddAssign, Sub, SubAssign, Neg, Not, Shl, ShlAssign, Shr, ShrAssign, BitXor, BitXorAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, Rem, RemAssign}; +use std::ffi::CString; +use std::{u32, i32, usize}; +use num_traits::{Zero, One}; + +use super::ffi::*; + +#[repr(C)] +pub struct mpz_struct { + _mp_alloc: c_int, + _mp_size: c_int, + _mp_d: *mut c_void +} + +pub type mp_limb_t = usize; // TODO: Find a way to use __gmp_bits_per_limb instead. +pub type mp_bitcnt_t = c_ulong; +pub type mpz_srcptr = *const mpz_struct; +pub type mpz_ptr = *mut mpz_struct; + +#[link(name = "gmp", kind = "static")] +extern "C" { + static __gmp_bits_per_limb: c_int; + fn __gmpz_init(x: mpz_ptr); + fn __gmpz_init2(x: mpz_ptr, n: mp_bitcnt_t); + fn __gmpz_init_set(rop: mpz_ptr, op: mpz_srcptr); + fn __gmpz_init_set_ui(rop: mpz_ptr, op: c_ulong); + fn __gmpz_init_set_str(rop: mpz_ptr, s: *const c_char, base: c_int) -> c_int; + fn __gmpz_clear(x: mpz_ptr); + fn __gmpz_realloc2(x: mpz_ptr, n: mp_bitcnt_t); + fn __gmpz_set(rop: mpz_ptr, op: mpz_srcptr); + fn __gmpz_set_str(rop: mpz_ptr, s: *const c_char, base: c_int) -> c_int; + fn __gmpz_get_str(s: *mut c_char, base: c_int, op: mpz_srcptr) -> *mut c_char; + fn __gmpz_get_ui(op: mpz_srcptr) -> c_ulong; + fn __gmpz_fits_ulong_p(op: mpz_srcptr) -> c_int; + fn __gmpz_get_si(op: mpz_srcptr) -> c_ulong; + fn __gmpz_get_d(op: mpz_srcptr) -> c_double; + fn __gmpz_fits_slong_p(op: mpz_srcptr) -> c_long; + fn __gmpz_sizeinbase(op: mpz_srcptr, base: c_int) -> size_t; + fn __gmpz_cmp(op1: mpz_srcptr, op2: mpz_srcptr) -> c_int; + fn __gmpz_cmp_ui(op1: mpz_srcptr, op2: c_ulong) -> c_int; + fn __gmpz_add(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr); + fn __gmpz_add_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong); + fn __gmpz_sub(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr); + fn __gmpz_sub_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong); + fn __gmpz_ui_sub(rop: mpz_ptr, op1: c_ulong, op2: mpz_srcptr); + fn __gmpz_mul(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr); + fn __gmpz_mul_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong); + fn __gmpz_mul_si(rop: mpz_ptr, op1: mpz_srcptr, op2: c_long); + fn __gmpz_mul_2exp(rop: mpz_ptr, op1: mpz_srcptr, op2: mp_bitcnt_t); + fn __gmpz_neg(rop: mpz_ptr, op: mpz_srcptr); + fn __gmpz_abs(rop: mpz_ptr, op: mpz_srcptr); + fn __gmpz_tdiv_q(q: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr); + fn __gmpz_tdiv_r(r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr); + fn __gmpz_tdiv_q_ui(q: mpz_ptr, n: mpz_srcptr, d: c_ulong); + fn __gmpz_tdiv_r_ui(r: mpz_ptr, n: mpz_srcptr, d: c_ulong); + fn __gmpz_fdiv_r(r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr); + fn __gmpz_fdiv_q_2exp(q: mpz_ptr, n: mpz_srcptr, b: mp_bitcnt_t); + fn __gmpz_mod(r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr); + fn __gmpz_divisible_p(n: mpz_srcptr, d: mpz_srcptr) -> c_int; + fn __gmpz_and(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr); + fn __gmpz_ior(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr); + fn __gmpz_xor(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr); + fn __gmpz_com(rop: mpz_ptr, op: mpz_srcptr); + fn __gmpz_popcount(op: mpz_srcptr) -> mp_bitcnt_t; + fn __gmpz_pow_ui(rop: mpz_ptr, base: mpz_srcptr, exp: c_ulong); + fn __gmpz_ui_pow_ui(rop: mpz_ptr, base: c_ulong, exp: c_ulong); + fn __gmpz_powm(rop: mpz_ptr, base: mpz_srcptr, exp: mpz_srcptr, modulo: mpz_srcptr); + fn __gmpz_powm_sec(rop: mpz_ptr, base: mpz_srcptr, exp: mpz_srcptr, modulo: mpz_srcptr); + fn __gmpz_hamdist(op1: mpz_srcptr, op2: mpz_srcptr) -> mp_bitcnt_t; + fn __gmpz_setbit(rop: mpz_ptr, bit_index: mp_bitcnt_t); + fn __gmpz_clrbit(rop: mpz_ptr, bit_index: mp_bitcnt_t); + fn __gmpz_combit(rop: mpz_ptr, bit_index: mp_bitcnt_t); + fn __gmpz_tstbit(rop: mpz_srcptr, bit_index: mp_bitcnt_t) -> c_int; + fn __gmpz_probab_prime_p(n: mpz_srcptr, reps: c_int) -> c_int; + fn __gmpz_nextprime(rop: mpz_ptr, op: mpz_srcptr); + fn __gmpz_gcd(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr); + fn __gmpz_gcdext(g: mpz_ptr, s: mpz_ptr, t: mpz_ptr, a: mpz_srcptr, b: mpz_srcptr); + fn __gmpz_lcm(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr); + fn __gmpz_invert(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr) -> c_int; + fn __gmpz_import(rop: mpz_ptr, count: size_t, order: c_int, size: size_t, + endian: c_int, nails: size_t, op: *const c_void); + fn __gmpz_export(rop: *mut c_void, countp: *mut size_t, order: c_int, size: size_t, + endian: c_int, nails: size_t, op: mpz_srcptr); + fn __gmpz_root(rop: mpz_ptr, op: mpz_srcptr, n: c_ulong) -> c_int; + fn __gmpz_sqrt(rop: mpz_ptr, op: mpz_srcptr); + fn __gmpz_millerrabin(n: mpz_srcptr, reps: c_int) -> c_int; +} + +#[repr(transparent)] +pub struct Mpz { + mpz: mpz_struct, +} + +unsafe impl Send for Mpz { } +unsafe impl Sync for Mpz { } + +impl Drop for Mpz { + fn drop(&mut self) { unsafe { __gmpz_clear(&mut self.mpz) } } +} + +/// The result of running probab_prime +#[derive(PartialEq)] +pub enum ProbabPrimeResult { + NotPrime, + ProbablyPrime, + Prime +} + +impl Mpz { + #[inline] + pub unsafe fn inner(&self) -> mpz_srcptr { + &self.mpz + } + + #[inline] + pub unsafe fn inner_mut(&mut self) -> mpz_ptr { + &mut self.mpz + } + + #[inline] + pub fn new() -> Mpz { + unsafe { + let mut mpz = uninitialized(); + __gmpz_init(&mut mpz); + Mpz { mpz: mpz } + } + } + + #[inline] + pub fn new_reserve(n: usize) -> Mpz { + unsafe { + let mut mpz = uninitialized(); + __gmpz_init2(&mut mpz, n as c_ulong); + Mpz { mpz: mpz } + } + } + + #[inline] + pub fn reserve(&mut self, n: usize) { + if self.bit_length() < n { + unsafe { __gmpz_realloc2(&mut self.mpz, n as c_ulong) } + } + } + + #[inline] + pub fn size_in_base(&self, base: u8) -> usize { + unsafe { + __gmpz_sizeinbase(&self.mpz, base as c_int) as usize + } + } + + // TODO: fail on an invalid base + // FIXME: Unfortunately it isn't currently possible to use the fmt::RadixFmt + // machinery for a custom type. + pub fn to_str_radix(&self, base: u8) -> String { + unsafe { + assert!(base >= 2 && base <= 36, "invalid base"); + // Extra two bytes are for possible minus sign and null terminator + let len = { + let len = __gmpz_sizeinbase(&self.mpz, base as c_int) as usize; + assert!(usize::MAX - len >= 2, "capacity overflow"); + len + 2 + }; + + // Allocate and write into a raw *c_char of the correct length + let mut vector: Vec = Vec::with_capacity(len); + __gmpz_get_str(vector.as_mut_ptr() as *mut _, base as c_int, &self.mpz); + let string_len = strnlen(vector.as_ptr() as *const _, len); + assert!(string_len < len); + vector.set_len(string_len); + // FIXME is this actually a problem? + String::from_utf8(vector).expect("GMP returned invalid UTF-8!") + } + } + + pub fn from_str_radix(s: &str, base: u8) -> Result { + let s = CString::new(s.to_string()).map_err(|_| ParseMpzError { _priv: () })?; + unsafe { + assert!(base == 0 || (base >= 2 && base <= 62)); + let mut mpz = uninitialized(); + let r = __gmpz_init_set_str(&mut mpz, s.as_ptr(), base as c_int); + if r == 0 { + Ok(Mpz { mpz: mpz }) + } else { + __gmpz_clear(&mut mpz); + Err(ParseMpzError { _priv: () }) + } + } + } + + #[inline] + pub fn set(&mut self, other: &Mpz) { + unsafe { __gmpz_set(&mut self.mpz, &other.mpz) } + } + + // TODO: too easy to forget to check this return value - rename? + pub fn set_from_str_radix(&mut self, s: &str, base: u8) -> bool { + assert!(base == 0 || (base >= 2 && base <= 62)); + let s = CString::new(s.to_string()).unwrap(); + unsafe { __gmpz_set_str(&mut self.mpz, s.as_ptr(), base as c_int) == 0 } + } + + #[inline] + pub fn bit_length(&self) -> usize { + unsafe { __gmpz_sizeinbase(&self.mpz, 2) as usize } + } + + #[inline] + pub fn compl(&self) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_com(&mut res.mpz, &self.mpz); + res + } + } + + #[inline] + pub fn abs(&self) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_abs(&mut res.mpz, &self.mpz); + res + } + } + + #[inline] + pub fn div_floor(&self, other: &Mpz) -> Mpz { + unsafe { + if other.is_zero() { + panic!("divide by zero") + } + + let mut res = Mpz::new(); + __gmpz_fdiv_q(&mut res.mpz, &self.mpz, &other.mpz); + res + } + } + + #[inline] + pub fn mod_floor(&self, other: &Mpz) -> Mpz { + unsafe { + if other.is_zero() { + panic!("divide by zero") + } + + let mut res = Mpz::new(); + __gmpz_fdiv_r(&mut res.mpz, &self.mpz, &other.mpz); + res + } + } + + /// Determine whether n is prime. + /// + /// This function performs some trial divisions, then reps Miller-Rabin probabilistic primality tests. A higher reps value will reduce the chances of a non-prime being identified as “probably prime”. A composite number will be identified as a prime with a probability of less than 4^(-reps). Reasonable values of reps are between 15 and 50. + pub fn probab_prime(&self, reps: i32) -> ProbabPrimeResult { + match unsafe { + __gmpz_probab_prime_p(&self.mpz, reps as c_int) as u8 + } { + 2 => ProbabPrimeResult::Prime, + 1 => ProbabPrimeResult::ProbablyPrime, + 0 => ProbabPrimeResult::NotPrime, + x => panic!("Undocumented return value {} from __gmpz_probab_prime_p", x), + } + } + + #[inline] + pub fn nextprime(&self) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_nextprime(&mut res.mpz, &self.mpz); + res + } + } + + #[inline] + pub fn gcd(&self, other: &Mpz) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_gcd(&mut res.mpz, &self.mpz, &other.mpz); + res + } + } + + /// Given (a, b), return (g, s, t) such that g = gcd(a, b) = s*a + t*b. + pub fn gcdext(&self, other: &Mpz) -> (Mpz, Mpz, Mpz) { + unsafe { + let mut g = Mpz::new(); + let mut s = Mpz::new(); + let mut t = Mpz::new(); + __gmpz_gcdext(&mut g.mpz, &mut s.mpz, &mut t.mpz, + &self.mpz, &other.mpz); + (g, s, t) + } + } + + #[inline] + pub fn lcm(&self, other: &Mpz) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_lcm(&mut res.mpz, &self.mpz, &other.mpz); + res + } + } + + #[inline] + pub fn is_multiple_of(&self, other: &Mpz) -> bool { + unsafe { + __gmpz_divisible_p(&self.mpz, &other.mpz) != 0 + } + } + + #[inline] + pub fn divides(&self, other: &Mpz) -> bool { + other.is_multiple_of(self) + } + + pub fn modulus(&self, modulo: &Mpz) -> Mpz { + unsafe { + if modulo.is_zero() { + panic!("divide by zero") + } + + let mut res = Mpz::new(); + __gmpz_mod(&mut res.mpz, &self.mpz, &modulo.mpz); + res + } + } + + // TODO: handle a zero modulo + pub fn invert(&self, modulo: &Mpz) -> Option { + unsafe { + let mut res = Mpz::new(); + if __gmpz_invert(&mut res.mpz, &self.mpz, &modulo.mpz) == 0 { + None + } else { + Some(res) + } + } + } + + #[inline] + pub fn popcount(&self) -> usize { + unsafe { __gmpz_popcount(&self.mpz) as usize } + } + + #[inline] + pub fn pow(&self, exp: u32) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_pow_ui(&mut res.mpz, &self.mpz, exp as c_ulong); + res + } + } + + #[inline] + pub fn powm(&self, exp: &Mpz, modulus: &Mpz) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_powm(&mut res.mpz, &self.mpz, &exp.mpz, &modulus.mpz); + res + } + } + + #[inline] + pub fn powm_sec(&self, exp: &Mpz, modulus: &Mpz) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_powm_sec(&mut res.mpz, &self.mpz, &exp.mpz, &modulus.mpz); + res + } + } + + #[inline] + pub fn ui_pow_ui(x: u32, y: u32) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_ui_pow_ui(&mut res.mpz, x as c_ulong, y as c_ulong); + res + } + } + + #[inline] + pub fn hamdist(&self, other: &Mpz) -> usize { + unsafe { __gmpz_hamdist(&self.mpz, &other.mpz) as usize } + } + + #[inline] + pub fn setbit(&mut self, bit_index: usize) { + unsafe { __gmpz_setbit(&mut self.mpz, bit_index as c_ulong) } + } + + #[inline] + pub fn clrbit(&mut self, bit_index: usize) { + unsafe { __gmpz_clrbit(&mut self.mpz, bit_index as c_ulong) } + } + + #[inline] + pub fn combit(&mut self, bit_index: usize) { + unsafe { __gmpz_combit(&mut self.mpz, bit_index as c_ulong) } + } + + #[inline] + pub fn tstbit(&self, bit_index: usize) -> bool { + unsafe { __gmpz_tstbit(&self.mpz, bit_index as c_ulong) == 1 } + } + + pub fn root(&self, n: u32) -> Mpz { + assert!(self.mpz._mp_size >= 0); + unsafe { + let mut res = Mpz::new(); + let _perfect_root + = match __gmpz_root(&mut res.mpz, &self.mpz, n as c_ulong) { + 0 => false, + _ => true, + }; + // TODO: consider returning `_perfect_root` + res + } + } + + pub fn sqrt(&self) -> Mpz { + assert!(self.mpz._mp_size >= 0); + unsafe { + let mut res = Mpz::new(); + __gmpz_sqrt(&mut res.mpz, &self.mpz); + res + } + } + + pub fn millerrabin(&self, reps: i32) -> i32 { + unsafe { + __gmpz_millerrabin(&self.mpz, reps as c_int) + } + } + + pub fn sign(&self) -> Sign { + let size = self.mpz._mp_size; + if size == 0 { + Sign::Zero + } else if size > 0 { + Sign::Positive + } else { + Sign::Negative + } + } + + pub fn one() -> Mpz { + unsafe { + let mut mpz = uninitialized(); + __gmpz_init_set_ui(&mut mpz, 1); + Mpz { mpz: mpz } + } + } + + pub fn zero() -> Mpz { Mpz::new() } + + pub fn is_zero(&self) -> bool { + self.mpz._mp_size == 0 + } +} + +#[derive(Debug)] +pub struct ParseMpzError { + _priv: () +} + +impl fmt::Display for ParseMpzError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.description().fmt(f) + } +} + +impl Error for ParseMpzError { + fn description(&self) -> &'static str { + "invalid integer" + } + + fn cause(&self) -> Option<&'static Error> { + None + } +} + +impl Clone for Mpz { + fn clone(&self) -> Mpz { + unsafe { + let mut mpz = uninitialized(); + __gmpz_init_set(&mut mpz, &self.mpz); + Mpz { mpz: mpz } + } + } +} + +impl Eq for Mpz { } + +impl PartialEq for Mpz { + fn eq(&self, other: &Mpz) -> bool { + unsafe { __gmpz_cmp(&self.mpz, &other.mpz) == 0 } + } +} + +impl Ord for Mpz { + fn cmp(&self, other: &Mpz) -> Ordering { + let cmp = unsafe { __gmpz_cmp(&self.mpz, &other.mpz) }; + if cmp == 0 { + Equal + } else if cmp < 0 { + Less + } else { + Greater + } + } +} + +impl PartialOrd for Mpz { + fn partial_cmp(&self, other: &Mpz) -> Option { + Some(self.cmp(other)) + } +} + +// Implementation of operators + +// This macro inserts a guard against division by 0 for Div and Rem implementations +macro_rules! div_guard { + (Div, $is_zero: expr) => { + if $is_zero { + panic!("divide by zero") + } + }; + (Rem, $is_zero: expr) => { + if $is_zero { + panic!("divide by zero") + } + }; + ($tr: ident, $is_zero: expr) => {} +} + +// On Windows c_long and c_ulong are only 32-bit - in order to implement operations for +// 64-bit types we need some workarounds +macro_rules! bit_guard { + (u64, $what: ident, $e1: expr, $e2: expr) => ( + if size_of::() == 8 || $what <= u32::MAX as u64 { + $e1 + } + else { + $e2 + } + ); + + (i64, $what: ident, $e1: expr, $e2: expr) => ( + if size_of::() == 8 || $what <= i32::MAX as i64 { + $e1 + } + else { + $e2 + } + ); + + (u32, $what: ident, $e1: expr, $e2: expr) => ($e1); + + (i32, $what: ident, $e1: expr, $e2: expr) => ($e1); +} + +macro_rules! impl_oper { + ($tr: ident, $meth: ident, $tr_assign: ident, $meth_assign: ident, $fun: ident) => { + impl $tr for Mpz { + type Output = Mpz; + #[inline] + fn $meth(self, other: Mpz) -> Mpz { + self.$meth(&other) + } + } + + impl<'a> $tr<&'a Mpz> for Mpz { + type Output = Mpz; + #[inline] + fn $meth(mut self, other: &Mpz) -> Mpz { + self.$meth_assign(other); + self + } + } + + impl<'a> $tr for &'a Mpz { + type Output = Mpz; + #[inline] + fn $meth(self, mut other: Mpz) -> Mpz { + unsafe { + div_guard!($tr, other.is_zero()); + $fun(&mut other.mpz, &self.mpz, &other.mpz); + other + } + } + } + + impl<'a, 'b> $tr<&'b Mpz> for &'a Mpz { + type Output = Mpz; + fn $meth(self, other: &Mpz) -> Mpz { + unsafe { + div_guard!($tr, other.is_zero()); + let mut res = Mpz::new(); + $fun(&mut res.mpz, &self.mpz, &other.mpz); + res + } + } + } + + impl $tr_assign for Mpz { + #[inline] + fn $meth_assign(&mut self, other: Mpz) { + self.$meth_assign(&other) + } + } + + impl<'a> $tr_assign<&'a Mpz> for Mpz { + #[inline] + fn $meth_assign(&mut self, other: &Mpz) { + unsafe { + div_guard!($tr, other.is_zero()); + $fun(&mut self.mpz, &self.mpz, &other.mpz); + } + } + } + }; + + (both $num: ident, $cnum: ident, $tr: ident, $meth: ident, $tr_assign: ident, $meth_assign: ident, $fun: ident) => { + impl_oper!(normal $num, $cnum, $tr, $meth, $tr_assign, $meth_assign, $fun); + + impl $tr for $num { + type Output = Mpz; + #[inline] + fn $meth(self, mut other: Mpz) -> Mpz { + unsafe { + bit_guard!($num, self, { + $fun(&mut other.mpz, &other.mpz, self as $cnum); + other + }, other.$meth(Mpz::from(self))) + } + } + } + + impl<'a> $tr<&'a Mpz> for $num { + type Output = Mpz; + fn $meth(self, other: &'a Mpz) -> Mpz { + unsafe { + bit_guard!($num, self, { + let mut res = Mpz::new(); + $fun(&mut res.mpz, &other.mpz, self as $cnum); + res + }, other.$meth(Mpz::from(self))) + } + } + } + }; + + (normal $num: ident, $cnum: ident, $tr: ident, $meth: ident, $tr_assign: ident, $meth_assign: ident, $fun: ident) => { + impl $tr<$num> for Mpz { + type Output = Mpz; + #[inline] + fn $meth(mut self, other: $num) -> Mpz { + self.$meth_assign(other); + self + } + } + + impl<'a> $tr<$num> for &'a Mpz { + type Output = Mpz; + fn $meth(self, other: $num) -> Mpz { + unsafe { + div_guard!($tr, other == 0); + bit_guard!($num, other, { + let mut res = Mpz::new(); + $fun(&mut res.mpz, &self.mpz, other as $cnum); + res + }, self.$meth(Mpz::from(other))) + } + } + } + + impl $tr_assign<$num> for Mpz { + #[inline] + fn $meth_assign(&mut self, other: $num) { + unsafe { + div_guard!($tr, other == 0); + bit_guard!($num, other, + $fun(&mut self.mpz, &self.mpz, other as $cnum), + self.$meth_assign(Mpz::from(other))) + } + } + } + }; + + (reverse $num: ident, $cnum: ident, $tr: ident, $meth: ident, $fun: ident) => { + impl $tr for $num { + type Output = Mpz; + #[inline] + fn $meth(self, mut other: Mpz) -> Mpz { + unsafe { + bit_guard!($num, self, { + $fun(&mut other.mpz, self as $cnum, &other.mpz); + other + }, Mpz::from(self).$meth(other)) + } + } + } + + impl<'a> $tr<&'a Mpz> for $num { + type Output = Mpz; + fn $meth(self, other: &'a Mpz) -> Mpz { + unsafe { + bit_guard!($num, self, { + let mut res = Mpz::new(); + $fun(&mut res.mpz, self as $cnum, &other.mpz); + res + }, Mpz::from(self).$meth(other)) + } + } + } + }; + +} + +impl_oper!(Add, add, AddAssign, add_assign, __gmpz_add); +impl_oper!(both u64, c_ulong, Add, add, AddAssign, add_assign, __gmpz_add_ui); + +impl_oper!(Sub, sub, SubAssign, sub_assign, __gmpz_sub); +impl_oper!(normal u64, c_ulong, Sub, sub, SubAssign, sub_assign, __gmpz_sub_ui); +impl_oper!(reverse u64, c_ulong, Sub, sub, __gmpz_ui_sub); + +impl_oper!(Mul, mul, MulAssign, mul_assign, __gmpz_mul); +impl_oper!(both i64, c_long, Mul, mul, MulAssign, mul_assign, __gmpz_mul_si); +impl_oper!(both u64, c_ulong, Mul, mul, MulAssign, mul_assign, __gmpz_mul_ui); + +impl_oper!(Div, div, DivAssign, div_assign, __gmpz_tdiv_q); +impl_oper!(normal u64, c_ulong, Div, div, DivAssign, div_assign, __gmpz_tdiv_q_ui); + +impl_oper!(Rem, rem, RemAssign, rem_assign, __gmpz_tdiv_r); +impl_oper!(normal u64, c_ulong, Rem, rem, RemAssign, rem_assign, __gmpz_tdiv_r_ui); + +impl<'b> Neg for &'b Mpz { + type Output = Mpz; + fn neg(self) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_neg(&mut res.mpz, &self.mpz); + res + } + } +} + +impl Neg for Mpz { + type Output = Mpz; + #[inline] + fn neg(mut self) -> Mpz { + unsafe { + __gmpz_neg(&mut self.mpz, &self.mpz); + self + } + } +} + +impl<'b> Not for &'b Mpz { + type Output = Mpz; + fn not(self) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_com(&mut res.mpz, &self.mpz); + res + } + } +} + +impl Not for Mpz { + type Output = Mpz; + #[inline] + fn not(mut self) -> Mpz { + unsafe { + __gmpz_com(&mut self.mpz, &self.mpz); + self + } + } +} + +// Similarly to mpz_export, this does not preserve the sign of the input. +impl<'b> From<&'b Mpz> for Vec { + fn from(other: &Mpz) -> Vec { + unsafe { + let bit_size = size_of::() * 8; + let size = (__gmpz_sizeinbase(&other.mpz, 2) + bit_size - 1) / bit_size; + let mut result: Vec = vec!(0; size); + __gmpz_export(result.as_mut_ptr() as *mut c_void, 0 as *mut size_t, 1, size_of::() as size_t, 0, 0, &other.mpz); + result + } + } +} + +impl<'b> From<&'b Mpz> for Option { + fn from(other: &Mpz) -> Option { + unsafe { + let negative = other.mpz._mp_size < 0; + let mut to_export = Mpz::new(); + + if negative { + __gmpz_com(&mut to_export.mpz, &other.mpz); + } else { + __gmpz_set(&mut to_export.mpz, &other.mpz); + } + + if __gmpz_sizeinbase(&to_export.mpz, 2) <= 63 { + let mut result : i64 = 0; + __gmpz_export(&mut result as *mut i64 as *mut c_void, 0 as *mut size_t, -1, size_of::() as size_t, 0, 0, &to_export.mpz); + if negative { + Some(result ^ -1i64) + } else { + Some(result) + } + } else { + return None; + } + } + } +} + +impl<'b> From<&'b Mpz> for Option { + fn from(other: &Mpz) -> Option { + unsafe { + if __gmpz_sizeinbase(&other.mpz, 2) <= 64 && other.mpz._mp_size >= 0 { + let mut result : u64 = 0; + __gmpz_export(&mut result as *mut u64 as *mut c_void, 0 as *mut size_t, -1, size_of::() as size_t, 0, 0, &other.mpz); + Some(result) + } else { + None + } + } + } +} + +impl<'a> From<&'a Mpz> for f64 { + fn from(other: &Mpz) -> f64 { + unsafe { + __gmpz_get_d(&other.mpz) as f64 + } + } +} + +impl<'a> From<&'a [u8]> for Mpz { + fn from(other: &'a [u8]) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_import(&mut res.mpz, other.len(), 1, size_of::() as size_t, + 0, 0, other.as_ptr() as *const c_void); + res + } + } +} + +impl From for Mpz { + fn from(other: u64) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_import(&mut res.mpz, 1, -1, size_of::() as size_t, 0, 0, + &other as *const u64 as *const c_void); + res + } + } +} + +impl From for Mpz { + fn from(other: u32) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_import(&mut res.mpz, 1, -1, size_of::() as size_t, 0, 0, + &other as *const u32 as *const c_void); + res + } + } +} + +impl From for Mpz { + fn from(other: i64) -> Mpz { + unsafe { + let mut res = Mpz::new(); + + if other.is_negative() { + __gmpz_import(&mut res.mpz, 1, -1, size_of::() as size_t, 0, 0, + &(other ^ -1i64) as *const i64 as *const c_void); + __gmpz_com(&mut res.mpz, &res.mpz); + } else { + __gmpz_import(&mut res.mpz, 1, -1, size_of::() as size_t, 0, 0, + &other as *const i64 as *const c_void); + } + res + } + } +} + +impl From for Mpz { + fn from(other: i32) -> Mpz { + unsafe { + let mut res = Mpz::new(); + + if other.is_negative() { + __gmpz_import(&mut res.mpz, 1, -1, size_of::() as size_t, 0, 0, + &(other ^ -1i32) as *const i32 as *const c_void); + __gmpz_com(&mut res.mpz, &res.mpz); + } else { + __gmpz_import(&mut res.mpz, 1, -1, size_of::() as size_t, 0, 0, + &other as *const i32 as *const c_void); + } + res + } + } +} + +impl_oper!(BitAnd, bitand, BitAndAssign, bitand_assign, __gmpz_and); +impl_oper!(BitOr, bitor, BitOrAssign, bitor_assign, __gmpz_ior); +impl_oper!(BitXor, bitxor, BitXorAssign, bitxor_assign, __gmpz_xor); + +impl<'b> Shl for &'b Mpz { + type Output = Mpz; + fn shl(self, other: usize) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_mul_2exp(&mut res.mpz, &self.mpz, other as c_ulong); + res + } + } +} + +impl<'b> Shr for &'b Mpz { + type Output = Mpz; + fn shr(self, other: usize) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_fdiv_q_2exp(&mut res.mpz, &self.mpz, other as c_ulong); + res + } + } +} + +impl Shl for Mpz { + type Output = Mpz; + fn shl(self, other: usize) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_mul_2exp(&mut res.mpz, &self.mpz, other as c_ulong); + res + } + } +} + +impl Shr for Mpz { + type Output = Mpz; + fn shr(self, other: usize) -> Mpz { + unsafe { + let mut res = Mpz::new(); + __gmpz_fdiv_q_2exp(&mut res.mpz, &self.mpz, other as c_ulong); + res + } + } +} + +impl ShlAssign for Mpz { + fn shl_assign(&mut self, other: usize) { + unsafe { + __gmpz_mul_2exp(&mut self.mpz, &self.mpz, other as c_ulong); + } + } +} + +impl ShrAssign for Mpz { + fn shr_assign(&mut self, other: usize) { + unsafe { + __gmpz_fdiv_q_2exp(&mut self.mpz, &self.mpz, other as c_ulong); + } + } +} + +impl FromStr for Mpz { + type Err = ParseMpzError; + fn from_str(s: &str) -> Result { + Mpz::from_str_radix(s, 10) + } +} + +impl fmt::Display for Mpz { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.to_str_radix(10)) + } +} + +impl fmt::Debug for Mpz { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.to_str_radix(10)) + } +} + +impl hash::Hash for Mpz { + fn hash(&self, state: &mut S) { + unsafe { + for i in 0..self.mpz._mp_size.abs() { + let limb = self.mpz._mp_d as *const mp_limb_t; + let limb = *(limb.offset(i as isize)); + limb.hash(state); + } + } + } +} + +impl Zero for Mpz { + #[inline] + fn zero() -> Mpz { + Mpz::zero() + } + + #[inline] + fn is_zero(&self) -> bool { + self.is_zero() + } +} + +impl One for Mpz { + #[inline] + fn one() -> Mpz { + Mpz::one() + } +} + diff --git a/crates/classgroup/src/gmp/sign.rs b/crates/classgroup/src/gmp/sign.rs new file mode 100644 index 0000000..660b2b4 --- /dev/null +++ b/crates/classgroup/src/gmp/sign.rs @@ -0,0 +1,7 @@ +#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug)] +pub enum Sign { + Negative, + Zero, + Positive, +} + diff --git a/crates/classgroup/src/gmp/test.rs b/crates/classgroup/src/gmp/test.rs new file mode 100644 index 0000000..8036386 --- /dev/null +++ b/crates/classgroup/src/gmp/test.rs @@ -0,0 +1,582 @@ +use super::mpz::mp_limb_t; +use std; +use libc::c_int; + +#[link(name = "gmp", kind = "static")] +extern "C" { + static __gmp_bits_per_limb: c_int; +} + +#[test] +#[allow(unsafe_code)] +fn test_limb_size() { + // We are assuming that the limb size is the same as the pointer size. + assert_eq!(std::mem::size_of::() * 8, + unsafe { __gmp_bits_per_limb as usize }); +} + +mod mpz { + use super::super::mpz::Mpz; + use super::super::mpz::ProbabPrimeResult; + use super::super::sign::Sign; + use std::str::FromStr; + use std::convert::{From, Into}; + use std::{i64, u64}; + + use std::hash::{Hash, Hasher}; + use std::collections::hash_map::DefaultHasher; + + #[test] + fn test_set() { + let mut x: Mpz = From::::from(1000); + let y: Mpz = From::::from(5000); + assert!(x != y); + x.set(&y); + assert!(x == y); + } + + #[test] + fn test_set_from_str_radix() { + let mut x: Mpz = From::::from(1000); + let y: Mpz = From::::from(5000); + assert!(x != y); + assert!(x.set_from_str_radix("5000", 10)); + assert!(x == y); + assert!(!x.set_from_str_radix("aaaa", 2)); + } + + #[test] + #[should_panic] + fn test_from_str_radix_lower_bound() { + let _ = Mpz::from_str_radix("", 1); + } + + #[test] + #[should_panic] + fn test_from_str_radix_upper_bound() { + let _ = Mpz::from_str_radix("", 63); + } + + #[test] + #[should_panic] + fn test_set_from_str_radix_lower_bound() { + let mut x = Mpz::new(); + x.set_from_str_radix("", 1); + } + + #[test] + #[should_panic] + fn test_set_from_str_radix_upper_bound() { + let mut x = Mpz::new(); + x.set_from_str_radix("", 63); + } + + #[test] + fn test_eq() { + let x: Mpz = From::::from(4242142195); + let y: Mpz = From::::from(4242142195); + let z: Mpz = From::::from(4242142196); + + assert!(x == y); + assert!(x != z); + assert!(y != z); + } + + #[test] + fn test_ord() { + let x: Mpz = FromStr::from_str("40000000000000000000000").unwrap(); + let y: Mpz = FromStr::from_str("45000000000000000000000").unwrap(); + let z: Mpz = FromStr::from_str("50000000000000000000000").unwrap(); + + assert!(x < y && x < z && y < z); + assert!(x <= x && x <= y && x <= z && y <= z); + assert!(z > y && z > x && y > x); + assert!(z >= z && z >= y && z >= x && y >= x); + } + + #[test] + #[should_panic] + fn test_div_zero() { + let x: Mpz = From::::from(1); + let y = Mpz::new(); + drop(x / y) + } + + #[test] + #[should_panic] + fn test_rem_zero() { + let x: Mpz = From::::from(1); + let y = Mpz::new(); + drop(x % y) + } + + #[test] + fn test_div_round() { + let x: Mpz = From::::from(2); + let y: Mpz = From::::from(3); + assert!((&x / &y).to_string() == (2i32 / 3).to_string()); + assert!((&x / -&y).to_string() == (2i32 / -3).to_string()); + } + + #[test] + fn test_rem() { + let x: Mpz = From::::from(20); + let y: Mpz = From::::from(3); + assert!((&x % &y).to_string() == (20i32 % 3).to_string()); + assert!((&x % 3).to_string() == (20i32 % 3).to_string()); + assert!((&x % -&y).to_string() == (20i32 % -3).to_string()); + assert!((-&x % &y).to_string() == (-20i32 % 3).to_string()); + } + + #[test] + fn test_add() { + let x: Mpz = From::::from(2); + let y: Mpz = From::::from(3); + let str5 = 5i32.to_string(); + assert!((&x + &y).to_string() == str5); + assert!((&x + 3).to_string() == str5); + assert!((&y + 2).to_string() == str5); + } + + #[test] + fn test_sub() { + let x: Mpz = From::::from(2); + let y: Mpz = From::::from(3); + assert!((&x - &y).to_string() == (-1i32).to_string()); + assert!((&y - &x).to_string() == 1i32.to_string()); + assert!((&y - 8).to_string() == (-5i32).to_string()); + } + + #[test] + fn test_mul() { + let x: Mpz = From::::from(2); + let y: Mpz = From::::from(3); + assert!((&x * &y).to_string() == 6i32.to_string()); + assert!((&x * 3i64).to_string() == 6i32.to_string()); + assert!((&y * -5i64).to_string() == (-15i32).to_string()); + // check with values not fitting in 32 bits + assert!((&x * 5000000000i64).to_string() == 10000000000i64.to_string()); + } + + #[test] + fn test_to_str_radix() { + let x: Mpz = From::::from(255); + assert!(x.to_str_radix(16) == "ff".to_string()); + } + + #[test] + fn test_to_string() { + let x: Mpz = FromStr::from_str("1234567890").unwrap(); + assert!(x.to_string() == "1234567890".to_string()); + } + + #[test] + fn test_invalid_str() { + let x: Result = FromStr::from_str("foobar"); + assert!(x.is_err()); + } + + #[test] + fn test_clone() { + let a: Mpz = From::::from(100); + let b = a.clone(); + let aplusb: Mpz = From::::from(200); + assert!(b == a); + assert!(a + b == aplusb); + } + + #[test] + fn test_from_int() { + let x: Mpz = From::::from(150); + assert!(x.to_string() == "150".to_string()); + assert!(x == FromStr::from_str("150").unwrap()); + } + + #[test] + fn test_from_slice_u8() { + let v: Vec = vec!(255, 255); + let x: Mpz = From::from(&v[..]); + assert!(x.to_string() == "65535".to_string()); + } + + #[test] + fn test_abs() { + let x: Mpz = From::::from(1000); + let y: Mpz = From::::from(-1000); + assert!(-&x == y); + assert!(x == -&y); + assert!(x == y.abs()); + assert!(x.abs() == y.abs()); + } + + #[test] + fn test_div_floor() { + let two: Mpz = From::::from(2); + let eight: Mpz = From::::from(8); + let minuseight: Mpz = From::::from(-8); + let three: Mpz = From::::from(3); + let minusthree: Mpz = From::::from(-3); + assert_eq!(eight.div_floor(&three), two); + assert_eq!(eight.div_floor(&minusthree), minusthree); + assert_eq!(minuseight.div_floor(&three), minusthree); + assert_eq!(minuseight.div_floor(&minusthree), two); + } + + #[test] + fn test_mod_floor() { + let one: Mpz = From::::from(1); + let minusone: Mpz = From::::from(-1); + let two: Mpz = From::::from(2); + let minustwo: Mpz = From::::from(-2); + let three: Mpz = From::::from(3); + let minusthree: Mpz = From::::from(-3); + let eight: Mpz = From::::from(8); + let minuseight: Mpz = From::::from(-8); + assert_eq!(eight.mod_floor(&three), two); + assert_eq!(eight.mod_floor(&minusthree), minusone); + assert_eq!(minuseight.mod_floor(&three), one); + assert_eq!(minuseight.mod_floor(&minusthree), minustwo); + } + + #[test] + fn test_bitand() { + let a = 0b1001_0111; + let b = 0b1100_0100; + let mpza: Mpz = From::::from(a); + let mpzb: Mpz = From::::from(b); + let mpzres: Mpz = From::::from(a & b); + assert!(mpza & mpzb == mpzres); + } + + #[test] + fn test_bitor() { + let a = 0b1001_0111; + let b = 0b1100_0100; + let mpza: Mpz = From::::from(a); + let mpzb: Mpz = From::::from(b); + let mpzres: Mpz = From::::from(a | b); + assert!(mpza | mpzb == mpzres); + } + + #[test] + fn test_bitxor() { + let a = 0b1001_0111; + let b = 0b1100_0100; + let mpza: Mpz = From::::from(a); + let mpzb: Mpz = From::::from(b); + let mpzres: Mpz = From::::from(a ^ b); + assert!(mpza ^ mpzb == mpzres); + } + + #[test] + fn test_shifts() { + let i = 227; + let j: Mpz = From::::from(i); + assert!((i << 4).to_string() == (&j << 4).to_string()); + assert!((-i << 4).to_string() == (-&j << 4).to_string()); + assert!((i >> 4).to_string() == (&j >> 4).to_string()); + assert!((-i >> 4).to_string() == (-&j >> 4).to_string()); + } + + #[test] + fn test_compl() { + let a: Mpz = From::::from(13); + let b: Mpz = From::::from(-442); + assert!(a.compl().to_string() == (!13i32).to_string()); + assert!(b.compl().to_string() == (!-442i32).to_string()); + } + + #[test] + fn test_pow() { + let a: Mpz = From::::from(2); + let b: Mpz = From::::from(8); + assert!(a.pow(3) == b); + assert!(Mpz::ui_pow_ui(2, 3) == b); + } + + #[test] + fn test_powm() { + let a: Mpz = From::::from(13); + let b: Mpz = From::::from(7); + let p: Mpz = From::::from(19); + let c: Mpz = From::::from(10); + assert!(a.powm(&b, &p) == c); + } + + #[test] + fn test_powm_sec() { + let a: Mpz = From::::from(13); + let b: Mpz = From::::from(7); + let p: Mpz = From::::from(19); + let c: Mpz = From::::from(10); + assert!(a.powm_sec(&b, &p) == c); + } + + #[test] + fn test_popcount() { + assert_eq!(Mpz::from_str_radix("1010010011", 2).unwrap().popcount(), 5); + } + + #[test] + fn test_hamdist() { + let a: Mpz = From::::from(0b1011_0001); + let b: Mpz = From::::from(0b0010_1011); + assert!(a.hamdist(&b) == 4); + } + + #[test] + fn test_bit_length() { + let a: Mpz = From::::from(0b1011_0000_0001_0000); + let b: Mpz = From::::from(0b101); + assert!(a.bit_length() == 16); + assert!(b.bit_length() == 3); + } + + #[test] + fn test_probab_prime() { + let prime: Mpz = From::::from(2); + assert!(prime.probab_prime(15) == ProbabPrimeResult::Prime); + + let not_prime: Mpz = From::::from(4); + assert!(not_prime.probab_prime(15) == ProbabPrimeResult::NotPrime); + } + + #[test] + fn test_nextprime() { + let a: Mpz = From::::from(123456); + let b: Mpz = From::::from(123457); + assert!(a.nextprime() == b); + } + + #[test] + fn test_gcd() { + let zero: Mpz = From::::from(0); + let three: Mpz = From::::from(3); + let six: Mpz = From::::from(6); + let eighteen: Mpz = From::::from(18); + let twentyfour: Mpz = From::::from(24); + assert!(zero.gcd(&zero) == zero); + assert!(three.gcd(&six) == three); + assert!(eighteen.gcd(&twentyfour) == six); + } + + #[test] + fn test_gcdext() { + let six: Mpz = From::::from(6); + let eighteen: Mpz = From::::from(18); + let twentyfour: Mpz = From::::from(24); + let (g, s, t) = eighteen.gcdext(&twentyfour); + assert!(g == six); + assert!(g == s*eighteen + t*twentyfour); + } + + #[test] + fn test_lcm() { + let zero: Mpz = From::::from(0); + let three: Mpz = From::::from(3); + let five: Mpz = From::::from(5); + let six: Mpz = From::::from(6); + let eighteen: Mpz = From::::from(18); + let twentyfour: Mpz = From::::from(24); + let seventytwo: Mpz = From::::from(72); + assert!(zero.lcm(&five) == zero); + assert!(five.lcm(&zero) == zero); + assert!(three.lcm(&six) == six); + assert!(eighteen.lcm(&twentyfour) == seventytwo); + } + + #[test] + fn test_is_multiple_of() { + let two: Mpz = From::::from(2); + let three: Mpz = From::::from(3); + let six: Mpz = From::::from(6); + assert!(six.is_multiple_of(&two)); + assert!(six.is_multiple_of(&three)); + assert!(!three.is_multiple_of(&two)); + } + + #[test] + fn test_modulus() { + let minusone: Mpz = From::::from(-1); + let two: Mpz = From::::from(2); + let three: Mpz = From::::from(3); + assert_eq!(two.modulus(&three), two); + assert_eq!(minusone.modulus(&three), two); + } + + #[test] + fn test_invert() { + let two: Mpz = From::::from(2); + let three: Mpz = From::::from(3); + let four: Mpz = From::::from(4); + let five: Mpz = From::::from(5); + let eleven: Mpz = From::::from(11); + assert!(three.invert(&eleven) == Some(four.clone())); + assert!(four.invert(&eleven) == Some(three.clone())); + assert!(two.invert(&five) == Some(three.clone())); + assert!(three.invert(&five) == Some(two.clone())); + assert!(two.invert(&four).is_none()); + } + + #[test] + fn test_one() { + let onea: Mpz = From::::from(1); + let oneb: Mpz = From::::from(1); + assert!(onea == oneb); + } + + #[test] + fn test_bit_fiddling() { + let mut xs: Mpz = From::::from(0b1010_1000_0010_0011); + assert!(xs.bit_length() == 16); + let mut ys = [true, false, true, false, + true, false, false, false, + false, false, true, false, + false, false, true, true]; + ys.reverse(); + for i in 0..xs.bit_length() { + assert!(xs.tstbit(i) == ys[i]); + } + xs.setbit(0); + ys[0] = true; + xs.setbit(3); + ys[3] = true; + xs.clrbit(1); + ys[1] = false; + xs.clrbit(5); + ys[5] = false; + xs.combit(14); + ys[14] = !ys[14]; + xs.combit(15); + ys[15] = !ys[15]; + for i in 0..xs.bit_length() { + assert!(xs.tstbit(i) == ys[i]); + } + } + + #[test] + fn test_root() { + let x: Mpz = From::::from(123456); + let y: Mpz = From::::from(49); + assert!(x.root(3) == y); + } + + #[test] + fn test_sqrt() { + let x: Mpz = From::::from(567); + let y: Mpz = From::::from(23); + assert!(x.sqrt() == y); + } + + #[test] + fn test_hash_short() { + let zero: Mpz = From::::from(0); + let one: Mpz = From::::from(1); + let two = &one + &one; + + let hash = |x : &Mpz| { + let mut hasher = DefaultHasher::new(); + x.hash(&mut hasher); + hasher.finish() + }; + + assert!(hash(&zero) != hash(&one)); + assert_eq!(hash(&one), hash(&(&two - &one))); + } + + #[test] + fn test_hash_long() { + let a = Mpz::from_str_radix("348917329847193287498312749187234192387", 10) + .unwrap(); + let b = Mpz::from_str_radix("348917329847193287498312749187234192386", 10) + .unwrap(); + let one: Mpz = From::::from(1); + + let hash = |x : &Mpz| { + let mut hasher = DefaultHasher::new(); + x.hash(&mut hasher); + hasher.finish() + }; + + assert!(hash(&a) != hash(&b)); + assert_eq!(hash(&a), hash(&(&b + &one))); + assert_eq!(hash(&(&a - &a)), hash(&(&one - &one))); + } + + #[test] + fn test_to_vec_u8() { + let minus_five: Mpz = From::::from(-5); + let minus_one: Mpz = From::::from(-1); + let zero: Mpz = From::::from(0); + let one: Mpz = From::::from(1); + let five: Mpz = From::::from(5); + let xffff: Mpz = From::::from(65535); + let max_u64: Mpz = From::::from(u64::MAX); + + assert_eq!(Into::>::into(&minus_five), vec!(5u8)); + assert_eq!(Into::>::into(&minus_one), vec!(1u8)); + assert_eq!(Into::>::into(&zero), vec!(0u8)); + assert_eq!(Into::>::into(&one), vec!(1u8)); + assert_eq!(Into::>::into(&five), vec!(5u8)); + assert_eq!(Into::>::into(&xffff), vec!(255u8, 255u8)); + assert_eq!(Into::>::into(&max_u64), vec!(255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8)); + } + + #[test] + fn test_to_u64() { + let minus_five: Mpz = From::::from(-5); + let minus_one: Mpz = From::::from(-1); + let zero: Mpz = From::::from(0); + let one: Mpz = From::::from(1); + let five: Mpz = From::::from(5); + let max_u64: Mpz = From::::from(u64::MAX); + + assert_eq!(Into::>::into(&minus_five), None); + assert_eq!(Into::>::into(&minus_one), None); + assert_eq!(Into::>::into(&zero), Some(0u64)); + assert_eq!(Into::>::into(&one), Some(1u64)); + assert_eq!(Into::>::into(&five), Some(5u64)); + assert_eq!(Into::>::into(&max_u64), Some(u64::MAX)); + assert_eq!(Into::>::into(&(&max_u64 + &one)), None); + } + + #[test] + fn test_to_i64() { + let min_i64: Mpz = From::::from(i64::MIN); + let minus_five: Mpz = From::::from(-5); + let minus_one: Mpz = From::::from(-1); + let zero: Mpz = From::::from(0); + let one: Mpz = From::::from(1); + let five: Mpz = From::::from(5); + let max_i64: Mpz = From::::from(i64::MAX); + + assert_eq!(Into::>::into(&(&min_i64 - &one)), None); + assert_eq!(Into::>::into(&min_i64), Some(i64::MIN)); + assert_eq!(Into::>::into(&minus_five), Some(-5i64)); + assert_eq!(Into::>::into(&minus_one), Some(-1i64)); + assert_eq!(Into::>::into(&zero), Some(0i64)); + assert_eq!(Into::>::into(&one), Some(1i64)); + assert_eq!(Into::>::into(&five), Some(5i64)); + assert_eq!(Into::>::into(&max_i64), Some(i64::MAX)); + assert_eq!(Into::>::into(&(&max_i64 + &one)), None); + } + + #[test] + fn test_sign() { + let zero: Mpz = From::::from(0); + let five: Mpz = From::::from(5); + let minus_five: Mpz = From::::from(-5); + + assert_eq!(zero.sign(), Sign::Zero); + assert_eq!(five.sign(), Sign::Positive); + assert_eq!(minus_five.sign(), Sign::Negative); + } + + #[test] + fn test_format() { + let zero = Mpz::zero(); + assert_eq!(format!("{}", zero), "0"); + let zero = Mpz::from(-51213); + assert_eq!(format!("{}", zero), "-51213"); + } +} diff --git a/crates/classgroup/src/gmp_classgroup/congruence.rs b/crates/classgroup/src/gmp_classgroup/congruence.rs new file mode 100644 index 0000000..7a30297 --- /dev/null +++ b/crates/classgroup/src/gmp_classgroup/congruence.rs @@ -0,0 +1,90 @@ +// Copyright 2018 Chia Network Inc and POA Networks Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#![forbid(unsafe_code)] +use self::ffi::Mpz; +use super::ffi; + +/// Stores temporary values for congruence computations, to avoid +/// repeated allocations. +/// +/// It is allowed (but inefficient) to generate a fresh `CongruenceContest` +/// for each call to `solve_linear_congruence`. +/// +/// `self.solve_linear_congruence` can be called no matter what values +/// this struct’s public members hold, so long as they are valid `Mpz` values. +/// However, the values of these members after such a call must not be relied +/// on. +#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug)] +pub struct CongruenceContext { + pub g: Mpz, + pub d: Mpz, + pub q: Mpz, + pub r: Mpz, +} + +// #[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug)] +// struct NoCongruence; + +impl Default for CongruenceContext { + fn default() -> Self { + Self { + g: Mpz::new(), + d: Mpz::new(), + q: Mpz::new(), + r: Mpz::new(), + } + } +} + +impl CongruenceContext { + /// Solves `a*x = b (mod m)`, storing `x` in `mu` + /// + /// This function may clobber any or all of `self`’s member variables. + /// + /// # Panics + /// + /// Panics if the congruence could not be solved. + pub fn solve_linear_congruence( + &mut self, + mu: &mut Mpz, + v: Option<&mut Mpz>, + a: &Mpz, + b: &Mpz, + m: &Mpz, + ) { + ffi::mpz_gcdext(&mut self.g, &mut self.d, mu, a, m); + if cfg!(test) { + println!( + "g = {}, d = {}, e = {}, a = {}, m = {}", + self.g, self.d, mu, a, m + ); + } + if cfg!(debug_assertions) { + ffi::mpz_fdiv_qr(&mut self.q, &mut self.r, b, &self.g); + debug_assert!(self.r.is_zero(), "Could not solve the congruence ― did you pass a non-prime or a positive number to the command line tool?!"); + } else { + ffi::mpz_divexact(&mut self.q, b, &self.g) + } + ffi::mpz_mul(&mut self.r, &self.q, &self.d); + ffi::mpz_tdiv_r(mu, &self.r, m); + if let Some(v) = v { + if cfg!(debug_assertions) { + ffi::mpz_fdiv_qr(v, &mut self.r, &m, &self.g); + debug_assert!(self.r.is_zero(), "Could not solve the congruence ― did you pass a non-prime or a positive number to the command line tool?!"); + } else { + ffi::mpz_divexact(v, &m, &self.g) + } + } + } +} diff --git a/crates/classgroup/src/gmp_classgroup/ffi.rs b/crates/classgroup/src/gmp_classgroup/ffi.rs new file mode 100644 index 0000000..7e7b31f --- /dev/null +++ b/crates/classgroup/src/gmp_classgroup/ffi.rs @@ -0,0 +1,340 @@ +// Copyright 2018 POA Networks Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! FFI bindings to GMP. This module exists because the `rust-gmp` crate +//! is too high-level. High-performance bignum computation requires that +//! bignums be modified in-place, so that their storage can be reused. +//! Furthermore, the `rust-gmp` crate doesn’t support many operations that +//! this library requires. +#![allow(unsafe_code)] +pub use super::super::gmp::mpz::Mpz; +use super::super::gmp::mpz::{mp_bitcnt_t, mp_limb_t}; +use libc::{c_int, c_long, c_ulong, c_void, size_t}; +// pub use c_ulong; +use std::{mem, usize}; +// We use the unsafe versions to avoid unecessary allocations. +#[link(name = "gmp", kind = "static")] +extern "C" { + fn __gmpz_gcdext(gcd: *mut Mpz, s: *mut Mpz, t: *mut Mpz, a: *const Mpz, b: *const Mpz); + fn __gmpz_gcd(rop: *mut Mpz, op1: *const Mpz, op2: *const Mpz); + fn __gmpz_fdiv_qr(q: *mut Mpz, r: *mut Mpz, b: *const Mpz, g: *const Mpz); + fn __gmpz_fdiv_q(q: *mut Mpz, n: *const Mpz, d: *const Mpz); + fn __gmpz_divexact(q: *mut Mpz, n: *const Mpz, d: *const Mpz); + fn __gmpz_tdiv_q(q: *mut Mpz, n: *const Mpz, d: *const Mpz); + fn __gmpz_mul(p: *mut Mpz, a: *const Mpz, b: *const Mpz); + fn __gmpz_mul_2exp(rop: *mut Mpz, op1: *const Mpz, op2: mp_bitcnt_t); + fn __gmpz_sub(rop: *mut Mpz, op1: *const Mpz, op2: *const Mpz); + fn __gmpz_import( + rop: *mut Mpz, + count: size_t, + order: c_int, + size: size_t, + endian: c_int, + nails: size_t, + op: *const c_void, + ); + fn __gmpz_tdiv_r(r: *mut Mpz, n: *const Mpz, d: *const Mpz); + fn __gmpz_sizeinbase(op: &Mpz, base: c_int) -> size_t; + fn __gmpz_fdiv_q_ui(rop: *mut Mpz, op1: *const Mpz, op2: c_ulong) -> c_ulong; + fn __gmpz_add(rop: *mut Mpz, op1: *const Mpz, op2: *const Mpz); + fn __gmpz_add_ui(rop: *mut Mpz, op1: *const Mpz, op2: c_ulong); + fn __gmpz_set_ui(rop: &mut Mpz, op: c_ulong); + fn __gmpz_set_si(rop: &mut Mpz, op: c_long); + fn __gmpz_cdiv_ui(n: &Mpz, d: c_ulong) -> c_ulong; + fn __gmpz_fdiv_ui(n: &Mpz, d: c_ulong) -> c_ulong; + fn __gmpz_tdiv_ui(n: &Mpz, d: c_ulong) -> c_ulong; + fn __gmpz_export( + rop: *mut c_void, + countp: *mut size_t, + order: c_int, + size: size_t, + endian: c_int, + nails: size_t, + op: &Mpz, + ) -> *mut c_void; + fn __gmpz_powm(rop: *mut Mpz, base: *const Mpz, exp: *const Mpz, modulus: *const Mpz); +} + +// MEGA HACK: rust-gmp doesn’t expose the fields of this struct, so we must define +// it ourselves and cast. +// +// Should be stable though, as only GMP can change it, and doing would break binary compatibility. +#[repr(C)] +struct MpzStruct { + mp_alloc: c_int, + mp_size: c_int, + mp_d: *mut mp_limb_t, +} + +macro_rules! impl_div_ui { + ($t:ident, $i:ident, $f:expr) => { + pub fn $i(n: &Mpz, d: $t) -> $t { + use std::$t; + let res = unsafe { $f(n, c_ulong::from(d)) }; + assert!(res <= $t::MAX.into()); + res as $t + } + }; +} + +impl_div_ui!(u16, mpz_crem_u16, __gmpz_cdiv_ui); +impl_div_ui!(u32, mpz_frem_u32, __gmpz_fdiv_ui); + +/// Returns `true` if `z` is negative and not zero. Otherwise, +/// returns `false`. +#[inline] +pub fn mpz_is_negative(z: &Mpz) -> bool { + unsafe { (*(z as *const _ as *const MpzStruct)).mp_size < 0 } +} + +#[inline] +pub fn mpz_powm(rop: &mut Mpz, base: &Mpz, exponent: &Mpz, modulus: &Mpz) { + unsafe { __gmpz_powm(rop, base, exponent, modulus) } +} + +#[inline] +pub fn mpz_tdiv_r(r: &mut Mpz, n: &Mpz, d: &Mpz) { + unsafe { __gmpz_tdiv_r(r, n, d) } +} + +/// Sets `g` to the GCD of `a` and `b`. +#[inline] +pub fn mpz_gcdext(gcd: &mut Mpz, s: &mut Mpz, t: &mut Mpz, a: &Mpz, b: &Mpz) { + unsafe { __gmpz_gcdext(gcd, s, t, a, b) } +} + +/// Doubles `rop` in-place +#[inline] +pub fn mpz_double(rop: &mut Mpz) { + if true { + // slightly faster + unsafe { __gmpz_mul_2exp(rop, rop, 1) } + } else { + unsafe { __gmpz_add(rop, rop, rop) } + } +} + +#[inline] +pub fn mpz_fdiv_qr(q: &mut Mpz, r: &mut Mpz, b: &Mpz, g: &Mpz) { + unsafe { __gmpz_fdiv_qr(q, r, b, g) } +} + +#[inline] +pub fn mpz_fdiv_q_ui_self(rop: &mut Mpz, op: c_ulong) -> c_ulong { + unsafe { __gmpz_fdiv_q_ui(rop, rop, op) } +} + +/// Unmarshals a buffer to an `Mpz`. `buf` is interpreted as a 2’s complement, +/// big-endian integer. If the buffer is empty, zero is returned. +pub fn import_obj(buf: &[u8]) -> Mpz { + fn raw_import(buf: &[u8]) -> Mpz { + let mut obj = Mpz::new(); + + unsafe { __gmpz_import(&mut obj, buf.len(), 1, 1, 1, 0, buf.as_ptr() as *const _) } + obj + } + let is_negative = match buf.first() { + None => return Mpz::zero(), + Some(x) => x & 0x80 != 0, + }; + if !is_negative { + raw_import(buf) + } else { + let mut new_buf: Vec<_> = buf.iter().cloned().skip_while(|&x| x == 0xFF).collect(); + if new_buf.is_empty() { + (-1).into() + } else { + for i in &mut new_buf { + *i ^= 0xFF + } + !raw_import(&new_buf) + } + } +} + +pub fn three_gcd(rop: &mut Mpz, a: &Mpz, b: &Mpz, c: &Mpz) { + unsafe { + __gmpz_gcd(rop, a, b); + __gmpz_gcd(rop, rop, c) + } +} + +#[inline] +pub fn size_in_bits(obj: &Mpz) -> usize { + unsafe { __gmpz_sizeinbase(obj, 2) } +} + +#[inline] +pub fn mpz_add(rop: &mut Mpz, op1: &Mpz, op2: &Mpz) { + unsafe { __gmpz_add(rop, op1, op2) } +} + +#[inline] +pub fn mpz_mul(rop: &mut Mpz, op1: &Mpz, op2: &Mpz) { + unsafe { __gmpz_mul(rop, op1, op2) } +} + +#[inline] +pub fn mpz_divexact(q: &mut Mpz, n: &Mpz, d: &Mpz) { + unsafe { __gmpz_divexact(q, n, d) } +} + +#[inline] +pub fn mpz_mul_2exp(rop: &mut Mpz, op1: &Mpz, op2: mp_bitcnt_t) { + unsafe { __gmpz_mul_2exp(rop as *mut _ as *mut Mpz, op1, op2) } +} + +/// Divide `n` by `d`. Round towards -∞ and place the result in `q`. +#[inline] +pub fn mpz_fdiv_q(q: &mut Mpz, n: &Mpz, d: &Mpz) { + if mpz_is_negative(n) == mpz_is_negative(d) { + unsafe { __gmpz_tdiv_q(q, n, d) } + } else { + unsafe { __gmpz_fdiv_q(q, n, d) } + } +} + +/// Sets `rop` to `(-1) * op` +#[inline] +#[cfg(none)] +pub fn mpz_neg(rop: &mut Mpz) { + assert!(mem::size_of::() == mem::size_of::()); + unsafe { + let ptr = rop as *mut _ as *mut MpzStruct; + let v = (*ptr).mp_size; + (*ptr).mp_size = -v; + } +} + +/// Subtracts `op2` from `op1` and stores the result in `rop`. +#[inline] +pub fn mpz_sub(rop: &mut Mpz, op1: &Mpz, op2: &Mpz) { + unsafe { __gmpz_sub(rop as *mut _ as *mut Mpz, op1, op2) } +} + +/// Exports `obj` to `v` as an array of 2’s complement, big-endian +/// bytes. If `v` is too small to hold the result, returns `Err(s)`, +/// where `s` is the size needed to hold the exported version of `obj`. +pub fn export_obj(obj: &Mpz, v: &mut [u8]) -> Result<(), usize> { + // Requires: offset < v.len() and v[offset..] be able to hold all of `obj` + unsafe fn raw_export(v: &mut [u8], offset: usize, obj: &Mpz) -> usize { + // SAFE as `offset` will always be in-bounds, since byte_len always <= + // byte_len_needed and we check that v.len() >= byte_len_needed. + let ptr = v.as_mut_ptr().add(offset) as *mut c_void; + + // Necessary ― this byte may not be fully overwritten + *(ptr as *mut u8) = 0; + + // SAFE as __gmpz_export will *always* initialize this. + let mut s: usize = mem::uninitialized(); + let ptr2 = __gmpz_export(ptr, &mut s, 1, 1, 1, 0, obj); + assert_eq!(ptr, ptr2); + if 0 == s { + 1 + } else { + s + } + } + + let size = size_in_bits(obj); + assert!(size > 0); + + // Check to avoid integer overflow in later operations. + if size > usize::MAX - 8 || v.len() > usize::MAX >> 3 { + return Err(usize::MAX); + } + + // One additional bit is needed for the sign bit. + let byte_len_needed = (size + 8) >> 3; + if v.len() < byte_len_needed { + return if v.is_empty() && obj.is_zero() { + Ok(()) + } else { + Err(byte_len_needed) + }; + } + let is_negative = mpz_is_negative(obj); + + if is_negative { + // MEGA HACK: GMP does not have a function to perform 2's complement + let obj = !obj; + debug_assert!( + !mpz_is_negative(&obj), + "bitwise negation of a negative number produced a negative number" + ); + let new_byte_size = (size_in_bits(&obj) + 7) >> 3; + let offset = v.len() - new_byte_size; + + for i in &mut v[..offset] { + *i = 0xFF + } + unsafe { + assert_eq!(raw_export(v, offset, &obj), new_byte_size); + } + + // We had to do a one’s complement to get the data in a decent format, + // so now we need to flip all of the bits back. LLVM should be able to + // vectorize this loop easily. + for i in &mut v[offset..] { + *i ^= 0xFF + } + } else { + // ...but GMP will not include that in the number of bytes it writes + // (except for negative numbers) + let byte_len = (size + 7) >> 3; + assert!(byte_len > 0); + + let offset = v.len() - byte_len; + + // Zero out any leading bytes + for i in &mut v[..offset] { + *i = 0 + } + unsafe { + assert_eq!(raw_export(v, offset, &obj), byte_len); + } + } + + Ok(()) +} + +#[cfg(test)] +mod test { + use super::*; + #[test] + fn check_expected_bit_width() { + let mut s: Mpz = (-2).into(); + assert_eq!(size_in_bits(&s), 2); + s = !s; + assert_eq!(s, 1.into()); + s.setbit(2); + assert_eq!(s, 5.into()); + } + + #[test] + fn check_export() { + let mut s: Mpz = 0x100.into(); + s = !s; + let mut buf = [0, 0, 0]; + export_obj(&s, &mut buf).expect("buffer should be large enough"); + assert_eq!(buf, [0xFF, 0xFE, 0xFF]); + export_obj(&Mpz::zero(), &mut []).unwrap(); + } + + #[test] + fn check_rem() { + assert_eq!(mpz_crem_u16(&(-100i64).into(), 3), 1); + assert_eq!(mpz_crem_u16(&(100i64).into(), 3), 2); + } +} diff --git a/crates/classgroup/src/gmp_classgroup/mod.rs b/crates/classgroup/src/gmp_classgroup/mod.rs new file mode 100644 index 0000000..f89d8b9 --- /dev/null +++ b/crates/classgroup/src/gmp_classgroup/mod.rs @@ -0,0 +1,590 @@ +// Copyright 2018 Chia Network Inc and POA Networks Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#![deny(unsafe_code)] +use super::ClassGroup; +use super::gmp::mpz::Mpz; +use super::gmp::mpz::ProbabPrimeResult::NotPrime; +use num_traits::{One, Zero}; +use std::{ + borrow::Borrow, + cell::RefCell, + mem::swap, + ops::{Mul, MulAssign}, +}; +use std::convert::TryInto; + +mod congruence; +pub(super) mod ffi; + +#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Clone)] +pub struct GmpClassGroup { + a: Mpz, + b: Mpz, + c: Mpz, + discriminant: Mpz, +} + +#[derive(PartialEq, PartialOrd, Eq, Ord, Clone, Hash, Debug)] +pub struct Ctx { + negative_a: Mpz, + r: Mpz, + denom: Mpz, + old_a: Mpz, + old_b: Mpz, + ra: Mpz, + s: Mpz, + x: Mpz, + congruence_context: congruence::CongruenceContext, + h: Mpz, + w: Mpz, + m: Mpz, + u: Mpz, + a: Mpz, + l: Mpz, + j: Mpz, + b: Mpz, + k: Mpz, + t: Mpz, + mu: Mpz, + v: Mpz, + sigma: Mpz, + lambda: Mpz, +} + +thread_local! { + static CTX: RefCell = Default::default(); +} + +impl GmpClassGroup { + pub fn into_raw(self) -> (Mpz, Mpz) { + (self.a, self.b) + } + + fn inner_multiply(&mut self, rhs: &Self, ctx: &mut Ctx) { + self.assert_valid(); + rhs.assert_valid(); + + // g = (b1 + b2) / 2 + ffi::mpz_add(&mut ctx.congruence_context.g, &self.b, &rhs.b); + ffi::mpz_fdiv_q_ui_self(&mut ctx.congruence_context.g, 2); + + // h = (b2 - b1) / 2 + ffi::mpz_sub(&mut ctx.h, &rhs.b, &self.b); + ffi::mpz_fdiv_q_ui_self(&mut ctx.h, 2); + + debug_assert!(&ctx.h + &ctx.congruence_context.g == rhs.b); + debug_assert!(&ctx.congruence_context.g - &ctx.h == self.b); + + // w = gcd(a1, a2, g) + ffi::three_gcd(&mut ctx.w, &self.a, &rhs.a, &ctx.congruence_context.g); + + // j = w + ctx.j.set(&ctx.w); + + // s = a1/w + ffi::mpz_fdiv_q(&mut ctx.s, &self.a, &ctx.w); + + // t = a2/w + ffi::mpz_fdiv_q(&mut ctx.t, &rhs.a, &ctx.w); + + // u = g/w + ffi::mpz_fdiv_q(&mut ctx.u, &ctx.congruence_context.g, &ctx.w); + + // a = t*u + ffi::mpz_mul(&mut ctx.a, &ctx.t, &ctx.u); + + // b = h*u - s*c1 + ffi::mpz_mul(&mut ctx.b, &ctx.h, &ctx.u); + ffi::mpz_mul(&mut ctx.m, &ctx.s, &self.c); + ctx.b += &ctx.m; + + // m = s*t + ffi::mpz_mul(&mut ctx.m, &ctx.s, &ctx.t); + ctx.congruence_context.solve_linear_congruence( + &mut ctx.mu, + Some(&mut ctx.v), + &ctx.a, + &ctx.b, + &ctx.m, + ); + + // a = t*v + ffi::mpz_mul(&mut ctx.a, &ctx.t, &ctx.v); + + // b = h - t * mu + ffi::mpz_mul(&mut ctx.m, &ctx.t, &ctx.mu); + ffi::mpz_sub(&mut ctx.b, &ctx.h, &ctx.m); + + // m = s + ctx.m.set(&ctx.s); + + ctx.congruence_context.solve_linear_congruence( + &mut ctx.lambda, + Some(&mut ctx.sigma), + &ctx.a, + &ctx.b, + &ctx.m, + ); + + // k = mu + v*lambda + ffi::mpz_mul(&mut ctx.a, &ctx.v, &ctx.lambda); + ffi::mpz_add(&mut ctx.k, &ctx.mu, &ctx.a); + + // l = (k*t - h)/s + ffi::mpz_mul(&mut ctx.l, &ctx.k, &ctx.t); + ffi::mpz_sub(&mut ctx.v, &ctx.l, &ctx.h); + ffi::mpz_fdiv_q(&mut ctx.l, &ctx.v, &ctx.s); + + // m = (t*u*k - h*u - c*s) / s*t + ffi::mpz_mul(&mut ctx.m, &ctx.t, &ctx.u); + ctx.m *= &ctx.k; + ffi::mpz_mul(&mut ctx.a, &ctx.h, &ctx.u); + ctx.m -= &ctx.a; + ffi::mpz_mul(&mut ctx.a, &self.c, &ctx.s); + ctx.m -= &ctx.a; + ffi::mpz_mul(&mut ctx.a, &ctx.s, &ctx.t); + ffi::mpz_fdiv_q(&mut ctx.lambda, &ctx.m, &ctx.a); + + // A = s*t - r*u + ffi::mpz_mul(&mut self.a, &ctx.s, &ctx.t); + + // B = ju + mr - (kt + ls) + ffi::mpz_mul(&mut self.b, &ctx.j, &ctx.u); + ffi::mpz_mul(&mut ctx.a, &ctx.k, &ctx.t); + self.b -= &ctx.a; + ffi::mpz_mul(&mut ctx.a, &ctx.l, &ctx.s); + self.b -= &ctx.a; + + // C = kl - jm + ffi::mpz_mul(&mut self.c, &ctx.k, &ctx.l); + ffi::mpz_mul(&mut ctx.a, &ctx.j, &ctx.lambda); + self.c -= &ctx.a; + + self.inner_reduce(ctx); + } + + #[cfg_attr(not(debug_assertions), inline(always))] + fn new(a: Mpz, b: Mpz, c: Mpz, discriminant: Mpz) -> Self { + let s = GmpClassGroup { + a, + b, + c, + discriminant, + }; + s.assert_valid(); + s + } + + #[cfg_attr(not(debug_assertions), inline(always))] + fn assert_valid(&self) { + if cfg!(debug_assertions) { + let four: Mpz = 4u64.into(); + let four_ac: Mpz = four * &self.a * &self.c; + assert!(&self.discriminant + four_ac == &self.b * &self.b); + } + } + + fn inner_normalize(&mut self, ctx: &mut Ctx) { + self.assert_valid(); + ctx.negative_a = -&self.a; + if self.b > ctx.negative_a && self.b <= self.a { + return; + } + ffi::mpz_sub(&mut ctx.r, &self.a, &self.b); + ffi::mpz_mul_2exp(&mut ctx.denom, &self.a, 1); + ffi::mpz_fdiv_q(&mut ctx.negative_a, &ctx.r, &ctx.denom); + swap(&mut ctx.negative_a, &mut ctx.r); + swap(&mut ctx.old_b, &mut self.b); + ffi::mpz_mul(&mut ctx.ra, &ctx.r, &self.a); + ffi::mpz_mul_2exp(&mut ctx.negative_a, &ctx.ra, 1); + ffi::mpz_add(&mut self.b, &ctx.old_b, &ctx.negative_a); + + ffi::mpz_mul(&mut ctx.negative_a, &ctx.ra, &ctx.r); + ffi::mpz_add(&mut ctx.old_a, &self.c, &ctx.negative_a); + + ffi::mpz_mul(&mut ctx.ra, &ctx.r, &ctx.old_b); + ffi::mpz_add(&mut self.c, &ctx.old_a, &ctx.ra); + + self.assert_valid(); + } + + fn inner_reduce(&mut self, ctx: &mut Ctx) { + self.inner_normalize(ctx); + + while if ffi::mpz_is_negative(&self.b) { + self.a >= self.c + } else { + self.a > self.c + } { + debug_assert!(!self.c.is_zero()); + ffi::mpz_add(&mut ctx.s, &self.c, &self.b); + ffi::mpz_add(&mut ctx.x, &self.c, &self.c); + swap(&mut self.b, &mut ctx.old_b); + ffi::mpz_fdiv_q(&mut self.b, &ctx.s, &ctx.x); + swap(&mut self.b, &mut ctx.s); + swap(&mut self.a, &mut self.c); + + // x = 2sc + ffi::mpz_mul(&mut self.b, &ctx.s, &self.a); + ffi::mpz_mul_2exp(&mut ctx.x, &self.b, 1); + + // b = x - old_b + ffi::mpz_sub(&mut self.b, &ctx.x, &ctx.old_b); + + // x = b*s + ffi::mpz_mul(&mut ctx.x, &ctx.old_b, &ctx.s); + + // s = c*s^2 + ffi::mpz_mul(&mut ctx.old_b, &ctx.s, &ctx.s); + ffi::mpz_mul(&mut ctx.s, &self.a, &ctx.old_b); + + // c = s - x + ffi::mpz_sub(&mut ctx.old_a, &ctx.s, &ctx.x); + + // c += a + self.c += &ctx.old_a; + } + self.inner_normalize(ctx); + } + + fn inner_square_impl(&mut self, ctx: &mut Ctx) { + self.assert_valid(); + ctx.congruence_context.solve_linear_congruence( + &mut ctx.mu, + None, + &self.b, + &self.c, + &self.a, + ); + ffi::mpz_mul(&mut ctx.m, &self.b, &ctx.mu); + ctx.m -= &self.c; + ctx.m = ctx.m.div_floor(&self.a); + + // New a + ctx.old_a.set(&self.a); + ffi::mpz_mul(&mut self.a, &ctx.old_a, &ctx.old_a); + + // New b + ffi::mpz_mul(&mut ctx.a, &ctx.mu, &ctx.old_a); + ffi::mpz_double(&mut ctx.a); + self.b -= &ctx.a; + + // New c + ffi::mpz_mul(&mut self.c, &ctx.mu, &ctx.mu); + self.c -= &ctx.m; + self.inner_reduce(ctx); + } + + #[cfg_attr(not(debug_assertions), inline(always))] + fn inner_square(&mut self, ctx: &mut Ctx) { + if cfg!(debug_assertions) { + let mut q = self.clone(); + q.inner_multiply(self, ctx); + self.inner_square_impl(ctx); + assert_eq!(*self, q); + } else { + self.inner_square_impl(ctx); + } + } + + /// Call `cb` with a mutable reference to the context of type `Ctx`. + /// + /// The reference cannot escape the closure and cannot be sent across + /// threads. + /// + /// # Panics + /// + /// Panics if called recursively. This library guarantees that it will + /// never call this function from any function that takes a parameter of + /// type `&mut Ctx`. + pub fn with_context(cb: T) -> U + where + T: FnOnce(&mut Ctx) -> U, + { + let mut opt = None; + CTX.with(|x| opt = Some(cb(&mut x.borrow_mut()))); + opt.unwrap() + } +} + +impl Default for GmpClassGroup { + fn default() -> Self { + GmpClassGroup { + a: Mpz::new(), + b: Mpz::new(), + c: Mpz::new(), + discriminant: Mpz::new(), + } + } +} + +impl> MulAssign for GmpClassGroup { + #[cfg_attr(not(debug_assertions), inline(always))] + fn mul_assign(&mut self, rhs: B) { + let rhs = rhs.borrow(); + debug_assert!(self.discriminant == rhs.discriminant); + GmpClassGroup::with_context(|ctx| self.inner_multiply(rhs, ctx)); + } +} + +impl super::BigNum for Mpz { + fn probab_prime(&self, iterations: u32) -> bool { + let reps: i32 = iterations.try_into().expect("Iterations fits into i32"); + self.probab_prime(reps) != NotPrime + } + + fn setbit(&mut self, bit_index: usize) { + self.setbit(bit_index) + } + + fn mod_powm(&mut self, base: &Self, exponent: &Self, modulus: &Self) { + ffi::mpz_powm(self, base, exponent, modulus) + } +} + +impl super::BigNumExt for Mpz { + fn frem_u32(&self, modulus: u32) -> u32 { + ffi::mpz_frem_u32(self, modulus) + } + fn crem_u16(&mut self, modulus: u16) -> u16 { + ffi::mpz_crem_u16(self, modulus) + } +} + +impl> Mul for GmpClassGroup { + type Output = Self; + #[inline] + fn mul(mut self, rhs: B) -> Self { + self *= rhs.borrow(); + self + } +} + +impl<'a, B: Borrow> Mul for &'a GmpClassGroup { + type Output = GmpClassGroup; + + #[inline(always)] + fn mul(self, rhs: B) -> Self::Output { + let mut s = Clone::clone(self.borrow()); + s *= rhs; + s + } +} + +impl ClassGroup for GmpClassGroup { + type BigNum = Mpz; + + /// Normalize `self`. + /// + /// # Panics + /// + /// Panics if called within a call to `Self::with_context`. + fn normalize(&mut self) { + Self::with_context(|x| self.inner_normalize(x)) + } + + #[cfg_attr(not(debug_assertions), inline(always))] + fn inverse(&mut self) { + self.assert_valid(); + self.b = -self.b.clone(); + } + + fn serialize(&self, buf: &mut [u8]) -> Result<(), usize> { + self.assert_valid(); + if buf.len() & 1 == 1 { + // odd lengths do not make sense + Err(0) + } else { + let len = buf.len() >> 1; + ffi::export_obj(&self.a, &mut buf[..len])?; + ffi::export_obj(&self.b, &mut buf[len..]) + } + } + + fn from_bytes(bytearray: &[u8], discriminant: Self::BigNum) -> Self { + let len = (ffi::size_in_bits(&discriminant) + 16) >> 4; + let a = ffi::import_obj(&bytearray[..len]); + let b = ffi::import_obj(&bytearray[len..]); + Self::from_ab_discriminant(a, b, discriminant) + } + + fn from_ab_discriminant(a: Self::BigNum, b: Self::BigNum, discriminant: Self::BigNum) -> Self { + let mut four_a: Self::BigNum = 4u64.into(); + four_a *= &a; + let c = (&b * &b - &discriminant) / four_a; + Self { + a, + b, + c, + discriminant, + } + } + + /// Returns the discriminant of `self`. + #[inline(always)] + fn discriminant(&self) -> &Self::BigNum { + &self.discriminant + } + + fn size_in_bits(num: &Self::BigNum) -> usize { + ffi::size_in_bits(num) + } + + /// Reduce `self`. + /// + /// # Panics + /// + /// Panics if called within a call to `Self::with_context`. + fn reduce(&mut self) { + Self::with_context(|x| self.inner_reduce(x)) + } + + fn deserialize(buf: &[u8], discriminant: Self::BigNum) -> Self { + let len = buf.len(); + debug_assert!(len != 0, "Cannot deserialize an empty buffer!"); + debug_assert!(len & 1 == 0, "Buffer must be of even length"); + let half_len = len >> 1; + Self::from_ab_discriminant( + ffi::import_obj(&buf[..half_len]), + ffi::import_obj(&buf[half_len..]), + discriminant, + ) + } + + /// Square `self`.ClassGroupPartial + /// + /// # Panics + /// + /// Panics if called within the scope of a call to `with_context`. + fn square(&mut self) { + Self::with_context(|ctx| self.inner_square(ctx)) + } + + fn unsigned_deserialize_bignum(buf: &[u8]) -> Self::BigNum { + buf.into() + } + + /// Square `self` `iterations` times. + /// + /// # Panics + /// + /// Panics if called within the scope of a call to `with_context`. + fn repeated_square(&mut self, iterations: u64) { + Self::with_context(|ctx| { + for _ in 0..iterations { + self.inner_square(ctx) + } + }) + } + + fn generator_for_discriminant(discriminant: Self::BigNum) -> Self { + let one: Mpz = One::one(); + let x: Mpz = &one - &discriminant; + let mut form = Self::new(2.into(), one, x.div_floor(&8.into()), discriminant); + form.reduce(); + form + } + + fn pow(&mut self, mut exponent: Mpz) { + self.assert_valid(); + debug_assert!(exponent >= Mpz::zero()); + let mut state = self.identity(); + loop { + let is_odd = exponent.tstbit(0); + exponent >>= 1; + if is_odd { + state *= &*self + } + if exponent.is_zero() { + *self = state; + break; + } + self.square(); + } + } +} + +impl Default for Ctx { + fn default() -> Self { + Self { + negative_a: Mpz::new(), + r: Mpz::new(), + denom: Mpz::new(), + old_a: Mpz::new(), + old_b: Mpz::new(), + ra: Mpz::new(), + s: Mpz::new(), + x: Mpz::new(), + congruence_context: Default::default(), + w: Mpz::new(), + m: Mpz::new(), + u: Mpz::new(), + l: Mpz::new(), + j: Mpz::new(), + t: Mpz::new(), + a: Mpz::new(), + b: Mpz::new(), + k: Mpz::new(), + h: Mpz::new(), + mu: Mpz::new(), + v: Mpz::new(), + sigma: Mpz::new(), + lambda: Mpz::new(), + } + } +} + +pub fn do_compute(discriminant: Mpz, iterations: u64) -> GmpClassGroup { + debug_assert!(discriminant < Zero::zero()); + debug_assert!(discriminant.probab_prime(50) != NotPrime); + let mut f = GmpClassGroup::generator_for_discriminant(discriminant); + f.repeated_square(iterations); + f +} + +#[cfg(test)] +mod test { + #![allow(unused_imports)] + use super::*; + #[test] + fn normalize() { + let mut s = GmpClassGroup::new( + 16.into(), + (-23).into(), + 5837_3892.into(), + (-0xdead_beefi64).into(), + ); + let mut new = GmpClassGroup { + b: 9.into(), + c: 5837_3885.into(), + ..s.clone() + }; + s.normalize(); + assert_eq!(s, new); + + s = GmpClassGroup { + a: (1 << 16).into(), + b: (-76951).into(), + c: 36840.into(), + ..s + }; + new = GmpClassGroup { + b: 54121.into(), + c: 25425.into(), + ..s.clone() + }; + s.normalize(); + assert_eq!(s, new); + } +} diff --git a/crates/classgroup/src/lib.rs b/crates/classgroup/src/lib.rs new file mode 100644 index 0000000..8da546b --- /dev/null +++ b/crates/classgroup/src/lib.rs @@ -0,0 +1,251 @@ +// Copyright 2018 Chia Network Inc and POA Networks Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#![deny(unsafe_code)] +use num_traits::{One, Zero}; +use std::ops::{Mul, MulAssign, Rem, ShlAssign}; + +pub mod gmp; + +pub mod gmp_classgroup; +pub use self::gmp_classgroup::{ + do_compute, + ffi::{export_obj, import_obj}, +}; +pub trait BigNum: + Zero + + One + + Clone + + PartialOrd + + std::fmt::Debug + + Rem + + ShlAssign + + for<'a> MulAssign<&'a Self> + + std::ops::Sub + + std::ops::Add + + std::convert::From + + for<'a> std::convert::From<&'a [u8]> + + std::ops::Shl + + std::ops::Shr + + std::ops::Neg + + std::str::FromStr + + for<'a> std::ops::Div<&'a Self, Output = Self> + + Eq + + std::hash::Hash +{ + fn probab_prime(&self, iterations: u32) -> bool; + fn setbit(&mut self, offset: usize); + fn mod_powm(&mut self, base: &Self, exponent: &Self, modulus: &Self); +} + +pub trait BigNumExt: BigNum { + fn frem_u32(&self, modulus: u32) -> u32; + fn crem_u16(&mut self, modulus: u16) -> u16; +} + +pub trait ClassGroup: + Sized + Clone + for<'a> MulAssign<&'a Self> + for<'a> Mul<&'a Self> + PartialEq + std::fmt::Debug +{ + type BigNum: BigNum; + + /// Produces a `Self` from `a`, `b`, and a discriminant. + fn from_ab_discriminant(a: Self::BigNum, b: Self::BigNum, discriminant: Self::BigNum) -> Self; + + /// Unmarshals a `Self` from a byte array and discriminant. + /// + /// The byte array will be in the format of two big-endian byte sequences + /// concatenated together. + fn from_bytes(bytearray: &[u8], discriminant: Self::BigNum) -> Self; + + /// Computes the identity element of `Self` for a given discriminant. + /// + /// If the discriminant is not valid, the result is unspecified. + /// + /// # Panics + /// + /// This may panic (but is not required to) if the discriminant is not + /// valid. If this function does not panic, the results of future + /// operations are unspecified: they will not invoke undefined behavior, + /// but may panic, loop forever, or just compute garbage. + /// + /// In debug builds, this will always panic if the discriminant is invalid. + fn identity_for_discriminant(discriminant: Self::BigNum) -> Self { + Self::from_ab_discriminant(Self::BigNum::one(), Self::BigNum::one(), discriminant) + } + + /// Serializes `self` to a byte array. Returns `Err(s)` if there + /// is not enough space in the buffer. + /// + /// The data must be serialized in twos-complement, big-endian format. + fn serialize(&self, buf: &mut [u8]) -> std::result::Result<(), usize>; + + /// Deserializes a bignum from raw bytes. The bytes **must** be interpreted + /// as a big-endian unsigned integer. + fn unsigned_deserialize_bignum(_: &[u8]) -> Self::BigNum; + + /// Reduce `self` in-place. + fn reduce(&mut self); + + /// Squares `self`, modifying it in-place. + /// + /// A default implementation is provided, but implementations are suggested + /// to override it for performance reasons. + fn square(&mut self) { + let s = self.clone(); + self.mul_assign(&s) + } + + /// Normalize `self`. + fn normalize(&mut self); + + /// The length of `num` in **bits** + fn size_in_bits(num: &Self::BigNum) -> usize; + + /// Gets the discriminant of `self`. + fn discriminant(&self) -> &Self::BigNum; + + /// Computes the identity element of a `ClassGroup`. + fn identity(&self) -> Self { + Self::identity_for_discriminant(self.discriminant().clone()) + } + + /// Generates a *generator* for the class group of `Self`, given a + /// discriminant. + /// + /// If the discriminant is not valid, the result is unspecified. + /// + /// # Relation to `Self::identity_for_discriminant` + /// + /// This is *not* the same as `Self::identity_for_discriminant`: the + /// identity element is *never* a generator for *any* group. This follows + /// from their definitions: the identity element, when multiplied by another + /// element, always gives that other element, whereas *every* element in the + /// group is some power of a generator. + /// + /// # Panics + /// + /// This may panic (but is not required to) if the discriminant is not + /// valid. If this function does not panic, the results of future + /// operations are unspecified: they will not invoke undefined behavior, + /// but may panic, loop forever, or just compute garbage. + /// + /// If the global allocator panics on running out of memory, then this + /// function may panic in the same situation, but it may also just abort the + /// program instead. + /// + /// In debug builds, this will always panic if the discriminant is invalid. + fn generator_for_discriminant(discriminant: Self::BigNum) -> Self { + Self::from_ab_discriminant(2.into(), One::one(), discriminant) + } + + /// Replaces `*self` with its inverse. + fn inverse(&mut self); + + /// Squares `self` repeatedly in-place. + /// + /// Implementors of this trait are encouraged to override this + /// with a more efficient implementation, if one exists. + fn repeated_square(&mut self, iterations: u64) { + for _ in 0..iterations { + self.square() + } + } + + /// Exponentiation + fn pow(&mut self, exponent: Self::BigNum); + + /// Deserialization + fn deserialize(buf: &[u8], discriminant: Self::BigNum) -> Self; +} + +#[cfg(test)] +mod test { + + use std::{ + fs::File, + io::{BufRead, BufReader}, + path::PathBuf, + }; + + use super::{gmp_classgroup::GmpClassGroup, ClassGroup}; + use super::gmp::mpz::Mpz; + + fn split_into_three_pieces(line: &str, c: char) -> [&str; 3] { + let mut iter = line.split(c); + let fst = iter.next().expect("bad test file"); + let snd = iter.next().expect("bad test file"); + let thd = iter.next().expect("bad test file"); + assert!(iter.next().is_none(), "bad test file"); + [fst, snd, thd] + } + + #[test] + fn multiplication_is_correct() { + let manifest_path = + std::env::var("CARGO_MANIFEST_DIR").expect("cargo should have set this"); + let mut path = PathBuf::from(&manifest_path); + path.push("tests/multiply.txt"); + let mut f = BufReader::new(File::open(path).expect("test file missing or unreadable")); + let mut buffer = String::new(); + loop { + let bytes_read = f + .read_line(&mut buffer) + .expect("could not read from test file"); + assert!(bytes_read == buffer.len()); + if bytes_read == 0 { + break; + } + if buffer.ends_with('\n') { + buffer.pop(); + } + if buffer.ends_with('\r') { + buffer.pop(); + } + let mut current_discriminant: Option = None; + let q: Vec<_> = split_into_three_pieces(&buffer, '|') + .iter() + .map(|i| { + let k = split_into_three_pieces(i, ','); + + let a = Mpz::from_str_radix(k[0], 10).expect("bad test file"); + let b = Mpz::from_str_radix(k[1], 10).expect("bad test file"); + let c = Mpz::from_str_radix(k[2], 10).expect("bad test file"); + let mut discriminant: Mpz = &b * &b; + let mut minuand: Mpz = (4u64).into(); + minuand *= &a * &c; + discriminant -= &minuand; + assert!(discriminant < Mpz::zero()); + // takes waaaay too long + // assert!(discriminant.probab_prime(20) != + // gmp::mpz::ProbabPrimeResult::NotPrime); + if let Some(ref q) = current_discriminant { + assert_eq!(q, &discriminant, "mismatching discriminant in test files"); + } else { + current_discriminant = Some(discriminant.clone()); + } + GmpClassGroup::from_ab_discriminant(a, b, discriminant) + }) + .collect(); + assert_eq!(q.len(), 3); + if q[0] == q[1] { + let mut i = q[0].clone(); + i.square(); + assert_eq!(i, q[2]); + } + assert_eq!(&q[1] * &q[0], q[2], "multiplication not valid"); + assert_eq!(&q[0] * &q[1], q[2], "multiplication not valid"); + buffer.clear(); + } + } + +} diff --git a/crates/classgroup/tests/multiply.txt b/crates/classgroup/tests/multiply.txt new file mode 100644 index 0000000..6249c9a --- /dev/null +++ b/crates/classgroup/tests/multiply.txt @@ -0,0 +1,100 @@ +10000018491751458060893889018190756675058808109876974330719629294415871248770716417843542202672894233523533522085426391611508488462673577289978500560291881560964103822003262872704649110111368415677918460552197008588860300461769848797788221536509692873112178498610293735717449110462487732034905273446995235572,6192881975696225786035966982664995064937044822044587534644251299449043731778362309709151420033302511678628887337754750911692576543520793791684926797453257880919340267222510512181015985728296989735175472866965866872698457694161211487470544291337368825900113948256559852781942460432108372735686602775132351861,447562623961213317971342646547297454284223350038133828902656285846421695114449573517005802064814603287280139301229441755696758326577197667784458131993559071961595818908854193681416803619972011522725445624820104005456169532111411278882533391024720916070194718519556110684723979632586634811370262763099820931946|10000018491751458060893889018190756675058808109876974330719629294415871248770716417843542202672894233523533522085426391611508488462673577289978500560291881560964103822003262872704649110111368415677918460552197008588860300461769848797788221536509692873112178498610293735717449110462487732034905273446995235572,6192881975696225786035966982664995064937044822044587534644251299449043731778362309709151420033302511678628887337754750911692576543520793791684926797453257880919340267222510512181015985728296989735175472866965866872698457694161211487470544291337368825900113948256559852781942460432108372735686602775132351861,447562623961213317971342646547297454284223350038133828902656285846421695114449573517005802064814603287280139301229441755696758326577197667784458131993559071961595818908854193681416803619972011522725445624820104005456169532111411278882533391024720916070194718519556110684723979632586634811370262763099820931946|19255554116382770161579383715714909264782708765539029964624834623077914838241374452996111823462588737699221151887520236764901217774034554643488538519529924118839366411749516259835028878669578401436677730193218203890014064720579917095034628468204338354122803225577022412929359504950608508400413031048217497926,15092837287167018117143864462870004173493326087323162483214185994683512256473920528820058682931229518373567536566141901399624393736734616696317492646832399845295961581562413238135817545423153806714585874605091134049460217739322207059368564835209958877374166810803213938557201936549078491894191793263450700347,234893006768044042788914260913118901546740453084924505628085298368208613193607118822477736613870586900826160773678687890939302953916150044522278344184471658898873737893277827322372416620559784208443693756270533224257971092005354126278524692768704444715469609790946460097751182675767317515935452615150233004184 +10000041052183522790242850644893154590720039288612095879016416132777489378534703527529316376767361213758229530778215090392226004364711343494340009516684351602465954563523094253968698993441741189497557646486818525059302740665570749018871945434231968929038967533223013692831944903924891259290137962329173675618,1902993169831098968408340994163042640289698812843652994188396853325597449053613940738900681358483309978075948057374939279288006967407927201371876070720282077185512088102089011109098339510946105167168603912904329219763993441428070797711607939058596983469167495985136256807429373538982995591135613664471290691,648679116947253221704188706776650677211463611636395838310356904951972039958552218839434071543988637793619482253205477878855250277635662749169650536657554110192985236141029049474956216985923614316507072329807839408341849104680142145376380471455107520480114830913820742685234228885993868983705228973767491332409|10000041052183522790242850644893154590720039288612095879016416132777489378534703527529316376767361213758229530778215090392226004364711343494340009516684351602465954563523094253968698993441741189497557646486818525059302740665570749018871945434231968929038967533223013692831944903924891259290137962329173675618,1902993169831098968408340994163042640289698812843652994188396853325597449053613940738900681358483309978075948057374939279288006967407927201371876070720282077185512088102089011109098339510946105167168603912904329219763993441428070797711607939058596983469167495985136256807429373538982995591135613664471290691,648679116947253221704188706776650677211463611636395838310356904951972039958552218839434071543988637793619482253205477878855250277635662749169650536657554110192985236141029049474956216985923614316507072329807839408341849104680142145376380471455107520480114830913820742685234228885993868983705228973767491332409|11014730391994022921548019318564443238610906141262076480168925966763126765751815894971319798676750825680596366806816953155468468927850506963854768575341863098700465049052526243803093026353195834059474734029876952052212354875982568724849333989940233032713622829273608000126280643959163722728068472850088622786,10741667368771260991465304819723549356187315169745538829427954074292104964386739024958802023185700235860418655331632400858711212007319896932342251013222776723172845936147563193613725240374195945000924112718166206035243862199173787901602224623957181722190890413718871860292878014198837725481829866947825981913,591458717193488352905603034790202837072660316706237076413003353962226001987681937225165602501036312777007571264636495875979803481147253392478958512772229202313701414596984055959140281478236518410326724468820458881999271606689529119264353275033892327553507658401114443924515886686374958949587811834733084613494 +10000381915681932465973261183425742883776417480816046593820159088331265076946313439425523314444345253320002870252043057595684488140407211015115892705028395378796407813776706176594457902083795049968208905578343034404017956993894296039160788337679442024505335413399442760803039586109332233036553257459967307992,4817573728667361865336022581228097408185105735439009440346088109945423944514625700845976724084897576632126538284617885680024575350161902075565426943435359103696435860065323384485576321976518692508202982451179520762630115309722600967720404130152140308793673263051352095721900258702511325402177650727880246935,669873650881721761367318894015191721808238052876596531632606045247446982615721443478227885999211090819818334947786875090863090531638122013530669226521626152920347047659485744946461307259365312735407042929006458450763753134816736952808194188478460912675596404179851630644942038849386883091149385220764843706257|10000381915681932465973261183425742883776417480816046593820159088331265076946313439425523314444345253320002870252043057595684488140407211015115892705028395378796407813776706176594457902083795049968208905578343034404017956993894296039160788337679442024505335413399442760803039586109332233036553257459967307992,4817573728667361865336022581228097408185105735439009440346088109945423944514625700845976724084897576632126538284617885680024575350161902075565426943435359103696435860065323384485576321976518692508202982451179520762630115309722600967720404130152140308793673263051352095721900258702511325402177650727880246935,669873650881721761367318894015191721808238052876596531632606045247446982615721443478227885999211090819818334947786875090863090531638122013530669226521626152920347047659485744946461307259365312735407042929006458450763753134816736952808194188478460912675596404179851630644942038849386883091149385220764843706257|15406883651839353468888340788129827256524366500559993343402492794080742895081542466902089892082975781941021139173750937371748781682695257732868858255213590996446142784059996942302405311028161097993332331718537383888482114789770414489490580461393020737016788325059322912336073066124099655242000162998144490191,4360823987526422964670528620808397080272081276432190896883401768539814490180903410645821165307382339042226562722529652661460320310396511517028476587614669988004410806997734064375576646534713644939599630073534432499720811712867334091133681123961660738588960398432344316577526812821260889068523826290764750305,434737123855318232136803285518736106774596594589476825779021338309188039202684276728719741767739900154018854551253981210446831263812934806367418646532886786527458187655685060926749423401952358398253824964655841491692769761412354811289837062586506164527515355144754089246394187279961001728737349715244065290684 +10000382084844819863091735393428537123796094124029988695624509543701671917373805547793586171907452267004536696714359178508237591675470611568215269390130161491021123479579310299191808477715227540644280867131359924216029489859205866802370878621090778893635118109144685744213704279596306855259529008805569484738,-444155911792016461297666514223280647275019670279235098115904524278820479908555182212414682305357120850467322036353999623022556562078881846242421627622835673248504490647482104203937046492778180626801172318868765508903156634858880238203680354870853572676123032093150013906751911065758499256507194503286999359,567054671672969689387757610046141412714538710354002952292665369546607156429867011238555624731427279061383543924144630291236714076290759079492403352598432624404020019598559946194717566760077730429172494635087510893397235439040191683342313758118884331110227782487142203190483880485876667351431228811762752414559|10000382084844819863091735393428537123796094124029988695624509543701671917373805547793586171907452267004536696714359178508237591675470611568215269390130161491021123479579310299191808477715227540644280867131359924216029489859205866802370878621090778893635118109144685744213704279596306855259529008805569484738,-444155911792016461297666514223280647275019670279235098115904524278820479908555182212414682305357120850467322036353999623022556562078881846242421627622835673248504490647482104203937046492778180626801172318868765508903156634858880238203680354870853572676123032093150013906751911065758499256507194503286999359,567054671672969689387757610046141412714538710354002952292665369546607156429867011238555624731427279061383543924144630291236714076290759079492403352598432624404020019598559946194717566760077730429172494635087510893397235439040191683342313758118884331110227782487142203190483880485876667351431228811762752414559|25233315598122077418065976820332071042466787077699487654424387918664961172156179342884760885536120785360009215201873305025819279551843543582105904004062292352688557410351568671077765651689593128194982886401323218888273326531345494420553999096902303332712335656165115841742118280506588108873800795844703864919,-21589572107561067243363628128888045942080137348693403707950771695641329996718935854060105037586070646944119604332897696206540905887323628203932721112852139156892903280775223036949323848394414919310082155940615053363132829628799672709557839434529964085755781777411447385312731490258576057970445296620960747711,229349228584333455202515805454481561086661761655883453088894599746824713549123206719584169689814830025633382253625181015273278307916408839487283320828823538420290774632766998050162873483736921565586622385485530453983863042070274251829142359266901387980967335820672065096008596106715431022577378179753339164658 +10000535283948766913969186677763146947350893764133523013624566402396075467775122389351423347627366996308717336970472190566686266526440447170486872996146388310569838407203380788397656952824650289706008150444069157387402604479170310815759950456001810768733293842505752683896727400110806658910272623240889276302,3517715128667026666780257130236186883393464552180724243651182669587910084592324227192755249223315343739548139286489599592680626480533511441942660471947189354661549994487257423179947475122454624754426244988595239282883275819687054584105503928955994194464535141072191228405010641132986293339925974908519502951,570034118010650587062470713310391834950695503036920240298132931861980289236162947574989015145270228575455513419386383991154247888350856213235253786311087987346865298158646949041224197372582390632868027286119802250763817862749191433673344918830453654023465432067298969962772419746088402608223812814936545467246|10000535283948766913969186677763146947350893764133523013624566402396075467775122389351423347627366996308717336970472190566686266526440447170486872996146388310569838407203380788397656952824650289706008150444069157387402604479170310815759950456001810768733293842505752683896727400110806658910272623240889276302,3517715128667026666780257130236186883393464552180724243651182669587910084592324227192755249223315343739548139286489599592680626480533511441942660471947189354661549994487257423179947475122454624754426244988595239282883275819687054584105503928955994194464535141072191228405010641132986293339925974908519502951,570034118010650587062470713310391834950695503036920240298132931861980289236162947574989015145270228575455513419386383991154247888350856213235253786311087987346865298158646949041224197372582390632868027286119802250763817862749191433673344918830453654023465432067298969962772419746088402608223812814936545467246|59075354970692991755903146214605554332637224507205941847466515241658938543685224447213353186403252887052183944064961699964728259961938411627544944845776708313892390437907961447141588832103578886894741951168483053303302416173045780507296127716028825436246283574600092245162214148065236680479535423660537547914,6142586061770095737227904853540455719428485301510321654081360726874454746843797212863006221294314976215484969948774214251692404250673117267549442037815482195083213974160653516820675375995512277154295678704255795063545010227709473438581077714090470093020228882800682332012139884210689872621538573295925265993,96605184581646361029373732724432135349175091555904351927012123488431445097722589746711095342410196584277564279992867684018993498546178659279293376777551513451631505380655431533215245951077120355215801949799249196142928522335615942042353764886891560316955633828555662725473411497902686741832487630568702990486 +10000992092359348487480681816729833858083850458212481718635084324812805161168823645716695515173763020806162121153711923870750015861003941980870964102569907660333270160386745314618020099129085566179786211585530303068327607946822258160299176181360948584855686949828385515610423848592364973361809055890165682387,1387707194943048769069000645578034755727575677682880147095892736572338185330919801102067876481652092034533316677281336622039276010947331496276488954193596489132454018768653574924396409513550904384989555254933742194365096022768325215822785577085941233088045260998209615597763890732713200353258054623633203363,717334904486111082107761816895355357018690502858423612748563938578649989943228419203563081094256539563484346776479991186971459579979441405718434993605445911043337999222596585935065011724285592737227690661183256354762587476450143021573235732571046140183664111033663616265739167081365443050278073128430130275044|10000992092359348487480681816729833858083850458212481718635084324812805161168823645716695515173763020806162121153711923870750015861003941980870964102569907660333270160386745314618020099129085566179786211585530303068327607946822258160299176181360948584855686949828385515610423848592364973361809055890165682387,1387707194943048769069000645578034755727575677682880147095892736572338185330919801102067876481652092034533316677281336622039276010947331496276488954193596489132454018768653574924396409513550904384989555254933742194365096022768325215822785577085941233088045260998209615597763890732713200353258054623633203363,717334904486111082107761816895355357018690502858423612748563938578649989943228419203563081094256539563484346776479991186971459579979441405718434993605445911043337999222596585935065011724285592737227690661183256354762587476450143021573235732571046140183664111033663616265739167081365443050278073128430130275044|46482666589787057164981427600152979028584675170625944424946407599960201881805307116957471661211638766618134840736062752900079748534826618093953946800313092285412874757225443617416186449293441503680335786478712016820930243711850679772176006938838607901709770799483635364697553013258865109416434882051210741449,3101717798468321538599785648396208464189816894621339325506629294456148802654755640066207376362353269286149982363784579708988481769754035006891067923386713257060529140906313751403507998251605485836475302614223762235407657418301209467207199741940328204824018102771458491705342260612142478146285653246057987987,154379792819937466421655387360779358004857339117994029103954006768201464432625988196022580370956875717212647779858597489967018623693936133011607398083022906238217469025231498041115162395196295497816525433748189786409656276394144968660209259259055129261299657708619246489632848864169630941858852164482792598772 +100016993550415829135262361263254459069906572411523652885898601946150332160005753209165983241360621518247046578246408973951913750019427396230791395391900464740479884371689964652672891087059763533492805056734857093926525888370387953270730195624561287530833550654825448807998575583518751690880145682614320134626,97867808093652711513661030354940855898834960524171083907471520733521588237588575528935854367900557849089129501606401645574828485643984844895342166280487749477320616345326562522776423978127616648618120061233592736634312164206210712776242358394865817287600812334839844119000151584498625451416447766525556737091,101546865178620340984298080630771114165409461904937118589108835750643335026750315119287055941177105859697880165662377691746530085636458948369814197349790717060438350144172923110723731589639766266300381349821152919234474715235659078426677984814293485454727036020005038295982154861599467045526190910921111647828|100016993550415829135262361263254459069906572411523652885898601946150332160005753209165983241360621518247046578246408973951913750019427396230791395391900464740479884371689964652672891087059763533492805056734857093926525888370387953270730195624561287530833550654825448807998575583518751690880145682614320134626,97867808093652711513661030354940855898834960524171083907471520733521588237588575528935854367900557849089129501606401645574828485643984844895342166280487749477320616345326562522776423978127616648618120061233592736634312164206210712776242358394865817287600812334839844119000151584498625451416447766525556737091,101546865178620340984298080630771114165409461904937118589108835750643335026750315119287055941177105859697880165662377691746530085636458948369814197349790717060438350144172923110723731589639766266300381349821152919234474715235659078426677984814293485454727036020005038295982154861599467045526190910921111647828|38112895924354771000755967523257705692975308805226188158888846989042277994318034233632572801944291367363544635160689172507870767350780603573652174702847837195353422410303076999489362677424810242035375507542324255582549804459073498689456734177829753341266635299826832746075600445484602669454902196797110414268,29514825972671498452469428270002667581396743351651746797469797047436108385118786112979101930068512381300796319538713657519350359618509818562580593402643136639943548729030802553674984090829042397520519175389582956780710082733565916489480248905811215441925467758974481931055406921284703112579763389522667256173,209369197456369085510398489829077224010383063845121124974155708663637684112727148688124840116395472316273115362880530986565561714461662746456509765896943657967931982155109566457128704664240543108345283001161566864139257311910823070822151712032036583892036613154176268529246135956533435036580269691993608092680 +10001857278272414635783742468687626112156223003835485801536389954295572560863634462501676022563000509436968020300398791815574826898175032553202096799719821296404518525211113962533485614199031043964942385615363652892938675160040173449995570062547675787656647030050979129677693759900885701969029983016110814344,4689276451232458601825639665209988136946233783317430787463374655024892705415877731372938558103104801918261384975590626995047805878141047994265820723310810966786623993284261416684874325742989563037963206467146622805115830511715873009621433988190289268680824928937364349844265466118648518849937971040073290847,417151168234058306514924962236880342366392470330250088900617117412557071558608977094869379187282436222898630224671275148160961737937513168266914431807498623302460140528881877180166348694674662748849360025138764269398178107070427436885941278328572218964052739099341639294288244256170434477924203033934350673327|10001857278272414635783742468687626112156223003835485801536389954295572560863634462501676022563000509436968020300398791815574826898175032553202096799719821296404518525211113962533485614199031043964942385615363652892938675160040173449995570062547675787656647030050979129677693759900885701969029983016110814344,4689276451232458601825639665209988136946233783317430787463374655024892705415877731372938558103104801918261384975590626995047805878141047994265820723310810966786623993284261416684874325742989563037963206467146622805115830511715873009621433988190289268680824928937364349844265466118648518849937971040073290847,417151168234058306514924962236880342366392470330250088900617117412557071558608977094869379187282436222898630224671275148160961737937513168266914431807498623302460140528881877180166348694674662748849360025138764269398178107070427436885941278328572218964052739099341639294288244256170434477924203033934350673327|39512406098482423779120312488933213318036506673065796538336022993655638182250527755522829589375917826833348984821059004871245970343092490834408525776732580142621174939994986501353324355190007207510458548320626445520306240377159533568686613898702507848891809938754441261902406274233712558160571614302439957131,33458680315871522230740954658476053975126560151398110919331173177225767029941330426356821906446363070251030468052516656211641983986229753635879608148342626307073260672093693099423083101538134818421873088154104042575469404107414196063491342206675483762419581621360672445423968155195195983917204254937268665705,112538323552595379512976869360963431325956968605739748467981199043411580278581204995308070112281536994589175551282469490999392089726267157369534414758432876571069898487221813246689682731800084089695271351717243345819033451481449481940560204129785884663224360555776373560572513249146398346919605386672664225732 +10001885848475688153826124264809818246080666151576830718882253306412201821167674972767046901596625026072385280166547579462646990262300818624039744400633121727773879619930855094164710044647150456604915949836019563376717637829785627004484641494826695600821088683607312916171680087163211415876920408834836303184,-6401849646396930994521658626667447090190354097997530993450466589091600058118189817231880440719330366452128426380645424906405833189843064340607355709362044588398581812540592198712107929843518387144633043143678667045861106413931254718474764939962100744640406024944116893338624373426827575556627557030324975185,729010733894420808263762284440227341447693348621882426869722779163540379242011358298248405166128119693780872987746515732812024832371695093716504877119416045933332381529307504733200317114594647306152268108402837078447121693601055930678151182644443827620435481034522157377127949376404692708089215142290715182147|10001885848475688153826124264809818246080666151576830718882253306412201821167674972767046901596625026072385280166547579462646990262300818624039744400633121727773879619930855094164710044647150456604915949836019563376717637829785627004484641494826695600821088683607312916171680087163211415876920408834836303184,-6401849646396930994521658626667447090190354097997530993450466589091600058118189817231880440719330366452128426380645424906405833189843064340607355709362044588398581812540592198712107929843518387144633043143678667045861106413931254718474764939962100744640406024944116893338624373426827575556627557030324975185,729010733894420808263762284440227341447693348621882426869722779163540379242011358298248405166128119693780872987746515732812024832371695093716504877119416045933332381529307504733200317114594647306152268108402837078447121693601055930678151182644443827620435481034522157377127949376404692708089215142290715182147|29744618895999892950369062264736486891947372089326189805787662049365991492371249728993520356943689392647109012744687302300685788536119433016012855224253957313263294648625309856809103016565484862180956099939466843259337398301571034092060768935310042949815131108676382925915723778520018870120465703148469427226,-10209285996871914054868241646783255177966316197845761911887894869148957597460422378515655227929008210712234487944652632986850515682880041083632277387837772452379138668071836676947710588769042538916436601704393264463866941375385749221300434945563044575029802713999893603873804815268692854499670177122342861333,245667750146427110150677187685482906099978771660913415239953145936955067540313763536644215438217145059701666728130321490946010447912027178133916738527033418368981585094936292739042791746985193177096407440545894318127458296684680664341938696795502212145624334822453802110708189609055956050992529688916696742439 +10002016107047298540914373810554280751018084476212026169532336244000095667290766720576480147453702781819098831501724861337484902920323127318735651635800283580581543246660775103367813382337363027395892342097619966629022106712471908155888170784651450900253429516651100879214540932985016853993115133868182018064,3932953570343042122021312972484149360925874859667466184891542534824273073163448674737029662190753442883970728845641115381889397609743429783435425637213409939798177187589001177019943245975437142488968879145205618985792078085357316999616817143927979980310665100836939307474346180730761675171280731347158671449,501820428787763072597412186811130523406055528535842317937667844140331895435375780110188856271616785538949009425271158566975765518229735762290911833082144356638560737127790858277137050097833066958564259261818227652665496782587799644931796940046040067871968056722480981736692953918030967693251282638067356406145|10002016107047298540914373810554280751018084476212026169532336244000095667290766720576480147453702781819098831501724861337484902920323127318735651635800283580581543246660775103367813382337363027395892342097619966629022106712471908155888170784651450900253429516651100879214540932985016853993115133868182018064,3932953570343042122021312972484149360925874859667466184891542534824273073163448674737029662190753442883970728845641115381889397609743429783435425637213409939798177187589001177019943245975437142488968879145205618985792078085357316999616817143927979980310665100836939307474346180730761675171280731347158671449,501820428787763072597412186811130523406055528535842317937667844140331895435375780110188856271616785538949009425271158566975765518229735762290911833082144356638560737127790858277137050097833066958564259261818227652665496782587799644931796940046040067871968056722480981736692953918030967693251282638067356406145|64735528603519488065780804878324224417188886620278284672701068126880574848630151784368770212266476848015707656767389613750457721321054695685260658278678665196373574627583845291930832489025699028328049591231345912341357077706665618380075933900907723135182099099317242925058024706513979297237254597076227095551,4676767511975502628189775967741301363073348373643615464321451471292999156583060169457486234222367809825517380380305131875518326506653500784620820595247817795436795668446618561421217197076229074005115884048096800861583629462266306937502121558685767398985500271610752282597009278306418521631471902811873963535,77558909729073708624985274700160896365175589183029958928607160881016530406365743721430360419631842295388705380922110512036514218268293799548453381932743351256518434510701744265175175287358735767897041689462764452869200380851139430193325516047764774954110200096814808839955087651569998366318539183831351467636 +10002034549022819403076408239222347017099550415714472028923655065363879242538082883332046406086443448767298655226522786685511031384602322251464988942315474592768020948704552969250388174426697733005815698500285576084348657180234667772665672224649309035191988841439951539719672753703757656633080728573515972292,2010796810968504378931299158317582090146742925585241000850486049458701149088072887117382202081460750175074877155829037914121263394655667323321997117300425990805089503958548860857023509792455388955490579562907955528791083522774450681564161379845706643578690350999966442870934289738064461129972772676090524913,558321669961648887847428632824052548431625768519625138834794746205714201508858412984925892097351057558062620149468106508584560558388430324467000609767675063271492932614039773497135546738436362846803805003389182782828963768739992366197919348230812882254139576244708687275965273358081737826555824405654768290694|6826578859626734597480939133878569229694460186644971629457853526114421649076835335603573751879988329839397104649987465835398566386002039755592773568446984903389961798459390528478761929712163120494037385730792909171532085167309911050308445263496353865937264941597436020907055251736048076644006844409202248304,5916703632910582851125880793132408903816292476260991242513549737921610794279828040608017189829216974970365350284663821730060215581487763067707193344265376739551991053238254698337087591646614840450823227220261123886424801128338724411047128491092060105475853943890821103779036774500319107460531685286202841441,819164879939066316247739921674596158995075399415076526828586576697986820808489862654252316603348700696267835592140978359698748448462852314742485570195189002909951418034161212683212111469166114805395316595157859568773382000204444562394625047968122644730117571140576687713835978983039148632840884180063353321919|24525593055568742416097249604269483346856874441455178370798633512644823613408551383898889724136436641596007886888916843304556505396562460452498580122367837296026711996552032327466172455184570034171840642876125912558571322892683749487069829210684821264854566376842632617791479252532263566234814371052354893484,-1533308789349159850456496166928278185899248924637820082743446320631452265558278807739507468009525157831824183682096795742851767532204899527778707496003773066153051313109361171305769881696175185189326727846932831915940721252274125841396183853650527186995865126146441484052102425089961043364891055445991541807,227677657081722376213157149142023336288707753333770972277638057778548802624067098792373455123375286502620159760351354502534495438446400227420867854824820469572948638801811562066346273782346907474917163347261714943740349452378338981756888788776146521650040273657711500699241321825395413707817445618060462480902 +10002074125017355975599743151046242846511112798798396053226619327592735057422378177948114365284430939135093491265336806767482478919758311098907293451660632908142687429542305038471993566061112091142254674235636984969318093242303552823770654042157452160266396125764144057012639465935378258561790879307671193782,-2677875592705731980082114894429792995071386706298929334230749772186164127600272370546755010431170895608048375369668020170159823760294147973474095537503850192302837032131733237064875342982073993793395058782971441692000690573793255526540716486233592692407763281116363187020386252791667246848349317822548915689,648635985571325401692595356147567233561468612108663071405974903212101924183730392746938934107001054497457734923399698902258386855829500228588241165821030031659482670628135844118612829510920403042586089191580683729603024542404607259365592152472123612035976391470864076397175842526847201114587386293478162448846|10002074125017355975599743151046242846511112798798396053226619327592735057422378177948114365284430939135093491265336806767482478919758311098907293451660632908142687429542305038471993566061112091142254674235636984969318093242303552823770654042157452160266396125764144057012639465935378258561790879307671193782,-2677875592705731980082114894429792995071386706298929334230749772186164127600272370546755010431170895608048375369668020170159823760294147973474095537503850192302837032131733237064875342982073993793395058782971441692000690573793255526540716486233592692407763281116363187020386252791667246848349317822548915689,648635985571325401692595356147567233561468612108663071405974903212101924183730392746938934107001054497457734923399698902258386855829500228588241165821030031659482670628135844118612829510920403042586089191580683729603024542404607259365592152472123612035976391470864076397175842526847201114587386293478162448846|67949938415113064293161178659030590691132496955041316494045733862875749417850747302562113500007310852668303846586641135508462313201852828769777121178050596003427926460422904475476244906898063142012649435038037100034350908875980928269206397866321214852019966694130786407505714074230941338096203488261864055662,53288668959102688425004591339691466327049075866255869214424335604117440952293373897678874847548640712084573721941183729796456325294146528429835461394439973255133211226526484818899123041166158632993340470979352834271983572524972059884357370847142645448863117621210245351327485761671145696210503054900410821273,105899036571802576293359771771735244647493044658191270723159384029727618422730315689072753328136534522456073200532359330590111785906447289835484981246848193838501538977975954024004079425925298710095769756420575788761877694146481988831153103750420171232975154220500803062063592047512891980560706613446433318602 +1000253663479701075381410901780503799818388911512704954335021374915858764824090995263167708417293347017273433263645587016366542848367626143993424043714190337762737334693150155289579305664876408056173092807453213218218789600598025704962632695206955492435575043105375877466941810990278101450609180156411393563,66294252873466406327783927757894402143872047742685585398248434686370376436933447604037129338463580005900665059990247763362159976852149607009612276330769317942643706356713296053874697713940805071384498697200382739281769000631492714220560824564622672983217861541737814215572898066821664279189734871952442485,7449081821920052343907585734636804107890073716887030220252146886374375473495388497829441955869708386804952455148603275078999958645575875758803250484635047415319443379977946970239132988474813562402674036138638943113227930164450433318295035974410121827732702738775533740738542926454278142700154894632584181276846|1000253663479701075381410901780503799818388911512704954335021374915858764824090995263167708417293347017273433263645587016366542848367626143993424043714190337762737334693150155289579305664876408056173092807453213218218789600598025704962632695206955492435575043105375877466941810990278101450609180156411393563,66294252873466406327783927757894402143872047742685585398248434686370376436933447604037129338463580005900665059990247763362159976852149607009612276330769317942643706356713296053874697713940805071384498697200382739281769000631492714220560824564622672983217861541737814215572898066821664279189734871952442485,7449081821920052343907585734636804107890073716887030220252146886374375473495388497829441955869708386804952455148603275078999958645575875758803250484635047415319443379977946970239132988474813562402674036138638943113227930164450433318295035974410121827732702738775533740738542926454278142700154894632584181276846|24568037830590216352984530012697330969024585773239190902318728852976076281369516446912320948078334220155283803919583544158932277992855289960471883436534381687899324079630011764816867889328310023423094633012275199876596315083044545869380586009580913007036860399795245680314963399389559624688311082823805090231,5319068676363461453927187061672827259672166236556729558696928212559807675749791870496620364221934584448485936117599756917409724038460841591469075162277678937851596763739958878425260723977292640004766308405052660448827954872311329092739598965306131405515429262746842239243566030717413542127898656259746125971,303566913138393892567904204367686915490068122814370585780506941778399006742359108535463859108136357801343091343038391472615790503246239776473238906631454625779972045236751565874336398670607783613554147722203607531035833062634596664836955674449545888313212125443460195013735390947268982347767364377764736422042 +10002641226772515081987795211537787929272477458505554463354638964352971364408874452069546961937801811210947177338408164991078687591091465516969203874900752888301636133298179753283838003443413422949614854305289101035884523695670918489325845677592608946818353360132477183288514801318828834214935649039394032252,-8793160452550363276528664072517898739234784407606709040941098303790678596260001324417462973553168029853952326856848991111004093395583096302100461452777142804629182141499607986715453131122448708636069213611853518781262192482364818383993101471525466753092118188242931192181704912063647353300605222746836800483,492078265126922274690434467399394077805701275647322071646319840779745006934618899651871133218190471317339124114044099413606811819906582945782428482112475530640807894231223382852644187084233002016394775416098135698147532762509163053201184493973160623592655199338520312133914851239167130412730662124292772722504|10002641226772515081987795211537787929272477458505554463354638964352971364408874452069546961937801811210947177338408164991078687591091465516969203874900752888301636133298179753283838003443413422949614854305289101035884523695670918489325845677592608946818353360132477183288514801318828834214935649039394032252,-8793160452550363276528664072517898739234784407606709040941098303790678596260001324417462973553168029853952326856848991111004093395583096302100461452777142804629182141499607986715453131122448708636069213611853518781262192482364818383993101471525466753092118188242931192181704912063647353300605222746836800483,492078265126922274690434467399394077805701275647322071646319840779745006934618899651871133218190471317339124114044099413606811819906582945782428482112475530640807894231223382852644187084233002016394775416098135698147532762509163053201184493973160623592655199338520312133914851239167130412730662124292772722504|33269093498653459355911056721677057317009942094586213583836482429509057025072754420372439736248690513834971332175814464148672813487558426999636798377556094849446738441259743858358991688742216573871382813744898911570710319471125784318155373816902285919608190930249032332855663246217414413642466621378338134637,-10949330241414165733888189262458140426986707558351886540903470879800574033213186052244846799127577601176842705714647638204280400911455131674484085082600626371557414203990940725212684526037217982855212341310843343357217588085473017983047320842712153347738590477893040712557903922232099275263522420010197087053,148267471797952946823163847078479485183284021963476657656706944246030488584019895488346778002211592139277760491813666056346782934726026456786554441575227882221237740554377749215785707126496176370984922985820419829339644729974154901755996939823200818910973576565060260711661905159023290114040762532541467088824 +100032603932113584190385248548088424648269645571686859576017823592423034520849963520508387815309023735382902503732005885189155388332561494704539042592634007656219743816845911733895132144423102052942452746877943975353248517709377531317937542644854604549820822373960740354167669496547979026679046866602436687763,-99537978095529356699713913260068351078290498972088228356731296595606062051578098868796341286417844471545193824704430742131836251590438154579238324251435089098889846479244366361006756968943661462663756515208457066560709300104052348033879750430334191090716067038009316021882909761152311655341491437691827562957,100461141672958569681488420113742834080404730978030677210672600173957843011309217083950874294428866093615815291020711039763544235459696431813304652678133959812856917140520431023445877504376180839416510225066460002908711498876105285713692498849763216560421523587971326926569083287005470828615251682690932454480|100032603932113584190385248548088424648269645571686859576017823592423034520849963520508387815309023735382902503732005885189155388332561494704539042592634007656219743816845911733895132144423102052942452746877943975353248517709377531317937542644854604549820822373960740354167669496547979026679046866602436687763,-99537978095529356699713913260068351078290498972088228356731296595606062051578098868796341286417844471545193824704430742131836251590438154579238324251435089098889846479244366361006756968943661462663756515208457066560709300104052348033879750430334191090716067038009316021882909761152311655341491437691827562957,100461141672958569681488420113742834080404730978030677210672600173957843011309217083950874294428866093615815291020711039763544235459696431813304652678133959812856917140520431023445877504376180839416510225066460002908711498876105285713692498849763216560421523587971326926569083287005470828615251682690932454480|83415806280351408759589239958761219329310176984650613508633653230456890652830525586600995644504636518476026029385588047137454270096528621205370620292951275504650266248010650846690600983384462303830915876850693795019055500604246841544238285169828416374845816289496545562107780789460316448092131365832361151375,-74625562140946530658296843057459607794092129677035083950600450768713067569753818651802415894941493999582236546770594323673470134033058099517659971836561944651594028658674853294680303580112276880640835753725828631472628486095723473976221487197988748307970291488083264976555432132424815586850501052682570560083,107469811246399151523671670639445335406080264077456915839785825558020206498489889359444002816596192076606675057819088885526103113392920720840544571898931473254561406865074149733521627542981016723238264871496686055481103379945620155327472162297506458535202575738651893005921523712726080367985636694514383291872 +10003476324006195750203056589672528920142608070881173628253070002202847822896965018507956629750620754180015153597378490052619698657641883238019501085375230761464051022240631149609917748136390010621917552270797301343624990317089853119601059038653584566960989367701622621948512038032835888249299441269693147481,8948477894687501835769347042476812359286265266925800130378128090450514350343716170849427570408163707014128103924229513747579348337292452228930399170228437675863524232253003114523522760158376999688617602181401251377230973508602086745348949552684443228687100653278976227886870750067529496753791759215379958009,452977737155070764205462061852384767406000511527628419268926246340664360293838298755195741559726771936393803381121945775594031166662560564547853061983512305458290529662211961236299108870033900884457317683226459798783650763565076645131166564022405125204306354508519035128680777341173496414054336245228904798396|10003476324006195750203056589672528920142608070881173628253070002202847822896965018507956629750620754180015153597378490052619698657641883238019501085375230761464051022240631149609917748136390010621917552270797301343624990317089853119601059038653584566960989367701622621948512038032835888249299441269693147481,8948477894687501835769347042476812359286265266925800130378128090450514350343716170849427570408163707014128103924229513747579348337292452228930399170228437675863524232253003114523522760158376999688617602181401251377230973508602086745348949552684443228687100653278976227886870750067529496753791759215379958009,452977737155070764205462061852384767406000511527628419268926246340664360293838298755195741559726771936393803381121945775594031166662560564547853061983512305458290529662211961236299108870033900884457317683226459798783650763565076645131166564022405125204306354508519035128680777341173496414054336245228904798396|5651402082864001341383043857276519034370923662130513841623791595519661596270558403629904832806805434101124739144545597592273345291679321664787896528184481483087832442891723960004144034071036416654549567647433046035924426144596821847342448417665300158067728473706875334422169591609969538712389716925515442159,1090636869023214934530000512317584955330428598448445756182897777909589608376391586933678383330159027516570062459675025398064909568706408769200853022274439337235651672149891920445243421589467522791785184925567074521782213195039081340473683210796200673383772228925769534634646704414996683315287011695982045215,798320586788500330131894474104550120349737015590338005277237799938184156294041064946603812109197024144698401875127120433554460509300984485272200798966972702950997831115495437993447800151856526214460125938349981191215783025651707239371732305323555609927700663473758594406982664526774948117622844814657936546368 +10003857993456427654260743531593175331844381828365670865226962439897092670436459982112189381696267158765639464830025128699564487196364496581401927783840749033897594251479939418637644343310965529659395490594160241233118920895398385679767173659034336248678548857485551806702464695049628038493630764757131936433,499412956562517742917849279756715433309262335746117865845799881793024584024558389384536935608560698495018673505480555335883339312289660314988198774876439555916228389426783735627572745304130362478355104078356335948823975431983850031098878540627311553089477219658101715631431867688289331308014437329410794367,428065574132217643458625663050023831718642242887566540643235772550790937328471994487142052675941441071975523602876098842203000859003355118835451924426231099194913042875268766884651796522017073832982218720474562973379560560341143898312656272368395693435837758889298389279644428917154166725285871991579086938078|10003857993456427654260743531593175331844381828365670865226962439897092670436459982112189381696267158765639464830025128699564487196364496581401927783840749033897594251479939418637644343310965529659395490594160241233118920895398385679767173659034336248678548857485551806702464695049628038493630764757131936433,499412956562517742917849279756715433309262335746117865845799881793024584024558389384536935608560698495018673505480555335883339312289660314988198774876439555916228389426783735627572745304130362478355104078356335948823975431983850031098878540627311553089477219658101715631431867688289331308014437329410794367,428065574132217643458625663050023831718642242887566540643235772550790937328471994487142052675941441071975523602876098842203000859003355118835451924426231099194913042875268766884651796522017073832982218720474562973379560560341143898312656272368395693435837758889298389279644428917154166725285871991579086938078|5985067419244985135241171028798929574240680468883302468191968098879216438700233164875805694297003438862738484975665356224507623680806342430269752869889205306990703427045634087633153837909332034829737848013329051690528535659192743560129505700514703339932109459152656849997168043791609090148125676966411164474,-3013789663785982033470828503772197819235935022596925513202295899674251698616743229507943605240952571134961898221616756365279257136756498538053825862952363683344784599061589171181375336294364884944425024815089748650913141333142482818080242503626668488451409454453378105252995530177887117956522924628476106577,715867557387629444794828253143137494171652360384349041477991757900406478237922421388389881678979412011018924778952400351577186261046593876844081918575484239857072969176632122684840733871691016063878843026835488228409619596420110671483199617250854032506474798364927317129700200264636864303167131823097056257391 +100039629164915279615632745626755403195135344051296300065703707540722103090866387847978086519807842461360227602981314815898651188162817881999812578911179147999641525372151514639575701701027057192828570924656410854140601616073626299097374452319600612002632648030238739679305929396591878384845108611708173073473,-99956757702796747144330474031362091634322580823618978945421296776762235722820502139320048823797118970112849105309821058917042066320137328941305079762427354700730983116887319872947138001541985096571674792479594585340751798952938060950882542376800246430517653157385999869147535721348848735105635711972964679549,102428094420528235210038473992722778047449595066683562474358311327561453376741151333873834215335094090938635116665776111534217214948922896682406927145735733279560659220902423840693623822669973775960053647983979336042821226775972118591820157680473747907152458057697531888053067296726895267408102940444171410942|100039629164915279615632745626755403195135344051296300065703707540722103090866387847978086519807842461360227602981314815898651188162817881999812578911179147999641525372151514639575701701027057192828570924656410854140601616073626299097374452319600612002632648030238739679305929396591878384845108611708173073473,-99956757702796747144330474031362091634322580823618978945421296776762235722820502139320048823797118970112849105309821058917042066320137328941305079762427354700730983116887319872947138001541985096571674792479594585340751798952938060950882542376800246430517653157385999869147535721348848735105635711972964679549,102428094420528235210038473992722778047449595066683562474358311327561453376741151333873834215335094090938635116665776111534217214948922896682406927145735733279560659220902423840693623822669973775960053647983979336042821226775972118591820157680473747907152458057697531888053067296726895267408102940444171410942|59758487461561694442379025688208789272805646117766841371919206129104643340187013959248829747415979662207515324483234883850993532329266696739297473585807619628400010464577117227971680163239657561855113693233183544551556435408658445465178524557249837569329921343630595316681776567395248915519114258200940556334,-22671153376331064045596883212849524458683137875144383539728632975135493675352244172470558064096651200683764074233134897430860850593927295220691708458835598930765635309529560060316074048705829611628256591181426206810132007799209323907835404383161225433151628885627129593154801395506335278453552670824539376361,131822706075099232761447085662042248387269214384273446870979850351593187356535380305031128889463232587293325792397508871970239127171842305342534211852386333093595103295196214505820601536505750244236747510387243858827641299979267104558491688743963318805624534666949772263803599250156326714304699457238299478944 +10004832714804908103723742535198592770160203517705805986990840545592954373052531534772757807185128680232142411531940850138353354052288042367716414491900227710660117192168358032143450533265736882961031789512953512836372805323721228539257249690634554067409180163736018674169229333523619015614939108311094404955,-4106122534013672070279170985250180991164806091813516237606357362858804809149171076685686783446662860787711693312632306442369721226548746949829113367814838200945066703674460902843843266912498986340273761329459609877828321975866552396500360382623866557971900410837449507727615090091955001901337773500512564083,735528321490864741305341471765335107420487103909921951579694743548116478766357351448185791472115882125120532716552174779001460694927011404974670401193452353207309236668713919095870342289746072100419468138261516298395168201040490324057099586440436334562163475983175689744239719212727501982130267247535538654526|10004832714804908103723742535198592770160203517705805986990840545592954373052531534772757807185128680232142411531940850138353354052288042367716414491900227710660117192168358032143450533265736882961031789512953512836372805323721228539257249690634554067409180163736018674169229333523619015614939108311094404955,-4106122534013672070279170985250180991164806091813516237606357362858804809149171076685686783446662860787711693312632306442369721226548746949829113367814838200945066703674460902843843266912498986340273761329459609877828321975866552396500360382623866557971900410837449507727615090091955001901337773500512564083,735528321490864741305341471765335107420487103909921951579694743548116478766357351448185791472115882125120532716552174779001460694927011404974670401193452353207309236668713919095870342289746072100419468138261516298395168201040490324057099586440436334562163475983175689744239719212727501982130267247535538654526|49571248488801947323762143907209086317313166403240424924024453432101823875387693931106394388064932448674243115016411805337571297304108452331736192767907165219921775519019524307831072755876229558621548399009624087618962075649066655387832586784423916396427426550173498305707525522262009377144776100617511504479,-29828959784506381554151288596212589266056524896738496309595862456247322273883550277461362725785642216517361460931008602989968457887994880159243708746757201494721079152033527869271494859280160324467867179845744346034683576782637256359631403582150391967236780147449482496203963125132702633751829108018063107905,152851999786112534607728017818026345885853920855328921975341927606898018268835818661916681924713268354620755264611816045133624308753790454966902035653944158070765154497702110731650604894939030177902410742021315843443639601716505769494787447868225921446367758854610060178076102048397807948745556177069401434816 +10005026798525081885012940723882427584501711356233986451433820326862561577003483273848888665415005023331324845917111198606297565890343057122006058437816088078150993643095110440273546307247953190370321453395387856022986496964659738868016549698302294761145902566546443562453064814285197415999088360521895892448,-2012773415393071452341702894100369945009950648974284842979647951404344133571843387257391629610481617222572984474542523680934261770552452770758419481294248980432288030428538457156536090278813518012614750771478130023297469887908317305397718948039728500945544029263259198696111632370324283021118376979818613221,535224191733498084376882360698126323023228440191548650672747703583096856785431353632400792141685069598130344590929419053715450660967162173014581599286976146407034427713180051638727241035734570695485508350936098840329272631647750135734419630658939038108543820389342159392044477918576834926838103968922627914592|10005026798525081885012940723882427584501711356233986451433820326862561577003483273848888665415005023331324845917111198606297565890343057122006058437816088078150993643095110440273546307247953190370321453395387856022986496964659738868016549698302294761145902566546443562453064814285197415999088360521895892448,-2012773415393071452341702894100369945009950648974284842979647951404344133571843387257391629610481617222572984474542523680934261770552452770758419481294248980432288030428538457156536090278813518012614750771478130023297469887908317305397718948039728500945544029263259198696111632370324283021118376979818613221,535224191733498084376882360698126323023228440191548650672747703583096856785431353632400792141685069598130344590929419053715450660967162173014581599286976146407034427713180051638727241035734570695485508350936098840329272631647750135734419630658939038108543820389342159392044477918576834926838103968922627914592|22336292342012135551012779505885821083546735296581603650297115029465681138287871430168423025904988089547671399414611655350486697669350669877738276496552244732628186316333718561702084292478964766694437983324796248956801158028485684181499933232337147261336601523192790302252474972512181980447183622505293176152,-11674427075188626733931744428592651339949229796533683950532721050654863919331228509781516498261584604218739331608896593403871873856541410150113580209210756699310754431102708096662231135908839829374052715278169746619957236796967122303020947804850902024480676480363166504231340429878256710974972888619078138229,241221441172507985920847839600569201674621990755660781190984844223834501365279182693592593623964679309297220103180052193705500388401906318363940879681334805954355205327811300356578283407461158222974345862172435329520610152326479352290565487656045066487426033103805627728579179611865031310778705197856088085583 +10006672794990347502279526000879267078734551177313370372283212271611928222796898904661389050998596001740140300896360857122349676163698172929644657861948036337955651058773337605834505825285215111994884147090626904932283811767278804138486301736275150746935294318794069137540121225700303083939876242601120625682,-9838237801085818249924597009069669407425270661770560087620729925196161025957715438545136585598174869667669532449305460474170293173380362768481774634876936899174710462784386243070041206971463923591073715195084153396862556329146939171493281676244388685209328525900813769124322086835985741784348578408662428059,491155226409710325351546145673359292444301383692142579605004960553566299358747456958419756937691174297624212871558627081110141997099054271399339089662075140351079784991312987158527194379830582795343003721494456884032748354538831215203553329779263289722351779436025499608302937937453427548391343898256662436681|10006672794990347502279526000879267078734551177313370372283212271611928222796898904661389050998596001740140300896360857122349676163698172929644657861948036337955651058773337605834505825285215111994884147090626904932283811767278804138486301736275150746935294318794069137540121225700303083939876242601120625682,-9838237801085818249924597009069669407425270661770560087620729925196161025957715438545136585598174869667669532449305460474170293173380362768481774634876936899174710462784386243070041206971463923591073715195084153396862556329146939171493281676244388685209328525900813769124322086835985741784348578408662428059,491155226409710325351546145673359292444301383692142579605004960553566299358747456958419756937691174297624212871558627081110141997099054271399339089662075140351079784991312987158527194379830582795343003721494456884032748354538831215203553329779263289722351779436025499608302937937453427548391343898256662436681|31407608254280798910068647236171832681250921019767339322092058225211898617080663268645257485291372241381998253211825069099135787304279471888561584499577479790815455728926265455210044341705458408895536936732959677488304976642419035897631658694309182269500334892813396007185893728237634667266625229835842258012,-22092195466303851660176460286320107196721548719910482849923927669374860570040607441847880914766942886335893807802817619964909625774361248243281497972957437956640995020582500875700785617741050040570062784832399237969854446892064368205401494750753136317996032567462911904310221537322445611817601703460856421217,159599806073129555202146898538117276396235868652725582464386632067108341746813360586970644466851546908557689300426749066266037355857824949308514825360431584985378792225819436535456535877098069496677684472533670862820828085751117871568305588734769334428789980131666205325600082215182496839515396421731764800737 +10007655975072154117483238977535537637081635031134550457387493208328357153313126763724056490057039627482071052486779071595119245261713445964779121986765033599055846695490518512461118572219672259974233020703702627262496120864385268977830794693731299984872419878272800221037178910859958719636556859814167846842,-8361996877393239419962455468169075798408150795370677399435249551651328619535668258497248839588331109071829636371568824578953377032648893445576430394495769342785817892484051892349027624952023346102193243274713308717688268734992258026540569970994360123565176304254781068869111211172521527332383420931814632155,527575030718114283859783398581144142162250986653324445494333022369741458612967189239531512810665999743981788039851897018720856433180698951454061341786291502239652788707044944021930279936172715091766668769968367606820938741461139670556714129528610125247077397188304136573449554427712758172626387820770141650206|10007655975072154117483238977535537637081635031134550457387493208328357153313126763724056490057039627482071052486779071595119245261713445964779121986765033599055846695490518512461118572219672259974233020703702627262496120864385268977830794693731299984872419878272800221037178910859958719636556859814167846842,-8361996877393239419962455468169075798408150795370677399435249551651328619535668258497248839588331109071829636371568824578953377032648893445576430394495769342785817892484051892349027624952023346102193243274713308717688268734992258026540569970994360123565176304254781068869111211172521527332383420931814632155,527575030718114283859783398581144142162250986653324445494333022369741458612967189239531512810665999743981788039851897018720856433180698951454061341786291502239652788707044944021930279936172715091766668769968367606820938741461139670556714129528610125247077397188304136573449554427712758172626387820770141650206|34241072322144183964883259292388971270387490908021459682602920713448556112203521610314068181522265567865990070656464669642401927077378188525809052299062988871029831250362663444310773841166814396928628138166361702759595641474414467093470838454994055079747035830130336863078894622890889652436509718402679470062,1655044484629008994406707658240182084237566731635262662670986570402287449045651466425429233810999012995111207637792772902737734854633738760139439026788661518884592067665179528199667479368791803292009159500093938626059289257062277449763464663360562677734593664715953368375153510854218241931074507165471380277,153704107279914282661047729774770107006301606465000116416112632832793659221845961744254897413922500063463878032418234980336383112232225712099359203910269544199247014938285831933417628129448739918915220344920675471322163945672122675565456045357008398369947791399948189771245653263744530465795945375711800221494 +10007966435478170058236863959453072022400241955644959598691575049123018331553853255192930054734316870465371869338898000445140839711278341717767617282979890871322011741629926128943966839416929813730135095452717804664810492420201325502018871240152164282158649420833075991948508448454814819879697083763652090752,7668231477440831839423530692551370703245159224024821557501520508935072774934016430350932340192015949812739085292897564854127442271354000519287430094037838940253057942410525639491576166138997981100229304259461266977184946214511723634011266273522059488169041964372462366036564169749432744133670979109152595493,447718029574060000854039425364603339241323607028045749886344661853336043472604487444001370995744392053933719052361283419535725001600963164946166051448582948801443754508763343722896658178932382756498803522119159379373755295799841416904795415386643502857959662236798809639975132008241096398997653679085633708897|10007966435478170058236863959453072022400241955644959598691575049123018331553853255192930054734316870465371869338898000445140839711278341717767617282979890871322011741629926128943966839416929813730135095452717804664810492420201325502018871240152164282158649420833075991948508448454814819879697083763652090752,7668231477440831839423530692551370703245159224024821557501520508935072774934016430350932340192015949812739085292897564854127442271354000519287430094037838940253057942410525639491576166138997981100229304259461266977184946214511723634011266273522059488169041964372462366036564169749432744133670979109152595493,447718029574060000854039425364603339241323607028045749886344661853336043472604487444001370995744392053933719052361283419535725001600963164946166051448582948801443754508763343722896658178932382756498803522119159379373755295799841416904795415386643502857959662236798809639975132008241096398997653679085633708897|40511141969971494931196941724119791194752303140317604712667802312789797258087471388916305711860938934695113621471555129205767772174234194577636062024449049659844773057153826765602668788474097413358584157199226050803019714953337366130977602640661927789662051175267419967969752702153115129111296636218703221612,-10457935161594282983478001185436442312204066321569717319909561123122508532580035425990850447859762708795499274494409851573173766858979090795797351580839052039648316518437023326040967891533445612383815607198257699325318317220032705269084861881246335591645639989108557010113256147197407668582018981690523309277,110917353905486580092614272588489684725195855203152146381960572034045032865176004516881779898341056044802327638909692940931520745099129277448149432184154526338845672459752333598562775198340962552587031950250223610238795938815226253408453715102541267901432200534831078606195360844918970056237910632079232669397 +10008244313737062814090386880777002042274406310106728621588663972235471114422710824990333652789716385198940169070112715764189602790244309290680116655115170883594213904067142922764109544956215574952085160301875958128721493047843010586892757750339772804652221926614373576181872540979939178502806140149454950631,-2481333037464667013966629436643252131544342493286852105020088420979287811035788180793459525355154058635281869829040750298007562342275673082167816644462962921681726865943832615136603374637684966019868013077849325437190351276393203980513956812271998916894664710817164796538864396449149557648172823426916063171,517388856778664723601259064328056938198839891258102587545663260307743028813773980886782766877880248247356976487931222165792012525513693034189039784629831615801247177080220119155265743113547860287043754078724492811312457109356002302194457816150319735657096232303313256118001093875043014711306978887626524797260|10008244313737062814090386880777002042274406310106728621588663972235471114422710824990333652789716385198940169070112715764189602790244309290680116655115170883594213904067142922764109544956215574952085160301875958128721493047843010586892757750339772804652221926614373576181872540979939178502806140149454950631,-2481333037464667013966629436643252131544342493286852105020088420979287811035788180793459525355154058635281869829040750298007562342275673082167816644462962921681726865943832615136603374637684966019868013077849325437190351276393203980513956812271998916894664710817164796538864396449149557648172823426916063171,517388856778664723601259064328056938198839891258102587545663260307743028813773980886782766877880248247356976487931222165792012525513693034189039784629831615801247177080220119155265743113547860287043754078724492811312457109356002302194457816150319735657096232303313256118001093875043014711306978887626524797260|64779254867032834011440641150787867084487920384040666681242863744168381419066139445297813847374258248415619741363374551837200937516385938256833819108665346550630274436247175069020139650724403378810927075885582938267576954742862532587966930483553143703545329576408261048628895456023143683431401990598479630366,24927519754546965921961831708915463327214053646451495956699845075284971443847002280078538714647321447563383780925628397892739377674787824980025060340980938596623558107083184245064110657008379362919768477366918649506291628246060968841505524504481964062641513562929769991452205428879332678008403472520391251145,82309686205222727769575596923556209136176331852352419263671129190093456370915941776219688571948801625823542691573133895930427074460493264530457559070546811793879069016319253690636501038391024472030629593224593147217100960263693987497514077967804017050957134551364124670419141176242216681820543629095623072541 +10008352850657920583191404584913972319002983012580386292746025042416454380781500166787911252581886951373899680476686789855174455691633284341038191233672952065406558892215211615248443825941676410729187290225060888418790745853338806784833379906941049072152726050837490871126796612653775780560679723194628349029,-9709060422739575026005372809573612137660920177893029425373199378974797630708961048789082569968621509437270608151157000245230087521990222886335775421061577025607819009612244487407314145511220306148818899675596604132364981950337516654200767452148218615182517964628917157152074917236803799933149738760713914115,671115082942262350108425488433280481526339397188879799636007596624691786030758042881307602706684291172315374822828497006497958099138318651797094407888149790626224845978208367284081376364107905539290535619502916118224586762249253502377439399087435554291997555942600131361589961111751560971988821471576625969886|10008352850657920583191404584913972319002983012580386292746025042416454380781500166787911252581886951373899680476686789855174455691633284341038191233672952065406558892215211615248443825941676410729187290225060888418790745853338806784833379906941049072152726050837490871126796612653775780560679723194628349029,-9709060422739575026005372809573612137660920177893029425373199378974797630708961048789082569968621509437270608151157000245230087521990222886335775421061577025607819009612244487407314145511220306148818899675596604132364981950337516654200767452148218615182517964628917157152074917236803799933149738760713914115,671115082942262350108425488433280481526339397188879799636007596624691786030758042881307602706684291172315374822828497006497958099138318651797094407888149790626224845978208367284081376364107905539290535619502916118224586762249253502377439399087435554291997555942600131361589961111751560971988821471576625969886|16114275461489124968204609015452254643913218363912153828520620336762113684215205643094736684144935580728436126433843432822838401301502605946365466722979644980151185661620762014580187078928560591048729719792010275975517300898462040047538702188845074821092289043342754604938854931775373800424648368644203310763,13547284929895770484441101131779787363607604008853234716726800689182086390631494419380414868563006093483607315075063367989733593307441496946636597309123175793027336201138908596859844194042146843338047555922226658114601025214153360367295508810902077991437858537936819515034120605401664389985997179289268252367,418205108772032981216907044691421436420223410030163644353520139623926934302604091399665635789664245218369914570143791026851295152484545480995319870729672449287479092631425718630481935403940901614139408947960419781742920397934070995211934874602805252466775364873888815295833211854864682623780313523183909895620 +10008513012069041332156344897527216827073553214887592180214088737934259014714007486627977262733380816543933881903835772165306652083392244023687978336905351870998572186485570559256669905157006164174099943880073052263685924132434457096891529676454801384608866315724043225840413063557160938985851639441472622874,4312440429846754396035977404383353442711216523950513352151701783462030788529545110163564186199448542666033789397218053312248834710387435083551347290942668449155398673665487605130911092851155993391138549740383991056332072450757325017931588809593307558375428030693435084458386227675282989067613496797817920303,522058710434436061847099419719287842052400501259816466826452187248685474462894015989166683733824910524432920930163132078895575756633553848962708405953874665062957204347147145554667232000278570561581943016274309565656027423053224928776350261510971295444303769013653510888595366416887399411638422346190508715452|10008513012069041332156344897527216827073553214887592180214088737934259014714007486627977262733380816543933881903835772165306652083392244023687978336905351870998572186485570559256669905157006164174099943880073052263685924132434457096891529676454801384608866315724043225840413063557160938985851639441472622874,4312440429846754396035977404383353442711216523950513352151701783462030788529545110163564186199448542666033789397218053312248834710387435083551347290942668449155398673665487605130911092851155993391138549740383991056332072450757325017931588809593307558375428030693435084458386227675282989067613496797817920303,522058710434436061847099419719287842052400501259816466826452187248685474462894015989166683733824910524432920930163132078895575756633553848962708405953874665062957204347147145554667232000278570561581943016274309565656027423053224928776350261510971295444303769013653510888595366416887399411638422346190508715452|56624718412625747746001342620243125157932460809156476585686153252078788391585133765039303843105555487145302765475232301210334902069549060211140618709834572969221737838704380629832808447436726398836532031324189279819743594568958857642880728907272717965484249241620624993448126533648876371412676969976240808091,11251560979241989333315174860442827950692807971893794693178074029555222489351465658673586544289854384482236484135520000810924047294537285452423708542539424019529971512734796753346419671011832872098038047241101770150064698634673955572614027093346044433647412285209492755021945840975963737352969268461227245507,92751569706316371333649854241258112606711033359078430605766627827390581284909646252513959841970681664755979852330064323247275252913920697545008377769665486889671185641317526987823359091775252097776601502427528886408060350050959249578998479135473207338710170069765535652326679605884886200884837141964865764438 +10008863920545293758159888428446364046156260276486716019468090049016703539043486840953638396736429084536043888977532647111473229479529562166982909202873868243789742163658153824593686536088450915373691535781953841623992587097366077922476705574496276542011226471851020760887612018025249445972903686455787297913,2645740853855108763896589086717998001934973089513790734148937968197932490008236360599464772889429848037464262397763532307275971891237738829761101393275168415676294997564886931379267812086428886706751772215615432393366054082725778686112559307784475932288658665407220266586240637350907136870607040913290590611,793400754874236243676721564968016542454513488899050997526586540816446069760957715423992612546686769171106427349384375943641326144133116588670645501231299064478777846694278704641598622565613076600211712243453441442617903127555189233115008530187155578099336294750097716133611190867259168037807083105588642566246|10008863920545293758159888428446364046156260276486716019468090049016703539043486840953638396736429084536043888977532647111473229479529562166982909202873868243789742163658153824593686536088450915373691535781953841623992587097366077922476705574496276542011226471851020760887612018025249445972903686455787297913,2645740853855108763896589086717998001934973089513790734148937968197932490008236360599464772889429848037464262397763532307275971891237738829761101393275168415676294997564886931379267812086428886706751772215615432393366054082725778686112559307784475932288658665407220266586240637350907136870607040913290590611,793400754874236243676721564968016542454513488899050997526586540816446069760957715423992612546686769171106427349384375943641326144133116588670645501231299064478777846694278704641598622565613076600211712243453441442617903127555189233115008530187155578099336294750097716133611190867259168037807083105588642566246|27460683971089209913632788439277008206698726108421557048449583612748157436343375175859322164187154644764726127789104341389062435393682455959407312665088265825287372841830854948020646918675509930411197475014852013755108095396665264198600695220092526372517655520066812589582003333706156211987354238157895214440,-18754257799889030610388359385148211437538401837086321292345976113516028840634213460141894145979065231860481969629551490782467029876512509259774443102990636739699402915097564612184570929798790707857065137355337741260683852677325380877763634549633686621832440525952151518844155190936539038380094790162128388423,292316854113502420768516012912807278549304319263771926401370626456917590670162968070277533769157336622178624301667258725748409713154982300194605653065586096039574795291737865145837966259393195694514901162748686464295686525957546330665390520676177065848461958642958875916650558856747431365214941153816669348325 +10009505680139870683354483014980979080857116598143181111545123603173294088551257446784978515102956309603131729036042239470868522730508351640411841336927180142285333130556003408088825172687266397290471685595705033772539426652454509785808561354205994913107889793645231496289597484325916247643676615653797810040,-3204245228048542338423395469208468824364162898707311656951717207097770099550386735738728259011638956652924858793824233816950950613612534337274326306432643930039092581092193180132506302083387198832944317276664858711681950020725043153356848379502277900787129851654969895020729278524823784274520152043485072291,452691911613679447746063326513639174263793060004909642518772775706171480163325072807358357220816303993075973139644460675947299910587502105955195991864534504547078402941938298035649970749378328953718405749778603278187778609058449113337901162098857859007739511955733974919843773983479386171581120876366473480535|10009505680139870683354483014980979080857116598143181111545123603173294088551257446784978515102956309603131729036042239470868522730508351640411841336927180142285333130556003408088825172687266397290471685595705033772539426652454509785808561354205994913107889793645231496289597484325916247643676615653797810040,-3204245228048542338423395469208468824364162898707311656951717207097770099550386735738728259011638956652924858793824233816950950613612534337274326306432643930039092581092193180132506302083387198832944317276664858711681950020725043153356848379502277900787129851654969895020729278524823784274520152043485072291,452691911613679447746063326513639174263793060004909642518772775706171480163325072807358357220816303993075973139644460675947299910587502105955195991864534504547078402941938298035649970749378328953718405749778603278187778609058449113337901162098857859007739511955733974919843773983479386171581120876366473480535|57325550832595720002282991260198520855619892385753125887287449562869890287547556782700649421653735594090065432438621527792246214244092693717739414731384442034231735428582082971424584764012096459469280873967739009228670210741931717901688698237272251048307176343047617528247235108742851430347676100126914108357,40951175564652222245195473979961933400303424050552593889813171845223826940735103640121837889061263540857785714549429721536079825338211400035410823730435714524768011703151474601155984454456549759808694516594213778747991012336774365782807914607474811422076337673527879293888167855766653181026300408358374972063,86312387529619002943462127766854108620725875072481894074267557421849877085810739137001331161310595596779531729111999016553742317053715695938778491822422663861385491102185170957066107188324354310777066756950531425606616940837381593339739089909995724195482868610730939023987110641593221757790669575104910938446 +1000951516029909402241580153254201911805533650981363847468064026947791885513152190496939080952901855372998038682278000380636609527998130327379270561313029246942896140134101369621908911346125374976926115893278132230058065500703131104226075681633220114919188893134454475954292791954736302126634675741318978601,-932129972046203740107893826647984861393190609401184260933369527488206703962436872059299754006964658145411135715285131543309666916261147162906324852866784469362588174806798886084835311322495644384917815753456114043848321591684728503353583125390553182460085266457044328481386164295062361453557198381234996483,7741880922056878066612714130026240867522108473639420974553105203701418374724364127305856418938534523230858044879263234730427059699274843010051016880192588782731180142670836033616687676672699018701220814586539096635490574816118709819174615703862984275251303192202153140463446907523629847791487096446425558516238|1000951516029909402241580153254201911805533650981363847468064026947791885513152190496939080952901855372998038682278000380636609527998130327379270561313029246942896140134101369621908911346125374976926115893278132230058065500703131104226075681633220114919188893134454475954292791954736302126634675741318978601,-932129972046203740107893826647984861393190609401184260933369527488206703962436872059299754006964658145411135715285131543309666916261147162906324852866784469362588174806798886084835311322495644384917815753456114043848321591684728503353583125390553182460085266457044328481386164295062361453557198381234996483,7741880922056878066612714130026240867522108473639420974553105203701418374724364127305856418938534523230858044879263234730427059699274843010051016880192588782731180142670836033616687676672699018701220814586539096635490574816118709819174615703862984275251303192202153140463446907523629847791487096446425558516238|15746368080076547639613112548931198412928034872598867786846558772081390410891968919792236071990423045407820022126215168896502300352310051471939494022340800892491023480415508952796942181491516127339639471207019480870149174572084740672853889392694282271865099892527052018243852819055812247442628083006705785149,-1817913436531155250968687681482056128774282329369952888473920830262042372654938097136436607889208234812116291336524382413655603485552821293038078939629653209114696856829043835764482596948782168253580822692634503701439593841617763234039276530741649509861202111285883608345674200240173376261557395276050534745,492167869580416546150864341469450817106189778801161330939305290046708175512988010176297694665433672849671984872726657705850871343875774836983621356338570200418265577466209423429850230482380970478840847989123705290014954835386530282830688430538273550828822069628430975922343455045834201595340872511606366704728 +10009614232615212022005150149343932420969657134336251266196874043830583063114875468409344410544755395263952674188421355541706476649104687178621105860662213481607819203924674901060643908339267017280510002551378392012520463262809409257654601850085574494274200629627329653203473234690149811173235149360768384838,836267856629353024976937718074908246524235283001080657657057590803147642759710349203535369107634985057019274642907780561827986871269168282562729482602832882014993174240061797035451659603107102838592209619951864142851506020290496133563766536500833473922797379921857659870104796371847757654270012370698502999,784213921791375719854653276558811892255578032965532623567863494564671611248783758720878204565462346000781224582747048981949572160149632172258392213554094289354008679022701865566865099047150582908470578815534139684037571258726801746576984534581957278215217261339431677162978264928931155436559875241964125506266|91259641317840920388592572245493602418223311736654347455817117920969722081887399519379251381184940824844626111264019221904601665534920622151118371387906395484279959508114917794568416938471005687918332893135141888811509257566326226278046422522746020345472499138217410394253037717517813153026786742476211897426,65560628471815349730768404773504307627679453655870244754876894481952096786914419991524915369113837577161059316635270325176467655387763062001209403412378388608286732350937986269983898741335821089925199082458466627097168531389395465235586971316043725352106687336132311388859476958068300601993983492409770068953,97787509018580500559531280765247530593654008165836933101614934455794219747727474184974783904602569289723706867556213004773348953706945069163461128745310430174496134494281188144065521418637123474052338785100571778752720085930925320282428718659058820028049740359320116709840549247824331580105759766861379891210|75062088452630474843888448210053283462706588708992115575383926339301467347310815006622009334498696501710113137263962332974627478074375539845396462501277814094889463218705190380441269364077952749970929670210201903809188825244244127139203763727765293010747505303529125943832432756718681546490336041697468666190,5541281329506174033291380410034395388042944047800558435987093009948507724655465795692214345462752044394730637949505190953507095375192582819240934021514991426264136507386865262105651669874195906257084096658225527132816732104755767839079135854552727988309212343735183861434005237105894184406202983254934534757,104675750550793205502943520352684154101269712315945996783868759572927470248283594480842218327785617106312969404704918354113342765451442832450177716298160659447475598063377646514258038986139271814855804490712610499304684910754302950004231911223315677097295880861233808821150324765848314271787214250899197923793 +10009735080309013514440203870605983374104835055250399704317172848646825795572764221124512471397022599041102696110601760496809311877056400885225531243115647095694305859001567326435058426543669680082356076887117616533496794600222886637873441727978976019755009690240085029104982970925792121991104293242809524644,6716504442878527910519807778046246423810093302344836517925018933141102172400301207571530237654753113978791017298256211048865142019514745459130820608857728114059755451415522450033212605102272496818594519931368393561070233092047087381778868100623694505448318327728934167707696920045126563192647607794472189195,721610628334648695598193480418084731432879897882901829331594044580759141755040057210356863808123513214754128306537665937117531576524824114459745892010308401743734165555223754018460218362992047097741240949227118743681363740856040612578898979577195958019157067541288613303223475902295909138865214617457058483843|10009735080309013514440203870605983374104835055250399704317172848646825795572764221124512471397022599041102696110601760496809311877056400885225531243115647095694305859001567326435058426543669680082356076887117616533496794600222886637873441727978976019755009690240085029104982970925792121991104293242809524644,6716504442878527910519807778046246423810093302344836517925018933141102172400301207571530237654753113978791017298256211048865142019514745459130820608857728114059755451415522450033212605102272496818594519931368393561070233092047087381778868100623694505448318327728934167707696920045126563192647607794472189195,721610628334648695598193480418084731432879897882901829331594044580759141755040057210356863808123513214754128306537665937117531576524824114459745892010308401743734165555223754018460218362992047097741240949227118743681363740856040612578898979577195958019157067541288613303223475902295909138865214617457058483843|27431399959730041618757181598450126761864467783308250953166653158864868050165660437728250584906458406104160649372946064796764756251284036703521851065427172085011598154374858106257477054034049690307574700876194576753048475242472071051384544187235302865991596395901667453599382886279428660852987448092730327814,-12178152192814077151051956033210165813331619111090720689608458837738277955478946125067643676733373652534546194632007566276305197498317660468910084573634326652156582085984031315753626693903214933704476608819110626280721237157346811918265527840918335083118991187163668918374733603234110068582400025069332861471,264256662843741154538126874284653325441730644362235064492791411891511464369737085603945845443869261733906715033378896197504349395743395072323232105722154314007209047495860245950090828739984743068229024820070744102308175917924790982043751500738655732108120833669083027766207125418432774798887679934336031211189 +100097767925729329322181122349613179670027446504792908817095637890752573498574361347439148152051968207056866825997618536117991814714859714673883034645066867063812091504212589938420469209673745687587262010655197327448038749016704401923718318821311108473542621283106029369259039074767836862058509435455755610726,-100049042457569505632055807384899059068938967940837318894350268996535213352709148936435708901083176589583550587767198440304487034715449239754368855557475044885723026390661018171437823688972174609609018769743817618355306963644565862125983532960059011062792908538954329635940471395263688377520252608542030523093,101825233069512741038457795802309532831632092007485080725676678162290037786417230184436300741781748657320031840082727976574819880666874823641143033563613526015930298529985774382970686476257558271965201142223855170907771875249088691707619925926120372987467772228909661019762594761741996613700919454999805975044|100097767925729329322181122349613179670027446504792908817095637890752573498574361347439148152051968207056866825997618536117991814714859714673883034645066867063812091504212589938420469209673745687587262010655197327448038749016704401923718318821311108473542621283106029369259039074767836862058509435455755610726,-100049042457569505632055807384899059068938967940837318894350268996535213352709148936435708901083176589583550587767198440304487034715449239754368855557475044885723026390661018171437823688972174609609018769743817618355306963644565862125983532960059011062792908538954329635940471395263688377520252608542030523093,101825233069512741038457795802309532831632092007485080725676678162290037786417230184436300741781748657320031840082727976574819880666874823641143033563613526015930298529985774382970686476257558271965201142223855170907771875249088691707619925926120372987467772228909661019762594761741996613700919454999805975044|84308318710770953640248175476462028139373764391035194691231680218526343685551415536853656437464155941615590227223191821309564306137129412203074445224501367988293836354108333795252385654176431244360276218862523025987282479232565449230085787098609814824691928891608841637881937218976744434331438048491668714172,78229471895771291032128733343240907956513700512674961776679342047382405281968278678548353708794851883965121941126776164617402656831058062037098035411278996202926380143407188337949264849125051865072631849969234447888440699755954052452126159543200468837557873802507174337535425627611660644229281086936050355075,109360363649395746265656497473367613906192696966623732296103764282264963662145240362278977792876351026988778202744708027814748063715992412060773465595050876884872367497101878287000352814221891140816680001766329736587915177644869655423120132329944663172310205372239088325795595410385678741576083941746461375629 +1000990088197024747059083499592558231720263720277516776155079181049136503434198702340667607714363713879340855424897665647049377714485771691188931707633550660945052279457196551479047254741496420585602556120439906566870228385196796680534214981451257503126475671546702014976009092407415021171352670275245814728,725466386677782932169006961452587026457506864587404408874444216403861787891316322821563900402539391905854377725716394516795127638578550566829765062852138101610829715414344025748861390095121907615243675775588453320217679236986850051456109259336757301010447881360582473998540771452509411313781955577190588933,5517508390471385461294072894661016222336566054567430728481305159339660984012399389945095200514405410813099792232460346983221900276173777626934161693012967410321899909279792957271372152068664807744591895618427921351514391226515490690862669088614356482368865242803422288159831017511240290921861425877221350767081|1000990088197024747059083499592558231720263720277516776155079181049136503434198702340667607714363713879340855424897665647049377714485771691188931707633550660945052279457196551479047254741496420585602556120439906566870228385196796680534214981451257503126475671546702014976009092407415021171352670275245814728,725466386677782932169006961452587026457506864587404408874444216403861787891316322821563900402539391905854377725716394516795127638578550566829765062852138101610829715414344025748861390095121907615243675775588453320217679236986850051456109259336757301010447881360582473998540771452509411313781955577190588933,5517508390471385461294072894661016222336566054567430728481305159339660984012399389945095200514405410813099792232460346983221900276173777626934161693012967410321899909279792957271372152068664807744591895618427921351514391226515490690862669088614356482368865242803422288159831017511240290921861425877221350767081|46386382398471210654004936862977280764038033260370855702299152174715903684807635787033726061221737095817373565974565953991423132816014499962739297327315390959305555345973541148973281098200177613839273688191655843120140926599099288046020383471244522466342336148402764983519506510433171993666037668400990623062,30909786208868059159308250284546387617592958673051467586322533557805038169619650467442753505158926723729781335720702109207080121759415266351938588413071223894526233303271669156163543157906212613065654926067039001367294657463422342698879421926602847752406836893005886958919719183994605725308548242138957881171,124210879529497457542798731661855988692615123385567383434289407838970666113795793650595394981286850762118704131523110658152541154934468138859842609878663166338576053338898592108554591614195107201143517584467526852469899754023757894264352510613574752993978429183938806214485060920755151052534935466538850750938 +10010004064090651409010594639848304417245586560948860214310742766846249258119176243618948796060231286565945627267454791543296430719743208401586187196864109595450365240377376347430379493062158659135705093920261708675191488141331016387425285934969492844933812420736541635790559026628543841128935951718908539896,-1498575286639922441240963650822632036400568058110825911189335188996116649771598943688044499782411654295552472829397529434461014441578505662359180553723401992140786537396607735356416120600823531080136067285152784381639454281243980298334520221160338176676576774798710776186339169032737324810281860916038070823,768468744922072210410085870438045813460934852024069843981629956982064663744441536899640311347039303574749086761908444837858696612124820590763553776868490058405671131188766507451909827840059264627966884129949211264617246300058675643121776631374263858887287691658300066890342985411108805960696775940061827501049|10010004064090651409010594639848304417245586560948860214310742766846249258119176243618948796060231286565945627267454791543296430719743208401586187196864109595450365240377376347430379493062158659135705093920261708675191488141331016387425285934969492844933812420736541635790559026628543841128935951718908539896,-1498575286639922441240963650822632036400568058110825911189335188996116649771598943688044499782411654295552472829397529434461014441578505662359180553723401992140786537396607735356416120600823531080136067285152784381639454281243980298334520221160338176676576774798710776186339169032737324810281860916038070823,768468744922072210410085870438045813460934852024069843981629956982064663744441536899640311347039303574749086761908444837858696612124820590763553776868490058405671131188766507451909827840059264627966884129949211264617246300058675643121776631374263858887287691658300066890342985411108805960696775940061827501049|28314042997988233306636589016992476577770908296597830278146083272521268550372497996517202454826620755010065709821222609305573779332296860088326682557505516615132304908709189030516196077907461669993069872444768482204126654812645619744037494119483770734571472757955818228427379193994724836630122637837874512512,-3910830326710790111629753186982470489266159472894461132493344186147852161393575078274643639038642275689976708947162470525418556533103511874282953768387384089989557162835543128542264012421515524615699954054931189762734554550136613958599656445264920707571157499612722532218838749658906057952745224391208374423,271795782638036641105135359411824479015439355083041167763715963674151201738370794758665358014925962658456682314365819593590637317922383444961883165716906142863933218099402568928834160919844733051508148071302780085990761872080854429570287769745420760134784589649743625063761926379339662449726354233483569572692 +10010469709639397131321593392335940518221591944212653476848636010049901173327189141010003266402662587851391795365145565853592244249890218572600240492819519129624586319882991468883851157495158734614747790710618700576914513912845835699748008363226744953360119054075282875557290214809856164142199477757165509164,7505657900398833324827399204281082596119737445028635348485466721806081208043020690125518041418692182505619967598743043368451311836537618411006688337064144530591029793349206581566058245087905481171249541532084530428115422022022771262499445387394812364092046818720427959757560293344117843608115308687123143421,553113242511887630245562923692119334560619363555162251614925548023827683747558857060226873484593892808999168052131745589052836855443167606888604202950573221560622773360660465500305832700518144444548624823481416168401044677399877530532448619602616847965589554700283201541685397541240490155576228110029131773379|63201743899616470908035016615759783248572310773988939570648682086965508954735585744990615463863202134213890574490859916770336808958389758836363215334497075053557112818568576204445815232807749791417195377923291221271056534552496867547808556556792554364734430966783089440150789750091730879530896624414277659061,-55856955103087382729788364385235549210397677016869607285896429414455503436682728351867754944498329815149524455764192011560832811681933262606199210273482312024649522293283703849873542800068494104680666316436079341962770915103078184937312059708038123793720277348890693601123206211567358221715195838805665244815,99725721230004762208212433032530958477513183167215245049998941633413237167002350956483975841846292547322289722635488222088283425749457741260773683563042470151127137265045721725293085765918300826804733069413639039496778512157339321750973991239393851776816288547058721349853339439566413417882881431596395398482|10058483900212848371336105395105034597443877759659095074874545915088017898536154919284167493951088960283199509655255215299440632845548287448716500241460028925186589031890037337660582657444623147488470508614291087038125788600526809670994940639159256871538287711131658514500837340353796975836990505301624273881,-157799394991431658935500911446539445587307591494655221580870826914115793039596841571933100144135016253304167518063315606333327146563644719359095984750603598277704663545389186967829006269785943764149594510946914419779083189746476236548753466257639182993421200334901817261951648692278188884421732061466347929,549073390680838282030926276806663190640362547475399531148862958328951733805907419890212210186161292258493318221366553074237370828617692229205217240695895636477792753409007387702564155250318872755670718485591591748806803837858464359711143468897253705933551825195496604931204015549587680036788025676123194339726 +10010496751485016737255498721953568674323163915462879922384146496780957659766649785727318078913117215770623612059774196084160730194502430474210832948012098222392905483059314666266093994762308130821733627116456649448335020123456572070799012785074345756980230844151670979497392292798505519219012749959532875338,799688122820510610823764584829566759424107985411345815493636913295490164723810636027858758547620320075665083037412723404618585417481351642215686069179403481765070501469154817238059870792625025657772680475594951623612932084444307492923899340395814785386177783715246947669812896758158101579611206283404125383,756465676775987727565397432418408198121332665761199779426305954315978948084770158074763521327096161584122642931162604561074895576932338265005852611804594502809713943064130145585384616864112057298562543101439879468994210857521510834193578678095039312141817959445372442666042645305218271194929494814070515333525|10010496751485016737255498721953568674323163915462879922384146496780957659766649785727318078913117215770623612059774196084160730194502430474210832948012098222392905483059314666266093994762308130821733627116456649448335020123456572070799012785074345756980230844151670979497392292798505519219012749959532875338,799688122820510610823764584829566759424107985411345815493636913295490164723810636027858758547620320075665083037412723404618585417481351642215686069179403481765070501469154817238059870792625025657772680475594951623612932084444307492923899340395814785386177783715246947669812896758158101579611206283404125383,756465676775987727565397432418408198121332665761199779426305954315978948084770158074763521327096161584122642931162604561074895576932338265005852611804594502809713943064130145585384616864112057298562543101439879468994210857521510834193578678095039312141817959445372442666042645305218271194929494814070515333525|88526457805417802579401128655636200680578875592064917653502726799402631022732331707242469404309708934422669188417199074013672835521067841289769648786519913947468121765630841991231363845393790849492596901524640146832343923907202043034825750225542103503647484110551329413090031876302117118017242617457435270440,-55270872554503717308092985383981103433537850547649491053003970562528650386510337748001788465211336165026556518877922750831164872435215600571701093825986357449663403092607944719717658773706993903771608486872517959780200593880280040497747294339054563275578214457748886755324708980839180036767067720944832209613,94165686390158171873356770999242344439144784888928297429784348143756989501060133555039087406934644294830253094462126060631940792293289142829036758298101067851753964448066092115935075783351846337421975097419550731994478824011482838934049698582968608287926659413694080435137971696387627102349753238458722293238 +10010579112627452164700751672418124874438960016155391309411143579238371993812216949415371161492459719515415809121706298625750585115724165801767312632070537335293199529430577590690991572481217905708780746070115008642386973910356482808275744430781549387996153714070117005169542728240082244119738613459581149403,2350957735421970008675187616979703886327431020247822920032684793437439591770682963150195069182216167082120247951141628182676139493494439884424368912802413855370850694844333281369444099710260137140856858089878674493931790511953123605380418199403899915269505474711266010465371671818915910810005642457030207323,611423654589890839284741885001129722618409625326976389817674733477626186444470464645132913394627656053210319902647997769502456733804852681598112059600692683589494771437615834703370743285630660946188840487388799145726650756609808617614030574039934664771328233896579676781994740365464050319193605788676121096976|10010579112627452164700751672418124874438960016155391309411143579238371993812216949415371161492459719515415809121706298625750585115724165801767312632070537335293199529430577590690991572481217905708780746070115008642386973910356482808275744430781549387996153714070117005169542728240082244119738613459581149403,2350957735421970008675187616979703886327431020247822920032684793437439591770682963150195069182216167082120247951141628182676139493494439884424368912802413855370850694844333281369444099710260137140856858089878674493931790511953123605380418199403899915269505474711266010465371671818915910810005642457030207323,611423654589890839284741885001129722618409625326976389817674733477626186444470464645132913394627656053210319902647997769502456733804852681598112059600692683589494771437615834703370743285630660946188840487388799145726650756609808617614030574039934664771328233896579676781994740365464050319193605788676121096976|8039922802491265414309990967793279613501148402448480465019122506003939256870540144853780285033203931808455458595860030453208550342558408097242925918803433428637982781245121194507511100106884732787332881816376538778408183713312626895063525916116529477067428617194552870724443468826009500481151973572267660629,7782542056885878734681190877592906346631460224605439140627247356888850052165135682978538906914658013311431434956582299659243906965976772069489496351182726287233109256230929112390639759813836413367620416284403736856845659506160807594525033721234682734219240024280033734701579761670420320393555156688458386939,763000498381829086301710784279931419423976764939217073711509076091719761279556145759370750276614372372724227557071534934449510558501017918011817000937860419860520748646784487080323157808376840620794576624474012291138723116851111311356377966880000941424814810860193927148425226557672422373368027666445875216544 +10011186832308679529580531778689417394449477080570215256255872899524060756354513251052234139190381882237674326102549194541918465150411281044342531791718191209528218579215954684479017629118919205540336463087633388203942961094184672710469514635568862008937176486425382826532999400454876885123467677882356280867,-9760739041412831860016040329300538464595968662597654195818825742388623357499061055114241473465244979572894681398742727120008689894660036669893911021076723092236596538937507422477033501397620347314916527511417876669224922540378674704881346598392965888769411037021701309263621236037226524490335501235413158317,618797456627391285757491837806082074086781183030320963821992656495001963414332567515207750538267219197978733813073360730643354769504354220428586481088489050423524166052003546758616279336334294024003134192912678054276268653141558092399335706944717740861723542047714673114465932057975066598256237991004833528194|10011186832308679529580531778689417394449477080570215256255872899524060756354513251052234139190381882237674326102549194541918465150411281044342531791718191209528218579215954684479017629118919205540336463087633388203942961094184672710469514635568862008937176486425382826532999400454876885123467677882356280867,-9760739041412831860016040329300538464595968662597654195818825742388623357499061055114241473465244979572894681398742727120008689894660036669893911021076723092236596538937507422477033501397620347314916527511417876669224922540378674704881346598392965888769411037021701309263621236037226524490335501235413158317,618797456627391285757491837806082074086781183030320963821992656495001963414332567515207750538267219197978733813073360730643354769504354220428586481088489050423524166052003546758616279336334294024003134192912678054276268653141558092399335706944717740861723542047714673114465932057975066598256237991004833528194|16023810805641333724336357094511552886496985977223317205804900540875359074549841799895438359675279197334185032768159914670757201278192258514539721858337894442748764924011517017369466984819970583389409069776399176053947560735257602992978470081403520015409641979689232868403667818818613535419071872687266278871,-7532673756475565262302348084703438182578166716950696747316478761861175843795966574151023129542515752521204794815061142348575304950316771972303577053107419061405627955596801577300288807854600908796497666677601605740930719732644371749303298593761133443055158847238113190613766743442416892398264321417028494683,386004572289283022539377207289773679498488550299986782511093221618938108821853499898482934516175608928422720022347987369229961237741779367136076661442684969604660313702194515039707016073494920297591526290529740277402244949703587380758181579357976708139982649833967127198595634906215849970601175752843362414638 +10011352260197967961196723001882777157351136553686255118590538903088960848511094106778638364952379274889738636611531352467905470187088001978395724543759615578178012440339389212117360666565610883522821465968556183822388268042856072812425704980952391373927012924156734141733616109526841203308615171993851798580,-7221676671346271775547094631755878098073875121922187404285664906337078018452572717764275630077273635227060270555255283560769931807823554231983067592327106941484374528295871153247243771907559825959222732921231505238074239141672724791953035282099263068621712554135551648164407808630494744659356436708196075003,491103641942430897255353076452858177434280940975186423223949785500010643311551520732003340225232164561507795653594281473147298622615199173589020255105363616020518202959139902358320338695214760426102498591057589117988289772846024859991303086757574971564242450863802854515962057480781826855732055129393601722620|10011352260197967961196723001882777157351136553686255118590538903088960848511094106778638364952379274889738636611531352467905470187088001978395724543759615578178012440339389212117360666565610883522821465968556183822388268042856072812425704980952391373927012924156734141733616109526841203308615171993851798580,-7221676671346271775547094631755878098073875121922187404285664906337078018452572717764275630077273635227060270555255283560769931807823554231983067592327106941484374528295871153247243771907559825959222732921231505238074239141672724791953035282099263068621712554135551648164407808630494744659356436708196075003,491103641942430897255353076452858177434280940975186423223949785500010643311551520732003340225232164561507795653594281473147298622615199173589020255105363616020518202959139902358320338695214760426102498591057589117988289772846024859991303086757574971564242450863802854515962057480781826855732055129393601722620|47792242549528045573835222090102709180753366247917233792162207697772127315858077638348932444421521322861739464396186442116808539325522348191328660258855448870212049194866543072912231226457359914737534217070905308248553545640574239424386722275092722710319161088562287826715987711727881278079923845948791676890,8254269885969125051120540706292376386106399376632912551223385556280906209369492834220174830708813086153383708455555132979546664334186800724505969898808175578003259356450761612161617233904190263463404177018953974392386560633539661122851396041321655235390273818809845177966554527106703090511634271703426366333,102958270685953367083211535309354861429334576908033521565612066728144639011805671376037609804664223083707360606267980895711740633481159521495849279040716328723662579233841335201356070651023351445332747117601073346257424542725915546556026838056238556081287286460939074972020327613774707117438966240554700925838 +10011859648773232442448733215609838143695842496672408041181163963731715385957428830906426802116840506850796500226397482148532808790741216756533590408501689411024510944680051255986998627975919616236379312627952364824369227089618523233361113970064976301643797723660966748317498805671195280559795030489377669812,1389268097793948084201915587623858469968349389719030883277892933626050552994624565080658001697742466760286196070343106937791393185285082388402785127475337008454634105961822228566730985518119778298380464943436464040236734762976514693785454254940058632017513195975469702286256915116671279121716893380760195997,798259439380551890168577021365722645610234093426080631569938818141778075039283575889046619146360005141391892307832892070793699590106322160142086889812498495186005607708401945977916695847229243650515563078729723204186390753029064543583093290363210178756937751032079469629502953157831010865389293997646642560816|10011859648773232442448733215609838143695842496672408041181163963731715385957428830906426802116840506850796500226397482148532808790741216756533590408501689411024510944680051255986998627975919616236379312627952364824369227089618523233361113970064976301643797723660966748317498805671195280559795030489377669812,1389268097793948084201915587623858469968349389719030883277892933626050552994624565080658001697742466760286196070343106937791393185285082388402785127475337008454634105961822228566730985518119778298380464943436464040236734762976514693785454254940058632017513195975469702286256915116671279121716893380760195997,798259439380551890168577021365722645610234093426080631569938818141778075039283575889046619146360005141391892307832892070793699590106322160142086889812498495186005607708401945977916695847229243650515563078729723204186390753029064543583093290363210178756937751032079469629502953157831010865389293997646642560816|42206894030530619844844137895190664968269730414499521872109243265156383878372533066719066634351278056931106119952256575854241753055519807843572490047146976978089248439736200704784039417511594978273239033477711961360762067155137236184651290217781497985287933853456015958183471535758824703982061917287661765041,40970642478148233733033585114396071242748464687693709425944631778683899124773146938566992970029345645063087493796799166205427214444613129772321140093187953348169602638764727669726146858903079780374349625954437240902856681427277267635228715453381995681831199770224812459964590952867744306421769761996026104513,199285626990423651406783664663645910990492228214328517061400776387771491511391310851645339521126305819574623301901411324234792418046438608476979083398394165188934652648732128312553721596148859379616564443828216278968549632096439205379175627317399435861673444161870109940456991316291287290279435962880377080302 +10011942112859072995258791154733863477789940396938883213028206575320538554823437297402241742896497695874369416027516907850508925314968512498072222974096801648178807861791486753853486254133021354211722209138812867027895370716192265840613761606054294753819681190630045043947858812851889188252918713433862450937,-5571668968866828804921046721301654575883923332633233994134906673281267773210784380932788963105885600448276206900049033963090555880641132208787100277713410661373854250945949489885604664165828601242508315193830303811886340805084372525080806602568264342555171074951419758002241352180046540480238252242954050299,447717522759824444351173111605711384841786993787566688069178368722388364402515540644758414533643421974927299526439953604872416797996604293432960735663438930460329264500528581210531189312463600150764233828882749159851806734992346380036786298515789780808132282396713107095426662454069422796780131140784450873310|10011942112859072995258791154733863477789940396938883213028206575320538554823437297402241742896497695874369416027516907850508925314968512498072222974096801648178807861791486753853486254133021354211722209138812867027895370716192265840613761606054294753819681190630045043947858812851889188252918713433862450937,-5571668968866828804921046721301654575883923332633233994134906673281267773210784380932788963105885600448276206900049033963090555880641132208787100277713410661373854250945949489885604664165828601242508315193830303811886340805084372525080806602568264342555171074951419758002241352180046540480238252242954050299,447717522759824444351173111605711384841786993787566688069178368722388364402515540644758414533643421974927299526439953604872416797996604293432960735663438930460329264500528581210531189312463600150764233828882749159851806734992346380036786298515789780808132282396713107095426662454069422796780131140784450873310|27084975518223203685159476564968667757147005650320881882446538924664746760650597697153771281773275150298344920435750377585362202361041033907635631944580948271756519774659017735803323446011519248098440794538345241902148398434473456015090213973679829939390143526742895252747749904765235510343943624603085395760,-12790519385524034711380512698893130061457017090294213212099271214034680483663421242204264773620969593678221374876014811278470247764306480672296083402927981473695204988274213121345880281894543363725179804965957322222445321774678314607579703404237389600553993220560492758375020231080071561518133534954466259951,166721966963161057002408800656254458745347212698279982813080522419206471402712564010508086006697422863841361930966373632778322663543126671570353059325275245779405843551444614505569300692917404907917428765459530333591345110277642064762234238705296425159456946404870175457906061825086330206230526422507612458697 +10011955414042796957539613462833567748978021174979466353940011258968857683495843510716962870026112990120612239420094468274757074371715099897797764809018818677244411173050607051965491060861928470702220861911485527125770697960299381766502895029523905888655809759985815187019718331529320273577105879315557816044,-2903598288233181369386909069725761325455718972241715705067575929894098338713960225913955377920698582104810776546675110854231130224088963639880575858411672466883767586627134811452446768341259728766799505769981364639560814489840847334997666650046443822662727211952763808116443820225341403833059567092278686013,716711840847237503666263684416016435149389642949031161572660687058464860752744538837256522716160171257335781518708196625364621151126528577774399883526209845714231475374012476325785739496418344991482641972669482173664514234171584896006659617692101904655946713038460582513645370686741753929246439907983936752037|10011955414042796957539613462833567748978021174979466353940011258968857683495843510716962870026112990120612239420094468274757074371715099897797764809018818677244411173050607051965491060861928470702220861911485527125770697960299381766502895029523905888655809759985815187019718331529320273577105879315557816044,-2903598288233181369386909069725761325455718972241715705067575929894098338713960225913955377920698582104810776546675110854231130224088963639880575858411672466883767586627134811452446768341259728766799505769981364639560814489840847334997666650046443822662727211952763808116443820225341403833059567092278686013,716711840847237503666263684416016435149389642949031161572660687058464860752744538837256522716160171257335781518708196625364621151126528577774399883526209845714231475374012476325785739496418344991482641972669482173664514234171584896006659617692101904655946713038460582513645370686741753929246439907983936752037|83377818300427508414411209474182765418541299931790991979162498055814470115047955070666996621536705209820738216257135146862349180486198221400982101436215575798938096836021071281557720129695222554778979084677391347787960453403954349664348198928269790759939576077051077722913333980873848885097124565249932890109,-30688215255611971606034471669429848439589330363616017559694024730487742561639314516549592500671986661135255749032859202031979689977991786343363266117721953715761747898795102634113940122259396542403236218273245556434610755838474462460273735366438965428724794482250645649141152999575795556913839603294733616297,88860815315671630897460232604076507207530961201107386907073059232104245557771716637121266612833291311086440284416177092484049670682110328081485080434205469417936503447466464463362446293805166057694349242947508206617775986775538756539497474332372390720218420029346868304694279430904189373022716924576015411382 +10012228673376152026567450992902390970336864997567041834794435762949115261281228493411090141625349816927161690458296667158108080969724709444972658280448694411038715631967371509920701285876643071095813601274276803568595952200658716678278724478871970783503276566469041579910541903097002012017970816393023705126,-1525621196152714906745704861653134857598506051934926836340086172347518826544771422485438019089512861580045344082067612865732790885320087313117232977161635917848068594652072218066650842997301426696286712170439049522381084448274527064469835335059461198790200539335886996343589558210546809155519571241608841115,566490489998797306378193876913958339109032806676495000099448643263727848667893470101258216128095777975779077696408017781065855401798377205019264716443061687881268372472869438487229092017706767156974596159933038800310353717032995999433855144018018195220506116678554717313645342356609548972497509792111447080303|10012228673376152026567450992902390970336864997567041834794435762949115261281228493411090141625349816927161690458296667158108080969724709444972658280448694411038715631967371509920701285876643071095813601274276803568595952200658716678278724478871970783503276566469041579910541903097002012017970816393023705126,-1525621196152714906745704861653134857598506051934926836340086172347518826544771422485438019089512861580045344082067612865732790885320087313117232977161635917848068594652072218066650842997301426696286712170439049522381084448274527064469835335059461198790200539335886996343589558210546809155519571241608841115,566490489998797306378193876913958339109032806676495000099448643263727848667893470101258216128095777975779077696408017781065855401798377205019264716443061687881268372472869438487229092017706767156974596159933038800310353717032995999433855144018018195220506116678554717313645342356609548972497509792111447080303|43590031232680232081751882157307176889837208488946678228473969287186808910765585247541543237267000539198165783309913805801898560564494504170518670105700488271939383325260531063287350050801106407955825720824399992214830540252117419097263989404727460007269455161541372200543947623309137659512638261713267690824,-14075226919726761245118463757100097494169008867441262054574698130139530299753414803053777844415814847468435199262862690860015506966052100586678181635131495519430715844772863497248903106204345001653326109572317033217334530762155783910231739525445183612742122146838723561339801552140211476495875670393868085081,131240521940112916676543723913094551994900810880147949771730918304609983182487804507629012504949522364314455047343021279573082629269863237002108329413796491307563278912051552679953053070493799302202693873331428377723854674840449409246578209307981263784655485960382622975619701504230119584672038533695429676088 +1001288292714450803721216442216625955625371798611921786124245018047248562264647981975960215285171753909781321204807230585425114478278803844011930274438946371170816602064333453376960652483578633927890649034364140705267107257789492504807548712851379509812488664968862197781823935761608178854275129769647589581,118977223991225808492576983063622698908224268079465629025347336989392083161221074952362214752172730464574518166801398443928377167452950936101606770394549907364810511870992758058622270316795961219734709916323416843582267371642230512848102350867740488489154654911017481701711273952134350507762249130961129603,4253782247854217005640367062054391551273020323289717198551116404593406680781947315659948108589518702797872582317228254446273819182123102223859859093093126618316964313793208051942159218633324159151062222504543999694994085787779078206117679218461273671966899590739444942724001001618068559652898782396232628519674|1001288292714450803721216442216625955625371798611921786124245018047248562264647981975960215285171753909781321204807230585425114478278803844011930274438946371170816602064333453376960652483578633927890649034364140705267107257789492504807548712851379509812488664968862197781823935761608178854275129769647589581,118977223991225808492576983063622698908224268079465629025347336989392083161221074952362214752172730464574518166801398443928377167452950936101606770394549907364810511870992758058622270316795961219734709916323416843582267371642230512848102350867740488489154654911017481701711273952134350507762249130961129603,4253782247854217005640367062054391551273020323289717198551116404593406680781947315659948108589518702797872582317228254446273819182123102223859859093093126618316964313793208051942159218633324159151062222504543999694994085787779078206117679218461273671966899590739444942724001001618068559652898782396232628519674|28938807607695569686193558386017186559599585089880944105080644798657187851944851177349121001670507484268388813019981112914318210410185959709469975835597908447130200721022330232315439534240435891776843814205222365393996713243986623555128903274366840091822641672516816965782305494688964249039137567600077936606,24347068586442893587653361936682544233359974224524919385561963293036974216353969467745312829316424149479715944098504674533950906586338239024243122404600846692591968993298391467756407074710363297328032595080001517924404972784909440292445668484007116372818768610926770836254572445727057593300358575616247842763,152302535148483948223815371530668367432578267200771233287129083802472440010529096619024512937585549897229409792244544585546299937914900082139679373959823145377421946865824314455823557999559223736926801877211472988708620154393053288483777738533792797643686229459318486035573754517579909390578108894692032268889 +10012892006475941528884203206760641995368133321794055404979199342382084602756352644705532078779012887564604213637869579074484075768567055417796954674356138026767547529561933792018043105730958440781327057508393480700527196787164950646236383499370902496883935791129999602941562207002549251300455418372635519273,1454009605238489140114391427335527519147008275556174452371701295849315335234637169205945347453687617440824028465168238395128115858746597274081455839498538752590048744221995446875637484166488769782049750872805524958169087781809205120801537577068712904423342748390795604976651954642488089689583155223913397665,647808943230731060739626381975524675037163647891128462337945233305926315404323308376753006196333731632781667393569616294591379982170007646969372304454389485880137478967587874806562743050788204733473153064889810620961745850926397404102543921057382519028198560438333275110757811110797391594327323261044640054976|10012892006475941528884203206760641995368133321794055404979199342382084602756352644705532078779012887564604213637869579074484075768567055417796954674356138026767547529561933792018043105730958440781327057508393480700527196787164950646236383499370902496883935791129999602941562207002549251300455418372635519273,1454009605238489140114391427335527519147008275556174452371701295849315335234637169205945347453687617440824028465168238395128115858746597274081455839498538752590048744221995446875637484166488769782049750872805524958169087781809205120801537577068712904423342748390795604976651954642488089689583155223913397665,647808943230731060739626381975524675037163647891128462337945233305926315404323308376753006196333731632781667393569616294591379982170007646969372304454389485880137478967587874806562743050788204733473153064889810620961745850926397404102543921057382519028198560438333275110757811110797391594327323261044640054976|62940556237396653206223780718542562667295386352158429493270469961690767724114029222148067827069562399174914339449248246366326268552997433890745884344199015208364859348865726612586847277646257664344896903583225600388420348724002194132332892190932637136851080726053181726410409254132012307744554948406613929323,-48701511676436282890206508014619418354003032902027055232648782348677470406094053907961181547187251236573045647699655583258566497581891423764342023041779904338115306722370857935574573523817812044494597510209680776289279513137149479122384803569185846747971729826779306714510975413862168549755168167117700353327,112469164343071489234368373987004423456191302343816707379444012274611228263948855290569720261858996544051020707105809245289927202553907369725233852283792575569835413308417689095793467463934173594106404637573580430116767215310604286894257928685108943559541701617509990028119392117707508006024253191362515564488 +10012909351086759965456044227627057711408098785482672328633074337493434448564318338609803059310568728348413958910299881715937715018572879175542723270961874435550327968633029584188957768139340259030454592302362749027465867807734115139476094923287105973980458884201581736181829195017361330152871853820144480008,4004735351364710265644908449319598352103612215188460925760295665563484237162745827742855116753659687319941982652183152982522805963387540988424745778802028813186258777373064074552858455437921359277118582292259532327491507456668283228943221341315392967683928177537547570473748486481294902027111753951887811107,625070500924631773027293646808528931297961990338169633089637061010766445639876245993583660254312851352153995204943188734825803541904480394551165674837469282411059121521375161737576421883549419892239480294917943542161102975888315623576549465990742662361177906359742645436834392762941048730926726541953775339985|10012909351086759965456044227627057711408098785482672328633074337493434448564318338609803059310568728348413958910299881715937715018572879175542723270961874435550327968633029584188957768139340259030454592302362749027465867807734115139476094923287105973980458884201581736181829195017361330152871853820144480008,4004735351364710265644908449319598352103612215188460925760295665563484237162745827742855116753659687319941982652183152982522805963387540988424745778802028813186258777373064074552858455437921359277118582292259532327491507456668283228943221341315392967683928177537547570473748486481294902027111753951887811107,625070500924631773027293646808528931297961990338169633089637061010766445639876245993583660254312851352153995204943188734825803541904480394551165674837469282411059121521375161737576421883549419892239480294917943542161102975888315623576549465990742662361177906359742645436834392762941048730926726541953775339985|50884288706475165946257509654999208555658693396648687044835752784386552584102384977309647778026166442592405819250800637374065583324042092667913200394806282864115429746583280943890188029227669788614986056318825797041482189685920834253378958370006347565609320222176974991924753600658153514244660657255122224708,38124750578737274821917753227232162791003089617481557231259566762030985520934492451354616032457170217275564281951330766101660738724598191687885679545346283525262542724874642642872748420737930473130307644519437933305026842012536784886496944579276550709211116316390318564020889816097235068462785319614865578597,130062522389522343683740057432381314776477134408262105090740417520527750971142246152091337403925616258740469387086918783120971977871460574454924803144389152275224257452330149332865693355986252454785361887191345579925263888502541640915087986171712168495464223258466766753612088491549102305993177855419426172515 +10012949731508230844521554364973074187572984168621445800774150709798807735949381704091845966274845524513566631062798752350499554699759712145607818652191568463373664709797900265336143905874117568859521742454341137224521191983729963831041097053387797083787709902762145306866562987693831491238763225325353128845,-7151999616242866495807184767334673387014110620932054515899434747323053830494035687486485101495361247552977403879925385683437335608704813457204456533123612810231681288244199329093278043176840326889166441056953674708680650112341950599518566211501622893081961748190383051196092405691509055911825933224776999729,728959856841002416924230811929428724002543698647639902715200337469187398607311841753203087774058534727465005007422722827247541795373827101651083024979629054119806748202357685733330535940416577507509240075110229140018035405816024445205831928017961602089222683008780078758377712656395593651285944681456109357272|78605684766061357400507779695495682929810684632437884872357120089392494231881706222602069457907886449103098011256954019318391632581377073457287658351584831830230683661446071913790640516272177525020187886119102997352695696049059080937602038841787771510139456284931095360062636771451048097974369276252684666749,12001075534855282519055781006726767731199194746822836204491410167536180166431388377323739159072959927587441133024108242424202303987846968293631866746295774320809136575432861690259530718674237632206265488487198601880322884976030897140623633254152458705315742157972429278484090634288310049511931491105240527901,93151749819352486101012886560489221249552002889236789406862251708880381277922290057447780576080950571200028266859881169907512608303652032886801146810143008245384785580165444902988038417617761865310968792125862316413739796643982228185896004498606219961899388723793207292461251691711779811000343374670531988570|95620961524949716684140097524982794699249535271050516669544121744125934159117898820120095869213277316814159636331359612088008309956314498753337898007810553303289522178449103493384329227781778413500531168007453332099452587335790687068580171335323542117871903087433014777736086345342400718427907876478857651725,93982690612240904950679627999951286744516720026289165825378439518867065181987722717690665329424786689958612327347934970490613914683496125042910877240489318265091859294188434182919729530207613831730142844292090902152344156800509267822168626995816691703927249712872762026654985358484494213663737589506902782009,99292425117587212531473852181491241954331600716435740239461638370783102438068248269577051049726048567729703659744591520045688390816935889052570162756642088994924462717034854539966002991020871080627249804440896263676225604896518999268622239261793212314602300584784534836058487675621509713476733501463323785340 +10013285697697981291514875192049827757071760177573323421009966878146856227693938310986650067592898605619488251263628358029535725840627847357496217367653253065239804661689467675594407401100934372130923704422822224913415836705341468552018728686468194407664564227575182128302559705354560745061529474614082985076,6561642167054255252332139226189226301150630422474494620863616714017817447379372804603010573956570809208555270847201719676149529315047658055027624866235618098171962008631941847341271231615706090718182990766223922159167490454724094386151343698580819149354278973243680974477529170554988807127882542455236037061,528470097447394031501467541165507900676972213983504375431777006857690508074506764381712795328953309294516807977445847891975262681647237636757123951794958241571326610288116591734368211279530252114133992576937361883752806300690109922381969083425358175983601420535008716582685323406262131690670391327047692590496|10013285697697981291514875192049827757071760177573323421009966878146856227693938310986650067592898605619488251263628358029535725840627847357496217367653253065239804661689467675594407401100934372130923704422822224913415836705341468552018728686468194407664564227575182128302559705354560745061529474614082985076,6561642167054255252332139226189226301150630422474494620863616714017817447379372804603010573956570809208555270847201719676149529315047658055027624866235618098171962008631941847341271231615706090718182990766223922159167490454724094386151343698580819149354278973243680974477529170554988807127882542455236037061,528470097447394031501467541165507900676972213983504375431777006857690508074506764381712795328953309294516807977445847891975262681647237636757123951794958241571326610288116591734368211279530252114133992576937361883752806300690109922381969083425358175983601420535008716582685323406262131690670391327047692590496|34436981724331071994857876336695803178232447897168183469251879445354282383737983320261577504714614276116113259188008664067129808039959751651485877586471601565784430914037035998508212337945584341667506911125463475285113792006322617814372685212577273915390962094210529917778766692621996665878783549527139893242,32421657027122874777191628085590775058881834171831914535958291812982208823927027425208685420460283486647223529499620732980942837410329269106357656112224843439688604221190662744374320594231296457180058248568608247918397639378809724702503728912863511608290047988244839274296444657984762607288102260430546556327,160982437047557923662754621724904101004108273738876884592163845288132647289990060919034667221490978793506721749816537966400403944327808168366534024580437483775879522831741601830069730429889808208871000895202628107312664119771131677027106136972021612902580949354880064038858290748071858588504931122717671875719 +10013409568078797146570807857755720961248912529367151061974511181033586582464029378963193763825696350496154303179345126636835517120186897096948192379786846194127995559270109497428813513500508574813803534331316886434340387606885978254975074973425350503976585044856706375756665039166645930515210729176181994797,6863076338634175024934436723026392698236823689304369693969685928390616820215350991816780229964708018996782742906430454861638727991380590099557403163016242141034822837520016392592164770889783961757225608245037212056737255646000577024303400659319142788815209178052443133447533618473993771130005829940742472843,518144219445747450843112374880923475954988909716176430338161904285754222207619744119028881545602958596524518340559183715691125114950676034953086100367357569860971147170398898521979791627387469550508096062409978585338647803044577182942437027156401628087522267601972713267759073787404132654921721043098478369296|10013409568078797146570807857755720961248912529367151061974511181033586582464029378963193763825696350496154303179345126636835517120186897096948192379786846194127995559270109497428813513500508574813803534331316886434340387606885978254975074973425350503976585044856706375756665039166645930515210729176181994797,6863076338634175024934436723026392698236823689304369693969685928390616820215350991816780229964708018996782742906430454861638727991380590099557403163016242141034822837520016392592164770889783961757225608245037212056737255646000577024303400659319142788815209178052443133447533618473993771130005829940742472843,518144219445747450843112374880923475954988909716176430338161904285754222207619744119028881545602958596524518340559183715691125114950676034953086100367357569860971147170398898521979791627387469550508096062409978585338647803044577182942437027156401628087522267601972713267759073787404132654921721043098478369296|29934292569471815703363755226997845073545738667501237803957680847283080542129475423696483417806010171923751057450372494361758724728289501602492090448848706266885172109480272010048281849170055027096272553904872380723830007840644079815126735090510221286243662888112310922242506575820245103502418648518037684112,-21627427564859692871607980544502391995135725746472152647532172629071699503752589147589008201502208786678594136605740253912219755939688067145589663222363251747851181456245722891111913772396992196602024806546104102083185098682262204868868794139167512528524369543939531083241005579818092881356982615423576691605,176839029147532789455522785442738478049409371224700882039503756023790320876676330359714505430586793397649436855899139335082011213013721973064579158662211626800445041202290699798718862085318933995294002499387627536860514923891246937832235709964008507131234282169012371627871115559920941075179401745449676837538 +10013439159433989368964725373563382887574891949489700677050044742848904863973460805304293375442411192907083507310299969395983146408589524560833202656559624127327840001867965274370013167539210363322627273718141213894086509619780941576547772641539573210833142422223317097724915074066448586076045470572140906640,8310509330265721057433243761087295977033094222529694041792873186617167079529403730551603568975196878825930300295178836012162497002423788954615523897720318575793014458944774857654309162161287534450951840479782552544416928129945375223479302487034431413802055998746646446418560576461091628250104710978988283711,729371463016273963110544177662324936807730201765611306002068268068668637824971025044896789932884019488152669624502699796991126775679816762002628560217169359562928488795097209366461843162752726085374841269043547767926070040941464791696126630730708190840765048657149163857767697743125679328771823496672841634424|53070231924347082568804835060631378289496498123832644772276016787246416299549861270518581840230464146779761127524498364504195386387182521904349896158340177993161553682765729098600652803891496382298875979768509788803608935382898072295003870146958848103249920622300892108001270267505518700281027764636096833740,-10417045904363157434661773205739749791733323923523249180794936274249482583161962687848890485454386657190132561052636607343240275768181642068289523597327390757351630390400726183726689859598985450769013120294233573698641240921187000189001584616004996169093549349734180954432033587699679729849675222478884233311,137805678896928752296520072917407826444192224958002583188528402832110905130383122933446618731410797305667977506853537200263986333845054038041545138300862253525372279908216585177453144947870717454801757363277754721032068341587435554423804921498405475740879440309992782986462772299747827377706986933475774033684|56482649708459145913698445611252485312060512622120077359133908474066254680736347932747096146010188731146496181655662751016088725094095969432429720148408144169456178462601187248728823790080612841522193324466093276526908124707660336237710411213793152471895601301243018110500181075901054216803639852864737028850,49500528206529841911957152384541310290857923328806104231198472543790151686945922117895513040239668591093558926952515368216015961042415506812499837082111798870583213244606704215667322437109994138978691823955863634369767001231824513186587618556524171225612093890634215231765102523588484540352521700864775908391,139845177982276960575270039101197150993163035851524438788484301872591911839811648314287998492505051870128263318114638169162126726205946284015475459749582002542133038527256092765477445685371965587948783428628744556595668607565825917211361759008178572918967281201176709071648799305995083323084664578756735938622 +100137176306265990029733961444031383061223366889811053704411233166327830634077756142922727010656909223245031237249254709133350667800868491437148280477941194204587700926281351055456250199609042270725753605165960788792303060065875576152280599302149022622498012279559937562935558359151996671916418735428920407874,97779166460841276445850871197751897473918068054418745266060401791237288238653436085640513289818870139139618919771865928628062692360137571273452019987828179736062700190532592747648476510214800565987627353502647292543809222510700867942163153624606570877663088964161374448935565221244874684751958995844140920147,102256681515788126438883260779614224655986266663397201843001234522477597459794964756711032437403434184534404583233460968937962164574558546102488980641209149336930446800149993628815025349402768080588150480797996340762754608056907877670259116917971852689279794852877026737551375891068290636218096081379871615065|100137176306265990029733961444031383061223366889811053704411233166327830634077756142922727010656909223245031237249254709133350667800868491437148280477941194204587700926281351055456250199609042270725753605165960788792303060065875576152280599302149022622498012279559937562935558359151996671916418735428920407874,97779166460841276445850871197751897473918068054418745266060401791237288238653436085640513289818870139139618919771865928628062692360137571273452019987828179736062700190532592747648476510214800565987627353502647292543809222510700867942163153624606570877663088964161374448935565221244874684751958995844140920147,102256681515788126438883260779614224655986266663397201843001234522477597459794964756711032437403434184534404583233460968937962164574558546102488980641209149336930446800149993628815025349402768080588150480797996340762754608056907877670259116917971852689279794852877026737551375891068290636218096081379871615065|90230316563580194408667213300439360765549943827123723976699582813489678898952655680387614045807099591452452020884059027873359796950334151880947386773848115789736943898016681027189561282963394481712553688761042044178529870890932063063291912576811880180339151930033798900788177324802354824840693823677567948727,-51250096968515553727207440971544562384114008768089106206247467547899665759345213630706768471270630937078525436219387041016063211534659780348494492859921683763678230787094584046438254568966852960609578580031708027705688875405694260795850267621602038107210044773776590144869507841095128986805399917716889737097,94271497992835932562874103278757400032116756041765039747726332995183554964390204442288393334665236335700063020174534799860251424117225874828741908247259400897208844068836969114844343301370484015148786737029807531127609578040269356203181806490127049090765570457173053771731322678344641402857532580837050951380 +1001395889265586485395767421092943095772484906688205160639025138850588355434167443569518670890639224060287615982046173119211466447418875356487968111638376610456681184419174307282534045999642719677458693603373061246804412063778941537663208494251233702824916937867260454282227810431834716831538058300952240529,60445540632407873888807630431208524230030823670563578058253542014522089940657440267941912297376844686920437735513309169811551129412183931683096248710036617268265519243947751270645191479229689326385715524956466565650374324873653293511970021452999675894489762841364719216977754928108945414058693987652866277,5401452543992462314517473547060846830682300053665170002473827326781788915141651047957910827411217522592705590143110487190395657380723574363184777022159851917393607961064987992588915644654812213550360705959643031621136573608890274219923270810168453305278905475435769643968988593393956330128341342800859836282482|1001395889265586485395767421092943095772484906688205160639025138850588355434167443569518670890639224060287615982046173119211466447418875356487968111638376610456681184419174307282534045999642719677458693603373061246804412063778941537663208494251233702824916937867260454282227810431834716831538058300952240529,60445540632407873888807630431208524230030823670563578058253542014522089940657440267941912297376844686920437735513309169811551129412183931683096248710036617268265519243947751270645191479229689326385715524956466565650374324873653293511970021452999675894489762841364719216977754928108945414058693987652866277,5401452543992462314517473547060846830682300053665170002473827326781788915141651047957910827411217522592705590143110487190395657380723574363184777022159851917393607961064987992588915644654812213550360705959643031621136573608890274219923270810168453305278905475435769643968988593393956330128341342800859836282482|43569972642791160005757596858255828258440677425601503825448806514649923603624018287716685991744061240705340542732331922577472226472918231509238166036331218027449035406029770845535194662631393899654058445399116462950394778843477054303490660149914576382156352231393154632904722395547296167018467287872528029256,-25416175075838450919641769013264410597729745958193362136948110865397498509541978552163608664910111097484344111265508414674502206468095426484449495661952091027512836383946952942259134571474962916748153155124469369237399224386694894533985438381306408742628779331072259662078374717232763484127547679303302310423,127851513581210146707222534812462714415549658228702116548129323569875687997527570139914376876955894345964691178029394628745573178902316765592327648023513178993717765546280790932769863585265709550819660882599525799584893587529991012504312937097442098858522399473806578431530443021404617174701716319817659510588 +10014457466865501413264699180995213607651643403581155351850240885586127254516466035686557278805989563280873217997386135507560429328380625332058111008767730524810617486297285562994007263758369576890950982876431843971907525378186076190945281470031905336296565482376151661355756246367703162199805483942789509516,-9493045169000225624825724585241654877107258957466554573322941788423005986836702078635071088783742277452705183557515581054220105186163500969879785143181676844657120253295906990349839818041129525896218008774011956975336293108128480236859770511279248182237458109627660116415432972887068943678814730002774447323,568058498128347562017983106577404112679290790118077765226872096344304166614495246835964393367142362074124393647429278191341969083397190437238809441291521483431836555168421336650034272837791888742028164348356631901893675815620388348481938896223555723594783353067563133868242273893775394833482067029611721906579|10014457466865501413264699180995213607651643403581155351850240885586127254516466035686557278805989563280873217997386135507560429328380625332058111008767730524810617486297285562994007263758369576890950982876431843971907525378186076190945281470031905336296565482376151661355756246367703162199805483942789509516,-9493045169000225624825724585241654877107258957466554573322941788423005986836702078635071088783742277452705183557515581054220105186163500969879785143181676844657120253295906990349839818041129525896218008774011956975336293108128480236859770511279248182237458109627660116415432972887068943678814730002774447323,568058498128347562017983106577404112679290790118077765226872096344304166614495246835964393367142362074124393647429278191341969083397190437238809441291521483431836555168421336650034272837791888742028164348356631901893675815620388348481938896223555723594783353067563133868242273893775394833482067029611721906579|53924208564494923109968517258991384333718615783597634502228353963509962336751805354923463494565719411128406689879296751392427452179492575502279868846589843663305526485431433798862642111241114809566645178986499564696116126963309686958809916838000470566457881788520159467305886335238376585070031885019107861839,-39165088112891919485404645022206551911392044983195122526582505244941571614658605614311191813725723193620640489676510478992438060577861340792571425647895723271516089195795031639152263494946222662918005100610385322895768473350699779206361702599565733658715228168714169147264299885332019593127372341848528310877,112189763824528641217468278574322392988954546777239131658850758660466358827365295080995339889134329849615042048060538504294364321483596732194229239161149447040110980960983657967678809117682823152517826486688609621632734218254085881353576474560418869461310902870862203604502294697766172436420730459846253285376 +10014524612435081655051402581388141399758826121078479680077428037590919760198044078469208114625992172565561472610137633731570114446039320551421576820201144498480274752068507237188168464666743295560743051180514619150806895664325776982239371917265280309982409950396003685063877356037007592827997650696359708648,-1151946584820929060448198375444913319887694243637725495546164532401952339142382368891700429417009398962503441132652463153588614606824550308747271936296460648801898782148675402610858915130433609314541230955826121143276189468724039832396682232064702428868374548095200287491142543410829209121388657552507539861,755148183880958266120452185655234110618667867205538459331580575221728013160051641776310146717168795492323023035012567121444609095123943446710618919745199683082156201032014589922592096239933647413759449971964484414757026090967529868635390069577397530636511831668757182454799405458183267048363982001659170207347|10014524612435081655051402581388141399758826121078479680077428037590919760198044078469208114625992172565561472610137633731570114446039320551421576820201144498480274752068507237188168464666743295560743051180514619150806895664325776982239371917265280309982409950396003685063877356037007592827997650696359708648,-1151946584820929060448198375444913319887694243637725495546164532401952339142382368891700429417009398962503441132652463153588614606824550308747271936296460648801898782148675402610858915130433609314541230955826121143276189468724039832396682232064702428868374548095200287491142543410829209121388657552507539861,755148183880958266120452185655234110618667867205538459331580575221728013160051641776310146717168795492323023035012567121444609095123943446710618919745199683082156201032014589922592096239933647413759449971964484414757026090967529868635390069577397530636511831668757182454799405458183267048363982001659170207347|46183360432532901454553912811649590320395866004347241196844991991079215314437275037790647677890495653136878666779844887628869070006778207117633836660092513861015319661569732287838772799418674107359979430356246346034550280154482402202513605341927486676571446547869725605869822695502032982833841088921112910317,-14839171560103132001614843311520281027921489422034665235320812512225719145369465447283012912841921017696170329655940078247191555778130550993274994429848671209676820244675419866031667103832358269654123112505016252317575238332509399397558348115029597533711563469431946692326093523953990323828622920869190596305,164933181779897671999712222932130083401866004577771560343160060853528269308468525452931360567865498324819919495168385048274257865546801611749112060417208336526645794766502287072279593583106527746581118239327199774476900334621937982627978739872164479446504941326886004356233761306601172587310954186017120057146 +10015153163121593836478079113660124757348318592530821165639828390191159358973882062973457665510869038410016978521906069415643885467466803613263638452835291035274253082105374798431579187029855868716866951698965254377198199868261126247017409456764474165861037253182443325274363795830109568972878953062238823520,2382294090568001333199894323474279123934374114667847405540440750564854209907703388935432920732110218963078674073256448624811505546395497000378710736855311825351193195350046490926404354706980500837042629648272073851723169837427468358824989832884534921916167168920876623159906890551519514875606250679556403973,773658465692173962483130527303229646901934499596511207834787839028928145069426505005504820136922810366817841934360207193839133022641619097494932108724559232945611195348726835877676174729010759098808115181632361389730445448407363060843805088069390583778242530477288002693827656348092952397617162960252636436602|10015153163121593836478079113660124757348318592530821165639828390191159358973882062973457665510869038410016978521906069415643885467466803613263638452835291035274253082105374798431579187029855868716866951698965254377198199868261126247017409456764474165861037253182443325274363795830109568972878953062238823520,2382294090568001333199894323474279123934374114667847405540440750564854209907703388935432920732110218963078674073256448624811505546395497000378710736855311825351193195350046490926404354706980500837042629648272073851723169837427468358824989832884534921916167168920876623159906890551519514875606250679556403973,773658465692173962483130527303229646901934499596511207834787839028928145069426505005504820136922810366817841934360207193839133022641619097494932108724559232945611195348726835877676174729010759098808115181632361389730445448407363060843805088069390583778242530477288002693827656348092952397617162960252636436602|2334289880943001376407857326996263570161383789108737840675851906077977981768540714248105544895055900962482225672861273136265466132609608331964249615854131927898907957201650301595252550620756829520427054784019840985991520693282395588941752214974743008251596421642708049368885083348322205731564243670420111453,1451720076983591598762998723081545117923198868478265830640664361188690301293679623937617406037087334975387230852094993435248087727723628228521184122895045650428549727009619829664472593953602490826316016345941727517760259061554173070969494032097919619747777129170826368624036489935713881661043471800066640125,3318960568956834644312274599956969298741234864897695465866703354170475923995521916039531437101483638236150279927673715871252637092748519401149230098061946550109095773979423194478592673363716301124276065026975130628863523060647342416992862735921072287765667600233548851774826575592417995450427441845506696081388 +10015239581157875832393535763226085031936027674008799231064578015529654192320817181717861924169857992310709531421935508097069554814977182072669044193680614850544453265357095259368437732015348877933787885875170804438256215681419620514332393733243248548151757671725579685427667920968624432291421418590675885300,5094068907677575740286879080674249533942090145311835759008798415694966420126408035500684853222542571817165748053609110326610732625612063208376418866488998532875479258993000620044826461966140228426897339103003926919606128736757098245146058573375685873266553963971816210554103991392539430164989850926128708273,793368698167290739626939845245925598679004619304386735598558585912760256279890735283141314660505981777266664338091862952502183635644778863932176282239208069911448671090051312086285039683208751050938084831532228722294544316547609430035555984901118374565436615559075980852757981922632778527357570396074193505873|10015239581157875832393535763226085031936027674008799231064578015529654192320817181717861924169857992310709531421935508097069554814977182072669044193680614850544453265357095259368437732015348877933787885875170804438256215681419620514332393733243248548151757671725579685427667920968624432291421418590675885300,5094068907677575740286879080674249533942090145311835759008798415694966420126408035500684853222542571817165748053609110326610732625612063208376418866488998532875479258993000620044826461966140228426897339103003926919606128736757098245146058573375685873266553963971816210554103991392539430164989850926128708273,793368698167290739626939845245925598679004619304386735598558585912760256279890735283141314660505981777266664338091862952502183635644778863932176282239208069911448671090051312086285039683208751050938084831532228722294544316547609430035555984901118374565436615559075980852757981922632778527357570396074193505873|54841829397576178848410586601034860596951681568779361478370108261032921497569280442168530570346157404440784855573637229833444102498053726559151577392605738325853410653119896676062193149054976747541732412004218217068288550127184839213667255982218678702854737220904918059908451831872125006158411607941690397052,-13987639594862577439517093919564754940146287009709146462369986810150221519296281298521622497304190878362220137401179604871651085725669668566995040192751337189374220954170616856835063054456944563624013156491483611079953326833211481288513306777121436082074004700443915242579221138749893848640705537321387708809,145658957896464652977038505022308448361415349923894631554394890309500215673949920864830014124570888235622920757378372327525946059952077895236293799705256119864823158645268515234330467061529263252614881624406296566043408419602845128600163566622927193489899129202143975708704672075445501568437520798105023647844 +10016254093062341091793169016069728267098466973354611327776341296362926980734885768145505535610323176943330336454162903286601650062616238131379152236760546371204482195908361542328829078490793642835057146484428739306586521325328236448343779367153378279828280298660045704810418678221790320328995853516877961219,5290291792844776128036538578818355234036731339837804827682257620535756451822532868533550409363458436730292692155637706486234356872153487706954079157252741244973963860424508734267445638531496348565715559236158994920739250737957339663944820624379832490664101888239401802029497939684558696213321821587965089165,649562196414599732260624464563141423074514382020176141033151990702926870363780837252385965871530682720560442789827097838322398249975199460284454895932864056555126156062190575895999061116214790474483579500239339070750293285631666586984632253828693474154470829221739655058926181416125562534958534381263761974132|10016254093062341091793169016069728267098466973354611327776341296362926980734885768145505535610323176943330336454162903286601650062616238131379152236760546371204482195908361542328829078490793642835057146484428739306586521325328236448343779367153378279828280298660045704810418678221790320328995853516877961219,5290291792844776128036538578818355234036731339837804827682257620535756451822532868533550409363458436730292692155637706486234356872153487706954079157252741244973963860424508734267445638531496348565715559236158994920739250737957339663944820624379832490664101888239401802029497939684558696213321821587965089165,649562196414599732260624464563141423074514382020176141033151990702926870363780837252385965871530682720560442789827097838322398249975199460284454895932864056555126156062190575895999061116214790474483579500239339070750293285631666586984632253828693474154470829221739655058926181416125562534958534381263761974132|4371923964825216081284965901486251829658920327478160330494959761785570498729926171763697403539994609514035386549444286899305836316283570402957212167175599769519526858160920653621106184279087086218630872059466833612874880235324503114394586087353649281136173057014948419793113247251617601913225740371158264594,-1777711233855585326424402788112018092969733488690398670027508570423282261674718543600694888501454195345939794788269076453964223553057248156896791027286117126036185606587718958830247368692129308590218482424190086311842595428742140075700660885589198113766412954745249944832418277914084817045523687626938171785,1486753504481531714235052666066139608869409848938074431937349188798515713076253106271449862728854109674272536360912828894345019832890057397353770574425655506024994198304163182702822689738838001321557096641997078734385067590564038418788081682782254559978113888414124552326849527747130706995014118004294289090507 +100168933817004159727571823870862212374515071383247163682233493029515956409883385367746187285740348786673303354766599662884032925310153869913659930858915269690815416234679514078167380783771768659750083394948158950008326340270387586985723448583932705818464704601214600293828130344813737095058092807371622380596,94832715670637342331954204053963565603302480280224254821703778448479787031215111088413069986664424694762700821340882966261664606716747356784210807087846121536668261049472463334524682357378613143974178468771819549191894308095591279746614292380149290609465170348542192697415722868093623009037253233869856957249,102860441967964242444445722269341757702905607863364253263839843561869841563005656247302036622183568251273499262767768690361280263007610763737074443848261770701568579600837276156244861738658629562432640564576786387713071777708265072467592751700403901387393831303255944800743982818455033707731784929932463764787|100168933817004159727571823870862212374515071383247163682233493029515956409883385367746187285740348786673303354766599662884032925310153869913659930858915269690815416234679514078167380783771768659750083394948158950008326340270387586985723448583932705818464704601214600293828130344813737095058092807371622380596,94832715670637342331954204053963565603302480280224254821703778448479787031215111088413069986664424694762700821340882966261664606716747356784210807087846121536668261049472463334524682357378613143974178468771819549191894308095591279746614292380149290609465170348542192697415722868093623009037253233869856957249,102860441967964242444445722269341757702905607863364253263839843561869841563005656247302036622183568251273499262767768690361280263007610763737074443848261770701568579600837276156244861738658629562432640564576786387713071777708265072467592751700403901387393831303255944800743982818455033707731784929932463764787|77074101972769923370658023573461029047908280864501436531886214070884695444419790476920141159581106162534554398040667029684395317753749995140975694643351101153246406361333865778019332847126758508398386399309944270422140994351224794089223904030644354844471144608782627152160492615030406249102513998568586126653,41985809674026851301068939458342266766093613320697544468890621111459064094913132603897896518617407840492037076180430740254366932298578105226006922522339189157081422030305375009727018508446301230399756872145212262654632874007091596766171377732560260349745066521408866260391195589212337788533541057115385883425,110229138576369926974358954548772667512560757802376313780826844717365768043167923353943051327604684088175403151021231033281660580097059744410859188703138886987578267563448651782227630417696079180690392826925010189611494463744920925421564075513181916017454497019126236913116432477001913262238126225201422341436 +10016905787587129103970068378589209223718079791180726370802218768976971488497998963132244508629494308529380628538141221743580243393344335649567002150936320257090927900467530902572471077942584896593451110546304416815718151825873142786318484895510554032583903064792109176935301749381314577344473149515437073560,-4606191417439560848418163571752652850846391635765859587403508494460979835111500495993727812816590518091323150783186546267331220869638878833615969103418728210432746474134652280483753966001415196686238333974286033749286862708642243562674370580850529480084335445537434013760930078201975018692661527689582576651,605629172398620500162437997408160351967898827176789386195142449064206069917749164747262079121234714184955198496120255981525746584380916729025666697652941726995464456228081635615903549843932017595245592861355354651584306759089064045480854767640497444940703279199283744488071666641763271403206424800946819221209|10016905787587129103970068378589209223718079791180726370802218768976971488497998963132244508629494308529380628538141221743580243393344335649567002150936320257090927900467530902572471077942584896593451110546304416815718151825873142786318484895510554032583903064792109176935301749381314577344473149515437073560,-4606191417439560848418163571752652850846391635765859587403508494460979835111500495993727812816590518091323150783186546267331220869638878833615969103418728210432746474134652280483753966001415196686238333974286033749286862708642243562674370580850529480084335445537434013760930078201975018692661527689582576651,605629172398620500162437997408160351967898827176789386195142449064206069917749164747262079121234714184955198496120255981525746584380916729025666697652941726995464456228081635615903549843932017595245592861355354651584306759089064045480854767640497444940703279199283744488071666641763271403206424800946819221209|46304687373394436931218438666336335256163483212484332920442711829320278593351077938042811198542492407186729960199059393629663370119443451307712349370714705707036441431251782566272288509732854919564985572759872505231639307883389746522852343879592729064407291688011480357040596643477509242715875322162180945750,-27559962602683142671407402152656684625711978340483108455301920226275039655520624691717381412007576185077377268485337641259513780832297300630514833099989822452624240349981167585374487019267119021970798715861631920467292530317231419988216997273247875678528676583110608263771292353047679830100015076536212572871,134999594026951253395775325545499481323026670784912424362786946325493588697203309584859459643146426717172468824814166286260797091069281816967149658244654968987888219904891951992996909324931101736714925044299968419433398393443198400917682271553527341988170608553689440600718627726318712053029382276372293927321 +10018204832407485307717168433283551951171211565712475881182623460525924044598415564148247583748572210844295784844361310074903318189804960966908772513031346031383059069976302114174587533940128565286800673190990221782901119861314311455679210523773394109738879256410739142961640761546729001001316019848803176862,5319904375533742100925641023534751951391638893478820023967035481652261436239987131193126434052892185984232529181792190920674907331089418651303709226767934571557921846173913244300134187483219524696758678859856206200663423378880336983240402046185791279466371047694436246549133924131892629303395892591776395187,649443554629399472805877307531888884997294549224205118199170867300682218925831813905978113513120968194233947187441042861450829488125193696091497608405966874500722600331516590109468259720034716473854550338705028445661682847162605116427138852824514186119049574433700978648124399292078009263486664308050317605762|10018204832407485307717168433283551951171211565712475881182623460525924044598415564148247583748572210844295784844361310074903318189804960966908772513031346031383059069976302114174587533940128565286800673190990221782901119861314311455679210523773394109738879256410739142961640761546729001001316019848803176862,5319904375533742100925641023534751951391638893478820023967035481652261436239987131193126434052892185984232529181792190920674907331089418651303709226767934571557921846173913244300134187483219524696758678859856206200663423378880336983240402046185791279466371047694436246549133924131892629303395892591776395187,649443554629399472805877307531888884997294549224205118199170867300682218925831813905978113513120968194233947187441042861450829488125193696091497608405966874500722600331516590109468259720034716473854550338705028445661682847162605116427138852824514186119049574433700978648124399292078009263486664308050317605762|2096824613311195474736703091933491927179118439681576075463684305365113996801091784928235546455105051723066941197368294736517297176841884535935805063900042702255946184765201041823632273617760317603104813509978347996857764943233871467178918416729927262302333533232369242879390413535385046393166248041635195052,106494743809548339750384465880660679449902990323530191499768868050880389213560457433755933556230921885636912867886887645004590062925256300108980851523487384554584007694663026566980186001150284697993766392145530903618307059918756399086400576557720952521322359177695970013138988731324890614696675530003172189,3099537274480186341907264372921810635861168363663532429504499040028118656288725100184032700559268063816635775634703345843577214400172811320277070043994325333354476328328682954931303645039746659585813529747367061450073478508564524387846459195219414272058883943010351216728564728313947382708438971484753032540491 +10018324718324265352080889354041349230495045650756363847859249064826167700621077306379636998633382620068424485758426219639651755498284131150741688356919555549109464768469845299901089390604198312107185124929799165529332689261450442020302769382765032211061987664530506790585428478002180255625233322864976647458,-1506556466689461719964363510118987647616549995746954868616471745983245113792074110437071688516535364802439931589935160320446594866789971924891832800418288544496229576060497571654938278590804451001178571222736016531030712235951293438712713277945256316492298818368402112911658258565046390998975710669014707937,708633648140842422465025989226402132551754445128385378651747216241166649232185357696677838986015643979480257385865744447602978939236447538983280973796461564754777224324765925807967303202117722154439166886733422154436177593473337680099402130518111476687602398807958385973240844776043934886139211712396905414373|10018324718324265352080889354041349230495045650756363847859249064826167700621077306379636998633382620068424485758426219639651755498284131150741688356919555549109464768469845299901089390604198312107185124929799165529332689261450442020302769382765032211061987664530506790585428478002180255625233322864976647458,-1506556466689461719964363510118987647616549995746954868616471745983245113792074110437071688516535364802439931589935160320446594866789971924891832800418288544496229576060497571654938278590804451001178571222736016531030712235951293438712713277945256316492298818368402112911658258565046390998975710669014707937,708633648140842422465025989226402132551754445128385378651747216241166649232185357696677838986015643979480257385865744447602978939236447538983280973796461564754777224324765925807967303202117722154439166886733422154436177593473337680099402130518111476687602398807958385973240844776043934886139211712396905414373|27695493339474189059880649994786373673681195258723034498967136263221174895242876882887946040754182923842018399590448977999734476968405279409965275664350294423197625592498762797252651752487096596479518881899735472134497736489815871889587384160668070191112126826489102305651218385469424433736996571142100268141,4244952032054732923978416579691917713463067102733490131769022354718180777349838220573662792933493750823939044158056520471214587505994364897599832929831064732609354344151098280452640031958247121275726298011899146169585223669027857229201360814944532694404419990370729211245101258947186079227140704211123597077,256477087542010205875387979681474864287758986482727894664413009819175948644274490742191718780565989800083756066810584023109412061717270312386676508030363737098913494555400729954736934622756650518307368707185355806725304278546342578972238562139946071381611959969612417306120634997866733933066171286156441897864 +100183725937805337440102832154923451468884088040067509735031176134138272029603097931029532527171620687937178427853408917605171373483732022096443082050272616813579999826937201905718430121138104894761796713162794983612090638008542903172271321979734531328047767185223183894705715872373581190063338544430105324944,97967360545064065581782092795782542381718050317435898718948431525445051912029574864522929506831468927036372238440312318277489221772379035158891587900186742286147138092170859279721424649522055176445825889170777870731814816272149484567390197282747308726861433765864290861778135213069453090668850681241158130141,102026058802637364547431940124628332383045736950389197653455431566764985503089749509318465184383586821649550424369391712983254618997917250229615538329822378126555642981029789087346297188093481472570239624171949132198549570384613605722016512646835562730355439782372504448945801732597394795504733391497603335093|100183725937805337440102832154923451468884088040067509735031176134138272029603097931029532527171620687937178427853408917605171373483732022096443082050272616813579999826937201905718430121138104894761796713162794983612090638008542903172271321979734531328047767185223183894705715872373581190063338544430105324944,97967360545064065581782092795782542381718050317435898718948431525445051912029574864522929506831468927036372238440312318277489221772379035158891587900186742286147138092170859279721424649522055176445825889170777870731814816272149484567390197282747308726861433765864290861778135213069453090668850681241158130141,102026058802637364547431940124628332383045736950389197653455431566764985503089749509318465184383586821649550424369391712983254618997917250229615538329822378126555642981029789087346297188093481472570239624171949132198549570384613605722016512646835562730355439782372504448945801732597394795504733391497603335093|88007552516538570862938195555687347843271125145294862509637863339852312849461683699513427251868777755449793173646890377883712394792262777503483942996934326765981582162423696391672000556247247431253370862284402004050248548817767631668543644528300726312835546938100615886799945875203418182610947796762957426066,46229538931090505519067196461411597385016117678710797853895441617844339335997518932818211184588127766146461427860967017470462043930326616555616035492326025837765159149630918451827844844437116744925433303753825438769925710637787423788344940219740545569047456022116580673560308925831201666938083175493702647671,94949150488319392606413346466333119512866765599276437121309157049458742789511630485348500087618567561361017601972082423173906361345987933875129792711583865107081204947273992176380167405635064486260061816002217859656028475745573246943400761862339441042416462774614661346152692808807449954694367626488600259377 +10018622993047838712433185410421446815061984959152870777572656734193435222251946970691795794836467121595552277401220487788714277091933394850502637162917792769686767139849624312881217655116086523917779102305498425044983500792458780789534783880422443059521517950075233845690825129430658238084704480639376209109,-5642888291743578132708587871691433542854601085995709323535797030150736747981212204721414421313379808144339701595994626772514328521365374368168430420450149143091140909885716813202658261033852230689379211692039890782701731228409652608328076923100699005939261407374626950263084881921749869854247192520776393467,584355741641273221932263410866659097943618996328052690659780811632775391934038170008705223727517700749237903184431819452649538607172642783739379843963426355234430525043677403033326216332450474494227299404505243469315575849027861412999876408965870212198057391050926245137105584182883631254668161360450853213630|10018622993047838712433185410421446815061984959152870777572656734193435222251946970691795794836467121595552277401220487788714277091933394850502637162917792769686767139849624312881217655116086523917779102305498425044983500792458780789534783880422443059521517950075233845690825129430658238084704480639376209109,-5642888291743578132708587871691433542854601085995709323535797030150736747981212204721414421313379808144339701595994626772514328521365374368168430420450149143091140909885716813202658261033852230689379211692039890782701731228409652608328076923100699005939261407374626950263084881921749869854247192520776393467,584355741641273221932263410866659097943618996328052690659780811632775391934038170008705223727517700749237903184431819452649538607172642783739379843963426355234430525043677403033326216332450474494227299404505243469315575849027861412999876408965870212198057391050926245137105584182883631254668161360450853213630|24492216963212266409994030118552483730975075727585752220177989563872338705971497453471962798275543072636175655672560120906290569324009187038649563218726182874757477950170840864973817320145411108769238293767323154108926503045123037222803844779103784397763216133236290396907058542243428101056150879809315089176,-17735224044627622852810014209171696937481849587925646605967048837801771413294839162751742330787917315172217980725109761639973896911760524548506285715284414033504356013230406678376141516049028049732948719065205234900025147050216480775931691209693009856949654955944471263615211623003442072374457069595919699233,241918233622395884761827246850514897219165802162342296635123580790888932192977763833922926853355444881644755349323889380463316458550630788255600843973415342916444918642659362862569058232566277775534472941540495721557558697754452057639207696448965752690070221361062821443638513586031328286832012283835743514220 +10018933732727277902205269315771289076593947560040587959114941078087116999373425488340685401505876624281584630582917353725134238041079746342415896279966203184863826892445916822683268888700587092452305745538315423010290563725863170080340035065039975298577793326244665530455537053974727163555479979119191279926,-2305656050929911594001774361902538333750937712118410383814661797948886130836022054225957304174319742645328482100663492843669952358370802861270894168816436326458990297136526459920949376942432261379981780315229778535749028029896216855337892147060100885167806805043764484945583720350824386167496969085180728505,426903073734578001112620417146509321508736309565051582451873814142074420259405364041324675206078055851221135785335125834745297538613608978468731354815366776968439807098716134814276564770795992539739869501301828055278204465499226602180360134210119244471648153940999928351968352054963731820177407885865927236658|10018933732727277902205269315771289076593947560040587959114941078087116999373425488340685401505876624281584630582917353725134238041079746342415896279966203184863826892445916822683268888700587092452305745538315423010290563725863170080340035065039975298577793326244665530455537053974727163555479979119191279926,-2305656050929911594001774361902538333750937712118410383814661797948886130836022054225957304174319742645328482100663492843669952358370802861270894168816436326458990297136526459920949376942432261379981780315229778535749028029896216855337892147060100885167806805043764484945583720350824386167496969085180728505,426903073734578001112620417146509321508736309565051582451873814142074420259405364041324675206078055851221135785335125834745297538613608978468731354815366776968439807098716134814276564770795992539739869501301828055278204465499226602180360134210119244471648153940999928351968352054963731820177407885865927236658|26579833924289520389972900117950394438805828628221899849785251193277262506904016180015838661767033925903809658684422106275456221210787145479887893793178117616282806012189342470201902133434844784106437109753666637085736679857929223320267986046560553880930252162405414807068330327382869655263308507921578124762,-12071122961357042682227388807856025622183781701383406123339407125622773263556987057807120839167314088703384163940961495607053608272112660158109007999608142815575559883680071225874610842202742230050716632165554413346974345932440553672309803223445371844345386485359912292135145947019769810450457220546043659979,162236250544606905260439724773080091403174351417582646687611423124289071438608418146998192800378143503443566522030518800544598083530735564341780541276153264296511032654040655556029284610154943880012602862804365596003928006715967740792065055405085248350810462900711904458160412653922105321414238780026013533451 +10018948288270418016780081341685235002997245256040164792426543952818991311558791493453519174957285944783722833865026222848031081817691340856453828555107871396513690880005707344898646359417008593189440903277104626759357903337151059344508962185668959714673026792114793015152022487676173726198202553281736763192,-6995555163054430382942870868581755160069395592106884274460542261252343393118569480209218511916560630596078206970035597385154389463448089846021818488631352733935369530889081823095829009383638648970953617256944401187962256866752201837099775227177656065063350644379695273754386677388279021465213328634933930909,721042528909917874686430575245079781825221838112029624394686069315349560814178350680306853206143047638999149938695007663434153092166743090545673695580676514178586788701941454964134693721185647384090760708127649587795147765724504088383646300322664057264796405575462352962768416720670014119545119956267157763268|33152009177899700335521286237987596749114678289874326434440918518081126413178191723162867529955418655435996482622593235632019894996887430996202492483564865515014035645906573982414795827153656592748272697286574461771116159112804016039989028059075628750439940373451196506327787093378094310321443683918398305578,19078728942670828368834699251746230066071047051172922041653025393624623551743744386999716370764191631344442619983012078124921474009852416209669177199713374821106687471027572426997637428928400364743864020836844501941937756570061589022465875716319591910681201998018650317776190333584438330413688185262916051155,220283868712478416207788658621383280997894846941561822444891957123908778028879195278346553006033805168466857198910274082404942136780954015736899511278911633428569844883635491399257549871333616419819287122510218677255768780334985075712076521491595155945026941146633288297234150638278140903654693829381901681364|86660112777924566325641144753803400410997086305075442702977432289312131972915955256795072094482313726948480079751898750790544713440908592818334342498838917381523558133222779818572943010979268307136948067185583734409642160207725489813897991564467762533071090190022128208402492072833343072675416905847421692846,-52778887618554305290105838041380262564458801465646670949464065301477666757134518520029567230285725793439487930254994645696418125229532386083964770290005616954332222417663293453485136710527439679565903814537080125880293745499032607178356596254426977323351345945596998496291222195474053846483056964155485024969,91256009874012914314189895519654249139544913048606429213352879670217368386794747037392624823085153501261342847050224541672528576684432409807110715865396865727844957353872518329845940826549252426734698443465027159176074936925639415490497467627459134074448093109088470713684894800193345119623601342741289991431 +10019019997781066559943515640881506642517558843222778169026234770851975313720579259773361086779089551884331113250530982852069738010518159622349375335824689350970737457654843734623714224913981064444982445158390435699719229301999181267314607899665318687660691355693147862987025822541914292231182646321427861873,-3157363997717363888291408594979293600171398541934051160356171159608233287859036491344319963143369936444410446129850053542356863751408144208404845266526711359417425663346085658910109244458752728340593138106611282955961606114280076234921423984338932045399865574815874428373668830300085650219459974701588901291,427660300107522994538791232761616142662131142234945666620460681757069587002421636449099874675218488912225359428713775902235016576565531397345002001166527254555699729200052739867740788272516457497859568251192144704431298212101856469342734690447583085607097591547685515622397916186942279884556709767139560196364|10019019997781066559943515640881506642517558843222778169026234770851975313720579259773361086779089551884331113250530982852069738010518159622349375335824689350970737457654843734623714224913981064444982445158390435699719229301999181267314607899665318687660691355693147862987025822541914292231182646321427861873,-3157363997717363888291408594979293600171398541934051160356171159608233287859036491344319963143369936444410446129850053542356863751408144208404845266526711359417425663346085658910109244458752728340593138106611282955961606114280076234921423984338932045399865574815874428373668830300085650219459974701588901291,427660300107522994538791232761616142662131142234945666620460681757069587002421636449099874675218488912225359428713775902235016576565531397345002001166527254555699729200052739867740788272516457497859568251192144704431298212101856469342734690447583085607097591547685515622397916186942279884556709767139560196364|21550716916645018398165650019236850766796511258117069952017796540701386085912310717417651598467640925140901250417026118119274327376121328459299004640348530767025071918784935281870705231282717494840395458987826494640924389129904911635742804398745940919397702998940021391844339448198369222701583556010313045812,17308540888407999086403450710891722292596558140904996642436794702554735336548386086410226733754785281982433279805336861038046891710619959255360830608311138886000204010857210058502793117398659272632248311839231357476736302883731390652600445524351263663967663494261178750828036606884450644013387538641171794195,202180803355870010447215408817189049345827932931561109501494466474799106708426285256026437292412097802628616665602361337631758401467452446995726703770591794057694222974232570992815439680545736890553211079290478720762205284250715176457370298196341449115424087895906723941555883338741498383975320110297668277534 +10019269520234431826137367355034420920528860342846780753959912064827599010243316724633755419135436935645907443407020572618899291215095816080730065338555965834485853320180090560809076866724238012634325051855947616588404872824038021038592555404461140712393653058441964129349148722979422040489509372096847725674,4522869991076735362499160116541059903683984737748984347542239263701333187108105456062644949444149453629982469461841568384073346981390834850295332934943879978241839313265925834724485912067878288054867100877621399054735204930899125650232136163964080568519169554901660276496750207252542508193487574803619459009,749663683253588383775532442379228650764046549728574777396900821733935114135159669567652069917832665405176945410288020981482404785970875873582684426212358839598234585501899432885966938532819200647768194074040482435441119436072379143147234400064595949108182133121869311200924895068707591158185629325001898213097|10019269520234431826137367355034420920528860342846780753959912064827599010243316724633755419135436935645907443407020572618899291215095816080730065338555965834485853320180090560809076866724238012634325051855947616588404872824038021038592555404461140712393653058441964129349148722979422040489509372096847725674,4522869991076735362499160116541059903683984737748984347542239263701333187108105456062644949444149453629982469461841568384073346981390834850295332934943879978241839313265925834724485912067878288054867100877621399054735204930899125650232136163964080568519169554901660276496750207252542508193487574803619459009,749663683253588383775532442379228650764046549728574777396900821733935114135159669567652069917832665405176945410288020981482404785970875873582684426212358839598234585501899432885966938532819200647768194074040482435441119436072379143147234400064595949108182133121869311200924895068707591158185629325001898213097|16642018863761441710765797012067927359722077189969631448415362616699814913503672898852374525215334055299068298216385689523710707393718883505223743676435071846547044089283998146628167129062401919282532587286538467437993909697773987546172287165832896898434018866746267084068433592983100742343012553891013967598,4279618085412193426188644638927864595084294097891450444438077735383453062127268915528450003127312343513730070105859170701493137563013978799842440344152818674511355384686181809257130294212609318791976849425989687196701708107582124757707100916931554678238461537620568164241235565012338998887375426548345583339,451300244762011954040540232948856842185637826616664360199909803894796107535366932948228367749161671550552967885565839529658452718412544695138612399812114901538129955756634712380719016039028157710981132001101643596366369267735875381875175432502771795477425963992931644164806539340880034536557519705047322385756 +10019417926514296392019946929112818021632198703101505458649653394849455829204203329294836960034957633501294764450648155864378373289178486051989714219614702737597295310475376780688730971937576079121199314793519307265245938553456529418922522984552293638273911817508398110317305685502955048568809327523071451646,7901274255200127696618788587659559342110188499337362982289909048078505324309251529636836412429419509644512565320215289593933580545899621400755280134055539493035902983697255734323738954580031486643652880504218537900293807494750583881428021909372888539470375818772560108989429450107579283565673329101511361623,623699550931583586227312516211712634135558043787600676758608115259112248746313728815655527067581286781548781459656217474418345498402764321216306327583412055637930534007526887412883845579485648951016708462255973917762702757210736584322682381497339273737323760137458761222143566171226992185720766268284746949539|33994172292722720621983078916917152805135157553786453695681859425113486805780487896660717595372501233092400041645960826591356846046682770081212496668808601116475820169782887756136359474132767453083956483565660497074117273547864843066209384954581834231890370515327604527171929343867967182910635357940103381259,31993846672125961531384598386820046988679306439927918439126442104342750287165534338581303476671621941233213276321267207968356271919850887377330275696357098758109012385572207725576199219446164534402970313646005215676387512077572153065651471880735849343888575800500099273015977254516159942552263434250458169021,190897440537416564844354648094133803032782149306929915760090455032909782181885170078703110757010607891226613247221902350507051587112666985339761578838390574506735798985627221778883031220656445342689661417080864579978266745285225101384742969161503945655665695989381533846227380883303389726073267640913232240808|46223752318790909370837447383363380695209474743451082994109239582734730617406604327737568722130199854939421799114849872972877989567189718205858628003551407137904188277330292052370440786619825504842930785565096667031645779355485895793277208105594179243179236367866554346063343397949912203277267219196168228342,-11006265064354212636439188801633654461277681721343546696389358983928696946083632218719947786058303199938972841132237674419697191902116627029793522898887023505508883048022803011324802659223889838681052775013756116093960676539648227562055647315361638076266948642978861465645013053193461759019970585499519918551,135510058813836316466595636693848570774859961098724584660465530747418644245153590246150906297996570248784693174475582519076799984652691145697384165112598092893383581702308752699625740019767305915611482144859189733431647333812818245189583002227073705672065057825892795634209388635037930002295896526893410999911 +10019602901864092738325953873535047812547299524695025320532290515768840900630595544396879008556083370139972255849271116199083634435552540915196064651229780380925328336224573551564497154428220750159228126503023660786371036661986963326869101885946108118123565859605937169197265825780593487194236118858010532600,385562394428775749047853575173957314087625602564743010180946094529317438985024787344743900106472493168796231871305499111699051361035813309229378162588371556942740300961721890004066420192802443990741112403096930009444198021764517249355582327168404565052575639878289683556483174213973783173191751884045426337,783418388779217407199495491198572563161785093246466615634830075323053502538909242522004194931674520522772536562755280126097220160459899598091584353065112800205031495803329979380114748688327366649214078234380064643848371559165846159884696566323937944146599304471519733682046929885711023157291005000370881207583|10019602901864092738325953873535047812547299524695025320532290515768840900630595544396879008556083370139972255849271116199083634435552540915196064651229780380925328336224573551564497154428220750159228126503023660786371036661986963326869101885946108118123565859605937169197265825780593487194236118858010532600,385562394428775749047853575173957314087625602564743010180946094529317438985024787344743900106472493168796231871305499111699051361035813309229378162588371556942740300961721890004066420192802443990741112403096930009444198021764517249355582327168404565052575639878289683556483174213973783173191751884045426337,783418388779217407199495491198572563161785093246466615634830075323053502538909242522004194931674520522772536562755280126097220160459899598091584353065112800205031495803329979380114748688327366649214078234380064643848371559165846159884696566323937944146599304471519733682046929885711023157291005000370881207583|19818230550133203045823734101898906263121512206428289485014719092970295967340599816897147977749512129070950063889339566610951920388554330328298156066258170373411927366975503222525343688945315211747565841144619516815319867733346621311891854079913905473945585105165350274151561111090081792706060108559348689465,3535705381589141871228391312322719660822687473426523492896512078425893509048104602680687792493669387659393458499063851065894084002514574997947346565631807028562721897282782831306960899838643543821499923380013426924166037069379808013932912663720597103553887305082262913905822119893857258661880909162082386383,396232614221934638032209379440961132627800399045535096109310461742382984824006540071415151913091585171033970335144034008200593280126662125846778006926029922409396791751216059456912978293211117174561768028351334637727875808828406496707486419218523437819900629926847694284488804630237181598046520852448325184912 +10019618759445604574695938593576587154046024907827143734869384751181580594765954554297229655147503034078881467428687208204647162639839815171638500727552711523715462319701731893862102462479728615304020826611064530542284194703939928285119162487825469366941939907341692107287635698074740058272417655173119766470,-1495231899271916161022455577964100860902948284811380648472435397705462086200159484323324090415310461943736883556854457678257712744145878200402349694425772714427495950140611274533744925805188738644517051127445631541048041016411029423836592778690668280454275321001430386581000830461603779827661500573849313313,783469223238034771138196543049546952638608016561545783572815717469547125551690528706587314602219345674223915943792376346892343135362218779360461138111067908088830730205053230437782849794424701715846764766896886615248793041482000930114725702333293352788421520623938402925312326001614873502389289399996101695820|10019618759445604574695938593576587154046024907827143734869384751181580594765954554297229655147503034078881467428687208204647162639839815171638500727552711523715462319701731893862102462479728615304020826611064530542284194703939928285119162487825469366941939907341692107287635698074740058272417655173119766470,-1495231899271916161022455577964100860902948284811380648472435397705462086200159484323324090415310461943736883556854457678257712744145878200402349694425772714427495950140611274533744925805188738644517051127445631541048041016411029423836592778690668280454275321001430386581000830461603779827661500573849313313,783469223238034771138196543049546952638608016561545783572815717469547125551690528706587314602219345674223915943792376346892343135362218779360461138111067908088830730205053230437782849794424701715846764766896886615248793041482000930114725702333293352788421520623938402925312326001614873502389289399996101695820|42753617832955580018896456376048021312038672906196490293353833260191208069121641097415768067383199309083970209480148720670849061245193936234205337011636997701073642429299438906449136644520319530218401933372485811940869805081506160718825508067884253210821932270118450554609943933258707984251287707298966456434,17230882403850817862353558174953648187864024855604030801497255731670352761964080837026196910757872387822284474688098560486179344653906733048259368377140267627812727873134204479739477928295254560644024291521347574950750033700697110313592478883239065168888362080121017118321399563553912315660492325767550439625,185334720796235401233770375301583579692277465177160979515315309579304038663377302594175210667527463523713902806451243556694869849316694559583762178930255061453115298736511664428765337617081386042405590606496094216885684005811351670599975552269701611841562351169528636440894665534868320186990351387365005093446 +10019692946699738437088786776088494849594837049086417807717694310404351446172508582779767667693745900344488207593378322991177040183985344860702086830308533532509706853397521152883298228273128452797173239342923997882671035778655648164732292144430552486960912845252279998708953177942214236682313539500552760871,2604527605619485478722364121534608303298155156200794123073555280322873845863667712157493176540131822726294136122515227024701303496679207443255980148330176850776277321446427192954383305967741429509598325549628410919591073607402118557146971439755257250099080900555940132394424289156437827280461319685081840835,500718425039020767061203454192505123268716467124573838196978962956303476515938135055207132642966201859533626566887497521633145487747565092871485790754737106452537951081291971352805654412531250563576927867442028177911508524615458471957056998884949042800057393476930961808638050281181278355398049850987480026266|10019692946699738437088786776088494849594837049086417807717694310404351446172508582779767667693745900344488207593378322991177040183985344860702086830308533532509706853397521152883298228273128452797173239342923997882671035778655648164732292144430552486960912845252279998708953177942214236682313539500552760871,2604527605619485478722364121534608303298155156200794123073555280322873845863667712157493176540131822726294136122515227024701303496679207443255980148330176850776277321446427192954383305967741429509598325549628410919591073607402118557146971439755257250099080900555940132394424289156437827280461319685081840835,500718425039020767061203454192505123268716467124573838196978962956303476515938135055207132642966201859533626566887497521633145487747565092871485790754737106452537951081291971352805654412531250563576927867442028177911508524615458471957056998884949042800057393476930961808638050281181278355398049850987480026266|15699856336284744968275216258343503146645953756650748657692246165468174044843605062520381697859516745152728271221936503804746010309726370554190521588468426695997279591480421106636754720909204606127286384900034321176510676319624471022876412905986167145718126102692531020933251202001854123564019876070185880355,-14062166839366990397106911248374270143217677864591057546982352524148999437729801685798965579843060529335708158623771293637111706433187114619631528674568287241750380206758693785598159577574034470606603276333153981703961125634290277406642003061722480822932526131741380714977106447263763374124622526844984498859,322600729981396869806359195462894217882445977495880795669692121484810837171658548584546952485525802042033579797467228310295552846960328437752401071423653349872764602844139832402563063433112043761099494603274082871711473366936549010464198833941650861319850342621348528624209403813616631484437129382551268946870 +10019878828465334585310006306241539349820320632176313877609501227637096062920082798688866463474161563221707726590576927421178038553651876427988000587231398238649949818114022781306536860520405792494648694702226319794624629000713829609168795402418848754413215058377284034953425744232395623600320736707606263601,1457969396702138085449463993396644727452880810876852537963663018612951369129008613129868381569339225995112076334917995066335564006261425730889703965704362733694154907573251182502287488642500690958462811412545500622611307129116327910472660655763332350656262023349742750811995788737019311563028749123005882623,450291340913970001914821927902049497930656487941189505155449421740207064831253795807819514379798428822187833726946052293837627776646264129023306160855543475421211570474321370516290659041655321190880413623652464931091503946846331738732993987858421621514193715128900207229532916132573315382608752305324170212688|10019878828465334585310006306241539349820320632176313877609501227637096062920082798688866463474161563221707726590576927421178038553651876427988000587231398238649949818114022781306536860520405792494648694702226319794624629000713829609168795402418848754413215058377284034953425744232395623600320736707606263601,1457969396702138085449463993396644727452880810876852537963663018612951369129008613129868381569339225995112076334917995066335564006261425730889703965704362733694154907573251182502287488642500690958462811412545500622611307129116327910472660655763332350656262023349742750811995788737019311563028749123005882623,450291340913970001914821927902049497930656487941189505155449421740207064831253795807819514379798428822187833726946052293837627776646264129023306160855543475421211570474321370516290659041655321190880413623652464931091503946846331738732993987858421621514193715128900207229532916132573315382608752305324170212688|42833037907205783423276083695584027308854900022881436412191284154327219859963073830726581978719142468079055995456299937273491938799745755641832339881754413481117724798837471944396287268574687471412696368395253559323362777618554120629431245413190434891698142985970974309630607227057049486649455303551234276454,39533289765204979838239940217464189791925681811448897199438008522556423440885704979337332145873978223602711609006720684578384015360399795422483770905500296209984111909778890881255526888804755991926913525266473446809003766056812782710240729514579954010888129016691348159521572577875112811888010834450317724241,114445618247053384708154338158850812121782306445016732813783780022720172489813267526238634887903604880900808775058943405768328545540868455633901730958967680579278364092793074061036266572372464072327099841482886966487871555516444733955521438600902217517451457471166242011115873608622049499975622745683155293044 +10020286611438471830628019358455663881253310586699113562825236385112929540691864656311239753327727457544039348532845219250052901384983806849838772233628634015372101882756673893804993295286755978494686187836862364142553996432815511321224683238615875757382081170105089085250727802357622063598298344850144933258,-3518711690583590719591097309663537838033234040270517781284035777894691716513958367977437977244707408588621580445912322309023058291956527967904833369032334021917801602130557563969030363343390282689269679494383594614447232630864097161162053988664606910387710340058810601198928739842230703566256279504206597349,624519074467883157241759882142650482668439956786299222741478860768930417779553600133573019763129305374619657419598952403430928431333332942138935285782814167747294995855160857963617057240775629113016734743963566849367848417555290458534979590030936513460373735155075741191499370817771701007396549636851814063246|8984140046463484249883815882793946664284637844291004682379330614023973939307670161213321888699915249072065095665013984357459013131040423611078930602512682262356539184355252741789076484547599307370908468303880417320438645852556648240043112769759543510509999231273948875843246292758661134579579434257790056943,1015829211229239775971450394627474475125445320143707214965330038892897841144751214160653701706601947354240523693277132829250608515076685164228306669891554248890083979225036216154539270241518786129131737028646904986272214000689553330402618431223976598945398343370629254397826639390022921851207744783430299181,696229436805911789845333715373446839368886781044433762113742356470360747294068486152977041956647781976745992022313448046591023280602965461797453603661925762491060402477228052040796508933029960965488494546655270327536485285614615574903948243360057525231142937895796209410153481097105649076038536726330776071856|54848884991217637960566999744777250759299676195564728508167267655054271555707478739692179275489551583228746099712696785024768087317010330909987410610335755940330039266190842809649304513680352828151859917245186776225281746820196246056188053726348717015680880973426980177317094806038726097322528009147634772745,-6297694570572926762876118238570574530971092334512760425031884066392157325338148271545111848669911902764684562706179269339278979620083804367858431071965438609706945865206821584390347519912299967269039438763099113180095159546022212222371772149775642184659607016581991317838734844206339663600961049231899483767,114217089877346912860627247021964232304547591103532855496244374445579581677534108677722729277710412822218846458954885849274521645333106817369257230151814552428619784818123898009869914417388072106361002314975966932911313776975771180600386738223895005689517440276702703392932181245821359844597699717902940161882 +10020350829980446730171851653876883566847163081423697114380946239282341122006641305758856122547334357120649922140862854047676100901410759420113771337592330434048703781028710403003719890979006119445870636592350392949743016116360518402562929646175152381835283065319457849053035555929737557936105886116269575510,5109280702416633154295665717802160083976280911440360164357040723966034505263983198614731009455276771449649216657900445462253241694441028125347117381803166387820276260518904247537793302370100297043111469835733504997940289628818493126591029673530532890213508380205622484398576652164337711722991311438354895077,783009249844890893386725492620727464553802137797080547324163831661264002221403011235072342035014102836039015675936188668078646910670188403603171656900915122608838040537846311585633442130109085368959065613240580402159306705278726186443869273434480098383561830991110484097132938532579731404550435571781667457120|10020350829980446730171851653876883566847163081423697114380946239282341122006641305758856122547334357120649922140862854047676100901410759420113771337592330434048703781028710403003719890979006119445870636592350392949743016116360518402562929646175152381835283065319457849053035555929737557936105886116269575510,5109280702416633154295665717802160083976280911440360164357040723966034505263983198614731009455276771449649216657900445462253241694441028125347117381803166387820276260518904247537793302370100297043111469835733504997940289628818493126591029673530532890213508380205622484398576652164337711722991311438354895077,783009249844890893386725492620727464553802137797080547324163831661264002221403011235072342035014102836039015675936188668078646910670188403603171656900915122608838040537846311585633442130109085368959065613240580402159306705278726186443869273434480098383561830991110484097132938532579731404550435571781667457120|15925442580907323476159397125803944340654208405155024852617286343514956884706735535756801413937274485810029110697926230088903038708172843921662902925858010133310107241826173293821650453674715296467364194160263065021258375363251922427504055324499581378214158250201451314577475359578763255572268099357250433862,-7555018813268449946347299883155637510823174468910058845458344328340586029132905296413170968626375161086356436888766911933184468019856845539645923943455062521960029199818385839225962202237763532700191551972267033706448220551883282613693004882011515763441495954827960366711246754821589418038272565907011571371,493158713590448502858812148491777446425856175908645102112390069549258575786631074217529579034304661646702428496672314797453719364387931287920597953147023776521758543809562386644010437874871311725548645377471116791426470171042917330992088151061235643311858502168972419940204783448967903363982044887911681560644 +10020520888850607221318889209733010855356370939979030352174416847268871176606842611908448929226351061331244222832181615393476121893202716429497688626737367070357875341852767661277331348237224754401428337725087948250057680576003972340744936007808116625981445480427395587481367415686693519322831225744083857506,-3510865184553106032575534381192821350315875177100225193260562098432442799313338094676188269972656054940854032321449718355451351690660219631429988981801589127116014570347706272895437608443770068021130141264825492984427313262655182236186480543751195475768423487011396127341338009641051881511727659162848161119,631736658355910953992723930048397079196586052511742763210137641692860240361410089621711682505909275894759266095700988382555714505394268624248297891868203056209475282038131157087467910727013960998888913755441699771876897234334835639550616100989309716008969633105517000398222168491114030388197708472040972683126|10020520888850607221318889209733010855356370939979030352174416847268871176606842611908448929226351061331244222832181615393476121893202716429497688626737367070357875341852767661277331348237224754401428337725087948250057680576003972340744936007808116625981445480427395587481367415686693519322831225744083857506,-3510865184553106032575534381192821350315875177100225193260562098432442799313338094676188269972656054940854032321449718355451351690660219631429988981801589127116014570347706272895437608443770068021130141264825492984427313262655182236186480543751195475768423487011396127341338009641051881511727659162848161119,631736658355910953992723930048397079196586052511742763210137641692860240361410089621711682505909275894759266095700988382555714505394268624248297891868203056209475282038131157087467910727013960998888913755441699771876897234334835639550616100989309716008969633105517000398222168491114030388197708472040972683126|7743624975856046040306859618381122855435839505066655963077953345318192394961725484815279361678840380508650449544352702656790861663924047145774380332205220566837995316217250717822771650639012193352578327705393209628172084550305955102732361657948117240351750958876943333563882332223706621973470079325216233558,-1302101084353535785220069078550654080595332453473298993211431176604229397211571627224468015823760998656644913758576425096529602829962318111227560243799515644278666734720045652589883053894188670485823003998604116205699634345292108055002592831517880997584910995083278522924829895139882422136963697022188627761,817146068444645002282702401442161961453363715531517354922416373299365609662611633811411725714915989553805697260975442785287852917015804775140015044436435034561860932937633743951090004573111260937285724402644730836466114286731010063169028245934842509507242843981736397798548000353928823827450308171577842094862 +10020928293252284825691361744328291985679526412406671670547266480511907045983316758483586023724996977667177961315263269397743828323222195866600241379821175298238115703011379072606569390759148045042025527825985903353933863183965714600189445609817913064133950477152949408914363876047922634974111379776851043444,8142743010559227647391965354039043610167208616578224783916189122845589179285287981476385252457789283574398377141778580365522603626148442954692842646237080732477747098895946414915542936790529750280288364463486949414374698119959104763454330750738981793594749326992763123032351693132354526673391669903228534689,592964939014299189950759948556152413778070028508201513223477782517837089792535061751235218815245724595945353108562584681842937744985593454797280372456160144528618905336752579099036263281502692258180148097231362749391384857475259373320991218168838336648271137666762974150421876463236269917491554488254970217679|1349884692028663713443418855258970852876197688505766806916101525225125648882224033090914393786384981404185367136201476426040087000294669320520442557740324611111940178669433599306350594555401574017007121415045406126185440950248044705540071793090107212207268142684391021538262661004297297377597036659211434174,875208077680684118200876261868445011629698306468238985964846580756586701312125036248886125282325554453814339944800057599270619114144498434513170361313175501368378946075602194132049645256086611958223310749365652107262190169934699379958455541016773996539749758645125590779000274985163557422936755735709025447,4389763511378485954501282191747251660999265924712682485695638493214865378547677386856476228802410653501422368180730844272453992845175409659922990510986478738442978379229425566565975718386747664393902959866984083918397026705604419570614664652992630348606149487368881973666571039701786237266865588917768672714852|5132295574467316848841777686734617679960174295612803556136691640948831222631657128041983413228627956037030789543068853182770008751639881188344733284990628383483491534738190385257771536358960825091917844011611151709882253457446948086421180899165481250089224998180312937340245384853080966454437114981749282088,4739229759958591334649295599424854432655955954287517912213597569502250150023192426249576133181257597090869245470242256174272934097508617180274802785425851556700817333154643929185825330049486269453049410315760063060060300773867433992976428473895933388104059320286367359084036012644394853593574323294698599047,1155642354763640840161317866632512711606463189115904666846240158382151567767869875575965412366883980252176109447698054839109820546539837615968386168917753356894372414795267678454138557008897676758489406076799290056896394919016510966326013771652656266881913835619564662608220574395369543699406086980500479286021 +1002117978472811787753331928095730917976095264113100009019616793747721435107135088389509812754479746771762680547024275550906766428627777497396364614972130274470274918515966945652987824482224985008334448385591915791378703701911471719689908547324909949135740705163689874051360252727792128439306172396510982072,-605384264858430906616142488992272359132356724983679496986875094989266808748892270936577381465129550495430948251840196888998891525556778784313001078991820767039598015715393254809115469379426480017252950332375890914475777381882010670869152139638115965300974540658001803028482400664131564914546111105190254697,5913050976191825085156815974405378266929897129377882420061135471366299940142986781640170880340909029950997987433372868814199338484242838439841578708925504283923079897355159590243914836924282498902916652661483948536914918309139164893684671128828548900808846820323860573206533041501286493089345814823705125482184|1002117978472811787753331928095730917976095264113100009019616793747721435107135088389509812754479746771762680547024275550906766428627777497396364614972130274470274918515966945652987824482224985008334448385591915791378703701911471719689908547324909949135740705163689874051360252727792128439306172396510982072,-605384264858430906616142488992272359132356724983679496986875094989266808748892270936577381465129550495430948251840196888998891525556778784313001078991820767039598015715393254809115469379426480017252950332375890914475777381882010670869152139638115965300974540658001803028482400664131564914546111105190254697,5913050976191825085156815974405378266929897129377882420061135471366299940142986781640170880340909029950997987433372868814199338484242838439841578708925504283923079897355159590243914836924282498902916652661483948536914918309139164893684671128828548900808846820323860573206533041501286493089345814823705125482184|40380288636863554747802272146363479186663329648459490067115808757434033306882038739884681373117979723495792330864501446629245889731229516933727403492773771957483850679041758865017396807842498482944854723605982182982516939476048881995525535805104281408686338183559590430185038164235953706463250800021094604474,-39534865948835591455192703514729394748021266253728249692602243000799548352268225360374954844443730084878434721021241498114475458481167089270721522242274850596448738616202710373135498775106936938952151771547223007405550740805387552512761050820125134092471485389585963771433812018574391368483598373549383847189,156418754990595886837540510636676538980249340054775526675231187766083040611703861850669234853631535367187296945071108522620946681763860321505477715553908841995650918300850635601347255855518666703848642329714582982193362014895765955759528160104377932684150225067984397783920984799879483126817672124425872829049 +10021358599463053436428121851639014288861925656265693598359693460594603335959883569550641125363212428397536880700859686977743945025535807563785786052244914761332363029072620567677261483868230251440566526595521949067385197316983806258145013751454322468391099167319094251906044804264200412596430324237392628100,709083183297048652772820333122772466256400885278203522245823989743215866042577745109340161132152908476855845193022669210873284198994493560336775521366659865852432460708969754436068709338598181470025481044065851120985245468046464349075382208377683917405549429133970439515821299430661611942330536123845644949,516570730285299534762323653103362077033679349887441156383985263227144702832028548168588332437855509742797208817471793880841971810641558363411834198813856099949994799818753787070184420373328485385171466383296907894871575302325766835865200237080249407408770698788688709844525521993129914019403957225364497263784|10021358599463053436428121851639014288861925656265693598359693460594603335959883569550641125363212428397536880700859686977743945025535807563785786052244914761332363029072620567677261483868230251440566526595521949067385197316983806258145013751454322468391099167319094251906044804264200412596430324237392628100,709083183297048652772820333122772466256400885278203522245823989743215866042577745109340161132152908476855845193022669210873284198994493560336775521366659865852432460708969754436068709338598181470025481044065851120985245468046464349075382208377683917405549429133970439515821299430661611942330536123845644949,516570730285299534762323653103362077033679349887441156383985263227144702832028548168588332437855509742797208817471793880841971810641558363411834198813856099949994799818753787070184420373328485385171466383296907894871575302325766835865200237080249407408770698788688709844525521993129914019403957225364497263784|45614503146354773723748422556503247371485318543120586857419562717702458851951901017328552145694380945314803604713256441070275022414069445773768101699000362770774983002903055045789385932735047082208988353464300453066243128392263161058473354625441431303590972274514200470903553097396578608004283743393727480965,-18121746874119905746733087661833019801123133290011543785996868679743860577167772600952885673213204134707814090152450287251108460725457761668330446170883400606809709199165941064933022535458655256850936026007055165113021346772772048647561510274730081303287537167422875133875982474754404203878182518086566378039,115286014209231820841785285504789236723202458419099047051127275140595097884705397561562945865060894329450657461353202401141562369532605474636151114816630008035888537731586842019104642780200033707263419710825605300157241899226642312799356394901240315456385563221341513078098381767868711376025198760539717198382 +10021467180917602737976485607440169246689782775819592060097133723376896163041617997117690261968456452635527584517534178504548298348503697184587408892932776130526709512085862666360259215825375712520283335147827351975626062358619071671249870717811464295853663335144999169566479738875598518880232950110692415860,5837741371138928752178739797917364838658798118140089345232324713852930065920933839519905580179654383108038638880741427980662680469791777270068068248248823295528533080598248956003543247574941878960563240116001302598572351690506654603050328390643642345907246472180377442808566360199364409627306574545050404961,447367712945794368035040617182455309390859836657260473211881159345841479208328013611245196832742331205848397804369783648021077720443154207595416670723327933025826385393654289188255079761853719682847837385185400997339750661153486494578411301935184740783631461198583032914565210707960404049019611688784713553950|10021467180917602737976485607440169246689782775819592060097133723376896163041617997117690261968456452635527584517534178504548298348503697184587408892932776130526709512085862666360259215825375712520283335147827351975626062358619071671249870717811464295853663335144999169566479738875598518880232950110692415860,5837741371138928752178739797917364838658798118140089345232324713852930065920933839519905580179654383108038638880741427980662680469791777270068068248248823295528533080598248956003543247574941878960563240116001302598572351690506654603050328390643642345907246472180377442808566360199364409627306574545050404961,447367712945794368035040617182455309390859836657260473211881159345841479208328013611245196832742331205848397804369783648021077720443154207595416670723327933025826385393654289188255079761853719682847837385185400997339750661153486494578411301935184740783631461198583032914565210707960404049019611688784713553950|37349917633767587717677900017226055640277491797128368066909216648299856708848885314856667952257677125356703617528489552040640666031343260644627231518748509259039268948250724796991429094425535890736981916444739110193691988414365116633947866879178749608358114634543684726462828729304210028284694641568628398966,28432301470760114127472799211494908630719349909135890789013779669649467182102043473145513283547284407986093529470668063517370252190889483927419539271833812410008532555047333957640590516339384293520187649830718680466604203963675273404448810489933228206090139475240540056839557201036234130668781355507913201183,125217411042216743409615853418748212447815557938720716586287232669270939052168073429461670911284540249994159813915524580152040717865022372477773851596046555005754956888615646701914356508633194785367798807957000924761874706728044310360895862676117058335122487191434401996751617050877596333038588838996255145412 +10021498468260956088123000232540981309673362233093607160766199611849988598018670545801586655713528191099718167654049219862424879654097800612715754405882205966256512537388088543329708772570689386840584832681600027519346949153293344313097460804932850840053785736778266237521116511372386612740914586110495537184,3731424607272136278046418371062826309603938690430502989163037797814883875895107208656392082954628965555189423854897982564780098075475012739517997385664143357277834178448678167762594236943371764347482562787414335427396456552673654489280935057856453787409277651050808844230948476551514072021069206021678774679,804130312590685641878596579775606667166276173286759021130255643061750446804433775305738231667374247846782607238734204509216228540137516790899866440807044660490591982953819190288555363659024778526537985822773652575997791262130221988665167762257066646395773224522658242462757313827560884465576118125526400301268|34167053368438934062493883132954265990697806318308586148616977663701145830016368570117108522767165162437388551633476818714638781998737588453423052906955047313659481428825017492981415212399429876112133486106544289854247118707826610748061980313138870978861241099932331052851628733408772936072321439631381625681,-3231990625187035132148669134941674343311291560670575472626948487039873506375201953961203524971750773872175368844083313789606744945666601496978495543448223413432959722175027775640416642119534579082078058359377011061266769493053544073177090778768228650034186796092538667273516567672252447273843436045477135595,235833074847574898390813679013790646015645150909185733872405459206523708909325302363230937825102097363178252008781874033668789787718772243559737247157023625992313606650868510119173526138833975525463395139358451436580786324137262685697090102400693677208248369147898653293586089386800659102730021728025849255818|64608837982278224108987963939830921137767130655870201859314566649037112194604993755919994541029928783963356571015929786284493006279718103094473109088356869444636451105877134516067500703977445578997872357043341015093673550983708510265625469154579844276561631683451922580837098594165662625287526508058436293986,15854906341458894966500422391448052536768193946037447623218750633953720338742777805649471066920966160101792990529839212517155533383911249825767111242302747793376405376781322851763232537121183798411448041082168628199040455135693063512226758138709898399548068871039436946823094929235771529576088321067557016361,125647737690478667744295859750549841902875194170056775019306475803353424716724181236654109541003077830795994847519888612974479612555855274394676374638319448048091194349835875247946393849792063872096400150096455332718354245732182310596592154379165437563189009506346555534189191250868232374253149843604451203312 +100215518435515616798081693150831119413586767021678884124518533924984792516593586077070489902053827517598088670562746849336597165534172718871853401767137095032008213339529086616777467841346280017019578258259797551450310087222690828893461467525694138266456717327225955476876417507053206969995585955166268406129,95057958551667401403353090513192344071592935246219146691681088413017107538601166978955721880254187942559271242509539286042857509266018196345088028113071042234423096387755035509877692642793106294014825987119124937967036662120185797721977723389759564327297787909379686186622926363357951464215904895677999421567,102919326722329333489116060760618421823222867295966177344707558731080005177983472593218329502964236109795974387237881276225611846575332218440299281932674994159773703889896299379022277106535867836949285795306043775879545666098740309487810106763993748938964994198360229518682147400433454886610366004026941047356|100215518435515616798081693150831119413586767021678884124518533924984792516593586077070489902053827517598088670562746849336597165534172718871853401767137095032008213339529086616777467841346280017019578258259797551450310087222690828893461467525694138266456717327225955476876417507053206969995585955166268406129,95057958551667401403353090513192344071592935246219146691681088413017107538601166978955721880254187942559271242509539286042857509266018196345088028113071042234423096387755035509877692642793106294014825987119124937967036662120185797721977723389759564327297787909379686186622926363357951464215904895677999421567,102919326722329333489116060760618421823222867295966177344707558731080005177983472593218329502964236109795974387237881276225611846575332218440299281932674994159773703889896299379022277106535867836949285795306043775879545666098740309487810106763993748938964994198360229518682147400433454886610366004026941047356|97265337163108204413956364816446311461172514617683583383746668715450840222180976393430496104553022674333721978573099848181220662887846947468935453182046364733749916475895309307017567642434296055225121834950440706059303257140878621147190170027097598386070490643511792242136161870345758898813890460055238965518,87547457109798873839305649757452333043926932497015596041815056726077989206997009131840148396020804211298638181409067017194388111483773222118240882283209994405160200490126585806391098433830826470475358556954973925001096433563812177048160467037091694157852152308504545492956027258260588167152638099756708452923,102515957029857878751803789736896993327202543313952394340885451428025600212535749454672085478483321275958139112689603772374702592116757008616636478536965453679964666255956305064090090239129654015924433954512354305722977754010864408774189090428174122344384620043576093595618564991259055360564491303523423085863 +100215518435515616798081693150831119413586767021678884124518533924984792516593586077070489902053827517598088670562746849336597165534172718871853401767137095032008213339529086616777467841346280017019578258259797551450310087222690828893461467525694138266456717327225955476876417507053206969995585955166268406129,95057958551667401403353090513192344071592935246219146691681088413017107538601166978955721880254187942559271242509539286042857509266018196345088028113071042234423096387755035509877692642793106294014825987119124937967036662120185797721977723389759564327297787909379686186622926363357951464215904895677999421567,102919326722329333489116060760618421823222867295966177344707558731080005177983472593218329502964236109795974387237881276225611846575332218440299281932674994159773703889896299379022277106535867836949285795306043775879545666098740309487810106763993748938964994198360229518682147400433454886610366004026941047356|97265337163108204413956364816446311461172514617683583383746668715450840222180976393430496104553022674333721978573099848181220662887846947468935453182046364733749916475895309307017567642434296055225121834950440706059303257140878621147190170027097598386070490643511792242136161870345758898813890460055238965518,87547457109798873839305649757452333043926932497015596041815056726077989206997009131840148396020804211298638181409067017194388111483773222118240882283209994405160200490126585806391098433830826470475358556954973925001096433563812177048160467037091694157852152308504545492956027258260588167152638099756708452923,102515957029857878751803789736896993327202543313952394340885451428025600212535749454672085478483321275958139112689603772374702592116757008616636478536965453679964666255956305064090090239129654015924433954512354305722977754010864408774189090428174122344384620043576093595618564991259055360564491303523423085863|36966589133632021596451231446360613869218644305972974964188922476722370035917724082641341991636532809500406571267262673636673259154835535079572834230006192461227395506315158937114124659074990425552664025796331234355303904150803244972310400202941266552149385712614489884410598364289566113507512621328083820598,-21149549205459986335385704446469107610959268704221609170214996514478740430167085550085863459876947711137447213809502018277525104101042350103376631096271919925064995296178696672186362840988476041323653097243744018198278462448741240768165379772727430920245528842325914682295445854217287403981994755438946746143,220927487842748418739085114242513506611909793723984315299233121420377274197319470229298268289856409101985756388437199198962449705412131211265923072982106236351953282676471404053070507026981693842676184502073850443982862759823135849927410711140706664324113248738142786497634534093355523248932828221913746822818 +1002171279912987474674729832690970557140429555644292059472271841324924331291685060249454596336585889404705002700240738701699260928512934819245660001207610075089195766056310376194900771895925996113770666776022108500330653518924376342638824072832759321658474598385675431858595122771183526939999696158578609708,826219028959713490046361889088584439498783654783530925153550597879152616132729000468702177706363955325292708928091882754198698376648310966516057873159349764829040425546512821864182430231493467696041840597321743210951783900165181749863389211006249005916285731575237461143803624956905795631847651371075603271,8037828098286918052259824988376802356784599160404526733485731117320394626772712632224126968007402853349764765913068975115077635719542022449549397610278043584259551667143554443745235133704301422592616247052815801996895563245349515275951060813799742580455732670079073038616591480535324416008144264918698168050014|1002171279912987474674729832690970557140429555644292059472271841324924331291685060249454596336585889404705002700240738701699260928512934819245660001207610075089195766056310376194900771895925996113770666776022108500330653518924376342638824072832759321658474598385675431858595122771183526939999696158578609708,826219028959713490046361889088584439498783654783530925153550597879152616132729000468702177706363955325292708928091882754198698376648310966516057873159349764829040425546512821864182430231493467696041840597321743210951783900165181749863389211006249005916285731575237461143803624956905795631847651371075603271,8037828098286918052259824988376802356784599160404526733485731117320394626772712632224126968007402853349764765913068975115077635719542022449549397610278043584259551667143554443745235133704301422592616247052815801996895563245349515275951060813799742580455732670079073038616591480535324416008144264918698168050014|56177784089692916832266345214421120674340798487038570515623153805048107174705903801913422904686022519185882309714950449353350144136176082122642988743155385846519789014579069658520240091050781441562176069717906258293112423657764692478227614483398005555460543943687308770699629754468588531994448652035243537193,-1367086938896255072793415069058299472671169571526909227192393757206171174220534221238412428332819898373711167739278653738196147736460040492805449727552702294473184951105379473908985544436596593693459127262500591594358945429165046595165680187593280155590732587752336804926254680443537232304173256876819864345,143394353759539327949427865403227850259090677769631111628953936665415814894670562885615312902238352976078395198035416430261300974094600135242231268642783230986499797624830094698405716034919055851528418996945744623233014619026973652777892429824489371625486460871462705495597542593148226840678864076948049036056 +10022430537581100668502883292824778933607339338765926026805737984600928768394291101969168677779321137283218236917508266473465030665219284863536608447940487677072083129795072785840083494425556238492937940196822995238448372796541954279303435932510765640503040286741618037016213243353519162818665268721728774804,1745450390765598318476765814191109791291817192933930838487529317598912090407141417101048723630667618601898718290746648849351810269839537783425961583377520701947088669609241693035013571476458016904170389418378228794668337339954300480921565354479003099904568784841604791321827362751710640603340143528678878307,505461416773210200375665916297012066614237052797213136609066313311545733018491487357728242574093909073856795981653867763762281713211234379922321747443616377604676750509494828442443340820844933440417718090216464110039019539088373064239526712549777394214168807828906636896179669124200810156121848745927583143473|10022430537581100668502883292824778933607339338765926026805737984600928768394291101969168677779321137283218236917508266473465030665219284863536608447940487677072083129795072785840083494425556238492937940196822995238448372796541954279303435932510765640503040286741618037016213243353519162818665268721728774804,1745450390765598318476765814191109791291817192933930838487529317598912090407141417101048723630667618601898718290746648849351810269839537783425961583377520701947088669609241693035013571476458016904170389418378228794668337339954300480921565354479003099904568784841604791321827362751710640603340143528678878307,505461416773210200375665916297012066614237052797213136609066313311545733018491487357728242574093909073856795981653867763762281713211234379922321747443616377604676750509494828442443340820844933440417718090216464110039019539088373064239526712549777394214168807828906636896179669124200810156121848745927583143473|62092481921639574438226283198332200678734028657724766941730022043809545444204108322446905830622252301375431538847493859046365695561521947886739278282380330944740137778796806258440017010320211759144908638103476555150573303911926239710190937911611647166321874200336757808613044926465128049757211183544247137033,-45250053315775064910191280612561362661486537888549446589078696876018947013616669550765115160411532144837380748629686624052593601626644191366587957076497250945144687082001936959339633808733565487985938465191480629685961056777143827741613522372695750936020580143021192692134512265227690413020620317312128938767,89818959533274049458857462069020739338602011671046728330943513188118466840658369260446327848180189713317967953477747595755322234416809755612045527023070344299134617743385420998285144607795275808302453674682604268889767229654448620219461284821255145925444306004911131336470833940664306256327917520781637949994 +10022447467429108159774355787589122715485396978224199367300758397771363796346073591552810427326339622121413685155961164725589610901918895551781900417862806225664599680621980718988526130452221161919053852672286805155084312599146807342205269705230729665300558186233143844168304167857171548003707472393702474384,1188885044590400163258159304120537014931301063692806659646722818307638465604090862597898645794165661603569562151904733849823451481071963642820939826997500655539582070601901658042242359967350311563512079177663668335375683704849269904109356286951724174166294895547399547486092075854607019467491563004574181747,451886511793730238078310968270671960837012936994555807769579552350299617939295621484477388940254813126337697555682035175155312684470552706006082326229489214590934446980684912399661406451818153885180492656373585024394872163807899894979861799817481760468528780471201306793514412189815424515752868704991093442748|10022447467429108159774355787589122715485396978224199367300758397771363796346073591552810427326339622121413685155961164725589610901918895551781900417862806225664599680621980718988526130452221161919053852672286805155084312599146807342205269705230729665300558186233143844168304167857171548003707472393702474384,1188885044590400163258159304120537014931301063692806659646722818307638465604090862597898645794165661603569562151904733849823451481071963642820939826997500655539582070601901658042242359967350311563512079177663668335375683704849269904109356286951724174166294895547399547486092075854607019467491563004574181747,451886511793730238078310968270671960837012936994555807769579552350299617939295621484477388940254813126337697555682035175155312684470552706006082326229489214590934446980684912399661406451818153885180492656373585024394872163807899894979861799817481760468528780471201306793514412189815424515752868704991093442748|40311793122681847438147936825674014314470693373123318161207015676732082581716792137317735331938108693356512243120485847992937858572985495883514340613966135614307974866016309204238807033530669264492564117724246353883749827195305324197399377631361609176376894124562777952015115546002574992839306368859847102214,-33025539083635098527284543501358773726385310602673068647569756256609245347645406103541323476799319282115094670558563042038040727572072629107289743928712116480609261863925810781181839890265471330792670893248452312920468922228853995606392415425665874155050360471274554137526685669823510791388257867791420447345,119104774305358145853754696022566395542085319811674406549968528384273306539129655277119394569116384064134522924495522726505126314830673393570305912602792523829301472113875383292982915986048501532006750975293601050038174705411480721485112499986909208662941192321772927410908019836648310546774872889908741289549 +10022730206246523605885847628248331589129959745152946800589982371582759735440896033124734292653525513269378463322751069994968860121969888496580966465696069881018097413525001416210515174455496944629883370533539582159385347137053307519490537337422600372155743988569466107652391801498216166822344049274248006914,729727310531644666459577636524370584122920562232400100508958613100574209791027073647329563436154072167135037277674792721862334569450792556614550488339055151138688316081220432057278684502305768700617734898572463248131416139418546546921772768563777642345566507958981323489827996692750181630164696164350792239,743420530670049129014551314283001582671251574132606225656558769248051872668919945335156046109684599461479010072698042194265131432439432111708952985059170648240550914992169145894926437588173425753889988734024781047390921725232442091277340971091116650569099484901188657501225210251920789312381353410873675482898|10022730206246523605885847628248331589129959745152946800589982371582759735440896033124734292653525513269378463322751069994968860121969888496580966465696069881018097413525001416210515174455496944629883370533539582159385347137053307519490537337422600372155743988569466107652391801498216166822344049274248006914,729727310531644666459577636524370584122920562232400100508958613100574209791027073647329563436154072167135037277674792721862334569450792556614550488339055151138688316081220432057278684502305768700617734898572463248131416139418546546921772768563777642345566507958981323489827996692750181630164696164350792239,743420530670049129014551314283001582671251574132606225656558769248051872668919945335156046109684599461479010072698042194265131432439432111708952985059170648240550914992169145894926437588173425753889988734024781047390921725232442091277340971091116650569099484901188657501225210251920789312381353410873675482898|72678153493282504157416115644391264652311137140691071678059939078869970502440343742868078709786102781757123551689967637475890683084227768997487411568948523707471659432320585674519265605598599734502760770267332905322559905487379207111063130039684891358469047921852095373415568614214678421199229135813148340086,-33947255666808860516772098102208086001134373039996489095024233296987004975315716216270171442041054094605710390151835995913332617034994068103936254773578912095997116516855870766220741602335129322709546766837859664219492792132163257557798382623121354098297535938342782377977312458602436715508338777893530715947,106484190269718620144286637065233814518223762302071472353291401620347574484719889974719727699170546479802692571973907348709106400438154108695479596777257546039047068390011589281587022778512291574952016353907379824791098458869045617748541670371657706126860369909581308416699070396340994092087729258233572584479 +10022801037884735919398225401015346770690037220981230548926941756106963920408338416095733094536206053772963879852109190901255264805008288279841331919785607478274212775267264447609163695284184368267756738466008982331882800742073245734831347575593957813641726104668466028052775256385701674654962758632735214325,-1581758127940839328365881014818315360646059541554455415456767586268677829342640676667660057584626141079060910685268398574862315277919005616512245424342499450499940252940175197812452339693288044870174334000429767858420712066019926176503980859313840839446940401868444636117019979796283038985302067912785275287,496761537019467923365643288264945659788228256979170730808696057920098575449994591930452099194380843846370073248896650848520976197841222484748214967557803091427696552713317560221122191533744679546984546053333189737767090004462878944114371161170193473185997313558677097782867340116873490763865370370260817678938|10022801037884735919398225401015346770690037220981230548926941756106963920408338416095733094536206053772963879852109190901255264805008288279841331919785607478274212775267264447609163695284184368267756738466008982331882800742073245734831347575593957813641726104668466028052775256385701674654962758632735214325,-1581758127940839328365881014818315360646059541554455415456767586268677829342640676667660057584626141079060910685268398574862315277919005616512245424342499450499940252940175197812452339693288044870174334000429767858420712066019926176503980859313840839446940401868444636117019979796283038985302067912785275287,496761537019467923365643288264945659788228256979170730808696057920098575449994591930452099194380843846370073248896650848520976197841222484748214967557803091427696552713317560221122191533744679546984546053333189737767090004462878944114371161170193473185997313558677097782867340116873490763865370370260817678938|11794018787280482940784484560654447929703367834543013693618622456325444683498014462584498990809979794991029406828035162064888206099231897450516338131683344468341641773247077777974904033180523619849644665052604243871182886239709602918372696154159689574416694382901020412810986466933364313296340223658056711860,1521303582082972784094072429213245037004474422912041747980341661334088522130166480999863587718878595218681652383126000473728595142115360315778132844751721718890137106680913339185860894697918722593994440198312742439897553470706013918108591714015302153342792691194124679477731145179750991721088470556891980683,422154249545788907790313192562529747503206514258177376656051975747255059759645179919603489351691318624495599133821906453410850735326793444201922900151270842818708202863054380424556183873836633029531584190623724167592312286966999660766414372084390763660497972689763908414494950088490657933080790950343854684683 +100229993686309443431652234853242745584964039848901396902154758000675611952948762456754223980100376888310959032918053199573371179952836402943594446966248713771392255748269391671122973567354604611827710836480143363448852247469233467634585666281897503837387248046923275198978369387627574778973203963568459570613,99141614774063628352404317381455383177814780210220526925227232275804977777537108958838490639289349073928621828114260050626184229387757267144939794360548040966543453766396248232212371430223357646841577045712198699745634479223254936354615654319866477688010773948549511551046967361375809493630740150224195152939,104882524400956127942658813062851389442407913609672222789148495255743494809906874598039501219688723468166574648371069153919928988258063568059818823680918241728433303999086584504182405446032391227196284068159574388579981415818096136448105143139694516800086480906674126689437313489030594417564677758780953521314|100229993686309443431652234853242745584964039848901396902154758000675611952948762456754223980100376888310959032918053199573371179952836402943594446966248713771392255748269391671122973567354604611827710836480143363448852247469233467634585666281897503837387248046923275198978369387627574778973203963568459570613,99141614774063628352404317381455383177814780210220526925227232275804977777537108958838490639289349073928621828114260050626184229387757267144939794360548040966543453766396248232212371430223357646841577045712198699745634479223254936354615654319866477688010773948549511551046967361375809493630740150224195152939,104882524400956127942658813062851389442407913609672222789148495255743494809906874598039501219688723468166574648371069153919928988258063568059818823680918241728433303999086584504182405446032391227196284068159574388579981415818096136448105143139694516800086480906674126689437313489030594417564677758780953521314|74350434749389969050012184990337127551177662105941520713519479144559556197790064845857130327167806787623076521428876751871163669518580183330141936425233250661556229643890019866856080560251792692090494599862764037832371889499003253542457382200017573287275373464647146587627430764219256453016377003846953421792,63957711791573361964387609614017192151897432836032720396105880275969302058600840013396804158201720534370023895822842857827830012733763196699928990175961939998886321856401382898475734879783268690655497427397663979021512999064707392335539401656442120559970485354029428771216688798043679886727502284879667604695,122094202522303244187343830185980046602374556531568820744954812272038371153739943186637285289631950376927966459293327247925407412742819149064968500238603572438294529950547276948751033111097715894035925769404645235126181286620345914299937264438033627270225587240098530161700877220337370607067995020225846162049 +100236185197041329075554833621063049933091933804804579181020863476728313391686305869039610612323226747485959655907451027539483829746780221656275287251359920572256326848112354466643258852396004468792417619989592999892771161118188446161121453052287245392349650298061886772129843629230859327769032485896380376,-23246228755139486121091450291914215536752934295258164744923084651696211557139982911633633936256958755233390860799953871691506689375274550434281909010783595844874773750530708001462730196953616598369162178869242223651107363158755851755977149870788847101056032248840046983417481075963548958473469668684959891,56573523673680298471644280373809509686143659597565817726545502453421314503494549466829923326874504507298291631695935926527600390521472116074127195438583945763976558015737054829572336871056542824657451863625497940311479875421301704568832621760721804490304525701867696665290350769186367013604263730372702025776917|100236185197041329075554833621063049933091933804804579181020863476728313391686305869039610612323226747485959655907451027539483829746780221656275287251359920572256326848112354466643258852396004468792417619989592999892771161118188446161121453052287245392349650298061886772129843629230859327769032485896380376,-23246228755139486121091450291914215536752934295258164744923084651696211557139982911633633936256958755233390860799953871691506689375274550434281909010783595844874773750530708001462730196953616598369162178869242223651107363158755851755977149870788847101056032248840046983417481075963548958473469668684959891,56573523673680298471644280373809509686143659597565817726545502453421314503494549466829923326874504507298291631695935926527600390521472116074127195438583945763976558015737054829572336871056542824657451863625497940311479875421301704568832621760721804490304525701867696665290350769186367013604263730372702025776917|15573203821391096660668742152065727671791482748659900060639926963022005424305428598384096201045285103243110012385503647750757013115954608677386233978142224494513680866630913236076316930192686744226921983870965664346251492074685634583531334565997695428546882772894918870424603926033309071559111059501203642333,6451721584690521069581901111974092204654122587875579916279551744658661205413364185368986076832511568929170794843492990781144450828332965740817648161987976580582338126230945095334678085775013660661642032765404588316501300352495628863315640949745573214882043885532409624351786399389352651138436910377540588715,364800994330757396882653090957020494991186585063682233319677342832051344502776958834410035811370111943816463424448302716551318762170472662165419035921367121365358358160571142517808605560056227966869017916492144933000445349984077920674346135535102210585266868874844995392794923436866721883251932973852604825116 +10023667082494025533694458923906062911614808800770741660171152481026059347510371753561616097379084784341713671154750835715019868680624888814365226032644794597463378220681171484265152741451558871527205613714299617780955377578029153710181790009777505367079339560569389236075705577562497976407198835496123421815,8237178824212969139758302266371465433903111044341794615829413365403141507594223080352356455683475273814082845524013102162873125179530876016035628585832833134556337909718743386830931466874558092486241907311137385119488677802975754525714977343935483066353264879509528297193753064624793968877384112576484389591,423224971588853021692214116546653537988666116441804013450094782696541031203993989512468938158606185066216192664407632356213925851579704646681338385590758369803509256824915492724160624602987883926813515751341908451718832678074898298694978135986894313441355375932022035725661361883088309484290780962315557040384|10023667082494025533694458923906062911614808800770741660171152481026059347510371753561616097379084784341713671154750835715019868680624888814365226032644794597463378220681171484265152741451558871527205613714299617780955377578029153710181790009777505367079339560569389236075705577562497976407198835496123421815,8237178824212969139758302266371465433903111044341794615829413365403141507594223080352356455683475273814082845524013102162873125179530876016035628585832833134556337909718743386830931466874558092486241907311137385119488677802975754525714977343935483066353264879509528297193753064624793968877384112576484389591,423224971588853021692214116546653537988666116441804013450094782696541031203993989512468938158606185066216192664407632356213925851579704646681338385590758369803509256824915492724160624602987883926813515751341908451718832678074898298694978135986894313441355375932022035725661361883088309484290780962315557040384|26149581659024134542252839056088737943459101230098434304929833472689045273647101980834416767117184344850968739815058973073425320764635194473778310753733774870500611744687135320440722493629102059325894273417025541554717397282491317870553755571826770905575804901409545560793682652830798005534542887045797606186,-1697969983698485305905454448895722929114256960413081228420951351866600414430800217182268923658152076765210118720420817273440690524435493363475828642615467592516719174944772197605654745416391960101282581330420264887754748587983051609045080004443224578293135292425351561632174977350140009380537152490928076887,161609629862554141142708472275797044218689904367615056614920333643328937851927686237891781051003871507296405842898237370248243352582987628460341700892139196626441792037632328670727659225186548971653052724874684965299456515833967561157293186033533538079205556741150926459475886439855496878616457828726831550112 +10023862893594232582190646068648463209940952006884955056666263414474264317722655546318247009455771884983355234222787422801894657323776793269825967901010897328305149754199815134059038386803327107954623997783328925014573712361190412041544730846393144970158584993932522919092961533807689663994273510181230611975,-2760322820547873699921094239708262618123220686640344280427532457964735913231839541155448488755106353058077772483391926518490758309421884945189004380274532339303673658136307214150768559915038249044318636340829040623019533080008795877188365713108541851533478868182315253939354465782006188226272150540248455533,539774532098344028178575637715654362402942864818067869426574212334581836029933543954242820122684669884416483020859433711413498388105161261765872011520166122694643001745601237406507189268543940858796801993814111596277340371144355358041455940732653675597524992815557778776692308187755956982584432604519599405036|10023862893594232582190646068648463209940952006884955056666263414474264317722655546318247009455771884983355234222787422801894657323776793269825967901010897328305149754199815134059038386803327107954623997783328925014573712361190412041544730846393144970158584993932522919092961533807689663994273510181230611975,-2760322820547873699921094239708262618123220686640344280427532457964735913231839541155448488755106353058077772483391926518490758309421884945189004380274532339303673658136307214150768559915038249044318636340829040623019533080008795877188365713108541851533478868182315253939354465782006188226272150540248455533,539774532098344028178575637715654362402942864818067869426574212334581836029933543954242820122684669884416483020859433711413498388105161261765872011520166122694643001745601237406507189268543940858796801993814111596277340371144355358041455940732653675597524992815557778776692308187755956982584432604519599405036|48715243603698629821940426961114291788526831094737919680655564244368028434506892148169445801801507062147482077938401141271200004998443292904217897448972538551776558146708202066192286102689914350481841990540885514221263570815029978710961611989482704700171591369852446182654047272669614885074291437285365544460,15461979039278362276597154663342472093520340953601325231902305531667625678747495978358134272949704300055117324152966543774546452680787464009096008897144630532639259858616922948118805845884304673520502690819270668894425836172912196918903901652212033563796089034742441883378992888990103186375633458530164516317,112254170401540486949707124025758283679636240637378289192656933481574624585762302045534446659987957789349537165930984237831795400327841686426067814232036082567083362372524941094990583657803451112651533845361102072607539347050570081691100018981326399925221570110823787216043908322347678600920061436414622205345 +10024289314253109068181408824584907548682813194738591861732979563130066037537322274697443177137048505246344585833979570630525401656305713560413859208020518275537432959569499157916033857588787751319126726484190263493857704290501320067515311770609186057345956871152108834406551727855172143151298819670712846606,250504711193651543885319560950205973661493792695329060474635142907355144915197487552594082031949875905008463463563678142215091936373578313885813322111597330162926418717728507984924427400756505737871837782137693463723537653383553918621336520844369928180694979696895523967764933497235970432812594037072497051,715621301200572432492975207084152505969843326949635795107806123209445143151718517449817068713936125495042559248838811939558778417894618132276860461288711015473626724568542195567695133648202437411311798035098899324593482673311597084169133485553033610858821471717692594066324611630669968328053616507731719142856|10024289314253109068181408824584907548682813194738591861732979563130066037537322274697443177137048505246344585833979570630525401656305713560413859208020518275537432959569499157916033857588787751319126726484190263493857704290501320067515311770609186057345956871152108834406551727855172143151298819670712846606,250504711193651543885319560950205973661493792695329060474635142907355144915197487552594082031949875905008463463563678142215091936373578313885813322111597330162926418717728507984924427400756505737871837782137693463723537653383553918621336520844369928180694979696895523967764933497235970432812594037072497051,715621301200572432492975207084152505969843326949635795107806123209445143151718517449817068713936125495042559248838811939558778417894618132276860461288711015473626724568542195567695133648202437411311798035098899324593482673311597084169133485553033610858821471717692594066324611630669968328053616507731719142856|69691918841176288984823797473901681196094628879675315489755259444998436434953893357490252440851727841764856894926617359858762775119043951866997363697297297444653923770370354552225052699848341814307273549886449783549055935119439453155817735871573060612568620074695549908654214345458834165261842993120064731877,29396998803244259208706324369693841135210373137766178345587378836957006029896347992580130862460199303906902776177861781944189386331882004200746161097147483839158568813322086972498062377955537624817737605600339132204987534032119897113967273038860438816060235575010015500174845850861550917579850703027368690837,106032740697299793989572674990101926746114173477172287236417937947154096127701068054351010022541808717403069236123423199088480578855329299917113038220143550055260783011691574203288951873393089140671443554631887510834797278656898859315134431047639142121497581377857339388563046962362704012299890107532747273864 +10025428900225290685290151690469854982214932916715816521705584076773008242243937008766386881454192668460673460928145859037221457715710934570710912601758825277917537132977601878466722300639421318388444709119075347515835153260761313907776418189378977092187686581753209864749194659254262457796167519362282389944,8035407417908027120985682166291560102987169154314800046344974577695327891178900017914738842677039490694291401465931876496716613929624358740551659992744919248664062419629947961043318471204322567520912143542047278378993142962380418872588429956261466474640589358106914252999077869082097127384356318300378316515,526506212965607285294504652802203087863317784238837123201810456971631654056439372780456787465506517550858742170829690899565417756124817089047569475165769047941621936008499130409010932902058625548248971355379292220521819976269615165269965092960486278068237861168382524126578791019346639264332649030378056985183|10025428900225290685290151690469854982214932916715816521705584076773008242243937008766386881454192668460673460928145859037221457715710934570710912601758825277917537132977601878466722300639421318388444709119075347515835153260761313907776418189378977092187686581753209864749194659254262457796167519362282389944,8035407417908027120985682166291560102987169154314800046344974577695327891178900017914738842677039490694291401465931876496716613929624358740551659992744919248664062419629947961043318471204322567520912143542047278378993142962380418872588429956261466474640589358106914252999077869082097127384356318300378316515,526506212965607285294504652802203087863317784238837123201810456971631654056439372780456787465506517550858742170829690899565417756124817089047569475165769047941621936008499130409010932902058625548248971355379292220521819976269615165269965092960486278068237861168382524126578791019346639264332649030378056985183|22138319840700167895312881508181272807615611642960031764554010440709354488166777949391350577243475719290294812551529754345491786841502661934416467056115565617682227037416000132315258676326832664293472268496755124942179527934459542753167413348749025306046598965185451619481594689484505194124705909904529437016,-11131863740438194145696527360624732907005872365618169777307266620259512556501908857842536958655885195096195748687569086057992329814846073549253878495916056982261048696264863065937434987201822416655310303356962123778695372607503843603636308900759414300401601767853289915741229529512784406304245742359645877437,239100722014735247362237833086276623512072741916888955896402203382427372194255695065669877432592987292352301916479402236621014870053157629159394772682571609781590319296070407875820019520943129073048256367075297134176669670916790346961022995994025660850270895833918044332478002360056773821184240475743476227793 +10025696373056081323076067608649787757301021243808185859274808349280293058956119916709251366791092102112010300737183625444037192198725817688527600134257833611989912831501342672141015848343142445555687647450237725473967806277927764282835935236016323094913726640542283793306041765928288192544236949963888652742,-7551573577419239436071851881922105087510160439185121186338107875456959549550841973546977393389532111591614312842887678906809652876632858754122403767673808362967953534249136664179536748454994677273595591516700421480181975305574013927943181245218443636797391029556909610245497977668952560989113626530355626403,488551202347944315504020596344859283372184958565644254623325222360870646703286196267475027122265755221917465236349901297478448862017138325309245093096937651510172757567584161967211867376922683411877153052678659984267061266457787269417246896692832538104568250487618601354692837088103049130077128213591142309282|10025696373056081323076067608649787757301021243808185859274808349280293058956119916709251366791092102112010300737183625444037192198725817688527600134257833611989912831501342672141015848343142445555687647450237725473967806277927764282835935236016323094913726640542283793306041765928288192544236949963888652742,-7551573577419239436071851881922105087510160439185121186338107875456959549550841973546977393389532111591614312842887678906809652876632858754122403767673808362967953534249136664179536748454994677273595591516700421480181975305574013927943181245218443636797391029556909610245497977668952560989113626530355626403,488551202347944315504020596344859283372184958565644254623325222360870646703286196267475027122265755221917465236349901297478448862017138325309245093096937651510172757567584161967211867376922683411877153052678659984267061266457787269417246896692832538104568250487618601354692837088103049130077128213591142309282|60393031392510595353689024388979736338459176869905458858711562614756995826747740419365757994707737913997543366818386810567166008495382740947599739430340534765458717365457600414802742877973222192406990314478073640352910084093417199594859293029865969059185936671473103965892459853411850141569702842003428649274,38329753573953857590669151489102652306888210200689056278625104334993443543324622863340848043537460677248162565965074671978338401303611611484783137870568580776992301362308417714890643838644524909137849140837295996399799637901901974938629017550061052634048860038885099946489697555545683915123490961748882032563,86948805727102164020528697795654924433436758890959241635759391106001442581272485956111792521204085749386969011988358799013634480122996757146530322550896381169828204152724081141046858586814946327125019525970600049950459272456428386457599502469581747116784271717706447744628609754739530433937342398267975398266 +10025795277027889904587708106143218928217212795791943900096455901045016119560329143219194735847213817310006544292588010221295347093799623990992065640705758739633420740707391553060038825197435786302291280814741597987499076013530747593280825513696921556065232738339683658383829389180388637941998690144811369597,5684979695119467447669475199616030835217750876317308626399899267476547529035287916782085067945907170746605510283861183133612038067129245932165458949837306805149633974813244043762392619755476811530088171886491397765159164208502011381649757076514242464099478526057069033992519207091422655970324739132300656901,562007444349085595243678168150362315344210015071199683818344834829191775432825810670825147187078104135705553739701002486305372357596398874560795249464367016590567012959728033251032467564115881230202627660086530992291649152268041406000599974523312325932278194132351429623587227242904398909856612628818780435778|10025795277027889904587708106143218928217212795791943900096455901045016119560329143219194735847213817310006544292588010221295347093799623990992065640705758739633420740707391553060038825197435786302291280814741597987499076013530747593280825513696921556065232738339683658383829389180388637941998690144811369597,5684979695119467447669475199616030835217750876317308626399899267476547529035287916782085067945907170746605510283861183133612038067129245932165458949837306805149633974813244043762392619755476811530088171886491397765159164208502011381649757076514242464099478526057069033992519207091422655970324739132300656901,562007444349085595243678168150362315344210015071199683818344834829191775432825810670825147187078104135705553739701002486305372357596398874560795249464367016590567012959728033251032467564115881230202627660086530992291649152268041406000599974523312325932278194132351429623587227242904398909856612628818780435778|21268893649707309919570226960346372728495718162766890279898665692070832053021527941744710318344298178920800948932846738089018664772788493927580517099544523821251022066659574678369202749060209753445042621950578890219002532761197990179516522502045501310564866950615799259252489912339574839719060814022687315833,-16974163508967143175633640446755920949410222455507178592573412674696095005693865169009177473634493301741992193686041205183814819978515841920175784743689108590732720018205453159865088935842801461210617037675036778351747079803439546961298001090840400908639940207556458714733757110771041917290102952953525885901,267927541659497862467954399158595317217757334505550228883969422271210761133505257969057962914766286654857630940214532971487737583736851759345565614399969808206018020458924660929875641469250964043761370010683938550578868703713683401770700995854517531350144574746588257756156838858326386968013405064043171677102 +10027231464587935675639730747678568553908782143975994882531107664457436183429164280181747996889942331170488347016005448660418260392761004178712470722876674735769717730721096608074660784751458654872470573207263246635112395824536847938300087322544843942058256547417838850894365569811278659238183569174057618461,-4440267082761131414853294025879558077404333378765096794740543986499915534978609296838455472705453725784503668845242671918380807204902116758601260037461056825902249629220350908043324356588944839161111532952326818438147003761862650635018374512533491039199092599100710336766544058009407418500582600655649176731,648644865497954786776779349508457974872894617589720812073415733603605246322174185807123848556285887617844905639166726609275182111944451202589938026255239735903760010573449137429043799240258539000988138770732321918291392488327546867698375214486961050410251228096630089455328472100573545758827677160537099320072|10027231464587935675639730747678568553908782143975994882531107664457436183429164280181747996889942331170488347016005448660418260392761004178712470722876674735769717730721096608074660784751458654872470573207263246635112395824536847938300087322544843942058256547417838850894365569811278659238183569174057618461,-4440267082761131414853294025879558077404333378765096794740543986499915534978609296838455472705453725784503668845242671918380807204902116758601260037461056825902249629220350908043324356588944839161111532952326818438147003761862650635018374512533491039199092599100710336766544058009407418500582600655649176731,648644865497954786776779349508457974872894617589720812073415733603605246322174185807123848556285887617844905639166726609275182111944451202589938026255239735903760010573449137429043799240258539000988138770732321918291392488327546867698375214486961050410251228096630089455328472100573545758827677160537099320072|46009921711915221172675762660378602913284935911769009327398886576025556944392570855250807675821524214292205195685897041743100957229886916848065466280285331142834500895832407569582736664860239313946858454701727263963934792933919730548918244937925570913918752904708052633399310307728141781833372082621654521012,23113475896105025107394605331889841460333790037514477610982037645403180016015663190091781841332002225731097821541822074963875072814544317858697958764287783670995655541483455486482934375887626558700537105583870368524253911345190227270218382103667348149461739557925536602713765457923023851021682724701425292285,144158936962616263074854848511540730235089365933518189341717329619972562457005307870230026030935456404849352326770086269924745439466300887545713518178631945541398236558781981355199214433550895067837895099984050382102279411033270720567051341019780619857285120976043103941344405749600962507460384488305160927409 +10028350739307738239553437040783010537831658077620987335136512740169676263676747904072610524038617826531776850363823183733316438383606013506243196250082245650509414494066287488240898643357609392647649696817421880362011995934355791054933802156008906495889209763185641418699747996844644309107005112769042124318,-8707724909729199988066303291337645249173793540898282778024990496827621579508639942367666079187451324678862416133361451354021503910330702173658524643590899178624105480074443491370735876152164927759833250717689047284841393067105491783984924710355073809596596309834373465404107419929383484013294580151001556205,709758849546988349416271112886481225556022674837057904210411294800853958134290458192748393663317224087035819308413648727887254453418237510262143014913358121419251454923066768843049946946235581252429358021933518874438830803109875124372809973223871915099838973789742920465584130081571378073407884375094121268086|75318449301263415467735932548665333631833209464496019863964846786179367552717568503501179580307848690931127517090493242442668414948431300766436151276701082711193885234526326365772794857402011587084042826807831628195071551088506032974178171732912459672450935320336391563419572190330442739927553072512433668492,-37666884930926310053453757600840503983118095033807980727340808659295811653448510252245931091899049389573453471548035871058367468721695376360491358764096189091201995027259909431928638716214539254513869701208949761595174662474754859884399931318260163661631099379190898913272807941135716989109599181870658955411,98959195118263740892956000993748226884659367220332828268929254332674345256309662055166848715197441404549693155497652798902798133883715701424760429622411156195661335500009744018343869593442437677434882815576040667549098187431048868332096738149061496080175268157896224795266747997461998351291015430290846127991|78879828918733154172761232408717349879484411577276118445906917725867063887736403698268620449039366903222875325557071665537210036919488537356651491469585633888702020869953229589162929365722510146484615161939420331780149558523973332122378453822513488024388432239153051455307708434618917487055946350509115159954,76022832032228931560745697540761625684085285731069434889900171934534714627230254695020398894919788417337545845925550378316932977023401785630385785258013781974664129868656557307645950862628223235191878262315897562597443878541677560567949780990105397727409041603839660905756066382442879369790583798789010488305,108311876812780092185464248430819211209817518273155531596997245418001592611818208219323720419932959536655772814492616252593108875759365327114882816039706034356112007450695439375062874008822159624139628714241658551452565287963490475631456873365249553095821106476912177956653681222238113836907581862856535718737 +10028851844651833483859929571953137249991455639548429827963027247884276614126582614765754168788406967864569784762670102265610798647378386836840906226432130520069813697908016956233348000504802826879321612396642793367212498698674853695626535119160503473498038239103440516242421347929877540717111105756485685416,2125595786027029524418010744012416366895751257304333344547068089057782417304598028459234751630103098379533864111162338454453990302791615035666668646880454521909199231924063610130346480860493194786475025500179927152042631414216166076205706865335089506746163544867373884186074330874303125032398057106297186863,800913161978634698742609378449357774955505407483415355913501780948951093468088505693408572348493350961801168010893237963412292289122055848739177106855852125098292236006510856110523212361731635197072591774393685461794786770421350652687522647241859653967881884006552182286419954577117744245767788677817306762852|50429916262905224121199165505326103712322633321578675412441680250060233972857110270845245669993781820897616267433177701631160063889458653764653687193369398981186203131244488744056545097485284912257268749768458331368107477031080466529105477483573960360042156349879055924595032652993263006931935621163071940669,-27065457947223595691396496360583757525811978893552969421355220262690251856919447274985744020030753772138102799000695707517100290349316439468276434701083568894717249805760937039437729313480400330251378090593495078991541936054800615447964857892934462412215184000258243195317080477356913381022045983896051265339,162884360410278142867611075754290453359699000687335791914852080089316910769333692647979960993562595617317591055325367385753910502341805589561432506963888415490402296553372275035046411345233183682360113909981999769321373626395576042577426393704313732652524189312065702142816306042456646293512481995292218184630|53997723292458827021420578276444072896002053124414909531202213558828743141566632795132611868503445251027453958158504792518315802051451653007369750551307662332396699632827748059470875485288011830316694909885816703989889585271656952405885761371722676008299809654786389827849524552375005490619782071967768476620,-3921961296864439599504210025762424797468664702267290731411285739993844771294339132594454147684650522033462891630908841344585194018116919380259122700777039543903609394837238783496880317096351827072103366260798880944073390853134441762823497871536553346031444078137460262118850735234076150428857645894786599751,148801743068668131617014767083337764289837422117725728166091414005082627848729316116752646484455568027336119364510594603975358934000097718262611755893849397982664596027513725455266261222215386005085253076887565120162601272630243587251846986242350641739720550891898677287459766121608903079025422071040317411427 +10029389724354647916501896404393742667486460299990236556418317010668116357688170330436730152626311842309710400719826928488284825527027730454134618086311842571929328216480439284941404499751921093227604323134474990591797348436817566328316099817073417778247297081309102907064789976846493401165211794614652077581,-5748548483444797737722189452249937786310843486604864328602367281135708748614533947090219774019556230317272055169227525539578087511031078860820692360107715435130140444616499305586047090927584090418666083007681585523416727535418733837425822999564006750813702161869964846496575730545650729911357481033875975819,719895727819428792994563756994341424767785889195228293344753744212732679301708252203825226413012156273021174986595157595824763180256881701588113889797640827369987995936500880423386237711358833858185065722206691788564039408747808726964665919487597212670306097386648373066512338291830265434985728533154609458396|10029389724354647916501896404393742667486460299990236556418317010668116357688170330436730152626311842309710400719826928488284825527027730454134618086311842571929328216480439284941404499751921093227604323134474990591797348436817566328316099817073417778247297081309102907064789976846493401165211794614652077581,-5748548483444797737722189452249937786310843486604864328602367281135708748614533947090219774019556230317272055169227525539578087511031078860820692360107715435130140444616499305586047090927584090418666083007681585523416727535418733837425822999564006750813702161869964846496575730545650729911357481033875975819,719895727819428792994563756994341424767785889195228293344753744212732679301708252203825226413012156273021174986595157595824763180256881701588113889797640827369987995936500880423386237711358833858185065722206691788564039408747808726964665919487597212670306097386648373066512338291830265434985728533154609458396|8560998041202342563145796199673331908087223591151890019844277290088279806853407215903188817680041281745686724901293662893322531582604865370359246593736212994518909947445852055733198112706083016676348016714291995623917124402224705247934604030962953619706293397331305385867121828720733169551586472433525366937,-537975643989974344334263003423538768209474800355518283566587248897859525466409192148505701554962331296631250873445941844817525452815362174465113061273994639614043454341045805645253425898526417994404807933232055819444976823823121190979410608683098711316112363065614462414343124780847750195760827288806749811,842416466225224033183393216850362224780744722633748075411867357471068659147784175969996596348967969848559647034288532517371764252498077837862667546193299637156461175039504339023851201930547252305821527420041035325847162633397442876512610187216200063222815713605031344575281997919080197584636819283493689893368 +10029462828108406279939177067115161395010840703955688660855251935920272008672857135011101256731718086932191566776707625465927083826902687987460773347952918706606341231446896979494902183159052228641287627294356517943283997224691515527031637969828335115038316970291491432668820800917926368076854280638205187309,-6629646230072911423556297764360629625589965368903862583111147478898388162363395818084398589541887766856708633717083099875720612184669212924373539095145308857941719336023981955297255371765324592355503775749174475673743444341624220885937903545914339945102711106579165895756968511409705213351719512183267438507,782742743661597372172423816386424221021017552503284524697466177183281891845425353410464186233869636520966594583971179297268228166989165546064661406781232750204176842910595282543729669785450570724055031796400642778914378223882150571438409693254554219540729724954243581265311980228274664427499269984624348473720|10029462828108406279939177067115161395010840703955688660855251935920272008672857135011101256731718086932191566776707625465927083826902687987460773347952918706606341231446896979494902183159052228641287627294356517943283997224691515527031637969828335115038316970291491432668820800917926368076854280638205187309,-6629646230072911423556297764360629625589965368903862583111147478898388162363395818084398589541887766856708633717083099875720612184669212924373539095145308857941719336023981955297255371765324592355503775749174475673743444341624220885937903545914339945102711106579165895756968511409705213351719512183267438507,782742743661597372172423816386424221021017552503284524697466177183281891845425353410464186233869636520966594583971179297268228166989165546064661406781232750204176842910595282543729669785450570724055031796400642778914378223882150571438409693254554219540729724954243581265311980228274664427499269984624348473720|78667156036256111077611624900655903416490936286908879028793529978954307476546731244382117972535629204391216663640753691624585098486838208251820032478479477157140644001833697695041181016581251701307504852404041540782811897181398727717806959310986773271700555774873273014053192416692372242335858566589217791557,-11681938670990905592355073596188490162953864508666802257304897456361955348551384361326321552281799532866414312577544184561189074950098884814900830627703536569755802878449922371901033061871486784064588452214883192668082672979794267084922475962025561930112420060063420934779749780994794637529679089941387143427,100087743332058471063169855843669770171915090829420561680411008586982501053400685795132793033729482971332564612241450018617179058547543051543609602249472699027915450803902552375241387388609502154707845080333148480015751381946173697011349301767118798190494650916047348538729674905622316757245591467381527471900 diff --git a/crates/vdf/Cargo.toml b/crates/vdf/Cargo.toml new file mode 100644 index 0000000..acc815d --- /dev/null +++ b/crates/vdf/Cargo.toml @@ -0,0 +1,46 @@ +# Copyright 2018 POA Networks Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# and limitations under the License. +[package] +name = "vdf" +version = "0.1.0" +authors = ["Demi M. Obenour "] +readme = "README.md" +keywords = ["vdf", "classgroup", "crypto", "cryptography"] +repository = "https://github.com/poanetwork/vdf" +license = "Apache-2.0" +edition = "2018" +description = "An implementation of Verifiable Delay Functions (VDFs) in Rust" + +[lib] +crate-type = ["lib", "staticlib"] +name = "vdf" + +[dependencies] +classgroup = { path = "../classgroup", version = "^0.1.0" } +num-traits = "0.2" +sha2 = "0.8" +bit-vec = "0.5" +uniffi = { version= "0.25", features = ["cli"]} + +[build-dependencies] +uniffi = { version = "0.25", features = [ "build" ] } + +[dev-dependencies] +criterion = ">=0.2" +hex = "0.3" + +[[bench]] +name = "classgroup-bench" +harness = false +path = "bench/bench.rs" diff --git a/crates/vdf/README.md b/crates/vdf/README.md new file mode 100644 index 0000000..63276c7 --- /dev/null +++ b/crates/vdf/README.md @@ -0,0 +1,223 @@ +# Verifiable Delay Function (VDF) Implementation in Rust + +## What is a VDF? + +A Verifiable Delay Function (VDF) is a function that requires substantial time +to evaluate (even with a polynomial number of parallel processors) but can be +very quickly verified as correct. VDFs can be used to construct randomness +beacons with multiple applications in a distributed network environment. By +introducing a time delay during evaluation, VDFs prevent malicious actors from +influencing output. The output cannot be differentiated from a random number +until the final result is computed. See +for more details. + +## Description + +This VDF implementation is written in Rust. The GMP library is used for +arithmetic and greatest common divisor (GCD) calculations. We use class groups +to implement the approaches described in the following papers: + +1. [Simple Verifiable Delay Functions](https://eprint.iacr.org/2018/627.pdf). Pietrzak, 2018 +2. [Efficient Verifiable Delay Functions](https://eprint.iacr.org/2018/623.pdf). Wesolowski, 2018 + +The chosen generator is (2, 1, c), where c is calculated from the provided +discriminant. A form is represented internally (a, b, c), with the +discriminant not being used in most omputations. This implementation performs +reduction is performed after every multiplication and squaring, as not doing so +did not give any gains in our benchmarks. + + +This repo includes three crates: + +* `classgroup`: a class group implementation, as well as a trait for class + groups. +* `vdf`: a Verifyable Delay Function (VDF) trait, as well as an + implementation of that trait. +* `vdf-cli`: a command-line interface to the vdf crate. It also includes + additional commands, which are deprecated and will be replaced by a CLI to + the classgroup crate. + +## Usage + +- Install [Rust]. We (POA Networks) have tested the code with the latest + stable, beta, and nightly versions of Rust. It may work with older + versions, but this is not guaranteed. +- Install the [GNU Multiple Precision Library](https://gmplib.org/) + * On Debian and derivatives (including Ubuntu): + ```sh + $ sudo apt-get install -y libgmp-dev + ``` + * On Red Hat and derivatives (Fedora, CentOS) + ```sh + $ sudo dnf -y install gmp-devel + ``` +- Download and prepare the repository + + ```sh + $ git clone https://github.com/poanetwork/vdf.git + $ cargo install --path=vdf-cli + $ # or for the competition binary + $ cargo install --path=vdf-competition + ``` + +### Command Line Interface + +To initiate, use the `vdf-cli` command followed by 2 arguments: + +- _challenge_: byte string of arbitrary length +- _difficulty_: number of iterations, each iteration requires more time to evaluate + +This generates the Weslowski proof of time. To generate the Pietrzak proof of +time, pass `-tpietrzak`. For detailed usage information, run `vdf-cli --help`. + +Once complete you will see the output, returned as a `Vec`. The CLI tool +hex-encodes its output. + +**Example** + +```sh +$ vdf-cli aa 100 +005271e8f9ab2eb8a2906e851dfcb5542e4173f016b85e29d481a108dc82ed3b3f97937b7aa824801138d1771dea8dae2f6397e76a80613afda30f2c30a34b040baaafe76d5707d68689193e5d211833b372a6a4591abb88e2e7f2f5a5ec818b5707b86b8b2c495ca1581c179168509e3593f9a16879620a4dc4e907df452e8dd0ffc4f199825f54ec70472cc061f22eb54c48d6aa5af3ea375a392ac77294e2d955dde1d102ae2ace494293492d31cff21944a8bcb4608993065c9a00292e8d3f4604e7465b4eeefb494f5bea102db343bb61c5a15c7bdf288206885c130fa1f2d86bf5e4634fdc4216bc16ef7dac970b0ee46d69416f9a9acee651d158ac64915b +``` + +To verify, use the `vdi-cli` command with the same arguments and include the +output. + +**Example** + +```sh +$ vdf-cli aa 100 005271e8f9ab2eb8a2906e851dfcb5542e4173f016b85e29d481a108dc82ed3b3f97937b7aa824801138d1771dea8dae2f6397e76a80613afda30f2c30a34b040baaafe76d5707d68689193e5d211833b372a6a4591abb88e2e7f2f5a5ec818b5707b86b8b2c495ca1581c179168509e3593f9a16879620a4dc4e907df452e8dd0ffc4f199825f54ec70472cc061f22eb54c48d6aa5af3ea375a392ac77294e2d955dde1d102ae2ace494293492d31cff21944a8bcb4608993065c9a00292e8d3f4604e7465b4eeefb494f5bea102db343bb61c5a15c7bdf288206885c130fa1f2d86bf5e4634fdc4216bc16ef7dac970b0ee46d69416f9a9acee651d158ac64915b +Proof is valid +``` +### VDF Library + + + +```rust +extern crate vdf; +use vdf::{InvalidProof, PietrzakVDFParams, VDFParams, WesolowskiVDFParams, VDF}; + +/// The correct solution. +const CORRECT_SOLUTION: &[u8] = + b"\x00\x52\x71\xe8\xf9\xab\x2e\xb8\xa2\x90\x6e\x85\x1d\xfc\xb5\x54\x2e\x41\x73\xf0\x16\ + \xb8\x5e\x29\xd4\x81\xa1\x08\xdc\x82\xed\x3b\x3f\x97\x93\x7b\x7a\xa8\x24\x80\x11\x38\ + \xd1\x77\x1d\xea\x8d\xae\x2f\x63\x97\xe7\x6a\x80\x61\x3a\xfd\xa3\x0f\x2c\x30\xa3\x4b\ + \x04\x0b\xaa\xaf\xe7\x6d\x57\x07\xd6\x86\x89\x19\x3e\x5d\x21\x18\x33\xb3\x72\xa6\xa4\ + \x59\x1a\xbb\x88\xe2\xe7\xf2\xf5\xa5\xec\x81\x8b\x57\x07\xb8\x6b\x8b\x2c\x49\x5c\xa1\ + \x58\x1c\x17\x91\x68\x50\x9e\x35\x93\xf9\xa1\x68\x79\x62\x0a\x4d\xc4\xe9\x07\xdf\x45\ + \x2e\x8d\xd0\xff\xc4\xf1\x99\x82\x5f\x54\xec\x70\x47\x2c\xc0\x61\xf2\x2e\xb5\x4c\x48\ + \xd6\xaa\x5a\xf3\xea\x37\x5a\x39\x2a\xc7\x72\x94\xe2\xd9\x55\xdd\xe1\xd1\x02\xae\x2a\ + \xce\x49\x42\x93\x49\x2d\x31\xcf\xf2\x19\x44\xa8\xbc\xb4\x60\x89\x93\x06\x5c\x9a\x00\ + \x29\x2e\x8d\x3f\x46\x04\xe7\x46\x5b\x4e\xee\xfb\x49\x4f\x5b\xea\x10\x2d\xb3\x43\xbb\ + \x61\xc5\xa1\x5c\x7b\xdf\x28\x82\x06\x88\x5c\x13\x0f\xa1\xf2\xd8\x6b\xf5\xe4\x63\x4f\ + \xdc\x42\x16\xbc\x16\xef\x7d\xac\x97\x0b\x0e\xe4\x6d\x69\x41\x6f\x9a\x9a\xce\xe6\x51\ + \xd1\x58\xac\x64\x91\x5b"; +fn main() { + // The length of the prime numbers generated, in bits. + let num_bits: u16 = 2048; + + // An instance of the VDF. Instances can be used arbitrarily many times. + let pietrzak_vdf = PietrzakVDFParams(num_bits).new(); + + // Solve for the correct answer. This will take a minute or two. + assert_eq!( + &pietrzak_vdf.solve(b"\xaa", 10000).unwrap()[..], + CORRECT_SOLUTION + ); + + // Verify the answer. This should be far faster (less than a second). + assert!(pietrzak_vdf.verify(b"\xaa", 10000, CORRECT_SOLUTION).is_ok()); +} +``` + +## Benchmarks + +Benchmarks are provided for the classgroup operations. To run benchmarks: + +```sh +$ ./bench.sh +``` + +Additional benchmarks are under development. + +### Current Benchmarks + +These were generated by `./bench.sh aadf`. Outliers could be due to preemption +by the OS and/or hypervisor. Changes are relative to the previous test run +done on the same machine. Since the previous run was done with different +settings and/or code than reported here, these changes are not meaningful. + +```text +Benchmarking square with seed aadf: 512: Collecting 100 samples in estimated 5.0439 s (374k iteratio square with seed aadf: 512 + time: [13.301 us 13.333 us 13.372 us] + change: [-22.286% -21.745% -21.225%] (p = 0.00 < 0.05) + Performance has improved. +Found 22 outliers among 100 measurements (22.00%) + 5 (5.00%) high mild + 17 (17.00%) high severe + +Benchmarking multiply with seed aadf: 512: Collecting 100 samples in estimated 5.0452 s (293k iterat multiply with seed aadf: 512 + time: [17.219 us 17.251 us 17.287 us] + change: [-24.323% -23.739% -23.149%] (p = 0.00 < 0.05) + Performance has improved. +Found 10 outliers among 100 measurements (10.00%) + 4 (4.00%) high mild + 6 (6.00%) high severe + +Benchmarking square with seed aadf: 1024: Collecting 100 samples in estimated 5.0822 s (177k iterati square with seed aadf: 1024 + time: [28.672 us 28.716 us 28.767 us] + change: [-29.947% -29.339% -28.708%] (p = 0.00 < 0.05) + Performance has improved. +Found 8 outliers among 100 measurements (8.00%) + 1 (1.00%) low mild + 1 (1.00%) high mild + 6 (6.00%) high severe + +Benchmarking multiply with seed aadf: 1024: Collecting 100 samples in estimated 5.0886 s (136k itera multiply with seed aadf: 1024 + time: [37.163 us 37.207 us 37.254 us] + change: [-21.403% -20.750% -20.170%] (p = 0.00 < 0.05) + Performance has improved. +Found 8 outliers among 100 measurements (8.00%) + 1 (1.00%) low mild + 1 (1.00%) high mild + 6 (6.00%) high severe + +Benchmarking square with seed aadf: 2048: Collecting 100 samples in estimated 5.2519 s (76k iteratio square with seed aadf: 2048 + time: [69.115 us 69.254 us 69.430 us] + change: [-28.091% -27.738% -27.341%] (p = 0.00 < 0.05) + Performance has improved. +Found 8 outliers among 100 measurements (8.00%) + 1 (1.00%) low mild + 1 (1.00%) high mild + 6 (6.00%) high severe + +Benchmarking multiply with seed aadf: 2048: Collecting 100 samples in estimated 5.0554 s (56k iterat multiply with seed aadf: 2048 + time: [90.922 us 91.057 us 91.201 us] + change: [-25.236% -24.794% -24.336%] (p = 0.00 < 0.05) + Performance has improved. +Found 13 outliers among 100 measurements (13.00%) + 2 (2.00%) low mild + 5 (5.00%) high mild + 6 (6.00%) high severe +``` + +[Rust]: + + +## License + +Copyright 2018 Chia Network Inc and POA Networks Ltd. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/crates/vdf/bench/bench.rs b/crates/vdf/bench/bench.rs new file mode 100644 index 0000000..4757276 --- /dev/null +++ b/crates/vdf/bench/bench.rs @@ -0,0 +1,54 @@ +// Copyright 2018 POA Networks Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[macro_use] +extern crate criterion; + +use hex; + +use classgroup::{gmp_classgroup::GmpClassGroup, ClassGroup}; +use criterion::Criterion; +use std::{cell::RefCell, env, rc::Rc}; +use vdf::create_discriminant; +fn bench_square(c: &mut Criterion) { + let bench_params = |c: &mut Criterion, len: u16, seed: &[u8]| { + let i = Rc::new(RefCell::new(GmpClassGroup::generator_for_discriminant( + create_discriminant(seed, len), + ))); + { + let i = i.clone(); + c.bench_function( + &format!("square with seed {}: {}", hex::encode(seed), len), + move |b| b.iter(|| i.borrow_mut().square()), + ); + } + { + let multiplier = i.borrow().clone(); + c.bench_function( + &format!("multiply with seed {}: {}", hex::encode(seed), len), + move |b| b.iter(|| *i.borrow_mut() *= &multiplier), + ); + } + }; + let seed = env::var("VDF_BENCHMARK_SEED") + .ok() + .and_then(|x| hex::decode(x).ok()) + .expect("bug in calling script"); + for &i in &[512, 1024, 2048] { + bench_params(c, i, &seed) + } +} + +criterion_group!(benches, bench_square); +criterion_main!(benches); diff --git a/crates/vdf/build.rs b/crates/vdf/build.rs new file mode 100644 index 0000000..a8de622 --- /dev/null +++ b/crates/vdf/build.rs @@ -0,0 +1,115 @@ +// Copyright 2018 Chia Network Inc and POA Networks Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +use std::{env, fs::File, io::Write, path::PathBuf, u16}; + +/// The number of odd primes less than 65536. +const PRIMES_LEN: usize = 6541; + +/// The number of integers that are: +/// +/// * equal to 7 mod 8 +/// * not divisible by any prime number less than or equal to 13. +/// * less than 8 * 3 * 5 * 7 * 11 * 13 +const RESIDUES_LEN: usize = 5760; + +/// The number of odd prime numbers between 13 and 65536 exclusive. +const SIEVE_INFO_LEN: usize = PRIMES_LEN - 5; + +fn odd_primes_below_65536() -> Vec { + const N: usize = 1 << 16; + let mut sieve = vec![true; N >> 1]; + let mut q = (N as f64).powf(0.5) as usize; + assert!(q * q <= N); + q += 1; + assert!(q * q > N); + for i in (3..q).step_by(2) { + if sieve[i >> 1] { + for i in ((i * i >> 1)..sieve.len()).step_by(i) { + sieve[i] = false; + } + } + } + // mega cheat ― we know the exact size of this vector + let res: Vec<_> = (1..N / 2) + .filter(|&i| sieve[i]) + .map(|i| 2 * i + 1) + .collect(); + assert_eq!(res.len(), PRIMES_LEN); + res +} + +fn mod_exponentiation(base: usize, exponent: usize, modulus: usize) -> usize { + assert!(base < u16::MAX.into()); + assert!(exponent < u16::MAX.into()); + assert!(modulus < u16::MAX.into()); + let (mut base, mut exponent, modulus) = (base as u32, exponent as u32, modulus as u32); + let mut state = 1; + loop { + if exponent & 1 != 0 { + state *= base; + state %= modulus; + } + exponent >>= 1; + if exponent == 0 { + return state as _; + } + base *= base; + base %= modulus; + } +} + +macro_rules! const_fmt { + () => { + "#[allow(warnings)]\nconst {}: [{}; {}] = {:#?};\n\n"; + }; +} + +/// A product of many small prime numbers. We precompute the numbers between +/// `1` and `M` that are coprime to `M`. Any number whose residue modulo `M` is +/// one of these is not divisible by any of the prime factors of `M`. This +/// speeds up the generation of random prime numbers. +const M: usize = 8 * 3 * 5 * 7 * 11 * 13; +fn emit(f: &mut dyn Write, name: &str, t: &str, obj: &[T]) { + write!(f, const_fmt!(), name, t, obj.len(), obj).expect("i/o error in build script"); +} + +/// Write the generated code to `f`. +fn generate(f: &mut dyn Write) { + write!(f, "const M: u32 = 8 * 3 * 5 * 7 * 11 * 13;\n\n").expect("i/o error"); + let residues: Vec = { + let primes = [3, 5, 7, 11, 13]; + let not_divisible = |&x: &usize| primes.iter().all(|p| x % p != 0); + (7..M).step_by(8).filter(not_divisible).collect() + }; + assert_eq!(residues.len(), RESIDUES_LEN); + emit(f, "RESIDUES", "u32", &residues[..]); + let sieve_info: Vec<(usize, usize)> = odd_primes_below_65536()[5..] + .iter() + .map(|&i| (i, mod_exponentiation(M % i, i - 2, i))) + .collect(); + assert_eq!(sieve_info.len(), SIEVE_INFO_LEN); + emit(f, "SIEVE_INFO", "(u16, u16)", &sieve_info[..]); +} + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + + uniffi::generate_scaffolding("src/lib.udl").expect("uniffi generation failed"); + + let manifest_path = env::var("OUT_DIR").expect("cargo should have set this"); + let mut path = PathBuf::from(&manifest_path); + path.push("constants.rs"); + let mut f = File::create(path).expect("cannot create constants.rs"); + generate(&mut f); +} diff --git a/crates/vdf/src/create_discriminant.rs b/crates/vdf/src/create_discriminant.rs new file mode 100644 index 0000000..4b10225 --- /dev/null +++ b/crates/vdf/src/create_discriminant.rs @@ -0,0 +1,199 @@ +// Copyright 2018 Chia Network Inc and POA Networks Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Creation of discriminants. +//! +//! The [`pot`] tool does not accept a discriminant as a command-line argument. +//! Instead, we generate the discriminant from a (much smaller) seed. +//! +//! For performance, we follow the Chia network's [`inkfish`] implementation +//! of ["Close to Uniform Prime Number Generation With Fewer Random Bits"][1] +//! by Pierre-Alain Fouque and Mehdi Tibouchi. +//! We employ a table of precomputed constants generated by `build.rs`. +//! +//! [1]: https://eprint.iacr.org/2011/481.pdf +//! [`inkfish`]: +//! [`pot`]: + +include!(concat!(env!("OUT_DIR"), "/constants.rs")); + +use classgroup::BigNumExt; +use num_traits::Zero; +use sha2::{digest::FixedOutput, Digest, Sha256}; +use std::u16; + +fn random_bytes_from_seed(seed: &[u8], byte_count: usize) -> Vec { + assert!(byte_count <= 32 * ((1 << 16) - 1)); + let mut blob = Vec::with_capacity(byte_count); + let mut extra: u16 = 0; + while blob.len() < byte_count { + let mut hasher = Sha256::new(); + hasher.input(seed); + let extra_bits: [u8; 2] = [((extra & 0xFF00) >> 8) as _, (extra & 0xFF) as _]; + hasher.input(&extra_bits); + blob.extend_from_slice(&hasher.fixed_result()[..]); + extra += 1; + } + blob.resize(byte_count, 0); + blob +} + +/// Create a discriminant from a seed (a byte string) and a bit length (a +/// `u16`). The discriminant is guaranteed to be a negative prime number that +/// fits in `length` bits, except with negligible probability (less than +/// 2^(-100)). It is also guaranteed to equal 7 modulo 8. +/// +/// This function uses sha256 to expand the seed. Therefore, different seeds +/// will result in completely different discriminants with overwhelming +/// probability, unless `length` is very small. However, this function is +/// deterministic: if it is called twice with identical seeds and lengths, it +/// will always return the same discriminant. +/// +/// This function is guaranteed not to panic for any inputs whatsoever, unless +/// memory allocation fails and the allocator in use panics in that case. +pub fn create_discriminant(seed: &[u8], length: u16) -> T { + let (mut n, residue) = { + // The number of “extra” bits (that don’t evenly fit in a byte) + let extra: u8 = (length as u8) & 7; + + // The number of random bytes needed (the number of bytes that hold `length` + // bits, plus 2). + let random_bytes_len = ((usize::from(length) + 7) >> 3) + 2; + let random_bytes = random_bytes_from_seed(seed, random_bytes_len); + let (n, last_2) = random_bytes.split_at(random_bytes_len - 2); + let numerator = (usize::from(last_2[0]) << 8) + usize::from(last_2[1]); + + // If there are any extra bits, right shift `n` so that it fits + // in `length` bits, discarding the least significant bits. + let n = T::from(n) >> usize::from((8 - extra) & 7); + (n, RESIDUES[numerator % RESIDUES.len()]) + }; + n.setbit(usize::from(length - 1)); + debug_assert!(n >= Zero::zero()); + let rem = n.frem_u32(M); + + // HACK HACK `rust-gmp` doesn’t expose += and -= with i32 or i64 + if residue > rem { + n = n + u64::from(residue - rem); + } else { + n = n - u64::from(rem - residue); + } + debug_assert!(n >= Zero::zero()); + + // This generates the smallest prime ≥ n that is of the form n + m*x. + loop { + // Speed up prime-finding by quickly ruling out numbers + // that are known to be composite. + let mut sieve = ::bit_vec::BitVec::from_elem(1 << 16, false); + for &(p, q) in SIEVE_INFO.iter() { + // The reference implementation changes the sign of `n` before taking its + // remainder. Instead, we leave `n` as positive, but use ceiling + // division instead of floor division. This is mathematically + // equivalent and potentially faster. + let mut i: usize = (n.crem_u16(p) as usize * q as usize) % p as usize; + while i < sieve.len() { + sieve.set(i, true); + i += p as usize; + } + } + + for (i, x) in sieve.iter().enumerate() { + if !x { + let q = u64::from(M) * u64::from(i as u32); + n = n + q; + if n.probab_prime(1) { + return -n; + } + n = n - q; + } + } + // M is set to a number with many prime factors so the results are + // more uniform https://eprint.iacr.org/2011/481.pdf + // TODO: Explain previous reference to https://eprint.iacr.org/2011/401.pdf + n = n + (u64::from(M) * (1 << 16)) as u64 + } +} + +#[cfg(test)] +mod test { + use super::*; + use classgroup::{gmp_classgroup::GmpClassGroup, ClassGroup}; + type Mpz = ::BigNum; + use std::str::FromStr; + + #[test] + fn check_discriminant_1() { + assert_eq!( + create_discriminant::(b"\xaa", 40), + (-685_537_176_559i64).into() + ); + } + + #[test] + fn check_discriminant_3() { + assert_eq!( + create_discriminant::(b"\xaa", 1024), + Mpz::from_str( + "-112084717443890964296630631725167420667316836131914185144761\ + 7438378168250988242739496385274308134767869324152361453294226\ + 8295868231081182819214054220080323345750407342623884342617809\ + 8794592117225058677336074005099949757067786815439982423354682\ + 0386024058617141397148586038290164093146862666602485017735298\ + 03183" + ) + .unwrap() + ) + } + + #[test] + fn check_discriminant_2() { + assert_eq!( + create_discriminant::(b"\xaa", 2048), + -Mpz::from_str( + "201493927071865251625903550712920535753645598483515670853547009\ + 878440933309489362800393797428711071833308081461824159206915864\ + 150805748296170245037221957772328044276705571745811271212292422\ + 075849739248257870371300001313586036515879618764093772248760562\ + 386804073478433157526816295216137723803793411828867470089409596\ + 238958950007370719325959579892866588928887249912429688364409867\ + 895510817680171869190054122881274299350947669820596157115994418\ + 034091728887584373727555384075665624624856766441009974642693066\ + 751400054217209981490667208950669417773785631693879782993019167\ + 69407006303085854796535778826115224633447713584423" + ) + .unwrap() + ); + } + #[test] + fn check_random_bytes() { + assert_eq!( + &random_bytes_from_seed(b"\xaa", 7), + b"\x9f\x9d*\xe5\xe7<\xcb" + ); + assert_eq!( + &random_bytes_from_seed(b"\xaa", 258)[..], + &b"\x9f\x9d*\xe5\xe7<\xcbq\xa4q\x8e\ + \xbc\xf0\xe3:\xa2\x98\xf8\xbd\xdc\xaa\xcbi\xcb\x10\xff\x0e\xafv\xdb\xec!\xc4K\ + \xc6Jf\xf3\xa5\xda.7\xb7\xef\x87I\x85\xb8YX\xfc\xf2\x03\xa1\x8f4\xaf`\xab\xae]n\ + \xcc,g1\x12EI\xc7\xd5\xe2\xfc\x8b\x9a\xde\xd5\xf3\x8f'\xcd\x08\x0fU\xc7\xee\xa85\ + [>\x87]\x07\x82\x00\x13\xce\xf7\xc3/@\xef\x08v\x8f\x85\x87dm(1\x8b\xd9w\xffA]xzY\ + \xa0,\xebz\xff\x03$`\x91\xb66\x88-_\xa9\xf1\xc5\x8e,\x15\xae\x8f\x04\rvhnU3f\x84\ + [{$\xa6l\x95w\xa9\x1f\xba\xa8)\x05\xe6\x8f\x167o\x11/X\x9cl\xab\x9c\xcb}\xec\x88\ + \xf8\xa5\xabXpY\xb0\x88\xed@r\x05\xba\\\x03\xf6\x91\xf8\x03\xca\x18\x1c\xcdH\x1c\ + \x91\xe1V\xed;\x94oJ\xa8 \xa4\x97\xb7K\xce\xc4e\xea\xa2\xbf\x8b\x1f\x90\x87\xc8\ + \x15\xee\x0e\x0fPC:\xb5\xe1g\x97\xea/_\x86c\xaf\x12Wp\xfd\x11\xdb\x17\xe6\x9f\ + \xa5\x8a"[..] + ); + } +} diff --git a/crates/vdf/src/lib.rs b/crates/vdf/src/lib.rs new file mode 100644 index 0000000..4156829 --- /dev/null +++ b/crates/vdf/src/lib.rs @@ -0,0 +1,261 @@ +// Copyright 2018 Chia Network Inc and POA Networks Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#![deny(warnings)] +//! # Rust implementations of class groups and verifyable delay functions +//! +//! This repo includes three crates +//! +//! * `classgroup`, which includes a class group implementation, as well as a +//! trait for class groups. +//! * `vdf`, which includes a Verifyable Delay Function (VDF) trait, as well as +//! an implementation of that trait. +//! * `vdf-cli`, which includes a command-line interface to the `vdf` crate. It +//! also includes additional commands, which are deprecated and will later be +//! replaced by a CLI to the `classgroup` crate. +//! +//! ## Usage +//! +//! First, install Rust, Cargo, and the GNU Multiprecision Library (GMP). Then, +//! follow one of the below steps. +//! +//! ### To use the command line interface +//! +//! ```sh +//! $ git clone https://github.com/poanetwork/vdf +//! $ cd vdf +//! $ cargo install +//! $ vdf-cli aa 100 +//! 005271e8f9ab2eb8a2906e851dfcb5542e4173f016b85e29d481a108dc82ed3b3f97937b7aa824801138d1771dea8dae2f6397e76a80613afda30f2c30a34b040baaafe76d5707d68689193e5d211833b372a6a4591abb88e2e7f2f5a5ec818b5707b86b8b2c495ca1581c179168509e3593f9a16879620a4dc4e907df452e8dd0ffc4f199825f54ec70472cc061f22eb54c48d6aa5af3ea375a392ac77294e2d955dde1d102ae2ace494293492d31cff21944a8bcb4608993065c9a00292e8d3f4604e7465b4eeefb494f5bea102db343bb61c5a15c7bdf288206885c130fa1f2d86bf5e4634fdc4216bc16ef7dac970b0ee46d69416f9a9acee651d158ac64915b +//! $ vdf-cli aa 100 005271e8f9ab2eb8a2906e851dfcb5542e4173f016b85e29d481a108dc82ed3b3f97937b7aa824801138d1771dea8dae2f6397e76a80613afda30f2c30a34b040baaafe76d5707d68689193e5d211833b372a6a4591abb88e2e7f2f5a5ec818b5707b86b8b2c495ca1581c179168509e3593f9a16879620a4dc4e907df452e8dd0ffc4f199825f54ec70472cc061f22eb54c48d6aa5af3ea375a392ac77294e2d955dde1d102ae2ace494293492d31cff21944a8bcb4608993065c9a00292e8d3f4604e7465b4eeefb494f5bea102db343bb61c5a15c7bdf288206885c130fa1f2d86bf5e4634fdc4216bc16ef7dac970b0ee46d69416f9a9acee651d158ac64915b +//! Proof is valid +//! ``` +//! +//! ### To use the VDF library +//! +//! ```rust +//! extern crate vdf; +//! use vdf::{InvalidProof, PietrzakVDFParams, VDFParams, WesolowskiVDFParams, VDF}; +//! const CORRECT_SOLUTION: &[u8] = +//! b"\x00\x52\x71\xe8\xf9\xab\x2e\xb8\xa2\x90\x6e\x85\x1d\xfc\xb5\x54\x2e\x41\x73\xf0\x16\ +//! \xb8\x5e\x29\xd4\x81\xa1\x08\xdc\x82\xed\x3b\x3f\x97\x93\x7b\x7a\xa8\x24\x80\x11\x38\ +//! \xd1\x77\x1d\xea\x8d\xae\x2f\x63\x97\xe7\x6a\x80\x61\x3a\xfd\xa3\x0f\x2c\x30\xa3\x4b\ +//! \x04\x0b\xaa\xaf\xe7\x6d\x57\x07\xd6\x86\x89\x19\x3e\x5d\x21\x18\x33\xb3\x72\xa6\xa4\ +//! \x59\x1a\xbb\x88\xe2\xe7\xf2\xf5\xa5\xec\x81\x8b\x57\x07\xb8\x6b\x8b\x2c\x49\x5c\xa1\ +//! \x58\x1c\x17\x91\x68\x50\x9e\x35\x93\xf9\xa1\x68\x79\x62\x0a\x4d\xc4\xe9\x07\xdf\x45\ +//! \x2e\x8d\xd0\xff\xc4\xf1\x99\x82\x5f\x54\xec\x70\x47\x2c\xc0\x61\xf2\x2e\xb5\x4c\x48\ +//! \xd6\xaa\x5a\xf3\xea\x37\x5a\x39\x2a\xc7\x72\x94\xe2\xd9\x55\xdd\xe1\xd1\x02\xae\x2a\ +//! \xce\x49\x42\x93\x49\x2d\x31\xcf\xf2\x19\x44\xa8\xbc\xb4\x60\x89\x93\x06\x5c\x9a\x00\ +//! \x29\x2e\x8d\x3f\x46\x04\xe7\x46\x5b\x4e\xee\xfb\x49\x4f\x5b\xea\x10\x2d\xb3\x43\xbb\ +//! \x61\xc5\xa1\x5c\x7b\xdf\x28\x82\x06\x88\x5c\x13\x0f\xa1\xf2\xd8\x6b\xf5\xe4\x63\x4f\ +//! \xdc\x42\x16\xbc\x16\xef\x7d\xac\x97\x0b\x0e\xe4\x6d\x69\x41\x6f\x9a\x9a\xce\xe6\x51\ +//! \xd1\x58\xac\x64\x91\x5b"; +//! +//! fn main() { +//! let pietrzak_vdf = PietrzakVDFParams(2048).new(); +//! assert_eq!( +//! &pietrzak_vdf.solve(b"\xaa", 100).unwrap()[..], +//! CORRECT_SOLUTION +//! ); +//! assert!(pietrzak_vdf.verify(b"\xaa", 100, CORRECT_SOLUTION).is_ok()); +//! } +//! ``` +//! +//! ### To run the benchmarks +//! +//! Benchmarks are provided for the classgroup operations. Run `cargo bench` +//! to run them. Additional benchmarks are under development. +use classgroup; + +mod create_discriminant; +use std::fmt::Debug; + +pub use self::{ + create_discriminant::create_discriminant, + proof_pietrzak::{PietrzakVDF, PietrzakVDFParams}, + proof_wesolowski::{WesolowskiVDF, WesolowskiVDFParams}, +}; + +/// Message used to report an internal miscalculation of serialization buffer +/// sizes. +const INCORRECT_BUFFER_SIZE: &str = + "internal error: incorrect buffer size calculation (this is a bug)"; + +mod proof_of_time; +mod proof_pietrzak; +mod proof_wesolowski; + +uniffi::include_scaffolding!("lib"); + +/// An empty struct indicating verification failure. +/// +/// For security reasons, the functions that perform verification *do not* +/// return any information on failure. Use `VDF::validate_params` to check if +/// the parameters are correct. +#[derive(Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, Debug)] +pub struct InvalidProof; + +/// An error return indicating an invalid number of iterations. The string is a +/// human-readable message describing the valid iterations. It should not be +/// interpreted by programs. +#[derive(Clone, Eq, PartialEq, PartialOrd, Ord, Hash, Debug)] +pub struct InvalidIterations(String); + +/// The type of VDF parameters. +/// +/// Parameters represent public information that can be shared by all users +/// of the protocol. As such, they must implement `Clone`, so that they can +/// be duplicated. They also must implement `Send`, so that a parallel +/// application can send them safely across threads. +/// +/// The parameters *do not* include the difficulty level (usually an +/// iteration count), since that can be separate for each invocation. +/// +/// This must implement `Clone` and `Eq`. +pub trait VDFParams: Clone + Eq { + type VDF: VDF + Sized; + + /// Creates an instance of this VDF from the given parameters. + /// + /// # Performance + /// + /// This method is expected to be fairly cheap. For example, it is okay if + /// it allocates memory, but it should not perform expensive computations or + /// I/O. + /// + /// # Panics + /// + /// This method **MUST NOT** fail due to invalid values for `params`. Such + /// errors should be checked by the factory functions for `Self::Params`. + /// + /// This function **MAY** panic for other reasons. For example, it is + /// allowed to panic if an allocation fails, or if a needed external library + /// could not be dynamically loaded. + fn new(self) -> Self::VDF; +} + +/// A Verifiable Delay Function (VDF). +/// +/// VDFs are problems that require a certain amount of time to solve, even on a +/// parallel machine, but can be validated much more easily. +/// +/// While VDFs are considered to be cryptographic primitives, they generally do +/// *not* operate on highly sensitive data. As such, implementers of this trait +/// **do not** guarantee that they will be immune to side-channel attacks, and +/// consumers of this trait **MUST NOT** expect this. +/// +/// Instances of this trait are *not* expected to be `Sync`. This allows them +/// to reuse allocations (such as scratch memory) accross invocations without +/// the need for locking. However, they **MUST** be `Send` and `Clone`, so that +/// consumers can duplicate them and send them across threads. +pub trait VDF: Send + Debug { + /// Solve an instance of this VDF, with challenge `challenge` and difficulty + /// `difficulty`. + /// + /// The output is to be returned in a `Vec`, so it can be stored to disk + /// or sent over the network. + /// + /// # Challenge format + /// + /// The challenge is an opaque byte string of arbitrary length. + /// Implementors **MUST NOT** make any assumptions about its contents, + /// and **MUST** produce distinct outputs for distinct challenges + /// (except with negiligible probability). + /// + /// This can be most easily implemented by using the challenge as part of + /// the input of a cryptographic hash function. The VDFs provided in this + /// crate use this strategy. + /// + /// The difficulty must be checked before performing any expensive + /// computations. + /// + /// Most applications will generate the challenge using a + /// cryptographically-secure pseudorandom number generator, but implementors + /// **MUST NOT** rely on this. In particular, this function must be secure + /// even if `challenge` is chosen by an adversary. Excessive values for + /// `difficulty` may cause excessive resource consumption, but must not + /// create any other vulnerabilities. + /// + /// # Complexity + /// + /// The VDFs in this crate consume memory that does not depend on + /// `difficulty`, and time linearly proportional to `difficulty`. + /// Implementors of this trait should document the resource use. + /// + /// # Purity + /// + /// This method must have no side effects. In particular, it must be + /// **deterministic**: it must always return the same output for the same + /// inputs, except with negligible probability. Furthermore, while it may + /// change `self` via interior mutability, such changes must not affect + /// future calls to this method, `Self::check_difficulty`, or + /// `Self::verify`. They *may* affect the `Debug` output. + fn solve(&self, challenge: &[u8], difficulty: u64) -> Result, InvalidIterations>; + + /// Check that the difficulty is valid. + /// + /// This must return `Ok` if and only if `difficulty` is valid. Otherwise, + /// it must return `Err`. + /// + /// # Rationale + /// + /// It would be more ideomatic Rust to use the type system to enforce that a + /// difficulty has been validated before use. However, I (Demi) have not + /// yet figured out an object-safe way to do so. + fn check_difficulty(&self, difficulty: u64) -> Result<(), InvalidIterations>; + + /// Verifies an alleged solution of this VDF, with challenge `challenge` and + /// difficulty `difficulty`. Return `Ok(())` on success, or + /// `Err(InvalidProof)` on failure. + /// + /// This function *does not* return any extended error information for + /// security reasons. To check that the difficulty is correct, call + /// `Self::check_difficulty`. + /// + /// # Uniqueness of valid solutions + /// + /// For any `(challenge, difficulty)` tuple, there must be at most one + /// `alleged_solution` (as measured by `Eq`) that causes this function to + /// return `Ok(())`. If the difficulty is valid (as determined by + /// `check_difficulty`), there must be exactly one such solution; otherwise, + /// there must be none. + /// + /// # Purity + /// + /// This method must have no side effects. In particular, it must be + /// **deterministic**: it must always return the same output for the same + /// inputs. Furthermore, while it may change `self` via interior + /// mutability, such changes must not affect future calls to this method, + /// `Self::prove`, or `Self::check_difficulty`. Such changes **MAY** affect + /// debugging output. + fn verify( + &self, + challenge: &[u8], + difficulty: u64, + alleged_solution: &[u8], + ) -> Result<(), InvalidProof>; +} + +/// Solve and prove with the Wesolowski VDF using the given parameters. +/// Outputs the concatenated solution and proof (in this order). +pub fn wesolowski_solve(int_size_bits: u16, challenge: &[u8], difficulty: u32) -> Vec { + let vdf = WesolowskiVDFParams(int_size_bits).new(); + vdf.solve(challenge, difficulty.into()).expect("invalid difficulty") +} + +/// Verify with the Wesolowski VDF using the given parameters. +/// `alleged_solution` is the output of `wesolowski_solve`. +pub fn wesolowski_verify(int_size_bits: u16, challenge: &[u8], difficulty: u32, alleged_solution: &[u8]) -> bool { + let vdf = WesolowskiVDFParams(int_size_bits).new(); + vdf.verify(challenge, difficulty.into(), alleged_solution).is_ok() +} diff --git a/crates/vdf/src/lib.udl b/crates/vdf/src/lib.udl new file mode 100644 index 0000000..66c0d18 --- /dev/null +++ b/crates/vdf/src/lib.udl @@ -0,0 +1,4 @@ +namespace vdf { + sequence wesolowski_solve(u16 int_size_bits, [ByRef] sequence challenge, u32 difficulty); + boolean wesolowski_verify(u16 int_size_bits, [ByRef] sequence challenge, u32 difficulty, [ByRef] sequence alleged_solution); +}; diff --git a/crates/vdf/src/proof_of_time.rs b/crates/vdf/src/proof_of_time.rs new file mode 100644 index 0000000..4b6afb6 --- /dev/null +++ b/crates/vdf/src/proof_of_time.rs @@ -0,0 +1,88 @@ +// Copyright 2018 Chia Network Inc and POA Networks Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +use super::classgroup::ClassGroup; +use std::{collections::HashMap, usize}; + +pub fn serialize(proof: &[V], y: &V, int_size_bits: usize) -> Vec { + let proof_len = proof.len(); + let element_length = 2 * ((int_size_bits + 16) >> 4); + let proof_len_in_bytes = (proof_len + 1) * element_length; + let mut v = vec![0; proof_len_in_bytes]; + y.serialize(&mut v[0..element_length]) + .expect(super::INCORRECT_BUFFER_SIZE); + for (index, group) in proof.iter().enumerate() { + let offset = (index + 1) * element_length; + group + .serialize(&mut v[offset..offset + element_length]) + .expect(super::INCORRECT_BUFFER_SIZE) + } + v +} +pub fn deserialize_proof( + proof_blob: &[u8], + discriminant: &T::BigNum, + orig_length: usize, +) -> Result, ()> +where + T: ClassGroup, + for<'a, 'b> &'a T: std::ops::Mul<&'b T, Output = T>, + for<'a, 'b> &'a T::BigNum: std::ops::Mul<&'b T::BigNum, Output = T::BigNum>, +{ + let length = T::size_in_bits(discriminant); + if length > usize::MAX - 16 { + return Err(()); + } + let length = (length + 16) >> 4; + if length == 0 { + return Err(()); + } + if orig_length != length { + return Err(()); + } + let length = length * 2; + let proof_blob_length = proof_blob.len(); + let rem = proof_blob_length % length; + if rem != 0 { + return Err(()); + } + let proof_len = proof_blob_length / length; + let mut v = Vec::with_capacity(proof_len); + for i in 0..proof_len { + let offset = i * length; + v.push(T::from_bytes( + &proof_blob[offset..offset + length], + discriminant.clone(), + )) + } + Ok(v) +} + +pub fn iterate_squarings(mut x: V, powers_to_calculate: U) -> HashMap +where + V: ClassGroup, + for<'a, 'b> &'a V: std::ops::Mul<&'b V, Output = V>, + for<'a, 'b> &'a V::BigNum: std::ops::Mul<&'b V::BigNum, Output = V::BigNum>, + U: Iterator, +{ + let mut powers_calculated = HashMap::new(); + let mut powers_to_calculate: Vec = powers_to_calculate.collect(); + powers_to_calculate.sort_unstable(); + let mut previous_power: u64 = 0; + for ¤t_power in &powers_to_calculate { + x.repeated_square(current_power - previous_power); + powers_calculated.insert(current_power, x.clone()); + previous_power = current_power + } + powers_calculated +} diff --git a/crates/vdf/src/proof_pietrzak.rs b/crates/vdf/src/proof_pietrzak.rs new file mode 100644 index 0000000..786cecb --- /dev/null +++ b/crates/vdf/src/proof_pietrzak.rs @@ -0,0 +1,466 @@ +// Copyright 2018 Chia Network Inc and POA Networks Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +use super::proof_of_time::{deserialize_proof, iterate_squarings, serialize}; +use classgroup::{gmp_classgroup::GmpClassGroup, BigNumExt, ClassGroup}; +use num_traits::{One, Zero}; +use std::{fmt, num::ParseIntError, ops::Index, str::FromStr, u64, usize}; + +#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone, Debug)] +pub struct Iterations(u64); + +#[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Copy, Clone, Debug)] +pub enum InvalidIterations { + OddNumber(u64), + LessThan66(u64), +} + +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ParseIterationsError { + kind: Result, +} + +impl From for ParseIterationsError { + fn from(t: InvalidIterations) -> Self { + Self { kind: Ok(t) } + } +} + +impl From for ParseIterationsError { + fn from(t: ParseIntError) -> Self { + Self { kind: Err(t) } + } +} + +impl fmt::Display for InvalidIterations { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + InvalidIterations::OddNumber(s) => { + write!(f, "Pietrzak iterations must be an even number, not {}", s) + } + InvalidIterations::LessThan66(s) => write!( + f, + "Pietrzak proof-of-time must run for at least 66 iterations, not {}", + s + ), + } + } +} + +impl From for u64 { + fn from(t: Iterations) -> u64 { + t.0 + } +} + +impl fmt::Display for ParseIterationsError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.kind { + Ok(ref q) => ::fmt(q, f), + Err(ref q) => ::fmt(q, f), + } + } +} + +impl FromStr for Iterations { + type Err = ParseIterationsError; + fn from_str(s: &str) -> Result { + Self::new(s.parse::().map_err(ParseIterationsError::from)?) + .map_err(ParseIterationsError::from) + } +} + +impl Iterations { + pub fn new>(iterations: T) -> Result { + let iterations = iterations.into(); + if iterations & 1 != 0 { + Err(InvalidIterations::OddNumber(iterations)) + } else if iterations < 66 { + Err(InvalidIterations::LessThan66(iterations)) + } else { + Ok(Iterations(iterations)) + } + } +} + +/// Selects a reasonable choice of cache size. +fn approximate_i(t: Iterations) -> u64 { + let x: f64 = (((t.0 >> 1) as f64) / 8.) * 2.0f64.ln(); + let w = x.ln() - x.ln().ln() + 0.25; + (w / (2. * 2.0f64.ln())).round() as _ +} + +fn sum_combinations<'a, T: IntoIterator>(numbers: T) -> Vec { + let mut combinations = vec![0]; + for i in numbers { + let mut new_combinations = combinations.clone(); + for j in combinations { + new_combinations.push(i + j) + } + combinations = new_combinations + } + combinations.remove(0); + combinations +} + +fn cache_indices_for_count(t: Iterations) -> Vec { + let i: u64 = approximate_i(t); + let mut curr_t = t.0; + let mut intermediate_ts = vec![]; + for _ in 0..i { + curr_t >>= 1; + intermediate_ts.push(curr_t); + if curr_t & 1 != 0 { + curr_t += 1 + } + } + let mut cache_indices = sum_combinations(&intermediate_ts); + cache_indices.sort(); + cache_indices.push(t.0); + cache_indices +} + +fn generate_r_value(x: &T, y: &T, sqrt_mu: &T, int_size_bits: usize) -> T::BigNum +where + T: ClassGroup, + for<'a, 'b> &'a T: std::ops::Mul<&'b T, Output = T>, + for<'a, 'b> &'a T::BigNum: std::ops::Mul<&'b T::BigNum, Output = T::BigNum>, +{ + use sha2::{digest::FixedOutput, Digest, Sha256}; + + let size = (int_size_bits + 16) >> 4; + let mut v = Vec::with_capacity(size * 2); + for _ in 0..size * 2 { + v.push(0) + } + let mut hasher = Sha256::new(); + for i in &[&x, &y, &sqrt_mu] { + i.serialize(&mut v).expect(super::INCORRECT_BUFFER_SIZE); + hasher.input(&v); + } + let res = hasher.fixed_result(); + T::unsigned_deserialize_bignum(&res[..16]) +} + +fn create_proof_of_time_pietrzak( + challenge: &[u8], + iterations: Iterations, + int_size_bits: u16, +) -> Vec +where + T: ClassGroup, + ::BigNum: BigNumExt, + for<'a, 'b> &'a T: std::ops::Mul<&'b T, Output = T>, + for<'a, 'b> &'a T::BigNum: std::ops::Mul<&'b T::BigNum, Output = T::BigNum>, +{ + let discriminant = super::create_discriminant::create_discriminant(&challenge, int_size_bits); + let x = T::from_ab_discriminant(2.into(), 1.into(), discriminant); + + let delta = 8; + let powers_to_calculate = cache_indices_for_count(iterations); + let powers = iterate_squarings(x.clone(), powers_to_calculate.iter().cloned()); + let proof: Vec = generate_proof( + x, + iterations, + delta, + &powers, + &generate_r_value, + usize::from(int_size_bits), + ); + serialize( + &proof, + &powers[&iterations.into()], + usize::from(int_size_bits), + ) +} + +pub fn check_proof_of_time_pietrzak( + challenge: &[u8], + proof_blob: &[u8], + iterations: u64, + length_in_bits: u16, +) -> Result<(), super::InvalidProof> +where + T: ClassGroup, + T::BigNum: BigNumExt, + for<'a, 'b> &'a T: std::ops::Mul<&'b T, Output = T>, + for<'a, 'b> &'a T::BigNum: std::ops::Mul<&'b T::BigNum, Output = T::BigNum>, +{ + let discriminant = super::create_discriminant::create_discriminant(&challenge, length_in_bits); + let x = T::from_ab_discriminant(2.into(), 1.into(), discriminant); + let iterations = Iterations::new(iterations).map_err(|_| super::InvalidProof)?; + if usize::MAX - 16 < length_in_bits.into() { + // Proof way too long. + return Err(super::InvalidProof); + } + let length: usize = (usize::from(length_in_bits) + 16usize) >> 4; + if proof_blob.len() < 2 * length { + // Invalid length of proof + return Err(super::InvalidProof); + } + let result_bytes = &proof_blob[..length * 2]; + let proof_bytes = &proof_blob[length * 2..]; + let discriminant = x.discriminant().clone(); + let proof = + deserialize_proof(proof_bytes, &discriminant, length).map_err(|()| super::InvalidProof)?; + let y = T::from_bytes(result_bytes, discriminant); + verify_proof( + &x, + &y, + proof, + iterations, + 8, + &generate_r_value, + length_in_bits.into(), + ) + .map_err(|()| super::InvalidProof) +} + +fn calculate_final_t(t: Iterations, delta: usize) -> u64 { + let mut curr_t = t.0; + let mut ts = vec![]; + while curr_t != 2 { + ts.push(curr_t); + curr_t >>= 1; + if curr_t & 1 == 1 { + curr_t += 1 + } + } + ts.push(2); + ts.push(1); + assert!(ts.len() >= delta); + ts[ts.len() - delta] +} + +pub fn generate_proof( + x: V, + iterations: Iterations, + delta: usize, + powers: &T, + generate_r_value: &U, + int_size_bits: usize, +) -> Vec +where + T: for<'a> Index<&'a u64, Output = V>, + U: Fn(&V, &V, &V, usize) -> V::BigNum, + V: ClassGroup, + for<'a, 'b> &'a V: std::ops::Mul<&'b V, Output = V>, + for<'a, 'b> &'a V::BigNum: std::ops::Mul<&'b V::BigNum, Output = V::BigNum>, +{ + let identity = x.identity(); + let i = approximate_i(iterations); + let mut mus = vec![]; + let mut rs: Vec = vec![]; + let mut x_p = vec![x]; + let mut curr_t = iterations.0; + + let mut y_p = vec![powers[&curr_t].clone()]; + + let mut ts = vec![]; + + let final_t = calculate_final_t(iterations, delta); + + let mut round_index = 0; + while curr_t != final_t { + assert_eq!(curr_t & 1, 0); + let half_t = curr_t >> 1; + ts.push(half_t); + assert!(round_index < 63); + let denominator: u64 = 1 << (round_index + 1); + + mus.push(if round_index < i { + let mut mu = identity.clone(); + for numerator in (1..denominator).step_by(2) { + let num_bits = 62 - denominator.leading_zeros() as usize; + let mut r_prod: V::BigNum = One::one(); + for b in (0..num_bits).rev() { + if 0 == (numerator & (1 << (b + 1))) { + r_prod *= &rs[num_bits - b - 1] + } + } + let mut t_sum = half_t; + for b in 0..num_bits { + if 0 != (numerator & (1 << (b + 1))) { + t_sum += ts[num_bits - b - 1] + } + } + let mut power = powers[&t_sum].clone(); + power.pow(r_prod); + mu *= &power; + } + mu + } else { + let mut mu = x_p.last().unwrap().clone(); + for _ in 0..half_t { + mu *= &mu.clone() + } + mu + }); + let mut mu: V = mus.last().unwrap().clone(); + let last_r: V::BigNum = generate_r_value(&x_p[0], &y_p[0], &mu, int_size_bits); + assert!(last_r >= Zero::zero()); + rs.push(last_r.clone()); + { + let mut last_x: V = x_p.last().unwrap().clone(); + last_x.pow(last_r.clone()); + last_x *= μ + x_p.push(last_x); + } + mu.pow(last_r); + mu *= y_p.last().unwrap(); + y_p.push(mu); + curr_t >>= 1; + if curr_t & 1 != 0 { + curr_t += 1; + y_p.last_mut().unwrap().square(); + } + round_index += 1 + } + if cfg!(debug_assertions) { + let mut last_y = y_p.last().unwrap().clone(); + let mut last_x = x_p.last().unwrap().clone(); + let one: V::BigNum = 1u64.into(); + last_y.pow(one.clone()); + assert_eq!(last_y, y_p.last().unwrap().clone()); + last_x.pow(one << final_t as usize); + } + mus +} + +pub fn verify_proof( + x_initial: &V, + y_initial: &V, + proof: T, + t: Iterations, + delta: usize, + generate_r_value: &U, + int_size_bits: usize, +) -> Result<(), ()> +where + T: IntoIterator, + U: Fn(&V, &V, &V, usize) -> V::BigNum, + V: ClassGroup, + for<'a, 'b> &'a V: std::ops::Mul<&'b V, Output = V>, + for<'a, 'b> &'a V::BigNum: std::ops::Mul<&'b V::BigNum, Output = V::BigNum>, +{ + let mut one: V::BigNum = One::one(); + let (mut x, mut y): (V, V) = (x_initial.clone(), y_initial.clone()); + let final_t = calculate_final_t(t, delta); + let mut curr_t = t.0; + for mut mu in proof { + assert!( + curr_t & 1 == 0, + "Cannot have an odd number of iterations remaining" + ); + let r = generate_r_value(x_initial, y_initial, &mu, int_size_bits); + x.pow(r.clone()); + x *= μ + mu.pow(r); + y *= μ + + curr_t >>= 1; + if curr_t & 1 != 0 { + curr_t += 1; + y.square(); + } + } + one <<= final_t as _; + x.pow(one); + if x == y { + Ok(()) + } else { + Err(()) + } +} + +#[derive(Debug, Clone)] +pub struct PietrzakVDF { + int_size_bits: u16, +} +use super::InvalidIterations as Bad; + +#[derive(Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, Debug)] +pub struct PietrzakVDFParams(pub u16); +impl super::VDFParams for PietrzakVDFParams { + type VDF = PietrzakVDF; + fn new(self) -> Self::VDF { + PietrzakVDF { + int_size_bits: self.0, + } + } +} + +impl super::VDF for PietrzakVDF { + fn check_difficulty(&self, difficulty: u64) -> Result<(), Bad> { + Iterations::new(difficulty) + .map_err(|x| Bad(format!("{}", x))) + .map(drop) + } + fn solve(&self, challenge: &[u8], difficulty: u64) -> Result, Bad> { + Ok(create_proof_of_time_pietrzak::( + challenge, + Iterations::new(difficulty).map_err(|x| Bad(format!("{}", x)))?, + self.int_size_bits, + )) + } + + fn verify( + &self, + challenge: &[u8], + difficulty: u64, + alleged_solution: &[u8], + ) -> Result<(), super::InvalidProof> { + check_proof_of_time_pietrzak::( + challenge, + alleged_solution, + difficulty, + self.int_size_bits, + ) + } +} + +#[cfg(test)] +mod test { + use super::*; + #[test] + fn check_approximate_i() { + assert_eq!(approximate_i(Iterations(534)), 2); + assert_eq!(approximate_i(Iterations(134)), 1); + assert_eq!(approximate_i(Iterations(1024)), 2); + } + #[test] + fn check_cache_indices() { + assert_eq!(cache_indices_for_count(Iterations(66))[..], [33, 66]); + assert_eq!( + cache_indices_for_count(Iterations(534))[..], + [134, 267, 401, 534] + ); + } + + #[test] + fn check_calculate_final_t() { + assert_eq!(calculate_final_t(Iterations(1024), 8), 128); + assert_eq!(calculate_final_t(Iterations(1000), 8), 126); + assert_eq!(calculate_final_t(Iterations(100), 8), 100); + } + #[test] + fn check_assuptions_about_stdlib() { + assert_eq!(62 - u64::leading_zeros(1024u64), 9); + let mut q: Vec<_> = (1..4).step_by(2).collect(); + assert_eq!(q[..], [1, 3]); + q = (1..3).step_by(2).collect(); + assert_eq!(q[..], [1]); + q = (1..2).step_by(2).collect(); + assert_eq!(q[..], [1]); + } +} diff --git a/crates/vdf/src/proof_wesolowski.rs b/crates/vdf/src/proof_wesolowski.rs new file mode 100644 index 0000000..bbc72b5 --- /dev/null +++ b/crates/vdf/src/proof_wesolowski.rs @@ -0,0 +1,316 @@ +// Copyright 2018 POA Networks Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::proof_of_time::{iterate_squarings, serialize}; +use classgroup::{gmp_classgroup::GmpClassGroup, BigNum, BigNumExt, ClassGroup}; +use sha2::{digest::FixedOutput, Digest, Sha256}; +use std::{cmp::Eq, collections::HashMap, hash::Hash, mem, u64, usize}; +use std::convert::TryInto; + +#[derive(Debug, Clone)] +pub struct WesolowskiVDF { + int_size_bits: u16, +} +use super::InvalidIterations as Bad; + +#[derive(Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, Debug)] +pub struct WesolowskiVDFParams(pub u16); +impl super::VDFParams for WesolowskiVDFParams { + type VDF = WesolowskiVDF; + fn new(self) -> Self::VDF { + WesolowskiVDF { + int_size_bits: self.0, + } + } +} + +impl super::VDF for WesolowskiVDF { + fn check_difficulty(&self, _difficulty: u64) -> Result<(), Bad> { + Ok(()) + } + fn solve(&self, challenge: &[u8], difficulty: u64) -> Result, Bad> { + if difficulty > usize::MAX as u64 { + Err(Bad("Cannot have more that usize::MAX iterations".to_owned())) + } else { + Ok(create_proof_of_time_wesolowski::< + ::BigNum, + GmpClassGroup, + >( + challenge, difficulty as usize, self.int_size_bits + )) + } + } + + fn verify( + &self, + challenge: &[u8], + difficulty: u64, + alleged_solution: &[u8], + ) -> Result<(), super::InvalidProof> { + check_proof_of_time_wesolowski::<::BigNum, GmpClassGroup>( + challenge, + alleged_solution, + difficulty, + self.int_size_bits, + ) + .map_err(|()| super::InvalidProof) + } +} +/// To quote the original Python code: +/// +/// > Create `L` and `k` parameters from papers, based on how many iterations +/// > need to be performed, and how much memory should be used. +pub fn approximate_parameters(t: f64) -> (usize, u8, u64) { + let log_memory = (10_000_000.0f64).log2(); + let log_t = (t as f64).log2(); + let l = if log_t - log_memory > 0. { + 2.0f64.powf(log_memory - 20.).ceil() + } else { + 1. + }; + + let intermediate = t * (2.0f64).ln() / (2.0 * l); + let k = (intermediate.ln() - intermediate.ln().ln() + 0.25) + .round() + .max(1.); + + let w = (t / (t / k + l * (2.0f64).powf(k + 1.0)) - 2.0).floor(); + (l as _, k as _, w as _) +} + +fn u64_to_bytes(q: u64) -> [u8; 8] { + if false { + // This use of `std::mem::transumte` is correct, but still not justified. + unsafe { std::mem::transmute(q.to_be()) } + } else { + [ + (q >> 56) as u8, + (q >> 48) as u8, + (q >> 40) as u8, + (q >> 32) as u8, + (q >> 24) as u8, + (q >> 16) as u8, + (q >> 8) as u8, + q as u8, + ] + } +} + +/// Quote: +/// +/// > Creates a random prime based on input s. +fn hash_prime(seed: &[&[u8]], t: u32) -> T { + let mut j = 0u64; + loop { + let mut hasher = Sha256::new(); + hasher.input(b"prime"); + hasher.input(u64_to_bytes(j)); + for i in seed { + hasher.input(i); + } + hasher.input(t.to_be_bytes()); + let n = T::from(&hasher.fixed_result()[..16]); + if n.probab_prime(1) { + break n; + } + j += 1; + } +} + +/// Quote: +/// +/// > Get“s the ith block of `2^T // B`, such that `sum(get_block(i) * 2^(k*i)) +/// > = t^T // B` +fn get_block(i: u64, k: u8, t: u64, b: &T) -> T { + let mut res = T::from(0); + let two = T::from(2); + res.mod_powm(&two, &T::from(t - u64::from(k) * (i + 1)), b); + res *= &((two >> 1) << (k as usize)); + res / b +} + +fn eval_optimized + Eq + Hash>( + h: &L, + b: &U, + t: usize, + k: u8, + l: usize, + powers: &T, +) -> L +where + T: for<'a> std::ops::Index<&'a u64, Output = L>, +{ + assert!(k > 0, "k cannot be zero"); + assert!(l > 0, "l cannot be zero"); + let kl = (k as usize) + .checked_mul(l) + .expect("computing k*l overflowed a u64"); + assert!(kl <= u64::MAX as _); + assert!((kl as u64) < (1u64 << 53), "k*l overflowed an f64"); + assert!((t as u64) < (1u64 << 53), "t overflows an f64"); + assert!( + k < (mem::size_of::() << 3) as u8, + "k must be less than the number of bits in a usize" + ); + let k1 = k >> 1; + let k0 = k - k1; + let mut x = h.identity(); + let identity = h.identity(); + let k_exp = 1usize << k; + let k0_exp = 1usize << k0; + let k1_exp = 1usize << k1; + for j in (0..l).rev() { + x.pow(U::from(k_exp as u64)); + let mut ys: HashMap = HashMap::new(); + for b in 0..1usize << k { + ys.entry(U::from(b as u64)) + .or_insert_with(|| identity.clone()); + } + let end_of_loop = ((t as f64) / kl as f64).ceil() as usize; + assert!(end_of_loop == 0 || (end_of_loop as u64 - 1).checked_mul(l as u64).is_some()); + for i in 0..end_of_loop { + if t < k as usize * (i * l + j + 1) { + continue; + } + let b = get_block((i as u64) * (l as u64), k, t as _, b); + *ys.get_mut(&b).unwrap() *= &powers[&((i * kl) as _)]; + } + + for b1 in 0..k1_exp { + let mut z = identity.clone(); + for b0 in 0..k0_exp { + z *= &ys[&U::from((b1 * k0_exp + b0) as u64)] + } + z.pow(U::from((b1 as u64) * (k0_exp as u64))); + x *= &z; + } + + for b0 in 0..k0_exp { + let mut z = identity.clone(); + for b1 in 0..k1_exp { + z *= &ys[&U::from((b1 * k0_exp + b0) as u64)]; + } + z.pow(U::from(b0 as u64)); + x *= &z; + } + } + x +} + +pub fn generate_proof + Eq + Hash>( + x: &V, + iterations: u64, + k: u8, + l: usize, + powers: &U, + int_size_bits: usize, +) -> V +where + U: for<'a> std::ops::Index<&'a u64, Output = V>, +{ + let element_len = 2 * ((int_size_bits + 16) >> 4); + let mut x_buf = vec![0; element_len]; + x.serialize(&mut x_buf[..]) + .expect(super::INCORRECT_BUFFER_SIZE); + let mut y_buf = vec![0; element_len]; + powers[&iterations] + .serialize(&mut y_buf[..]) + .expect(super::INCORRECT_BUFFER_SIZE); + let b = hash_prime( + &[&x_buf[..], &y_buf[..]], + iterations.try_into().expect("iterations fit into u32") + ); + eval_optimized(&x, &b, iterations as _, k, l, powers) +} + +/// Verify a proof, according to the Wesolowski paper. +pub fn verify_proof>( + mut x: V, + y: &V, + mut proof: V, + t: u64, + int_size_bits: usize, +) -> Result<(), ()> { + let element_len = 2 * ((int_size_bits + 16) >> 4); + let mut x_buf = vec![0; element_len]; + x.serialize(&mut x_buf[..]) + .expect(super::INCORRECT_BUFFER_SIZE); + let mut y_buf = vec![0; element_len]; + y.serialize(&mut y_buf[..]) + .expect(super::INCORRECT_BUFFER_SIZE); + let b = hash_prime( + &[&x_buf[..], &y_buf[..]], + t.try_into().expect("iterations fit into u32") + ); + let mut r = T::from(0); + r.mod_powm(&T::from(2u64), &T::from(t), &b); + proof.pow(b); + x.pow(r); + proof *= &x; + if &proof == y { + Ok(()) + } else { + Err(()) + } +} + +pub fn create_proof_of_time_wesolowski + Eq + Hash>( + challenge: &[u8], + iterations: usize, + int_size_bits: u16, +) -> Vec +where + for<'a, 'b> &'a V: std::ops::Mul<&'b V, Output = V>, + for<'a, 'b> &'a V::BigNum: std::ops::Mul<&'b V::BigNum, Output = V::BigNum>, +{ + let discriminant = super::create_discriminant::create_discriminant(&challenge, int_size_bits); + let x = V::from_ab_discriminant(2.into(), 1.into(), discriminant); + assert!((iterations as u128) < (1u128 << 53)); + let (l, k, _) = approximate_parameters(iterations as f64); + let q = l.checked_mul(k as _).expect("bug"); + let powers = iterate_squarings( + x.clone(), + (0..=iterations / q + 1) + .map(|i| i * q) + .chain(Some(iterations)) + .map(|x| x as _), + ); + let proof = generate_proof(&x, iterations as _, k, l, &powers, int_size_bits.into()); + serialize(&[proof], &powers[&(iterations as _)], int_size_bits.into()) +} + +pub fn check_proof_of_time_wesolowski>( + challenge: &[u8], + proof_blob: &[u8], + iterations: u64, + int_size_bits: u16, +) -> Result<(), ()> +where + T: BigNumExt, +{ + let discriminant: T = super::create_discriminant::create_discriminant(challenge, int_size_bits); + let x = V::from_ab_discriminant(2.into(), 1.into(), discriminant.clone()); + if (usize::MAX - 16) < int_size_bits.into() { + return Err(()); + } + let int_size = (usize::from(int_size_bits) + 16) >> 4; + if int_size * 4 != proof_blob.len() { + return Err(()); + } + let (result_bytes, proof_bytes) = proof_blob.split_at(2 * int_size); + let proof = ClassGroup::from_bytes(proof_bytes, discriminant.clone()); + let y = ClassGroup::from_bytes(result_bytes, discriminant); + + verify_proof(x, &y, proof, iterations, int_size_bits.into()) +} diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 10d6265..816b238 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -7,14 +7,6 @@ services: node: image: ${QUILIBRIUM_IMAGE_NAME:-quilibrium} restart: unless-stopped - command: ["--signature-check=false"] - deploy: - resources: - limits: - memory: '32G' - reservations: - cpus: '12' - memory: '16G' environment: - DEFAULT_LISTEN_GRPC_MULTIADDR=/ip4/0.0.0.0/tcp/8337 - DEFAULT_LISTEN_REST_MULTIADDR=/ip4/0.0.0.0/tcp/8338 @@ -28,7 +20,7 @@ services: interval: 30s timeout: 5s retries: 3 - start_period: 1m + start_period: 15m volumes: - ./.config:/root/.config logging: diff --git a/docker/rustup-init.sh b/docker/rustup-init.sh new file mode 100755 index 0000000..c49b6ab --- /dev/null +++ b/docker/rustup-init.sh @@ -0,0 +1,811 @@ +#!/bin/sh +# shellcheck shell=dash +# shellcheck disable=SC2039 # local is non-POSIX + +# This is just a little script that can be downloaded from the internet to +# install rustup. It just does platform detection, downloads the installer +# and runs it. + +# It runs on Unix shells like {a,ba,da,k,z}sh. It uses the common `local` +# extension. Note: Most shells limit `local` to 1 var per line, contra bash. + +# Some versions of ksh have no `local` keyword. Alias it to `typeset`, but +# beware this makes variables global with f()-style function syntax in ksh93. +# mksh has this alias by default. +has_local() { + # shellcheck disable=SC2034 # deliberately unused + local _has_local +} + +has_local 2>/dev/null || alias local=typeset + +is_zsh() { + [ -n "${ZSH_VERSION-}" ] +} + +set -u + +# If RUSTUP_UPDATE_ROOT is unset or empty, default it. +RUSTUP_UPDATE_ROOT="${RUSTUP_UPDATE_ROOT:-https://static.rust-lang.org/rustup}" + +# NOTICE: If you change anything here, please make the same changes in setup_mode.rs +usage() { + cat < + Choose a default host triple + --default-toolchain + Choose a default toolchain to install. Use 'none' to not install any toolchains at all + --profile + [default: default] [possible values: minimal, default, complete] + -c, --component ... + Component name to also install + -t, --target ... + Target name to also install + --no-update-default-toolchain + Don't update any existing default toolchain after install + --no-modify-path + Don't configure the PATH environment variable + -h, --help + Print help + -V, --version + Print version +EOF +} + +main() { + downloader --check + need_cmd uname + need_cmd mktemp + need_cmd chmod + need_cmd mkdir + need_cmd rm + need_cmd rmdir + + get_architecture || return 1 + local _arch="$RETVAL" + assert_nz "$_arch" "arch" + + local _ext="" + case "$_arch" in + *windows*) + _ext=".exe" + ;; + esac + + local _url="${RUSTUP_UPDATE_ROOT}/dist/${_arch}/rustup-init${_ext}" + + local _dir + if ! _dir="$(ensure mktemp -d)"; then + # Because the previous command ran in a subshell, we must manually + # propagate exit status. + exit 1 + fi + local _file="${_dir}/rustup-init${_ext}" + + local _ansi_escapes_are_valid=false + if [ -t 2 ]; then + if [ "${TERM+set}" = 'set' ]; then + case "$TERM" in + xterm*|rxvt*|urxvt*|linux*|vt*) + _ansi_escapes_are_valid=true + ;; + esac + fi + fi + + # check if we have to use /dev/tty to prompt the user + local need_tty=yes + for arg in "$@"; do + case "$arg" in + --help) + usage + exit 0 + ;; + *) + OPTIND=1 + if [ "${arg%%--*}" = "" ]; then + # Long option (other than --help); + # don't attempt to interpret it. + continue + fi + while getopts :hy sub_arg "$arg"; do + case "$sub_arg" in + h) + usage + exit 0 + ;; + y) + # user wants to skip the prompt -- + # we don't need /dev/tty + need_tty=no + ;; + *) + ;; + esac + done + ;; + esac + done + + if $_ansi_escapes_are_valid; then + printf "\33[1minfo:\33[0m downloading installer\n" 1>&2 + else + printf '%s\n' 'info: downloading installer' 1>&2 + fi + + ensure mkdir -p "$_dir" + ensure downloader "$_url" "$_file" "$_arch" + ensure chmod u+x "$_file" + if [ ! -x "$_file" ]; then + printf '%s\n' "Cannot execute $_file (likely because of mounting /tmp as noexec)." 1>&2 + printf '%s\n' "Please copy the file to a location where you can execute binaries and run ./rustup-init${_ext}." 1>&2 + exit 1 + fi + + if [ "$need_tty" = "yes" ] && [ ! -t 0 ]; then + # The installer is going to want to ask for confirmation by + # reading stdin. This script was piped into `sh` though and + # doesn't have stdin to pass to its children. Instead we're going + # to explicitly connect /dev/tty to the installer's stdin. + if [ ! -t 1 ]; then + err "Unable to run interactively. Run with -y to accept defaults, --help for additional options" + fi + + ignore "$_file" "$@" < /dev/tty + else + ignore "$_file" "$@" + fi + + local _retval=$? + + ignore rm "$_file" + ignore rmdir "$_dir" + + return "$_retval" +} + +check_proc() { + # Check for /proc by looking for the /proc/self/exe link + # This is only run on Linux + if ! test -L /proc/self/exe ; then + err "fatal: Unable to find /proc/self/exe. Is /proc mounted? Installation cannot proceed without /proc." + fi +} + +get_bitness() { + need_cmd head + # Architecture detection without dependencies beyond coreutils. + # ELF files start out "\x7fELF", and the following byte is + # 0x01 for 32-bit and + # 0x02 for 64-bit. + # The printf builtin on some shells like dash only supports octal + # escape sequences, so we use those. + local _current_exe_head + _current_exe_head=$(head -c 5 /proc/self/exe ) + if [ "$_current_exe_head" = "$(printf '\177ELF\001')" ]; then + echo 32 + elif [ "$_current_exe_head" = "$(printf '\177ELF\002')" ]; then + echo 64 + else + err "unknown platform bitness" + fi +} + +is_host_amd64_elf() { + need_cmd head + need_cmd tail + # ELF e_machine detection without dependencies beyond coreutils. + # Two-byte field at offset 0x12 indicates the CPU, + # but we're interested in it being 0x3E to indicate amd64, or not that. + local _current_exe_machine + _current_exe_machine=$(head -c 19 /proc/self/exe | tail -c 1) + [ "$_current_exe_machine" = "$(printf '\076')" ] +} + +get_endianness() { + local cputype=$1 + local suffix_eb=$2 + local suffix_el=$3 + + # detect endianness without od/hexdump, like get_bitness() does. + need_cmd head + need_cmd tail + + local _current_exe_endianness + _current_exe_endianness="$(head -c 6 /proc/self/exe | tail -c 1)" + if [ "$_current_exe_endianness" = "$(printf '\001')" ]; then + echo "${cputype}${suffix_el}" + elif [ "$_current_exe_endianness" = "$(printf '\002')" ]; then + echo "${cputype}${suffix_eb}" + else + err "unknown platform endianness" + fi +} + +# Detect the Linux/LoongArch UAPI flavor, with all errors being non-fatal. +# Returns 0 or 234 in case of successful detection, 1 otherwise (/tmp being +# noexec, or other causes). +check_loongarch_uapi() { + need_cmd base64 + + local _tmp + if ! _tmp="$(ensure mktemp)"; then + return 1 + fi + + # Minimal Linux/LoongArch UAPI detection, exiting with 0 in case of + # upstream ("new world") UAPI, and 234 (-EINVAL truncated) in case of + # old-world (as deployed on several early commercial Linux distributions + # for LoongArch). + # + # See https://gist.github.com/xen0n/5ee04aaa6cecc5c7794b9a0c3b65fc7f for + # source to this helper binary. + ignore base64 -d > "$_tmp" <&2 + echo 'Your Linux kernel does not provide the ABI required by this Rust' >&2 + echo 'distribution. Please check with your OS provider for how to obtain a' >&2 + echo 'compatible Rust package for your system.' >&2 + echo >&2 + exit 1 + ;; + *) + echo "Warning: Cannot determine current system's ABI flavor, continuing anyway." >&2 + echo >&2 + echo 'Note that the official Rust distribution only works with the upstream' >&2 + echo 'kernel ABI. Installation will fail if your running kernel happens to be' >&2 + echo 'incompatible.' >&2 + ;; + esac +} + +get_architecture() { + local _ostype _cputype _bitness _arch _clibtype + _ostype="$(uname -s)" + _cputype="$(uname -m)" + _clibtype="gnu" + + if [ "$_ostype" = Linux ]; then + if [ "$(uname -o)" = Android ]; then + _ostype=Android + fi + if ldd --version 2>&1 | grep -q 'musl'; then + _clibtype="musl" + fi + fi + + if [ "$_ostype" = Darwin ]; then + # Darwin `uname -m` can lie due to Rosetta shenanigans. If you manage to + # invoke a native shell binary and then a native uname binary, you can + # get the real answer, but that's hard to ensure, so instead we use + # `sysctl` (which doesn't lie) to check for the actual architecture. + if [ "$_cputype" = i386 ]; then + # Handling i386 compatibility mode in older macOS versions (<10.15) + # running on x86_64-based Macs. + # Starting from 10.15, macOS explicitly bans all i386 binaries from running. + # See: + + # Avoid `sysctl: unknown oid` stderr output and/or non-zero exit code. + if sysctl hw.optional.x86_64 2> /dev/null || true | grep -q ': 1'; then + _cputype=x86_64 + fi + elif [ "$_cputype" = x86_64 ]; then + # Handling x86-64 compatibility mode (a.k.a. Rosetta 2) + # in newer macOS versions (>=11) running on arm64-based Macs. + # Rosetta 2 is built exclusively for x86-64 and cannot run i386 binaries. + + # Avoid `sysctl: unknown oid` stderr output and/or non-zero exit code. + if sysctl hw.optional.arm64 2> /dev/null || true | grep -q ': 1'; then + _cputype=arm64 + fi + fi + fi + + if [ "$_ostype" = SunOS ]; then + # Both Solaris and illumos presently announce as "SunOS" in "uname -s" + # so use "uname -o" to disambiguate. We use the full path to the + # system uname in case the user has coreutils uname first in PATH, + # which has historically sometimes printed the wrong value here. + if [ "$(/usr/bin/uname -o)" = illumos ]; then + _ostype=illumos + fi + + # illumos systems have multi-arch userlands, and "uname -m" reports the + # machine hardware name; e.g., "i86pc" on both 32- and 64-bit x86 + # systems. Check for the native (widest) instruction set on the + # running kernel: + if [ "$_cputype" = i86pc ]; then + _cputype="$(isainfo -n)" + fi + fi + + case "$_ostype" in + + Android) + _ostype=linux-android + ;; + + Linux) + check_proc + _ostype=unknown-linux-$_clibtype + _bitness=$(get_bitness) + ;; + + FreeBSD) + _ostype=unknown-freebsd + ;; + + NetBSD) + _ostype=unknown-netbsd + ;; + + DragonFly) + _ostype=unknown-dragonfly + ;; + + Darwin) + _ostype=apple-darwin + ;; + + illumos) + _ostype=unknown-illumos + ;; + + MINGW* | MSYS* | CYGWIN* | Windows_NT) + _ostype=pc-windows-gnu + ;; + + *) + err "unrecognized OS type: $_ostype" + ;; + + esac + + case "$_cputype" in + + i386 | i486 | i686 | i786 | x86) + _cputype=i686 + ;; + + xscale | arm) + _cputype=arm + if [ "$_ostype" = "linux-android" ]; then + _ostype=linux-androideabi + fi + ;; + + armv6l) + _cputype=arm + if [ "$_ostype" = "linux-android" ]; then + _ostype=linux-androideabi + else + _ostype="${_ostype}eabihf" + fi + ;; + + armv7l | armv8l) + _cputype=armv7 + if [ "$_ostype" = "linux-android" ]; then + _ostype=linux-androideabi + else + _ostype="${_ostype}eabihf" + fi + ;; + + aarch64 | arm64) + _cputype=aarch64 + ;; + + x86_64 | x86-64 | x64 | amd64) + _cputype=x86_64 + ;; + + mips) + _cputype=$(get_endianness mips '' el) + ;; + + mips64) + if [ "$_bitness" -eq 64 ]; then + # only n64 ABI is supported for now + _ostype="${_ostype}abi64" + _cputype=$(get_endianness mips64 '' el) + fi + ;; + + ppc) + _cputype=powerpc + ;; + + ppc64) + _cputype=powerpc64 + ;; + + ppc64le) + _cputype=powerpc64le + ;; + + s390x) + _cputype=s390x + ;; + riscv64) + _cputype=riscv64gc + ;; + loongarch64) + _cputype=loongarch64 + ensure_loongarch_uapi + ;; + *) + err "unknown CPU type: $_cputype" + + esac + + # Detect 64-bit linux with 32-bit userland + if [ "${_ostype}" = unknown-linux-gnu ] && [ "${_bitness}" -eq 32 ]; then + case $_cputype in + x86_64) + if [ -n "${RUSTUP_CPUTYPE:-}" ]; then + _cputype="$RUSTUP_CPUTYPE" + else { + # 32-bit executable for amd64 = x32 + if is_host_amd64_elf; then { + echo "This host is running an x32 userland; as it stands, x32 support is poor," 1>&2 + echo "and there isn't a native toolchain -- you will have to install" 1>&2 + echo "multiarch compatibility with i686 and/or amd64, then select one" 1>&2 + echo "by re-running this script with the RUSTUP_CPUTYPE environment variable" 1>&2 + echo "set to i686 or x86_64, respectively." 1>&2 + echo 1>&2 + echo "You will be able to add an x32 target after installation by running" 1>&2 + echo " rustup target add x86_64-unknown-linux-gnux32" 1>&2 + exit 1 + }; else + _cputype=i686 + fi + }; fi + ;; + mips64) + _cputype=$(get_endianness mips '' el) + ;; + powerpc64) + _cputype=powerpc + ;; + aarch64) + _cputype=armv7 + if [ "$_ostype" = "linux-android" ]; then + _ostype=linux-androideabi + else + _ostype="${_ostype}eabihf" + fi + ;; + riscv64gc) + err "riscv64 with 32-bit userland unsupported" + ;; + esac + fi + + # Detect armv7 but without the CPU features Rust needs in that build, + # and fall back to arm. + # See https://github.com/rust-lang/rustup.rs/issues/587. + if [ "$_ostype" = "unknown-linux-gnueabihf" ] && [ "$_cputype" = armv7 ]; then + if ensure grep '^Features' /proc/cpuinfo | grep -E -q -v 'neon|simd'; then + # At least one processor does not have NEON (which is asimd on armv8+). + _cputype=arm + fi + fi + + _arch="${_cputype}-${_ostype}" + + RETVAL="$_arch" +} + +say() { + printf 'rustup: %s\n' "$1" +} + +err() { + say "$1" >&2 + exit 1 +} + +need_cmd() { + if ! check_cmd "$1"; then + err "need '$1' (command not found)" + fi +} + +check_cmd() { + command -v "$1" > /dev/null 2>&1 +} + +assert_nz() { + if [ -z "$1" ]; then err "assert_nz $2"; fi +} + +# Run a command that should never fail. If the command fails execution +# will immediately terminate with an error showing the failing +# command. +ensure() { + if ! "$@"; then err "command failed: $*"; fi +} + +# This is just for indicating that commands' results are being +# intentionally ignored. Usually, because it's being executed +# as part of error handling. +ignore() { + "$@" +} + +# This wraps curl or wget. Try curl first, if not installed, +# use wget instead. +downloader() { + # zsh does not split words by default, Required for curl retry arguments below. + is_zsh && setopt local_options shwordsplit + + local _dld + local _ciphersuites + local _err + local _status + local _retry + if check_cmd curl; then + _dld=curl + elif check_cmd wget; then + _dld=wget + else + _dld='curl or wget' # to be used in error message of need_cmd + fi + + if [ "$1" = --check ]; then + need_cmd "$_dld" + elif [ "$_dld" = curl ]; then + check_curl_for_retry_support + _retry="$RETVAL" + get_ciphersuites_for_curl + _ciphersuites="$RETVAL" + if [ -n "$_ciphersuites" ]; then + _err=$(curl $_retry --proto '=https' --tlsv1.2 --ciphers "$_ciphersuites" --silent --show-error --fail --location "$1" --output "$2" 2>&1) + _status=$? + else + echo "Warning: Not enforcing strong cipher suites for TLS, this is potentially less secure" + if ! check_help_for "$3" curl --proto --tlsv1.2; then + echo "Warning: Not enforcing TLS v1.2, this is potentially less secure" + _err=$(curl $_retry --silent --show-error --fail --location "$1" --output "$2" 2>&1) + _status=$? + else + _err=$(curl $_retry --proto '=https' --tlsv1.2 --silent --show-error --fail --location "$1" --output "$2" 2>&1) + _status=$? + fi + fi + if [ -n "$_err" ]; then + echo "$_err" >&2 + if echo "$_err" | grep -q 404$; then + err "installer for platform '$3' not found, this may be unsupported" + fi + fi + return $_status + elif [ "$_dld" = wget ]; then + if [ "$(wget -V 2>&1|head -2|tail -1|cut -f1 -d" ")" = "BusyBox" ]; then + echo "Warning: using the BusyBox version of wget. Not enforcing strong cipher suites for TLS or TLS v1.2, this is potentially less secure" + _err=$(wget "$1" -O "$2" 2>&1) + _status=$? + else + get_ciphersuites_for_wget + _ciphersuites="$RETVAL" + if [ -n "$_ciphersuites" ]; then + _err=$(wget --https-only --secure-protocol=TLSv1_2 --ciphers "$_ciphersuites" "$1" -O "$2" 2>&1) + _status=$? + else + echo "Warning: Not enforcing strong cipher suites for TLS, this is potentially less secure" + if ! check_help_for "$3" wget --https-only --secure-protocol; then + echo "Warning: Not enforcing TLS v1.2, this is potentially less secure" + _err=$(wget "$1" -O "$2" 2>&1) + _status=$? + else + _err=$(wget --https-only --secure-protocol=TLSv1_2 "$1" -O "$2" 2>&1) + _status=$? + fi + fi + fi + if [ -n "$_err" ]; then + echo "$_err" >&2 + if echo "$_err" | grep -q ' 404 Not Found$'; then + err "installer for platform '$3' not found, this may be unsupported" + fi + fi + return $_status + else + err "Unknown downloader" # should not reach here + fi +} + +check_help_for() { + local _arch + local _cmd + local _arg + _arch="$1" + shift + _cmd="$1" + shift + + local _category + if "$_cmd" --help | grep -q 'For all options use the manual or "--help all".'; then + _category="all" + else + _category="" + fi + + case "$_arch" in + + *darwin*) + if check_cmd sw_vers; then + case $(sw_vers -productVersion) in + 10.*) + # If we're running on macOS, older than 10.13, then we always + # fail to find these options to force fallback + if [ "$(sw_vers -productVersion | cut -d. -f2)" -lt 13 ]; then + # Older than 10.13 + echo "Warning: Detected macOS platform older than 10.13" + return 1 + fi + ;; + 11.*) + # We assume Big Sur will be OK for now + ;; + *) + # Unknown product version, warn and continue + echo "Warning: Detected unknown macOS major version: $(sw_vers -productVersion)" + echo "Warning TLS capabilities detection may fail" + ;; + esac + fi + ;; + + esac + + for _arg in "$@"; do + if ! "$_cmd" --help "$_category" | grep -q -- "$_arg"; then + return 1 + fi + done + + true # not strictly needed +} + +# Check if curl supports the --retry flag, then pass it to the curl invocation. +check_curl_for_retry_support() { + local _retry_supported="" + # "unspecified" is for arch, allows for possibility old OS using macports, homebrew, etc. + if check_help_for "notspecified" "curl" "--retry"; then + _retry_supported="--retry 3" + if check_help_for "notspecified" "curl" "--continue-at"; then + # "-C -" tells curl to automatically find where to resume the download when retrying. + _retry_supported="--retry 3 -C -" + fi + fi + + RETVAL="$_retry_supported" +} + +# Return cipher suite string specified by user, otherwise return strong TLS 1.2-1.3 cipher suites +# if support by local tools is detected. Detection currently supports these curl backends: +# GnuTLS and OpenSSL (possibly also LibreSSL and BoringSSL). Return value can be empty. +get_ciphersuites_for_curl() { + if [ -n "${RUSTUP_TLS_CIPHERSUITES-}" ]; then + # user specified custom cipher suites, assume they know what they're doing + RETVAL="$RUSTUP_TLS_CIPHERSUITES" + return + fi + + local _openssl_syntax="no" + local _gnutls_syntax="no" + local _backend_supported="yes" + if curl -V | grep -q ' OpenSSL/'; then + _openssl_syntax="yes" + elif curl -V | grep -iq ' LibreSSL/'; then + _openssl_syntax="yes" + elif curl -V | grep -iq ' BoringSSL/'; then + _openssl_syntax="yes" + elif curl -V | grep -iq ' GnuTLS/'; then + _gnutls_syntax="yes" + else + _backend_supported="no" + fi + + local _args_supported="no" + if [ "$_backend_supported" = "yes" ]; then + # "unspecified" is for arch, allows for possibility old OS using macports, homebrew, etc. + if check_help_for "notspecified" "curl" "--tlsv1.2" "--ciphers" "--proto"; then + _args_supported="yes" + fi + fi + + local _cs="" + if [ "$_args_supported" = "yes" ]; then + if [ "$_openssl_syntax" = "yes" ]; then + _cs=$(get_strong_ciphersuites_for "openssl") + elif [ "$_gnutls_syntax" = "yes" ]; then + _cs=$(get_strong_ciphersuites_for "gnutls") + fi + fi + + RETVAL="$_cs" +} + +# Return cipher suite string specified by user, otherwise return strong TLS 1.2-1.3 cipher suites +# if support by local tools is detected. Detection currently supports these wget backends: +# GnuTLS and OpenSSL (possibly also LibreSSL and BoringSSL). Return value can be empty. +get_ciphersuites_for_wget() { + if [ -n "${RUSTUP_TLS_CIPHERSUITES-}" ]; then + # user specified custom cipher suites, assume they know what they're doing + RETVAL="$RUSTUP_TLS_CIPHERSUITES" + return + fi + + local _cs="" + if wget -V | grep -q '\-DHAVE_LIBSSL'; then + # "unspecified" is for arch, allows for possibility old OS using macports, homebrew, etc. + if check_help_for "notspecified" "wget" "TLSv1_2" "--ciphers" "--https-only" "--secure-protocol"; then + _cs=$(get_strong_ciphersuites_for "openssl") + fi + elif wget -V | grep -q '\-DHAVE_LIBGNUTLS'; then + # "unspecified" is for arch, allows for possibility old OS using macports, homebrew, etc. + if check_help_for "notspecified" "wget" "TLSv1_2" "--ciphers" "--https-only" "--secure-protocol"; then + _cs=$(get_strong_ciphersuites_for "gnutls") + fi + fi + + RETVAL="$_cs" +} + +# Return strong TLS 1.2-1.3 cipher suites in OpenSSL or GnuTLS syntax. TLS 1.2 +# excludes non-ECDHE and non-AEAD cipher suites. DHE is excluded due to bad +# DH params often found on servers (see RFC 7919). Sequence matches or is +# similar to Firefox 68 ESR with weak cipher suites disabled via about:config. +# $1 must be openssl or gnutls. +get_strong_ciphersuites_for() { + if [ "$1" = "openssl" ]; then + # OpenSSL is forgiving of unknown values, no problems with TLS 1.3 values on versions that don't support it yet. + echo "TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384" + elif [ "$1" = "gnutls" ]; then + # GnuTLS isn't forgiving of unknown values, so this may require a GnuTLS version that supports TLS 1.3 even if wget doesn't. + # Begin with SECURE128 (and higher) then remove/add to build cipher suites. Produces same 9 cipher suites as OpenSSL but in slightly different order. + echo "SECURE128:-VERS-SSL3.0:-VERS-TLS1.0:-VERS-TLS1.1:-VERS-DTLS-ALL:-CIPHER-ALL:-MAC-ALL:-KX-ALL:+AEAD:+ECDHE-ECDSA:+ECDHE-RSA:+AES-128-GCM:+CHACHA20-POLY1305:+AES-256-GCM" + fi +} + +main "$@" || exit 1 diff --git a/go-libp2p-blossomsub/blossomsub.go b/go-libp2p-blossomsub/blossomsub.go index 9005a1e..bb2824b 100644 --- a/go-libp2p-blossomsub/blossomsub.go +++ b/go-libp2p-blossomsub/blossomsub.go @@ -1,6 +1,7 @@ package blossomsub import ( + "bytes" "context" "fmt" "math/rand" @@ -9,12 +10,14 @@ import ( pb "source.quilibrium.com/quilibrium/monorepo/go-libp2p-blossomsub/pb" + "github.com/libp2p/go-libp2p/core/event" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peerstore" "github.com/libp2p/go-libp2p/core/protocol" "github.com/libp2p/go-libp2p/core/record" + "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem" ) const ( @@ -26,7 +29,7 @@ const ( var ( BlossomSubD = 6 BlossomSubDlo = 5 - BlossomSubDhi = 10 + BlossomSubDhi = 12 BlossomSubDscore = 4 BlossomSubDout = 2 BlossomSubHistoryLength = 5 @@ -219,6 +222,7 @@ func NewBlossomSubRouter(h host.Host, params BlossomSubParams) *BlossomSubRouter lastpub: make(map[string]int64), gossip: make(map[peer.ID][]*pb.ControlIHave), control: make(map[peer.ID]*pb.ControlMessage), + cab: pstoremem.NewAddrBook(), backoff: make(map[string]map[peer.ID]time.Time), peerhave: make(map[peer.ID]int), iasked: make(map[peer.ID]int), @@ -247,6 +251,7 @@ func DefaultBlossomSubRouter(h host.Host) *BlossomSubRouter { iasked: make(map[peer.ID]int), outbound: make(map[peer.ID]bool), connect: make(chan connectInfo, params.MaxPendingConnections), + cab: pstoremem.NewAddrBook(), mcache: NewMessageCache(params.HistoryGossip, params.HistoryLength), protos: BlossomSubDefaultProtocols, feature: BlossomSubDefaultFeatures, @@ -447,6 +452,7 @@ type BlossomSubRouter struct { outbound map[peer.ID]bool // connection direction cache, marks peers with outbound connections backoff map[string]map[peer.ID]time.Time // prune backoff connect chan connectInfo // px connection requests + cab peerstore.AddrBook protos []protocol.ID feature BlossomSubFeatureTest @@ -525,6 +531,9 @@ func (bs *BlossomSubRouter) Attach(p *PubSub) { go bs.connector() } + // Manage our address book from events emitted by libp2p + go bs.manageAddrBook() + // connect to direct peers if len(bs.direct) > 0 { go func() { @@ -538,6 +547,46 @@ func (bs *BlossomSubRouter) Attach(p *PubSub) { } } +func (bs *BlossomSubRouter) manageAddrBook() { + sub, err := bs.p.host.EventBus().Subscribe([]interface{}{ + &event.EvtPeerIdentificationCompleted{}, + &event.EvtPeerConnectednessChanged{}, + }) + if err != nil { + log.Errorf("failed to subscribe to peer identification events: %v", err) + return + } + defer sub.Close() + + for { + select { + case <-bs.p.ctx.Done(): + return + case ev := <-sub.Out(): + switch ev := ev.(type) { + case event.EvtPeerIdentificationCompleted: + if ev.SignedPeerRecord != nil { + cab, ok := peerstore.GetCertifiedAddrBook(bs.cab) + if ok { + ttl := peerstore.RecentlyConnectedAddrTTL + if bs.p.host.Network().Connectedness(ev.Peer) == network.Connected { + ttl = peerstore.ConnectedAddrTTL + } + _, err := cab.ConsumePeerRecord(ev.SignedPeerRecord, ttl) + if err != nil { + log.Warnf("failed to consume signed peer record: %v", err) + } + } + } + case event.EvtPeerConnectednessChanged: + if ev.Connectedness != network.Connected { + bs.cab.UpdateAddrs(ev.Peer, peerstore.ConnectedAddrTTL, peerstore.RecentlyConnectedAddrTTL) + } + } + } + } +} + func (bs *BlossomSubRouter) AddPeer(p peer.ID, proto protocol.ID) { log.Debugf("PEERUP: Add new peer %s using %s", p, proto) bs.tracer.AddPeer(p, proto) @@ -550,7 +599,7 @@ loop: for _, c := range conns { stat := c.Stat() - if stat.Transient { + if stat.Limited { continue } @@ -968,7 +1017,7 @@ func (bs *BlossomSubRouter) connector() { } log.Debugf("connecting to %s", ci.p) - cab, ok := peerstore.GetCertifiedAddrBook(bs.p.host.Peerstore()) + cab, ok := peerstore.GetCertifiedAddrBook(bs.cab) if ok && ci.spr != nil { _, err := cab.ConsumePeerRecord(ci.spr, peerstore.TempAddrTTL) if err != nil { @@ -977,7 +1026,7 @@ func (bs *BlossomSubRouter) connector() { } ctx, cancel := context.WithTimeout(bs.p.ctx, bs.params.ConnectionTimeout) - err := bs.p.host.Connect(ctx, peer.AddrInfo{ID: ci.p}) + err := bs.p.host.Connect(ctx, peer.AddrInfo{ID: ci.p, Addrs: bs.cab.Addrs(ci.p)}) cancel() if err != nil { log.Debugf("error connecting to %s: %s", ci.p, err) @@ -1188,20 +1237,20 @@ func (bs *BlossomSubRouter) sendRPC(p peer.ID, out *RPC) { return } - // If we're too big, fragment into multiple RPCs and send each sequentially - outRPCs, err := fragmentRPC(out, bs.p.maxMessageSize) - if err != nil { - bs.doDropRPC(out, p, fmt.Sprintf("unable to fragment RPC: %s", err)) - return - } - + // Potentially split the RPC into multiple RPCs that are below the max message size + outRPCs := appendOrMergeRPC(nil, bs.p.maxMessageSize, *out) for _, rpc := range outRPCs { + if rpc.Size() > bs.p.maxMessageSize { + // This should only happen if a single message/control is above the maxMessageSize. + bs.doDropRPC(out, p, fmt.Sprintf("Dropping oversized RPC. Size: %d, limit: %d. (Over by %d bytes)", rpc.Size(), bs.p.maxMessageSize, rpc.Size()-bs.p.maxMessageSize)) + continue + } bs.doSendRPC(rpc, p, mch) } } func (bs *BlossomSubRouter) doDropRPC(rpc *RPC, p peer.ID, reason string) { - log.Debugf("dropping message to peer %s: %s", p.Pretty(), reason) + log.Debugf("dropping message to peer %s: %s", p, reason) bs.tracer.DropRPC(rpc, p) // push control messages that need to be retried ctl := rpc.GetControl() @@ -1219,119 +1268,134 @@ func (bs *BlossomSubRouter) doSendRPC(rpc *RPC, p peer.ID, mch chan *RPC) { } } -func fragmentRPC(rpc *RPC, limit int) ([]*RPC, error) { - if rpc.Size() < limit { - return []*RPC{rpc}, nil +// appendOrMergeRPC appends the given RPCs to the slice, merging them if possible. +// If any elem is too large to fit in a single RPC, it will be split into multiple RPCs. +// If an RPC is too large and can't be split further (e.g. Message data is +// bigger than the RPC limit), then it will be returned as an oversized RPC. +// The caller should filter out oversized RPCs. +func appendOrMergeRPC(slice []*RPC, limit int, elems ...RPC) []*RPC { + if len(elems) == 0 { + return slice } - c := (rpc.Size() / limit) + 1 - rpcs := make([]*RPC, 1, c) - rpcs[0] = &RPC{RPC: pb.RPC{}, from: rpc.from} + if len(slice) == 0 && len(elems) == 1 && elems[0].Size() < limit { + // Fast path: no merging needed and only one element + return append(slice, &elems[0]) + } - // outRPC returns the current RPC message if it will fit sizeToAdd more bytes - // otherwise, it will create a new RPC message and add it to the list. - // if withCtl is true, the returned message will have a non-nil empty Control message. - outRPC := func(sizeToAdd int, withCtl bool) *RPC { - current := rpcs[len(rpcs)-1] - // check if we can fit the new data, plus an extra byte for the protobuf field tag - if current.Size()+sizeToAdd+1 < limit { - if withCtl && current.Control == nil { - current.Control = &pb.ControlMessage{} + out := slice + if len(out) == 0 { + out = append(out, &RPC{RPC: pb.RPC{}}) + out[0].from = elems[0].from + } + + for _, elem := range elems { + lastRPC := out[len(out)-1] + + // Merge/Append publish messages + // TODO: Never merge messages. The current behavior is the same as the + // old behavior. In the future let's not merge messages. Since, + // it may increase message latency. + for _, msg := range elem.GetPublish() { + if lastRPC.Publish = append(lastRPC.Publish, msg); lastRPC.Size() > limit { + lastRPC.Publish = lastRPC.Publish[:len(lastRPC.Publish)-1] + lastRPC = &RPC{RPC: pb.RPC{}, from: elem.from} + lastRPC.Publish = append(lastRPC.Publish, msg) + out = append(out, lastRPC) } - return current } - var ctl *pb.ControlMessage - if withCtl { - ctl = &pb.ControlMessage{} + + // Merge/Append Subscriptions + for _, sub := range elem.GetSubscriptions() { + if lastRPC.Subscriptions = append(lastRPC.Subscriptions, sub); lastRPC.Size() > limit { + lastRPC.Subscriptions = lastRPC.Subscriptions[:len(lastRPC.Subscriptions)-1] + lastRPC = &RPC{RPC: pb.RPC{}, from: elem.from} + lastRPC.Subscriptions = append(lastRPC.Subscriptions, sub) + out = append(out, lastRPC) + } } - next := &RPC{RPC: pb.RPC{Control: ctl}, from: rpc.from} - rpcs = append(rpcs, next) - return next - } - for _, msg := range rpc.GetPublish() { - s := msg.Size() - // if an individual message is too large, we can't fragment it and have to fail entirely - if s > limit { - return nil, fmt.Errorf("message with len=%d exceeds limit %d", s, limit) - } - out := outRPC(s, false) - out.Publish = append(out.Publish, msg) - } + // Merge/Append Control messages + if ctl := elem.GetControl(); ctl != nil { + if lastRPC.Control == nil { + lastRPC.Control = &pb.ControlMessage{} + if lastRPC.Size() > limit { + lastRPC.Control = nil + lastRPC = &RPC{RPC: pb.RPC{Control: &pb.ControlMessage{}}, from: elem.from} + out = append(out, lastRPC) + } + } - for _, sub := range rpc.GetSubscriptions() { - out := outRPC(sub.Size(), false) - out.Subscriptions = append(out.Subscriptions, sub) - } + for _, graft := range ctl.GetGraft() { + if lastRPC.Control.Graft = append(lastRPC.Control.Graft, graft); lastRPC.Size() > limit { + lastRPC.Control.Graft = lastRPC.Control.Graft[:len(lastRPC.Control.Graft)-1] + lastRPC = &RPC{RPC: pb.RPC{Control: &pb.ControlMessage{}}, from: elem.from} + lastRPC.Control.Graft = append(lastRPC.Control.Graft, graft) + out = append(out, lastRPC) + } + } - ctl := rpc.GetControl() - if ctl == nil { - // if there were no control messages, we're done - return rpcs, nil - } - // if all the control messages fit into one RPC, we just add it to the end and return - ctlOut := &RPC{RPC: pb.RPC{Control: ctl}, from: rpc.from} - if ctlOut.Size() < limit { - rpcs = append(rpcs, ctlOut) - return rpcs, nil - } + for _, prune := range ctl.GetPrune() { + if lastRPC.Control.Prune = append(lastRPC.Control.Prune, prune); lastRPC.Size() > limit { + lastRPC.Control.Prune = lastRPC.Control.Prune[:len(lastRPC.Control.Prune)-1] + lastRPC = &RPC{RPC: pb.RPC{Control: &pb.ControlMessage{}}, from: elem.from} + lastRPC.Control.Prune = append(lastRPC.Control.Prune, prune) + out = append(out, lastRPC) + } + } - // we need to split up the control messages into multiple RPCs - for _, graft := range ctl.Graft { - out := outRPC(graft.Size(), true) - out.Control.Graft = append(out.Control.Graft, graft) - } - for _, prune := range ctl.Prune { - out := outRPC(prune.Size(), true) - out.Control.Prune = append(out.Control.Prune, prune) - } + for _, iwant := range ctl.GetIwant() { + if len(lastRPC.Control.Iwant) == 0 { + // Initialize with a single IWANT. + // For IWANTs we don't need more than a single one, + // since there are no bitmask IDs here. + newIWant := &pb.ControlIWant{} + if lastRPC.Control.Iwant = append(lastRPC.Control.Iwant, newIWant); lastRPC.Size() > limit { + lastRPC.Control.Iwant = lastRPC.Control.Iwant[:len(lastRPC.Control.Iwant)-1] + lastRPC = &RPC{RPC: pb.RPC{Control: &pb.ControlMessage{ + Iwant: []*pb.ControlIWant{newIWant}, + }}, from: elem.from} + out = append(out, lastRPC) + } + } + for _, msgID := range iwant.GetMessageIDs() { + if lastRPC.Control.Iwant[0].MessageIDs = append(lastRPC.Control.Iwant[0].MessageIDs, msgID); lastRPC.Size() > limit { + lastRPC.Control.Iwant[0].MessageIDs = lastRPC.Control.Iwant[0].MessageIDs[:len(lastRPC.Control.Iwant[0].MessageIDs)-1] + lastRPC = &RPC{RPC: pb.RPC{Control: &pb.ControlMessage{ + Iwant: []*pb.ControlIWant{{MessageIDs: []string{msgID}}}, + }}, from: elem.from} + out = append(out, lastRPC) + } + } + } - // An individual IWANT or IHAVE message could be larger than the limit if we have - // a lot of message IDs. fragmentMessageIds will split them into buckets that - // fit within the limit, with some overhead for the control messages themselves - for _, iwant := range ctl.Iwant { - const protobufOverhead = 6 - idBuckets := fragmentMessageIds(iwant.MessageIDs, limit-protobufOverhead) - for _, ids := range idBuckets { - iwant := &pb.ControlIWant{MessageIDs: ids} - out := outRPC(iwant.Size(), true) - out.Control.Iwant = append(out.Control.Iwant, iwant) + for _, ihave := range ctl.GetIhave() { + if len(lastRPC.Control.Ihave) == 0 || + !bytes.Equal(lastRPC.Control.Ihave[len(lastRPC.Control.Ihave)-1].Bitmask, ihave.Bitmask) { + // Start a new IHAVE if we are referencing a new bitmask ID + newIhave := &pb.ControlIHave{Bitmask: ihave.Bitmask} + if lastRPC.Control.Ihave = append(lastRPC.Control.Ihave, newIhave); lastRPC.Size() > limit { + lastRPC.Control.Ihave = lastRPC.Control.Ihave[:len(lastRPC.Control.Ihave)-1] + lastRPC = &RPC{RPC: pb.RPC{Control: &pb.ControlMessage{ + Ihave: []*pb.ControlIHave{newIhave}, + }}, from: elem.from} + out = append(out, lastRPC) + } + } + for _, msgID := range ihave.GetMessageIDs() { + lastIHave := lastRPC.Control.Ihave[len(lastRPC.Control.Ihave)-1] + if lastIHave.MessageIDs = append(lastIHave.MessageIDs, msgID); lastRPC.Size() > limit { + lastIHave.MessageIDs = lastIHave.MessageIDs[:len(lastIHave.MessageIDs)-1] + lastRPC = &RPC{RPC: pb.RPC{Control: &pb.ControlMessage{ + Ihave: []*pb.ControlIHave{{Bitmask: ihave.Bitmask, MessageIDs: []string{msgID}}}, + }}, from: elem.from} + out = append(out, lastRPC) + } + } + } } } - for _, ihave := range ctl.Ihave { - const protobufOverhead = 6 - idBuckets := fragmentMessageIds(ihave.MessageIDs, limit-protobufOverhead) - for _, ids := range idBuckets { - ihave := &pb.ControlIHave{MessageIDs: ids} - out := outRPC(ihave.Size(), true) - out.Control.Ihave = append(out.Control.Ihave, ihave) - } - } - return rpcs, nil -} -func fragmentMessageIds(msgIds []string, limit int) [][]string { - // account for two bytes of protobuf overhead per array element - const protobufOverhead = 2 - - out := [][]string{{}} - var currentBucket int - var bucketLen int - for i := 0; i < len(msgIds); i++ { - size := len(msgIds[i]) + protobufOverhead - if size > limit { - // pathological case where a single message ID exceeds the limit. - log.Warnf("message ID length %d exceeds limit %d, removing from outgoing gossip", size, limit) - continue - } - bucketLen += size - if bucketLen > limit { - out = append(out, []string{}) - currentBucket++ - bucketLen = size - } - out[currentBucket] = append(out[currentBucket], msgIds[i]) - } return out } diff --git a/go-libp2p-blossomsub/comm.go b/go-libp2p-blossomsub/comm.go index fa24ebd..2c36c07 100644 --- a/go-libp2p-blossomsub/comm.go +++ b/go-libp2p-blossomsub/comm.go @@ -76,6 +76,9 @@ func (p *PubSub) handleNewStream(s network.Stream) { return } + if len(msgbytes) == 0 { + continue + } rpc := new(RPC) err = rpc.Unmarshal(msgbytes) diff --git a/go-libp2p-blossomsub/go.mod b/go-libp2p-blossomsub/go.mod index aec4283..45db1c2 100644 --- a/go-libp2p-blossomsub/go.mod +++ b/go-libp2p-blossomsub/go.mod @@ -66,10 +66,7 @@ require ( github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.39.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect - github.com/quic-go/qtls-go1-18 v0.2.0 // indirect - github.com/quic-go/qtls-go1-19 v0.2.0 // indirect - github.com/quic-go/qtls-go1-20 v0.1.0 // indirect - github.com/quic-go/quic-go v0.32.0 // indirect + github.com/quic-go/quic-go v0.37.5 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/stretchr/testify v1.8.1 // indirect diff --git a/go-libp2p-blossomsub/notify.go b/go-libp2p-blossomsub/notify.go index 4d9ef0f..770a54c 100644 --- a/go-libp2p-blossomsub/notify.go +++ b/go-libp2p-blossomsub/notify.go @@ -18,7 +18,7 @@ func (p *PubSubNotif) ClosedStream(n network.Network, s network.Stream) { func (p *PubSubNotif) Connected(n network.Network, c network.Conn) { // ignore transient connections - if c.Stat().Transient { + if c.Stat().Limited { return } @@ -48,7 +48,7 @@ func (p *PubSubNotif) ListenClose(n network.Network, _ ma.Multiaddr) { func (p *PubSubNotif) Initialize() { isTransient := func(pid peer.ID) bool { for _, c := range p.host.Network().ConnsToPeer(pid) { - if !c.Stat().Transient { + if !c.Stat().Limited { return false } } diff --git a/go-libp2p-blossomsub/peer_gater.go b/go-libp2p-blossomsub/peer_gater.go index c4610ad..1922000 100644 --- a/go-libp2p-blossomsub/peer_gater.go +++ b/go-libp2p-blossomsub/peer_gater.go @@ -303,7 +303,7 @@ func (pg *peerGater) getPeerIP(p peer.ID) string { // most streams; it's a nightmare to track multiple IPs per peer, so pick the best one. streams := make(map[string]int) for _, c := range conns { - if c.Stat().Transient { + if c.Stat().Limited { // ignore transient continue } diff --git a/go-libp2p-blossomsub/score.go b/go-libp2p-blossomsub/score.go index 32a66d8..8816bc5 100644 --- a/go-libp2p-blossomsub/score.go +++ b/go-libp2p-blossomsub/score.go @@ -990,7 +990,7 @@ func (ps *peerScore) getIPs(p peer.ID) []string { conns := ps.host.Network().ConnsToPeer(p) res := make([]string, 0, 1) for _, c := range conns { - if c.Stat().Transient { + if c.Stat().Limited { // ignore transient continue } diff --git a/go-libp2p-gostream/go.mod b/go-libp2p-gostream/go.mod index 1961155..b7c96bb 100644 --- a/go-libp2p-gostream/go.mod +++ b/go-libp2p-gostream/go.mod @@ -72,8 +72,7 @@ require ( github.com/prometheus/common v0.44.0 // indirect github.com/prometheus/procfs v0.11.1 // indirect github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/qtls-go1-20 v0.2.3 // indirect - github.com/quic-go/quic-go v0.36.3 // indirect + github.com/quic-go/quic-go v0.37.5 // indirect github.com/quic-go/webtransport-go v0.5.3 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect diff --git a/go-libp2p/.github/ISSUE_TEMPLATE/config.yml b/go-libp2p/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..1ba3fd8 --- /dev/null +++ b/go-libp2p/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: true +contact_links: + - name: Technical Questions + url: https://github.com/libp2p/go-libp2p/discussions/new?category=q-a + about: Please ask technical questions in the go-libp2p Github Discusions forum. + - name: Community-wide libp2p Discussion + url: https://discuss.libp2p.io + about: Discussions and questions about the libp2p community. diff --git a/go-libp2p/.github/workflows/automerge.yml b/go-libp2p/.github/workflows/automerge.yml deleted file mode 100644 index 3833fc2..0000000 --- a/go-libp2p/.github/workflows/automerge.yml +++ /dev/null @@ -1,11 +0,0 @@ -# File managed by web3-bot. DO NOT EDIT. -# See https://github.com/protocol/.github/ for details. - -name: Automerge -on: [ pull_request ] - -jobs: - automerge: - uses: protocol/.github/.github/workflows/automerge.yml@master - with: - job: 'automerge' diff --git a/go-libp2p/.github/workflows/go-check.yml b/go-libp2p/.github/workflows/go-check.yml index cc65ce6..a1cc205 100644 --- a/go-libp2p/.github/workflows/go-check.yml +++ b/go-libp2p/.github/workflows/go-check.yml @@ -1,67 +1,20 @@ -# File managed by web3-bot. DO NOT EDIT. -# See https://github.com/protocol/.github/ for details. - -on: [push, pull_request] name: Go Checks +on: + pull_request: + push: + branches: ["master","release-v0[0-9][0-9]"] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }} + cancel-in-progress: true + jobs: - unit: - runs-on: ubuntu-latest - name: All - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - id: config - uses: protocol/.github/.github/actions/read-config@master - - uses: actions/setup-go@v3 - with: - go-version: 1.20.x - - name: Run repo-specific setup - uses: ./.github/actions/go-check-setup - if: hashFiles('./.github/actions/go-check-setup') != '' - - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@4970552d932f48b71485287748246cf3237cebdf # 2023.1 (v0.4.0) - - name: Check that go.mod is tidy - uses: protocol/multiple-go-modules@v1.2 - with: - run: | - go mod tidy - if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then - echo "go.sum was added by go mod tidy" - exit 1 - fi - git diff --exit-code -- go.sum go.mod - - name: gofmt - if: success() || failure() # run this step even if the previous one failed - run: | - out=$(gofmt -s -l .) - if [[ -n "$out" ]]; then - echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}' - exit 1 - fi - - name: go vet - if: success() || failure() # run this step even if the previous one failed - uses: protocol/multiple-go-modules@v1.2 - with: - run: go vet ./... - - name: staticcheck - if: success() || failure() # run this step even if the previous one failed - uses: protocol/multiple-go-modules@v1.2 - with: - run: | - set -o pipefail - staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g' - - name: go generate - uses: protocol/multiple-go-modules@v1.2 - if: (success() || failure()) && fromJSON(steps.config.outputs.json).gogenerate == true - with: - run: | - git clean -fd # make sure there aren't untracked files / directories - go generate -x ./... - # check if go generate modified or added any files - if ! $(git add . && git diff-index HEAD --exit-code --quiet); then - echo "go generated caused changes to the repository:" - git status --short - exit 1 - fi + go-check: + uses: ipdxco/unified-github-workflows/.github/workflows/go-check.yml@v1.0 + with: + go-generate-ignore-protoc-version-comments: true diff --git a/go-libp2p/.github/workflows/go-test.yml b/go-libp2p/.github/workflows/go-test.yml index c5cb3ef..e33480c 100644 --- a/go-libp2p/.github/workflows/go-test.yml +++ b/go-libp2p/.github/workflows/go-test.yml @@ -1,76 +1,22 @@ -# File managed by web3-bot. DO NOT EDIT. -# See https://github.com/protocol/.github/ for details. - -on: [push, pull_request] name: Go Test +on: + pull_request: + push: + branches: ["master","release-v0[0-9][0-9]"] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }} + cancel-in-progress: true + jobs: - unit: - strategy: - fail-fast: false - matrix: - os: [ "ubuntu", "windows", "macos" ] - go: ["1.19.x","1.20.x"] - env: - COVERAGES: "" - runs-on: ${{ fromJSON(vars[format('UCI_GO_TEST_RUNNER_{0}', matrix.os)] || format('"{0}-latest"', matrix.os)) }} - name: ${{ matrix.os }} (go ${{ matrix.go }}) - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - id: config - uses: protocol/.github/.github/actions/read-config@master - - uses: actions/setup-go@v3 - with: - go-version: ${{ matrix.go }} - - name: Go information - run: | - go version - go env - - name: Use msys2 on windows - if: matrix.os == 'windows' - shell: bash - # The executable for msys2 is also called bash.cmd - # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#shells - # If we prepend its location to the PATH - # subsequent 'shell: bash' steps will use msys2 instead of gitbash - run: echo "C:/msys64/usr/bin" >> $GITHUB_PATH - - name: Run repo-specific setup - uses: ./.github/actions/go-test-setup - if: hashFiles('./.github/actions/go-test-setup') != '' - - name: Run tests - if: contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false - uses: protocol/multiple-go-modules@v1.2 - with: - # Use -coverpkg=./..., so that we include cross-package coverage. - # If package ./A imports ./B, and ./A's tests also cover ./B, - # this means ./B's coverage will be significantly higher than 0%. - run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./... - - name: Run tests (32 bit) - # can't run 32 bit tests on OSX. - if: matrix.os != 'macos' && - fromJSON(steps.config.outputs.json).skip32bit != true && - contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false - uses: protocol/multiple-go-modules@v1.2 - env: - GOARCH: 386 - with: - run: | - export "PATH=$PATH_386:$PATH" - go test -v -shuffle=on ./... - - name: Run tests with race detector - # speed things up. Windows and OSX VMs are slow - if: matrix.os == 'ubuntu' && - contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false - uses: protocol/multiple-go-modules@v1.2 - with: - run: go test -v -race ./... - - name: Collect coverage files - shell: bash - run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV - - name: Upload coverage to Codecov - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 - with: - files: '${{ env.COVERAGES }}' - env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} + go-test: + uses: libp2p/uci/.github/workflows/go-test.yml@v1.0 + with: + go-versions: '["1.21.x", "1.22.x"]' + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/go-libp2p/.github/workflows/interop-test.yml b/go-libp2p/.github/workflows/interop-test.yml index c5f2a5e..f320553 100644 --- a/go-libp2p/.github/workflows/interop-test.yml +++ b/go-libp2p/.github/workflows/interop-test.yml @@ -1,19 +1,32 @@ name: Interoperability Testing on: + workflow_dispatch: pull_request: + paths: + - 'config/**' + - 'core/**' + - 'internal/**' + - 'p2p/**' + - 'test-plans/**' push: branches: - "master" + paths: + - 'config/**' + - 'core/**' + - 'internal/**' + - 'p2p/**' + - 'test-plans/**' jobs: - run-multidim-interop: - name: Run multidimensional interoperability tests + run-transport-interop: + name: Run transport interoperability tests runs-on: ${{ fromJSON(vars['INTEROP_TEST_RUNNER_UBUNTU'] || '"ubuntu-22.04"') }} steps: - uses: actions/checkout@v3 - name: Build image run: docker build -t go-libp2p-head -f test-plans/PingDockerfile . - - uses: libp2p/test-plans/.github/actions/run-interop-ping-test@master + - uses: libp2p/test-plans/.github/actions/run-transport-interop-test@master with: test-filter: go-libp2p-head extra-versions: ${{ github.workspace }}/test-plans/ping-version.json diff --git a/go-libp2p/.github/workflows/release-check.yml b/go-libp2p/.github/workflows/release-check.yml index e2408e3..0b5ff60 100644 --- a/go-libp2p/.github/workflows/release-check.yml +++ b/go-libp2p/.github/workflows/release-check.yml @@ -1,13 +1,19 @@ -# File managed by web3-bot. DO NOT EDIT. -# See https://github.com/protocol/.github/ for details. - name: Release Checker + on: pull_request_target: paths: [ 'version.json' ] + types: [ opened, synchronize, reopened, labeled, unlabeled ] + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: release-check: - uses: protocol/.github/.github/workflows/release-check.yml@master - with: - go-version: 1.20.x + uses: ipdxco/unified-github-workflows/.github/workflows/release-check.yml@v1.0 diff --git a/go-libp2p/.github/workflows/releaser.yml b/go-libp2p/.github/workflows/releaser.yml index cdccbf8..2ebdbed 100644 --- a/go-libp2p/.github/workflows/releaser.yml +++ b/go-libp2p/.github/workflows/releaser.yml @@ -1,11 +1,17 @@ -# File managed by web3-bot. DO NOT EDIT. -# See https://github.com/protocol/.github/ for details. - name: Releaser + on: push: paths: [ 'version.json' ] + workflow_dispatch: + +permissions: + contents: write + +concurrency: + group: ${{ github.workflow }}-${{ github.sha }} + cancel-in-progress: true jobs: releaser: - uses: protocol/.github/.github/workflows/releaser.yml@master + uses: ipdxco/unified-github-workflows/.github/workflows/releaser.yml@v1.0 diff --git a/go-libp2p/.github/workflows/tagpush.yml b/go-libp2p/.github/workflows/tagpush.yml index d849961..5ef3fb9 100644 --- a/go-libp2p/.github/workflows/tagpush.yml +++ b/go-libp2p/.github/workflows/tagpush.yml @@ -1,12 +1,18 @@ -# File managed by web3-bot. DO NOT EDIT. -# See https://github.com/protocol/.github/ for details. - name: Tag Push Checker + on: push: tags: - v* +permissions: + contents: read + issues: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: releaser: - uses: protocol/.github/.github/workflows/tagpush.yml@master + uses: ipdxco/unified-github-workflows/.github/workflows/tagpush.yml@v1.0 diff --git a/go-libp2p/README.md b/go-libp2p/README.md index 155f466..960d89e 100644 --- a/go-libp2p/README.md +++ b/go-libp2p/README.md @@ -1,6 +1,6 @@

- libp2p hex logo + libp2p hex logo

The Go implementation of the libp2p Networking Stack.

@@ -18,6 +18,7 @@ - [Roadmap](#roadmap) - [Usage](#usage) - [Examples](#examples) + - [Dashboards](#dashboards) - [Contribute](#contribute) - [Supported Go Versions](#supported-go-versions) - [Notable Users](#notable-users) @@ -54,6 +55,13 @@ import "github.com/libp2p/go-libp2p" Examples can be found in the [examples folder](examples). +## Dashboards + +We provide prebuilt Grafana dashboards so that applications can better monitor libp2p in production. +You can find the [dashboard JSON files here](https://github.com/libp2p/go-libp2p/tree/master/dashboards). + +We also have live [Public Dashboards](https://github.com/libp2p/go-libp2p/tree/master/dashboards/README.md#public-dashboards) that you can check out to see real time monitoring in action. + # Contribute @@ -75,7 +83,7 @@ There's a few things you can do right now to help out: ## Supported Go Versions We test against and support the two most recent major releases of Go. This is -informed by Go's own [security policy](https://go.dev/security). +informed by Go's own [security policy](https://go.dev/doc/security/policy). # Notable Users Some notable users of go-libp2p are: diff --git a/go-libp2p/config/config.go b/go-libp2p/config/config.go index cea8ef1..cc689ba 100644 --- a/go-libp2p/config/config.go +++ b/go-libp2p/config/config.go @@ -1,6 +1,7 @@ package config import ( + "context" "crypto/rand" "errors" "fmt" @@ -23,7 +24,6 @@ import ( "github.com/libp2p/go-libp2p/p2p/host/autonat" "github.com/libp2p/go-libp2p/p2p/host/autorelay" bhost "github.com/libp2p/go-libp2p/p2p/host/basic" - blankhost "github.com/libp2p/go-libp2p/p2p/host/blank" "github.com/libp2p/go-libp2p/p2p/host/eventbus" "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem" rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" @@ -38,6 +38,7 @@ import ( ma "github.com/multiformats/go-multiaddr" madns "github.com/multiformats/go-multiaddr-dns" + "github.com/quic-go/quic-go" "go.uber.org/fx" "go.uber.org/fx/fxevent" ) @@ -128,6 +129,8 @@ type Config struct { DialRanker network.DialRanker SwarmOpts []swarm.Option + + DisableIdentifyAddressDiscovery bool } func (cfg *Config) makeSwarm(eventBus event.Bus, enableMetrics bool) (*swarm.Swarm, error) { @@ -190,20 +193,11 @@ func (cfg *Config) makeSwarm(eventBus event.Bus, enableMetrics bool) (*swarm.Swa return swarm.NewSwarm(pid, cfg.Peerstore, eventBus, opts...) } -func (cfg *Config) addTransports(h host.Host) error { - swrm, ok := h.Network().(transport.TransportNetwork) - if !ok { - // Should probably skip this if no transports. - return fmt.Errorf("swarm does not support transports") - } - +func (cfg *Config) addTransports() ([]fx.Option, error) { fxopts := []fx.Option{ fx.WithLogger(func() fxevent.Logger { return getFXLogger() }), fx.Provide(fx.Annotate(tptu.New, fx.ParamTags(`name:"security"`))), fx.Supply(cfg.Muxers), - fx.Supply(h.ID()), - fx.Provide(func() host.Host { return h }), - fx.Provide(func() crypto.PrivKey { return h.Peerstore().PrivKey(h.ID()) }), fx.Provide(func() connmgr.ConnectionGater { return cfg.ConnectionGater }), fx.Provide(func() pnet.PSK { return cfg.PSK }), fx.Provide(func() network.ResourceManager { return cfg.ResourceManager }), @@ -261,15 +255,25 @@ func (cfg *Config) addTransports(h host.Host) error { } fxopts = append(fxopts, fx.Provide(PrivKeyToStatelessResetKey)) + fxopts = append(fxopts, fx.Provide(PrivKeyToTokenGeneratorKey)) if cfg.QUICReuse != nil { fxopts = append(fxopts, cfg.QUICReuse...) } else { - fxopts = append(fxopts, fx.Provide(quicreuse.NewConnManager)) // TODO: close the ConnManager when shutting down the node + fxopts = append(fxopts, + fx.Provide(func(key quic.StatelessResetKey, tokenGenerator quic.TokenGeneratorKey, _ *swarm.Swarm, lifecycle fx.Lifecycle) (*quicreuse.ConnManager, error) { + cm, err := quicreuse.NewConnManager(key, tokenGenerator) + if err != nil { + return nil, err + } + lifecycle.Append(fx.StopHook(cm.Close)) + return cm, nil + }), + ) } fxopts = append(fxopts, fx.Invoke( fx.Annotate( - func(tpts []transport.Transport) error { + func(swrm *swarm.Swarm, tpts []transport.Transport) error { for _, t := range tpts { if err := swrm.AddTransport(t); err != nil { return err @@ -277,54 +281,35 @@ func (cfg *Config) addTransports(h host.Host) error { } return nil }, - fx.ParamTags(`group:"transport"`), + fx.ParamTags("", `group:"transport"`), )), ) if cfg.Relay { fxopts = append(fxopts, fx.Invoke(circuitv2.AddTransport)) } - app := fx.New(fxopts...) - if err := app.Err(); err != nil { - h.Close() - return err - } - return nil + return fxopts, nil } -// NewNode constructs a new libp2p Host from the Config. -// -// This function consumes the config. Do not reuse it (really!). -func (cfg *Config) NewNode() (host.Host, error) { - eventBus := eventbus.NewBus(eventbus.WithMetricsTracer(eventbus.NewMetricsTracer(eventbus.WithRegisterer(cfg.PrometheusRegisterer)))) - swrm, err := cfg.makeSwarm(eventBus, !cfg.DisableMetrics) - if err != nil { - return nil, err - } - - if !cfg.DisableMetrics { - rcmgr.MustRegisterWith(cfg.PrometheusRegisterer) - } - +func (cfg *Config) newBasicHost(swrm *swarm.Swarm, eventBus event.Bus) (*bhost.BasicHost, error) { h, err := bhost.NewHost(swrm, &bhost.HostOpts{ - EventBus: eventBus, - ConnManager: cfg.ConnManager, - AddrsFactory: cfg.AddrsFactory, - NATManager: cfg.NATManager, - EnablePing: !cfg.DisablePing, - UserAgent: cfg.UserAgent, - ProtocolVersion: cfg.ProtocolVersion, - EnableHolePunching: cfg.EnableHolePunching, - HolePunchingOptions: cfg.HolePunchingOptions, - EnableRelayService: cfg.EnableRelayService, - RelayServiceOpts: cfg.RelayServiceOpts, - EnableMetrics: !cfg.DisableMetrics, - PrometheusRegisterer: cfg.PrometheusRegisterer, + EventBus: eventBus, + ConnManager: cfg.ConnManager, + AddrsFactory: cfg.AddrsFactory, + NATManager: cfg.NATManager, + EnablePing: !cfg.DisablePing, + UserAgent: cfg.UserAgent, + ProtocolVersion: cfg.ProtocolVersion, + EnableHolePunching: cfg.EnableHolePunching, + HolePunchingOptions: cfg.HolePunchingOptions, + EnableRelayService: cfg.EnableRelayService, + RelayServiceOpts: cfg.RelayServiceOpts, + EnableMetrics: !cfg.DisableMetrics, + PrometheusRegisterer: cfg.PrometheusRegisterer, + DisableIdentifyAddressDiscovery: cfg.DisableIdentifyAddressDiscovery, }) if err != nil { - swrm.Close() return nil, err } - if cfg.Relay { // If we've enabled the relay, we should filter out relay // addresses by default. @@ -335,60 +320,144 @@ func (cfg *Config) NewNode() (host.Host, error) { return oldFactory(autorelay.Filter(addrs)) } } + return h, nil +} - if err := cfg.addTransports(h); err != nil { - h.Close() - return nil, err +// NewNode constructs a new libp2p Host from the Config. +// +// This function consumes the config. Do not reuse it (really!). +func (cfg *Config) NewNode() (host.Host, error) { + if cfg.EnableAutoRelay && !cfg.Relay { + return nil, fmt.Errorf("cannot enable autorelay; relay is not enabled") + } + // If possible check that the resource manager conn limit is higher than the + // limit set in the conn manager. + if l, ok := cfg.ResourceManager.(connmgr.GetConnLimiter); ok { + err := cfg.ConnManager.CheckLimit(l) + if err != nil { + log.Warn(fmt.Sprintf("rcmgr limit conflicts with connmgr limit: %v", err)) + } } - // TODO: This method succeeds if listening on one address succeeds. We - // should probably fail if listening on *any* addr fails. - if err := h.Network().Listen(cfg.ListenAddrs...); err != nil { - h.Close() + if !cfg.DisableMetrics { + rcmgr.MustRegisterWith(cfg.PrometheusRegisterer) + } + + fxopts := []fx.Option{ + fx.Provide(func() event.Bus { + return eventbus.NewBus(eventbus.WithMetricsTracer(eventbus.NewMetricsTracer(eventbus.WithRegisterer(cfg.PrometheusRegisterer)))) + }), + fx.Provide(func(eventBus event.Bus, lifecycle fx.Lifecycle) (*swarm.Swarm, error) { + sw, err := cfg.makeSwarm(eventBus, !cfg.DisableMetrics) + if err != nil { + return nil, err + } + lifecycle.Append(fx.StopHook(sw.Close)) + return sw, nil + }), + // Make sure the swarm constructor depends on the quicreuse.ConnManager. + // That way, the ConnManager will be started before the swarm, and more importantly, + // the swarm will be stopped before the ConnManager. + fx.Decorate(func(sw *swarm.Swarm, _ *quicreuse.ConnManager, lifecycle fx.Lifecycle) *swarm.Swarm { + lifecycle.Append(fx.Hook{ + OnStart: func(context.Context) error { + // TODO: This method succeeds if listening on one address succeeds. We + // should probably fail if listening on *any* addr fails. + return sw.Listen(cfg.ListenAddrs...) + }, + OnStop: func(context.Context) error { + return sw.Close() + }, + }) + return sw + }), + fx.Provide(cfg.newBasicHost), + fx.Provide(func(bh *bhost.BasicHost) host.Host { + return bh + }), + fx.Provide(func(h *swarm.Swarm) peer.ID { return h.LocalPeer() }), + fx.Provide(func(h *swarm.Swarm) crypto.PrivKey { return h.Peerstore().PrivKey(h.LocalPeer()) }), + } + transportOpts, err := cfg.addTransports() + if err != nil { return nil, err } + fxopts = append(fxopts, transportOpts...) // Configure routing and autorelay - var router routing.PeerRouting if cfg.Routing != nil { - router, err = cfg.Routing(h) - if err != nil { - h.Close() - return nil, err - } + fxopts = append(fxopts, + fx.Provide(cfg.Routing), + fx.Provide(func(h host.Host, router routing.PeerRouting) *routed.RoutedHost { + return routed.Wrap(h, router) + }), + ) } // Note: h.AddrsFactory may be changed by relayFinder, but non-relay version is // used by AutoNAT below. - var ar *autorelay.AutoRelay - addrF := h.AddrsFactory if cfg.EnableAutoRelay { - if !cfg.Relay { - h.Close() - return nil, fmt.Errorf("cannot enable autorelay; relay is not enabled") - } if !cfg.DisableMetrics { mt := autorelay.WithMetricsTracer( autorelay.NewMetricsTracer(autorelay.WithRegisterer(cfg.PrometheusRegisterer))) mtOpts := []autorelay.Option{mt} cfg.AutoRelayOpts = append(mtOpts, cfg.AutoRelayOpts...) } - - ar, err = autorelay.NewAutoRelay(h, cfg.AutoRelayOpts...) - if err != nil { - return nil, err - } + fxopts = append(fxopts, + fx.Invoke(func(h *bhost.BasicHost, lifecycle fx.Lifecycle) (*autorelay.AutoRelay, error) { + ar, err := autorelay.NewAutoRelay(h, cfg.AutoRelayOpts...) + if err != nil { + return nil, err + } + lifecycle.Append(fx.StartStopHook(ar.Start, ar.Close)) + return ar, nil + }), + ) } + var bh *bhost.BasicHost + fxopts = append(fxopts, fx.Invoke(func(bho *bhost.BasicHost) { bh = bho })) + fxopts = append(fxopts, fx.Invoke(func(h *bhost.BasicHost, lifecycle fx.Lifecycle) { + lifecycle.Append(fx.StartHook(h.Start)) + })) + + var rh *routed.RoutedHost + if cfg.Routing != nil { + fxopts = append(fxopts, fx.Invoke(func(bho *routed.RoutedHost) { rh = bho })) + } + + app := fx.New(fxopts...) + if err := app.Start(context.Background()); err != nil { + return nil, err + } + + if err := cfg.addAutoNAT(bh); err != nil { + app.Stop(context.Background()) + if cfg.Routing != nil { + rh.Close() + } else { + bh.Close() + } + return nil, err + } + + if cfg.Routing != nil { + return &closableRoutedHost{App: app, RoutedHost: rh}, nil + } + return &closableBasicHost{App: app, BasicHost: bh}, nil +} + +func (cfg *Config) addAutoNAT(h *bhost.BasicHost) error { + addrF := h.AddrsFactory autonatOpts := []autonat.Option{ autonat.UsingAddresses(func() []ma.Multiaddr { return addrF(h.AllAddrs()) }), } if !cfg.DisableMetrics { - autonatOpts = append(autonatOpts, - autonat.WithMetricsTracer( - autonat.NewMetricsTracer(autonat.WithRegisterer(cfg.PrometheusRegisterer)))) + autonatOpts = append(autonatOpts, autonat.WithMetricsTracer( + autonat.NewMetricsTracer(autonat.WithRegisterer(cfg.PrometheusRegisterer)), + )) } if cfg.AutoNATConfig.ThrottleInterval != 0 { autonatOpts = append(autonatOpts, @@ -398,16 +467,15 @@ func (cfg *Config) NewNode() (host.Host, error) { if cfg.AutoNATConfig.EnableService { autonatPrivKey, _, err := crypto.GenerateEd25519Key(rand.Reader) if err != nil { - return nil, err + return err } ps, err := pstoremem.NewPeerstore() if err != nil { - return nil, err + return err } // Pull out the pieces of the config that we _actually_ care about. - // Specifically, don't set up things like autorelay, listeners, - // identify, etc. + // Specifically, don't set up things like listeners, identify, etc. autoNatCfg := Config{ Transports: cfg.Transports, Muxers: cfg.Muxers, @@ -419,23 +487,47 @@ func (cfg *Config) NewNode() (host.Host, error) { PeerKey: autonatPrivKey, Peerstore: ps, DialRanker: swarm.NoDelayDialRanker, + SwarmOpts: []swarm.Option{ + // It is better to disable black hole detection and just attempt a dial for autonat + swarm.WithUDPBlackHoleConfig(false, 0, 0), + swarm.WithIPv6BlackHoleConfig(false, 0, 0), + }, } - dialer, err := autoNatCfg.makeSwarm(eventbus.NewBus(), false) + fxopts, err := autoNatCfg.addTransports() if err != nil { - h.Close() - return nil, err + return err } - dialerHost := blankhost.NewBlankHost(dialer) - if err := autoNatCfg.addTransports(dialerHost); err != nil { - dialerHost.Close() - h.Close() - return nil, err + var dialer *swarm.Swarm + + fxopts = append(fxopts, + fx.Provide(eventbus.NewBus), + fx.Provide(func(lifecycle fx.Lifecycle, b event.Bus) (*swarm.Swarm, error) { + lifecycle.Append(fx.Hook{ + OnStop: func(context.Context) error { + return ps.Close() + }}) + var err error + dialer, err = autoNatCfg.makeSwarm(b, false) + return dialer, err + + }), + fx.Provide(func(s *swarm.Swarm) peer.ID { return s.LocalPeer() }), + fx.Provide(func() crypto.PrivKey { return autonatPrivKey }), + ) + app := fx.New(fxopts...) + if err := app.Err(); err != nil { + return err } - // NOTE: We're dropping the blank host here but that's fine. It - // doesn't really _do_ anything and doesn't even need to be - // closed (as long as we close the underlying network). - autonatOpts = append(autonatOpts, autonat.EnableService(dialerHost.Network())) + err = app.Start(context.Background()) + if err != nil { + return err + } + go func() { + <-dialer.Done() // The swarm used for autonat has closed, we can cleanup now + app.Stop(context.Background()) + }() + autonatOpts = append(autonatOpts, autonat.EnableService(dialer)) } if cfg.AutoNATConfig.ForceReachability != nil { autonatOpts = append(autonatOpts, autonat.WithReachability(*cfg.AutoNATConfig.ForceReachability)) @@ -443,25 +535,10 @@ func (cfg *Config) NewNode() (host.Host, error) { autonat, err := autonat.New(h, autonatOpts...) if err != nil { - h.Close() - return nil, fmt.Errorf("cannot enable autorelay; autonat failed to start: %v", err) + return fmt.Errorf("cannot enable autorelay; autonat failed to start: %v", err) } h.SetAutoNat(autonat) - - // start the host background tasks - h.Start() - - var ho host.Host - ho = h - if router != nil { - ho = routed.Wrap(h, router) - } - if ar != nil { - arh := autorelay.NewAutoRelayHost(ho, ar) - arh.Start() - ho = arh - } - return ho, nil + return nil } // Option is a libp2p config option that can be given to the libp2p constructor diff --git a/go-libp2p/config/host.go b/go-libp2p/config/host.go new file mode 100644 index 0000000..ac61df2 --- /dev/null +++ b/go-libp2p/config/host.go @@ -0,0 +1,30 @@ +package config + +import ( + "context" + + basichost "github.com/libp2p/go-libp2p/p2p/host/basic" + routed "github.com/libp2p/go-libp2p/p2p/host/routed" + + "go.uber.org/fx" +) + +type closableBasicHost struct { + *fx.App + *basichost.BasicHost +} + +func (h *closableBasicHost) Close() error { + _ = h.App.Stop(context.Background()) + return h.BasicHost.Close() +} + +type closableRoutedHost struct { + *fx.App + *routed.RoutedHost +} + +func (h *closableRoutedHost) Close() error { + _ = h.App.Stop(context.Background()) + return h.RoutedHost.Close() +} diff --git a/go-libp2p/config/quic_stateless_reset.go b/go-libp2p/config/quic.go similarity index 53% rename from go-libp2p/config/quic_stateless_reset.go rename to go-libp2p/config/quic.go index a12be56..66c40da 100644 --- a/go-libp2p/config/quic_stateless_reset.go +++ b/go-libp2p/config/quic.go @@ -11,7 +11,10 @@ import ( "github.com/quic-go/quic-go" ) -const statelessResetKeyInfo = "libp2p quic stateless reset key" +const ( + statelessResetKeyInfo = "libp2p quic stateless reset key" + tokenGeneratorKeyInfo = "libp2p quic token generator key" +) func PrivKeyToStatelessResetKey(key crypto.PrivKey) (quic.StatelessResetKey, error) { var statelessResetKey quic.StatelessResetKey @@ -25,3 +28,16 @@ func PrivKeyToStatelessResetKey(key crypto.PrivKey) (quic.StatelessResetKey, err } return statelessResetKey, nil } + +func PrivKeyToTokenGeneratorKey(key crypto.PrivKey) (quic.TokenGeneratorKey, error) { + var tokenKey quic.TokenGeneratorKey + keyBytes, err := key.Raw() + if err != nil { + return tokenKey, err + } + keyReader := hkdf.New(sha256.New, keyBytes, nil, []byte(tokenGeneratorKeyInfo)) + if _, err := io.ReadFull(keyReader, tokenKey[:]); err != nil { + return tokenKey, err + } + return tokenKey, nil +} diff --git a/go-libp2p/core/connmgr/manager.go b/go-libp2p/core/connmgr/manager.go index e0d6c52..d756e43 100644 --- a/go-libp2p/core/connmgr/manager.go +++ b/go-libp2p/core/connmgr/manager.go @@ -74,6 +74,10 @@ type ConnManager interface { // then it will return true if the peer is protected for any tag IsProtected(id peer.ID, tag string) (protected bool) + // CheckLimit will return an error if the connection manager's internal + // connection limit exceeds the provided system limit. + CheckLimit(l GetConnLimiter) error + // Close closes the connection manager and stops background processes. Close() error } @@ -89,3 +93,9 @@ type TagInfo struct { // Conns maps connection ids (such as remote multiaddr) to their creation time. Conns map[string]time.Time } + +// GetConnLimiter provides access to a component's total connection limit. +type GetConnLimiter interface { + // GetConnLimit returns the total connection limit of the implementing component. + GetConnLimit() int +} diff --git a/go-libp2p/core/connmgr/null.go b/go-libp2p/core/connmgr/null.go index 25743f4..7354117 100644 --- a/go-libp2p/core/connmgr/null.go +++ b/go-libp2p/core/connmgr/null.go @@ -21,4 +21,5 @@ func (NullConnMgr) Notifee() network.Notifiee { return network.Gl func (NullConnMgr) Protect(peer.ID, string) {} func (NullConnMgr) Unprotect(peer.ID, string) bool { return false } func (NullConnMgr) IsProtected(peer.ID, string) bool { return false } +func (NullConnMgr) CheckLimit(l GetConnLimiter) error { return nil } func (NullConnMgr) Close() error { return nil } diff --git a/go-libp2p/core/crypto/ecdsa.go b/go-libp2p/core/crypto/ecdsa.go index c936d50..c890afe 100644 --- a/go-libp2p/core/crypto/ecdsa.go +++ b/go-libp2p/core/crypto/ecdsa.go @@ -4,6 +4,7 @@ import ( "crypto/ecdsa" "crypto/elliptic" "crypto/rand" + "crypto/sha256" "crypto/x509" "encoding/asn1" "errors" @@ -12,8 +13,6 @@ import ( pb "github.com/libp2p/go-libp2p/core/crypto/pb" "github.com/libp2p/go-libp2p/core/internal/catch" - - "github.com/minio/sha256-simd" ) // ECDSAPrivateKey is an implementation of an ECDSA private key diff --git a/go-libp2p/core/crypto/ecdsa_test.go b/go-libp2p/core/crypto/ecdsa_test.go index cc75d57..6e4720d 100644 --- a/go-libp2p/core/crypto/ecdsa_test.go +++ b/go-libp2p/core/crypto/ecdsa_test.go @@ -25,7 +25,7 @@ func TestECDSABasicSignAndVerify(t *testing.T) { } if !ok { - t.Fatal("signature didnt match") + t.Fatal("signature didn't match") } // change data diff --git a/go-libp2p/core/crypto/key.go b/go-libp2p/core/crypto/key.go index 2c25be2..036c1e7 100644 --- a/go-libp2p/core/crypto/key.go +++ b/go-libp2p/core/crypto/key.go @@ -4,12 +4,10 @@ package crypto import ( - "crypto/elliptic" "crypto/rand" "crypto/subtle" "encoding/base64" "errors" - "fmt" "io" "github.com/libp2p/go-libp2p/core/crypto/pb" @@ -129,51 +127,6 @@ func GenerateKeyPairWithReader(typ, bits int, src io.Reader) (PrivKey, PubKey, e } } -// GenerateEKeyPair returns an ephemeral public key and returns a function that will compute -// the shared secret key. Used in the identify module. -// -// Focuses only on ECDH now, but can be made more general in the future. -func GenerateEKeyPair(curveName string) ([]byte, GenSharedKey, error) { - var curve elliptic.Curve - - switch curveName { - case "P-256": - curve = elliptic.P256() - case "P-384": - curve = elliptic.P384() - case "P-521": - curve = elliptic.P521() - default: - return nil, nil, fmt.Errorf("unknown curve name") - } - - priv, x, y, err := elliptic.GenerateKey(curve, rand.Reader) - if err != nil { - return nil, nil, err - } - - pubKey := elliptic.Marshal(curve, x, y) - - done := func(theirPub []byte) ([]byte, error) { - // Verify and unpack node's public key. - x, y := elliptic.Unmarshal(curve, theirPub) - if x == nil { - return nil, fmt.Errorf("malformed public key: %d %v", len(theirPub), theirPub) - } - - if !curve.IsOnCurve(x, y) { - return nil, errors.New("invalid public key") - } - - // Generate shared secret. - secret, _ := curve.ScalarMult(x, y, priv) - - return secret.Bytes(), nil - } - - return pubKey, done, nil -} - // UnmarshalPublicKey converts a protobuf serialized public key into its // representative object func UnmarshalPublicKey(data []byte) (PubKey, error) { diff --git a/go-libp2p/core/crypto/key_test.go b/go-libp2p/core/crypto/key_test.go index 2db4453..e9a3b0a 100644 --- a/go-libp2p/core/crypto/key_test.go +++ b/go-libp2p/core/crypto/key_test.go @@ -8,19 +8,19 @@ import ( "crypto/elliptic" "crypto/rand" "crypto/rsa" + "crypto/sha256" "crypto/x509" "fmt" "reflect" "testing" - "github.com/cloudflare/circl/sign/ed448" . "github.com/libp2p/go-libp2p/core/crypto" pb "github.com/libp2p/go-libp2p/core/crypto/pb" "github.com/libp2p/go-libp2p/core/test" + "github.com/cloudflare/circl/sign/ed448" "github.com/decred/dcrd/dcrec/secp256k1/v4" secp256k1ecdsa "github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa" - "github.com/minio/sha256-simd" ) func TestKeys(t *testing.T) { @@ -307,15 +307,3 @@ func testKeyEquals(t *testing.T, k Key) { t.Fatal("Keys should not equal.") } } - -func TestUnknownCurveErrors(t *testing.T) { - _, _, err := GenerateEKeyPair("P-256") - if err != nil { - t.Fatal(err) - } - - _, _, err = GenerateEKeyPair("error-please") - if err == nil { - t.Fatal("expected invalid key type to error") - } -} diff --git a/go-libp2p/core/crypto/key_to_stdlib.go b/go-libp2p/core/crypto/key_to_stdlib.go index 8d5d8c0..219cb55 100644 --- a/go-libp2p/core/crypto/key_to_stdlib.go +++ b/go-libp2p/core/crypto/key_to_stdlib.go @@ -28,16 +28,16 @@ func KeyPairFromStdKey(priv crypto.PrivateKey) (PrivKey, PubKey, error) { pub, _ := pubIfc.(ed25519.PublicKey) return &Ed25519PrivateKey{*p}, &Ed25519PublicKey{pub}, nil - case *secp256k1.PrivateKey: - sPriv := Secp256k1PrivateKey(*p) - sPub := Secp256k1PublicKey(*p.PubKey()) - return &sPriv, &sPub, nil - case *ed448.PrivateKey: pubIfc := p.Public() pub, _ := pubIfc.(ed448.PublicKey) return &Ed448PrivateKey{*p}, &Ed448PublicKey{pub}, nil + case *secp256k1.PrivateKey: + sPriv := Secp256k1PrivateKey(*p) + sPub := Secp256k1PublicKey(*p.PubKey()) + return &sPriv, &sPub, nil + default: return nil, nil, ErrBadKeyType } @@ -56,10 +56,10 @@ func PrivKeyToStdKey(priv PrivKey) (crypto.PrivateKey, error) { return p.priv, nil case *Ed25519PrivateKey: return &p.k, nil - case *Secp256k1PrivateKey: - return p, nil case *Ed448PrivateKey: return &p.k, nil + case *Secp256k1PrivateKey: + return p, nil default: return nil, ErrBadKeyType } @@ -78,10 +78,10 @@ func PubKeyToStdKey(pub PubKey) (crypto.PublicKey, error) { return p.pub, nil case *Ed25519PublicKey: return p.k, nil - case *Secp256k1PublicKey: - return p, nil case *Ed448PublicKey: return p.k, nil + case *Secp256k1PublicKey: + return p, nil default: return nil, ErrBadKeyType } diff --git a/go-libp2p/core/crypto/pb/crypto.pb.go b/go-libp2p/core/crypto/pb/crypto.pb.go index eb88361..903daf4 100644 --- a/go-libp2p/core/crypto/pb/crypto.pb.go +++ b/go-libp2p/core/crypto/pb/crypto.pb.go @@ -37,7 +37,6 @@ var ( 1: "Ed25519", 2: "Secp256k1", 3: "ECDSA", - 4: "Ed448", } KeyType_value = map[string]int32{ "RSA": 0, diff --git a/go-libp2p/core/crypto/rsa_go.go b/go-libp2p/core/crypto/rsa_go.go index 8981ba6..845dae9 100644 --- a/go-libp2p/core/crypto/rsa_go.go +++ b/go-libp2p/core/crypto/rsa_go.go @@ -4,14 +4,13 @@ import ( "crypto" "crypto/rand" "crypto/rsa" + "crypto/sha256" "crypto/x509" "errors" "io" pb "github.com/libp2p/go-libp2p/core/crypto/pb" "github.com/libp2p/go-libp2p/core/internal/catch" - - "github.com/minio/sha256-simd" ) // RsaPrivateKey is a rsa private key diff --git a/go-libp2p/core/crypto/rsa_test.go b/go-libp2p/core/crypto/rsa_test.go index f4a7971..dbc88dd 100644 --- a/go-libp2p/core/crypto/rsa_test.go +++ b/go-libp2p/core/crypto/rsa_test.go @@ -24,7 +24,7 @@ func TestRSABasicSignAndVerify(t *testing.T) { } if !ok { - t.Fatal("signature didnt match") + t.Fatal("signature didn't match") } // change data diff --git a/go-libp2p/core/crypto/secp256k1.go b/go-libp2p/core/crypto/secp256k1.go index 27544a5..99e7464 100644 --- a/go-libp2p/core/crypto/secp256k1.go +++ b/go-libp2p/core/crypto/secp256k1.go @@ -1,6 +1,7 @@ package crypto import ( + "crypto/sha256" "fmt" "io" @@ -9,7 +10,6 @@ import ( "github.com/decred/dcrd/dcrec/secp256k1/v4" "github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa" - "github.com/minio/sha256-simd" ) // Secp256k1PrivateKey is a Secp256k1 private key diff --git a/go-libp2p/core/crypto/secp256k1_test.go b/go-libp2p/core/crypto/secp256k1_test.go index 81f2f57..67bbe47 100644 --- a/go-libp2p/core/crypto/secp256k1_test.go +++ b/go-libp2p/core/crypto/secp256k1_test.go @@ -24,7 +24,7 @@ func TestSecp256k1BasicSignAndVerify(t *testing.T) { } if !ok { - t.Fatal("signature didnt match") + t.Fatal("signature didn't match") } // change data diff --git a/go-libp2p/core/event/identify.go b/go-libp2p/core/event/identify.go index ff14995..888572a 100644 --- a/go-libp2p/core/event/identify.go +++ b/go-libp2p/core/event/identify.go @@ -1,11 +1,40 @@ package event -import "github.com/libp2p/go-libp2p/core/peer" +import ( + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/protocol" + "github.com/libp2p/go-libp2p/core/record" + "github.com/multiformats/go-multiaddr" +) // EvtPeerIdentificationCompleted is emitted when the initial identification round for a peer is completed. type EvtPeerIdentificationCompleted struct { // Peer is the ID of the peer whose identification succeeded. Peer peer.ID + + // Conn is the connection we identified. + Conn network.Conn + + // ListenAddrs is the list of addresses the peer is listening on. + ListenAddrs []multiaddr.Multiaddr + + // Protocols is the list of protocols the peer advertised on this connection. + Protocols []protocol.ID + + // SignedPeerRecord is the provided signed peer record of the peer. May be nil. + SignedPeerRecord *record.Envelope + + // AgentVersion is like a UserAgent string in browsers, or client version in + // bittorrent includes the client name and client. + AgentVersion string + + // ProtocolVersion is the protocolVersion field in the identify message + ProtocolVersion string + + // ObservedAddr is the our side's connection address as observed by the + // peer. This is not verified, the peer could return anything here. + ObservedAddr multiaddr.Multiaddr } // EvtPeerIdentificationFailed is emitted when the initial identification round for a peer failed. diff --git a/go-libp2p/core/network/context.go b/go-libp2p/core/network/context.go index 7fabfb5..75db775 100644 --- a/go-libp2p/core/network/context.go +++ b/go-libp2p/core/network/context.go @@ -13,12 +13,12 @@ var DialPeerTimeout = 60 * time.Second type noDialCtxKey struct{} type dialPeerTimeoutCtxKey struct{} type forceDirectDialCtxKey struct{} -type useTransientCtxKey struct{} +type allowLimitedConnCtxKey struct{} type simConnectCtxKey struct{ isClient bool } var noDial = noDialCtxKey{} var forceDirectDial = forceDirectDialCtxKey{} -var useTransient = useTransientCtxKey{} +var allowLimitedConn = allowLimitedConnCtxKey{} var simConnectIsServer = simConnectCtxKey{} var simConnectIsClient = simConnectCtxKey{isClient: true} @@ -94,15 +94,35 @@ func WithDialPeerTimeout(ctx context.Context, timeout time.Duration) context.Con return context.WithValue(ctx, dialPeerTimeoutCtxKey{}, timeout) } -// WithUseTransient constructs a new context with an option that instructs the network -// that it is acceptable to use a transient connection when opening a new stream. -func WithUseTransient(ctx context.Context, reason string) context.Context { - return context.WithValue(ctx, useTransient, reason) +// WithAllowLimitedConn constructs a new context with an option that instructs +// the network that it is acceptable to use a limited connection when opening a +// new stream. +func WithAllowLimitedConn(ctx context.Context, reason string) context.Context { + return context.WithValue(ctx, allowLimitedConn, reason) } -// GetUseTransient returns true if the use transient option is set in the context. -func GetUseTransient(ctx context.Context) (usetransient bool, reason string) { - v := ctx.Value(useTransient) +// WithUseTransient constructs a new context with an option that instructs the network +// that it is acceptable to use a transient connection when opening a new stream. +// +// Deprecated: Use WithAllowLimitedConn instead. +func WithUseTransient(ctx context.Context, reason string) context.Context { + return context.WithValue(ctx, allowLimitedConn, reason) +} + +// GetAllowLimitedConn returns true if the allow limited conn option is set in the context. +func GetAllowLimitedConn(ctx context.Context) (usetransient bool, reason string) { + v := ctx.Value(allowLimitedConn) + if v != nil { + return true, v.(string) + } + return false, "" +} + +// GetUseTransient returns true if the use transient option is set in the context. +// +// Deprecated: Use GetAllowLimitedConn instead. +func GetUseTransient(ctx context.Context) (usetransient bool, reason string) { + v := ctx.Value(allowLimitedConn) if v != nil { return true, v.(string) } diff --git a/go-libp2p/core/network/context_test.go b/go-libp2p/core/network/context_test.go index b12def5..65a8654 100644 --- a/go-libp2p/core/network/context_test.go +++ b/go-libp2p/core/network/context_test.go @@ -47,13 +47,13 @@ func TestSimultaneousConnect(t *testing.T) { ok, isClient, reason := GetSimultaneousConnect(serverCtx) require.True(t, ok) require.False(t, isClient) - require.Equal(t, reason, "foobar") + require.Equal(t, "foobar", reason) }) t.Run("for the client", func(t *testing.T) { serverCtx := WithSimultaneousConnect(context.Background(), true, "foo") ok, isClient, reason := GetSimultaneousConnect(serverCtx) require.True(t, ok) require.True(t, isClient) - require.Equal(t, reason, "foo") + require.Equal(t, "foo", reason) }) } diff --git a/go-libp2p/core/network/errors.go b/go-libp2p/core/network/errors.go index 03bb90c..0f98cd5 100644 --- a/go-libp2p/core/network/errors.go +++ b/go-libp2p/core/network/errors.go @@ -22,7 +22,13 @@ var ErrNoConn = errors.New("no usable connection to peer") // ErrTransientConn is returned when attempting to open a stream to a peer with only a transient // connection, without specifying the UseTransient option. -var ErrTransientConn = errors.New("transient connection to peer") +// +// Deprecated: Use ErrLimitedConn instead. +var ErrTransientConn = ErrLimitedConn + +// ErrLimitedConn is returned when attempting to open a stream to a peer with only a conn +// connection, without specifying the AllowLimitedConn option. +var ErrLimitedConn = errors.New("limited connection to peer") // ErrResourceLimitExceeded is returned when attempting to perform an operation that would // exceed system resource limits. diff --git a/go-libp2p/core/network/mocks/mock_conn_management_scope.go b/go-libp2p/core/network/mocks/mock_conn_management_scope.go index 5d847f9..d6538e1 100644 --- a/go-libp2p/core/network/mocks/mock_conn_management_scope.go +++ b/go-libp2p/core/network/mocks/mock_conn_management_scope.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/libp2p/go-libp2p/core/network (interfaces: ConnManagementScope) +// +// Generated by this command: +// +// mockgen -package mocknetwork -destination mock_conn_management_scope.go github.com/libp2p/go-libp2p/core/network ConnManagementScope +// // Package mocknetwork is a generated GoMock package. package mocknetwork @@ -7,9 +12,9 @@ package mocknetwork import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" network "github.com/libp2p/go-libp2p/core/network" peer "github.com/libp2p/go-libp2p/core/peer" + gomock "go.uber.org/mock/gomock" ) // MockConnManagementScope is a mock of ConnManagementScope interface. @@ -83,7 +88,7 @@ func (m *MockConnManagementScope) ReleaseMemory(arg0 int) { } // ReleaseMemory indicates an expected call of ReleaseMemory. -func (mr *MockConnManagementScopeMockRecorder) ReleaseMemory(arg0 interface{}) *gomock.Call { +func (mr *MockConnManagementScopeMockRecorder) ReleaseMemory(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReleaseMemory", reflect.TypeOf((*MockConnManagementScope)(nil).ReleaseMemory), arg0) } @@ -97,7 +102,7 @@ func (m *MockConnManagementScope) ReserveMemory(arg0 int, arg1 byte) error { } // ReserveMemory indicates an expected call of ReserveMemory. -func (mr *MockConnManagementScopeMockRecorder) ReserveMemory(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockConnManagementScopeMockRecorder) ReserveMemory(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReserveMemory", reflect.TypeOf((*MockConnManagementScope)(nil).ReserveMemory), arg0, arg1) } @@ -111,7 +116,7 @@ func (m *MockConnManagementScope) SetPeer(arg0 peer.ID) error { } // SetPeer indicates an expected call of SetPeer. -func (mr *MockConnManagementScopeMockRecorder) SetPeer(arg0 interface{}) *gomock.Call { +func (mr *MockConnManagementScopeMockRecorder) SetPeer(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetPeer", reflect.TypeOf((*MockConnManagementScope)(nil).SetPeer), arg0) } diff --git a/go-libp2p/core/network/mocks/mock_peer_scope.go b/go-libp2p/core/network/mocks/mock_peer_scope.go index 1633839..325a894 100644 --- a/go-libp2p/core/network/mocks/mock_peer_scope.go +++ b/go-libp2p/core/network/mocks/mock_peer_scope.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/libp2p/go-libp2p/core/network (interfaces: PeerScope) +// +// Generated by this command: +// +// mockgen -package mocknetwork -destination mock_peer_scope.go github.com/libp2p/go-libp2p/core/network PeerScope +// // Package mocknetwork is a generated GoMock package. package mocknetwork @@ -7,9 +12,9 @@ package mocknetwork import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" network "github.com/libp2p/go-libp2p/core/network" peer "github.com/libp2p/go-libp2p/core/peer" + gomock "go.uber.org/mock/gomock" ) // MockPeerScope is a mock of PeerScope interface. @@ -71,7 +76,7 @@ func (m *MockPeerScope) ReleaseMemory(arg0 int) { } // ReleaseMemory indicates an expected call of ReleaseMemory. -func (mr *MockPeerScopeMockRecorder) ReleaseMemory(arg0 interface{}) *gomock.Call { +func (mr *MockPeerScopeMockRecorder) ReleaseMemory(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReleaseMemory", reflect.TypeOf((*MockPeerScope)(nil).ReleaseMemory), arg0) } @@ -85,7 +90,7 @@ func (m *MockPeerScope) ReserveMemory(arg0 int, arg1 byte) error { } // ReserveMemory indicates an expected call of ReserveMemory. -func (mr *MockPeerScopeMockRecorder) ReserveMemory(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockPeerScopeMockRecorder) ReserveMemory(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReserveMemory", reflect.TypeOf((*MockPeerScope)(nil).ReserveMemory), arg0, arg1) } diff --git a/go-libp2p/core/network/mocks/mock_protocol_scope.go b/go-libp2p/core/network/mocks/mock_protocol_scope.go index 646eede..80d2967 100644 --- a/go-libp2p/core/network/mocks/mock_protocol_scope.go +++ b/go-libp2p/core/network/mocks/mock_protocol_scope.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/libp2p/go-libp2p/core/network (interfaces: ProtocolScope) +// +// Generated by this command: +// +// mockgen -package mocknetwork -destination mock_protocol_scope.go github.com/libp2p/go-libp2p/core/network ProtocolScope +// // Package mocknetwork is a generated GoMock package. package mocknetwork @@ -7,9 +12,9 @@ package mocknetwork import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" network "github.com/libp2p/go-libp2p/core/network" protocol "github.com/libp2p/go-libp2p/core/protocol" + gomock "go.uber.org/mock/gomock" ) // MockProtocolScope is a mock of ProtocolScope interface. @@ -71,7 +76,7 @@ func (m *MockProtocolScope) ReleaseMemory(arg0 int) { } // ReleaseMemory indicates an expected call of ReleaseMemory. -func (mr *MockProtocolScopeMockRecorder) ReleaseMemory(arg0 interface{}) *gomock.Call { +func (mr *MockProtocolScopeMockRecorder) ReleaseMemory(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReleaseMemory", reflect.TypeOf((*MockProtocolScope)(nil).ReleaseMemory), arg0) } @@ -85,7 +90,7 @@ func (m *MockProtocolScope) ReserveMemory(arg0 int, arg1 byte) error { } // ReserveMemory indicates an expected call of ReserveMemory. -func (mr *MockProtocolScopeMockRecorder) ReserveMemory(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockProtocolScopeMockRecorder) ReserveMemory(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReserveMemory", reflect.TypeOf((*MockProtocolScope)(nil).ReserveMemory), arg0, arg1) } diff --git a/go-libp2p/core/network/mocks/mock_resource_manager.go b/go-libp2p/core/network/mocks/mock_resource_manager.go index dbf6219..98e186e 100644 --- a/go-libp2p/core/network/mocks/mock_resource_manager.go +++ b/go-libp2p/core/network/mocks/mock_resource_manager.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/libp2p/go-libp2p/core/network (interfaces: ResourceManager) +// +// Generated by this command: +// +// mockgen -package mocknetwork -destination mock_resource_manager.go github.com/libp2p/go-libp2p/core/network ResourceManager +// // Package mocknetwork is a generated GoMock package. package mocknetwork @@ -7,11 +12,11 @@ package mocknetwork import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" network "github.com/libp2p/go-libp2p/core/network" peer "github.com/libp2p/go-libp2p/core/peer" protocol "github.com/libp2p/go-libp2p/core/protocol" multiaddr "github.com/multiformats/go-multiaddr" + gomock "go.uber.org/mock/gomock" ) // MockResourceManager is a mock of ResourceManager interface. @@ -61,7 +66,7 @@ func (m *MockResourceManager) OpenConnection(arg0 network.Direction, arg1 bool, } // OpenConnection indicates an expected call of OpenConnection. -func (mr *MockResourceManagerMockRecorder) OpenConnection(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockResourceManagerMockRecorder) OpenConnection(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OpenConnection", reflect.TypeOf((*MockResourceManager)(nil).OpenConnection), arg0, arg1, arg2) } @@ -76,7 +81,7 @@ func (m *MockResourceManager) OpenStream(arg0 peer.ID, arg1 network.Direction) ( } // OpenStream indicates an expected call of OpenStream. -func (mr *MockResourceManagerMockRecorder) OpenStream(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockResourceManagerMockRecorder) OpenStream(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OpenStream", reflect.TypeOf((*MockResourceManager)(nil).OpenStream), arg0, arg1) } @@ -90,7 +95,7 @@ func (m *MockResourceManager) ViewPeer(arg0 peer.ID, arg1 func(network.PeerScope } // ViewPeer indicates an expected call of ViewPeer. -func (mr *MockResourceManagerMockRecorder) ViewPeer(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockResourceManagerMockRecorder) ViewPeer(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ViewPeer", reflect.TypeOf((*MockResourceManager)(nil).ViewPeer), arg0, arg1) } @@ -104,7 +109,7 @@ func (m *MockResourceManager) ViewProtocol(arg0 protocol.ID, arg1 func(network.P } // ViewProtocol indicates an expected call of ViewProtocol. -func (mr *MockResourceManagerMockRecorder) ViewProtocol(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockResourceManagerMockRecorder) ViewProtocol(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ViewProtocol", reflect.TypeOf((*MockResourceManager)(nil).ViewProtocol), arg0, arg1) } @@ -118,7 +123,7 @@ func (m *MockResourceManager) ViewService(arg0 string, arg1 func(network.Service } // ViewService indicates an expected call of ViewService. -func (mr *MockResourceManagerMockRecorder) ViewService(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockResourceManagerMockRecorder) ViewService(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ViewService", reflect.TypeOf((*MockResourceManager)(nil).ViewService), arg0, arg1) } @@ -132,7 +137,7 @@ func (m *MockResourceManager) ViewSystem(arg0 func(network.ResourceScope) error) } // ViewSystem indicates an expected call of ViewSystem. -func (mr *MockResourceManagerMockRecorder) ViewSystem(arg0 interface{}) *gomock.Call { +func (mr *MockResourceManagerMockRecorder) ViewSystem(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ViewSystem", reflect.TypeOf((*MockResourceManager)(nil).ViewSystem), arg0) } @@ -146,7 +151,7 @@ func (m *MockResourceManager) ViewTransient(arg0 func(network.ResourceScope) err } // ViewTransient indicates an expected call of ViewTransient. -func (mr *MockResourceManagerMockRecorder) ViewTransient(arg0 interface{}) *gomock.Call { +func (mr *MockResourceManagerMockRecorder) ViewTransient(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ViewTransient", reflect.TypeOf((*MockResourceManager)(nil).ViewTransient), arg0) } diff --git a/go-libp2p/core/network/mocks/mock_resource_scope_span.go b/go-libp2p/core/network/mocks/mock_resource_scope_span.go index ba9a424..5123ff8 100644 --- a/go-libp2p/core/network/mocks/mock_resource_scope_span.go +++ b/go-libp2p/core/network/mocks/mock_resource_scope_span.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/libp2p/go-libp2p/core/network (interfaces: ResourceScopeSpan) +// +// Generated by this command: +// +// mockgen -package mocknetwork -destination mock_resource_scope_span.go github.com/libp2p/go-libp2p/core/network ResourceScopeSpan +// // Package mocknetwork is a generated GoMock package. package mocknetwork @@ -7,8 +12,8 @@ package mocknetwork import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" network "github.com/libp2p/go-libp2p/core/network" + gomock "go.uber.org/mock/gomock" ) // MockResourceScopeSpan is a mock of ResourceScopeSpan interface. @@ -68,7 +73,7 @@ func (m *MockResourceScopeSpan) ReleaseMemory(arg0 int) { } // ReleaseMemory indicates an expected call of ReleaseMemory. -func (mr *MockResourceScopeSpanMockRecorder) ReleaseMemory(arg0 interface{}) *gomock.Call { +func (mr *MockResourceScopeSpanMockRecorder) ReleaseMemory(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReleaseMemory", reflect.TypeOf((*MockResourceScopeSpan)(nil).ReleaseMemory), arg0) } @@ -82,7 +87,7 @@ func (m *MockResourceScopeSpan) ReserveMemory(arg0 int, arg1 byte) error { } // ReserveMemory indicates an expected call of ReserveMemory. -func (mr *MockResourceScopeSpanMockRecorder) ReserveMemory(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockResourceScopeSpanMockRecorder) ReserveMemory(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReserveMemory", reflect.TypeOf((*MockResourceScopeSpan)(nil).ReserveMemory), arg0, arg1) } diff --git a/go-libp2p/core/network/mocks/mock_stream_management_scope.go b/go-libp2p/core/network/mocks/mock_stream_management_scope.go index 7dace90..472eb7a 100644 --- a/go-libp2p/core/network/mocks/mock_stream_management_scope.go +++ b/go-libp2p/core/network/mocks/mock_stream_management_scope.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/libp2p/go-libp2p/core/network (interfaces: StreamManagementScope) +// +// Generated by this command: +// +// mockgen -package mocknetwork -destination mock_stream_management_scope.go github.com/libp2p/go-libp2p/core/network StreamManagementScope +// // Package mocknetwork is a generated GoMock package. package mocknetwork @@ -7,9 +12,9 @@ package mocknetwork import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" network "github.com/libp2p/go-libp2p/core/network" protocol "github.com/libp2p/go-libp2p/core/protocol" + gomock "go.uber.org/mock/gomock" ) // MockStreamManagementScope is a mock of StreamManagementScope interface. @@ -97,7 +102,7 @@ func (m *MockStreamManagementScope) ReleaseMemory(arg0 int) { } // ReleaseMemory indicates an expected call of ReleaseMemory. -func (mr *MockStreamManagementScopeMockRecorder) ReleaseMemory(arg0 interface{}) *gomock.Call { +func (mr *MockStreamManagementScopeMockRecorder) ReleaseMemory(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReleaseMemory", reflect.TypeOf((*MockStreamManagementScope)(nil).ReleaseMemory), arg0) } @@ -111,7 +116,7 @@ func (m *MockStreamManagementScope) ReserveMemory(arg0 int, arg1 byte) error { } // ReserveMemory indicates an expected call of ReserveMemory. -func (mr *MockStreamManagementScopeMockRecorder) ReserveMemory(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockStreamManagementScopeMockRecorder) ReserveMemory(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReserveMemory", reflect.TypeOf((*MockStreamManagementScope)(nil).ReserveMemory), arg0, arg1) } @@ -139,7 +144,7 @@ func (m *MockStreamManagementScope) SetProtocol(arg0 protocol.ID) error { } // SetProtocol indicates an expected call of SetProtocol. -func (mr *MockStreamManagementScopeMockRecorder) SetProtocol(arg0 interface{}) *gomock.Call { +func (mr *MockStreamManagementScopeMockRecorder) SetProtocol(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetProtocol", reflect.TypeOf((*MockStreamManagementScope)(nil).SetProtocol), arg0) } @@ -153,7 +158,7 @@ func (m *MockStreamManagementScope) SetService(arg0 string) error { } // SetService indicates an expected call of SetService. -func (mr *MockStreamManagementScopeMockRecorder) SetService(arg0 interface{}) *gomock.Call { +func (mr *MockStreamManagementScopeMockRecorder) SetService(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetService", reflect.TypeOf((*MockStreamManagementScope)(nil).SetService), arg0) } diff --git a/go-libp2p/core/network/mocks/network.go b/go-libp2p/core/network/mocks/network.go index 6fe8e91..73025bd 100644 --- a/go-libp2p/core/network/mocks/network.go +++ b/go-libp2p/core/network/mocks/network.go @@ -1,8 +1,8 @@ package mocknetwork -//go:generate sh -c "go run github.com/golang/mock/mockgen -package mocknetwork -destination mock_resource_manager.go github.com/libp2p/go-libp2p/core/network ResourceManager" -//go:generate sh -c "go run github.com/golang/mock/mockgen -package mocknetwork -destination mock_conn_management_scope.go github.com/libp2p/go-libp2p/core/network ConnManagementScope" -//go:generate sh -c "go run github.com/golang/mock/mockgen -package mocknetwork -destination mock_stream_management_scope.go github.com/libp2p/go-libp2p/core/network StreamManagementScope" -//go:generate sh -c "go run github.com/golang/mock/mockgen -package mocknetwork -destination mock_peer_scope.go github.com/libp2p/go-libp2p/core/network PeerScope" -//go:generate sh -c "go run github.com/golang/mock/mockgen -package mocknetwork -destination mock_protocol_scope.go github.com/libp2p/go-libp2p/core/network ProtocolScope" -//go:generate sh -c "go run github.com/golang/mock/mockgen -package mocknetwork -destination mock_resource_scope_span.go github.com/libp2p/go-libp2p/core/network ResourceScopeSpan" +//go:generate sh -c "go run go.uber.org/mock/mockgen -package mocknetwork -destination mock_resource_manager.go github.com/libp2p/go-libp2p/core/network ResourceManager" +//go:generate sh -c "go run go.uber.org/mock/mockgen -package mocknetwork -destination mock_conn_management_scope.go github.com/libp2p/go-libp2p/core/network ConnManagementScope" +//go:generate sh -c "go run go.uber.org/mock/mockgen -package mocknetwork -destination mock_stream_management_scope.go github.com/libp2p/go-libp2p/core/network StreamManagementScope" +//go:generate sh -c "go run go.uber.org/mock/mockgen -package mocknetwork -destination mock_peer_scope.go github.com/libp2p/go-libp2p/core/network PeerScope" +//go:generate sh -c "go run go.uber.org/mock/mockgen -package mocknetwork -destination mock_protocol_scope.go github.com/libp2p/go-libp2p/core/network ProtocolScope" +//go:generate sh -c "go run go.uber.org/mock/mockgen -package mocknetwork -destination mock_resource_scope_span.go github.com/libp2p/go-libp2p/core/network ResourceScopeSpan" diff --git a/go-libp2p/core/network/network.go b/go-libp2p/core/network/network.go index 66b0a1c..22efbf2 100644 --- a/go-libp2p/core/network/network.go +++ b/go-libp2p/core/network/network.go @@ -55,16 +55,23 @@ const ( // Connected means has an open, live connection to peer Connected + // Deprecated: CanConnect is deprecated and will be removed in a future release. + // // CanConnect means recently connected to peer, terminated gracefully CanConnect + // Deprecated: CannotConnect is deprecated and will be removed in a future release. + // // CannotConnect means recently attempted connecting but failed to connect. // (should signal "made effort, failed") CannotConnect + + // Limited means we have a transient connection to the peer, but aren't fully connected. + Limited ) func (c Connectedness) String() string { - str := [...]string{"NotConnected", "Connected", "CanConnect", "CannotConnect"} + str := [...]string{"NotConnected", "Connected", "CanConnect", "CannotConnect", "Limited"} if c < 0 || int(c) >= len(str) { return unrecognized } @@ -111,8 +118,10 @@ type Stats struct { Direction Direction // Opened is the timestamp when this connection was opened. Opened time.Time - // Transient indicates that this connection is transient and may be closed soon. - Transient bool + // Limited indicates that this connection is Limited. It maybe limited by + // bytes or time. In practice, this is a connection formed over a circuit v2 + // relay. + Limited bool // Extra stores additional metadata about this connection. Extra map[interface{}]interface{} } diff --git a/go-libp2p/core/peer/addrinfo.go b/go-libp2p/core/peer/addrinfo.go index fba4cfd..de7dd4d 100644 --- a/go-libp2p/core/peer/addrinfo.go +++ b/go-libp2p/core/peer/addrinfo.go @@ -86,7 +86,7 @@ func AddrInfoFromP2pAddr(m ma.Multiaddr) (*AddrInfo, error) { // AddrInfoToP2pAddrs converts an AddrInfo to a list of Multiaddrs. func AddrInfoToP2pAddrs(pi *AddrInfo) ([]ma.Multiaddr, error) { - p2ppart, err := ma.NewComponent("p2p", Encode(pi.ID)) + p2ppart, err := ma.NewComponent("p2p", pi.ID.String()) if err != nil { return nil, err } @@ -102,7 +102,7 @@ func AddrInfoToP2pAddrs(pi *AddrInfo) ([]ma.Multiaddr, error) { func (pi *AddrInfo) Loggable() map[string]interface{} { return map[string]interface{}{ - "peerID": pi.ID.Pretty(), + "peerID": pi.ID.String(), "addrs": pi.Addrs, } } diff --git a/go-libp2p/core/peer/addrinfo_test.go b/go-libp2p/core/peer/addrinfo_test.go index 9f18a8b..3fd1556 100644 --- a/go-libp2p/core/peer/addrinfo_test.go +++ b/go-libp2p/core/peer/addrinfo_test.go @@ -3,9 +3,9 @@ package peer_test import ( "testing" - ma "github.com/multiformats/go-multiaddr" - . "github.com/libp2p/go-libp2p/core/peer" + + ma "github.com/multiformats/go-multiaddr" ) var ( @@ -19,7 +19,7 @@ func init() { if err != nil { panic(err) } - maddrPeer = ma.StringCast("/p2p/" + Encode(testID)) + maddrPeer = ma.StringCast("/p2p/" + testID.String()) maddrTpt = ma.StringCast("/ip4/127.0.0.1/tcp/1234") maddrFull = maddrTpt.Encapsulate(maddrPeer) } @@ -115,7 +115,7 @@ func TestAddrInfosFromP2pAddrs(t *testing.T) { t.Fatal(err) } for _, info := range infos { - exaddrs, ok := expected[info.ID.Pretty()] + exaddrs, ok := expected[info.ID.String()] if !ok { t.Fatalf("didn't expect peer %s", info.ID) } @@ -129,7 +129,7 @@ func TestAddrInfosFromP2pAddrs(t *testing.T) { t.Fatalf("expected %s, got %s", exaddrs[i], addr) } } - delete(expected, info.ID.Pretty()) + delete(expected, info.ID.String()) } } @@ -144,7 +144,7 @@ func TestAddrInfoJSON(t *testing.T) { t.Fatal(err) } if addrInfo.ID != testID { - t.Fatalf("expected ID to equal %s, got %s", testID.Pretty(), addrInfo.ID.Pretty()) + t.Fatalf("expected ID to equal %s, got %s", testID, addrInfo.ID) } if len(addrInfo.Addrs) != 1 || !addrInfo.Addrs[0].Equal(maddrFull) { t.Fatalf("expected addrs to match %v, got %v", maddrFull, addrInfo.Addrs) diff --git a/go-libp2p/core/peer/peer.go b/go-libp2p/core/peer/peer.go index f7f649f..b77fb68 100644 --- a/go-libp2p/core/peer/peer.go +++ b/go-libp2p/core/peer/peer.go @@ -41,12 +41,6 @@ const maxInlineKeyLength = 42 // hash output as a multihash. See IDFromPublicKey for details. type ID string -// Pretty returns a base58-encoded string representation of the ID. -// Deprecated: use String() instead. -func (id ID) Pretty() string { - return id.String() -} - // Loggable returns a pretty peer ID string in loggable JSON format. func (id ID) Loggable() map[string]interface{} { return map[string]interface{}{ @@ -145,16 +139,6 @@ func Decode(s string) (ID, error) { return FromCid(c) } -// Encode encodes a peer ID as a string. -// -// At the moment, it base58 encodes the peer ID but, in the future, it will -// switch to encoding it as a CID by default. -// -// Deprecated: use id.String instead. -func Encode(id ID) string { - return id.String() -} - // FromCid converts a CID to a peer ID, if possible. func FromCid(c cid.Cid) (ID, error) { code := mc.Code(c.Type()) diff --git a/go-libp2p/core/peer/peer_serde.go b/go-libp2p/core/peer/peer_serde.go index 5fd1cd5..3e2f717 100644 --- a/go-libp2p/core/peer/peer_serde.go +++ b/go-libp2p/core/peer/peer_serde.go @@ -45,7 +45,7 @@ func (id ID) Size() int { } func (id ID) MarshalJSON() ([]byte, error) { - return json.Marshal(Encode(id)) + return json.Marshal(id.String()) } func (id *ID) UnmarshalJSON(data []byte) (err error) { @@ -59,7 +59,7 @@ func (id *ID) UnmarshalJSON(data []byte) (err error) { // MarshalText returns the text encoding of the ID. func (id ID) MarshalText() ([]byte, error) { - return []byte(Encode(id)), nil + return []byte(id.String()), nil } // UnmarshalText restores the ID from its text encoding. diff --git a/go-libp2p/core/peerstore/peerstore.go b/go-libp2p/core/peerstore/peerstore.go index 4c9227f..0ef09df 100644 --- a/go-libp2p/core/peerstore/peerstore.go +++ b/go-libp2p/core/peerstore/peerstore.go @@ -28,9 +28,10 @@ var ( // RecentlyConnectedAddrTTL is used when we recently connected to a peer. // It means that we are reasonably certain of the peer's address. - RecentlyConnectedAddrTTL = time.Minute * 30 + RecentlyConnectedAddrTTL = time.Minute * 15 // OwnObservedAddrTTL is used for our own external addresses observed by peers. + // Deprecated: observed addresses are maintained till we disconnect from the peer which provided it OwnObservedAddrTTL = time.Minute * 30 ) diff --git a/go-libp2p/core/routing/routing.go b/go-libp2p/core/routing/routing.go index e1d4745..b995b05 100644 --- a/go-libp2p/core/routing/routing.go +++ b/go-libp2p/core/routing/routing.go @@ -76,7 +76,7 @@ type Routing interface { ValueStore // Bootstrap allows callers to hint to the routing system to get into a - // Boostrapped state and remain there. It is not a synchronous call. + // Bootstrapped state and remain there. It is not a synchronous call. Bootstrap(context.Context) error // TODO expose io.Closer or plain-old Close error diff --git a/go-libp2p/core/sec/security.go b/go-libp2p/core/sec/security.go index 83059d9..d9e9183 100644 --- a/go-libp2p/core/sec/security.go +++ b/go-libp2p/core/sec/security.go @@ -3,6 +3,7 @@ package sec import ( "context" + "fmt" "net" "github.com/libp2p/go-libp2p/core/network" @@ -29,3 +30,14 @@ type SecureTransport interface { // ID is the protocol ID of the security protocol. ID() protocol.ID } + +type ErrPeerIDMismatch struct { + Expected peer.ID + Actual peer.ID +} + +func (e ErrPeerIDMismatch) Error() string { + return fmt.Sprintf("peer id mismatch: expected %s, but remote key matches %s", e.Expected, e.Actual) +} + +var _ error = (*ErrPeerIDMismatch)(nil) diff --git a/go-libp2p/core/transport/transport.go b/go-libp2p/core/transport/transport.go index 89a9608..d56a3cf 100644 --- a/go-libp2p/core/transport/transport.go +++ b/go-libp2p/core/transport/transport.go @@ -5,6 +5,7 @@ package transport import ( "context" "errors" + "fmt" "net" "github.com/libp2p/go-libp2p/core/network" @@ -124,3 +125,47 @@ type Upgrader interface { // Upgrade upgrades the multiaddr/net connection into a full libp2p-transport connection. Upgrade(ctx context.Context, t Transport, maconn manet.Conn, dir network.Direction, p peer.ID, scope network.ConnManagementScope) (CapableConn, error) } + +// DialUpdater provides updates on in progress dials. +type DialUpdater interface { + // DialWithUpdates dials a remote peer and provides updates on the passed channel. + DialWithUpdates(context.Context, ma.Multiaddr, peer.ID, chan<- DialUpdate) (CapableConn, error) +} + +// DialUpdateKind indicates the type of DialUpdate event. +type DialUpdateKind int + +const ( + // UpdateKindDialFailed indicates dial failed. + UpdateKindDialFailed DialUpdateKind = iota + // UpdateKindDialSuccessful indicates dial succeeded. + UpdateKindDialSuccessful + // UpdateKindHandshakeProgressed indicates successful completion of the TCP 3-way + // handshake + UpdateKindHandshakeProgressed +) + +func (k DialUpdateKind) String() string { + switch k { + case UpdateKindDialFailed: + return "DialFailed" + case UpdateKindDialSuccessful: + return "DialSuccessful" + case UpdateKindHandshakeProgressed: + return "UpdateKindHandshakeProgressed" + default: + return fmt.Sprintf("DialUpdateKind", k) + } +} + +// DialUpdate is used by DialUpdater to provide dial updates. +type DialUpdate struct { + // Kind is the kind of update event. + Kind DialUpdateKind + // Addr is the peer's address. + Addr ma.Multiaddr + // Conn is the resulting connection on success. + Conn CapableConn + // Err is the reason for dial failure. + Err error +} diff --git a/go-libp2p/dashboards/README.md b/go-libp2p/dashboards/README.md index 6080dc0..c371685 100644 --- a/go-libp2p/dashboards/README.md +++ b/go-libp2p/dashboards/README.md @@ -3,6 +3,20 @@ This directory contains prebuilt dashboards (provided as JSON files) for various components. For steps on how to import and use them [please read the official Grafana documentation.](https://grafana.com/docs/grafana/latest/dashboards/export-import/#import-dashboard) +## Public dashboards + +You can check the following prebuilt dashboards in action: + +1. [AutoNAT](https://protocollabs.grafana.net/public-dashboards/fce8fdeb629742c89bd70f0ce38dfd97) +2. [Auto Relay](https://protocollabs.grafana.net/public-dashboards/380d52aded12404e9cf6ceccb824b7f9) +3. [Eventbus](https://protocollabs.grafana.net/public-dashboards/048029ac2d7e4a71b281ffea3535026e) +4. [Identify](https://protocollabs.grafana.net/public-dashboards/96b70328253d47c0b352dfae06f12a1b) +5. [Relay Service](https://protocollabs.grafana.net/public-dashboards/4a8cb5d245294893874ed65279b049be) +6. [Swarm](https://protocollabs.grafana.net/public-dashboards/2bd3f1bee9964d40b6786fbe3eafd9fc) + +These metrics come from one of the public IPFS DHT [bootstrap nodes](https://docs.ipfs.tech/concepts/nodes/#bootstrap) run by Protocol Labs. +At the time of writing (2023-08), these nodes handle many connections across various libp2p implementations, versions, and configurations (they don't handle large file transfers). + ## Using locally For local development and debugging, it can be useful to spin up a local Prometheus and Grafana instance. diff --git a/go-libp2p/dashboards/autonat/autonat.json b/go-libp2p/dashboards/autonat/autonat.json index 4a14de8..fea5b7a 100644 --- a/go-libp2p/dashboards/autonat/autonat.json +++ b/go-libp2p/dashboards/autonat/autonat.json @@ -730,7 +730,7 @@ }, "timepicker": {}, "timezone": "", - "title": "libp2p autonat", + "title": "go-libp2p autonat", "uid": "YNWSyiJ4k", "version": 5, "weekStart": "" diff --git a/go-libp2p/dashboards/docker-compose.base.yml b/go-libp2p/dashboards/docker-compose.base.yml index 4c87d28..b46514a 100644 --- a/go-libp2p/dashboards/docker-compose.base.yml +++ b/go-libp2p/dashboards/docker-compose.base.yml @@ -26,3 +26,4 @@ services: - ./identify/identify.json:/var/lib/grafana/dashboards/identify.json - ./relaysvc/relaysvc.json:/var/lib/grafana/dashboards/relaysvc.json - ./swarm/swarm.json:/var/lib/grafana/dashboards/swarm.json + - ./resource-manager/resource-manager.json:/var/lib/grafana/dashboards/resource-manager.json diff --git a/go-libp2p/dashboards/eventbus/eventbus.json b/go-libp2p/dashboards/eventbus/eventbus.json index 24b7e22..f51549a 100644 --- a/go-libp2p/dashboards/eventbus/eventbus.json +++ b/go-libp2p/dashboards/eventbus/eventbus.json @@ -554,7 +554,7 @@ }, "timepicker": {}, "timezone": "", - "title": "libp2p EventBus", + "title": "go-libp2p EventBus", "uid": "ZFbI6NAVn", "version": 4, "weekStart": "" diff --git a/go-libp2p/dashboards/holepunch/holepunch.json b/go-libp2p/dashboards/holepunch/holepunch.json index ba20951..7d986f7 100644 --- a/go-libp2p/dashboards/holepunch/holepunch.json +++ b/go-libp2p/dashboards/holepunch/holepunch.json @@ -1129,7 +1129,7 @@ }, "timepicker": {}, "timezone": "", - "title": "libp2p Hole Punches", + "title": "go-libp2p Hole Punches", "uid": "Ao24vOBVk", "version": 6, "weekStart": "" diff --git a/go-libp2p/dashboards/identify/identify.json b/go-libp2p/dashboards/identify/identify.json index 41d7823..4f4631c 100644 --- a/go-libp2p/dashboards/identify/identify.json +++ b/go-libp2p/dashboards/identify/identify.json @@ -877,7 +877,7 @@ }, "timepicker": {}, "timezone": "", - "title": "libp2p Identify", + "title": "go-libp2p Identify", "uid": "0NDzQQ0Vz", "version": 2, "weekStart": "" diff --git a/go-libp2p/dashboards/relaysvc/relaysvc.json b/go-libp2p/dashboards/relaysvc/relaysvc.json index d70a824..c2a0e22 100644 --- a/go-libp2p/dashboards/relaysvc/relaysvc.json +++ b/go-libp2p/dashboards/relaysvc/relaysvc.json @@ -1229,7 +1229,7 @@ }, "timepicker": {}, "timezone": "", - "title": "libp2p Relay Service", + "title": "go-libp2p Relay Service", "uid": "C6RUfAx4z", "version": 5, "weekStart": "" diff --git a/go-libp2p/dashboards/resource-manager/resource-manager.json b/go-libp2p/dashboards/resource-manager/resource-manager.json index 8395b2a..9b4ff68 100644 --- a/go-libp2p/dashboards/resource-manager/resource-manager.json +++ b/go-libp2p/dashboards/resource-manager/resource-manager.json @@ -1821,7 +1821,7 @@ }, "timepicker": {}, "timezone": "", - "title": "libp2p Resource Manager", + "title": "go-libp2p Resource Manager", "uid": "MgmGIjjnj", "version": 1, "weekStart": "" diff --git a/go-libp2p/dashboards/swarm/swarm.json b/go-libp2p/dashboards/swarm/swarm.json index ec64784..d206de2 100644 --- a/go-libp2p/dashboards/swarm/swarm.json +++ b/go-libp2p/dashboards/swarm/swarm.json @@ -232,9 +232,7 @@ "options": { "orientation": "auto", "reduceOptions": { - "calcs": [ - "lastNotNull" - ], + "calcs": ["lastNotNull"], "fields": "", "values": false }, @@ -1139,9 +1137,7 @@ }, "pieType": "pie", "reduceOptions": { - "calcs": [ - "lastNotNull" - ], + "calcs": ["lastNotNull"], "fields": "", "values": false }, @@ -1816,9 +1812,7 @@ }, "pieType": "pie", "reduceOptions": { - "calcs": [ - "lastNotNull" - ], + "calcs": ["lastNotNull"], "fields": "", "values": false }, @@ -2016,9 +2010,7 @@ }, "pieType": "pie", "reduceOptions": { - "calcs": [ - "lastNotNull" - ], + "calcs": ["lastNotNull"], "fields": "", "values": false }, @@ -2110,9 +2102,7 @@ }, "pieType": "pie", "reduceOptions": { - "calcs": [ - "lastNotNull" - ], + "calcs": ["lastNotNull"], "fields": "", "values": false }, @@ -2205,9 +2195,7 @@ }, "pieType": "pie", "reduceOptions": { - "calcs": [ - "lastNotNull" - ], + "calcs": ["lastNotNull"], "fields": "", "values": false }, @@ -2251,7 +2239,113 @@ }, "mappings": [] }, - "overrides": [] + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "canceled: concurrent dial successful" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "super-light-blue", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "application canceled" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "blue", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "canceled: other" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "dark-blue", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "timeout" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "orange", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "other" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "red", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "deadline" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "super-light-orange", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "connection refused" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "green", + "mode": "fixed" + } + } + ] + } + ] }, "gridPos": { "h": 8, @@ -2261,16 +2355,16 @@ }, "id": 15, "options": { + "displayLabels": [], "legend": { - "displayMode": "list", + "displayMode": "table", "placement": "right", - "showLegend": true + "showLegend": true, + "values": ["percent"] }, "pieType": "donut", "reduceOptions": { - "calcs": [ - "lastNotNull" - ], + "calcs": ["lastNotNull"], "fields": "", "values": false }, @@ -2542,9 +2636,7 @@ }, "pieType": "pie", "reduceOptions": { - "calcs": [ - "lastNotNull" - ], + "calcs": ["lastNotNull"], "fields": "", "values": false }, @@ -2688,22 +2780,16 @@ }, "id": 38, "options": { - "displayLabels": [ - "percent" - ], + "displayLabels": ["percent"], "legend": { "displayMode": "table", "placement": "right", "showLegend": true, - "values": [ - "percent" - ] + "values": ["percent"] }, "pieType": "donut", "reduceOptions": { - "calcs": [ - "lastNotNull" - ], + "calcs": ["lastNotNull"], "fields": "", "values": false }, @@ -2795,7 +2881,7 @@ "uid": "${DS_PROMETHEUS}" }, "editorMode": "code", - "expr": "sum(increase(libp2p_swarm_dial_ranking_delay_seconds_bucket{instance=~\"$instance\",le=\"inf\"}[$__range])) - ignoring(le) sum(increase(libp2p_swarm_dial_ranking_delay_seconds_bucket{instance=~\"$instance\",le=\"0.75\"}[$__range]))", + "expr": "sum(increase(libp2p_swarm_dial_ranking_delay_seconds_bucket{instance=~\"$instance\",le=\"+Inf\"}[$__range])) - ignoring(le) sum(increase(libp2p_swarm_dial_ranking_delay_seconds_bucket{instance=~\"$instance\",le=\"0.75\"}[$__range]))", "hide": false, "legendFormat": ">750ms", "range": true, @@ -2926,23 +3012,16 @@ }, "id": 42, "options": { - "displayLabels": [ - "percent", - "name" - ], + "displayLabels": ["percent", "name"], "legend": { "displayMode": "table", "placement": "right", "showLegend": true, - "values": [ - "percent" - ] + "values": ["percent"] }, "pieType": "donut", "reduceOptions": { - "calcs": [ - "lastNotNull" - ], + "calcs": ["lastNotNull"], "fields": "", "values": false }, @@ -3186,15 +3265,13 @@ "justifyMode": "auto", "orientation": "horizontal", "reduceOptions": { - "calcs": [ - "lastNotNull" - ], + "calcs": ["lastNotNull"], "fields": "", "values": false }, "textMode": "value_and_name" }, - "pluginVersion": "9.3.6", + "pluginVersion": "10.0.1", "targets": [ { "datasource": { @@ -3222,7 +3299,7 @@ "mode": "thresholds" }, "mappings": [], - "max": 10, + "max": 100, "min": 0, "thresholds": { "mode": "absolute", @@ -3250,16 +3327,14 @@ "options": { "orientation": "vertical", "reduceOptions": { - "calcs": [ - "lastNotNull" - ], + "calcs": ["lastNotNull"], "fields": "", "values": false }, "showThresholdLabels": false, "showThresholdMarkers": true }, - "pluginVersion": "9.3.6", + "pluginVersion": "10.0.1", "targets": [ { "datasource": { @@ -3275,12 +3350,12 @@ "refId": "A" } ], - "title": "Black Hole Filter Success Percentage", + "title": "Dial Success Rate", "type": "gauge" } ], - "refresh": false, - "schemaVersion": 37, + "refresh": "", + "schemaVersion": 38, "style": "dark", "tags": [], "templating": { @@ -3312,7 +3387,6 @@ "refId": "StandardVariableQuery" }, "refresh": 1, - "regex": "", "skipUrlSync": false, "sort": 0, "type": "query" @@ -3320,13 +3394,13 @@ ] }, "time": { - "from": "now-1h", + "from": "now-15m", "to": "now" }, "timepicker": {}, "timezone": "", - "title": "libp2p Swarm", + "title": "go-libp2p Swarm", "uid": "a15PyhO4z", - "version": 7, + "version": 4, "weekStart": "" } diff --git a/go-libp2p/defaults.go b/go-libp2p/defaults.go index c0ed669..8f7dc94 100644 --- a/go-libp2p/defaults.go +++ b/go-libp2p/defaults.go @@ -27,8 +27,8 @@ import ( // Useful when you want to extend, but not replace, the supported transport // security protocols. var DefaultSecurity = ChainOptions( - Security(noise.ID, noise.New), Security(tls.ID, tls.New), + Security(noise.ID, noise.New), ) // DefaultMuxers configures libp2p to use the stream connection multiplexers. @@ -79,11 +79,9 @@ var RandomIdentity = func(cfg *Config) error { var DefaultListenAddrs = func(cfg *Config) error { addrs := []string{ "/ip4/0.0.0.0/tcp/0", - "/ip4/0.0.0.0/udp/0/quic", "/ip4/0.0.0.0/udp/0/quic-v1", "/ip4/0.0.0.0/udp/0/quic-v1/webtransport", "/ip6/::/tcp/0", - "/ip6/::/udp/0/quic", "/ip6/::/udp/0/quic-v1", "/ip6/::/udp/0/quic-v1/webtransport", } diff --git a/go-libp2p/docs/flaky-tests.md b/go-libp2p/docs/flaky-tests.md index e65800a..667dd77 100644 --- a/go-libp2p/docs/flaky-tests.md +++ b/go-libp2p/docs/flaky-tests.md @@ -28,7 +28,7 @@ processes are vying for CPU time. sudo cgset -r cpu.cfs_quota_us=10000 cpulimit sudo cgset -r cpu.cfs_period_us=1000000 cpulimit - # Run a shell with in our limited environemnt + # Run a shell with in our limited environment sudo cgexec -g cpu:cpulimit bash # In the shell, run the test diff --git a/go-libp2p/examples/README.md b/go-libp2p/examples/README.md index 7930ff7..f9074de 100644 --- a/go-libp2p/examples/README.md +++ b/go-libp2p/examples/README.md @@ -2,17 +2,21 @@ In this folder, you can find a variety of examples to help you get started in using go-libp2p. Every example as a specific purpose and some of each incorporate a full tutorial that you can follow through, helping you expand your knowledge about libp2p and p2p networks in general. -Let us know if you find any issue or if you want to contribute and add a new tutorial, feel welcome to submit a pr, thank you! +Let us know if you find any issue or if you want to contribute and add a new tutorial, feel welcome to submit a PR, thank you! ## Examples and Tutorials - [The libp2p 'host'](./libp2p-host) - [Building an http proxy with libp2p](./http-proxy) - [An echo host](./echo) +- [Routed echo host](./routed-echo/) - [Multicodecs with protobufs](./multipro) +- [Relay-based P2P Communication](./relay/) - [P2P chat application](./chat) - [P2P chat application w/ rendezvous peer discovery](./chat-with-rendezvous) - [P2P chat application with peer discovery using mdns](./chat-with-mdns) +- [P2P chat using pubsub](./pubsub) - [A chapter based approach to building a libp2p application](./ipfs-camp-2019/) _Created for [IPFS Camp 2019](https://github.com/ipfs/camp/tree/master/CORE_AND_ELECTIVE_COURSES/CORE_COURSE_B)_ +- [View metrics using Prometheus and Grafana](./metrics-and-dashboards) -For js-libp2p examples, check https://github.com/libp2p/js-libp2p/tree/master/examples +For js-libp2p examples, check https://github.com/libp2p/js-libp2p-examples diff --git a/go-libp2p/examples/chat-with-mdns/README.md b/go-libp2p/examples/chat-with-mdns/README.md index 836fb7a..8e467e6 100644 --- a/go-libp2p/examples/chat-with-mdns/README.md +++ b/go-libp2p/examples/chat-with-mdns/README.md @@ -57,29 +57,37 @@ func handleStream(stream net.Stream) { 3. **Find peers nearby using mdns** -Start [mdns discovery](https://godoc.org/github.com/libp2p/go-libp2p/p2p/discovery#NewMdnsService) service in host. +New [mdns discovery](https://godoc.org/github.com/libp2p/go-libp2p/p2p/discovery#NewMdnsService) service in host. ```go -ser, err := discovery.NewMdnsService(peerhost, rendezvous) +notifee := &discoveryNotifee{PeerChan: make(chan peer.AddrInfo)} +ser, err := discovery.NewMdnsService(peerhost, rendezvous, notifee) ``` register [Notifee interface](https://godoc.org/github.com/libp2p/go-libp2p/p2p/discovery#Notifee) with service so that we get notified about peer discovery ```go - n := &discoveryNotifee{} - ser.RegisterNotifee(n) + ser.Start() ``` + 4. **Open streams to peers found.** Finally we open stream to the peers we found, as we find them ```go peer := <-peerChan // will block until we discover a peer + // this is used to avoid call `NewStream` from both side + if peer.ID > host.ID() { + // if other end peer id greater than us, don't connect to it, just wait for it to connect us + fmt.Println("Found peer:", peer, " id is greater than us, wait for it to connect to us") + continue + } fmt.Println("Found peer:", peer, ", connecting") if err := host.Connect(ctx, peer); err != nil { fmt.Println("Connection failed:", err) + continue } // open a stream, this stream will be handled by handleStream other end diff --git a/go-libp2p/examples/chat-with-mdns/main.go b/go-libp2p/examples/chat-with-mdns/main.go index 57b89c2..55c36ad 100644 --- a/go-libp2p/examples/chat-with-mdns/main.go +++ b/go-libp2p/examples/chat-with-mdns/main.go @@ -111,11 +111,16 @@ func main() { // This function is called when a peer initiates a connection and starts a stream with this peer. host.SetStreamHandler(protocol.ID(cfg.ProtocolID), handleStream) - fmt.Printf("\n[*] Your Multiaddress Is: /ip4/%s/tcp/%v/p2p/%s\n", cfg.listenHost, cfg.listenPort, host.ID().Pretty()) + fmt.Printf("\n[*] Your Multiaddress Is: /ip4/%s/tcp/%v/p2p/%s\n", cfg.listenHost, cfg.listenPort, host.ID()) peerChan := initMDNS(host, cfg.RendezvousString) for { // allows multiple peers to join peer := <-peerChan // will block until we discover a peer + if peer.ID > host.ID() { + // if other end peer id greater than us, don't connect to it, just wait for it to connect us + fmt.Println("Found peer:", peer, " id is greater than us, wait for it to connect to us") + continue + } fmt.Println("Found peer:", peer, ", connecting") if err := host.Connect(ctx, peer); err != nil { diff --git a/go-libp2p/examples/chat-with-rendezvous/chat.go b/go-libp2p/examples/chat-with-rendezvous/chat.go index 5fc8d4e..a2ddb89 100644 --- a/go-libp2p/examples/chat-with-rendezvous/chat.go +++ b/go-libp2p/examples/chat-with-rendezvous/chat.go @@ -6,7 +6,7 @@ import ( "flag" "fmt" "os" - "sync" + "time" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/network" @@ -114,7 +114,12 @@ func main() { // DHT, so that the bootstrapping node of the DHT can go down without // inhibiting future peer discovery. ctx := context.Background() - kademliaDHT, err := dht.New(ctx, host) + bootstrapPeers := make([]peer.AddrInfo, len(config.BootstrapPeers)) + for i, addr := range config.BootstrapPeers { + peerinfo, _ := peer.AddrInfoFromP2pAddr(addr) + bootstrapPeers[i] = *peerinfo + } + kademliaDHT, err := dht.New(ctx, host, dht.BootstrapPeers(bootstrapPeers...)) if err != nil { panic(err) } @@ -126,22 +131,8 @@ func main() { panic(err) } - // Let's connect to the bootstrap nodes first. They will tell us about the - // other nodes in the network. - var wg sync.WaitGroup - for _, peerAddr := range config.BootstrapPeers { - peerinfo, _ := peer.AddrInfoFromP2pAddr(peerAddr) - wg.Add(1) - go func() { - defer wg.Done() - if err := host.Connect(ctx, *peerinfo); err != nil { - logger.Warning(err) - } else { - logger.Info("Connection established with bootstrap node:", *peerinfo) - } - }() - } - wg.Wait() + // Wait a bit to let bootstrapping finish (really bootstrap should block until it's ready, but that isn't the case yet.) + time.Sleep(1 * time.Second) // We use a rendezvous point "meet me here" to announce our location. // This is like telling your friends to meet you at the Eiffel Tower. diff --git a/go-libp2p/examples/chat/chat.go b/go-libp2p/examples/chat/chat.go index cd1c287..d89ea3c 100644 --- a/go-libp2p/examples/chat/chat.go +++ b/go-libp2p/examples/chat/chat.go @@ -187,7 +187,7 @@ func startPeer(ctx context.Context, h host.Host, streamHandler network.StreamHan return } - log.Printf("Run './chat -d /ip4/127.0.0.1/tcp/%v/p2p/%s' on another console.\n", port, h.ID().Pretty()) + log.Printf("Run './chat -d /ip4/127.0.0.1/tcp/%v/p2p/%s' on another console.\n", port, h.ID()) log.Println("You can replace 127.0.0.1 with public IP as well.") log.Println("Waiting for incoming connection") log.Println() diff --git a/go-libp2p/examples/chat/chat_test.go b/go-libp2p/examples/chat/chat_test.go index 1a1cea3..4240b47 100644 --- a/go-libp2p/examples/chat/chat_test.go +++ b/go-libp2p/examples/chat/chat_test.go @@ -49,7 +49,7 @@ func TestMain(t *testing.T) { cancel() // end the test }) - dest := fmt.Sprintf("/ip4/127.0.0.1/tcp/%v/p2p/%s", port1, h1.ID().Pretty()) + dest := fmt.Sprintf("/ip4/127.0.0.1/tcp/%v/p2p/%s", port1, h1.ID()) h2, err := makeHost(port2, rand.Reader) if err != nil { diff --git a/go-libp2p/examples/echo/README.md b/go-libp2p/examples/echo/README.md index 3807160..4c30609 100644 --- a/go-libp2p/examples/echo/README.md +++ b/go-libp2p/examples/echo/README.md @@ -42,7 +42,7 @@ The `makeBasicHost()` function creates a [go-libp2p-basichost](https://godoc.org In order to create the swarm (and a `basichost`), the example needs: -- An [ipfs-procotol ID](https://godoc.org/github.com/libp2p/go-libp2p-peer#ID) like `QmNtX1cvrm2K6mQmMEaMxAuB4rTexhd87vpYVot4sEZzxc`. The example autogenerates a key pair on every run and uses an ID extracted from the public key (the hash of the public key). When using `-insecure`, it leaves the connection unencrypted (otherwise, it uses the key pair to encrypt communications). +- An [ipfs-protocol ID](https://godoc.org/github.com/libp2p/go-libp2p-peer#ID) like `QmNtX1cvrm2K6mQmMEaMxAuB4rTexhd87vpYVot4sEZzxc`. The example autogenerates a key pair on every run and uses an ID extracted from the public key (the hash of the public key). When using `-insecure`, it leaves the connection unencrypted (otherwise, it uses the key pair to encrypt communications). - A [Multiaddress](https://godoc.org/github.com/multiformats/go-multiaddr), which indicates how to reach this peer. There can be several of them (using different protocols or locations for example). Example: `/ip4/127.0.0.1/tcp/1234`. - A [go-libp2p-peerstore](https://godoc.org/github.com/libp2p/go-libp2p-peerstore), which is used as an address book which matches node IDs to the multiaddresses through which they can be contacted. This peerstore gets autopopulated when manually opening a connection (with [`Connect()`](https://godoc.org/github.com/libp2p/go-libp2p/p2p/host/basic#BasicHost.Connect). Alternatively, we can manually [`AddAddr()`](https://godoc.org/github.com/libp2p/go-libp2p-peerstore#AddrManager.AddAddr) as in the example. diff --git a/go-libp2p/examples/echo/main.go b/go-libp2p/examples/echo/main.go index 3bba896..90c7248 100644 --- a/go-libp2p/examples/echo/main.go +++ b/go-libp2p/examples/echo/main.go @@ -88,7 +88,7 @@ func makeBasicHost(listenPort int, insecure bool, randseed int64) (host.Host, er func getHostAddress(ha host.Host) string { // Build host multiaddress - hostAddr, _ := ma.NewMultiaddr(fmt.Sprintf("/p2p/%s", ha.ID().Pretty())) + hostAddr, _ := ma.NewMultiaddr(fmt.Sprintf("/p2p/%s", ha.ID())) // Now we can build a full multiaddress to reach this host // by encapsulating both addresses: @@ -125,18 +125,6 @@ func runSender(ctx context.Context, ha host.Host, targetPeer string) { fullAddr := getHostAddress(ha) log.Printf("I am %s\n", fullAddr) - // Set a stream handler on host A. /echo/1.0.0 is - // a user-defined protocol name. - ha.SetStreamHandler("/echo/1.0.0", func(s network.Stream) { - log.Println("sender received new stream") - if err := doEcho(s); err != nil { - log.Println(err) - s.Reset() - } else { - s.Close() - } - }) - // Turn the targetPeer into a multiaddr. maddr, err := ma.NewMultiaddr(targetPeer) if err != nil { diff --git a/go-libp2p/examples/go.mod b/go-libp2p/examples/go.mod index feb9b15..578546a 100644 --- a/go-libp2p/examples/go.mod +++ b/go-libp2p/examples/go.mod @@ -1,16 +1,16 @@ module github.com/libp2p/go-libp2p/examples -go 1.19 +go 1.21 require ( github.com/gogo/protobuf v1.3.2 - github.com/google/uuid v1.3.0 + github.com/google/uuid v1.4.0 github.com/ipfs/go-datastore v0.6.0 github.com/ipfs/go-log/v2 v2.5.1 - github.com/libp2p/go-libp2p v0.29.0 - github.com/libp2p/go-libp2p-kad-dht v0.20.1-0.20230209220319-6c2045abad23 - github.com/multiformats/go-multiaddr v0.10.1 - github.com/prometheus/client_golang v1.14.0 + github.com/libp2p/go-libp2p v0.33.0 + github.com/libp2p/go-libp2p-kad-dht v0.25.1 + github.com/multiformats/go-multiaddr v0.12.2 + github.com/prometheus/client_golang v1.18.0 ) require ( @@ -23,46 +23,45 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect - github.com/flynn/noise v1.0.0 // indirect + github.com/flynn/noise v1.1.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect + github.com/go-logr/logr v1.3.0 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect - github.com/golang/mock v1.6.0 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/gopacket v1.1.19 // indirect - github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect - github.com/gorilla/websocket v1.5.0 // indirect + github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect + github.com/gorilla/websocket v1.5.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect - github.com/huin/goupnp v1.2.0 // indirect + github.com/huin/goupnp v1.3.0 // indirect + github.com/ipfs/boxo v0.10.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect - github.com/ipfs/go-ipfs-util v0.0.2 // indirect - github.com/ipfs/go-ipns v0.2.0 // indirect github.com/ipfs/go-log v1.0.5 // indirect - github.com/ipld/go-ipld-prime v0.16.0 // indirect + github.com/ipld/go-ipld-prime v0.20.0 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect github.com/jbenet/goprocess v0.1.4 // indirect - github.com/klauspost/compress v1.16.7 // indirect - github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/klauspost/compress v1.17.6 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/koron/go-ssdp v0.0.4 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-cidranger v1.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect - github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect - github.com/libp2p/go-libp2p-kbucket v0.5.0 // indirect + github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect + github.com/libp2p/go-libp2p-kbucket v0.6.3 // indirect github.com/libp2p/go-libp2p-record v0.2.0 // indirect + github.com/libp2p/go-libp2p-routing-helpers v0.7.2 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect github.com/libp2p/go-nat v0.2.0 // indirect github.com/libp2p/go-netroute v0.2.1 // indirect - github.com/libp2p/go-reuseport v0.3.0 // indirect + github.com/libp2p/go-reuseport v0.4.0 // indirect github.com/libp2p/go-yamux/v4 v4.0.1 // indirect github.com/libp2p/zeroconf/v2 v2.2.0 // indirect github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect - github.com/mattn/go-isatty v0.0.19 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/miekg/dns v1.1.55 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/miekg/dns v1.1.58 // indirect github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect github.com/minio/sha256-simd v1.0.1 // indirect @@ -74,39 +73,41 @@ require ( github.com/multiformats/go-multibase v0.2.0 // indirect github.com/multiformats/go-multicodec v0.9.0 // indirect github.com/multiformats/go-multihash v0.2.3 // indirect - github.com/multiformats/go-multistream v0.4.1 // indirect + github.com/multiformats/go-multistream v0.5.0 // indirect github.com/multiformats/go-varint v0.0.7 // indirect - github.com/onsi/ginkgo/v2 v2.11.0 // indirect - github.com/opencontainers/runtime-spec v1.0.2 // indirect + github.com/onsi/ginkgo/v2 v2.15.0 // indirect + github.com/opencontainers/runtime-spec v1.2.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e // indirect - github.com/prometheus/client_model v0.4.0 // indirect - github.com/prometheus/common v0.42.0 // indirect - github.com/prometheus/procfs v0.9.0 // indirect + github.com/polydawn/refmt v0.89.0 // indirect + github.com/prometheus/client_model v0.6.0 // indirect + github.com/prometheus/common v0.47.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.2.2 // indirect - github.com/quic-go/quic-go v0.36.2 // indirect - github.com/quic-go/webtransport-go v0.5.3 // indirect + github.com/quic-go/quic-go v0.41.0 // indirect + github.com/quic-go/webtransport-go v0.6.0 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect go.opencensus.io v0.24.0 // indirect - go.uber.org/atomic v1.11.0 // indirect - go.uber.org/dig v1.17.0 // indirect - go.uber.org/fx v1.20.0 // indirect + go.opentelemetry.io/otel v1.16.0 // indirect + go.opentelemetry.io/otel/metric v1.16.0 // indirect + go.opentelemetry.io/otel/trace v1.16.0 // indirect + go.uber.org/dig v1.17.1 // indirect + go.uber.org/fx v1.20.1 // indirect + go.uber.org/mock v0.4.0 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.11.0 // indirect - golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect - golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.12.0 // indirect - golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.10.0 // indirect - golang.org/x/text v0.11.0 // indirect - golang.org/x/tools v0.11.0 // indirect - google.golang.org/protobuf v1.30.0 // indirect + go.uber.org/zap v1.27.0 // indirect + golang.org/x/crypto v0.19.0 // indirect + golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect + golang.org/x/mod v0.15.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sync v0.6.0 // indirect + golang.org/x/sys v0.17.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.18.0 // indirect + gonum.org/v1/gonum v0.13.0 // indirect + google.golang.org/protobuf v1.32.0 // indirect lukechampine.com/blake3 v1.2.1 // indirect ) diff --git a/go-libp2p/examples/go.sum b/go-libp2p/examples/go.sum index 5ac4751..bae0579 100644 --- a/go-libp2p/examples/go.sum +++ b/go-libp2p/examples/go.sum @@ -33,13 +33,13 @@ github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8 github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= +github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= @@ -54,19 +54,24 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= -github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= +github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg= +github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= -github.com/frankban/quicktest v1.14.2 h1:SPb1KFFmM+ybpEjPUhCCkZOM5xlovT5UbrMvWnXyBns= -github.com/frankban/quicktest v1.14.2/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= +github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= @@ -76,13 +81,12 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -93,7 +97,6 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -104,27 +107,27 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 h1:n6vlPhxsA+BW/XsS5+uqi7GyzaLa5MH7qlSLBZtRdiA= -github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 h1:E/LAvt58di64hlYjx7AsNS6C/ysHWYo+2qPCZKTQhRo= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRidnzC1Oq86fpX1q/iEv2KJdrCtttYjT4= +github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -134,9 +137,10 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY= -github.com/huin/goupnp v1.2.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= -github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj6+M= +github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= +github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= +github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY= +github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk= @@ -145,15 +149,13 @@ github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-ipfs-util v0.0.2 h1:59Sswnk1MFaiq+VcaknX7aYEyGyGDAA73ilhEK2POp8= github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdrtMecczcsQ= -github.com/ipfs/go-ipns v0.2.0 h1:BgmNtQhqOw5XEZ8RAfWEpK4DhqaYiuP6h71MhIp7xXU= -github.com/ipfs/go-ipns v0.2.0/go.mod h1:3cLT2rbvgPZGkHJoPO1YMJeh6LtkxopCkKFcio/wE24= github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= github.com/ipfs/go-log/v2 v2.1.3/go.mod h1:/8d0SH3Su5Ooc31QlL1WysJhvyOTDCjcCZ9Axpmri6g= github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= -github.com/ipld/go-ipld-prime v0.16.0 h1:RS5hhjB/mcpeEPJvfyj0qbOj/QL+/j05heZ0qa97dVo= -github.com/ipld/go-ipld-prime v0.16.0/go.mod h1:axSCuOCBPqrH+gvXr2w9uAOulJqBPhHPT2PjoiiU1qA= +github.com/ipld/go-ipld-prime v0.20.0 h1:Ud3VwE9ClxpO2LkCYP7vWPc0Fo+dYdYzgxUJZ3uRG4g= +github.com/ipld/go-ipld-prime v0.20.0/go.mod h1:PzqZ/ZR981eKbgdr3y2DJYeD/8bgMawdGVlJDE8kK+M= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= @@ -169,18 +171,16 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= -github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= -github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI= +github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -192,25 +192,28 @@ github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38y github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic= github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM= github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= -github.com/libp2p/go-libp2p v0.29.0 h1:QduJ2XQr/Crg4EnloueWDL0Jj86N3Ezhyyj7XH+XwHI= -github.com/libp2p/go-libp2p v0.29.0/go.mod h1:iNKL7mEnZ9wAss+03IjAwM9ZAQXfVUAPUUmOACQfQ/g= -github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= -github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w= -github.com/libp2p/go-libp2p-kad-dht v0.20.1-0.20230209220319-6c2045abad23 h1:VGjUg3I0gLugtjZKI4kzvPiptmfYhWHK6YGBI4ZI2Cs= -github.com/libp2p/go-libp2p-kad-dht v0.20.1-0.20230209220319-6c2045abad23/go.mod h1:ScWrKlutIaRETyELjPNXUO2TekuzLsE5nCBVuNR9l0g= -github.com/libp2p/go-libp2p-kbucket v0.5.0 h1:g/7tVm8ACHDxH29BGrpsQlnNeu+6OF1A9bno/4/U1oA= -github.com/libp2p/go-libp2p-kbucket v0.5.0/go.mod h1:zGzGCpQd78b5BNTDGHNDLaTt9aDK/A02xeZp9QeFC4U= +github.com/libp2p/go-libp2p v0.33.0 h1:yTPSr8sJRbfeEYXyeN8VPVSlTlFjtMUwGDRniwaf/xQ= +github.com/libp2p/go-libp2p v0.33.0/go.mod h1:RIJFRQVUBKy82dnW7J5f1homqqv6NcsDJAl3e7CRGfE= +github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94= +github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8= +github.com/libp2p/go-libp2p-kad-dht v0.25.1 h1:ofFNrf6MMEy4vi3R1VbJ7LOcTn3Csh0cDcaWHTxtWNA= +github.com/libp2p/go-libp2p-kad-dht v0.25.1/go.mod h1:6za56ncRHYXX4Nc2vn8z7CZK0P4QiMcrn77acKLM2Oo= +github.com/libp2p/go-libp2p-kbucket v0.6.3 h1:p507271wWzpy2f1XxPzCQG9NiN6R6lHL9GiSErbQQo0= +github.com/libp2p/go-libp2p-kbucket v0.6.3/go.mod h1:RCseT7AH6eJWxxk2ol03xtP9pEHetYSPXOaJnOiD8i0= github.com/libp2p/go-libp2p-record v0.2.0 h1:oiNUOCWno2BFuxt3my4i1frNrt7PerzB3queqa1NkQ0= github.com/libp2p/go-libp2p-record v0.2.0/go.mod h1:I+3zMkvvg5m2OcSdoL0KPljyJyvNDFGKX7QdlpYUcwk= +github.com/libp2p/go-libp2p-routing-helpers v0.7.2 h1:xJMFyhQ3Iuqnk9Q2dYE1eUTzsah7NLw3Qs2zjUV78T0= +github.com/libp2p/go-libp2p-routing-helpers v0.7.2/go.mod h1:cN4mJAD/7zfPKXBcs9ze31JGYAZgzdABEm+q/hkswb8= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= +github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk= github.com/libp2p/go-nat v0.2.0/go.mod h1:3MJr+GRpRkyT65EpVPBstXLvOlAPzUVlG6Pwg9ohLJk= github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU= github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ= -github.com/libp2p/go-reuseport v0.3.0 h1:iiZslO5byUYZEg9iCwJGf5h+sf1Agmqx2V2FDjPyvUw= -github.com/libp2p/go-reuseport v0.3.0/go.mod h1:laea40AimhtfEqysZ71UpYj4S+R9VpH8PgqLo7L+SwI= +github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s= +github.com/libp2p/go-reuseport v0.4.0/go.mod h1:ZtI03j/wO5hZVDFo2jKywN6bYKWLOy8Se6DrI2E1cLU= github.com/libp2p/go-yamux/v4 v4.0.1 h1:FfDR4S1wj6Bw2Pqbc8Uz7pCxeRBPbwsBbEdfwiCypkQ= github.com/libp2p/go-yamux/v4 v4.0.1/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4= github.com/libp2p/zeroconf/v2 v2.2.0 h1:Cup06Jv6u81HLhIj1KasuNM/RHHrJ8T7wOTS4+Tv53Q= @@ -220,16 +223,14 @@ github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= -github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo= -github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= +github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4= +github.com/miekg/dns v1.1.58/go.mod h1:Ypv+3b/KadlvW9vJfXOTf300O4UqaHFzFCuHz+rPkBY= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c h1:bzE/A84HN25pxAuk9Eej1Kz9OUelF97nAc82bDquQI8= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c/go.mod h1:0SQS9kMwD2VsyFEB++InYyBJroV/FRmBgcydeSUcJms= github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b h1:z78hV3sbSMAUoyUMM0I83AUIT6Hu17AWfgjzIbtrYFc= @@ -238,55 +239,46 @@ github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc h1:PTfri+PuQmWDqERdn github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc/go.mod h1:cGKTAVKx4SxOuR/czcZ/E2RSJ3sfHs8FpHhQ5CWMf9s= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= -github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE= github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI= github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= -github.com/multiformats/go-multiaddr v0.10.1 h1:HghtFrWyZEPrpTvgAMFJi6gFdgHfs2cb0pyfDsk+lqU= -github.com/multiformats/go-multiaddr v0.10.1/go.mod h1:jLEZsA61rwWNZQTHHnqq2HNa+4os/Hz54eqiRnsRqYQ= +github.com/multiformats/go-multiaddr v0.12.2 h1:9G9sTY/wCYajKa9lyfWPmpZAwe6oV+Wb1zcmMS1HG24= +github.com/multiformats/go-multiaddr v0.12.2/go.mod h1:GKyaTYjZRdcUhyOetrxTk9z0cW+jA/YrnqTOvKgi44M= github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= github.com/multiformats/go-multiaddr-fmt v0.1.0/go.mod h1:hGtDIW4PU4BqJ50gW2quDuPVjyWNZxToGUh/HwTZYJo= -github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g= github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk= -github.com/multiformats/go-multicodec v0.3.0/go.mod h1:qGGaQmioCDh+TeFOnxrbU0DaIPw8yFgAZgFG0V7p1qQ= github.com/multiformats/go-multicodec v0.9.0 h1:pb/dlPnzee/Sxv/j4PmkDRxCOi3hXTz3IbPKOXWJkmg= github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k= github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= -github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= -github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= -github.com/multiformats/go-multihash v0.1.0/go.mod h1:RJlXsxt6vHGaia+S8We0ErjhojtKzPP2AH4+kYM7k84= github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= -github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3de4741sbiSdfo= -github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= +github.com/multiformats/go-multistream v0.5.0 h1:5htLSLl7lvJk3xx3qT/8Zm9J4K8vEOf/QGkvOGQAyiE= +github.com/multiformats/go-multistream v0.5.0/go.mod h1:n6tMZiwiP2wUsR8DgfDWw1dydlEqV3l6N3/GBsX6ILA= github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= -github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= -github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= -github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= -github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= -github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc= -github.com/opencontainers/runtime-spec v1.0.2 h1:UfAcuLBJB9Coz72x1hgl8O5RVzTdNiaglX6v2DM6FI0= +github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= +github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= +github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= +github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= +github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk= +github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= @@ -297,36 +289,32 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e h1:ZOcivgkkFRnjfoTcGsDq3UQYiBmekwLA+qg0OjyB/ls= -github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o= +github.com/polydawn/refmt v0.89.0 h1:ADJTApkvkeBZsN0tBTx8QjpD9JkmxbKp0cxfr9qszm4= +github.com/polydawn/refmt v0.89.0/go.mod h1:/zvteZs/GwLtCgZ4BL6CBsk9IKIlexP43ObX9AxTqTw= github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= -github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= +github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= +github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= -github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= +github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= +github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= -github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= +github.com/prometheus/common v0.47.0 h1:p5Cz0FNHo7SnWOmWmoRozVcjEp0bIVU8cV7OShpjL1k= +github.com/prometheus/common v0.47.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= -github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= -github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= -github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.36.2 h1:ZX/UNQ4gvpCv2RmwdbA6lrRjF6EBm5yZ7TMoT4NQVrA= -github.com/quic-go/quic-go v0.36.2/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= -github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= -github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= +github.com/quic-go/quic-go v0.41.0 h1:aD8MmHfgqTURWNJy48IYFg2OnxwHT3JL7ahGs73lb4k= +github.com/quic-go/quic-go v0.41.0/go.mod h1:qCkNjqczPEvgsOnxZ0eCD14lv+B2LHlFAB++CNOh9hA= +github.com/quic-go/webtransport-go v0.6.0 h1:CvNsKqc4W2HljHJnoT+rMmbRJybShZ0YPFDD3NxaZLY= +github.com/quic-go/webtransport-go v0.6.0/go.mod h1:9KjU4AEBqEQidGHNDkZrb8CAa1abRaosM2yGOyiikEc= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= @@ -354,10 +342,10 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4= github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= +github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= +github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg= +github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM= github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= @@ -374,13 +362,14 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM= -github.com/warpfork/go-testmark v0.3.0/go.mod h1:jhEf8FVxd+F17juRubpmut64NEG6I2rgkUhlcqqXwE0= -github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a h1:G++j5e0OC488te356JvdhaM8YS6nMsjLAYF7JxCv07w= -github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= +github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0 h1:GDDkbFiaK8jsSDJfjId/PEGEShv6ugrt4kYsC5UIDaQ= +github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -389,16 +378,25 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1 go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= +go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s= +go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4= +go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26Q3hqOo= +go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4= +go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs= +go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI= -go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU= -go.uber.org/fx v1.20.0 h1:ZMC/pnRvhsthOZh9MZjMq5U8Or3mA9zBSPaLnzs3ihQ= -go.uber.org/fx v1.20.0/go.mod h1:qCUj0btiR3/JnanEr1TYEePfSw6o/4qYJscgvzQ5Ub0= +go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc= +go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE= +go.uber.org/fx v1.20.1 h1:zVwVQGS8zYvhh9Xxcu4w1M6ESyeMzebzj2NbSayZ4Mk= +go.uber.org/fx v1.20.1/go.mod h1:iSYNbHf2y55acNCwCXKx7LbWb5WG1Bnue5RDXz1OREg= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -406,8 +404,8 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8 go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= -go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -418,13 +416,12 @@ golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= -golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw= -golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE= +golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -436,8 +433,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= +golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -456,8 +453,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= -golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -471,8 +468,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -486,7 +483,6 @@ golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210426080607-c94f62235c83/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -494,16 +490,15 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= -golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -522,14 +517,15 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= -golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= +golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= +golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gonum.org/v1/gonum v0.13.0 h1:a0T3bh+7fhRyqeNbiC3qVHYmkiQgit3wnNan/2c0HMM= +gonum.org/v1/gonum v0.13.0/go.mod h1:/WPYRckkfWrhWefxyYTfrTtQR0KH4iyHNuzxqXAKyAU= google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y= @@ -561,10 +557,8 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= +google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= @@ -586,7 +580,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -lukechampine.com/blake3 v1.1.6/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA= lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI= lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck= diff --git a/go-libp2p/examples/http-proxy/proxy.go b/go-libp2p/examples/http-proxy/proxy.go index 27d9597..f96d4b8 100644 --- a/go-libp2p/examples/http-proxy/proxy.go +++ b/go-libp2p/examples/http-proxy/proxy.go @@ -144,7 +144,7 @@ func (p *ProxyService) Serve() { // Streams are multiplexed over single connections so, unlike connections // themselves, they are cheap to create and dispose of. func (p *ProxyService) ServeHTTP(w http.ResponseWriter, r *http.Request) { - fmt.Printf("proxying request for %s to peer %s\n", r.URL, p.dest.Pretty()) + fmt.Printf("proxying request for %s to peer %s\n", r.URL, p.dest) // We need to send the request to the remote libp2p peer, so // we open a stream to it stream, err := p.host.NewStream(context.Background(), p.dest, Protocol) diff --git a/go-libp2p/examples/ipfs-camp-2019/05-Discovery/main.go b/go-libp2p/examples/ipfs-camp-2019/05-Discovery/main.go index 51d5a6f..0f3446d 100644 --- a/go-libp2p/examples/ipfs-camp-2019/05-Discovery/main.go +++ b/go-libp2p/examples/ipfs-camp-2019/05-Discovery/main.go @@ -9,7 +9,6 @@ import ( "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/p2p/muxer/mplex" "github.com/libp2p/go-libp2p/p2p/muxer/yamux" tls "github.com/libp2p/go-libp2p/p2p/security/tls" "github.com/libp2p/go-libp2p/p2p/transport/tcp" @@ -27,10 +26,7 @@ func main() { libp2p.Transport(websocket.New), ) - muxers := libp2p.ChainOptions( - libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport), - libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport), - ) + muxers := libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport) security := libp2p.Security(tls.ID, tls.New) diff --git a/go-libp2p/examples/ipfs-camp-2019/06-Pubsub/main.go b/go-libp2p/examples/ipfs-camp-2019/06-Pubsub/main.go index 9034541..af7cab2 100644 --- a/go-libp2p/examples/ipfs-camp-2019/06-Pubsub/main.go +++ b/go-libp2p/examples/ipfs-camp-2019/06-Pubsub/main.go @@ -16,7 +16,6 @@ import ( "github.com/libp2p/go-libp2p/p2p/discovery/mdns" drouting "github.com/libp2p/go-libp2p/p2p/discovery/routing" dutil "github.com/libp2p/go-libp2p/p2p/discovery/util" - "github.com/libp2p/go-libp2p/p2p/muxer/mplex" "github.com/libp2p/go-libp2p/p2p/muxer/yamux" tls "github.com/libp2p/go-libp2p/p2p/security/tls" "github.com/libp2p/go-libp2p/p2p/transport/tcp" @@ -46,10 +45,7 @@ func main() { libp2p.Transport(websocket.New), ) - muxers := libp2p.ChainOptions( - libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport), - libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport), - ) + muxers := libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport) security := libp2p.Security(tls.ID, tls.New) diff --git a/go-libp2p/examples/ipfs-camp-2019/07-Messaging/main.go b/go-libp2p/examples/ipfs-camp-2019/07-Messaging/main.go index 84840d7..b758e21 100644 --- a/go-libp2p/examples/ipfs-camp-2019/07-Messaging/main.go +++ b/go-libp2p/examples/ipfs-camp-2019/07-Messaging/main.go @@ -9,7 +9,6 @@ import ( "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/p2p/discovery/mdns" - "github.com/libp2p/go-libp2p/p2p/muxer/mplex" "github.com/libp2p/go-libp2p/p2p/muxer/yamux" tls "github.com/libp2p/go-libp2p/p2p/security/tls" "github.com/libp2p/go-libp2p/p2p/transport/tcp" @@ -42,10 +41,7 @@ func main() { libp2p.Transport(websocket.New), ) - muxers := libp2p.ChainOptions( - libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport), - libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport), - ) + muxers := libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport) security := libp2p.Security(tls.ID, tls.New) diff --git a/go-libp2p/examples/ipfs-camp-2019/08-End/main.go b/go-libp2p/examples/ipfs-camp-2019/08-End/main.go index bc29152..e3ef953 100644 --- a/go-libp2p/examples/ipfs-camp-2019/08-End/main.go +++ b/go-libp2p/examples/ipfs-camp-2019/08-End/main.go @@ -14,7 +14,6 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" "github.com/libp2p/go-libp2p/p2p/discovery/mdns" - "github.com/libp2p/go-libp2p/p2p/muxer/mplex" "github.com/libp2p/go-libp2p/p2p/muxer/yamux" tls "github.com/libp2p/go-libp2p/p2p/security/tls" "github.com/libp2p/go-libp2p/p2p/transport/tcp" @@ -41,10 +40,7 @@ func main() { libp2p.Transport(websocket.New), ) - muxers := libp2p.ChainOptions( - libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport), - libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport), - ) + muxers := libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport) security := libp2p.Security(tls.ID, tls.New) diff --git a/go-libp2p/examples/ipfs-camp-2019/go.mod b/go-libp2p/examples/ipfs-camp-2019/go.mod index 2bcabeb..0d0b29c 100644 --- a/go-libp2p/examples/ipfs-camp-2019/go.mod +++ b/go-libp2p/examples/ipfs-camp-2019/go.mod @@ -1,13 +1,13 @@ module github.com/libp2p/go-libp2p/examples/ipfs-camp-2019 -go 1.19 +go 1.21 require ( github.com/gogo/protobuf v1.3.2 - github.com/libp2p/go-libp2p v0.28.0 - github.com/libp2p/go-libp2p-kad-dht v0.21.0 - github.com/libp2p/go-libp2p-pubsub v0.9.0 - github.com/multiformats/go-multiaddr v0.9.0 + github.com/libp2p/go-libp2p v0.33.0 + github.com/libp2p/go-libp2p-kad-dht v0.25.1 + github.com/libp2p/go-libp2p-pubsub v0.10.0 + github.com/multiformats/go-multiaddr v0.12.2 ) require ( @@ -20,52 +20,49 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect - github.com/emirpasic/gods v1.18.1 // indirect - github.com/flynn/noise v1.0.0 // indirect + github.com/flynn/noise v1.1.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect + github.com/go-logr/logr v1.3.0 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect - github.com/golang/mock v1.6.0 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/gopacket v1.1.19 // indirect - github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 // indirect - github.com/google/uuid v1.3.0 // indirect - github.com/gorilla/websocket v1.5.0 // indirect + github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect + github.com/google/uuid v1.4.0 // indirect + github.com/gorilla/websocket v1.5.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect - github.com/hashicorp/golang-lru/v2 v2.0.2 // indirect - github.com/huin/goupnp v1.2.0 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect + github.com/huin/goupnp v1.3.0 // indirect + github.com/ipfs/boxo v0.10.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect - github.com/ipfs/go-ipfs-util v0.0.2 // indirect - github.com/ipfs/go-ipns v0.2.0 // indirect github.com/ipfs/go-log v1.0.5 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect - github.com/ipld/go-ipld-prime v0.16.0 // indirect + github.com/ipld/go-ipld-prime v0.20.0 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect github.com/jbenet/goprocess v0.1.4 // indirect - github.com/klauspost/compress v1.16.5 // indirect - github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/klauspost/compress v1.17.6 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/koron/go-ssdp v0.0.4 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-cidranger v1.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect - github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect - github.com/libp2p/go-libp2p-kbucket v0.5.0 // indirect + github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect + github.com/libp2p/go-libp2p-kbucket v0.6.3 // indirect github.com/libp2p/go-libp2p-record v0.2.0 // indirect - github.com/libp2p/go-mplex v0.7.0 // indirect + github.com/libp2p/go-libp2p-routing-helpers v0.7.2 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect github.com/libp2p/go-nat v0.2.0 // indirect github.com/libp2p/go-netroute v0.2.1 // indirect - github.com/libp2p/go-reuseport v0.3.0 // indirect - github.com/libp2p/go-yamux/v4 v4.0.0 // indirect + github.com/libp2p/go-reuseport v0.4.0 // indirect + github.com/libp2p/go-yamux/v4 v4.0.1 // indirect github.com/libp2p/zeroconf/v2 v2.2.0 // indirect github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect - github.com/mattn/go-isatty v0.0.19 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/miekg/dns v1.1.54 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/miekg/dns v1.1.58 // indirect github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect github.com/minio/sha256-simd v1.0.1 // indirect @@ -76,41 +73,43 @@ require ( github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect github.com/multiformats/go-multibase v0.2.0 // indirect github.com/multiformats/go-multicodec v0.9.0 // indirect - github.com/multiformats/go-multihash v0.2.2 // indirect - github.com/multiformats/go-multistream v0.4.1 // indirect + github.com/multiformats/go-multihash v0.2.3 // indirect + github.com/multiformats/go-multistream v0.5.0 // indirect github.com/multiformats/go-varint v0.0.7 // indirect - github.com/onsi/ginkgo/v2 v2.9.7 // indirect - github.com/opencontainers/runtime-spec v1.0.2 // indirect + github.com/onsi/ginkgo/v2 v2.15.0 // indirect + github.com/opencontainers/runtime-spec v1.2.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e // indirect - github.com/prometheus/client_golang v1.14.0 // indirect - github.com/prometheus/client_model v0.4.0 // indirect - github.com/prometheus/common v0.42.0 // indirect - github.com/prometheus/procfs v0.9.0 // indirect + github.com/polydawn/refmt v0.89.0 // indirect + github.com/prometheus/client_golang v1.18.0 // indirect + github.com/prometheus/client_model v0.6.0 // indirect + github.com/prometheus/common v0.47.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.2.2 // indirect - github.com/quic-go/quic-go v0.33.0 // indirect - github.com/quic-go/webtransport-go v0.5.3 // indirect + github.com/quic-go/quic-go v0.41.0 // indirect + github.com/quic-go/webtransport-go v0.6.0 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect go.opencensus.io v0.24.0 // indirect - go.uber.org/atomic v1.11.0 // indirect - go.uber.org/dig v1.17.0 // indirect - go.uber.org/fx v1.19.2 // indirect + go.opentelemetry.io/otel v1.16.0 // indirect + go.opentelemetry.io/otel/metric v1.16.0 // indirect + go.opentelemetry.io/otel/trace v1.16.0 // indirect + go.uber.org/dig v1.17.1 // indirect + go.uber.org/fx v1.20.1 // indirect + go.uber.org/mock v0.4.0 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.7.0 // indirect - golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect - golang.org/x/mod v0.10.0 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect - golang.org/x/tools v0.9.1 // indirect - google.golang.org/protobuf v1.30.0 // indirect + go.uber.org/zap v1.27.0 // indirect + golang.org/x/crypto v0.19.0 // indirect + golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect + golang.org/x/mod v0.15.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sync v0.6.0 // indirect + golang.org/x/sys v0.17.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.18.0 // indirect + gonum.org/v1/gonum v0.13.0 // indirect + google.golang.org/protobuf v1.32.0 // indirect lukechampine.com/blake3 v1.2.1 // indirect ) diff --git a/go-libp2p/examples/ipfs-camp-2019/go.sum b/go-libp2p/examples/ipfs-camp-2019/go.sum index 23a9792..fecbd95 100644 --- a/go-libp2p/examples/ipfs-camp-2019/go.sum +++ b/go-libp2p/examples/ipfs-camp-2019/go.sum @@ -33,13 +33,13 @@ github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8 github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= +github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= @@ -49,26 +49,29 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/elastic/gosigar v0.12.0/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/4= github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= -github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= -github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= -github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= +github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg= +github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= -github.com/frankban/quicktest v1.14.2 h1:SPb1KFFmM+ybpEjPUhCCkZOM5xlovT5UbrMvWnXyBns= -github.com/frankban/quicktest v1.14.2/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= +github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= @@ -78,13 +81,12 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -95,7 +97,6 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -106,27 +107,27 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 h1:hR7/MlvK23p6+lIw9SN1TigNLn9ZnF3W4SYRKq2gAHs= -github.com/google/pprof v0.0.0-20230602150820-91b7bce49751/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 h1:E/LAvt58di64hlYjx7AsNS6C/ysHWYo+2qPCZKTQhRo= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRidnzC1Oq86fpX1q/iEv2KJdrCtttYjT4= +github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -136,11 +137,12 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/golang-lru/v2 v2.0.2 h1:Dwmkdr5Nc/oBiXgJS3CDHNhJtIHkuZ3DZF5twqnfBdU= -github.com/hashicorp/golang-lru/v2 v2.0.2/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= -github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY= -github.com/huin/goupnp v1.2.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= -github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj6+M= +github.com/hashicorp/golang-lru/v2 v2.0.5 h1:wW7h1TG88eUIJ2i69gaE3uNVtEPIagzhGvHgwfx2Vm4= +github.com/hashicorp/golang-lru/v2 v2.0.5/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= +github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= +github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY= +github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk= @@ -149,15 +151,13 @@ github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-ipfs-util v0.0.2 h1:59Sswnk1MFaiq+VcaknX7aYEyGyGDAA73ilhEK2POp8= github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdrtMecczcsQ= -github.com/ipfs/go-ipns v0.2.0 h1:BgmNtQhqOw5XEZ8RAfWEpK4DhqaYiuP6h71MhIp7xXU= -github.com/ipfs/go-ipns v0.2.0/go.mod h1:3cLT2rbvgPZGkHJoPO1YMJeh6LtkxopCkKFcio/wE24= github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= github.com/ipfs/go-log/v2 v2.1.3/go.mod h1:/8d0SH3Su5Ooc31QlL1WysJhvyOTDCjcCZ9Axpmri6g= github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= -github.com/ipld/go-ipld-prime v0.16.0 h1:RS5hhjB/mcpeEPJvfyj0qbOj/QL+/j05heZ0qa97dVo= -github.com/ipld/go-ipld-prime v0.16.0/go.mod h1:axSCuOCBPqrH+gvXr2w9uAOulJqBPhHPT2PjoiiU1qA= +github.com/ipld/go-ipld-prime v0.20.0 h1:Ud3VwE9ClxpO2LkCYP7vWPc0Fo+dYdYzgxUJZ3uRG4g= +github.com/ipld/go-ipld-prime v0.20.0/go.mod h1:PzqZ/ZR981eKbgdr3y2DJYeD/8bgMawdGVlJDE8kK+M= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= @@ -173,18 +173,16 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= -github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= -github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI= +github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -196,31 +194,32 @@ github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38y github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic= github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM= github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= -github.com/libp2p/go-libp2p v0.28.0 h1:zO8cY98nJiPzZpFv5w5gqqb8aVzt4ukQ0nVOSaaKhJ8= -github.com/libp2p/go-libp2p v0.28.0/go.mod h1:s3Xabc9LSwOcnv9UD4nORnXKTsWkPMkIMB/JIGXVnzk= -github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= -github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w= -github.com/libp2p/go-libp2p-kad-dht v0.21.0 h1:J0Yd22VA+sk0CJRGMgtfHvLVIkZDyJ3AJGiljywIw5U= -github.com/libp2p/go-libp2p-kad-dht v0.21.0/go.mod h1:Bhm9diAFmc6qcWAr084bHNL159srVZRKADdp96Qqd1I= -github.com/libp2p/go-libp2p-kbucket v0.5.0 h1:g/7tVm8ACHDxH29BGrpsQlnNeu+6OF1A9bno/4/U1oA= -github.com/libp2p/go-libp2p-kbucket v0.5.0/go.mod h1:zGzGCpQd78b5BNTDGHNDLaTt9aDK/A02xeZp9QeFC4U= -github.com/libp2p/go-libp2p-pubsub v0.9.0 h1:mcLb4WzwhUG4OKb0rp1/bYMd/DYhvMyzJheQH3LMd1s= -github.com/libp2p/go-libp2p-pubsub v0.9.0/go.mod h1:OEsj0Cc/BpkqikXRTrVspWU/Hx7bMZwHP+6vNMd+c7I= +github.com/libp2p/go-libp2p v0.33.0 h1:yTPSr8sJRbfeEYXyeN8VPVSlTlFjtMUwGDRniwaf/xQ= +github.com/libp2p/go-libp2p v0.33.0/go.mod h1:RIJFRQVUBKy82dnW7J5f1homqqv6NcsDJAl3e7CRGfE= +github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94= +github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8= +github.com/libp2p/go-libp2p-kad-dht v0.25.1 h1:ofFNrf6MMEy4vi3R1VbJ7LOcTn3Csh0cDcaWHTxtWNA= +github.com/libp2p/go-libp2p-kad-dht v0.25.1/go.mod h1:6za56ncRHYXX4Nc2vn8z7CZK0P4QiMcrn77acKLM2Oo= +github.com/libp2p/go-libp2p-kbucket v0.6.3 h1:p507271wWzpy2f1XxPzCQG9NiN6R6lHL9GiSErbQQo0= +github.com/libp2p/go-libp2p-kbucket v0.6.3/go.mod h1:RCseT7AH6eJWxxk2ol03xtP9pEHetYSPXOaJnOiD8i0= +github.com/libp2p/go-libp2p-pubsub v0.10.0 h1:wS0S5FlISavMaAbxyQn3dxMOe2eegMfswM471RuHJwA= +github.com/libp2p/go-libp2p-pubsub v0.10.0/go.mod h1:1OxbaT/pFRO5h+Dpze8hdHQ63R0ke55XTs6b6NwLLkw= github.com/libp2p/go-libp2p-record v0.2.0 h1:oiNUOCWno2BFuxt3my4i1frNrt7PerzB3queqa1NkQ0= github.com/libp2p/go-libp2p-record v0.2.0/go.mod h1:I+3zMkvvg5m2OcSdoL0KPljyJyvNDFGKX7QdlpYUcwk= +github.com/libp2p/go-libp2p-routing-helpers v0.7.2 h1:xJMFyhQ3Iuqnk9Q2dYE1eUTzsah7NLw3Qs2zjUV78T0= +github.com/libp2p/go-libp2p-routing-helpers v0.7.2/go.mod h1:cN4mJAD/7zfPKXBcs9ze31JGYAZgzdABEm+q/hkswb8= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= -github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY= -github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU= +github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk= github.com/libp2p/go-nat v0.2.0/go.mod h1:3MJr+GRpRkyT65EpVPBstXLvOlAPzUVlG6Pwg9ohLJk= github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU= github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ= -github.com/libp2p/go-reuseport v0.3.0 h1:iiZslO5byUYZEg9iCwJGf5h+sf1Agmqx2V2FDjPyvUw= -github.com/libp2p/go-reuseport v0.3.0/go.mod h1:laea40AimhtfEqysZ71UpYj4S+R9VpH8PgqLo7L+SwI= -github.com/libp2p/go-yamux/v4 v4.0.0 h1:+Y80dV2Yx/kv7Y7JKu0LECyVdMXm1VUoko+VQ9rBfZQ= -github.com/libp2p/go-yamux/v4 v4.0.0/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4= +github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s= +github.com/libp2p/go-reuseport v0.4.0/go.mod h1:ZtI03j/wO5hZVDFo2jKywN6bYKWLOy8Se6DrI2E1cLU= +github.com/libp2p/go-yamux/v4 v4.0.1 h1:FfDR4S1wj6Bw2Pqbc8Uz7pCxeRBPbwsBbEdfwiCypkQ= +github.com/libp2p/go-yamux/v4 v4.0.1/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4= github.com/libp2p/zeroconf/v2 v2.2.0 h1:Cup06Jv6u81HLhIj1KasuNM/RHHrJ8T7wOTS4+Tv53Q= github.com/libp2p/zeroconf/v2 v2.2.0/go.mod h1:fuJqLnUwZTshS3U/bMRJ3+ow/v9oid1n0DmyYyNO1Xs= github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= @@ -228,16 +227,14 @@ github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= -github.com/miekg/dns v1.1.54 h1:5jon9mWcb0sFJGpnI99tOMhCPyJ+RPVz5b63MQG0VWI= -github.com/miekg/dns v1.1.54/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= +github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4= +github.com/miekg/dns v1.1.58/go.mod h1:Ypv+3b/KadlvW9vJfXOTf300O4UqaHFzFCuHz+rPkBY= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c h1:bzE/A84HN25pxAuk9Eej1Kz9OUelF97nAc82bDquQI8= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c/go.mod h1:0SQS9kMwD2VsyFEB++InYyBJroV/FRmBgcydeSUcJms= github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b h1:z78hV3sbSMAUoyUMM0I83AUIT6Hu17AWfgjzIbtrYFc= @@ -246,55 +243,46 @@ github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc h1:PTfri+PuQmWDqERdn github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc/go.mod h1:cGKTAVKx4SxOuR/czcZ/E2RSJ3sfHs8FpHhQ5CWMf9s= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= -github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE= github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI= github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= -github.com/multiformats/go-multiaddr v0.9.0 h1:3h4V1LHIk5w4hJHekMKWALPXErDfz/sggzwC/NcqbDQ= -github.com/multiformats/go-multiaddr v0.9.0/go.mod h1:mI67Lb1EeTOYb8GQfL/7wpIZwc46ElrvzhYnoJOmTT0= +github.com/multiformats/go-multiaddr v0.12.2 h1:9G9sTY/wCYajKa9lyfWPmpZAwe6oV+Wb1zcmMS1HG24= +github.com/multiformats/go-multiaddr v0.12.2/go.mod h1:GKyaTYjZRdcUhyOetrxTk9z0cW+jA/YrnqTOvKgi44M= github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= github.com/multiformats/go-multiaddr-fmt v0.1.0/go.mod h1:hGtDIW4PU4BqJ50gW2quDuPVjyWNZxToGUh/HwTZYJo= -github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g= github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk= -github.com/multiformats/go-multicodec v0.3.0/go.mod h1:qGGaQmioCDh+TeFOnxrbU0DaIPw8yFgAZgFG0V7p1qQ= github.com/multiformats/go-multicodec v0.9.0 h1:pb/dlPnzee/Sxv/j4PmkDRxCOi3hXTz3IbPKOXWJkmg= github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k= github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= -github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= -github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= -github.com/multiformats/go-multihash v0.1.0/go.mod h1:RJlXsxt6vHGaia+S8We0ErjhojtKzPP2AH4+kYM7k84= -github.com/multiformats/go-multihash v0.2.2 h1:Uu7LWs/PmWby1gkj1S1DXx3zyd3aVabA4FiMKn/2tAc= -github.com/multiformats/go-multihash v0.2.2/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= -github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3de4741sbiSdfo= -github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= +github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= +github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= +github.com/multiformats/go-multistream v0.5.0 h1:5htLSLl7lvJk3xx3qT/8Zm9J4K8vEOf/QGkvOGQAyiE= +github.com/multiformats/go-multistream v0.5.0/go.mod h1:n6tMZiwiP2wUsR8DgfDWw1dydlEqV3l6N3/GBsX6ILA= github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= -github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= -github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= -github.com/onsi/ginkgo/v2 v2.9.7 h1:06xGQy5www2oN160RtEZoTvnP2sPhEfePYmCDc2szss= -github.com/onsi/ginkgo/v2 v2.9.7/go.mod h1:cxrmXWykAwTwhQsJOPfdIDiJ+l2RYq7U8hFU+M/1uw0= -github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU= -github.com/opencontainers/runtime-spec v1.0.2 h1:UfAcuLBJB9Coz72x1hgl8O5RVzTdNiaglX6v2DM6FI0= +github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= +github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= +github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= +github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= +github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk= +github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= @@ -305,36 +293,32 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e h1:ZOcivgkkFRnjfoTcGsDq3UQYiBmekwLA+qg0OjyB/ls= -github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o= +github.com/polydawn/refmt v0.89.0 h1:ADJTApkvkeBZsN0tBTx8QjpD9JkmxbKp0cxfr9qszm4= +github.com/polydawn/refmt v0.89.0/go.mod h1:/zvteZs/GwLtCgZ4BL6CBsk9IKIlexP43ObX9AxTqTw= github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= -github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= +github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= +github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= -github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= +github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= +github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= -github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= +github.com/prometheus/common v0.47.0 h1:p5Cz0FNHo7SnWOmWmoRozVcjEp0bIVU8cV7OShpjL1k= +github.com/prometheus/common v0.47.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= -github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= -github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= -github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0= -github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA= -github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= -github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= +github.com/quic-go/quic-go v0.41.0 h1:aD8MmHfgqTURWNJy48IYFg2OnxwHT3JL7ahGs73lb4k= +github.com/quic-go/quic-go v0.41.0/go.mod h1:qCkNjqczPEvgsOnxZ0eCD14lv+B2LHlFAB++CNOh9hA= +github.com/quic-go/webtransport-go v0.6.0 h1:CvNsKqc4W2HljHJnoT+rMmbRJybShZ0YPFDD3NxaZLY= +github.com/quic-go/webtransport-go v0.6.0/go.mod h1:9KjU4AEBqEQidGHNDkZrb8CAa1abRaosM2yGOyiikEc= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= @@ -362,10 +346,10 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4= github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= +github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= +github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg= +github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM= github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= @@ -381,14 +365,15 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM= -github.com/warpfork/go-testmark v0.3.0/go.mod h1:jhEf8FVxd+F17juRubpmut64NEG6I2rgkUhlcqqXwE0= -github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a h1:G++j5e0OC488te356JvdhaM8YS6nMsjLAYF7JxCv07w= -github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= +github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0 h1:GDDkbFiaK8jsSDJfjId/PEGEShv6ugrt4kYsC5UIDaQ= +github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -397,16 +382,25 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1 go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= +go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s= +go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4= +go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26Q3hqOo= +go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4= +go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs= +go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI= -go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU= -go.uber.org/fx v1.19.2 h1:SyFgYQFr1Wl0AYstE8vyYIzP4bFz2URrScjwC4cwUvY= -go.uber.org/fx v1.19.2/go.mod h1:43G1VcqSzbIv77y00p1DRAsyZS8WdzuYdhZXmEUkMyQ= +go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc= +go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE= +go.uber.org/fx v1.20.1 h1:zVwVQGS8zYvhh9Xxcu4w1M6ESyeMzebzj2NbSayZ4Mk= +go.uber.org/fx v1.20.1/go.mod h1:iSYNbHf2y55acNCwCXKx7LbWb5WG1Bnue5RDXz1OREg= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -414,8 +408,8 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8 go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= -go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -426,13 +420,12 @@ golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= -golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE= +golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -444,8 +437,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= -golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= +golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -464,8 +457,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -479,8 +472,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -494,7 +487,6 @@ golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210426080607-c94f62235c83/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -502,16 +494,15 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -530,14 +521,15 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo= -golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= +golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= +golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gonum.org/v1/gonum v0.13.0 h1:a0T3bh+7fhRyqeNbiC3qVHYmkiQgit3wnNan/2c0HMM= +gonum.org/v1/gonum v0.13.0/go.mod h1:/WPYRckkfWrhWefxyYTfrTtQR0KH4iyHNuzxqXAKyAU= google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y= @@ -569,10 +561,8 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= +google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= @@ -594,7 +584,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -lukechampine.com/blake3 v1.1.6/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA= lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI= lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck= diff --git a/go-libp2p/examples/libp2p-host/README.md b/go-libp2p/examples/libp2p-host/README.md index e187f06..966ee0e 100644 --- a/go-libp2p/examples/libp2p-host/README.md +++ b/go-libp2p/examples/libp2p-host/README.md @@ -84,7 +84,7 @@ defer h2.Close() fmt.Printf("Hello World, my second hosts ID is %s\n", h2.ID()) ``` -And thats it, you have a libp2p host and you're ready to start doing some awesome p2p networking! +And that's it, you have a libp2p host and you're ready to start doing some awesome p2p networking! In future guides we will go over ways to use hosts, configure them differently (hint: there are a huge number of ways to set these up), and interesting ways to apply this technology to various applications you might want to build. diff --git a/go-libp2p/examples/multipro/pb/p2p.pb.go b/go-libp2p/examples/multipro/pb/p2p.pb.go index a33d549..2399383 100644 --- a/go-libp2p/examples/multipro/pb/p2p.pb.go +++ b/go-libp2p/examples/multipro/pb/p2p.pb.go @@ -110,7 +110,7 @@ func (m *MessageData) GetSign() []byte { return nil } -// a protocol define a set of reuqest and responses +// A protocol defines a set of requests and responses. type PingRequest struct { MessageData *MessageData `protobuf:"bytes,1,opt,name=messageData" json:"messageData,omitempty"` // method specific data @@ -205,7 +205,7 @@ func (m *PingResponse) GetMessage() string { return "" } -// a protocol define a set of reuqest and responses +// A protocol defines a set of requests and responses type EchoRequest struct { MessageData *MessageData `protobuf:"bytes,1,opt,name=messageData" json:"messageData,omitempty"` // method specific data diff --git a/go-libp2p/examples/multipro/pb/p2p.proto b/go-libp2p/examples/multipro/pb/p2p.proto index 5488f2a..a360b24 100644 --- a/go-libp2p/examples/multipro/pb/p2p.proto +++ b/go-libp2p/examples/multipro/pb/p2p.proto @@ -16,7 +16,7 @@ message MessageData { //// ping protocol -// a protocol define a set of reuqest and responses +// A protocol defines a set of requests and responses. message PingRequest { MessageData messageData = 1; @@ -36,7 +36,7 @@ message PingResponse { //// echo protocol -// a protocol define a set of reuqest and responses +// A protocol defines a set of requests and responses. message EchoRequest { MessageData messageData = 1; diff --git a/go-libp2p/examples/pubsub/README.md b/go-libp2p/examples/pubsub/README.md index 050b33f..a41419a 100644 --- a/go-libp2p/examples/pubsub/README.md +++ b/go-libp2p/examples/pubsub/README.md @@ -3,4 +3,5 @@ This directory contains example projects that use [go-libp2p-pubsub](https://github.com/libp2p/go-libp2p-pubsub), the Go implementation of libp2p's [Publish / Subscribe system](https://docs.libp2p.io/concepts/publish-subscribe). -The [chat room example](./chat) covers the basics of using the PubSub API to build a peer-to-peer chat application. +- The [chat room example](./chat) covers the basics of using the PubSub API to build a peer-to-peer chat application. +- The [pubsub rendezvous example](./basic-chat-with-rendezvous) allows multiple peers to chat among each other using go-libp2p-pubsub using rendezvous names. diff --git a/go-libp2p/examples/pubsub/basic-chat-with-rendezvous/go.mod b/go-libp2p/examples/pubsub/basic-chat-with-rendezvous/go.mod index f9cf1ec..cd90b4d 100644 --- a/go-libp2p/examples/pubsub/basic-chat-with-rendezvous/go.mod +++ b/go-libp2p/examples/pubsub/basic-chat-with-rendezvous/go.mod @@ -1,11 +1,11 @@ module github.com/libp2p/go-libp2p/examples/pubsub/chat -go 1.19 +go 1.21 require ( - github.com/libp2p/go-libp2p v0.28.0 - github.com/libp2p/go-libp2p-kad-dht v0.21.0 - github.com/libp2p/go-libp2p-pubsub v0.9.0 + github.com/libp2p/go-libp2p v0.33.0 + github.com/libp2p/go-libp2p-kad-dht v0.25.1 + github.com/libp2p/go-libp2p-pubsub v0.10.0 ) require ( @@ -18,97 +18,97 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect - github.com/emirpasic/gods v1.18.1 // indirect - github.com/flynn/noise v1.0.0 // indirect + github.com/flynn/noise v1.1.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect + github.com/go-logr/logr v1.3.0 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/mock v1.6.0 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/gopacket v1.1.19 // indirect - github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 // indirect - github.com/google/uuid v1.3.0 // indirect - github.com/gorilla/websocket v1.5.0 // indirect + github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect + github.com/google/uuid v1.4.0 // indirect + github.com/gorilla/websocket v1.5.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect - github.com/hashicorp/golang-lru/v2 v2.0.2 // indirect - github.com/huin/goupnp v1.2.0 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect + github.com/huin/goupnp v1.3.0 // indirect + github.com/ipfs/boxo v0.10.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect - github.com/ipfs/go-ipfs-util v0.0.2 // indirect - github.com/ipfs/go-ipns v0.2.0 // indirect github.com/ipfs/go-log v1.0.5 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect - github.com/ipld/go-ipld-prime v0.9.0 // indirect + github.com/ipld/go-ipld-prime v0.20.0 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect github.com/jbenet/goprocess v0.1.4 // indirect - github.com/klauspost/compress v1.16.5 // indirect - github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/klauspost/compress v1.17.6 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/koron/go-ssdp v0.0.4 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-cidranger v1.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect - github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect - github.com/libp2p/go-libp2p-kbucket v0.5.0 // indirect + github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect + github.com/libp2p/go-libp2p-kbucket v0.6.3 // indirect github.com/libp2p/go-libp2p-record v0.2.0 // indirect + github.com/libp2p/go-libp2p-routing-helpers v0.7.2 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect github.com/libp2p/go-nat v0.2.0 // indirect github.com/libp2p/go-netroute v0.2.1 // indirect - github.com/libp2p/go-reuseport v0.3.0 // indirect - github.com/libp2p/go-yamux/v4 v4.0.0 // indirect + github.com/libp2p/go-reuseport v0.4.0 // indirect + github.com/libp2p/go-yamux/v4 v4.0.1 // indirect github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect - github.com/mattn/go-isatty v0.0.19 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/miekg/dns v1.1.54 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/miekg/dns v1.1.58 // indirect github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect github.com/minio/sha256-simd v1.0.1 // indirect github.com/mr-tron/base58 v1.2.0 // indirect github.com/multiformats/go-base32 v0.1.0 // indirect github.com/multiformats/go-base36 v0.2.0 // indirect - github.com/multiformats/go-multiaddr v0.9.0 // indirect + github.com/multiformats/go-multiaddr v0.12.2 // indirect github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect github.com/multiformats/go-multibase v0.2.0 // indirect github.com/multiformats/go-multicodec v0.9.0 // indirect - github.com/multiformats/go-multihash v0.2.2 // indirect - github.com/multiformats/go-multistream v0.4.1 // indirect + github.com/multiformats/go-multihash v0.2.3 // indirect + github.com/multiformats/go-multistream v0.5.0 // indirect github.com/multiformats/go-varint v0.0.7 // indirect - github.com/onsi/ginkgo/v2 v2.9.7 // indirect - github.com/opencontainers/runtime-spec v1.0.2 // indirect + github.com/onsi/ginkgo/v2 v2.15.0 // indirect + github.com/opencontainers/runtime-spec v1.2.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1 // indirect - github.com/prometheus/client_golang v1.14.0 // indirect - github.com/prometheus/client_model v0.4.0 // indirect - github.com/prometheus/common v0.42.0 // indirect - github.com/prometheus/procfs v0.9.0 // indirect + github.com/polydawn/refmt v0.89.0 // indirect + github.com/prometheus/client_golang v1.18.0 // indirect + github.com/prometheus/client_model v0.6.0 // indirect + github.com/prometheus/common v0.47.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.2.2 // indirect - github.com/quic-go/quic-go v0.33.0 // indirect - github.com/quic-go/webtransport-go v0.5.3 // indirect + github.com/quic-go/quic-go v0.41.0 // indirect + github.com/quic-go/webtransport-go v0.6.0 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect go.opencensus.io v0.24.0 // indirect - go.uber.org/atomic v1.11.0 // indirect - go.uber.org/dig v1.17.0 // indirect - go.uber.org/fx v1.19.2 // indirect + go.opentelemetry.io/otel v1.16.0 // indirect + go.opentelemetry.io/otel/metric v1.16.0 // indirect + go.opentelemetry.io/otel/trace v1.16.0 // indirect + go.uber.org/dig v1.17.1 // indirect + go.uber.org/fx v1.20.1 // indirect + go.uber.org/mock v0.4.0 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.7.0 // indirect - golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect - golang.org/x/mod v0.10.0 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect - golang.org/x/tools v0.9.1 // indirect - google.golang.org/protobuf v1.30.0 // indirect + go.uber.org/zap v1.27.0 // indirect + golang.org/x/crypto v0.19.0 // indirect + golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect + golang.org/x/mod v0.15.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sync v0.6.0 // indirect + golang.org/x/sys v0.17.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.18.0 // indirect + gonum.org/v1/gonum v0.13.0 // indirect + google.golang.org/protobuf v1.32.0 // indirect lukechampine.com/blake3 v1.2.1 // indirect ) diff --git a/go-libp2p/examples/pubsub/basic-chat-with-rendezvous/go.sum b/go-libp2p/examples/pubsub/basic-chat-with-rendezvous/go.sum index 8a766f9..826d9e2 100644 --- a/go-libp2p/examples/pubsub/basic-chat-with-rendezvous/go.sum +++ b/go-libp2p/examples/pubsub/basic-chat-with-rendezvous/go.sum @@ -39,6 +39,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= +github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= @@ -48,25 +49,29 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/elastic/gosigar v0.12.0/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/4= github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= -github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= -github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= -github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= +github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg= +github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= -github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= +github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= @@ -76,13 +81,12 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -93,7 +97,6 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -104,27 +107,27 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 h1:hR7/MlvK23p6+lIw9SN1TigNLn9ZnF3W4SYRKq2gAHs= -github.com/google/pprof v0.0.0-20230602150820-91b7bce49751/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 h1:E/LAvt58di64hlYjx7AsNS6C/ysHWYo+2qPCZKTQhRo= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRidnzC1Oq86fpX1q/iEv2KJdrCtttYjT4= +github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -134,11 +137,12 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/golang-lru/v2 v2.0.2 h1:Dwmkdr5Nc/oBiXgJS3CDHNhJtIHkuZ3DZF5twqnfBdU= -github.com/hashicorp/golang-lru/v2 v2.0.2/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= -github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY= -github.com/huin/goupnp v1.2.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= -github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj6+M= +github.com/hashicorp/golang-lru/v2 v2.0.5 h1:wW7h1TG88eUIJ2i69gaE3uNVtEPIagzhGvHgwfx2Vm4= +github.com/hashicorp/golang-lru/v2 v2.0.5/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= +github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= +github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY= +github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk= @@ -147,15 +151,13 @@ github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-ipfs-util v0.0.2 h1:59Sswnk1MFaiq+VcaknX7aYEyGyGDAA73ilhEK2POp8= github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdrtMecczcsQ= -github.com/ipfs/go-ipns v0.2.0 h1:BgmNtQhqOw5XEZ8RAfWEpK4DhqaYiuP6h71MhIp7xXU= -github.com/ipfs/go-ipns v0.2.0/go.mod h1:3cLT2rbvgPZGkHJoPO1YMJeh6LtkxopCkKFcio/wE24= github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= github.com/ipfs/go-log/v2 v2.1.3/go.mod h1:/8d0SH3Su5Ooc31QlL1WysJhvyOTDCjcCZ9Axpmri6g= github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= -github.com/ipld/go-ipld-prime v0.9.0 h1:N2OjJMb+fhyFPwPnVvJcWU/NsumP8etal+d2v3G4eww= -github.com/ipld/go-ipld-prime v0.9.0/go.mod h1:KvBLMr4PX1gWptgkzRjVZCrLmSGcZCb/jioOQwCqZN8= +github.com/ipld/go-ipld-prime v0.20.0 h1:Ud3VwE9ClxpO2LkCYP7vWPc0Fo+dYdYzgxUJZ3uRG4g= +github.com/ipld/go-ipld-prime v0.20.0/go.mod h1:PzqZ/ZR981eKbgdr3y2DJYeD/8bgMawdGVlJDE8kK+M= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= @@ -171,63 +173,65 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= -github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= -github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI= +github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c= github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic= github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM= github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= -github.com/libp2p/go-libp2p v0.28.0 h1:zO8cY98nJiPzZpFv5w5gqqb8aVzt4ukQ0nVOSaaKhJ8= -github.com/libp2p/go-libp2p v0.28.0/go.mod h1:s3Xabc9LSwOcnv9UD4nORnXKTsWkPMkIMB/JIGXVnzk= -github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= -github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w= -github.com/libp2p/go-libp2p-kad-dht v0.21.0 h1:J0Yd22VA+sk0CJRGMgtfHvLVIkZDyJ3AJGiljywIw5U= -github.com/libp2p/go-libp2p-kad-dht v0.21.0/go.mod h1:Bhm9diAFmc6qcWAr084bHNL159srVZRKADdp96Qqd1I= -github.com/libp2p/go-libp2p-kbucket v0.5.0 h1:g/7tVm8ACHDxH29BGrpsQlnNeu+6OF1A9bno/4/U1oA= -github.com/libp2p/go-libp2p-kbucket v0.5.0/go.mod h1:zGzGCpQd78b5BNTDGHNDLaTt9aDK/A02xeZp9QeFC4U= -github.com/libp2p/go-libp2p-pubsub v0.9.0 h1:mcLb4WzwhUG4OKb0rp1/bYMd/DYhvMyzJheQH3LMd1s= -github.com/libp2p/go-libp2p-pubsub v0.9.0/go.mod h1:OEsj0Cc/BpkqikXRTrVspWU/Hx7bMZwHP+6vNMd+c7I= +github.com/libp2p/go-libp2p v0.33.0 h1:yTPSr8sJRbfeEYXyeN8VPVSlTlFjtMUwGDRniwaf/xQ= +github.com/libp2p/go-libp2p v0.33.0/go.mod h1:RIJFRQVUBKy82dnW7J5f1homqqv6NcsDJAl3e7CRGfE= +github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94= +github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8= +github.com/libp2p/go-libp2p-kad-dht v0.25.1 h1:ofFNrf6MMEy4vi3R1VbJ7LOcTn3Csh0cDcaWHTxtWNA= +github.com/libp2p/go-libp2p-kad-dht v0.25.1/go.mod h1:6za56ncRHYXX4Nc2vn8z7CZK0P4QiMcrn77acKLM2Oo= +github.com/libp2p/go-libp2p-kbucket v0.6.3 h1:p507271wWzpy2f1XxPzCQG9NiN6R6lHL9GiSErbQQo0= +github.com/libp2p/go-libp2p-kbucket v0.6.3/go.mod h1:RCseT7AH6eJWxxk2ol03xtP9pEHetYSPXOaJnOiD8i0= +github.com/libp2p/go-libp2p-pubsub v0.10.0 h1:wS0S5FlISavMaAbxyQn3dxMOe2eegMfswM471RuHJwA= +github.com/libp2p/go-libp2p-pubsub v0.10.0/go.mod h1:1OxbaT/pFRO5h+Dpze8hdHQ63R0ke55XTs6b6NwLLkw= github.com/libp2p/go-libp2p-record v0.2.0 h1:oiNUOCWno2BFuxt3my4i1frNrt7PerzB3queqa1NkQ0= github.com/libp2p/go-libp2p-record v0.2.0/go.mod h1:I+3zMkvvg5m2OcSdoL0KPljyJyvNDFGKX7QdlpYUcwk= +github.com/libp2p/go-libp2p-routing-helpers v0.7.2 h1:xJMFyhQ3Iuqnk9Q2dYE1eUTzsah7NLw3Qs2zjUV78T0= +github.com/libp2p/go-libp2p-routing-helpers v0.7.2/go.mod h1:cN4mJAD/7zfPKXBcs9ze31JGYAZgzdABEm+q/hkswb8= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= +github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk= github.com/libp2p/go-nat v0.2.0/go.mod h1:3MJr+GRpRkyT65EpVPBstXLvOlAPzUVlG6Pwg9ohLJk= github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU= github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ= -github.com/libp2p/go-reuseport v0.3.0 h1:iiZslO5byUYZEg9iCwJGf5h+sf1Agmqx2V2FDjPyvUw= -github.com/libp2p/go-reuseport v0.3.0/go.mod h1:laea40AimhtfEqysZ71UpYj4S+R9VpH8PgqLo7L+SwI= -github.com/libp2p/go-yamux/v4 v4.0.0 h1:+Y80dV2Yx/kv7Y7JKu0LECyVdMXm1VUoko+VQ9rBfZQ= -github.com/libp2p/go-yamux/v4 v4.0.0/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4= +github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s= +github.com/libp2p/go-reuseport v0.4.0/go.mod h1:ZtI03j/wO5hZVDFo2jKywN6bYKWLOy8Se6DrI2E1cLU= +github.com/libp2p/go-yamux/v4 v4.0.1 h1:FfDR4S1wj6Bw2Pqbc8Uz7pCxeRBPbwsBbEdfwiCypkQ= +github.com/libp2p/go-yamux/v4 v4.0.1/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4= github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= -github.com/miekg/dns v1.1.54 h1:5jon9mWcb0sFJGpnI99tOMhCPyJ+RPVz5b63MQG0VWI= -github.com/miekg/dns v1.1.54/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= +github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4= +github.com/miekg/dns v1.1.58/go.mod h1:Ypv+3b/KadlvW9vJfXOTf300O4UqaHFzFCuHz+rPkBY= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c h1:bzE/A84HN25pxAuk9Eej1Kz9OUelF97nAc82bDquQI8= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c/go.mod h1:0SQS9kMwD2VsyFEB++InYyBJroV/FRmBgcydeSUcJms= github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b h1:z78hV3sbSMAUoyUMM0I83AUIT6Hu17AWfgjzIbtrYFc= @@ -236,54 +240,46 @@ github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc h1:PTfri+PuQmWDqERdn github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc/go.mod h1:cGKTAVKx4SxOuR/czcZ/E2RSJ3sfHs8FpHhQ5CWMf9s= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= -github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE= github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI= github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= -github.com/multiformats/go-multiaddr v0.9.0 h1:3h4V1LHIk5w4hJHekMKWALPXErDfz/sggzwC/NcqbDQ= -github.com/multiformats/go-multiaddr v0.9.0/go.mod h1:mI67Lb1EeTOYb8GQfL/7wpIZwc46ElrvzhYnoJOmTT0= +github.com/multiformats/go-multiaddr v0.12.2 h1:9G9sTY/wCYajKa9lyfWPmpZAwe6oV+Wb1zcmMS1HG24= +github.com/multiformats/go-multiaddr v0.12.2/go.mod h1:GKyaTYjZRdcUhyOetrxTk9z0cW+jA/YrnqTOvKgi44M= github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= github.com/multiformats/go-multiaddr-fmt v0.1.0/go.mod h1:hGtDIW4PU4BqJ50gW2quDuPVjyWNZxToGUh/HwTZYJo= -github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g= github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk= github.com/multiformats/go-multicodec v0.9.0 h1:pb/dlPnzee/Sxv/j4PmkDRxCOi3hXTz3IbPKOXWJkmg= github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k= github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= -github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= -github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= -github.com/multiformats/go-multihash v0.0.15/go.mod h1:D6aZrWNLFTV/ynMpKsNtB40mJzmCl4jb1alC0OvHiHg= -github.com/multiformats/go-multihash v0.2.2 h1:Uu7LWs/PmWby1gkj1S1DXx3zyd3aVabA4FiMKn/2tAc= -github.com/multiformats/go-multihash v0.2.2/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= -github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3de4741sbiSdfo= -github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= +github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= +github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= +github.com/multiformats/go-multistream v0.5.0 h1:5htLSLl7lvJk3xx3qT/8Zm9J4K8vEOf/QGkvOGQAyiE= +github.com/multiformats/go-multistream v0.5.0/go.mod h1:n6tMZiwiP2wUsR8DgfDWw1dydlEqV3l6N3/GBsX6ILA= github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= -github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= -github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= -github.com/onsi/ginkgo/v2 v2.9.7 h1:06xGQy5www2oN160RtEZoTvnP2sPhEfePYmCDc2szss= -github.com/onsi/ginkgo/v2 v2.9.7/go.mod h1:cxrmXWykAwTwhQsJOPfdIDiJ+l2RYq7U8hFU+M/1uw0= -github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU= -github.com/opencontainers/runtime-spec v1.0.2 h1:UfAcuLBJB9Coz72x1hgl8O5RVzTdNiaglX6v2DM6FI0= +github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= +github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= +github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= +github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= +github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk= +github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= @@ -294,34 +290,32 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1 h1:CskT+S6Ay54OwxBGB0R3Rsx4Muto6UnEYTyKJbyRIAI= -github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o= +github.com/polydawn/refmt v0.89.0 h1:ADJTApkvkeBZsN0tBTx8QjpD9JkmxbKp0cxfr9qszm4= +github.com/polydawn/refmt v0.89.0/go.mod h1:/zvteZs/GwLtCgZ4BL6CBsk9IKIlexP43ObX9AxTqTw= github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= -github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= +github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= +github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= -github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= +github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= +github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= -github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= +github.com/prometheus/common v0.47.0 h1:p5Cz0FNHo7SnWOmWmoRozVcjEp0bIVU8cV7OShpjL1k= +github.com/prometheus/common v0.47.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= -github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= -github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= -github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0= -github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA= -github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= -github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= +github.com/quic-go/quic-go v0.41.0 h1:aD8MmHfgqTURWNJy48IYFg2OnxwHT3JL7ahGs73lb4k= +github.com/quic-go/quic-go v0.41.0/go.mod h1:qCkNjqczPEvgsOnxZ0eCD14lv+B2LHlFAB++CNOh9hA= +github.com/quic-go/webtransport-go v0.6.0 h1:CvNsKqc4W2HljHJnoT+rMmbRJybShZ0YPFDD3NxaZLY= +github.com/quic-go/webtransport-go v0.6.0/go.mod h1:9KjU4AEBqEQidGHNDkZrb8CAa1abRaosM2yGOyiikEc= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= @@ -349,10 +343,10 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4= github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= +github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= +github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg= +github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM= github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= @@ -368,13 +362,15 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM= -github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a h1:G++j5e0OC488te356JvdhaM8YS6nMsjLAYF7JxCv07w= -github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= +github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0 h1:GDDkbFiaK8jsSDJfjId/PEGEShv6ugrt4kYsC5UIDaQ= +github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -383,16 +379,25 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1 go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= +go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s= +go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4= +go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26Q3hqOo= +go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4= +go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs= +go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI= -go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU= -go.uber.org/fx v1.19.2 h1:SyFgYQFr1Wl0AYstE8vyYIzP4bFz2URrScjwC4cwUvY= -go.uber.org/fx v1.19.2/go.mod h1:43G1VcqSzbIv77y00p1DRAsyZS8WdzuYdhZXmEUkMyQ= +go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc= +go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE= +go.uber.org/fx v1.20.1 h1:zVwVQGS8zYvhh9Xxcu4w1M6ESyeMzebzj2NbSayZ4Mk= +go.uber.org/fx v1.20.1/go.mod h1:iSYNbHf2y55acNCwCXKx7LbWb5WG1Bnue5RDXz1OREg= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -400,8 +405,8 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8 go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= -go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -412,13 +417,12 @@ golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= -golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE= +golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -430,8 +434,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= -golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= +golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -449,8 +453,8 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -464,8 +468,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -479,21 +483,19 @@ golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -512,14 +514,15 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo= -golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= +golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= +golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gonum.org/v1/gonum v0.13.0 h1:a0T3bh+7fhRyqeNbiC3qVHYmkiQgit3wnNan/2c0HMM= +gonum.org/v1/gonum v0.13.0/go.mod h1:/WPYRckkfWrhWefxyYTfrTtQR0KH4iyHNuzxqXAKyAU= google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y= @@ -551,10 +554,8 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= +google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= @@ -564,6 +565,8 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/go-libp2p/examples/pubsub/basic-chat-with-rendezvous/main.go b/go-libp2p/examples/pubsub/basic-chat-with-rendezvous/main.go index 57729ed..46d8ca0 100644 --- a/go-libp2p/examples/pubsub/basic-chat-with-rendezvous/main.go +++ b/go-libp2p/examples/pubsub/basic-chat-with-rendezvous/main.go @@ -95,9 +95,9 @@ func discoverPeers(ctx context.Context, h host.Host) { } err := h.Connect(ctx, peer) if err != nil { - fmt.Println("Failed connecting to ", peer.ID.Pretty(), ", error:", err) + fmt.Printf("Failed connecting to %s, error: %s\n", peer.ID, err) } else { - fmt.Println("Connected to:", peer.ID.Pretty()) + fmt.Println("Connected to:", peer.ID) anyConnected = true } } diff --git a/go-libp2p/examples/pubsub/chat/README.md b/go-libp2p/examples/pubsub/chat/README.md index 2b99c12..a37af70 100644 --- a/go-libp2p/examples/pubsub/chat/README.md +++ b/go-libp2p/examples/pubsub/chat/README.md @@ -132,7 +132,7 @@ to the `pubsub.Topic`: func (cr *ChatRoom) Publish(message string) error { m := ChatMessage{ Message: message, - SenderID: cr.self.Pretty(), + SenderID: cr.self.String(), SenderNick: cr.nick, } msgBytes, err := json.Marshal(m) diff --git a/go-libp2p/examples/pubsub/chat/chatroom.go b/go-libp2p/examples/pubsub/chat/chatroom.go index 452cc30..dc323d5 100644 --- a/go-libp2p/examples/pubsub/chat/chatroom.go +++ b/go-libp2p/examples/pubsub/chat/chatroom.go @@ -71,7 +71,7 @@ func JoinChatRoom(ctx context.Context, ps *pubsub.PubSub, selfID peer.ID, nickna func (cr *ChatRoom) Publish(message string) error { m := ChatMessage{ Message: message, - SenderID: cr.self.Pretty(), + SenderID: cr.self.String(), SenderNick: cr.nick, } msgBytes, err := json.Marshal(m) diff --git a/go-libp2p/examples/pubsub/chat/go.mod b/go-libp2p/examples/pubsub/chat/go.mod index 11b1eb1..6c53916 100644 --- a/go-libp2p/examples/pubsub/chat/go.mod +++ b/go-libp2p/examples/pubsub/chat/go.mod @@ -1,11 +1,11 @@ module github.com/libp2p/go-libp2p/examples/pubsub/chat -go 1.19 +go 1.21 require ( github.com/gdamore/tcell/v2 v2.5.2 - github.com/libp2p/go-libp2p v0.28.0 - github.com/libp2p/go-libp2p-pubsub v0.9.0 + github.com/libp2p/go-libp2p v0.33.0 + github.com/libp2p/go-libp2p-pubsub v0.10.0 github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8 ) @@ -19,89 +19,80 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect - github.com/emirpasic/gods v1.18.1 // indirect - github.com/flynn/noise v1.0.0 // indirect + github.com/flynn/noise v1.1.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect github.com/gdamore/encoding v1.0.0 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/mock v1.6.0 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/gopacket v1.1.19 // indirect - github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 // indirect - github.com/gorilla/websocket v1.5.0 // indirect - github.com/hashicorp/golang-lru/v2 v2.0.2 // indirect - github.com/huin/goupnp v1.2.0 // indirect + github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect + github.com/gorilla/websocket v1.5.1 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect + github.com/huin/goupnp v1.3.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect - github.com/ipfs/go-log v1.0.5 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect - github.com/klauspost/compress v1.16.5 // indirect - github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/klauspost/compress v1.17.6 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/koron/go-ssdp v0.0.4 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect - github.com/libp2p/go-cidranger v1.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect - github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect + github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect github.com/libp2p/go-nat v0.2.0 // indirect github.com/libp2p/go-netroute v0.2.1 // indirect - github.com/libp2p/go-reuseport v0.3.0 // indirect - github.com/libp2p/go-yamux/v4 v4.0.0 // indirect + github.com/libp2p/go-reuseport v0.4.0 // indirect + github.com/libp2p/go-yamux/v4 v4.0.1 // indirect github.com/libp2p/zeroconf/v2 v2.2.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/miekg/dns v1.1.54 // indirect + github.com/miekg/dns v1.1.58 // indirect github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect github.com/minio/sha256-simd v1.0.1 // indirect github.com/mr-tron/base58 v1.2.0 // indirect github.com/multiformats/go-base32 v0.1.0 // indirect github.com/multiformats/go-base36 v0.2.0 // indirect - github.com/multiformats/go-multiaddr v0.9.0 // indirect + github.com/multiformats/go-multiaddr v0.12.2 // indirect github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect github.com/multiformats/go-multibase v0.2.0 // indirect github.com/multiformats/go-multicodec v0.9.0 // indirect - github.com/multiformats/go-multihash v0.2.2 // indirect - github.com/multiformats/go-multistream v0.4.1 // indirect + github.com/multiformats/go-multihash v0.2.3 // indirect + github.com/multiformats/go-multistream v0.5.0 // indirect github.com/multiformats/go-varint v0.0.7 // indirect - github.com/onsi/ginkgo/v2 v2.9.7 // indirect - github.com/opencontainers/runtime-spec v1.0.2 // indirect - github.com/opentracing/opentracing-go v1.2.0 // indirect + github.com/onsi/ginkgo/v2 v2.15.0 // indirect + github.com/opencontainers/runtime-spec v1.2.0 // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/prometheus/client_golang v1.14.0 // indirect - github.com/prometheus/client_model v0.4.0 // indirect - github.com/prometheus/common v0.42.0 // indirect - github.com/prometheus/procfs v0.9.0 // indirect + github.com/prometheus/client_golang v1.18.0 // indirect + github.com/prometheus/client_model v0.6.0 // indirect + github.com/prometheus/common v0.47.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.2.2 // indirect - github.com/quic-go/quic-go v0.33.0 // indirect - github.com/quic-go/webtransport-go v0.5.3 // indirect + github.com/quic-go/quic-go v0.41.0 // indirect + github.com/quic-go/webtransport-go v0.6.0 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - go.uber.org/atomic v1.11.0 // indirect - go.uber.org/dig v1.17.0 // indirect - go.uber.org/fx v1.19.2 // indirect + go.uber.org/dig v1.17.1 // indirect + go.uber.org/fx v1.20.1 // indirect + go.uber.org/mock v0.4.0 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.7.0 // indirect - golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect - golang.org/x/mod v0.10.0 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/term v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect - golang.org/x/tools v0.9.1 // indirect - google.golang.org/protobuf v1.30.0 // indirect + go.uber.org/zap v1.27.0 // indirect + golang.org/x/crypto v0.19.0 // indirect + golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect + golang.org/x/mod v0.15.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sync v0.6.0 // indirect + golang.org/x/sys v0.17.0 // indirect + golang.org/x/term v0.17.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.18.0 // indirect + google.golang.org/protobuf v1.32.0 // indirect lukechampine.com/blake3 v1.2.1 // indirect ) diff --git a/go-libp2p/examples/pubsub/chat/go.sum b/go-libp2p/examples/pubsub/chat/go.sum index e9d38f1..fa89b78 100644 --- a/go-libp2p/examples/pubsub/chat/go.sum +++ b/go-libp2p/examples/pubsub/chat/go.sum @@ -37,6 +37,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= +github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= @@ -46,11 +47,9 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/elastic/gosigar v0.12.0/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/4= github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= -github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= -github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= -github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= +github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg= +github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -62,7 +61,8 @@ github.com/gdamore/tcell/v2 v2.5.2/go.mod h1:wSkrPaXoiIWZqW/g7Px4xc79di6FTcpB8tv github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -77,45 +77,36 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 h1:hR7/MlvK23p6+lIw9SN1TigNLn9ZnF3W4SYRKq2gAHs= -github.com/google/pprof v0.0.0-20230602150820-91b7bce49751/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 h1:E/LAvt58di64hlYjx7AsNS6C/ysHWYo+2qPCZKTQhRo= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= -github.com/hashicorp/golang-lru/v2 v2.0.2 h1:Dwmkdr5Nc/oBiXgJS3CDHNhJtIHkuZ3DZF5twqnfBdU= -github.com/hashicorp/golang-lru/v2 v2.0.2/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= -github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY= -github.com/huin/goupnp v1.2.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= +github.com/hashicorp/golang-lru/v2 v2.0.5 h1:wW7h1TG88eUIJ2i69gaE3uNVtEPIagzhGvHgwfx2Vm4= +github.com/hashicorp/golang-lru/v2 v2.0.5/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= +github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= -github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= -github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= -github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= -github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= -github.com/ipfs/go-log/v2 v2.1.3/go.mod h1:/8d0SH3Su5Ooc31QlL1WysJhvyOTDCjcCZ9Axpmri6g= github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= @@ -128,42 +119,43 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= -github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= -github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI= +github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= -github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c= -github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic= github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM= github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= -github.com/libp2p/go-libp2p v0.28.0 h1:zO8cY98nJiPzZpFv5w5gqqb8aVzt4ukQ0nVOSaaKhJ8= -github.com/libp2p/go-libp2p v0.28.0/go.mod h1:s3Xabc9LSwOcnv9UD4nORnXKTsWkPMkIMB/JIGXVnzk= -github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= -github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w= -github.com/libp2p/go-libp2p-pubsub v0.9.0 h1:mcLb4WzwhUG4OKb0rp1/bYMd/DYhvMyzJheQH3LMd1s= -github.com/libp2p/go-libp2p-pubsub v0.9.0/go.mod h1:OEsj0Cc/BpkqikXRTrVspWU/Hx7bMZwHP+6vNMd+c7I= +github.com/libp2p/go-libp2p v0.33.0 h1:yTPSr8sJRbfeEYXyeN8VPVSlTlFjtMUwGDRniwaf/xQ= +github.com/libp2p/go-libp2p v0.33.0/go.mod h1:RIJFRQVUBKy82dnW7J5f1homqqv6NcsDJAl3e7CRGfE= +github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94= +github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8= +github.com/libp2p/go-libp2p-pubsub v0.10.0 h1:wS0S5FlISavMaAbxyQn3dxMOe2eegMfswM471RuHJwA= +github.com/libp2p/go-libp2p-pubsub v0.10.0/go.mod h1:1OxbaT/pFRO5h+Dpze8hdHQ63R0ke55XTs6b6NwLLkw= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= +github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk= github.com/libp2p/go-nat v0.2.0/go.mod h1:3MJr+GRpRkyT65EpVPBstXLvOlAPzUVlG6Pwg9ohLJk= github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU= github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ= -github.com/libp2p/go-reuseport v0.3.0 h1:iiZslO5byUYZEg9iCwJGf5h+sf1Agmqx2V2FDjPyvUw= -github.com/libp2p/go-reuseport v0.3.0/go.mod h1:laea40AimhtfEqysZ71UpYj4S+R9VpH8PgqLo7L+SwI= -github.com/libp2p/go-yamux/v4 v4.0.0 h1:+Y80dV2Yx/kv7Y7JKu0LECyVdMXm1VUoko+VQ9rBfZQ= -github.com/libp2p/go-yamux/v4 v4.0.0/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4= +github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s= +github.com/libp2p/go-reuseport v0.4.0/go.mod h1:ZtI03j/wO5hZVDFo2jKywN6bYKWLOy8Se6DrI2E1cLU= +github.com/libp2p/go-yamux/v4 v4.0.1 h1:FfDR4S1wj6Bw2Pqbc8Uz7pCxeRBPbwsBbEdfwiCypkQ= +github.com/libp2p/go-yamux/v4 v4.0.1/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4= github.com/libp2p/zeroconf/v2 v2.2.0 h1:Cup06Jv6u81HLhIj1KasuNM/RHHrJ8T7wOTS4+Tv53Q= github.com/libp2p/zeroconf/v2 v2.2.0/go.mod h1:fuJqLnUwZTshS3U/bMRJ3+ow/v9oid1n0DmyYyNO1Xs= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= @@ -173,18 +165,16 @@ github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= -github.com/miekg/dns v1.1.54 h1:5jon9mWcb0sFJGpnI99tOMhCPyJ+RPVz5b63MQG0VWI= -github.com/miekg/dns v1.1.54/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= +github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4= +github.com/miekg/dns v1.1.58/go.mod h1:Ypv+3b/KadlvW9vJfXOTf300O4UqaHFzFCuHz+rPkBY= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c h1:bzE/A84HN25pxAuk9Eej1Kz9OUelF97nAc82bDquQI8= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c/go.mod h1:0SQS9kMwD2VsyFEB++InYyBJroV/FRmBgcydeSUcJms= github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b h1:z78hV3sbSMAUoyUMM0I83AUIT6Hu17AWfgjzIbtrYFc= @@ -206,8 +196,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= -github.com/multiformats/go-multiaddr v0.9.0 h1:3h4V1LHIk5w4hJHekMKWALPXErDfz/sggzwC/NcqbDQ= -github.com/multiformats/go-multiaddr v0.9.0/go.mod h1:mI67Lb1EeTOYb8GQfL/7wpIZwc46ElrvzhYnoJOmTT0= +github.com/multiformats/go-multiaddr v0.12.2 h1:9G9sTY/wCYajKa9lyfWPmpZAwe6oV+Wb1zcmMS1HG24= +github.com/multiformats/go-multiaddr v0.12.2/go.mod h1:GKyaTYjZRdcUhyOetrxTk9z0cW+jA/YrnqTOvKgi44M= github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= @@ -217,22 +207,22 @@ github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6o github.com/multiformats/go-multicodec v0.9.0 h1:pb/dlPnzee/Sxv/j4PmkDRxCOi3hXTz3IbPKOXWJkmg= github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k= github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= -github.com/multiformats/go-multihash v0.2.2 h1:Uu7LWs/PmWby1gkj1S1DXx3zyd3aVabA4FiMKn/2tAc= -github.com/multiformats/go-multihash v0.2.2/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= -github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3de4741sbiSdfo= -github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= +github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= +github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= +github.com/multiformats/go-multistream v0.5.0 h1:5htLSLl7lvJk3xx3qT/8Zm9J4K8vEOf/QGkvOGQAyiE= +github.com/multiformats/go-multistream v0.5.0/go.mod h1:n6tMZiwiP2wUsR8DgfDWw1dydlEqV3l6N3/GBsX6ILA= github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= -github.com/onsi/ginkgo/v2 v2.9.7 h1:06xGQy5www2oN160RtEZoTvnP2sPhEfePYmCDc2szss= -github.com/onsi/ginkgo/v2 v2.9.7/go.mod h1:cxrmXWykAwTwhQsJOPfdIDiJ+l2RYq7U8hFU+M/1uw0= -github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU= -github.com/opencontainers/runtime-spec v1.0.2 h1:UfAcuLBJB9Coz72x1hgl8O5RVzTdNiaglX6v2DM6FI0= +github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= +github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= +github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= +github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= -github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= -github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= +github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk= +github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= @@ -242,34 +232,31 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= -github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= +github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= +github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= -github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= +github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= +github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= -github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= +github.com/prometheus/common v0.47.0 h1:p5Cz0FNHo7SnWOmWmoRozVcjEp0bIVU8cV7OShpjL1k= +github.com/prometheus/common v0.47.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= -github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= -github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= -github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0= -github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA= -github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= -github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= +github.com/quic-go/quic-go v0.41.0 h1:aD8MmHfgqTURWNJy48IYFg2OnxwHT3JL7ahGs73lb4k= +github.com/quic-go/quic-go v0.41.0/go.mod h1:qCkNjqczPEvgsOnxZ0eCD14lv+B2LHlFAB++CNOh9hA= +github.com/quic-go/webtransport-go v0.6.0 h1:CvNsKqc4W2HljHJnoT+rMmbRJybShZ0YPFDD3NxaZLY= +github.com/quic-go/webtransport-go v0.6.0/go.mod h1:9KjU4AEBqEQidGHNDkZrb8CAa1abRaosM2yGOyiikEc= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU= github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8 h1:xe+mmCnDN82KhC010l3NfYlA8ZbOuzbXAzSYBa6wbMc= github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8/go.mod h1:WIfMkQNY+oq/mWwtsjOYHIZBuwthioY2srOmljJkTnk= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= @@ -307,7 +294,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= @@ -316,53 +304,50 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= -go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI= -go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU= -go.uber.org/fx v1.19.2 h1:SyFgYQFr1Wl0AYstE8vyYIzP4bFz2URrScjwC4cwUvY= -go.uber.org/fx v1.19.2/go.mod h1:43G1VcqSzbIv77y00p1DRAsyZS8WdzuYdhZXmEUkMyQ= +go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc= +go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE= +go.uber.org/fx v1.20.1 h1:zVwVQGS8zYvhh9Xxcu4w1M6ESyeMzebzj2NbSayZ4Mk= +go.uber.org/fx v1.20.1/go.mod h1:iSYNbHf2y55acNCwCXKx7LbWb5WG1Bnue5RDXz1OREg= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= -go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= -go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= -go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= -golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE= +golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= -golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= +golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -380,8 +365,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -395,8 +380,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -419,20 +404,20 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -442,17 +427,13 @@ golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo= -golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= +golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= +golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -473,15 +454,12 @@ google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmE google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= +google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -489,11 +467,11 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI= lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck= diff --git a/go-libp2p/examples/pubsub/chat/main.go b/go-libp2p/examples/pubsub/chat/main.go index 45a103d..593e41e 100644 --- a/go-libp2p/examples/pubsub/chat/main.go +++ b/go-libp2p/examples/pubsub/chat/main.go @@ -80,7 +80,7 @@ func defaultNick(p peer.ID) string { // shortID returns the last 8 chars of a base58-encoded peer id. func shortID(p peer.ID) string { - pretty := p.Pretty() + pretty := p.String() return pretty[len(pretty)-8:] } @@ -93,10 +93,10 @@ type discoveryNotifee struct { // the PubSub system will automatically start interacting with them if they also // support PubSub. func (n *discoveryNotifee) HandlePeerFound(pi peer.AddrInfo) { - fmt.Printf("discovered new peer %s\n", pi.ID.Pretty()) + fmt.Printf("discovered new peer %s\n", pi.ID) err := n.h.Connect(context.Background(), pi) if err != nil { - fmt.Printf("error connecting to peer %s: %s\n", pi.ID.Pretty(), err) + fmt.Printf("error connecting to peer %s: %s\n", pi.ID, err) } } diff --git a/go-libp2p/examples/relay/README.md b/go-libp2p/examples/relay/README.md new file mode 100644 index 0000000..a4bd5c5 --- /dev/null +++ b/go-libp2p/examples/relay/README.md @@ -0,0 +1,15 @@ +# Relay-based P2P Communication Example + +## Overview +This project demonstrates the setup of a relay-based peer-to-peer communication using the libp2p library in Go. It features creating unreachable libp2p hosts and facilitating their communication through a relay node. + +## Features +- Creation of two "unreachable" libp2p hosts. +- Setup of a relay node to enable communication between these hosts. + +## Usage + +Run the program + ```bash + go run . + ``` \ No newline at end of file diff --git a/go-libp2p/examples/relay/main.go b/go-libp2p/examples/relay/main.go index e8fa8b7..7e16b1b 100644 --- a/go-libp2p/examples/relay/main.go +++ b/go-libp2p/examples/relay/main.go @@ -27,7 +27,7 @@ func run() { unreachable1, err := libp2p.New( libp2p.NoListenAddrs, // Usually EnableRelay() is not required as it is enabled by default - // but NoListenAddrs overrides this, so we're adding it in explictly again. + // but NoListenAddrs overrides this, so we're adding it in explicitly again. libp2p.EnableRelay(), ) if err != nil { diff --git a/go-libp2p/examples/routed-echo/main.go b/go-libp2p/examples/routed-echo/main.go index 2f40549..342661b 100644 --- a/go-libp2p/examples/routed-echo/main.go +++ b/go-libp2p/examples/routed-echo/main.go @@ -83,7 +83,7 @@ func makeRoutedHost(listenPort int, randseed int64, bootstrapPeers []peer.AddrIn } // Build host multiaddress - hostAddr, _ := ma.NewMultiaddr(fmt.Sprintf("/ipfs/%s", routedHost.ID().Pretty())) + hostAddr, _ := ma.NewMultiaddr(fmt.Sprintf("/ipfs/%s", routedHost.ID())) // Now we can build a full multiaddress to reach this host // by encapsulating both addresses: @@ -94,7 +94,7 @@ func makeRoutedHost(listenPort int, randseed int64, bootstrapPeers []peer.AddrIn log.Println(addr.Encapsulate(hostAddr)) } - log.Printf("Now run \"./routed-echo -l %d -d %s%s\" on a different terminal\n", listenPort+1, routedHost.ID().Pretty(), globalFlag) + log.Printf("Now run \"./routed-echo -l %d -d %s%s\" on a different terminal\n", listenPort+1, routedHost.ID(), globalFlag) return routedHost, nil } diff --git a/go-libp2p/go.mod b/go-libp2p/go.mod index 980dd8a..bff7698 100644 --- a/go-libp2p/go.mod +++ b/go-libp2p/go.mod @@ -1,64 +1,69 @@ module github.com/libp2p/go-libp2p -go 1.19 +go 1.21 retract v0.26.1 // Tag was applied incorrectly due to a bug in the release workflow. require ( github.com/benbjohnson/clock v1.3.5 github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 - github.com/flynn/noise v1.0.0 - github.com/golang/mock v1.6.0 + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 + github.com/flynn/noise v1.1.0 github.com/google/gopacket v1.1.19 - github.com/gorilla/websocket v1.5.0 - github.com/hashicorp/golang-lru/v2 v2.0.2 + github.com/gorilla/websocket v1.5.1 + github.com/hashicorp/golang-lru/arc/v2 v2.0.7 + github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/ipfs/go-cid v0.4.1 github.com/ipfs/go-datastore v0.6.0 github.com/ipfs/go-ds-badger v0.3.0 github.com/ipfs/go-ds-leveldb v0.5.0 github.com/ipfs/go-log/v2 v2.5.1 github.com/jbenet/go-temp-err-catcher v0.1.0 - github.com/klauspost/compress v1.16.7 + github.com/klauspost/compress v1.17.8 github.com/libp2p/go-buffer-pool v0.1.0 github.com/libp2p/go-flow-metrics v0.1.0 - github.com/libp2p/go-libp2p-asn-util v0.3.0 + github.com/libp2p/go-libp2p-asn-util v0.4.1 github.com/libp2p/go-libp2p-testing v0.12.0 - github.com/libp2p/go-mplex v0.7.0 github.com/libp2p/go-msgio v0.3.0 github.com/libp2p/go-nat v0.2.0 github.com/libp2p/go-netroute v0.2.1 - github.com/libp2p/go-reuseport v0.3.0 + github.com/libp2p/go-reuseport v0.4.0 github.com/libp2p/go-yamux/v4 v4.0.1 github.com/libp2p/zeroconf/v2 v2.2.0 github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b - github.com/minio/sha256-simd v1.0.1 github.com/mr-tron/base58 v1.2.0 github.com/multiformats/go-base32 v0.1.0 - github.com/multiformats/go-multiaddr v0.10.1 + github.com/multiformats/go-multiaddr v0.12.4 github.com/multiformats/go-multiaddr-dns v0.3.1 github.com/multiformats/go-multiaddr-fmt v0.1.0 github.com/multiformats/go-multibase v0.2.0 github.com/multiformats/go-multicodec v0.9.0 github.com/multiformats/go-multihash v0.2.3 - github.com/multiformats/go-multistream v0.4.1 + github.com/multiformats/go-multistream v0.5.0 github.com/multiformats/go-varint v0.0.7 github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 - github.com/prometheus/client_golang v1.14.0 - github.com/prometheus/client_model v0.4.0 - github.com/quic-go/quic-go v0.36.3 - github.com/quic-go/webtransport-go v0.5.3 + github.com/pion/datachannel v1.5.6 + github.com/pion/ice/v2 v2.3.24 + github.com/pion/logging v0.2.2 + github.com/pion/sctp v1.8.16 + github.com/pion/stun v0.6.1 + github.com/pion/webrtc/v3 v3.2.40 + github.com/prometheus/client_golang v1.19.1 + github.com/prometheus/client_model v0.6.1 + github.com/quic-go/quic-go v0.44.0 + github.com/quic-go/webtransport-go v0.8.0 github.com/raulk/go-watchdog v1.3.0 - github.com/stretchr/testify v1.8.4 - go.uber.org/fx v1.20.0 - go.uber.org/goleak v1.1.12 - golang.org/x/crypto v0.11.0 - golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 - golang.org/x/sync v0.3.0 - golang.org/x/sys v0.10.0 - golang.org/x/tools v0.11.0 - google.golang.org/protobuf v1.30.0 + github.com/stretchr/testify v1.9.0 + go.uber.org/fx v1.21.1 + go.uber.org/goleak v1.3.0 + go.uber.org/mock v0.4.0 + golang.org/x/crypto v0.23.0 + golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 + golang.org/x/sync v0.7.0 + golang.org/x/sys v0.20.0 + golang.org/x/tools v0.21.0 + google.golang.org/protobuf v1.34.1 ) require ( @@ -66,7 +71,6 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/cloudflare/circl v1.3.3 github.com/containerd/cgroups v1.1.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -76,44 +80,55 @@ require ( github.com/dustin/go-humanize v1.0.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect github.com/francoispqt/gojay v1.2.13 // indirect - github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect - github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect - github.com/google/uuid v1.3.0 // indirect - github.com/huin/goupnp v1.2.0 // indirect + github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect + github.com/google/uuid v1.4.0 // indirect + github.com/huin/goupnp v1.3.0 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/goprocess v0.1.4 // indirect - github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/koron/go-ssdp v0.0.4 // indirect - github.com/libp2p/go-cidranger v1.1.0 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/miekg/dns v1.1.55 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/miekg/dns v1.1.58 // indirect github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect + github.com/minio/sha256-simd v1.0.1 // indirect github.com/multiformats/go-base36 v0.2.0 // indirect - github.com/onsi/ginkgo v1.16.5 // indirect - github.com/onsi/ginkgo/v2 v2.11.0 // indirect - github.com/opencontainers/runtime-spec v1.0.2 // indirect + github.com/nxadm/tail v1.4.11 // indirect + github.com/onsi/ginkgo/v2 v2.15.0 // indirect + github.com/opencontainers/runtime-spec v1.2.0 // indirect + github.com/pion/dtls/v2 v2.2.11 // indirect + github.com/pion/interceptor v0.1.29 // indirect + github.com/pion/mdns v0.0.12 // indirect + github.com/pion/randutil v0.1.0 // indirect + github.com/pion/rtcp v1.2.14 // indirect + github.com/pion/rtp v1.8.6 // indirect + github.com/pion/sdp/v3 v3.0.9 // indirect + github.com/pion/srtp/v2 v2.0.18 // indirect + github.com/pion/transport/v2 v2.2.5 // indirect + github.com/pion/turn/v2 v2.1.6 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/common v0.37.0 // indirect - github.com/prometheus/procfs v0.8.0 // indirect + github.com/prometheus/common v0.48.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/qtls-go1-19 v0.3.3 // indirect - github.com/quic-go/qtls-go1-20 v0.2.3 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect - go.uber.org/atomic v1.11.0 // indirect - go.uber.org/dig v1.17.0 // indirect + go.uber.org/dig v1.17.1 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.24.0 // indirect - golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.12.0 // indirect - golang.org/x/text v0.11.0 // indirect + go.uber.org/zap v1.27.0 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/text v0.15.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.2.1 // indirect ) + +// Remove this once fx releases the next version. +// We want to ship with a fix around SIGINT handling: +// https://github.com/uber-go/fx/pull/1198. +// Context: https://github.com/libp2p/go-libp2p/issues/2785 +replace go.uber.org/fx v1.21.1 => github.com/uber-go/fx v1.21.2-0.20240515133256-cb9cccf55845 diff --git a/go-libp2p/go.sum b/go-libp2p/go.sum index 21ddf91..5455f12 100644 --- a/go-libp2p/go.sum +++ b/go-libp2p/go.sum @@ -2,38 +2,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.31.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.37.0/go.mod h1:TS1dMSSfndXH133OKGwekG838Om/cQT0BUHV3HcBgoo= -cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= -cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= -cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= -cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= -cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= -cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= -cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= -cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= -cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= -cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= -cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= -cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= -cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= -cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= -cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= -cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= -cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= -cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= -cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= -cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= -cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= -cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= -cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= -cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= -cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= -cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= -cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= -cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= -cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= -cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/app/changes v0.0.0-20180602232624-0a106ad413e3/go.mod h1:Yl+fi1br7+Rr3LqpNJf1/uxUdtRUV+Tnj0o93V2B9MU= -dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBrvjyP0v+ecvNYvCpyZgu5/xkfAUhi6wJj28eUfSU= dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4= dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU= @@ -41,14 +10,8 @@ git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGy github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 h1:cTp8I5+VIoKjsnZuH8vjyaysT/ses3EvZeaV/1UkF2M= github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= @@ -56,26 +19,16 @@ github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o= github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/cilium/ebpf v0.2.0/go.mod h1:To2CFviqOWL/M0gIMsvSMlqe7em/l1ALkX1PyjrX2Qs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= -github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/containerd/cgroups v0.0.0-20201119153540-4cbc285b3327/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE= github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw= @@ -95,8 +48,9 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/dgraph-io/badger v1.6.2 h1:mNw0qs90GVgGGWylh0umH5iag1j6n/PeJtNvL6KY/x8= github.com/dgraph-io/badger v1.6.2/go.mod h1:JW2yswe3V058sS0kZ2h/AXeDSqFjxnZcRrVH//y2UQE= github.com/dgraph-io/ristretto v0.0.2 h1:a5WaUrDa0qm0YrAAS1tUykT5El3kt62KNZZeMxQn3po= @@ -111,36 +65,19 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/elastic/gosigar v0.12.0/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/4= github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= -github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= +github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg= +github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= -github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= +github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= -github.com/go-kit/log v0.2.0/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -152,90 +89,50 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= -github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 h1:n6vlPhxsA+BW/XsS5+uqi7GyzaLa5MH7qlSLBZtRdiA= -github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 h1:E/LAvt58di64hlYjx7AsNS6C/ysHWYo+2qPCZKTQhRo= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= -github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru/v2 v2.0.2 h1:Dwmkdr5Nc/oBiXgJS3CDHNhJtIHkuZ3DZF5twqnfBdU= -github.com/hashicorp/golang-lru/v2 v2.0.2/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/hashicorp/golang-lru/arc/v2 v2.0.7 h1:QxkVTxwColcduO+LP7eJO56r2hFiG8zEbfAAzRv52KQ= +github.com/hashicorp/golang-lru/arc/v2 v2.0.7/go.mod h1:Pe7gBlGdc8clY5LJ0LpJXMt5AmgmWNH1g+oFFVUHOEc= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY= -github.com/huin/goupnp v1.2.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= -github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= +github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= @@ -260,55 +157,43 @@ github.com/jbenet/go-temp-err-catcher v0.1.0/go.mod h1:0kJRvmDZXNMIiJirNPEYfhpPw github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o= github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= -github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= -github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= +github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= -github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c= -github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic= github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM= github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= -github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= -github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w= +github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94= +github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= -github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY= -github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU= github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk= github.com/libp2p/go-nat v0.2.0/go.mod h1:3MJr+GRpRkyT65EpVPBstXLvOlAPzUVlG6Pwg9ohLJk= github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU= github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ= -github.com/libp2p/go-reuseport v0.3.0 h1:iiZslO5byUYZEg9iCwJGf5h+sf1Agmqx2V2FDjPyvUw= -github.com/libp2p/go-reuseport v0.3.0/go.mod h1:laea40AimhtfEqysZ71UpYj4S+R9VpH8PgqLo7L+SwI= +github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s= +github.com/libp2p/go-reuseport v0.4.0/go.mod h1:ZtI03j/wO5hZVDFo2jKywN6bYKWLOy8Se6DrI2E1cLU= github.com/libp2p/go-yamux/v4 v4.0.1 h1:FfDR4S1wj6Bw2Pqbc8Uz7pCxeRBPbwsBbEdfwiCypkQ= github.com/libp2p/go-yamux/v4 v4.0.1/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4= github.com/libp2p/zeroconf/v2 v2.2.0 h1:Cup06Jv6u81HLhIj1KasuNM/RHHrJ8T7wOTS4+Tv53Q= @@ -319,16 +204,14 @@ github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= -github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo= -github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= +github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4= +github.com/miekg/dns v1.1.58/go.mod h1:Ypv+3b/KadlvW9vJfXOTf300O4UqaHFzFCuHz+rPkBY= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c h1:bzE/A84HN25pxAuk9Eej1Kz9OUelF97nAc82bDquQI8= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c/go.mod h1:0SQS9kMwD2VsyFEB++InYyBJroV/FRmBgcydeSUcJms= github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b h1:z78hV3sbSMAUoyUMM0I83AUIT6Hu17AWfgjzIbtrYFc= @@ -341,11 +224,8 @@ github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dz github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= @@ -355,8 +235,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= -github.com/multiformats/go-multiaddr v0.10.1 h1:HghtFrWyZEPrpTvgAMFJi6gFdgHfs2cb0pyfDsk+lqU= -github.com/multiformats/go-multiaddr v0.10.1/go.mod h1:jLEZsA61rwWNZQTHHnqq2HNa+4os/Hz54eqiRnsRqYQ= +github.com/multiformats/go-multiaddr v0.12.4 h1:rrKqpY9h+n80EwhhC/kkcunCZZ7URIF8yN1WEUt2Hvc= +github.com/multiformats/go-multiaddr v0.12.4/go.mod h1:sBXrNzucqkFJhvKOiwwLyqamGa/P5EIXNPLovyhQCII= github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= @@ -368,83 +248,103 @@ github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI1 github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= -github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3de4741sbiSdfo= -github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= +github.com/multiformats/go-multistream v0.5.0 h1:5htLSLl7lvJk3xx3qT/8Zm9J4K8vEOf/QGkvOGQAyiE= +github.com/multiformats/go-multistream v0.5.0/go.mod h1:n6tMZiwiP2wUsR8DgfDWw1dydlEqV3l6N3/GBsX6ILA= github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY= +github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= -github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= +github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= +github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc= -github.com/opencontainers/runtime-spec v1.0.2 h1:UfAcuLBJB9Coz72x1hgl8O5RVzTdNiaglX6v2DM6FI0= +github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= +github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= +github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk= +github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pion/datachannel v1.5.6 h1:1IxKJntfSlYkpUj8LlYRSWpYiTTC02nUrOE8T3DqGeg= +github.com/pion/datachannel v1.5.6/go.mod h1:1eKT6Q85pRnr2mHiWHxJwO50SfZRtWHTsNIVb/NfGW4= +github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s= +github.com/pion/dtls/v2 v2.2.11 h1:9U/dpCYl1ySttROPWJgqWKEylUdT0fXp/xst6JwY5Ks= +github.com/pion/dtls/v2 v2.2.11/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE= +github.com/pion/ice/v2 v2.3.24 h1:RYgzhH/u5lH0XO+ABatVKCtRd+4U1GEaCXSMjNr13tI= +github.com/pion/ice/v2 v2.3.24/go.mod h1:KXJJcZK7E8WzrBEYnV4UtqEZsGeWfHxsNqhVcVvgjxw= +github.com/pion/interceptor v0.1.29 h1:39fsnlP1U8gw2JzOFWdfCU82vHvhW9o0rZnZF56wF+M= +github.com/pion/interceptor v0.1.29/go.mod h1:ri+LGNjRUc5xUNtDEPzfdkmSqISixVTBF/z/Zms/6T4= +github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY= +github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms= +github.com/pion/mdns v0.0.12 h1:CiMYlY+O0azojWDmxdNr7ADGrnZ+V6Ilfner+6mSVK8= +github.com/pion/mdns v0.0.12/go.mod h1:VExJjv8to/6Wqm1FXK+Ii/Z9tsVk/F5sD/N70cnYFbk= +github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= +github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= +github.com/pion/rtcp v1.2.12/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= +github.com/pion/rtcp v1.2.14 h1:KCkGV3vJ+4DAJmvP0vaQShsb0xkRfWkO540Gy102KyE= +github.com/pion/rtcp v1.2.14/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= +github.com/pion/rtp v1.8.3/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= +github.com/pion/rtp v1.8.6 h1:MTmn/b0aWWsAzux2AmP8WGllusBVw4NPYPVFFd7jUPw= +github.com/pion/rtp v1.8.6/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= +github.com/pion/sctp v1.8.13/go.mod h1:YKSgO/bO/6aOMP9LCie1DuD7m+GamiK2yIiPM6vH+GA= +github.com/pion/sctp v1.8.16 h1:PKrMs+o9EMLRvFfXq59WFsC+V8mN1wnKzqrv+3D/gYY= +github.com/pion/sctp v1.8.16/go.mod h1:P6PbDVA++OJMrVNg2AL3XtYHV4uD6dvfyOovCgMs0PE= +github.com/pion/sdp/v3 v3.0.9 h1:pX++dCHoHUwq43kuwf3PyJfHlwIj4hXA7Vrifiq0IJY= +github.com/pion/sdp/v3 v3.0.9/go.mod h1:B5xmvENq5IXJimIO4zfp6LAe1fD9N+kFv+V/1lOdz8M= +github.com/pion/srtp/v2 v2.0.18 h1:vKpAXfawO9RtTRKZJbG4y0v1b11NZxQnxRl85kGuUlo= +github.com/pion/srtp/v2 v2.0.18/go.mod h1:0KJQjA99A6/a0DOVTu1PhDSw0CXF2jTkqOoMg3ODqdA= +github.com/pion/stun v0.6.1 h1:8lp6YejULeHBF8NmV8e2787BogQhduZugh5PdhDyyN4= +github.com/pion/stun v0.6.1/go.mod h1:/hO7APkX4hZKu/D0f2lHzNyvdkTGtIy3NDmLR7kSz/8= +github.com/pion/transport/v2 v2.2.1/go.mod h1:cXXWavvCnFF6McHTft3DWS9iic2Mftcz1Aq29pGcU5g= +github.com/pion/transport/v2 v2.2.2/go.mod h1:OJg3ojoBJopjEeECq2yJdXH9YVrUJ1uQ++NjXLOUorc= +github.com/pion/transport/v2 v2.2.3/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= +github.com/pion/transport/v2 v2.2.4/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= +github.com/pion/transport/v2 v2.2.5 h1:iyi25i/21gQck4hfRhomF6SktmUQjRsRW4WJdhfc3Kc= +github.com/pion/transport/v2 v2.2.5/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= +github.com/pion/transport/v3 v3.0.1/go.mod h1:UY7kiITrlMv7/IKgd5eTUcaahZx5oUN3l9SzK5f5xE0= +github.com/pion/transport/v3 v3.0.2 h1:r+40RJR25S9w3jbA6/5uEPTzcdn7ncyU44RWCbHkLg4= +github.com/pion/transport/v3 v3.0.2/go.mod h1:nIToODoOlb5If2jF9y2Igfx3PFYWfuXi37m0IlWa/D0= +github.com/pion/turn/v2 v2.1.3/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= +github.com/pion/turn/v2 v2.1.6 h1:Xr2niVsiPTB0FPtt+yAWKFUkU1eotQbGgpTIld4x1Gc= +github.com/pion/turn/v2 v2.1.6/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= +github.com/pion/webrtc/v3 v3.2.40 h1:Wtfi6AZMQg+624cvCXUuSmrKWepSB7zfgYDOYqsSOVU= +github.com/pion/webrtc/v3 v3.2.40/go.mod h1:M1RAe3TNTD1tzyvqHrbVODfwdPGSXOUo/OgpoGGJqFY= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= -github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= -github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= -github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= +github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= +github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= -github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= -github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= -github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= -github.com/prometheus/common v0.37.0 h1:ccBbHCgIiT9uSoFY0vX8H3zsNR5eLt17/RQLUvn8pXE= -github.com/prometheus/common v0.37.0/go.mod h1:phzohg0JFMnBEFGxTDbfu3QyL5GI8gTQJFhYO5B3mfA= +github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= +github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo= -github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/qtls-go1-19 v0.3.3 h1:wznEHvJwd+2X3PqftRha0SUKmGsnb6dfArMhy9PeJVE= -github.com/quic-go/qtls-go1-19 v0.3.3/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.2.3 h1:m575dovXn1y2ATOb1XrRFcrv0F+EQmlowTkoraNkDPI= -github.com/quic-go/qtls-go1-20 v0.2.3/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.36.3 h1:f+yOqeGhMoRX7/M3wmEw/djhzKWr15FtQysox85/834= -github.com/quic-go/quic-go v0.36.3/go.mod h1:qxQumdeKw5GmWs1OsTZZnOxzSI+RJWuhf1O8FN35L2o= -github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= -github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= +github.com/quic-go/quic-go v0.44.0 h1:So5wOr7jyO4vzL2sd8/pD9Kesciv91zSk8BoFngItQ0= +github.com/quic-go/quic-go v0.44.0/go.mod h1:z4cx/9Ny9UtGITIPzmPTXh1ULfOyWh4qGQlpnPcWmek= +github.com/quic-go/webtransport-go v0.8.0 h1:HxSrwun11U+LlmwpgM1kEqIqH90IT4N8auv/cD7QFJg= +github.com/quic-go/webtransport-go v0.8.0/go.mod h1:N99tjprW432Ut5ONql/aUhSLT0YVSlwHohQsuac9WaM= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= @@ -471,9 +371,6 @@ github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go. github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4= github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= @@ -487,45 +384,44 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6 github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= +github.com/uber-go/fx v1.21.2-0.20240515133256-cb9cccf55845 h1:1ZbnuG7aj1UxZnfsJmEpACmspZMkj5Fdvg7C1yWgQCE= +github.com/uber-go/fx v1.21.2-0.20240515133256-cb9cccf55845/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= -go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= -go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI= -go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU= -go.uber.org/fx v1.20.0 h1:ZMC/pnRvhsthOZh9MZjMq5U8Or3mA9zBSPaLnzs3ihQ= -go.uber.org/fx v1.20.0/go.mod h1:qCUj0btiR3/JnanEr1TYEePfSw6o/4qYJscgvzQ5Ub0= +go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc= +go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= -go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -533,113 +429,78 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8 go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.14.1/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= -go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= +golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= -golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= -golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= -golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= -golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw= -golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= -golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181029044818-c44066c5c816/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= -golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= +golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/perf v0.0.0-20180704124530-6e6d33e29852/go.mod h1:JLpeXjPJfIyPr5TlbXLkXWLhP8nz10XfvxElABhCtcw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -647,90 +508,74 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190316082340-a2f829d7f35f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210426080607-c94f62235c83/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= +golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= +golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -738,51 +583,18 @@ golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= -golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= -golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw= +golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -790,93 +602,23 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y= -google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= -google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= -google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20181202183823-bd91e49a0898/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg= google.golang.org/genproto v0.0.0-20190306203927-b5d61aea6440/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= -google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= -google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= -google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -889,11 +631,7 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= @@ -902,15 +640,8 @@ grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJd honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI= lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= -rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= -rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck= sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0= diff --git a/go-libp2p/leaky_tests/README.md b/go-libp2p/leaky_tests/README.md new file mode 100644 index 0000000..398a91a --- /dev/null +++ b/go-libp2p/leaky_tests/README.md @@ -0,0 +1 @@ +Tests that leak goroutines for various reasons. Mostly because libp2p node shutdown logic doesn't run if we fail to construct the node. diff --git a/go-libp2p/leaky_tests/leaky_test.go b/go-libp2p/leaky_tests/leaky_test.go new file mode 100644 index 0000000..172b656 --- /dev/null +++ b/go-libp2p/leaky_tests/leaky_test.go @@ -0,0 +1,19 @@ +package leaky_test + +import ( + "strings" + "testing" + + "github.com/libp2p/go-libp2p" +) + +func TestBadTransportConstructor(t *testing.T) { + h, err := libp2p.New(libp2p.Transport(func() {})) + if err == nil { + h.Close() + t.Fatal("expected an error") + } + if !strings.Contains(err.Error(), "_test.go") { + t.Error("expected error to contain debugging info") + } +} diff --git a/go-libp2p/libp2p.go b/go-libp2p/libp2p.go index db23253..1440648 100644 --- a/go-libp2p/libp2p.go +++ b/go-libp2p/libp2p.go @@ -42,13 +42,13 @@ func ChainOptions(opts ...Option) Option { // - If no security transport is provided, the host uses the go-libp2p's noise // and/or tls encrypted transport to encrypt all traffic; // -// - If no peer identity is provided, it generates a random RSA 2048 key-pair +// - If no peer identity is provided, it generates a random Ed25519 key-pair // and derives a new identity from it; // // - If no peerstore is provided, the host is initialized with an empty // peerstore. // -// To stop/shutdown the returned libp2p node, the user needs to cancel the passed context and call `Close` on the returned Host. +// To stop/shutdown the returned libp2p node, the user needs to call `Close` on the returned Host. func New(opts ...Option) (host.Host, error) { return NewWithoutDefaults(append(opts, FallbackDefaults)...) } diff --git a/go-libp2p/libp2p_test.go b/go-libp2p/libp2p_test.go index 7d947af..8a9a8ed 100644 --- a/go-libp2p/libp2p_test.go +++ b/go-libp2p/libp2p_test.go @@ -2,22 +2,31 @@ package libp2p import ( "context" + "crypto/rand" + "errors" "fmt" "regexp" - "strings" "testing" + "time" "github.com/libp2p/go-libp2p/core/connmgr" "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/event" "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/peerstore" + "github.com/libp2p/go-libp2p/core/routing" "github.com/libp2p/go-libp2p/core/transport" + rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" "github.com/libp2p/go-libp2p/p2p/net/swarm" + "github.com/libp2p/go-libp2p/p2p/protocol/ping" "github.com/libp2p/go-libp2p/p2p/security/noise" tls "github.com/libp2p/go-libp2p/p2p/security/tls" quic "github.com/libp2p/go-libp2p/p2p/transport/quic" "github.com/libp2p/go-libp2p/p2p/transport/tcp" webtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport" + "go.uber.org/goleak" ma "github.com/multiformats/go-multiaddr" "github.com/stretchr/testify/require" @@ -31,17 +40,6 @@ func TestNewHost(t *testing.T) { h.Close() } -func TestBadTransportConstructor(t *testing.T) { - h, err := New(Transport(func() {})) - if err == nil { - h.Close() - t.Fatal("expected an error") - } - if !strings.Contains(err.Error(), "libp2p_test.go") { - t.Error("expected error to contain debugging info") - } -} - func TestTransportConstructor(t *testing.T) { ctor := func( h host.Host, @@ -91,15 +89,9 @@ func TestInsecure(t *testing.T) { h.Close() } -func TestAutoNATService(t *testing.T) { - h, err := New(EnableNATService()) - require.NoError(t, err) - h.Close() -} - func TestDefaultListenAddrs(t *testing.T) { reTCP := regexp.MustCompile("/(ip)[4|6]/((0.0.0.0)|(::))/tcp/") - reQUIC := regexp.MustCompile("/(ip)[4|6]/((0.0.0.0)|(::))/udp/([0-9]*)/quic") + reQUIC := regexp.MustCompile("/(ip)[4|6]/((0.0.0.0)|(::))/udp/([0-9]*)/quic-v1") reCircuit := regexp.MustCompile("/p2p-circuit") // Test 1: Setting the correct listen addresses if userDefined.Transport == nil && userDefined.ListenAddrs == nil @@ -180,7 +172,7 @@ func TestTransportConstructorTCP(t *testing.T) { require.NoError(t, err) defer h.Close() require.NoError(t, h.Network().Listen(ma.StringCast("/ip4/127.0.0.1/tcp/0"))) - err = h.Network().Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic")) + err = h.Network().Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1")) require.Error(t, err) require.Contains(t, err.Error(), swarm.ErrNoTransport.Error()) } @@ -192,7 +184,7 @@ func TestTransportConstructorQUIC(t *testing.T) { ) require.NoError(t, err) defer h.Close() - require.NoError(t, h.Network().Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic"))) + require.NoError(t, h.Network().Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1"))) err = h.Network().Listen(ma.StringCast("/ip4/127.0.0.1/tcp/0")) require.Error(t, err) require.Contains(t, err.Error(), swarm.ErrNoTransport.Error()) @@ -325,8 +317,8 @@ func TestTransportCustomAddressWebTransport(t *testing.T) { require.NotEqual(t, addrs[0], customAddr) restOfAddr, lastComp := ma.SplitLast(addrs[0]) restOfAddr, secondToLastComp := ma.SplitLast(restOfAddr) - require.Equal(t, lastComp.Protocol().Code, ma.P_CERTHASH) - require.Equal(t, secondToLastComp.Protocol().Code, ma.P_CERTHASH) + require.Equal(t, ma.P_CERTHASH, lastComp.Protocol().Code) + require.Equal(t, ma.P_CERTHASH, secondToLastComp.Protocol().Code) require.True(t, restOfAddr.Equal(customAddr)) } @@ -352,7 +344,118 @@ func TestTransportCustomAddressWebTransportDoesNotStall(t *testing.T) { addrs := h.Addrs() require.Len(t, addrs, 1) _, lastComp := ma.SplitLast(addrs[0]) - require.NotEqual(t, lastComp.Protocol().Code, ma.P_CERTHASH) + require.NotEqual(t, ma.P_CERTHASH, lastComp.Protocol().Code) // We did not add the certhash to the multiaddr require.Equal(t, addrs[0], customAddr) } + +type mockPeerRouting struct { + queried []peer.ID +} + +func (r *mockPeerRouting) FindPeer(_ context.Context, id peer.ID) (peer.AddrInfo, error) { + r.queried = append(r.queried, id) + return peer.AddrInfo{}, errors.New("mock peer routing error") +} + +func TestRoutedHost(t *testing.T) { + mockRouter := &mockPeerRouting{} + h, err := New( + NoListenAddrs, + Routing(func(host.Host) (routing.PeerRouting, error) { return mockRouter, nil }), + DisableRelay(), + ) + require.NoError(t, err) + defer h.Close() + + priv, _, err := crypto.GenerateEd25519Key(rand.Reader) + require.NoError(t, err) + id, err := peer.IDFromPrivateKey(priv) + require.NoError(t, err) + require.EqualError(t, h.Connect(context.Background(), peer.AddrInfo{ID: id}), "mock peer routing error") + require.Equal(t, []peer.ID{id}, mockRouter.queried) +} + +func TestAutoNATService(t *testing.T) { + h, err := New(EnableNATService()) + require.NoError(t, err) + h.Close() +} + +func TestInsecureConstructor(t *testing.T) { + h, err := New( + EnableNATService(), + NoSecurity, + ) + require.NoError(t, err) + h.Close() + + h, err = New( + NoSecurity, + ) + require.NoError(t, err) + h.Close() +} + +func TestDisableIdentifyAddressDiscovery(t *testing.T) { + h, err := New(DisableIdentifyAddressDiscovery()) + require.NoError(t, err) + h.Close() +} + +func TestMain(m *testing.M) { + goleak.VerifyTestMain( + m, + // This will return eventually (5s timeout) but doesn't take a context. + goleak.IgnoreAnyFunction("github.com/koron/go-ssdp.Search"), + // Logging & Stats + goleak.IgnoreTopFunction("github.com/ipfs/go-log/v2/writer.(*MirrorWriter).logRoutine"), + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + goleak.IgnoreAnyFunction("github.com/jackpal/go-nat-pmp.(*Client).GetExternalAddress"), + ) +} + +func TestDialCircuitAddrWithWrappedResourceManager(t *testing.T) { + relay, err := New(EnableRelayService()) + require.NoError(t, err) + defer relay.Close() + + // Fake that the relay is publicly reachable + emitterForRelay, err := relay.EventBus().Emitter(&event.EvtLocalReachabilityChanged{}) + require.NoError(t, err) + defer emitterForRelay.Close() + emitterForRelay.Emit(event.EvtLocalReachabilityChanged{Reachability: network.ReachabilityPublic}) + + peerBehindRelay, err := New(EnableAutoRelayWithStaticRelays([]peer.AddrInfo{{ID: relay.ID(), Addrs: relay.Addrs()}})) + require.NoError(t, err) + defer peerBehindRelay.Close() + // Emit an event to tell this peer it is private + emitterForPeerBehindRelay, err := peerBehindRelay.EventBus().Emitter(&event.EvtLocalReachabilityChanged{}) + require.NoError(t, err) + defer emitterForPeerBehindRelay.Close() + emitterForPeerBehindRelay.Emit(event.EvtLocalReachabilityChanged{Reachability: network.ReachabilityPrivate}) + + // Use a wrapped resource manager to test that the circuit dialing works + // with it. Look at the PR introducing this test for context + type wrappedRcmgr struct{ network.ResourceManager } + mgr, err := rcmgr.NewResourceManager(rcmgr.NewFixedLimiter(rcmgr.DefaultLimits.AutoScale())) + require.NoError(t, err) + wmgr := wrappedRcmgr{mgr} + h, err := New(ResourceManager(wmgr)) + require.NoError(t, err) + defer h.Close() + + h.Peerstore().AddAddrs(relay.ID(), relay.Addrs(), 10*time.Minute) + h.Peerstore().AddAddr(peerBehindRelay.ID(), + ma.StringCast( + fmt.Sprintf("/p2p/%s/p2p-circuit", relay.ID()), + ), + peerstore.TempAddrTTL, + ) + require.NoError(t, err) + + ctx, cancel := context.WithCancel(context.Background()) + res := <-ping.Ping(ctx, h, peerBehindRelay.ID()) + require.NoError(t, res.Error) + defer cancel() +} diff --git a/go-libp2p/options.go b/go-libp2p/options.go index beb4930..de95251 100644 --- a/go-libp2p/options.go +++ b/go-libp2p/options.go @@ -349,7 +349,7 @@ func EnableAutoRelayWithPeerSource(peerSource autorelay.PeerSource, opts ...auto // forcing the local node to believe it is reachable externally. func ForceReachabilityPublic() Option { return func(cfg *Config) error { - public := network.Reachability(network.ReachabilityPublic) + public := network.ReachabilityPublic cfg.AutoNATConfig.ForceReachability = &public return nil } @@ -359,7 +359,7 @@ func ForceReachabilityPublic() Option { // forceing the local node to believe it is behind a NAT and not reachable externally. func ForceReachabilityPrivate() Option { return func(cfg *Config) error { - private := network.Reachability(network.ReachabilityPrivate) + private := network.ReachabilityPrivate cfg.AutoNATConfig.ForceReachability = &private return nil } @@ -579,6 +579,7 @@ func PrometheusRegisterer(reg prometheus.Registerer) Option { // DialRanker configures libp2p to use d as the dial ranker. To enable smart // dialing use `swarm.DefaultDialRanker`. use `swarm.NoDelayDialRanker` to // disable smart dialing. +// // Deprecated: use SwarmOpts(swarm.WithDialRanker(d)) instead func DialRanker(d network.DialRanker) Option { return func(cfg *Config) error { @@ -597,3 +598,14 @@ func SwarmOpts(opts ...swarm.Option) Option { return nil } } + +// DisableIdentifyAddressDiscovery disables address discovery using peer provided observed addresses +// in identify. If you know your public addresses upfront, the recommended way is to use +// AddressFactory to provide the external adddress to the host and use this option to disable +// discovery from identify. +func DisableIdentifyAddressDiscovery() Option { + return func(cfg *Config) error { + cfg.DisableIdentifyAddressDiscovery = true + return nil + } +} diff --git a/go-libp2p/p2p/discovery/backoff/backoffcache.go b/go-libp2p/p2p/discovery/backoff/backoffcache.go index 82c0724..c8f1180 100644 --- a/go-libp2p/p2p/discovery/backoff/backoffcache.go +++ b/go-libp2p/p2p/discovery/backoff/backoffcache.go @@ -82,14 +82,6 @@ func (c realClock) Now() time.Time { return time.Now() } -// withClock lets you override the default time.Now() call. Useful for tests. -func withClock(c clock) BackoffDiscoveryOption { - return func(b *BackoffDiscovery) error { - b.clock = c - return nil - } -} - type backoffCache struct { // strat is assigned on creation and not written to strat BackoffStrategy diff --git a/go-libp2p/p2p/discovery/backoff/backoffcache_test.go b/go-libp2p/p2p/discovery/backoff/backoffcache_test.go index fe528cc..6679415 100644 --- a/go-libp2p/p2p/discovery/backoff/backoffcache_test.go +++ b/go-libp2p/p2p/discovery/backoff/backoffcache_test.go @@ -80,6 +80,14 @@ func assertNumPeersWithLimit(t *testing.T, ctx context.Context, d discovery.Disc } } +// withClock lets you override the default time.Now() call. Useful for tests. +func withClock(c clock) BackoffDiscoveryOption { + return func(b *BackoffDiscovery) error { + b.clock = c + return nil + } +} + func TestBackoffDiscoverySingleBackoff(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/go-libp2p/p2p/host/autonat/autonat.go b/go-libp2p/p2p/host/autonat/autonat.go index fc8c676..479f31e 100644 --- a/go-libp2p/p2p/host/autonat/autonat.go +++ b/go-libp2p/p2p/host/autonat/autonat.go @@ -431,7 +431,7 @@ func (as *AmbientAutoNAT) getPeerToProbe() peer.ID { func (as *AmbientAutoNAT) Close() error { as.ctxCancel() if as.service != nil { - as.service.Disable() + return as.service.Close() } <-as.backgroundRunning return nil @@ -444,7 +444,7 @@ func (s *StaticAutoNAT) Status() network.Reachability { func (s *StaticAutoNAT) Close() error { if s.service != nil { - s.service.Disable() + return s.service.Close() } return nil } diff --git a/go-libp2p/p2p/host/autonat/svc.go b/go-libp2p/p2p/host/autonat/svc.go index 98b421c..d293550 100644 --- a/go-libp2p/p2p/host/autonat/svc.go +++ b/go-libp2p/p2p/host/autonat/svc.go @@ -68,7 +68,7 @@ func (as *autoNATService) handleStream(s network.Stream) { defer s.Close() pid := s.Conn().RemotePeer() - log.Debugf("New stream from %s", pid.Pretty()) + log.Debugf("New stream from %s", pid) r := pbio.NewDelimitedReader(s, maxMsgSize) w := pbio.NewDelimitedWriter(s) @@ -78,14 +78,14 @@ func (as *autoNATService) handleStream(s network.Stream) { err := r.ReadMsg(&req) if err != nil { - log.Debugf("Error reading message from %s: %s", pid.Pretty(), err.Error()) + log.Debugf("Error reading message from %s: %s", pid, err.Error()) s.Reset() return } t := req.GetType() if t != pb.Message_DIAL { - log.Debugf("Unexpected message from %s: %s (%d)", pid.Pretty(), t.String(), t) + log.Debugf("Unexpected message from %s: %s (%d)", pid, t.String(), t) s.Reset() return } @@ -96,7 +96,7 @@ func (as *autoNATService) handleStream(s network.Stream) { err = w.WriteMsg(&res) if err != nil { - log.Debugf("Error writing response to %s: %s", pid.Pretty(), err.Error()) + log.Debugf("Error writing response to %s: %s", pid, err.Error()) s.Reset() return } @@ -234,7 +234,7 @@ func (as *autoNATService) doDial(pi peer.AddrInfo) *pb.Message_DialResponse { conn, err := as.config.dialer.DialPeer(ctx, pi.ID) if err != nil { - log.Debugf("error dialing %s: %s", pi.ID.Pretty(), err.Error()) + log.Debugf("error dialing %s: %s", pi.ID, err.Error()) // wait for the context to timeout to avoid leaking timing information // this renders the service ineffective as a port scanner <-ctx.Done() @@ -273,6 +273,11 @@ func (as *autoNATService) Disable() { } } +func (as *autoNATService) Close() error { + as.Disable() + return as.config.dialer.Close() +} + func (as *autoNATService) background(ctx context.Context) { defer close(as.backgroundRunning) diff --git a/go-libp2p/p2p/host/autonat/svc_test.go b/go-libp2p/p2p/host/autonat/svc_test.go index 61e6038..d58a9b7 100644 --- a/go-libp2p/p2p/host/autonat/svc_test.go +++ b/go-libp2p/p2p/host/autonat/svc_test.go @@ -189,7 +189,7 @@ func TestAutoNATServiceRateLimitJitter(t *testing.T) { svc.mx.Lock() defer svc.mx.Unlock() return svc.globalReqs == 0 - }, dur*5/2, 10*time.Millisecond, "reset of rate limitter occured slower than expected") + }, dur*5/2, 10*time.Millisecond, "reset of rate limiter occurred slower than expected") } func TestAutoNATServiceStartup(t *testing.T) { diff --git a/go-libp2p/p2p/host/autorelay/addrsplosion.go b/go-libp2p/p2p/host/autorelay/addrsplosion.go index c6353b1..710dab1 100644 --- a/go-libp2p/p2p/host/autorelay/addrsplosion.go +++ b/go-libp2p/p2p/host/autorelay/addrsplosion.go @@ -54,7 +54,7 @@ func isRelayAddr(a ma.Multiaddr) bool { func isDNSAddr(a ma.Multiaddr) bool { if first, _ := ma.SplitFirst(a); first != nil { switch first.Protocol().Code { - case ma.P_DNS4, ma.P_DNS6, ma.P_DNSADDR: + case ma.P_DNS, ma.P_DNS4, ma.P_DNS6, ma.P_DNSADDR: return true } } diff --git a/go-libp2p/p2p/host/autorelay/addrsplosion_test.go b/go-libp2p/p2p/host/autorelay/addrsplosion_test.go index 0d8a57d..1bbd910 100644 --- a/go-libp2p/p2p/host/autorelay/addrsplosion_test.go +++ b/go-libp2p/p2p/host/autorelay/addrsplosion_test.go @@ -11,14 +11,14 @@ func TestCleanupAddrs(t *testing.T) { t.Run("with no addrplosion", func(t *testing.T) { addrs := makeAddrList( "/ip4/127.0.0.1/tcp/4001", - "/ip4/127.0.0.1/udp/4002/quic", + "/ip4/127.0.0.1/udp/4002/quic-v1", "/ip4/1.2.3.4/tcp/4001", - "/ip4/1.2.3.4/udp/4002/quic", + "/ip4/1.2.3.4/udp/4002/quic-v1", "/dnsaddr/somedomain.com/tcp/4002/ws", ) clean := makeAddrList( "/ip4/1.2.3.4/tcp/4001", - "/ip4/1.2.3.4/udp/4002/quic", + "/ip4/1.2.3.4/udp/4002/quic-v1", "/dnsaddr/somedomain.com/tcp/4002/ws", ) require.ElementsMatch(t, clean, cleanupAddressSet(addrs), "cleaned up set doesn't match expected") @@ -32,11 +32,11 @@ func TestCleanupAddrs(t *testing.T) { "/ip4/1.2.3.4/tcp/33333", "/ip4/1.2.3.4/tcp/33334", "/ip4/1.2.3.4/tcp/33335", - "/ip4/1.2.3.4/udp/4002/quic", + "/ip4/1.2.3.4/udp/4002/quic-v1", ) clean := makeAddrList( "/ip4/1.2.3.4/tcp/4001", - "/ip4/1.2.3.4/udp/4002/quic", + "/ip4/1.2.3.4/udp/4002/quic-v1", ) require.ElementsMatch(t, clean, cleanupAddressSet(addrs), "cleaned up set doesn't match expected") }) @@ -48,11 +48,11 @@ func TestCleanupAddrs(t *testing.T) { "/ip4/1.2.3.4/tcp/33333", "/ip4/1.2.3.4/tcp/33334", "/ip4/1.2.3.4/tcp/33335", - "/ip4/1.2.3.4/udp/4002/quic", + "/ip4/1.2.3.4/udp/4002/quic-v1", ) clean := makeAddrList( "/ip4/1.2.3.4/tcp/4001", - "/ip4/1.2.3.4/udp/4002/quic", + "/ip4/1.2.3.4/udp/4002/quic-v1", ) require.ElementsMatch(t, clean, cleanupAddressSet(addrs), "cleaned up set doesn't match expected") }) @@ -75,7 +75,7 @@ func TestCleanupAddrs(t *testing.T) { // test with a squeaky clean address set addrs := makeAddrList( "/ip4/1.2.3.4/tcp/4001", - "/ip4/1.2.3.4/udp/4001/quic", + "/ip4/1.2.3.4/udp/4001/quic-v1", ) require.ElementsMatch(t, addrs, cleanupAddressSet(addrs), "cleaned up set doesn't match expected") }) diff --git a/go-libp2p/p2p/host/autorelay/host.go b/go-libp2p/p2p/host/autorelay/host.go deleted file mode 100644 index c6bd9c5..0000000 --- a/go-libp2p/p2p/host/autorelay/host.go +++ /dev/null @@ -1,23 +0,0 @@ -package autorelay - -import ( - "github.com/libp2p/go-libp2p/core/host" -) - -type AutoRelayHost struct { - host.Host - ar *AutoRelay -} - -func (h *AutoRelayHost) Close() error { - _ = h.ar.Close() - return h.Host.Close() -} - -func (h *AutoRelayHost) Start() { - h.ar.Start() -} - -func NewAutoRelayHost(h host.Host, ar *AutoRelay) *AutoRelayHost { - return &AutoRelayHost{Host: h, ar: ar} -} diff --git a/go-libp2p/p2p/host/autorelay/metrics.go b/go-libp2p/p2p/host/autorelay/metrics.go index 8028655..af4b53e 100644 --- a/go-libp2p/p2p/host/autorelay/metrics.go +++ b/go-libp2p/p2p/host/autorelay/metrics.go @@ -59,7 +59,7 @@ var ( prometheus.CounterOpts{ Namespace: metricNamespace, Name: "candidates_circuit_v2_support_total", - Help: "Candidiates supporting circuit v2", + Help: "Candidates supporting circuit v2", }, []string{"support"}, ) @@ -167,7 +167,7 @@ func NewMetricsTracer(opts ...MetricsTracerOption) MetricsTracer { metricshelper.RegisterCollectors(setting.reg, collectors...) // Initialise these counters to 0 otherwise the first reservation requests aren't handled - // correctly when using promql increse function + // correctly when using promql increase function reservationRequestsOutcomeTotal.WithLabelValues("refresh", "success") reservationRequestsOutcomeTotal.WithLabelValues("new", "success") candidatesCircuitV2SupportTotal.WithLabelValues("yes") diff --git a/go-libp2p/p2p/host/autorelay/relay_finder.go b/go-libp2p/p2p/host/autorelay/relay_finder.go index 3133b7a..13f8c63 100644 --- a/go-libp2p/p2p/host/autorelay/relay_finder.go +++ b/go-libp2p/p2p/host/autorelay/relay_finder.go @@ -63,7 +63,7 @@ type relayFinder struct { candidates map[peer.ID]*candidate backoff map[peer.ID]time.Time maybeConnectToRelayTrigger chan struct{} // cap: 1 - // Any time _something_ hapens that might cause us to need new candidates. + // Any time _something_ happens that might cause us to need new candidates. // This could be // * the disconnection of a relay // * the failed attempt to obtain a reservation with a current candidate @@ -736,7 +736,7 @@ func (rf *relayFinder) relayAddrs(addrs []ma.Multiaddr) []ma.Multiaddr { for p := range rf.relays { addrs := cleanupAddressSet(rf.host.Peerstore().Addrs(p)) relayAddrCnt += len(addrs) - circuit := ma.StringCast(fmt.Sprintf("/p2p/%s/p2p-circuit", p.Pretty())) + circuit := ma.StringCast(fmt.Sprintf("/p2p/%s/p2p-circuit", p)) for _, addr := range addrs { pub := addr.Encapsulate(circuit) raddrs = append(raddrs, pub) diff --git a/go-libp2p/p2p/host/basic/basic_host.go b/go-libp2p/p2p/host/basic/basic_host.go index 79f02e2..8fc808e 100644 --- a/go-libp2p/p2p/host/basic/basic_host.go +++ b/go-libp2p/p2p/host/basic/basic_host.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net" + "slices" "sync" "time" @@ -27,6 +28,7 @@ import ( "github.com/libp2p/go-libp2p/p2p/protocol/holepunch" "github.com/libp2p/go-libp2p/p2p/protocol/identify" "github.com/libp2p/go-libp2p/p2p/protocol/ping" + libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc" libp2pwebtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport" "github.com/prometheus/client_golang/prometheus" @@ -52,6 +54,8 @@ var ( DefaultAddrsFactory = func(addrs []ma.Multiaddr) []ma.Multiaddr { return addrs } ) +const maxPeerRecordSize = 8 * 1024 // 8k to be compatible with identify's limit + // AddrsFactory functions can be passed to New in order to override // addresses returned by Addrs. type AddrsFactory func([]ma.Multiaddr) []ma.Multiaddr @@ -160,6 +164,9 @@ type HostOpts struct { EnableMetrics bool // PrometheusRegisterer is the PrometheusRegisterer used for metrics PrometheusRegisterer prometheus.Registerer + + // DisableIdentifyAddressDiscovery disables address discovery using peer provided observed addresses in identify + DisableIdentifyAddressDiscovery bool } // NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network. @@ -171,12 +178,11 @@ func NewHost(n network.Network, opts *HostOpts) (*BasicHost, error) { opts.EventBus = eventbus.NewBus() } - psManager, err := pstoremanager.NewPeerstoreManager(n.Peerstore(), opts.EventBus) + psManager, err := pstoremanager.NewPeerstoreManager(n.Peerstore(), opts.EventBus, n) if err != nil { return nil, err } hostCtx, cancel := context.WithCancel(context.Background()) - h := &BasicHost{ network: n, psManager: psManager, @@ -244,6 +250,9 @@ func NewHost(n network.Network, opts *HostOpts) (*BasicHost, error) { identify.WithMetricsTracer( identify.NewMetricsTracer(identify.WithRegisterer(opts.PrometheusRegisterer)))) } + if opts.DisableIdentifyAddressDiscovery { + idOpts = append(idOpts, identify.DisableObservedAddrManager()) + } h.ids, err = identify.NewIDService(h, idOpts...) if err != nil { @@ -415,7 +424,7 @@ func (h *BasicHost) newStreamHandler(s network.Stream) { } logf("protocol EOF: %s (took %s)", s.Conn().RemotePeer(), took) } else { - log.Debugf("protocol mux failed: %s (took %s)", err, took) + log.Debugf("protocol mux failed: %s (took %s, id:%s, remote peer:%s, remote addr:%v)", err, took, s.ID(), s.Conn().RemotePeer(), s.Conn().RemoteMultiaddr()) } s.Reset() return @@ -437,7 +446,7 @@ func (h *BasicHost) newStreamHandler(s network.Stream) { log.Debugf("negotiated: %s (took %s)", protoID, took) - go handle(protoID, s) + handle(protoID, s) } // SignalAddressChange signals to the host that it needs to determine whether our listen addresses have recently @@ -482,15 +491,18 @@ func makeUpdatedAddrEvent(prev, current []ma.Multiaddr) *event.EvtLocalAddresses return &evt } -func (h *BasicHost) makeSignedPeerRecord(evt *event.EvtLocalAddressesUpdated) (*record.Envelope, error) { - current := make([]ma.Multiaddr, 0, len(evt.Current)) - for _, a := range evt.Current { - current = append(current, a.Address) +func (h *BasicHost) makeSignedPeerRecord(addrs []ma.Multiaddr) (*record.Envelope, error) { + // Limit the length of currentAddrs to ensure that our signed peer records aren't rejected + peerRecordSize := 64 // HostID + k, err := h.signKey.Raw() + if err != nil { + peerRecordSize += 2 * len(k) // 1 for signature, 1 for public key } - + // we want the final address list to be small for keeping the signed peer record in size + addrs = trimHostAddrList(addrs, maxPeerRecordSize-peerRecordSize-256) // 256 B of buffer rec := peer.PeerRecordFromAddrInfo(peer.AddrInfo{ ID: h.ID(), - Addrs: current, + Addrs: addrs, }) return record.Seal(rec, h.signKey) } @@ -513,7 +525,7 @@ func (h *BasicHost) background() { if !h.disableSignedPeerRecord { // add signed peer record to the event - sr, err := h.makeSignedPeerRecord(changeEvt) + sr, err := h.makeSignedPeerRecord(currentAddrs) if err != nil { log.Errorf("error creating a signed peer record from the set of current addresses, err=%s", err) return @@ -543,7 +555,7 @@ func (h *BasicHost) background() { h.updateLocalIpAddr() } // Request addresses anyways because, technically, address filters still apply. - // The underlying AllAddrs call is effectivley a no-op. + // The underlying AllAddrs call is effectively a no-op. curr := h.Addrs() emitAddrChange(curr, lastAddrs) lastAddrs = curr @@ -666,7 +678,9 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I } if pref != "" { - s.SetProtocol(pref) + if err := s.SetProtocol(pref); err != nil { + return nil, err + } lzcon := msmux.NewMSSelect(s, pref) return &streamWrapper{ Stream: s, @@ -722,8 +736,10 @@ func (h *BasicHost) Connect(ctx context.Context, pi peer.AddrInfo) error { h.Peerstore().AddAddrs(pi.ID, pi.Addrs, peerstore.TempAddrTTL) forceDirect, _ := network.GetForceDirectDial(ctx) + canUseLimitedConn, _ := network.GetAllowLimitedConn(ctx) if !forceDirect { - if h.Network().Connectedness(pi.ID) == network.Connected { + connectedness := h.Network().Connectedness(pi.ID) + if connectedness == network.Connected || (canUseLimitedConn && connectedness == network.Limited) { return nil } } @@ -785,26 +801,34 @@ func (h *BasicHost) Addrs() []ma.Multiaddr { copy(addrs, addrsOld) for i, addr := range addrs { - if ok, n := libp2pwebtransport.IsWebtransportMultiaddr(addr); ok && n == 0 { + wtOK, wtN := libp2pwebtransport.IsWebtransportMultiaddr(addr) + webrtcOK, webrtcN := libp2pwebrtc.IsWebRTCDirectMultiaddr(addr) + if (wtOK && wtN == 0) || (webrtcOK && webrtcN == 0) { t := s.TransportForListening(addr) tpt, ok := t.(addCertHasher) if !ok { continue } addrWithCerthash, added := tpt.AddCertHashes(addr) - addrs[i] = addrWithCerthash if !added { - log.Debug("Couldn't add certhashes to webtransport multiaddr because we aren't listening on webtransport") + log.Debugf("Couldn't add certhashes to multiaddr: %s", addr) + continue } + addrs[i] = addrWithCerthash } } + return addrs } // NormalizeMultiaddr returns a multiaddr suitable for equality checks. // If the multiaddr is a webtransport component, it removes the certhashes. func (h *BasicHost) NormalizeMultiaddr(addr ma.Multiaddr) ma.Multiaddr { - if ok, n := libp2pwebtransport.IsWebtransportMultiaddr(addr); ok && n > 0 { + ok, n := libp2pwebtransport.IsWebtransportMultiaddr(addr) + if !ok { + ok, n = libp2pwebrtc.IsWebRTCDirectMultiaddr(addr) + } + if ok && n > 0 { out := addr for i := 0; i < n; i++ { out, _ = ma.SplitLast(out) @@ -942,17 +966,17 @@ func inferWebtransportAddrsFromQuic(in []ma.Multiaddr) []ma.Multiaddr { // Remove certhashes addr, _ = ma.SplitLast(addr) } - webtransportAddrs[addr.String()] = struct{}{} + webtransportAddrs[string(addr.Bytes())] = struct{}{} // Remove webtransport component, now it's a multiaddr that ends in /quic-v1 addr, _ = ma.SplitLast(addr) } if _, lastComponent := ma.SplitLast(addr); lastComponent.Protocol().Code == ma.P_QUIC_V1 { - addrStr := addr.String() - if _, ok := quicOrWebtransportAddrs[addrStr]; ok { + bytes := addr.Bytes() + if _, ok := quicOrWebtransportAddrs[string(bytes)]; ok { foundSameListeningAddr = true } else { - quicOrWebtransportAddrs[addrStr] = struct{}{} + quicOrWebtransportAddrs[string(bytes)] = struct{}{} } } } @@ -974,7 +998,7 @@ func inferWebtransportAddrsFromQuic(in []ma.Multiaddr) []ma.Multiaddr { if _, lastComponent := ma.SplitLast(addr); lastComponent.Protocol().Code == ma.P_QUIC_V1 { // Convert quic to webtransport addr = addr.Encapsulate(wtComponent) - if _, ok := webtransportAddrs[addr.String()]; ok { + if _, ok := webtransportAddrs[string(addr.Bytes())]; ok { // We already have this address continue } @@ -986,6 +1010,58 @@ func inferWebtransportAddrsFromQuic(in []ma.Multiaddr) []ma.Multiaddr { return out } +func trimHostAddrList(addrs []ma.Multiaddr, maxSize int) []ma.Multiaddr { + totalSize := 0 + for _, a := range addrs { + totalSize += len(a.Bytes()) + } + if totalSize <= maxSize { + return addrs + } + + score := func(addr ma.Multiaddr) int { + var res int + if manet.IsPublicAddr(addr) { + res |= 1 << 12 + } else if !manet.IsIPLoopback(addr) { + res |= 1 << 11 + } + var protocolWeight int + ma.ForEach(addr, func(c ma.Component) bool { + switch c.Protocol().Code { + case ma.P_QUIC_V1: + protocolWeight = 5 + case ma.P_TCP: + protocolWeight = 4 + case ma.P_WSS: + protocolWeight = 3 + case ma.P_WEBTRANSPORT: + protocolWeight = 2 + case ma.P_WEBRTC_DIRECT: + protocolWeight = 1 + case ma.P_P2P: + return false + } + return true + }) + res |= 1 << protocolWeight + return res + } + + slices.SortStableFunc(addrs, func(a, b ma.Multiaddr) int { + return score(b) - score(a) // b-a for reverse order + }) + totalSize = 0 + for i, a := range addrs { + totalSize += len(a.Bytes()) + if totalSize > maxSize { + addrs = addrs[:i] + break + } + } + return addrs +} + // SetAutoNat sets the autonat service for the host. func (h *BasicHost) SetAutoNat(a autonat.AutoNAT) { h.addrMu.Lock() @@ -1027,7 +1103,6 @@ func (h *BasicHost) Close() error { _ = h.emitters.evtLocalProtocolsUpdated.Close() _ = h.emitters.evtLocalAddrsUpdated.Close() - h.Network().Close() h.psManager.Close() if h.Peerstore() != nil { diff --git a/go-libp2p/p2p/host/basic/basic_host_test.go b/go-libp2p/p2p/host/basic/basic_host_test.go index 1093da3..c4f0680 100644 --- a/go-libp2p/p2p/host/basic/basic_host_test.go +++ b/go-libp2p/p2p/host/basic/basic_host_test.go @@ -377,7 +377,7 @@ func TestHostProtoPreknowledge(t *testing.T) { // This test implicitly relies on 1 connection. If a background identify // completes after we set the stream handler below things break - require.Equal(t, 1, len(h1.Network().ConnsToPeer(h2.ID()))) + require.Len(t, h1.Network().ConnsToPeer(h2.ID()), 1) // wait for identify handshake to finish completely select { @@ -469,7 +469,7 @@ func TestNewStreamResolve(t *testing.T) { break } } - assert.NotEqual(t, dialAddr, "") + assert.NotEqual(t, "", dialAddr) // Add the DNS multiaddr to h1's peerstore. maddr, err := ma.NewMultiaddr(dialAddr) @@ -506,7 +506,7 @@ func TestProtoDowngrade(t *testing.T) { defer s.Close() result, err := io.ReadAll(s) assert.NoError(t, err) - assert.Equal(t, string(result), "bar") + assert.Equal(t, "bar", string(result)) connectedOn <- s.Protocol() }) @@ -527,7 +527,7 @@ func TestProtoDowngrade(t *testing.T) { defer s.Close() result, err := io.ReadAll(s) assert.NoError(t, err) - assert.Equal(t, string(result), "foo") + assert.Equal(t, "foo", string(result)) connectedOn <- s.Protocol() }) @@ -838,6 +838,11 @@ func TestInferWebtransportAddrsFromQuic(t *testing.T) { in: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1/webtransport", "/ip4/1.2.3.4/udp/9999/quic-v1"}, out: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1/webtransport", "/ip4/1.2.3.4/udp/9999/quic-v1", "/ip4/1.2.3.4/udp/9999/quic-v1/webtransport"}, }, + { + name: "Happy Path With CertHashes", + in: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1/webtransport/certhash/uEgNmb28/certhash/uEgNmb28", "/ip4/1.2.3.4/udp/9999/quic-v1"}, + out: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1/webtransport/certhash/uEgNmb28/certhash/uEgNmb28", "/ip4/1.2.3.4/udp/9999/quic-v1", "/ip4/1.2.3.4/udp/9999/quic-v1/webtransport"}, + }, { name: "Already discovered", in: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1/webtransport", "/ip4/1.2.3.4/udp/9999/quic-v1", "/ip4/1.2.3.4/udp/9999/quic-v1/webtransport"}, @@ -877,9 +882,6 @@ func TestInferWebtransportAddrsFromQuic(t *testing.T) { sort.StringSlice(tc.in).Sort() sort.StringSlice(tc.out).Sort() min := make([]ma.Multiaddr, 0, len(tc.in)) - sort.Slice(tc.in, func(i, j int) bool { - return tc.in[i] < tc.in[j] - }) for _, addr := range tc.in { min = append(min, ma.StringCast(addr)) } @@ -894,3 +896,55 @@ func TestInferWebtransportAddrsFromQuic(t *testing.T) { } } + +func TestTrimHostAddrList(t *testing.T) { + type testCase struct { + name string + in []ma.Multiaddr + threshold int + out []ma.Multiaddr + } + + tcpPublic := ma.StringCast("/ip4/1.1.1.1/tcp/1") + quicPublic := ma.StringCast("/ip4/1.1.1.1/udp/1/quic-v1") + + tcpPrivate := ma.StringCast("/ip4/192.168.1.1/tcp/1") + quicPrivate := ma.StringCast("/ip4/192.168.1.1/udp/1/quic-v1") + + tcpLocal := ma.StringCast("/ip4/127.0.0.1/tcp/1") + quicLocal := ma.StringCast("/ip4/127.0.0.1/udp/1/quic-v1") + + testCases := []testCase{ + { + name: "Public preferred over private", + in: []ma.Multiaddr{tcpPublic, quicPrivate}, + threshold: len(tcpLocal.Bytes()), + out: []ma.Multiaddr{tcpPublic}, + }, + { + name: "Public and private preffered over local", + in: []ma.Multiaddr{tcpPublic, tcpPrivate, quicLocal}, + threshold: len(tcpPublic.Bytes()) + len(tcpPrivate.Bytes()), + out: []ma.Multiaddr{tcpPublic, tcpPrivate}, + }, + { + name: "quic preferred over tcp", + in: []ma.Multiaddr{tcpPublic, quicPublic}, + threshold: len(quicPublic.Bytes()), + out: []ma.Multiaddr{quicPublic}, + }, + { + name: "no filtering on large threshold", + in: []ma.Multiaddr{tcpPublic, quicPublic, quicLocal, tcpLocal, tcpPrivate}, + threshold: 10000, + out: []ma.Multiaddr{tcpPublic, quicPublic, quicLocal, tcpLocal, tcpPrivate}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + got := trimHostAddrList(tc.in, tc.threshold) + require.ElementsMatch(t, got, tc.out) + }) + } +} diff --git a/go-libp2p/p2p/host/basic/mock_nat_test.go b/go-libp2p/p2p/host/basic/mock_nat_test.go index 4e686fa..e601e71 100644 --- a/go-libp2p/p2p/host/basic/mock_nat_test.go +++ b/go-libp2p/p2p/host/basic/mock_nat_test.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/libp2p/go-libp2p/p2p/host/basic (interfaces: NAT) +// +// Generated by this command: +// +// mockgen -build_flags=-tags=gomock -package basichost -destination mock_nat_test.go github.com/libp2p/go-libp2p/p2p/host/basic NAT +// // Package basichost is a generated GoMock package. package basichost @@ -9,7 +14,7 @@ import ( netip "net/netip" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockNAT is a mock of NAT interface. @@ -44,7 +49,7 @@ func (m *MockNAT) AddMapping(arg0 context.Context, arg1 string, arg2 int) error } // AddMapping indicates an expected call of AddMapping. -func (mr *MockNATMockRecorder) AddMapping(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockNATMockRecorder) AddMapping(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddMapping", reflect.TypeOf((*MockNAT)(nil).AddMapping), arg0, arg1, arg2) } @@ -73,7 +78,7 @@ func (m *MockNAT) GetMapping(arg0 string, arg1 int) (netip.AddrPort, bool) { } // GetMapping indicates an expected call of GetMapping. -func (mr *MockNATMockRecorder) GetMapping(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNATMockRecorder) GetMapping(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMapping", reflect.TypeOf((*MockNAT)(nil).GetMapping), arg0, arg1) } @@ -87,7 +92,7 @@ func (m *MockNAT) RemoveMapping(arg0 context.Context, arg1 string, arg2 int) err } // RemoveMapping indicates an expected call of RemoveMapping. -func (mr *MockNATMockRecorder) RemoveMapping(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockNATMockRecorder) RemoveMapping(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveMapping", reflect.TypeOf((*MockNAT)(nil).RemoveMapping), arg0, arg1, arg2) } diff --git a/go-libp2p/p2p/host/basic/mocks.go b/go-libp2p/p2p/host/basic/mocks.go index 3ad4d4e..a29a0c5 100644 --- a/go-libp2p/p2p/host/basic/mocks.go +++ b/go-libp2p/p2p/host/basic/mocks.go @@ -2,5 +2,5 @@ package basichost -//go:generate sh -c "go run github.com/golang/mock/mockgen -build_flags=\"-tags=gomock\" -package basichost -destination mock_nat_test.go github.com/libp2p/go-libp2p/p2p/host/basic NAT" +//go:generate sh -c "go run go.uber.org/mock/mockgen -build_flags=\"-tags=gomock\" -package basichost -destination mock_nat_test.go github.com/libp2p/go-libp2p/p2p/host/basic NAT" type NAT nat diff --git a/go-libp2p/p2p/host/basic/natmgr.go b/go-libp2p/p2p/host/basic/natmgr.go index 8e8fbea..bc55e4d 100644 --- a/go-libp2p/p2p/host/basic/natmgr.go +++ b/go-libp2p/p2p/host/basic/natmgr.go @@ -127,7 +127,7 @@ func (nmgr *natManager) background(ctx context.Context) { for { select { case <-nmgr.syncFlag: - nmgr.doSync() // sync when our listen addresses chnage. + nmgr.doSync() // sync when our listen addresses change. case <-ctx.Done(): return } diff --git a/go-libp2p/p2p/host/basic/natmgr_test.go b/go-libp2p/p2p/host/basic/natmgr_test.go index d22092d..8cbe861 100644 --- a/go-libp2p/p2p/host/basic/natmgr_test.go +++ b/go-libp2p/p2p/host/basic/natmgr_test.go @@ -12,7 +12,7 @@ import ( swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func setupMockNAT(t *testing.T) (mockNAT *MockNAT, reset func()) { diff --git a/go-libp2p/p2p/host/blank/blank.go b/go-libp2p/p2p/host/blank/blank.go index 2430449..0cf6642 100644 --- a/go-libp2p/p2p/host/blank/blank.go +++ b/go-libp2p/p2p/host/blank/blank.go @@ -63,9 +63,10 @@ func NewBlankHost(n network.Network, options ...Option) *BlankHost { } bh := &BlankHost{ - n: n, - cmgr: cfg.cmgr, - mux: mstream.NewMultistreamMuxer[protocol.ID](), + n: n, + cmgr: cfg.cmgr, + mux: mstream.NewMultistreamMuxer[protocol.ID](), + eventbus: cfg.eventBus, } if bh.eventbus == nil { bh.eventbus = eventbus.NewBus(eventbus.WithMetricsTracer(eventbus.NewMetricsTracer())) @@ -210,7 +211,7 @@ func (bh *BlankHost) newStreamHandler(s network.Stream) { s.SetProtocol(protoID) - go handle(protoID, s) + handle(protoID, s) } // TODO: i'm not sure this really needs to be here diff --git a/go-libp2p/p2p/host/peerstore/pstoreds/addr_book.go b/go-libp2p/p2p/host/peerstore/pstoreds/addr_book.go index a16053b..2023de1 100644 --- a/go-libp2p/p2p/host/peerstore/pstoreds/addr_book.go +++ b/go-libp2p/p2p/host/peerstore/pstoreds/addr_book.go @@ -14,7 +14,7 @@ import ( "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoreds/pb" "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem" - lru "github.com/hashicorp/golang-lru/v2" + "github.com/hashicorp/golang-lru/arc/v2" ds "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/query" logging "github.com/ipfs/go-log/v2" @@ -202,7 +202,7 @@ func NewAddrBook(ctx context.Context, store ds.Batching, opts Options) (ab *dsAd } if opts.CacheSize > 0 { - if ab.cache, err = lru.NewARC[peer.ID, *addrsRecord](int(opts.CacheSize)); err != nil { + if ab.cache, err = arc.NewARC[peer.ID, *addrsRecord](int(opts.CacheSize)); err != nil { return nil, err } } else { @@ -362,7 +362,7 @@ func (ab *dsAddrBook) storeSignedPeerRecord(p peer.ID, envelope *record.Envelope func (ab *dsAddrBook) GetPeerRecord(p peer.ID) *record.Envelope { pr, err := ab.loadRecord(p, true, false) if err != nil { - log.Errorf("unable to load record for peer %s: %v", p.Pretty(), err) + log.Errorf("unable to load record for peer %s: %v", p, err) return nil } pr.RLock() @@ -372,7 +372,7 @@ func (ab *dsAddrBook) GetPeerRecord(p peer.ID) *record.Envelope { } state, _, err := record.ConsumeEnvelope(pr.CertifiedRecord.Raw, peer.PeerRecordEnvelopeDomain) if err != nil { - log.Errorf("error unmarshaling stored signed peer record for peer %s: %v", p.Pretty(), err) + log.Errorf("error unmarshaling stored signed peer record for peer %s: %v", p, err) return nil } return state @@ -398,7 +398,7 @@ func (ab *dsAddrBook) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Duratio func (ab *dsAddrBook) UpdateAddrs(p peer.ID, oldTTL time.Duration, newTTL time.Duration) { pr, err := ab.loadRecord(p, true, false) if err != nil { - log.Errorf("failed to update ttls for peer %s: %s\n", p.Pretty(), err) + log.Errorf("failed to update ttls for peer %s: %s\n", p, err) return } @@ -423,7 +423,7 @@ func (ab *dsAddrBook) UpdateAddrs(p peer.ID, oldTTL time.Duration, newTTL time.D func (ab *dsAddrBook) Addrs(p peer.ID) []ma.Multiaddr { pr, err := ab.loadRecord(p, true, true) if err != nil { - log.Warn("failed to load peerstore entry for peer %v while querying addrs, err: %v", p, err) + log.Warnf("failed to load peerstore entry for peer %s while querying addrs, err: %v", p, err) return nil } @@ -466,7 +466,7 @@ func (ab *dsAddrBook) ClearAddrs(p peer.ID) { key := addrBookBase.ChildString(b32.RawStdEncoding.EncodeToString([]byte(p))) if err := ab.ds.Delete(context.TODO(), key); err != nil { - log.Errorf("failed to clear addresses for peer %s: %v", p.Pretty(), err) + log.Errorf("failed to clear addresses for peer %s: %v", p, err) } } @@ -477,7 +477,7 @@ func (ab *dsAddrBook) setAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Duratio pr, err := ab.loadRecord(p, true, false) if err != nil { - return fmt.Errorf("failed to load peerstore entry for peer %v while setting addrs, err: %v", p, err) + return fmt.Errorf("failed to load peerstore entry for peer %s while setting addrs, err: %v", p, err) } pr.Lock() diff --git a/go-libp2p/p2p/host/peerstore/pstoreds/addr_book_gc.go b/go-libp2p/p2p/host/peerstore/pstoreds/addr_book_gc.go index a509131..2e35e7a 100644 --- a/go-libp2p/p2p/host/peerstore/pstoreds/addr_book_gc.go +++ b/go-libp2p/p2p/host/peerstore/pstoreds/addr_book_gc.go @@ -215,7 +215,7 @@ func (gc *dsAddrBookGc) purgeLookahead() { cached.Lock() if cached.clean(gc.ab.clock.Now()) { if err = cached.flush(batch); err != nil { - log.Warnf("failed to flush entry modified by GC for peer: &v, err: %v", id.Pretty(), err) + log.Warnf("failed to flush entry modified by GC for peer: %s, err: %v", id, err) } } dropOrReschedule(gcKey, cached) @@ -241,7 +241,7 @@ func (gc *dsAddrBookGc) purgeLookahead() { if record.clean(gc.ab.clock.Now()) { err = record.flush(batch) if err != nil { - log.Warnf("failed to flush entry modified by GC for peer: &v, err: %v", id.Pretty(), err) + log.Warnf("failed to flush entry modified by GC for peer: %s, err: %v", id, err) } } dropOrReschedule(gcKey, record) @@ -353,7 +353,7 @@ func (gc *dsAddrBookGc) populateLookahead() { } gcKey := gcLookaheadBase.ChildString(fmt.Sprintf("%d/%s", cached.Addrs[0].Expiry, idb32)) if err = batch.Put(context.TODO(), gcKey, []byte{}); err != nil { - log.Warnf("failed while inserting GC entry for peer: %v, err: %v", id.Pretty(), err) + log.Warnf("failed while inserting GC entry for peer: %s, err: %v", id, err) } cached.RUnlock() continue @@ -363,17 +363,17 @@ func (gc *dsAddrBookGc) populateLookahead() { val, err := gc.ab.ds.Get(context.TODO(), ds.RawKey(result.Key)) if err != nil { - log.Warnf("failed which getting record from store for peer: %v, err: %v", id.Pretty(), err) + log.Warnf("failed which getting record from store for peer: %s, err: %v", id, err) continue } if err := proto.Unmarshal(val, record); err != nil { - log.Warnf("failed while unmarshalling record from store for peer: %v, err: %v", id.Pretty(), err) + log.Warnf("failed while unmarshalling record from store for peer: %s, err: %v", id, err) continue } if len(record.Addrs) > 0 && record.Addrs[0].Expiry <= until { gcKey := gcLookaheadBase.ChildString(fmt.Sprintf("%d/%s", record.Addrs[0].Expiry, idb32)) if err = batch.Put(context.TODO(), gcKey, []byte{}); err != nil { - log.Warnf("failed while inserting GC entry for peer: %v, err: %v", id.Pretty(), err) + log.Warnf("failed while inserting GC entry for peer: %s, err: %v", id, err) } } } diff --git a/go-libp2p/p2p/host/peerstore/pstoreds/deprecate.go b/go-libp2p/p2p/host/peerstore/pstoreds/deprecate.go new file mode 100644 index 0000000..b549871 --- /dev/null +++ b/go-libp2p/p2p/host/peerstore/pstoreds/deprecate.go @@ -0,0 +1,5 @@ +// Deprecated: The database-backed peerstore will be removed from go-libp2p in the future. +// Use the memory peerstore (pstoremem) instead. +// For more details see https://github.com/libp2p/go-libp2p/issues/2329 +// and https://github.com/libp2p/go-libp2p/issues/2355. +package pstoreds diff --git a/go-libp2p/p2p/host/peerstore/pstoreds/keybook.go b/go-libp2p/p2p/host/peerstore/pstoreds/keybook.go index 9db799b..63c7e30 100644 --- a/go-libp2p/p2p/host/peerstore/pstoreds/keybook.go +++ b/go-libp2p/p2p/host/peerstore/pstoreds/keybook.go @@ -38,7 +38,7 @@ func (kb *dsKeyBook) PubKey(p peer.ID) ic.PubKey { if value, err := kb.ds.Get(context.TODO(), key); err == nil { pk, err = ic.UnmarshalPublicKey(value) if err != nil { - log.Errorf("error when unmarshalling pubkey from datastore for peer %s: %s\n", p.Pretty(), err) + log.Errorf("error when unmarshalling pubkey from datastore for peer %s: %s\n", p, err) } } else if err == ds.ErrNotFound { pk, err = p.ExtractPublicKey() @@ -47,20 +47,20 @@ func (kb *dsKeyBook) PubKey(p peer.ID) ic.PubKey { case peer.ErrNoPublicKey: return nil default: - log.Errorf("error when extracting pubkey from peer ID for peer %s: %s\n", p.Pretty(), err) + log.Errorf("error when extracting pubkey from peer ID for peer %s: %s\n", p, err) return nil } pkb, err := ic.MarshalPublicKey(pk) if err != nil { - log.Errorf("error when turning extracted pubkey into bytes for peer %s: %s\n", p.Pretty(), err) + log.Errorf("error when turning extracted pubkey into bytes for peer %s: %s\n", p, err) return nil } if err := kb.ds.Put(context.TODO(), key, pkb); err != nil { - log.Errorf("error when adding extracted pubkey to peerstore for peer %s: %s\n", p.Pretty(), err) + log.Errorf("error when adding extracted pubkey to peerstore for peer %s: %s\n", p, err) return nil } } else { - log.Errorf("error when fetching pubkey from datastore for peer %s: %s\n", p.Pretty(), err) + log.Errorf("error when fetching pubkey from datastore for peer %s: %s\n", p, err) } return pk @@ -74,11 +74,11 @@ func (kb *dsKeyBook) AddPubKey(p peer.ID, pk ic.PubKey) error { val, err := ic.MarshalPublicKey(pk) if err != nil { - log.Errorf("error while converting pubkey byte string for peer %s: %s\n", p.Pretty(), err) + log.Errorf("error while converting pubkey byte string for peer %s: %s\n", p, err) return err } if err := kb.ds.Put(context.TODO(), peerToKey(p, pubSuffix), val); err != nil { - log.Errorf("error while updating pubkey in datastore for peer %s: %s\n", p.Pretty(), err) + log.Errorf("error while updating pubkey in datastore for peer %s: %s\n", p, err) return err } return nil @@ -107,11 +107,11 @@ func (kb *dsKeyBook) AddPrivKey(p peer.ID, sk ic.PrivKey) error { val, err := ic.MarshalPrivateKey(sk) if err != nil { - log.Errorf("error while converting privkey byte string for peer %s: %s\n", p.Pretty(), err) + log.Errorf("error while converting privkey byte string for peer %s: %s\n", p, err) return err } if err := kb.ds.Put(context.TODO(), peerToKey(p, privSuffix), val); err != nil { - log.Errorf("error while updating privkey in datastore for peer %s: %s\n", p.Pretty(), err) + log.Errorf("error while updating privkey in datastore for peer %s: %s\n", p, err) } return err } diff --git a/go-libp2p/p2p/host/peerstore/pstoreds/protobook.go b/go-libp2p/p2p/host/peerstore/pstoreds/protobook.go index f5d7657..40fa7d9 100644 --- a/go-libp2p/p2p/host/peerstore/pstoreds/protobook.go +++ b/go-libp2p/p2p/host/peerstore/pstoreds/protobook.go @@ -17,7 +17,7 @@ type protoSegment struct { type protoSegments [256]*protoSegment func (s *protoSegments) get(p peer.ID) *protoSegment { - return s[byte(p[len(p)-1])] + return s[p[len(p)-1]] } var errTooManyProtocols = errors.New("too many protocols") diff --git a/go-libp2p/p2p/host/peerstore/pstoremem/addr_book.go b/go-libp2p/p2p/host/peerstore/pstoremem/addr_book.go index 67f9f91..209937c 100644 --- a/go-libp2p/p2p/host/peerstore/pstoremem/addr_book.go +++ b/go-libp2p/p2p/host/peerstore/pstoremem/addr_book.go @@ -49,7 +49,7 @@ func (segments *addrSegments) get(p peer.ID) *addrSegment { if len(p) == 0 { // it's not terribly useful to use an empty peer ID, but at least we should not panic return segments[0] } - return segments[uint8(p[len(p)-1])] + return segments[p[len(p)-1]] } type clock interface { diff --git a/go-libp2p/p2p/host/peerstore/pstoremem/protobook.go b/go-libp2p/p2p/host/peerstore/pstoremem/protobook.go index 0000f97..51c4b02 100644 --- a/go-libp2p/p2p/host/peerstore/pstoremem/protobook.go +++ b/go-libp2p/p2p/host/peerstore/pstoremem/protobook.go @@ -17,7 +17,7 @@ type protoSegment struct { type protoSegments [256]*protoSegment func (s *protoSegments) get(p peer.ID) *protoSegment { - return s[byte(p[len(p)-1])] + return s[p[len(p)-1]] } var errTooManyProtocols = errors.New("too many protocols") diff --git a/go-libp2p/p2p/host/peerstore/pstoremem/sorting_test.go b/go-libp2p/p2p/host/peerstore/pstoremem/sorting_test.go index 8ea52d1..82c76ef 100644 --- a/go-libp2p/p2p/host/peerstore/pstoremem/sorting_test.go +++ b/go-libp2p/p2p/host/peerstore/pstoremem/sorting_test.go @@ -16,5 +16,5 @@ func TestAddressSorting(t *testing.T) { l := addrList{local, u1, u2l, norm} sort.Sort(l) - require.Equal(t, l, addrList{u2l, u1, local, norm}) + require.Equal(t, addrList{u2l, u1, local, norm}, l) } diff --git a/go-libp2p/p2p/host/peerstore/test/peerstore_suite.go b/go-libp2p/p2p/host/peerstore/test/peerstore_suite.go index 576b8fd..369b459 100644 --- a/go-libp2p/p2p/host/peerstore/test/peerstore_suite.go +++ b/go-libp2p/p2p/host/peerstore/test/peerstore_suite.go @@ -144,7 +144,7 @@ func testGetStreamBeforePeerAdded(ps pstore.Peerstore) func(t *testing.T) { t.Fatal("channel shouldnt be closed yet") } if a == nil { - t.Fatal("got a nil address, thats weird") + t.Fatal("got a nil address, that's weird") } count++ if received[a.String()] { @@ -195,7 +195,7 @@ func testAddrStreamDuplicates(ps pstore.Peerstore) func(t *testing.T) { var count int for a := range ach { if a == nil { - t.Fatal("got a nil address, thats weird") + t.Fatal("got a nil address, that's weird") } count++ if received[a.String()] { @@ -337,11 +337,11 @@ func testMetadata(ps pstore.Peerstore) func(t *testing.T) { for _, p := range pids { v, err := ps.Get(p, "AgentVersion") require.NoError(t, err) - require.Equal(t, v, "string") + require.Equal(t, "string", v) v, err = ps.Get(p, "bar") require.NoError(t, err) - require.Equal(t, v, 1) + require.Equal(t, 1, v) } }) @@ -359,7 +359,7 @@ func testMetadata(ps pstore.Peerstore) func(t *testing.T) { // make sure that entries for otherP were not deleted val, err := ps.Get(otherP, "AgentVersion") require.NoError(t, err) - require.Equal(t, val, "v1") + require.Equal(t, "v1", val) }) } } diff --git a/go-libp2p/p2p/host/peerstore/test/utils.go b/go-libp2p/p2p/host/peerstore/test/utils.go index 8d327f4..254b713 100644 --- a/go-libp2p/p2p/host/peerstore/test/utils.go +++ b/go-libp2p/p2p/host/peerstore/test/utils.go @@ -38,7 +38,7 @@ func RandomPeer(b *testing.B, addrCount int) *peerpair { } for i := 0; i < addrCount; i++ { - if addrs[i], err = ma.NewMultiaddr(fmt.Sprintf(aFmt, i, pid.Pretty())); err != nil { + if addrs[i], err = ma.NewMultiaddr(fmt.Sprintf(aFmt, i, pid)); err != nil { b.Fatal(err) } } diff --git a/go-libp2p/p2p/host/pstoremanager/mock_peerstore_test.go b/go-libp2p/p2p/host/pstoremanager/mock_peerstore_test.go index fb9a282..b704cb1 100644 --- a/go-libp2p/p2p/host/pstoremanager/mock_peerstore_test.go +++ b/go-libp2p/p2p/host/pstoremanager/mock_peerstore_test.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/libp2p/go-libp2p/core/peerstore (interfaces: Peerstore) +// +// Generated by this command: +// +// mockgen -package pstoremanager_test -destination mock_peerstore_test.go github.com/libp2p/go-libp2p/core/peerstore Peerstore +// // Package pstoremanager_test is a generated GoMock package. package pstoremanager_test @@ -9,11 +14,11 @@ import ( reflect "reflect" time "time" - gomock "github.com/golang/mock/gomock" crypto "github.com/libp2p/go-libp2p/core/crypto" peer "github.com/libp2p/go-libp2p/core/peer" protocol "github.com/libp2p/go-libp2p/core/protocol" multiaddr "github.com/multiformats/go-multiaddr" + gomock "go.uber.org/mock/gomock" ) // MockPeerstore is a mock of Peerstore interface. @@ -46,7 +51,7 @@ func (m *MockPeerstore) AddAddr(arg0 peer.ID, arg1 multiaddr.Multiaddr, arg2 tim } // AddAddr indicates an expected call of AddAddr. -func (mr *MockPeerstoreMockRecorder) AddAddr(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) AddAddr(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddAddr", reflect.TypeOf((*MockPeerstore)(nil).AddAddr), arg0, arg1, arg2) } @@ -58,7 +63,7 @@ func (m *MockPeerstore) AddAddrs(arg0 peer.ID, arg1 []multiaddr.Multiaddr, arg2 } // AddAddrs indicates an expected call of AddAddrs. -func (mr *MockPeerstoreMockRecorder) AddAddrs(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) AddAddrs(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddAddrs", reflect.TypeOf((*MockPeerstore)(nil).AddAddrs), arg0, arg1, arg2) } @@ -72,7 +77,7 @@ func (m *MockPeerstore) AddPrivKey(arg0 peer.ID, arg1 crypto.PrivKey) error { } // AddPrivKey indicates an expected call of AddPrivKey. -func (mr *MockPeerstoreMockRecorder) AddPrivKey(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) AddPrivKey(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddPrivKey", reflect.TypeOf((*MockPeerstore)(nil).AddPrivKey), arg0, arg1) } @@ -80,7 +85,7 @@ func (mr *MockPeerstoreMockRecorder) AddPrivKey(arg0, arg1 interface{}) *gomock. // AddProtocols mocks base method. func (m *MockPeerstore) AddProtocols(arg0 peer.ID, arg1 ...protocol.ID) error { m.ctrl.T.Helper() - varargs := []interface{}{arg0} + varargs := []any{arg0} for _, a := range arg1 { varargs = append(varargs, a) } @@ -90,9 +95,9 @@ func (m *MockPeerstore) AddProtocols(arg0 peer.ID, arg1 ...protocol.ID) error { } // AddProtocols indicates an expected call of AddProtocols. -func (mr *MockPeerstoreMockRecorder) AddProtocols(arg0 interface{}, arg1 ...interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) AddProtocols(arg0 any, arg1 ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0}, arg1...) + varargs := append([]any{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddProtocols", reflect.TypeOf((*MockPeerstore)(nil).AddProtocols), varargs...) } @@ -105,7 +110,7 @@ func (m *MockPeerstore) AddPubKey(arg0 peer.ID, arg1 crypto.PubKey) error { } // AddPubKey indicates an expected call of AddPubKey. -func (mr *MockPeerstoreMockRecorder) AddPubKey(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) AddPubKey(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddPubKey", reflect.TypeOf((*MockPeerstore)(nil).AddPubKey), arg0, arg1) } @@ -119,7 +124,7 @@ func (m *MockPeerstore) AddrStream(arg0 context.Context, arg1 peer.ID) <-chan mu } // AddrStream indicates an expected call of AddrStream. -func (mr *MockPeerstoreMockRecorder) AddrStream(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) AddrStream(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddrStream", reflect.TypeOf((*MockPeerstore)(nil).AddrStream), arg0, arg1) } @@ -133,7 +138,7 @@ func (m *MockPeerstore) Addrs(arg0 peer.ID) []multiaddr.Multiaddr { } // Addrs indicates an expected call of Addrs. -func (mr *MockPeerstoreMockRecorder) Addrs(arg0 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) Addrs(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Addrs", reflect.TypeOf((*MockPeerstore)(nil).Addrs), arg0) } @@ -145,7 +150,7 @@ func (m *MockPeerstore) ClearAddrs(arg0 peer.ID) { } // ClearAddrs indicates an expected call of ClearAddrs. -func (mr *MockPeerstoreMockRecorder) ClearAddrs(arg0 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) ClearAddrs(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClearAddrs", reflect.TypeOf((*MockPeerstore)(nil).ClearAddrs), arg0) } @@ -167,7 +172,7 @@ func (mr *MockPeerstoreMockRecorder) Close() *gomock.Call { // FirstSupportedProtocol mocks base method. func (m *MockPeerstore) FirstSupportedProtocol(arg0 peer.ID, arg1 ...protocol.ID) (protocol.ID, error) { m.ctrl.T.Helper() - varargs := []interface{}{arg0} + varargs := []any{arg0} for _, a := range arg1 { varargs = append(varargs, a) } @@ -178,23 +183,23 @@ func (m *MockPeerstore) FirstSupportedProtocol(arg0 peer.ID, arg1 ...protocol.ID } // FirstSupportedProtocol indicates an expected call of FirstSupportedProtocol. -func (mr *MockPeerstoreMockRecorder) FirstSupportedProtocol(arg0 interface{}, arg1 ...interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) FirstSupportedProtocol(arg0 any, arg1 ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0}, arg1...) + varargs := append([]any{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FirstSupportedProtocol", reflect.TypeOf((*MockPeerstore)(nil).FirstSupportedProtocol), varargs...) } // Get mocks base method. -func (m *MockPeerstore) Get(arg0 peer.ID, arg1 string) (interface{}, error) { +func (m *MockPeerstore) Get(arg0 peer.ID, arg1 string) (any, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", arg0, arg1) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(any) ret1, _ := ret[1].(error) return ret0, ret1 } // Get indicates an expected call of Get. -func (mr *MockPeerstoreMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) Get(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockPeerstore)(nil).Get), arg0, arg1) } @@ -209,7 +214,7 @@ func (m *MockPeerstore) GetProtocols(arg0 peer.ID) ([]protocol.ID, error) { } // GetProtocols indicates an expected call of GetProtocols. -func (mr *MockPeerstoreMockRecorder) GetProtocols(arg0 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) GetProtocols(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetProtocols", reflect.TypeOf((*MockPeerstore)(nil).GetProtocols), arg0) } @@ -223,7 +228,7 @@ func (m *MockPeerstore) LatencyEWMA(arg0 peer.ID) time.Duration { } // LatencyEWMA indicates an expected call of LatencyEWMA. -func (mr *MockPeerstoreMockRecorder) LatencyEWMA(arg0 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) LatencyEWMA(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LatencyEWMA", reflect.TypeOf((*MockPeerstore)(nil).LatencyEWMA), arg0) } @@ -237,7 +242,7 @@ func (m *MockPeerstore) PeerInfo(arg0 peer.ID) peer.AddrInfo { } // PeerInfo indicates an expected call of PeerInfo. -func (mr *MockPeerstoreMockRecorder) PeerInfo(arg0 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) PeerInfo(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerInfo", reflect.TypeOf((*MockPeerstore)(nil).PeerInfo), arg0) } @@ -293,7 +298,7 @@ func (m *MockPeerstore) PrivKey(arg0 peer.ID) crypto.PrivKey { } // PrivKey indicates an expected call of PrivKey. -func (mr *MockPeerstoreMockRecorder) PrivKey(arg0 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) PrivKey(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrivKey", reflect.TypeOf((*MockPeerstore)(nil).PrivKey), arg0) } @@ -307,13 +312,13 @@ func (m *MockPeerstore) PubKey(arg0 peer.ID) crypto.PubKey { } // PubKey indicates an expected call of PubKey. -func (mr *MockPeerstoreMockRecorder) PubKey(arg0 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) PubKey(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PubKey", reflect.TypeOf((*MockPeerstore)(nil).PubKey), arg0) } // Put mocks base method. -func (m *MockPeerstore) Put(arg0 peer.ID, arg1 string, arg2 interface{}) error { +func (m *MockPeerstore) Put(arg0 peer.ID, arg1 string, arg2 any) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Put", arg0, arg1, arg2) ret0, _ := ret[0].(error) @@ -321,7 +326,7 @@ func (m *MockPeerstore) Put(arg0 peer.ID, arg1 string, arg2 interface{}) error { } // Put indicates an expected call of Put. -func (mr *MockPeerstoreMockRecorder) Put(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) Put(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockPeerstore)(nil).Put), arg0, arg1, arg2) } @@ -333,7 +338,7 @@ func (m *MockPeerstore) RecordLatency(arg0 peer.ID, arg1 time.Duration) { } // RecordLatency indicates an expected call of RecordLatency. -func (mr *MockPeerstoreMockRecorder) RecordLatency(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) RecordLatency(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordLatency", reflect.TypeOf((*MockPeerstore)(nil).RecordLatency), arg0, arg1) } @@ -345,7 +350,7 @@ func (m *MockPeerstore) RemovePeer(arg0 peer.ID) { } // RemovePeer indicates an expected call of RemovePeer. -func (mr *MockPeerstoreMockRecorder) RemovePeer(arg0 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) RemovePeer(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemovePeer", reflect.TypeOf((*MockPeerstore)(nil).RemovePeer), arg0) } @@ -353,7 +358,7 @@ func (mr *MockPeerstoreMockRecorder) RemovePeer(arg0 interface{}) *gomock.Call { // RemoveProtocols mocks base method. func (m *MockPeerstore) RemoveProtocols(arg0 peer.ID, arg1 ...protocol.ID) error { m.ctrl.T.Helper() - varargs := []interface{}{arg0} + varargs := []any{arg0} for _, a := range arg1 { varargs = append(varargs, a) } @@ -363,9 +368,9 @@ func (m *MockPeerstore) RemoveProtocols(arg0 peer.ID, arg1 ...protocol.ID) error } // RemoveProtocols indicates an expected call of RemoveProtocols. -func (mr *MockPeerstoreMockRecorder) RemoveProtocols(arg0 interface{}, arg1 ...interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) RemoveProtocols(arg0 any, arg1 ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0}, arg1...) + varargs := append([]any{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveProtocols", reflect.TypeOf((*MockPeerstore)(nil).RemoveProtocols), varargs...) } @@ -376,7 +381,7 @@ func (m *MockPeerstore) SetAddr(arg0 peer.ID, arg1 multiaddr.Multiaddr, arg2 tim } // SetAddr indicates an expected call of SetAddr. -func (mr *MockPeerstoreMockRecorder) SetAddr(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) SetAddr(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAddr", reflect.TypeOf((*MockPeerstore)(nil).SetAddr), arg0, arg1, arg2) } @@ -388,7 +393,7 @@ func (m *MockPeerstore) SetAddrs(arg0 peer.ID, arg1 []multiaddr.Multiaddr, arg2 } // SetAddrs indicates an expected call of SetAddrs. -func (mr *MockPeerstoreMockRecorder) SetAddrs(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) SetAddrs(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAddrs", reflect.TypeOf((*MockPeerstore)(nil).SetAddrs), arg0, arg1, arg2) } @@ -396,7 +401,7 @@ func (mr *MockPeerstoreMockRecorder) SetAddrs(arg0, arg1, arg2 interface{}) *gom // SetProtocols mocks base method. func (m *MockPeerstore) SetProtocols(arg0 peer.ID, arg1 ...protocol.ID) error { m.ctrl.T.Helper() - varargs := []interface{}{arg0} + varargs := []any{arg0} for _, a := range arg1 { varargs = append(varargs, a) } @@ -406,16 +411,16 @@ func (m *MockPeerstore) SetProtocols(arg0 peer.ID, arg1 ...protocol.ID) error { } // SetProtocols indicates an expected call of SetProtocols. -func (mr *MockPeerstoreMockRecorder) SetProtocols(arg0 interface{}, arg1 ...interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) SetProtocols(arg0 any, arg1 ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0}, arg1...) + varargs := append([]any{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetProtocols", reflect.TypeOf((*MockPeerstore)(nil).SetProtocols), varargs...) } // SupportsProtocols mocks base method. func (m *MockPeerstore) SupportsProtocols(arg0 peer.ID, arg1 ...protocol.ID) ([]protocol.ID, error) { m.ctrl.T.Helper() - varargs := []interface{}{arg0} + varargs := []any{arg0} for _, a := range arg1 { varargs = append(varargs, a) } @@ -426,9 +431,9 @@ func (m *MockPeerstore) SupportsProtocols(arg0 peer.ID, arg1 ...protocol.ID) ([] } // SupportsProtocols indicates an expected call of SupportsProtocols. -func (mr *MockPeerstoreMockRecorder) SupportsProtocols(arg0 interface{}, arg1 ...interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) SupportsProtocols(arg0 any, arg1 ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0}, arg1...) + varargs := append([]any{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SupportsProtocols", reflect.TypeOf((*MockPeerstore)(nil).SupportsProtocols), varargs...) } @@ -439,7 +444,7 @@ func (m *MockPeerstore) UpdateAddrs(arg0 peer.ID, arg1, arg2 time.Duration) { } // UpdateAddrs indicates an expected call of UpdateAddrs. -func (mr *MockPeerstoreMockRecorder) UpdateAddrs(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockPeerstoreMockRecorder) UpdateAddrs(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateAddrs", reflect.TypeOf((*MockPeerstore)(nil).UpdateAddrs), arg0, arg1, arg2) } diff --git a/go-libp2p/p2p/host/pstoremanager/pstoremanager.go b/go-libp2p/p2p/host/pstoremanager/pstoremanager.go index d9550f4..93cc2a9 100644 --- a/go-libp2p/p2p/host/pstoremanager/pstoremanager.go +++ b/go-libp2p/p2p/host/pstoremanager/pstoremanager.go @@ -41,6 +41,7 @@ func WithCleanupInterval(t time.Duration) Option { type PeerstoreManager struct { pstore peerstore.Peerstore eventBus event.Bus + network network.Network cancel context.CancelFunc refCount sync.WaitGroup @@ -49,11 +50,12 @@ type PeerstoreManager struct { cleanupInterval time.Duration } -func NewPeerstoreManager(pstore peerstore.Peerstore, eventBus event.Bus, opts ...Option) (*PeerstoreManager, error) { +func NewPeerstoreManager(pstore peerstore.Peerstore, eventBus event.Bus, network network.Network, opts ...Option) (*PeerstoreManager, error) { m := &PeerstoreManager{ pstore: pstore, gracePeriod: time.Minute, eventBus: eventBus, + network: network, } for _, opt := range opts { if err := opt(m); err != nil { @@ -101,20 +103,28 @@ func (m *PeerstoreManager) background(ctx context.Context, sub event.Subscriptio ev := e.(event.EvtPeerConnectednessChanged) p := ev.Peer switch ev.Connectedness { - case network.NotConnected: + case network.Connected, network.Limited: + // If we reconnect to the peer before we've cleared the information, + // keep it. This is an optimization to keep the disconnected map + // small. We still need to check that a peer is actually + // disconnected before removing it from the peer store. + delete(disconnected, p) + default: if _, ok := disconnected[p]; !ok { disconnected[p] = time.Now() } - case network.Connected: - // If we reconnect to the peer before we've cleared the information, keep it. - delete(disconnected, p) } case <-ticker.C: now := time.Now() for p, disconnectTime := range disconnected { if disconnectTime.Add(m.gracePeriod).Before(now) { - m.pstore.RemovePeer(p) - delete(disconnected, p) + // Check that the peer is actually not connected at this point. + // This avoids a race condition where the Connected notification + // is processed after this time has fired. + if m.network.Connectedness(p) != network.Connected { + m.pstore.RemovePeer(p) + delete(disconnected, p) + } } } case <-ctx.Done(): diff --git a/go-libp2p/p2p/host/pstoremanager/pstoremanager_test.go b/go-libp2p/p2p/host/pstoremanager/pstoremanager_test.go index 8726740..9321031 100644 --- a/go-libp2p/p2p/host/pstoremanager/pstoremanager_test.go +++ b/go-libp2p/p2p/host/pstoremanager/pstoremanager_test.go @@ -9,12 +9,13 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/p2p/host/eventbus" "github.com/libp2p/go-libp2p/p2p/host/pstoremanager" + swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) -//go:generate sh -c "go run github.com/golang/mock/mockgen -package pstoremanager_test -destination mock_peerstore_test.go github.com/libp2p/go-libp2p/core/peerstore Peerstore" +//go:generate sh -c "go run go.uber.org/mock/mockgen -package pstoremanager_test -destination mock_peerstore_test.go github.com/libp2p/go-libp2p/core/peerstore Peerstore" func TestGracePeriod(t *testing.T) { t.Parallel() @@ -23,7 +24,7 @@ func TestGracePeriod(t *testing.T) { eventBus := eventbus.NewBus() pstore := NewMockPeerstore(ctrl) const gracePeriod = 250 * time.Millisecond - man, err := pstoremanager.NewPeerstoreManager(pstore, eventBus, pstoremanager.WithGracePeriod(gracePeriod)) + man, err := pstoremanager.NewPeerstoreManager(pstore, eventBus, swarmt.GenSwarm(t), pstoremanager.WithGracePeriod(gracePeriod)) require.NoError(t, err) defer man.Close() man.Start() @@ -51,7 +52,7 @@ func TestReconnect(t *testing.T) { eventBus := eventbus.NewBus() pstore := NewMockPeerstore(ctrl) const gracePeriod = 200 * time.Millisecond - man, err := pstoremanager.NewPeerstoreManager(pstore, eventBus, pstoremanager.WithGracePeriod(gracePeriod)) + man, err := pstoremanager.NewPeerstoreManager(pstore, eventBus, swarmt.GenSwarm(t), pstoremanager.WithGracePeriod(gracePeriod)) require.NoError(t, err) defer man.Close() man.Start() @@ -77,7 +78,7 @@ func TestClose(t *testing.T) { eventBus := eventbus.NewBus() pstore := NewMockPeerstore(ctrl) const gracePeriod = time.Hour - man, err := pstoremanager.NewPeerstoreManager(pstore, eventBus, pstoremanager.WithGracePeriod(gracePeriod)) + man, err := pstoremanager.NewPeerstoreManager(pstore, eventBus, swarmt.GenSwarm(t), pstoremanager.WithGracePeriod(gracePeriod)) require.NoError(t, err) man.Start() diff --git a/go-libp2p/p2p/host/resource-manager/README.md b/go-libp2p/p2p/host/resource-manager/README.md index 9371832..68ce0aa 100644 --- a/go-libp2p/p2p/host/resource-manager/README.md +++ b/go-libp2p/p2p/host/resource-manager/README.md @@ -161,7 +161,7 @@ belong to some service in the system. Hence, this suggests that apart from global limits, we can constrain stream usage at finer granularity, at the protocol and service level. -Once again, we disinguish between inbound and outbound streams. +Once again, we distinguish between inbound and outbound streams. Inbound streams are initiated by remote peers and consume resources in response to network events; controlling inbound stream usage is again paramount for protecting the system from overload or attack. @@ -541,7 +541,7 @@ works best. ## Examples -Here we consider some concrete examples that can ellucidate the abstract +Here we consider some concrete examples that can elucidate the abstract design as described so far. ### Stream Lifetime @@ -578,7 +578,7 @@ More specifically the following constraints apply: - the peer scope, where the limits for the peer at the other end of the stream apply. - the service scope, where the limits of the specific service owning the stream apply. -- the protcol scope, where the limits of the specific protocol for the stream apply. +- the protocol scope, where the limits of the specific protocol for the stream apply. The resource transfer that happens in the `SetProtocol` and `SetService` diff --git a/go-libp2p/p2p/host/resource-manager/conn_limiter.go b/go-libp2p/p2p/host/resource-manager/conn_limiter.go new file mode 100644 index 0000000..717249e --- /dev/null +++ b/go-libp2p/p2p/host/resource-manager/conn_limiter.go @@ -0,0 +1,288 @@ +package rcmgr + +import ( + "math" + "net/netip" + "slices" + "sync" +) + +type ConnLimitPerSubnet struct { + // This defines how big the subnet is. For example, a /24 subnet has a + // PrefixLength of 24. All IPs that share the same 24 bit prefix are in the same + // subnet. Are in the same subnet, and bound to the same limit. + PrefixLength int + // The maximum number of connections allowed for each subnet. + ConnCount int +} + +type NetworkPrefixLimit struct { + // The Network prefix for which this limit applies. + Network netip.Prefix + + // The maximum number of connections allowed for this subnet. + ConnCount int +} + +// 8 for now so that it matches the number of concurrent dials we may do +// in swarm_dial.go. With future smart dialing work we should bring this +// down +var defaultMaxConcurrentConns = 8 + +var defaultIP4Limit = ConnLimitPerSubnet{ + ConnCount: defaultMaxConcurrentConns, + PrefixLength: 32, +} +var defaultIP6Limits = []ConnLimitPerSubnet{ + { + ConnCount: defaultMaxConcurrentConns, + PrefixLength: 56, + }, + { + ConnCount: 8 * defaultMaxConcurrentConns, + PrefixLength: 48, + }, +} + +var DefaultNetworkPrefixLimitV4 = sortNetworkPrefixes([]NetworkPrefixLimit{ + { + // Loopback address for v4 https://datatracker.ietf.org/doc/html/rfc6890#section-2.2.2 + Network: netip.MustParsePrefix("127.0.0.0/8"), + ConnCount: math.MaxInt, // Unlimited + }, +}) +var DefaultNetworkPrefixLimitV6 = sortNetworkPrefixes([]NetworkPrefixLimit{ + { + // Loopback address for v6 https://datatracker.ietf.org/doc/html/rfc6890#section-2.2.3 + Network: netip.MustParsePrefix("::1/128"), + ConnCount: math.MaxInt, // Unlimited + }, +}) + +// Network prefixes limits must be sorted by most specific to least specific. This lets us +// actually use the more specific limits, otherwise only the less specific ones +// would be matched. e.g. 1.2.3.0/24 must come before 1.2.0.0/16. +func sortNetworkPrefixes(limits []NetworkPrefixLimit) []NetworkPrefixLimit { + slices.SortStableFunc(limits, func(a, b NetworkPrefixLimit) int { + return b.Network.Bits() - a.Network.Bits() + }) + return limits +} + +// WithNetworkPrefixLimit sets the limits for the number of connections allowed +// for a specific Network Prefix. Use this when you want to set higher limits +// for a specific subnet than the default limit per subnet. +func WithNetworkPrefixLimit(ipv4 []NetworkPrefixLimit, ipv6 []NetworkPrefixLimit) Option { + return func(rm *resourceManager) error { + if ipv4 != nil { + rm.connLimiter.networkPrefixLimitV4 = sortNetworkPrefixes(ipv4) + } + if ipv6 != nil { + rm.connLimiter.networkPrefixLimitV6 = sortNetworkPrefixes(ipv6) + } + return nil + } +} + +// WithLimitPerSubnet sets the limits for the number of connections allowed per +// subnet. This will limit the number of connections per subnet if that subnet +// is not defined in the NetworkPrefixLimit option. Think of this as a default +// limit for any given subnet. +func WithLimitPerSubnet(ipv4 []ConnLimitPerSubnet, ipv6 []ConnLimitPerSubnet) Option { + return func(rm *resourceManager) error { + if ipv4 != nil { + rm.connLimiter.connLimitPerSubnetV4 = ipv4 + } + if ipv6 != nil { + rm.connLimiter.connLimitPerSubnetV6 = ipv6 + } + return nil + } +} + +type connLimiter struct { + mu sync.Mutex + + // Specific Network Prefix limits. If these are set, they take precedence over the + // subnet limits. + // These must be sorted by most specific to least specific. + networkPrefixLimitV4 []NetworkPrefixLimit + networkPrefixLimitV6 []NetworkPrefixLimit + connsPerNetworkPrefixV4 []int + connsPerNetworkPrefixV6 []int + + // Subnet limits. + connLimitPerSubnetV4 []ConnLimitPerSubnet + connLimitPerSubnetV6 []ConnLimitPerSubnet + ip4connsPerLimit []map[string]int + ip6connsPerLimit []map[string]int +} + +func newConnLimiter() *connLimiter { + return &connLimiter{ + networkPrefixLimitV4: DefaultNetworkPrefixLimitV4, + networkPrefixLimitV6: DefaultNetworkPrefixLimitV6, + + connLimitPerSubnetV4: []ConnLimitPerSubnet{defaultIP4Limit}, + connLimitPerSubnetV6: defaultIP6Limits, + } +} + +func (cl *connLimiter) addNetworkPrefixLimit(isIP6 bool, npLimit NetworkPrefixLimit) { + cl.mu.Lock() + defer cl.mu.Unlock() + if isIP6 { + cl.networkPrefixLimitV6 = append(cl.networkPrefixLimitV6, npLimit) + cl.networkPrefixLimitV6 = sortNetworkPrefixes(cl.networkPrefixLimitV6) + } else { + cl.networkPrefixLimitV4 = append(cl.networkPrefixLimitV4, npLimit) + cl.networkPrefixLimitV4 = sortNetworkPrefixes(cl.networkPrefixLimitV4) + } +} + +// addConn adds a connection for the given IP address. It returns true if the connection is allowed. +func (cl *connLimiter) addConn(ip netip.Addr) bool { + cl.mu.Lock() + defer cl.mu.Unlock() + networkPrefixLimits := cl.networkPrefixLimitV4 + connsPerNetworkPrefix := cl.connsPerNetworkPrefixV4 + limits := cl.connLimitPerSubnetV4 + connsPerLimit := cl.ip4connsPerLimit + isIP6 := ip.Is6() + if isIP6 { + networkPrefixLimits = cl.networkPrefixLimitV6 + connsPerNetworkPrefix = cl.connsPerNetworkPrefixV6 + limits = cl.connLimitPerSubnetV6 + connsPerLimit = cl.ip6connsPerLimit + } + + // Check Network Prefix limits first + if len(connsPerNetworkPrefix) == 0 && len(networkPrefixLimits) > 0 { + // Initialize the counts + connsPerNetworkPrefix = make([]int, len(networkPrefixLimits)) + if isIP6 { + cl.connsPerNetworkPrefixV6 = connsPerNetworkPrefix + } else { + cl.connsPerNetworkPrefixV4 = connsPerNetworkPrefix + } + } + + for i, limit := range networkPrefixLimits { + if limit.Network.Contains(ip) { + if connsPerNetworkPrefix[i]+1 > limit.ConnCount { + return false + } + connsPerNetworkPrefix[i]++ + // Done. If we find a match in the network prefix limits, we use + // that and don't use the general subnet limits. + return true + } + } + + if len(connsPerLimit) == 0 && len(limits) > 0 { + connsPerLimit = make([]map[string]int, len(limits)) + if isIP6 { + cl.ip6connsPerLimit = connsPerLimit + } else { + cl.ip4connsPerLimit = connsPerLimit + } + } + + for i, limit := range limits { + prefix, err := ip.Prefix(limit.PrefixLength) + if err != nil { + return false + } + masked := prefix.String() + counts, ok := connsPerLimit[i][masked] + if !ok { + if connsPerLimit[i] == nil { + connsPerLimit[i] = make(map[string]int) + } + connsPerLimit[i][masked] = 0 + } + if counts+1 > limit.ConnCount { + return false + } + } + + // All limit checks passed, now we update the counts + for i, limit := range limits { + prefix, _ := ip.Prefix(limit.PrefixLength) + masked := prefix.String() + connsPerLimit[i][masked]++ + } + + return true +} + +func (cl *connLimiter) rmConn(ip netip.Addr) { + cl.mu.Lock() + defer cl.mu.Unlock() + networkPrefixLimits := cl.networkPrefixLimitV4 + connsPerNetworkPrefix := cl.connsPerNetworkPrefixV4 + limits := cl.connLimitPerSubnetV4 + connsPerLimit := cl.ip4connsPerLimit + isIP6 := ip.Is6() + if isIP6 { + networkPrefixLimits = cl.networkPrefixLimitV6 + connsPerNetworkPrefix = cl.connsPerNetworkPrefixV6 + limits = cl.connLimitPerSubnetV6 + connsPerLimit = cl.ip6connsPerLimit + } + + // Check NetworkPrefix limits first + if len(connsPerNetworkPrefix) == 0 && len(networkPrefixLimits) > 0 { + // Initialize just in case. We should have already initialized in + // addConn, but if the callers calls rmConn first we don't want to panic + connsPerNetworkPrefix = make([]int, len(networkPrefixLimits)) + if isIP6 { + cl.connsPerNetworkPrefixV6 = connsPerNetworkPrefix + } else { + cl.connsPerNetworkPrefixV4 = connsPerNetworkPrefix + } + } + for i, limit := range networkPrefixLimits { + if limit.Network.Contains(ip) { + count := connsPerNetworkPrefix[i] + if count <= 0 { + log.Errorf("unexpected conn count for ip %s. Was this not added with addConn first?", ip) + return + } + connsPerNetworkPrefix[i]-- + // Done. We updated the count in the defined network prefix limit. + return + } + } + + if len(connsPerLimit) == 0 && len(limits) > 0 { + // Initialize just in case. We should have already initialized in + // addConn, but if the callers calls rmConn first we don't want to panic + connsPerLimit = make([]map[string]int, len(limits)) + if isIP6 { + cl.ip6connsPerLimit = connsPerLimit + } else { + cl.ip4connsPerLimit = connsPerLimit + } + } + + for i, limit := range limits { + prefix, err := ip.Prefix(limit.PrefixLength) + if err != nil { + // Unexpected since we should have seen this IP before in addConn + log.Errorf("unexpected error getting prefix: %v", err) + continue + } + masked := prefix.String() + counts, ok := connsPerLimit[i][masked] + if !ok || counts == 0 { + // Unexpected, but don't panic + log.Errorf("unexpected conn count for %s ok=%v count=%v", masked, ok, counts) + continue + } + connsPerLimit[i][masked]-- + if connsPerLimit[i][masked] <= 0 { + delete(connsPerLimit[i], masked) + } + } +} diff --git a/go-libp2p/p2p/host/resource-manager/conn_limiter_test.go b/go-libp2p/p2p/host/resource-manager/conn_limiter_test.go new file mode 100644 index 0000000..89ce5d5 --- /dev/null +++ b/go-libp2p/p2p/host/resource-manager/conn_limiter_test.go @@ -0,0 +1,214 @@ +package rcmgr + +import ( + "encoding/binary" + "net" + "net/netip" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestItLimits(t *testing.T) { + t.Run("IPv4", func(t *testing.T) { + ip, err := netip.ParseAddr("1.2.3.4") + require.NoError(t, err) + cl := newConnLimiter() + cl.connLimitPerSubnetV4[0].ConnCount = 1 + require.True(t, cl.addConn(ip)) + + // should fail the second time + require.False(t, cl.addConn(ip)) + + otherIP, err := netip.ParseAddr("1.2.3.5") + require.NoError(t, err) + require.True(t, cl.addConn(otherIP)) + }) + t.Run("IPv6", func(t *testing.T) { + ip, err := netip.ParseAddr("1:2:3:4::1") + require.NoError(t, err) + cl := newConnLimiter() + original := cl.connLimitPerSubnetV6[0].ConnCount + cl.connLimitPerSubnetV6[0].ConnCount = 1 + defer func() { + cl.connLimitPerSubnetV6[0].ConnCount = original + }() + require.True(t, cl.addConn(ip)) + + // should fail the second time + require.False(t, cl.addConn(ip)) + otherIPSameSubnet := netip.MustParseAddr("1:2:3:4::2") + require.False(t, cl.addConn(otherIPSameSubnet)) + + otherIP := netip.MustParseAddr("2:2:3:4::2") + require.True(t, cl.addConn(otherIP)) + }) + + t.Run("IPv6 with multiple limits", func(t *testing.T) { + cl := newConnLimiter() + for i := 0; i < defaultMaxConcurrentConns; i++ { + ip := net.ParseIP("ff:2:3:4::1") + binary.BigEndian.PutUint16(ip[14:], uint16(i)) + ipAddr := netip.MustParseAddr(ip.String()) + require.True(t, cl.addConn(ipAddr)) + } + + // Next one should fail + ip := net.ParseIP("ff:2:3:4::1") + binary.BigEndian.PutUint16(ip[14:], uint16(defaultMaxConcurrentConns+1)) + require.False(t, cl.addConn(netip.MustParseAddr(ip.String()))) + + // But on a different root subnet should work + otherIP := netip.MustParseAddr("ffef:2:3::1") + require.True(t, cl.addConn(otherIP)) + + // But too many on the next subnet limit will fail too + for i := 0; i < defaultMaxConcurrentConns*8; i++ { + ip := net.ParseIP("ffef:2:3:4::1") + binary.BigEndian.PutUint16(ip[5:7], uint16(i)) + ipAddr := netip.MustParseAddr(ip.String()) + require.True(t, cl.addConn(ipAddr)) + } + + ip = net.ParseIP("ffef:2:3:4::1") + binary.BigEndian.PutUint16(ip[5:7], uint16(defaultMaxConcurrentConns*8+1)) + ipAddr := netip.MustParseAddr(ip.String()) + require.False(t, cl.addConn(ipAddr)) + }) + + t.Run("IPv4 with localhost", func(t *testing.T) { + cl := &connLimiter{ + networkPrefixLimitV4: DefaultNetworkPrefixLimitV4, + connLimitPerSubnetV4: []ConnLimitPerSubnet{ + {PrefixLength: 0, ConnCount: 1}, // 1 connection for the whole IPv4 space + }, + } + + ip := netip.MustParseAddr("1.2.3.4") + require.True(t, cl.addConn(ip)) + + ip = netip.MustParseAddr("4.3.2.1") + // should fail the second time, we only allow 1 connection for the whole IPv4 space + require.False(t, cl.addConn(ip)) + + ip = netip.MustParseAddr("127.0.0.1") + // Succeeds because we defined an explicit limit for the loopback subnet + require.True(t, cl.addConn(ip)) + }) +} + +func genIP(data *[]byte) (netip.Addr, bool) { + if len(*data) < 1 { + return netip.Addr{}, false + } + + genIP6 := (*data)[0]&0x01 == 1 + bytesRequired := 4 + if genIP6 { + bytesRequired = 16 + } + + if len((*data)[1:]) < bytesRequired { + return netip.Addr{}, false + } + + *data = (*data)[1:] + ip, ok := netip.AddrFromSlice((*data)[:bytesRequired]) + *data = (*data)[bytesRequired:] + return ip, ok +} + +func FuzzConnLimiter(f *testing.F) { + // The goal is to try to enter a state where the count is incorrectly 0 + f.Fuzz(func(t *testing.T, data []byte) { + ips := make([]netip.Addr, 0, len(data)/5) + for { + ip, ok := genIP(&data) + if !ok { + break + } + ips = append(ips, ip) + } + + cl := newConnLimiter() + addedConns := make([]netip.Addr, 0, len(ips)) + for _, ip := range ips { + if cl.addConn(ip) { + addedConns = append(addedConns, ip) + } + } + + addedCount := 0 + for _, ip := range cl.ip4connsPerLimit { + for _, count := range ip { + addedCount += count + } + } + for _, ip := range cl.ip6connsPerLimit { + for _, count := range ip { + addedCount += count + } + } + for _, count := range cl.connsPerNetworkPrefixV4 { + addedCount += count + } + for _, count := range cl.connsPerNetworkPrefixV6 { + addedCount += count + } + if addedCount == 0 && len(addedConns) > 0 { + t.Fatalf("added count: %d", addedCount) + } + + for _, ip := range addedConns { + cl.rmConn(ip) + } + + leftoverCount := 0 + for _, ip := range cl.ip4connsPerLimit { + for _, count := range ip { + leftoverCount += count + } + } + for _, ip := range cl.ip6connsPerLimit { + for _, count := range ip { + leftoverCount += count + } + } + for _, count := range cl.connsPerNetworkPrefixV4 { + addedCount += count + } + for _, count := range cl.connsPerNetworkPrefixV6 { + addedCount += count + } + if leftoverCount != 0 { + t.Fatalf("leftover count: %d", leftoverCount) + } + }) +} + +func TestSortedNetworkPrefixLimits(t *testing.T) { + npLimits := []NetworkPrefixLimit{ + { + Network: netip.MustParsePrefix("1.2.0.0/16"), + }, + { + Network: netip.MustParsePrefix("1.2.3.0/28"), + }, + { + Network: netip.MustParsePrefix("1.2.3.4/32"), + }, + } + npLimits = sortNetworkPrefixes(npLimits) + sorted := []NetworkPrefixLimit{ + { + Network: netip.MustParsePrefix("1.2.3.4/32"), + }, + { + Network: netip.MustParsePrefix("1.2.3.0/28"), + }, + { + Network: netip.MustParsePrefix("1.2.0.0/16"), + }, + } + require.EqualValues(t, sorted, npLimits) +} diff --git a/go-libp2p/p2p/host/resource-manager/docs/allowlist.md b/go-libp2p/p2p/host/resource-manager/docs/allowlist.md index 4ada09c..6cf88e0 100644 --- a/go-libp2p/p2p/host/resource-manager/docs/allowlist.md +++ b/go-libp2p/p2p/host/resource-manager/docs/allowlist.md @@ -47,7 +47,7 @@ creates the connection resource scope using the allowlisted specific system and transient resource scopes. If it wasn't an allowlisted multiaddr it fails as before. -When an allowlisted connection is tied to a peer id and transfered with +When an allowlisted connection is tied to a peer id and transferred with `ConnManagementScope.SetPeer`, we check if that peer id matches the expected value in the allowlist (if it exists). If it does not match, we attempt to transfer this resource to the normal system and peer scope. If that transfer diff --git a/go-libp2p/p2p/host/resource-manager/extapi.go b/go-libp2p/p2p/host/resource-manager/extapi.go index 03edcd7..415d7f8 100644 --- a/go-libp2p/p2p/host/resource-manager/extapi.go +++ b/go-libp2p/p2p/host/resource-manager/extapi.go @@ -145,3 +145,7 @@ func (r *resourceManager) Stat() (result ResourceManagerStat) { return result } + +func (r *resourceManager) GetConnLimit() int { + return r.limits.GetSystemLimits().GetConnTotalLimit() +} diff --git a/go-libp2p/p2p/host/resource-manager/limit_test.go b/go-libp2p/p2p/host/resource-manager/limit_test.go index 68d6bf2..8d9f391 100644 --- a/go-libp2p/p2p/host/resource-manager/limit_test.go +++ b/go-libp2p/p2p/host/resource-manager/limit_test.go @@ -110,7 +110,6 @@ func TestScaling(t *testing.T) { require.Equal(t, 20+4*2, scaled.service["B"].Streams) require.Equal(t, int64(200+4*3), scaled.service["B"].Memory) require.Equal(t, 400, scaled.service["B"].FD) - }) } @@ -157,7 +156,7 @@ func TestJSONMarshalling(t *testing.T) { jsonEncoded, err := json.Marshal(bl) require.NoError(t, err) - require.Equal(t, string(jsonEncoded), `{"StreamsInbound":10,"StreamsOutbound":"blockAll","Conns":10,"ConnsOutbound":"unlimited","Memory":"unlimited"}`) + require.Equal(t, `{"StreamsInbound":10,"StreamsOutbound":"blockAll","Conns":10,"ConnsOutbound":"unlimited","Memory":"unlimited"}`, string(jsonEncoded)) // Roundtrip var blDecoded ResourceLimits @@ -175,7 +174,7 @@ func TestJSONRoundTripInt64(t *testing.T) { jsonEncoded, err := json.Marshal(bl) require.NoError(t, err) - require.Equal(t, string(jsonEncoded), `{"Memory":"9223372036854775807"}`) + require.Equal(t, `{"Memory":"9223372036854775807"}`, string(jsonEncoded)) // Roundtrip var blDecoded ResourceLimits diff --git a/go-libp2p/p2p/host/resource-manager/rcmgr.go b/go-libp2p/p2p/host/resource-manager/rcmgr.go index 188a171..2eb1b3a 100644 --- a/go-libp2p/p2p/host/resource-manager/rcmgr.go +++ b/go-libp2p/p2p/host/resource-manager/rcmgr.go @@ -3,6 +3,7 @@ package rcmgr import ( "context" "fmt" + "net/netip" "strings" "sync" "time" @@ -13,6 +14,7 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/multiformats/go-multiaddr" + manet "github.com/multiformats/go-multiaddr/net" ) var log = logging.Logger("rcmgr") @@ -20,6 +22,8 @@ var log = logging.Logger("rcmgr") type resourceManager struct { limits Limiter + connLimiter *connLimiter + trace *trace metrics *metrics disableMetrics bool @@ -103,6 +107,7 @@ type connectionScope struct { rcmgr *resourceManager peer *peerScope endpoint multiaddr.Multiaddr + ip netip.Addr } var _ network.ConnScope = (*connectionScope)(nil) @@ -129,11 +134,12 @@ type Option func(*resourceManager) error func NewResourceManager(limits Limiter, opts ...Option) (network.ResourceManager, error) { allowlist := newAllowlist() r := &resourceManager{ - limits: limits, - allowlist: &allowlist, - svc: make(map[string]*serviceScope), - proto: make(map[protocol.ID]*protocolScope), - peer: make(map[peer.ID]*peerScope), + limits: limits, + connLimiter: newConnLimiter(), + allowlist: &allowlist, + svc: make(map[string]*serviceScope), + proto: make(map[protocol.ID]*protocolScope), + peer: make(map[peer.ID]*peerScope), } for _, opt := range opts { @@ -142,6 +148,28 @@ func NewResourceManager(limits Limiter, opts ...Option) (network.ResourceManager } } + registeredConnLimiterPrefixes := make(map[string]struct{}) + for _, npLimit := range r.connLimiter.networkPrefixLimitV4 { + registeredConnLimiterPrefixes[npLimit.Network.String()] = struct{}{} + } + for _, npLimit := range r.connLimiter.networkPrefixLimitV6 { + registeredConnLimiterPrefixes[npLimit.Network.String()] = struct{}{} + } + for _, network := range allowlist.allowedNetworks { + prefix, err := netip.ParsePrefix(network.String()) + if err != nil { + log.Debugf("failed to parse prefix from allowlist %s, %s", network, err) + continue + } + if _, ok := registeredConnLimiterPrefixes[prefix.String()]; !ok { + // connlimiter doesn't know about this network. Let's fix that + r.connLimiter.addNetworkPrefixLimit(prefix.Addr().Is6(), NetworkPrefixLimit{ + Network: prefix, + ConnCount: r.limits.GetAllowlistedSystemLimits().GetConnTotalLimit(), + }) + } + } + if !r.disableMetrics { var sr TraceReporter sr, err := NewStatsTraceReporter() @@ -310,12 +338,37 @@ func (r *resourceManager) nextStreamId() int64 { return r.streamId } +// OpenConnectionNoIP is deprecated and will be removed in the next release +func (r *resourceManager) OpenConnectionNoIP(dir network.Direction, usefd bool, endpoint multiaddr.Multiaddr) (network.ConnManagementScope, error) { + return r.openConnection(dir, usefd, endpoint, netip.Addr{}) +} + func (r *resourceManager) OpenConnection(dir network.Direction, usefd bool, endpoint multiaddr.Multiaddr) (network.ConnManagementScope, error) { + ip, err := manet.ToIP(endpoint) + if err != nil { + // No IP address + return r.openConnection(dir, usefd, endpoint, netip.Addr{}) + } + + ipAddr, ok := netip.AddrFromSlice(ip) + if !ok { + return nil, fmt.Errorf("failed to convert ip to netip.Addr") + } + return r.openConnection(dir, usefd, endpoint, ipAddr) +} + +func (r *resourceManager) openConnection(dir network.Direction, usefd bool, endpoint multiaddr.Multiaddr, ip netip.Addr) (network.ConnManagementScope, error) { + if ip.IsValid() { + if ok := r.connLimiter.addConn(ip); !ok { + return nil, fmt.Errorf("connections per ip limit exceeded for %s", endpoint) + } + } + var conn *connectionScope - conn = newConnectionScope(dir, usefd, r.limits.GetConnLimits(), r, endpoint) + conn = newConnectionScope(dir, usefd, r.limits.GetConnLimits(), r, endpoint, ip) err := conn.AddConn(dir, usefd) - if err != nil { + if err != nil && ip.IsValid() { // Try again if this is an allowlisted connection // Failed to open connection, let's see if this was allowlisted and try again allowed := r.allowlist.Allowed(endpoint) @@ -476,7 +529,7 @@ func newPeerScope(p peer.ID, limit Limit, rcmgr *resourceManager) *peerScope { } } -func newConnectionScope(dir network.Direction, usefd bool, limit Limit, rcmgr *resourceManager, endpoint multiaddr.Multiaddr) *connectionScope { +func newConnectionScope(dir network.Direction, usefd bool, limit Limit, rcmgr *resourceManager, endpoint multiaddr.Multiaddr, ip netip.Addr) *connectionScope { return &connectionScope{ resourceScope: newResourceScope(limit, []*resourceScope{rcmgr.transient.resourceScope, rcmgr.system.resourceScope}, @@ -485,6 +538,7 @@ func newConnectionScope(dir network.Direction, usefd bool, limit Limit, rcmgr *r usefd: usefd, rcmgr: rcmgr, endpoint: endpoint, + ip: ip, } } @@ -643,6 +697,18 @@ func (s *connectionScope) PeerScope() network.PeerScope { return s.peer } +func (s *connectionScope) Done() { + s.Lock() + defer s.Unlock() + if s.done { + return + } + if s.ip.IsValid() { + s.rcmgr.connLimiter.rmConn(s.ip) + } + s.resourceScope.doneUnlocked() +} + // transferAllowedToStandard transfers this connection scope from being part of // the allowlist set of scopes to being part of the standard set of scopes. // Happens when we first allowlisted this connection due to its IP, but later diff --git a/go-libp2p/p2p/host/resource-manager/rcmgr_test.go b/go-libp2p/p2p/host/resource-manager/rcmgr_test.go index 61d53be..bf79f7a 100644 --- a/go-libp2p/p2p/host/resource-manager/rcmgr_test.go +++ b/go-libp2p/p2p/host/resource-manager/rcmgr_test.go @@ -1,12 +1,14 @@ package rcmgr import ( + "net/netip" "testing" "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/protocol" "github.com/libp2p/go-libp2p/core/test" + "github.com/stretchr/testify/require" "github.com/multiformats/go-multiaddr" ) @@ -1051,3 +1053,61 @@ func TestResourceManagerWithAllowlist(t *testing.T) { t.Fatal(err) } } + +// TestAllowlistAndConnLimiterPlayNice checks that the connLimiter learns about network prefix limits from the allowlist. +func TestAllowlistAndConnLimiterPlayNice(t *testing.T) { + limits := DefaultLimits.AutoScale() + limits.allowlistedSystem.Conns = 8 + limits.allowlistedSystem.ConnsInbound = 8 + limits.allowlistedSystem.ConnsOutbound = 8 + t.Run("IPv4", func(t *testing.T) { + rcmgr, err := NewResourceManager(NewFixedLimiter(limits), WithAllowlistedMultiaddrs([]multiaddr.Multiaddr{ + multiaddr.StringCast("/ip4/1.2.3.0/ipcidr/24"), + }), WithNetworkPrefixLimit([]NetworkPrefixLimit{}, []NetworkPrefixLimit{})) + if err != nil { + t.Fatal(err) + } + defer rcmgr.Close() + + // The connLimiter should have the allowlisted network prefix + require.Equal(t, netip.MustParsePrefix("1.2.3.0/24"), rcmgr.(*resourceManager).connLimiter.networkPrefixLimitV4[0].Network) + + // The connLimiter should use the limit from the allowlist + require.Equal(t, 8, rcmgr.(*resourceManager).connLimiter.networkPrefixLimitV4[0].ConnCount) + }) + t.Run("IPv6", func(t *testing.T) { + rcmgr, err := NewResourceManager(NewFixedLimiter(limits), WithAllowlistedMultiaddrs([]multiaddr.Multiaddr{ + multiaddr.StringCast("/ip6/1:2:3::/ipcidr/58"), + }), WithNetworkPrefixLimit([]NetworkPrefixLimit{}, []NetworkPrefixLimit{})) + if err != nil { + t.Fatal(err) + } + defer rcmgr.Close() + + // The connLimiter should have the allowlisted network prefix + require.Equal(t, netip.MustParsePrefix("1:2:3::/58"), rcmgr.(*resourceManager).connLimiter.networkPrefixLimitV6[0].Network) + + // The connLimiter should use the limit from the allowlist + require.Equal(t, 8, rcmgr.(*resourceManager).connLimiter.networkPrefixLimitV6[0].ConnCount) + }) + + t.Run("Does not override if you set a limit directly", func(t *testing.T) { + rcmgr, err := NewResourceManager(NewFixedLimiter(limits), WithAllowlistedMultiaddrs([]multiaddr.Multiaddr{ + multiaddr.StringCast("/ip4/1.2.3.0/ipcidr/24"), + }), WithNetworkPrefixLimit([]NetworkPrefixLimit{ + {Network: netip.MustParsePrefix("1.2.3.0/24"), ConnCount: 1}, + }, []NetworkPrefixLimit{})) + if err != nil { + t.Fatal(err) + } + defer rcmgr.Close() + + // The connLimiter should have it because we set it + require.Equal(t, netip.MustParsePrefix("1.2.3.0/24"), rcmgr.(*resourceManager).connLimiter.networkPrefixLimitV4[0].Network) + // should only have one network prefix limit + require.Equal(t, 1, len(rcmgr.(*resourceManager).connLimiter.networkPrefixLimitV4)) + + // The connLimiter should use the limit we defined explicitly + require.Equal(t, 1, rcmgr.(*resourceManager).connLimiter.networkPrefixLimitV4[0].ConnCount) + }) +} diff --git a/go-libp2p/p2p/host/resource-manager/scope.go b/go-libp2p/p2p/host/resource-manager/scope.go index 60089c3..8a6bc23 100644 --- a/go-libp2p/p2p/host/resource-manager/scope.go +++ b/go-libp2p/p2p/host/resource-manager/scope.go @@ -118,12 +118,10 @@ func (rc *resources) checkMemory(rsvp int64, prio uint8) error { threshold, mulOk := mulInt64WithOverflow(1+int64(prio), limit) if !mulOk { thresholdBig := big.NewInt(limit) - thresholdBig = thresholdBig.Mul(thresholdBig, big.NewInt(1+int64(prio))) + thresholdBig.Mul(thresholdBig, big.NewInt(1+int64(prio))) thresholdBig.Rsh(thresholdBig, 8) // Divide 256 - if !thresholdBig.IsInt64() { - // Shouldn't happen since the threshold can only be <= limit - threshold = limit - } + // necessarily a Int64 since we multiplied a int64 != MaxInt64 with + // a uint8+1 (max 255+1 = 256) and divided by 256 threshold = thresholdBig.Int64() } else { threshold = threshold / 256 @@ -745,10 +743,13 @@ func (s *resourceScope) Done() { s.Lock() defer s.Unlock() + s.doneUnlocked() +} + +func (s *resourceScope) doneUnlocked() { if s.done { return } - stat := s.rc.stat() if s.owner != nil { s.owner.ReleaseResources(stat) diff --git a/go-libp2p/p2p/host/resource-manager/scope_test.go b/go-libp2p/p2p/host/resource-manager/scope_test.go index 0464cb0..7bf7ff7 100644 --- a/go-libp2p/p2p/host/resource-manager/scope_test.go +++ b/go-libp2p/p2p/host/resource-manager/scope_test.go @@ -74,7 +74,7 @@ func TestCheckMemory(t *testing.T) { limit = 1024 } currentMem = (currentMem % limit) // We can't have reserved more than our limit - res = (res >> 14) // We won't resonably ever have a reservation > 2^50 + res = (res >> 14) // We won't reasonably ever have a reservation > 2^50 rc := resources{limit: &BaseLimit{ Memory: int64(limit), StreamsInbound: 1, @@ -88,7 +88,7 @@ func TestCheckMemory(t *testing.T) { rc.memory = int64(currentMem) priShift = (priShift % 9) - // Check different priorties at 2^0, 2^1,...2^8. This lets our math be correct in the check below (and avoid overflows). + // Check different priorities at 2^0, 2^1,...2^8. This lets our math be correct in the check below (and avoid overflows). pri := uint8((1 << priShift) - 1) err := rc.checkMemory(int64(res), pri) @@ -97,7 +97,7 @@ func TestCheckMemory(t *testing.T) { return true } - return (err != nil) == (uint64(res)+uint64(rc.memory) > (uint64(limit) >> uint64(8-priShift))) + return (err != nil) == (res+uint64(rc.memory) > (limit >> uint64(8-priShift))) } require.NoError(t, quick.Check(f, nil)) diff --git a/go-libp2p/p2p/host/routed/routed.go b/go-libp2p/p2p/host/routed/routed.go index eb8e58e..8248e50 100644 --- a/go-libp2p/p2p/host/routed/routed.go +++ b/go-libp2p/p2p/host/routed/routed.go @@ -48,8 +48,10 @@ func Wrap(h host.Host, r Routing) *RoutedHost { func (rh *RoutedHost) Connect(ctx context.Context, pi peer.AddrInfo) error { // first, check if we're already connected unless force direct dial. forceDirect, _ := network.GetForceDirectDial(ctx) + canUseLimitedConn, _ := network.GetAllowLimitedConn(ctx) if !forceDirect { - if rh.Network().Connectedness(pi.ID) == network.Connected { + connectedness := rh.Network().Connectedness(pi.ID) + if connectedness == network.Connected || (canUseLimitedConn && connectedness == network.Limited) { return nil } } diff --git a/go-libp2p/p2p/http/example_test.go b/go-libp2p/p2p/http/example_test.go new file mode 100644 index 0000000..ca87fe4 --- /dev/null +++ b/go-libp2p/p2p/http/example_test.go @@ -0,0 +1,359 @@ +package libp2phttp_test + +import ( + "fmt" + "io" + "log" + "net" + "net/http" + "strings" + + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p/core/peer" + libp2phttp "github.com/libp2p/go-libp2p/p2p/http" + ma "github.com/multiformats/go-multiaddr" +) + +func ExampleHost_withAStockGoHTTPClient() { + server := libp2phttp.Host{ + InsecureAllowHTTP: true, // For our example, we'll allow insecure HTTP + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/http")}, + } + + // A server with a simple echo protocol + server.SetHTTPHandler("/echo/1.0.0", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "application/octet-stream") + io.Copy(w, r.Body) + })) + go server.Serve() + defer server.Close() + + var serverHTTPPort string + var err error + for _, a := range server.Addrs() { + serverHTTPPort, err = a.ValueForProtocol(ma.P_TCP) + if err == nil { + break + } + } + if err != nil { + log.Fatal(err) + } + + // Make an HTTP request using the Go standard library. + resp, err := http.Post("http://127.0.0.1:"+serverHTTPPort+"/echo/1.0.0/", "application/octet-stream", strings.NewReader("Hello HTTP")) + if err != nil { + log.Fatal(err) + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + fmt.Println(string(body)) + + // Output: Hello HTTP +} + +func ExampleHost_listenOnHTTPTransportAndStreams() { + serverStreamHost, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1")) + if err != nil { + log.Fatal(err) + } + defer serverStreamHost.Close() + + server := libp2phttp.Host{ + InsecureAllowHTTP: true, // For our example, we'll allow insecure HTTP + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/http")}, + StreamHost: serverStreamHost, + } + go server.Serve() + defer server.Close() + + for _, a := range server.Addrs() { + _, transport := ma.SplitLast(a) + fmt.Printf("Server listening on transport: %s\n", transport) + } + // Output: Server listening on transport: /quic-v1 + // Server listening on transport: /http +} + +func ExampleHost_overLibp2pStreams() { + serverStreamHost, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1")) + if err != nil { + log.Fatal(err) + } + + server := libp2phttp.Host{ + StreamHost: serverStreamHost, + } + + // A server with a simple echo protocol + server.SetHTTPHandler("/echo/1.0.0", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "application/octet-stream") + io.Copy(w, r.Body) + })) + go server.Serve() + defer server.Close() + + clientStreamHost, err := libp2p.New(libp2p.NoListenAddrs) + if err != nil { + log.Fatal(err) + } + + client := libp2phttp.Host{StreamHost: clientStreamHost} + + // Make an HTTP request using the Go standard library, but over libp2p + // streams. If the server were listening on an HTTP transport, this could + // also make the request over the HTTP transport. + httpClient, err := client.NamespacedClient("/echo/1.0.0", peer.AddrInfo{ID: server.PeerID(), Addrs: server.Addrs()}) + + // Only need to Post to "/" because this client is namespaced to the "/echo/1.0.0" protocol. + resp, err := httpClient.Post("/", "application/octet-stream", strings.NewReader("Hello HTTP")) + if err != nil { + log.Fatal(err) + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + fmt.Println(string(body)) + + // Output: Hello HTTP +} + +func ExampleHost_Serve() { + server := libp2phttp.Host{ + InsecureAllowHTTP: true, // For our example, we'll allow insecure HTTP + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/50221/http")}, + } + + go server.Serve() + defer server.Close() + + fmt.Println(server.Addrs()) + + // Output: [/ip4/127.0.0.1/tcp/50221/http] +} + +func ExampleHost_SetHTTPHandler() { + server := libp2phttp.Host{ + InsecureAllowHTTP: true, // For our example, we'll allow insecure HTTP + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/http")}, + } + + server.SetHTTPHandler("/hello/1", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "text/plain") + w.Write([]byte("Hello World")) + })) + + go server.Serve() + defer server.Close() + + port, err := server.Addrs()[0].ValueForProtocol(ma.P_TCP) + if err != nil { + log.Fatal(err) + } + + resp, err := http.Get("http://127.0.0.1:" + port + "/hello/1/") + if err != nil { + log.Fatal(err) + } + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + + fmt.Println(string(respBody)) + + // Output: Hello World +} + +func ExampleHost_SetHTTPHandlerAtPath() { + server := libp2phttp.Host{ + InsecureAllowHTTP: true, // For our example, we'll allow insecure HTTP + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/http")}, + } + + server.SetHTTPHandlerAtPath("/hello/1", "/other-place/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "text/plain") + w.Write([]byte("Hello World")) + })) + + go server.Serve() + defer server.Close() + + port, err := server.Addrs()[0].ValueForProtocol(ma.P_TCP) + if err != nil { + log.Fatal(err) + } + + resp, err := http.Get("http://127.0.0.1:" + port + "/other-place/") + if err != nil { + log.Fatal(err) + } + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + + fmt.Println(string(respBody)) + + // Output: Hello World +} + +func ExampleHost_NamespacedClient() { + var client libp2phttp.Host + + // Create the server + server := libp2phttp.Host{ + InsecureAllowHTTP: true, // For our example, we'll allow insecure HTTP + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/http")}, + } + + server.SetHTTPHandlerAtPath("/hello/1", "/other-place/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "text/plain") + w.Write([]byte("Hello World")) + })) + + go server.Serve() + defer server.Close() + + // Create an http.Client that is namespaced to this protocol. + httpClient, err := client.NamespacedClient("/hello/1", peer.AddrInfo{ID: server.PeerID(), Addrs: server.Addrs()}) + if err != nil { + log.Fatal(err) + } + + resp, err := httpClient.Get("/") + if err != nil { + log.Fatal(err) + } + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + + fmt.Println(string(respBody)) + + // Output: Hello World +} + +func ExampleHost_NamespaceRoundTripper() { + var client libp2phttp.Host + + // Create the server + server := libp2phttp.Host{ + InsecureAllowHTTP: true, // For our example, we'll allow insecure HTTP + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/http")}, + } + + server.SetHTTPHandler("/hello/1", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "text/plain") + w.Write([]byte("Hello World")) + })) + + go server.Serve() + defer server.Close() + + // Create an http.Roundtripper for the server + rt, err := client.NewConstrainedRoundTripper(peer.AddrInfo{ID: server.PeerID(), Addrs: server.Addrs()}) + if err != nil { + log.Fatal(err) + } + + // Namespace this roundtripper to a specific protocol + rt, err = client.NamespaceRoundTripper(rt, "/hello/1", server.PeerID()) + if err != nil { + log.Fatal(err) + } + + resp, err := (&http.Client{Transport: rt}).Get("/") + if err != nil { + log.Fatal(err) + } + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + + fmt.Println(string(respBody)) + + // Output: Hello World +} + +func ExampleHost_NewConstrainedRoundTripper() { + var client libp2phttp.Host + + // Create the server + server := libp2phttp.Host{ + InsecureAllowHTTP: true, // For our example, we'll allow insecure HTTP + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/http")}, + } + + server.SetHTTPHandler("/hello/1", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "text/plain") + w.Write([]byte("Hello World")) + })) + + go server.Serve() + defer server.Close() + + // Create an http.Roundtripper for the server + rt, err := client.NewConstrainedRoundTripper(peer.AddrInfo{ID: server.PeerID(), Addrs: server.Addrs()}) + if err != nil { + log.Fatal(err) + } + + resp, err := (&http.Client{Transport: rt}).Get("/hello/1") + if err != nil { + log.Fatal(err) + } + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + + fmt.Println(string(respBody)) + + // Output: Hello World +} + +func ExampleWellKnownHandler() { + var h libp2phttp.WellKnownHandler + h.AddProtocolMeta("/hello/1", libp2phttp.ProtocolMeta{ + Path: "/hello-path/", + }) + + listener, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + log.Fatal(err) + } + + defer listener.Close() + // Serve the well-known resource. Note, this is handled automatically if you use the libp2phttp.Host. + go http.Serve(listener, &h) + + // Get the well-known resource + resp, err := http.Get("http://" + listener.Addr().String() + libp2phttp.WellKnownProtocols) + if err != nil { + log.Fatal(err) + } + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + + fmt.Println(string(respBody)) + // Output: {"/hello/1":{"path":"/hello-path/"}} + +} diff --git a/go-libp2p/p2p/http/libp2phttp.go b/go-libp2p/p2p/http/libp2phttp.go new file mode 100644 index 0000000..5ff025e --- /dev/null +++ b/go-libp2p/p2p/http/libp2phttp.go @@ -0,0 +1,918 @@ +// HTTP semantics with libp2p. Can use a libp2p stream transport or stock HTTP +// transports. This API is experimental and will likely change soon. Implements [libp2p spec #508](https://github.com/libp2p/specs/pull/508). +package libp2phttp + +import ( + "bufio" + "context" + "crypto/tls" + "encoding/json" + "errors" + "fmt" + "io" + "net" + "net/http" + "net/url" + "strconv" + "strings" + "sync" + "time" + + lru "github.com/hashicorp/golang-lru/v2" + logging "github.com/ipfs/go-log/v2" + host "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/peerstore" + "github.com/libp2p/go-libp2p/core/protocol" + gostream "github.com/libp2p/go-libp2p/p2p/net/gostream" + ma "github.com/multiformats/go-multiaddr" +) + +var log = logging.Logger("libp2phttp") + +var WellKnownRequestTimeout = 30 * time.Second + +const ProtocolIDForMultistreamSelect = "/http/1.1" +const WellKnownProtocols = "/.well-known/libp2p/protocols" + +// LegacyWellKnownProtocols refer to a the well-known resource used in an early +// draft of the libp2p+http spec. Some users have deployed this, and need backwards compatibility. +// Hopefully we can phase this out in the future. Context: https://github.com/libp2p/go-libp2p/pull/2797 +const LegacyWellKnownProtocols = "/.well-known/libp2p" + +const peerMetadataLimit = 8 << 10 // 8KB +const peerMetadataLRUSize = 256 // How many different peer's metadata to keep in our LRU cache + +// ProtocolMeta is metadata about a protocol. +type ProtocolMeta struct { + // Path defines the HTTP Path prefix used for this protocol + Path string `json:"path"` +} + +type PeerMeta map[protocol.ID]ProtocolMeta + +// WellKnownHandler is an http.Handler that serves the well-known resource +type WellKnownHandler struct { + wellknownMapMu sync.Mutex + wellKnownMapping PeerMeta + wellKnownCache []byte +} + +// streamHostListen returns a net.Listener that listens on libp2p streams for HTTP/1.1 messages. +func streamHostListen(streamHost host.Host) (net.Listener, error) { + return gostream.Listen(streamHost, ProtocolIDForMultistreamSelect) +} + +func (h *WellKnownHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + // Check if the requests accepts JSON + accepts := r.Header.Get("Accept") + if accepts != "" && !(strings.Contains(accepts, "application/json") || strings.Contains(accepts, "*/*")) { + http.Error(w, "Only application/json is supported", http.StatusNotAcceptable) + return + } + + if r.Method != http.MethodGet { + http.Error(w, "Only GET requests are supported", http.StatusMethodNotAllowed) + return + } + + // Return a JSON object with the well-known protocols + h.wellknownMapMu.Lock() + mapping := h.wellKnownCache + var err error + if mapping == nil { + mapping, err = json.Marshal(h.wellKnownMapping) + if err == nil { + h.wellKnownCache = mapping + } + } + h.wellknownMapMu.Unlock() + if err != nil { + http.Error(w, "Marshal error", http.StatusInternalServerError) + return + } + w.Header().Add("Content-Type", "application/json") + w.Header().Add("Content-Length", strconv.Itoa(len(mapping))) + w.Write(mapping) +} + +func (h *WellKnownHandler) AddProtocolMeta(p protocol.ID, protocolMeta ProtocolMeta) { + h.wellknownMapMu.Lock() + if h.wellKnownMapping == nil { + h.wellKnownMapping = make(map[protocol.ID]ProtocolMeta) + } + h.wellKnownMapping[p] = protocolMeta + h.wellKnownCache = nil + h.wellknownMapMu.Unlock() +} + +func (h *WellKnownHandler) RemoveProtocolMeta(p protocol.ID) { + h.wellknownMapMu.Lock() + if h.wellKnownMapping != nil { + delete(h.wellKnownMapping, p) + } + h.wellKnownCache = nil + h.wellknownMapMu.Unlock() +} + +// Host is a libp2p host for request/responses with HTTP semantics. This is +// in contrast to a stream-oriented host like the core host.Host interface. Its +// zero-value (&Host{}) is usable. Do not copy by value. +// See examples for usage. +// +// Warning, this is experimental. The API will likely change. +type Host struct { + // StreamHost is a stream based libp2p host used to do HTTP over libp2p streams. May be nil + StreamHost host.Host + // ListenAddrs are the requested addresses to listen on. Multiaddrs must be + // valid HTTP(s) multiaddr. Only multiaddrs for an HTTP transport are + // supported (must end with /http or /https). + ListenAddrs []ma.Multiaddr + // TLSConfig is the TLS config for the server to use + TLSConfig *tls.Config + // InsecureAllowHTTP indicates if the server is allowed to serve unencrypted + // HTTP requests over TCP. + InsecureAllowHTTP bool + // ServeMux is the http.ServeMux used by the server to serve requests. If + // nil, a new serve mux will be created. Users may manually add handlers to + // this mux instead of using `SetHTTPHandler`, but if they do, they should + // also update the WellKnownHandler's protocol mapping. + ServeMux *http.ServeMux + initializeServeMux sync.Once + + // DefaultClientRoundTripper is the default http.RoundTripper for clients to + // use when making requests over an HTTP transport. This must be an + // `*http.Transport` type so that the transport can be cloned and the + // `TLSClientConfig` field can be configured. If unset, it will create a new + // `http.Transport` on first use. + DefaultClientRoundTripper *http.Transport + + // WellKnownHandler is the http handler for the well-known + // resource. It is responsible for sharing this node's protocol metadata + // with other nodes. Users only care about this if they set their own + // ServeMux with pre-existing routes. By default, new protocols are added + // here when a user calls `SetHTTPHandler` or `SetHTTPHandlerAtPath`. + WellKnownHandler WellKnownHandler + + // EnableCompatibilityWithLegacyWellKnownEndpoint allows compatibility with + // an older version of the spec that defined the well-known resource as: + // .well-known/libp2p. + // For servers, this means hosting the well-known resource at both the + // legacy and current paths. + // For clients it means making two parallel requests and picking the first one that succeeds. + // + // Long term this should be deprecated once enough users have upgraded to a + // newer go-libp2p version and we can remove all this code. + EnableCompatibilityWithLegacyWellKnownEndpoint bool + + // peerMetadata is an LRU cache of a peer's well-known protocol map. + peerMetadata *lru.Cache[peer.ID, PeerMeta] + // createHTTPTransport is used to lazily create the httpTransport in a thread-safe way. + createHTTPTransport sync.Once + // createDefaultClientRoundTripper is used to lazily create the default + // client round tripper in a thread-safe way. + createDefaultClientRoundTripper sync.Once + httpTransport *httpTransport +} + +type httpTransport struct { + listenAddrs []ma.Multiaddr + listeners []net.Listener + closeListeners chan struct{} + waitingForListeners chan struct{} +} + +func newPeerMetadataCache() *lru.Cache[peer.ID, PeerMeta] { + peerMetadata, err := lru.New[peer.ID, PeerMeta](peerMetadataLRUSize) + if err != nil { + // Only happens if size is < 1. We make sure to not do that, so this should never happen. + panic(err) + } + return peerMetadata +} + +func (h *Host) httpTransportInit() { + h.createHTTPTransport.Do(func() { + h.httpTransport = &httpTransport{ + closeListeners: make(chan struct{}), + waitingForListeners: make(chan struct{}), + } + }) +} + +func (h *Host) serveMuxInit() { + h.initializeServeMux.Do(func() { + if h.ServeMux == nil { + h.ServeMux = http.NewServeMux() + } + }) +} + +func (h *Host) Addrs() []ma.Multiaddr { + h.httpTransportInit() + <-h.httpTransport.waitingForListeners + return h.httpTransport.listenAddrs +} + +// ID returns the peer ID of the underlying stream host, or the zero value if there is no stream host. +func (h *Host) PeerID() peer.ID { + if h.StreamHost != nil { + return h.StreamHost.ID() + } + return "" +} + +var ErrNoListeners = errors.New("nothing to listen on") + +func (h *Host) setupListeners(listenerErrCh chan error) error { + for _, addr := range h.ListenAddrs { + parsedAddr := parseMultiaddr(addr) + // resolve the host + ipaddr, err := net.ResolveIPAddr("ip", parsedAddr.host) + if err != nil { + return err + } + + host := ipaddr.String() + l, err := net.Listen("tcp", host+":"+parsedAddr.port) + if err != nil { + return err + } + h.httpTransport.listeners = append(h.httpTransport.listeners, l) + + // get resolved port + _, port, err := net.SplitHostPort(l.Addr().String()) + if err != nil { + return err + } + + var listenAddr ma.Multiaddr + if parsedAddr.useHTTPS && parsedAddr.sni != "" && parsedAddr.sni != host { + listenAddr = ma.StringCast(fmt.Sprintf("/ip4/%s/tcp/%s/tls/sni/%s/http", host, port, parsedAddr.sni)) + } else { + scheme := "http" + if parsedAddr.useHTTPS { + scheme = "https" + } + listenAddr = ma.StringCast(fmt.Sprintf("/ip4/%s/tcp/%s/%s", host, port, scheme)) + } + + if parsedAddr.useHTTPS { + go func() { + srv := http.Server{ + Handler: h.ServeMux, + TLSConfig: h.TLSConfig, + } + listenerErrCh <- srv.ServeTLS(l, "", "") + }() + h.httpTransport.listenAddrs = append(h.httpTransport.listenAddrs, listenAddr) + } else if h.InsecureAllowHTTP { + go func() { + listenerErrCh <- http.Serve(l, h.ServeMux) + }() + h.httpTransport.listenAddrs = append(h.httpTransport.listenAddrs, listenAddr) + } else { + // We are not serving insecure HTTP + log.Warnf("Not serving insecure HTTP on %s. Prefer an HTTPS endpoint.", listenAddr) + } + } + return nil +} + +// Serve starts the HTTP transport listeners. Always returns a non-nil error. +// If there are no listeners, returns ErrNoListeners. +func (h *Host) Serve() error { + // assert that each addr contains a /http component + for _, addr := range h.ListenAddrs { + _, isHTTP := normalizeHTTPMultiaddr(addr) + if !isHTTP { + return fmt.Errorf("address %s does not contain a /http or /https component", addr) + } + } + + h.serveMuxInit() + h.ServeMux.Handle(WellKnownProtocols, &h.WellKnownHandler) + if h.EnableCompatibilityWithLegacyWellKnownEndpoint { + h.ServeMux.Handle(LegacyWellKnownProtocols, &h.WellKnownHandler) + } + + h.httpTransportInit() + + closedWaitingForListeners := false + defer func() { + if !closedWaitingForListeners { + close(h.httpTransport.waitingForListeners) + } + }() + + if len(h.ListenAddrs) == 0 && h.StreamHost == nil { + return ErrNoListeners + } + + h.httpTransport.listeners = make([]net.Listener, 0, len(h.ListenAddrs)+1) // +1 for stream host + + streamHostAddrsCount := 0 + if h.StreamHost != nil { + streamHostAddrsCount = len(h.StreamHost.Addrs()) + } + h.httpTransport.listenAddrs = make([]ma.Multiaddr, 0, len(h.ListenAddrs)+streamHostAddrsCount) + + errCh := make(chan error) + + if h.StreamHost != nil { + listener, err := streamHostListen(h.StreamHost) + if err != nil { + return err + } + h.httpTransport.listeners = append(h.httpTransport.listeners, listener) + h.httpTransport.listenAddrs = append(h.httpTransport.listenAddrs, h.StreamHost.Addrs()...) + + go func() { + errCh <- http.Serve(listener, connectionCloseHeaderMiddleware(h.ServeMux)) + }() + } + + closeAllListeners := func() { + for _, l := range h.httpTransport.listeners { + l.Close() + } + } + + err := h.setupListeners(errCh) + if err != nil { + closeAllListeners() + return err + } + + close(h.httpTransport.waitingForListeners) + closedWaitingForListeners = true + + if len(h.httpTransport.listeners) == 0 || len(h.httpTransport.listenAddrs) == 0 { + closeAllListeners() + return ErrNoListeners + } + + expectedErrCount := len(h.httpTransport.listeners) + select { + case <-h.httpTransport.closeListeners: + case err = <-errCh: + expectedErrCount-- + } + + // Close all listeners + closeAllListeners() + for i := 0; i < expectedErrCount; i++ { + <-errCh + } + close(errCh) + + return err +} + +func (h *Host) Close() error { + h.httpTransportInit() + close(h.httpTransport.closeListeners) + return nil +} + +// SetHTTPHandler sets the HTTP handler for a given protocol. Automatically +// manages the well-known resource mapping. +// http.StripPrefix is called on the handler, so the handler will be unaware of +// its prefix path. +func (h *Host) SetHTTPHandler(p protocol.ID, handler http.Handler) { + h.SetHTTPHandlerAtPath(p, string(p), handler) +} + +// SetHTTPHandlerAtPath sets the HTTP handler for a given protocol using the +// given path. Automatically manages the well-known resource mapping. +// http.StripPrefix is called on the handler, so the handler will be unaware of +// its prefix path. +func (h *Host) SetHTTPHandlerAtPath(p protocol.ID, path string, handler http.Handler) { + if path == "" || path[len(path)-1] != '/' { + // We are nesting this handler under this path, so it should end with a slash. + path += "/" + } + h.WellKnownHandler.AddProtocolMeta(p, ProtocolMeta{Path: path}) + h.serveMuxInit() + // Do not trim the trailing / from path + // This allows us to serve `/a/b` when we mount a handler for `/b` at path `/a` + h.ServeMux.Handle(path, http.StripPrefix(strings.TrimSuffix(path, "/"), handler)) +} + +// PeerMetadataGetter lets RoundTrippers implement a specific way of caching a peer's protocol mapping. +type PeerMetadataGetter interface { + GetPeerMetadata() (PeerMeta, error) +} + +type streamRoundTripper struct { + server peer.ID + addrsAdded sync.Once + serverAddrs []ma.Multiaddr + h host.Host + httpHost *Host +} + +// streamReadCloser wraps an io.ReadCloser and closes the underlying stream when +// closed (as well as closing the wrapped ReadCloser). This is necessary because +// we have two things to close, the body and the stream. The stream isn't closed +// by the body automatically, as hinted at by the fact that `http.ReadResponse` +// takes a bufio.Reader. +type streamReadCloser struct { + io.ReadCloser + s network.Stream +} + +func (s *streamReadCloser) Close() error { + s.s.Close() + return s.ReadCloser.Close() +} + +func (rt *streamRoundTripper) GetPeerMetadata() (PeerMeta, error) { + ctx := context.Background() + ctx, cancel := context.WithDeadline(ctx, time.Now().Add(WellKnownRequestTimeout)) + defer cancel() + return rt.httpHost.getAndStorePeerMetadata(ctx, rt, rt.server) +} + +// RoundTrip implements http.RoundTripper. +func (rt *streamRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) { + // Add the addresses we learned about for this server + rt.addrsAdded.Do(func() { + if len(rt.serverAddrs) > 0 { + rt.h.Peerstore().AddAddrs(rt.server, rt.serverAddrs, peerstore.TempAddrTTL) + } + rt.serverAddrs = nil // may as well cleanup + }) + + s, err := rt.h.NewStream(r.Context(), rt.server, ProtocolIDForMultistreamSelect) + if err != nil { + return nil, err + } + + // Write connection: close header to ensure the stream is closed after the response + r.Header.Add("connection", "close") + + go func() { + defer s.CloseWrite() + r.Write(s) + if r.Body != nil { + r.Body.Close() + } + }() + + if deadline, ok := r.Context().Deadline(); ok { + s.SetReadDeadline(deadline) + } + + resp, err := http.ReadResponse(bufio.NewReader(s), r) + if err != nil { + s.Close() + return nil, err + } + resp.Body = &streamReadCloser{resp.Body, s} + + return resp, nil +} + +// roundTripperForSpecificServer is an http.RoundTripper targets a specific server. Still reuses the underlying RoundTripper for the requests. +// The underlying RoundTripper MUST be an HTTP Transport. +type roundTripperForSpecificServer struct { + http.RoundTripper + ownRoundtripper bool + httpHost *Host + server peer.ID + targetServerAddr string + sni string + scheme string + cachedProtos PeerMeta +} + +func (rt *roundTripperForSpecificServer) GetPeerMetadata() (PeerMeta, error) { + // Do we already have the peer's protocol mapping? + if rt.cachedProtos != nil { + return rt.cachedProtos, nil + } + + // if the underlying roundtripper implements GetPeerMetadata, use that + if g, ok := rt.RoundTripper.(PeerMetadataGetter); ok { + wk, err := g.GetPeerMetadata() + if err == nil { + rt.cachedProtos = wk + return wk, nil + } + } + + ctx := context.Background() + ctx, cancel := context.WithDeadline(ctx, time.Now().Add(WellKnownRequestTimeout)) + defer cancel() + wk, err := rt.httpHost.getAndStorePeerMetadata(ctx, rt, rt.server) + if err == nil { + rt.cachedProtos = wk + return wk, nil + } + return wk, err +} + +// RoundTrip implements http.RoundTripper. +func (rt *roundTripperForSpecificServer) RoundTrip(r *http.Request) (*http.Response, error) { + if (r.URL.Scheme != "" && r.URL.Scheme != rt.scheme) || (r.URL.Host != "" && r.URL.Host != rt.targetServerAddr) { + return nil, fmt.Errorf("this transport is only for requests to %s://%s", rt.scheme, rt.targetServerAddr) + } + r.URL.Scheme = rt.scheme + r.URL.Host = rt.targetServerAddr + r.Host = rt.sni + return rt.RoundTripper.RoundTrip(r) +} + +func (rt *roundTripperForSpecificServer) CloseIdleConnections() { + if rt.ownRoundtripper { + // Safe to close idle connections, since we own the RoundTripper. We + // aren't closing other's idle connections. + type closeIdler interface { + CloseIdleConnections() + } + if tr, ok := rt.RoundTripper.(closeIdler); ok { + tr.CloseIdleConnections() + } + } + // No-op, since we don't want users thinking they are closing idle + // connections for this server, when in fact they are closing all idle + // connections +} + +// namespacedRoundTripper is a round tripper that prefixes all requests with a +// given path prefix. It is used to namespace requests to a specific protocol. +type namespacedRoundTripper struct { + http.RoundTripper + protocolPrefix string + protocolPrefixRaw string +} + +func (rt *namespacedRoundTripper) GetPeerMetadata() (PeerMeta, error) { + if g, ok := rt.RoundTripper.(PeerMetadataGetter); ok { + return g.GetPeerMetadata() + } + + return nil, fmt.Errorf("can not get peer protocol map. Inner roundtripper does not implement GetPeerMetadata") +} + +// RoundTrip implements http.RoundTripper. +func (rt *namespacedRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) { + if !strings.HasPrefix(r.URL.Path, rt.protocolPrefix) { + r.URL.Path = rt.protocolPrefix + r.URL.Path + } + if !strings.HasPrefix(r.URL.RawPath, rt.protocolPrefixRaw) { + r.URL.RawPath = rt.protocolPrefixRaw + r.URL.Path + } + + return rt.RoundTripper.RoundTrip(r) +} + +// NamespaceRoundTripper returns an http.RoundTripper that are scoped to the given protocol on the given server. +func (h *Host) NamespaceRoundTripper(roundtripper http.RoundTripper, p protocol.ID, server peer.ID) (*namespacedRoundTripper, error) { + ctx := context.Background() + ctx, cancel := context.WithDeadline(ctx, time.Now().Add(WellKnownRequestTimeout)) + defer cancel() + protos, err := h.getAndStorePeerMetadata(ctx, roundtripper, server) + if err != nil { + return &namespacedRoundTripper{}, err + } + + v, ok := protos[p] + if !ok { + return &namespacedRoundTripper{}, fmt.Errorf("no protocol %s for server %s", p, server) + } + + path := v.Path + if path[len(path)-1] == '/' { + // Trim the trailing slash, since it's common to make requests starting with a leading forward slash for the path + path = path[:len(path)-1] + } + + u, err := url.Parse(path) + if err != nil { + return &namespacedRoundTripper{}, fmt.Errorf("invalid path %s for protocol %s for server %s", v.Path, p, server) + } + + return &namespacedRoundTripper{ + RoundTripper: roundtripper, + protocolPrefix: u.Path, + protocolPrefixRaw: u.RawPath, + }, nil +} + +// NamespacedClient returns an http.Client that is scoped to the given protocol +// on the given server. It creates a new RoundTripper for each call. If you are +// creating many namespaced clients, consider creating a round tripper directly +// and namespacing the roundripper yourself, then creating clients from the +// namespace round tripper. +func (h *Host) NamespacedClient(p protocol.ID, server peer.AddrInfo, opts ...RoundTripperOption) (http.Client, error) { + rt, err := h.NewConstrainedRoundTripper(server, opts...) + if err != nil { + return http.Client{}, err + } + + nrt, err := h.NamespaceRoundTripper(rt, p, server.ID) + if err != nil { + return http.Client{}, err + } + + return http.Client{Transport: nrt}, nil +} + +// NewConstrainedRoundTripper returns an http.RoundTripper that can fulfill and HTTP +// request to the given server. It may use an HTTP transport or a stream based +// transport. It is valid to pass an empty server.ID. +// If there are multiple addresses for the server, it will pick the best +// transport (stream vs standard HTTP) using the following rules: +// - If PreferHTTPTransport is set, use the HTTP transport. +// - If ServerMustAuthenticatePeerID is set, use the stream transport, as the +// HTTP transport does not do peer id auth yet. +// - If we already have a connection on a stream transport, use that. +// - Otherwise, if we have both, use the HTTP transport. +func (h *Host) NewConstrainedRoundTripper(server peer.AddrInfo, opts ...RoundTripperOption) (http.RoundTripper, error) { + options := roundTripperOpts{} + for _, o := range opts { + options = o(options) + } + + if options.serverMustAuthenticatePeerID && server.ID == "" { + return nil, fmt.Errorf("server must authenticate peer ID, but no peer ID provided") + } + + httpAddrs := make([]ma.Multiaddr, 0, 1) // The common case of a single http address + nonHTTPAddrs := make([]ma.Multiaddr, 0, len(server.Addrs)) + + firstAddrIsHTTP := false + + for i, addr := range server.Addrs { + addr, isHTTP := normalizeHTTPMultiaddr(addr) + if isHTTP { + if i == 0 { + firstAddrIsHTTP = true + } + httpAddrs = append(httpAddrs, addr) + } else { + nonHTTPAddrs = append(nonHTTPAddrs, addr) + } + } + + // Do we have an existing connection to this peer? + existingStreamConn := false + if server.ID != "" && h.StreamHost != nil { + existingStreamConn = len(h.StreamHost.Network().ConnsToPeer(server.ID)) > 0 + } + + // Currently the HTTP transport can not authenticate peer IDs. + if !options.serverMustAuthenticatePeerID && len(httpAddrs) > 0 && (options.preferHTTPTransport || (firstAddrIsHTTP && !existingStreamConn)) { + parsed := parseMultiaddr(httpAddrs[0]) + scheme := "http" + if parsed.useHTTPS { + scheme = "https" + } + + h.createDefaultClientRoundTripper.Do(func() { + if h.DefaultClientRoundTripper == nil { + h.DefaultClientRoundTripper = &http.Transport{} + } + }) + rt := h.DefaultClientRoundTripper + ownRoundtripper := false + if parsed.sni != parsed.host { + // We have a different host and SNI (e.g. using an IP address but specifying a SNI) + // We need to make our own transport to support this. + rt = rt.Clone() + rt.TLSClientConfig.ServerName = parsed.sni + ownRoundtripper = true + } + + return &roundTripperForSpecificServer{ + RoundTripper: rt, + ownRoundtripper: ownRoundtripper, + httpHost: h, + server: server.ID, + targetServerAddr: parsed.host + ":" + parsed.port, + sni: parsed.sni, + scheme: scheme, + }, nil + } + + // Otherwise use a stream based transport + if h.StreamHost == nil { + return nil, fmt.Errorf("can not use the HTTP transport (either no address or PeerID auth is required), and no stream host provided") + } + if !existingStreamConn { + if server.ID == "" { + return nil, fmt.Errorf("can not use the HTTP transport, and no server peer ID provided") + } + } + + return &streamRoundTripper{h: h.StreamHost, server: server.ID, serverAddrs: nonHTTPAddrs, httpHost: h}, nil +} + +type httpMultiaddr struct { + useHTTPS bool + host string + port string + sni string +} + +func parseMultiaddr(addr ma.Multiaddr) httpMultiaddr { + out := httpMultiaddr{} + ma.ForEach(addr, func(c ma.Component) bool { + switch c.Protocol().Code { + case ma.P_IP4, ma.P_IP6, ma.P_DNS, ma.P_DNS4, ma.P_DNS6: + out.host = c.Value() + case ma.P_TCP, ma.P_UDP: + out.port = c.Value() + case ma.P_TLS, ma.P_HTTPS: + out.useHTTPS = true + case ma.P_SNI: + out.sni = c.Value() + + } + return out.host == "" || out.port == "" || !out.useHTTPS || out.sni == "" + }) + + if out.useHTTPS && out.sni == "" { + out.sni = out.host + } + return out +} + +var httpComponent, _ = ma.NewComponent("http", "") +var tlsComponent, _ = ma.NewComponent("tls", "") + +// normalizeHTTPMultiaddr converts an https multiaddr to a tls/http one. +// Returns a bool indicating if the input multiaddr has an http (or https) component. +func normalizeHTTPMultiaddr(addr ma.Multiaddr) (ma.Multiaddr, bool) { + isHTTPMultiaddr := false + beforeHTTPS, afterIncludingHTTPS := ma.SplitFunc(addr, func(c ma.Component) bool { + if c.Protocol().Code == ma.P_HTTP { + isHTTPMultiaddr = true + } + + if c.Protocol().Code == ma.P_HTTPS { + isHTTPMultiaddr = true + return true + } + return false + }) + + if afterIncludingHTTPS == nil { + // No HTTPS component, just return the original + return addr, isHTTPMultiaddr + } + + _, afterHTTPS := ma.SplitFirst(afterIncludingHTTPS) + if afterHTTPS == nil { + return ma.Join(beforeHTTPS, tlsComponent, httpComponent), isHTTPMultiaddr + } + + return ma.Join(beforeHTTPS, tlsComponent, httpComponent, afterHTTPS), isHTTPMultiaddr +} + +// getAndStorePeerMetadata looks up the protocol path in the well-known mapping and +// returns it. Will only store the peer's protocol mapping if the server ID is +// provided. +func (h *Host) getAndStorePeerMetadata(ctx context.Context, roundtripper http.RoundTripper, server peer.ID) (PeerMeta, error) { + if h.peerMetadata == nil { + h.peerMetadata = newPeerMetadataCache() + } + if meta, ok := h.peerMetadata.Get(server); server != "" && ok { + return meta, nil + } + + var meta PeerMeta + var err error + if h.EnableCompatibilityWithLegacyWellKnownEndpoint { + type metaAndErr struct { + m PeerMeta + err error + } + legacyRespCh := make(chan metaAndErr, 1) + wellKnownRespCh := make(chan metaAndErr, 1) + ctx, cancel := context.WithCancel(ctx) + go func() { + meta, err := requestPeerMeta(ctx, roundtripper, LegacyWellKnownProtocols) + legacyRespCh <- metaAndErr{meta, err} + }() + go func() { + meta, err := requestPeerMeta(ctx, roundtripper, WellKnownProtocols) + wellKnownRespCh <- metaAndErr{meta, err} + }() + select { + case resp := <-legacyRespCh: + if resp.err != nil { + resp = <-wellKnownRespCh + } + meta, err = resp.m, resp.err + case resp := <-wellKnownRespCh: + if resp.err != nil { + legacyResp := <-legacyRespCh + if legacyResp.err != nil { + // If both endpoints error, return the error from the well + // known resource (not the legacy well known resource) + meta, err = resp.m, resp.err + } else { + meta, err = legacyResp.m, legacyResp.err + } + } else { + meta, err = resp.m, resp.err + } + } + cancel() + } else { + meta, err = requestPeerMeta(ctx, roundtripper, WellKnownProtocols) + } + if err != nil { + return nil, err + } + + if server != "" { + h.peerMetadata.Add(server, meta) + } + + return meta, nil +} + +func requestPeerMeta(ctx context.Context, roundtripper http.RoundTripper, wellKnownResource string) (PeerMeta, error) { + req, err := http.NewRequest("GET", wellKnownResource, nil) + if err != nil { + return nil, err + } + req.Header.Set("Accept", "application/json") + + client := http.Client{Transport: roundtripper} + resp, err := client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode) + } + + meta := PeerMeta{} + err = json.NewDecoder(&io.LimitedReader{ + R: resp.Body, + N: peerMetadataLimit, + }).Decode(&meta) + if err != nil { + return nil, err + } + + return meta, nil +} + +// SetPeerMetadata adds a peer's protocol metadata to the http host. Useful if +// you have out-of-band knowledge of a peer's protocol mapping. +func (h *Host) SetPeerMetadata(server peer.ID, meta PeerMeta) { + if h.peerMetadata == nil { + h.peerMetadata = newPeerMetadataCache() + } + h.peerMetadata.Add(server, meta) +} + +// AddPeerMetadata merges the given peer's protocol metadata to the http host. Useful if +// you have out-of-band knowledge of a peer's protocol mapping. +func (h *Host) AddPeerMetadata(server peer.ID, meta PeerMeta) { + if h.peerMetadata == nil { + h.peerMetadata = newPeerMetadataCache() + } + origMeta, ok := h.peerMetadata.Get(server) + if !ok { + h.peerMetadata.Add(server, meta) + return + } + for proto, m := range meta { + origMeta[proto] = m + } + h.peerMetadata.Add(server, origMeta) +} + +// GetPeerMetadata gets a peer's cached protocol metadata from the http host. +func (h *Host) GetPeerMetadata(server peer.ID) (PeerMeta, bool) { + if h.peerMetadata == nil { + return nil, false + } + return h.peerMetadata.Get(server) +} + +// RemovePeerMetadata removes a peer's protocol metadata from the http host +func (h *Host) RemovePeerMetadata(server peer.ID) { + if h.peerMetadata == nil { + return + } + h.peerMetadata.Remove(server) +} + +func connectionCloseHeaderMiddleware(next http.Handler) http.Handler { + // Sets connection: close. It's preferable to not reuse streams for HTTP. + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Connection", "close") + next.ServeHTTP(w, r) + }) +} diff --git a/go-libp2p/p2p/http/libp2phttp_test.go b/go-libp2p/p2p/http/libp2phttp_test.go new file mode 100644 index 0000000..a444c6e --- /dev/null +++ b/go-libp2p/p2p/http/libp2phttp_test.go @@ -0,0 +1,721 @@ +package libp2phttp_test + +import ( + "bytes" + "context" + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "crypto/tls" + "crypto/x509" + "crypto/x509/pkix" + "encoding/json" + "fmt" + "io" + "math/big" + "net" + "net/http" + "net/netip" + "net/url" + "os" + "reflect" + "strings" + "testing" + "time" + + "github.com/libp2p/go-libp2p" + host "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/peer" + libp2phttp "github.com/libp2p/go-libp2p/p2p/http" + httpping "github.com/libp2p/go-libp2p/p2p/http/ping" + ma "github.com/multiformats/go-multiaddr" + "github.com/stretchr/testify/require" +) + +func TestHTTPOverStreams(t *testing.T) { + serverHost, err := libp2p.New( + libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1"), + ) + require.NoError(t, err) + + httpHost := libp2phttp.Host{StreamHost: serverHost} + + httpHost.SetHTTPHandler("/hello", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("hello")) + })) + + // Start server + go httpHost.Serve() + defer httpHost.Close() + + // Start client + clientHost, err := libp2p.New(libp2p.NoListenAddrs) + require.NoError(t, err) + clientHost.Connect(context.Background(), peer.AddrInfo{ + ID: serverHost.ID(), + Addrs: serverHost.Addrs(), + }) + + clientRT, err := (&libp2phttp.Host{StreamHost: clientHost}).NewConstrainedRoundTripper(peer.AddrInfo{ID: serverHost.ID()}) + require.NoError(t, err) + + client := &http.Client{Transport: clientRT} + + resp, err := client.Get("/hello") + require.NoError(t, err) + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + require.NoError(t, err) + + require.Equal(t, "hello", string(body)) +} + +func TestHTTPOverStreamsSendsConnectionClose(t *testing.T) { + serverHost, err := libp2p.New( + libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1"), + ) + require.NoError(t, err) + + httpHost := libp2phttp.Host{StreamHost: serverHost} + + connectionHeaderVal := make(chan string, 1) + httpHost.SetHTTPHandlerAtPath("/hello", "/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("hello")) + connectionHeaderVal <- r.Header.Get("Connection") + })) + + // Start server + go httpHost.Serve() + defer httpHost.Close() + + // run client + clientHost, err := libp2p.New(libp2p.NoListenAddrs) + require.NoError(t, err) + clientHost.Connect(context.Background(), peer.AddrInfo{ + ID: serverHost.ID(), + Addrs: serverHost.Addrs(), + }) + clientHttpHost := libp2phttp.Host{StreamHost: clientHost} + rt, err := clientHttpHost.NewConstrainedRoundTripper(peer.AddrInfo{ID: serverHost.ID()}) + require.NoError(t, err) + client := &http.Client{Transport: rt} + _, err = client.Get("/") + require.NoError(t, err) + + select { + case val := <-connectionHeaderVal: + require.Equal(t, "close", strings.ToLower(val)) + case <-time.After(5 * time.Second): + t.Fatal("timeout waiting for connection header") + } +} + +func TestHTTPOverStreamsContextAndClientTimeout(t *testing.T) { + const clientTimeout = 200 * time.Millisecond + + serverHost, err := libp2p.New( + libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1"), + ) + require.NoError(t, err) + + httpHost := libp2phttp.Host{StreamHost: serverHost} + httpHost.SetHTTPHandler("/hello/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + time.Sleep(2 * clientTimeout) + w.Write([]byte("hello")) + })) + + // Start server + go httpHost.Serve() + defer httpHost.Close() + + // Start client + clientHost, err := libp2p.New(libp2p.NoListenAddrs) + require.NoError(t, err) + clientHost.Connect(context.Background(), peer.AddrInfo{ + ID: serverHost.ID(), + Addrs: serverHost.Addrs(), + }) + + clientRT, err := (&libp2phttp.Host{StreamHost: clientHost}).NewConstrainedRoundTripper(peer.AddrInfo{ID: serverHost.ID()}) + require.NoError(t, err) + + ctx, cancel := context.WithTimeout(context.Background(), clientTimeout) + defer cancel() + req, err := http.NewRequestWithContext(ctx, http.MethodGet, "/hello/", nil) + require.NoError(t, err) + + client := &http.Client{Transport: clientRT} + _, err = client.Do(req) + require.Error(t, err) + require.ErrorIs(t, err, os.ErrDeadlineExceeded) + t.Log("OK, deadline exceeded waiting for response as expected") + + // Make another request, this time using http.Client.Timeout. + clientRT, err = (&libp2phttp.Host{StreamHost: clientHost}).NewConstrainedRoundTripper(peer.AddrInfo{ID: serverHost.ID()}) + require.NoError(t, err) + + client = &http.Client{ + Transport: clientRT, + Timeout: clientTimeout, + } + + _, err = client.Get("/hello/") + require.Error(t, err) + var uerr *url.Error + require.ErrorAs(t, err, &uerr) + require.True(t, uerr.Timeout()) + t.Log("OK, timed out waiting for response as expected") +} + +func TestHTTPOverStreamsReturnsConnectionClose(t *testing.T) { + serverHost, err := libp2p.New( + libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1"), + ) + require.NoError(t, err) + + httpHost := libp2phttp.Host{StreamHost: serverHost} + + httpHost.SetHTTPHandlerAtPath("/hello", "/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("hello")) + })) + + // Start server + go httpHost.Serve() + defer httpHost.Close() + + // Start client + clientHost, err := libp2p.New(libp2p.NoListenAddrs) + require.NoError(t, err) + clientHost.Connect(context.Background(), peer.AddrInfo{ + ID: serverHost.ID(), + Addrs: serverHost.Addrs(), + }) + + s, err := clientHost.NewStream(context.Background(), serverHost.ID(), libp2phttp.ProtocolIDForMultistreamSelect) + require.NoError(t, err) + _, err = s.Write([]byte("GET / HTTP/1.1\r\nHost: \r\n\r\n")) + require.NoError(t, err) + + out := make([]byte, 1024) + n, err := s.Read(out) + if err != io.EOF { + require.NoError(t, err) + } + + require.Contains(t, strings.ToLower(string(out[:n])), "connection: close") +} + +func TestRoundTrippers(t *testing.T) { + serverHost, err := libp2p.New( + libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1"), + ) + require.NoError(t, err) + + httpHost := libp2phttp.Host{ + InsecureAllowHTTP: true, + StreamHost: serverHost, + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/http")}, + } + + httpHost.SetHTTPHandler("/hello", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("hello")) + })) + + // Start stream based server + go httpHost.Serve() + defer httpHost.Close() + + serverMultiaddrs := httpHost.Addrs() + serverHTTPAddr := serverMultiaddrs[1] + + testCases := []struct { + name string + setupRoundTripper func(t *testing.T, clientStreamHost host.Host, clientHTTPHost *libp2phttp.Host) http.RoundTripper + expectStreamRoundTripper bool + }{ + { + name: "HTTP preferred", + setupRoundTripper: func(t *testing.T, clientStreamHost host.Host, clientHTTPHost *libp2phttp.Host) http.RoundTripper { + rt, err := clientHTTPHost.NewConstrainedRoundTripper(peer.AddrInfo{ + ID: serverHost.ID(), + Addrs: serverMultiaddrs, + }, libp2phttp.PreferHTTPTransport) + require.NoError(t, err) + return rt + }, + }, + { + name: "HTTP first", + setupRoundTripper: func(t *testing.T, clientStreamHost host.Host, clientHTTPHost *libp2phttp.Host) http.RoundTripper { + rt, err := clientHTTPHost.NewConstrainedRoundTripper(peer.AddrInfo{ + ID: serverHost.ID(), + Addrs: []ma.Multiaddr{serverHTTPAddr, serverHost.Addrs()[0]}, + }) + require.NoError(t, err) + return rt + }, + }, + { + name: "No HTTP transport", + setupRoundTripper: func(t *testing.T, clientStreamHost host.Host, clientHTTPHost *libp2phttp.Host) http.RoundTripper { + rt, err := clientHTTPHost.NewConstrainedRoundTripper(peer.AddrInfo{ + ID: serverHost.ID(), + Addrs: []ma.Multiaddr{serverHost.Addrs()[0]}, + }) + require.NoError(t, err) + return rt + }, + expectStreamRoundTripper: true, + }, + { + name: "Stream transport first", + setupRoundTripper: func(t *testing.T, clientStreamHost host.Host, clientHTTPHost *libp2phttp.Host) http.RoundTripper { + rt, err := clientHTTPHost.NewConstrainedRoundTripper(peer.AddrInfo{ + ID: serverHost.ID(), + Addrs: []ma.Multiaddr{serverHost.Addrs()[0], serverHTTPAddr}, + }) + require.NoError(t, err) + return rt + }, + expectStreamRoundTripper: true, + }, + { + name: "Existing stream transport connection", + setupRoundTripper: func(t *testing.T, clientStreamHost host.Host, clientHTTPHost *libp2phttp.Host) http.RoundTripper { + clientStreamHost.Connect(context.Background(), peer.AddrInfo{ + ID: serverHost.ID(), + Addrs: serverHost.Addrs(), + }) + rt, err := clientHTTPHost.NewConstrainedRoundTripper(peer.AddrInfo{ + ID: serverHost.ID(), + Addrs: []ma.Multiaddr{serverHTTPAddr, serverHost.Addrs()[0]}, + }) + require.NoError(t, err) + return rt + }, + expectStreamRoundTripper: true, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + // Start client + clientStreamHost, err := libp2p.New(libp2p.NoListenAddrs) + require.NoError(t, err) + defer clientStreamHost.Close() + + clientHttpHost := &libp2phttp.Host{StreamHost: clientStreamHost} + + rt := tc.setupRoundTripper(t, clientStreamHost, clientHttpHost) + if tc.expectStreamRoundTripper { + // Hack to get the private type of this roundtripper + typ := reflect.TypeOf(rt).String() + require.Contains(t, typ, "streamRoundTripper", "Expected stream based round tripper") + } + + for _, tc := range []bool{true, false} { + name := "" + if tc { + name = "with namespaced roundtripper" + } + t.Run(name, func(t *testing.T) { + var resp *http.Response + var err error + if tc { + var h libp2phttp.Host + require.NoError(t, err) + nrt, err := h.NamespaceRoundTripper(rt, "/hello", serverHost.ID()) + require.NoError(t, err) + client := &http.Client{Transport: nrt} + resp, err = client.Get("/") + require.NoError(t, err) + } else { + client := &http.Client{Transport: rt} + resp, err = client.Get("/hello/") + require.NoError(t, err) + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + require.NoError(t, err) + require.Equal(t, "hello", string(body)) + }) + } + + // Read the well-known resource + wk, err := rt.(libp2phttp.PeerMetadataGetter).GetPeerMetadata() + require.NoError(t, err) + + expectedMap := make(libp2phttp.PeerMeta) + expectedMap["/hello"] = libp2phttp.ProtocolMeta{Path: "/hello/"} + require.Equal(t, expectedMap, wk) + }) + } +} + +func TestPlainOldHTTPServer(t *testing.T) { + mux := http.NewServeMux() + wk := libp2phttp.WellKnownHandler{} + mux.Handle(libp2phttp.WellKnownProtocols, &wk) + + mux.Handle("/ping/", httpping.Ping{}) + wk.AddProtocolMeta(httpping.PingProtocolID, libp2phttp.ProtocolMeta{Path: "/ping/"}) + + server := &http.Server{Addr: "127.0.0.1:0", Handler: mux} + + l, err := net.Listen("tcp", server.Addr) + require.NoError(t, err) + + go server.Serve(l) + defer server.Close() + + // That's all for the server, now the client: + + serverAddrParts := strings.Split(l.Addr().String(), ":") + + testCases := []struct { + name string + do func(*testing.T, *http.Request) (*http.Response, error) + getWellKnown func(*testing.T) (libp2phttp.PeerMeta, error) + }{ + { + name: "using libp2phttp", + do: func(t *testing.T, request *http.Request) (*http.Response, error) { + var clientHttpHost libp2phttp.Host + rt, err := clientHttpHost.NewConstrainedRoundTripper(peer.AddrInfo{Addrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/" + serverAddrParts[1] + "/http")}}) + require.NoError(t, err) + + client := &http.Client{Transport: rt} + return client.Do(request) + }, + getWellKnown: func(t *testing.T) (libp2phttp.PeerMeta, error) { + var clientHttpHost libp2phttp.Host + rt, err := clientHttpHost.NewConstrainedRoundTripper(peer.AddrInfo{Addrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/" + serverAddrParts[1] + "/http")}}) + require.NoError(t, err) + return rt.(libp2phttp.PeerMetadataGetter).GetPeerMetadata() + }, + }, + { + name: "using stock http client", + do: func(t *testing.T, request *http.Request) (*http.Response, error) { + request.URL.Scheme = "http" + request.URL.Host = l.Addr().String() + request.Host = l.Addr().String() + + client := http.Client{} + return client.Do(request) + }, + getWellKnown: func(t *testing.T) (libp2phttp.PeerMeta, error) { + client := http.Client{} + resp, err := client.Get("http://" + l.Addr().String() + libp2phttp.WellKnownProtocols) + require.NoError(t, err) + + b, err := io.ReadAll(resp.Body) + require.NoError(t, err) + + var out libp2phttp.PeerMeta + err = json.Unmarshal(b, &out) + return out, err + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + body := [32]byte{} + _, err = rand.Reader.Read(body[:]) + require.NoError(t, err) + req, err := http.NewRequest(http.MethodPost, "/ping/", bytes.NewReader(body[:])) + require.NoError(t, err) + resp, err := tc.do(t, req) + require.NoError(t, err) + require.Equal(t, http.StatusOK, resp.StatusCode) + rBody := [32]byte{} + _, err = io.ReadFull(resp.Body, rBody[:]) + require.NoError(t, err) + require.Equal(t, body, rBody) + + // Make sure we can get the well known resource + protoMap, err := tc.getWellKnown(t) + require.NoError(t, err) + + expectedMap := make(libp2phttp.PeerMeta) + expectedMap[httpping.PingProtocolID] = libp2phttp.ProtocolMeta{Path: "/ping/"} + require.Equal(t, expectedMap, protoMap) + }) + } +} + +func TestHostZeroValue(t *testing.T) { + server := libp2phttp.Host{ + InsecureAllowHTTP: true, + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/http")}, + } + server.SetHTTPHandler("/hello", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hello")) })) + go func() { + server.Serve() + }() + defer server.Close() + + c := libp2phttp.Host{} + client, err := c.NamespacedClient("/hello", peer.AddrInfo{Addrs: server.Addrs()}) + require.NoError(t, err) + resp, err := client.Get("/") + require.NoError(t, err) + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + require.NoError(t, err) + + require.Equal(t, "hello", string(body), "expected response from server") +} + +func TestHTTPS(t *testing.T) { + server := libp2phttp.Host{ + TLSConfig: selfSignedTLSConfig(t), + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/https")}, + } + server.SetHTTPHandler(httpping.PingProtocolID, httpping.Ping{}) + go func() { + server.Serve() + }() + defer server.Close() + + clientTransport := http.DefaultTransport.(*http.Transport).Clone() + clientTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + client := libp2phttp.Host{ + DefaultClientRoundTripper: clientTransport, + } + httpClient, err := client.NamespacedClient(httpping.PingProtocolID, peer.AddrInfo{Addrs: server.Addrs()}) + require.NoError(t, err) + err = httpping.SendPing(httpClient) + require.NoError(t, err) +} + +func selfSignedTLSConfig(t *testing.T) *tls.Config { + t.Helper() + priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + require.NoError(t, err) + + notBefore := time.Now() + notAfter := notBefore.Add(365 * 24 * time.Hour) + + serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) + serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) + require.NoError(t, err) + + certTemplate := x509.Certificate{ + SerialNumber: serialNumber, + Subject: pkix.Name{ + Organization: []string{"Test"}, + }, + NotBefore: notBefore, + NotAfter: notAfter, + KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, + BasicConstraintsValid: true, + } + + derBytes, err := x509.CreateCertificate(rand.Reader, &certTemplate, &certTemplate, &priv.PublicKey, priv) + require.NoError(t, err) + + cert := tls.Certificate{ + Certificate: [][]byte{derBytes}, + PrivateKey: priv, + } + + tlsConfig := &tls.Config{ + Certificates: []tls.Certificate{cert}, + } + return tlsConfig +} + +func TestCustomServeMux(t *testing.T) { + serveMux := http.NewServeMux() + serveMux.Handle("/ping/", httpping.Ping{}) + + server := libp2phttp.Host{ + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/http")}, + ServeMux: serveMux, + InsecureAllowHTTP: true, + } + server.WellKnownHandler.AddProtocolMeta(httpping.PingProtocolID, libp2phttp.ProtocolMeta{Path: "/ping/"}) + go func() { + server.Serve() + }() + defer server.Close() + + addrs := server.Addrs() + require.Len(t, addrs, 1) + var clientHttpHost libp2phttp.Host + rt, err := clientHttpHost.NewConstrainedRoundTripper(peer.AddrInfo{Addrs: addrs}, libp2phttp.PreferHTTPTransport) + require.NoError(t, err) + + client := &http.Client{Transport: rt} + body := [32]byte{} + req, _ := http.NewRequest(http.MethodPost, "/ping/", bytes.NewReader(body[:])) + resp, err := client.Do(req) + require.NoError(t, err) + require.Equal(t, 200, resp.StatusCode) +} + +func TestSetHandlerAtPath(t *testing.T) { + hf := func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "text/plain") + w.Write([]byte("Hello World")) + } + tests := []struct { + prefix, rest string + paths200 []string + paths404 []string + }{ + { + prefix: "/", + rest: "/", + paths200: []string{"/", "/a/", "/b", "/a/b"}, + }, + { + prefix: "/a", + rest: "/b/", + paths200: []string{"/a/b/", "///a///b/", "/a/b/c"}, + // Not being able to serve /a/b when handling /a/b/ is a rather annoying limitation + // of http.StripPrefix mechanism. This happens because /a/b is redirected to /b/ + // as the prefix /a is stripped when the redirect happens + paths404: []string{"/a/b", "/a", "/b", "/a/a"}, + }, + { + prefix: "/", + rest: "/b/", + paths200: []string{"/b", "/b/c", "/b/c/"}, + paths404: []string{"/", "/a/b"}, + }, + } + for i, tc := range tests { + t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + nestedMx := http.NewServeMux() + nestedMx.HandleFunc(tc.rest, hf) + server := libp2phttp.Host{ + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/http")}, + InsecureAllowHTTP: true, + } + server.SetHTTPHandlerAtPath("test", tc.prefix, nestedMx) + go func() { + server.Serve() + }() + defer server.Close() + addrs := server.Addrs() + require.Len(t, addrs, 1) + port, err := addrs[0].ValueForProtocol(ma.P_TCP) + require.NoError(t, err) + httpAddr := fmt.Sprintf("http://127.0.0.1:%s", port) + for _, p := range tc.paths200 { + resp, err := http.Get(httpAddr + p) + require.NoError(t, err) + require.Equal(t, 200, resp.StatusCode, "path:%s", p) + resp.Body.Close() + } + for _, p := range tc.paths404 { + resp, _ := http.Get(httpAddr + p) + require.Equal(t, 404, resp.StatusCode, "path:%s", p) + resp.Body.Close() + } + }) + } +} + +func TestServerLegacyWellKnownResource(t *testing.T) { + mkHTTPServer := func(wellKnown string) ma.Multiaddr { + mux := http.NewServeMux() + wk := libp2phttp.WellKnownHandler{} + mux.Handle(wellKnown, &wk) + + mux.Handle("/ping/", httpping.Ping{}) + wk.AddProtocolMeta(httpping.PingProtocolID, libp2phttp.ProtocolMeta{Path: "/ping/"}) + + server := &http.Server{Addr: "127.0.0.1:0", Handler: mux} + + l, err := net.Listen("tcp", server.Addr) + require.NoError(t, err) + + go server.Serve(l) + t.Cleanup(func() { server.Close() }) + addrPort, err := netip.ParseAddrPort(l.Addr().String()) + require.NoError(t, err) + return ma.StringCast(fmt.Sprintf("/ip4/%s/tcp/%d/http", addrPort.Addr().String(), addrPort.Port())) + } + + mkServerlibp2phttp := func(enableLegacyWellKnown bool) ma.Multiaddr { + server := libp2phttp.Host{ + EnableCompatibilityWithLegacyWellKnownEndpoint: enableLegacyWellKnown, + ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/0/http")}, + InsecureAllowHTTP: true, + } + server.SetHTTPHandler(httpping.PingProtocolID, httpping.Ping{}) + go server.Serve() + t.Cleanup(func() { server.Close() }) + return server.Addrs()[0] + } + + type testCase struct { + name string + client libp2phttp.Host + serverAddr ma.Multiaddr + expectErr bool + } + + var testCases = []testCase{ + { + name: "legacy server, client with compat", + client: libp2phttp.Host{EnableCompatibilityWithLegacyWellKnownEndpoint: true}, + serverAddr: mkHTTPServer(libp2phttp.LegacyWellKnownProtocols), + }, + { + name: "up-to-date http server, client with compat", + client: libp2phttp.Host{EnableCompatibilityWithLegacyWellKnownEndpoint: true}, + serverAddr: mkHTTPServer(libp2phttp.WellKnownProtocols), + }, + { + name: "up-to-date http server, client without compat", + client: libp2phttp.Host{}, + serverAddr: mkHTTPServer(libp2phttp.WellKnownProtocols), + }, + { + name: "libp2phttp server with compat, client with compat", + client: libp2phttp.Host{EnableCompatibilityWithLegacyWellKnownEndpoint: true}, + serverAddr: mkServerlibp2phttp(true), + }, + { + name: "libp2phttp server without compat, client with compat", + client: libp2phttp.Host{EnableCompatibilityWithLegacyWellKnownEndpoint: true}, + serverAddr: mkServerlibp2phttp(false), + }, + { + name: "libp2phttp server with compat, client without compat", + client: libp2phttp.Host{}, + serverAddr: mkServerlibp2phttp(true), + }, + { + name: "legacy server, client without compat", + client: libp2phttp.Host{}, + serverAddr: mkHTTPServer(libp2phttp.LegacyWellKnownProtocols), + expectErr: true, + }, + } + + for i := range testCases { + tc := &testCases[i] // to not copy the lock in libp2phttp.Host + t.Run(tc.name, func(t *testing.T) { + if tc.expectErr { + _, err := tc.client.NamespacedClient(httpping.PingProtocolID, peer.AddrInfo{Addrs: []ma.Multiaddr{tc.serverAddr}}) + require.Error(t, err) + return + } + httpClient, err := tc.client.NamespacedClient(httpping.PingProtocolID, peer.AddrInfo{Addrs: []ma.Multiaddr{tc.serverAddr}}) + require.NoError(t, err) + + err = httpping.SendPing(httpClient) + require.NoError(t, err) + }) + } + +} diff --git a/go-libp2p/p2p/http/options.go b/go-libp2p/p2p/http/options.go new file mode 100644 index 0000000..0062e59 --- /dev/null +++ b/go-libp2p/p2p/http/options.go @@ -0,0 +1,24 @@ +package libp2phttp + +type RoundTripperOption func(o roundTripperOpts) roundTripperOpts + +type roundTripperOpts struct { + preferHTTPTransport bool + serverMustAuthenticatePeerID bool +} + +// PreferHTTPTransport tells the roundtripper constructor to prefer using an +// HTTP transport (as opposed to a libp2p stream transport). Useful, for +// example, if you want to attempt to leverage HTTP caching. +func PreferHTTPTransport(o roundTripperOpts) roundTripperOpts { + o.preferHTTPTransport = true + return o +} + +// ServerMustAuthenticatePeerID tells the roundtripper constructor that we MUST +// authenticate the Server's PeerID. Note: this currently means we can not use a +// native HTTP transport (HTTP peer id authentication is not yet implemented: https://github.com/libp2p/specs/pull/564). +func ServerMustAuthenticatePeerID(o roundTripperOpts) roundTripperOpts { + o.serverMustAuthenticatePeerID = true + return o +} diff --git a/go-libp2p/p2p/http/ping/ping.go b/go-libp2p/p2p/http/ping/ping.go new file mode 100644 index 0000000..2c2ad80 --- /dev/null +++ b/go-libp2p/p2p/http/ping/ping.go @@ -0,0 +1,67 @@ +package httpping + +import ( + "bytes" + "crypto/rand" + "errors" + "fmt" + "io" + "net/http" + "strconv" +) + +const pingSize = 32 +const PingProtocolID = "/http-ping/1" + +type Ping struct{} + +var _ http.Handler = Ping{} + +// ServeHTTP implements http.Handler. +func (Ping) ServeHTTP(w http.ResponseWriter, r *http.Request) { + body := [pingSize]byte{} + _, err := io.ReadFull(r.Body, body[:]) + if err != nil { + w.WriteHeader(http.StatusBadRequest) + return + } + + w.Header().Set("Content-Type", "application/octet-stream") + w.Header().Set("Content-Length", strconv.Itoa(pingSize)) + w.Write(body[:]) +} + +// SendPing send an ping request over HTTP. The provided client should be namespaced to the Ping protocol. +func SendPing(client http.Client) error { + body := [pingSize]byte{} + _, err := io.ReadFull(rand.Reader, body[:]) + if err != nil { + return err + } + req, err := http.NewRequest("POST", "/", bytes.NewReader(body[:])) + req.Header.Set("Content-Type", "application/octet-stream") + req.Header.Set("Content-Length", strconv.Itoa(pingSize)) + if err != nil { + return err + } + resp, err := client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("unexpected status code: %d", resp.StatusCode) + } + + rBody := [pingSize]byte{} + _, err = io.ReadFull(resp.Body, rBody[:]) + if err != nil { + return err + } + + if !bytes.Equal(body[:], rBody[:]) { + return errors.New("ping body mismatch") + } + return nil +} diff --git a/go-libp2p/p2p/metricshelper/conn.go b/go-libp2p/p2p/metricshelper/conn.go index ef367ac..b07016c 100644 --- a/go-libp2p/p2p/metricshelper/conn.go +++ b/go-libp2p/p2p/metricshelper/conn.go @@ -2,7 +2,7 @@ package metricshelper import ma "github.com/multiformats/go-multiaddr" -var transports = [...]int{ma.P_CIRCUIT, ma.P_WEBRTC, ma.P_WEBTRANSPORT, ma.P_QUIC, ma.P_QUIC_V1, ma.P_WSS, ma.P_WS, ma.P_TCP} +var transports = [...]int{ma.P_CIRCUIT, ma.P_WEBRTC, ma.P_WEBRTC_DIRECT, ma.P_WEBTRANSPORT, ma.P_QUIC, ma.P_QUIC_V1, ma.P_WSS, ma.P_WS, ma.P_TCP} func GetTransport(a ma.Multiaddr) string { for _, t := range transports { diff --git a/go-libp2p/p2p/muxer/mplex/conn.go b/go-libp2p/p2p/muxer/mplex/conn.go deleted file mode 100644 index ed4e847..0000000 --- a/go-libp2p/p2p/muxer/mplex/conn.go +++ /dev/null @@ -1,48 +0,0 @@ -package mplex - -import ( - "context" - - "github.com/libp2p/go-libp2p/core/network" - - mp "github.com/libp2p/go-mplex" -) - -type conn mp.Multiplex - -var _ network.MuxedConn = &conn{} - -// NewMuxedConn constructs a new Conn from a *mp.Multiplex. -func NewMuxedConn(m *mp.Multiplex) network.MuxedConn { - return (*conn)(m) -} - -func (c *conn) Close() error { - return c.mplex().Close() -} - -func (c *conn) IsClosed() bool { - return c.mplex().IsClosed() -} - -// OpenStream creates a new stream. -func (c *conn) OpenStream(ctx context.Context) (network.MuxedStream, error) { - s, err := c.mplex().NewStream(ctx) - if err != nil { - return nil, err - } - return (*stream)(s), nil -} - -// AcceptStream accepts a stream opened by the other side. -func (c *conn) AcceptStream() (network.MuxedStream, error) { - s, err := c.mplex().Accept() - if err != nil { - return nil, err - } - return (*stream)(s), nil -} - -func (c *conn) mplex() *mp.Multiplex { - return (*mp.Multiplex)(c) -} diff --git a/go-libp2p/p2p/muxer/mplex/stream.go b/go-libp2p/p2p/muxer/mplex/stream.go deleted file mode 100644 index 53e9e6d..0000000 --- a/go-libp2p/p2p/muxer/mplex/stream.go +++ /dev/null @@ -1,64 +0,0 @@ -package mplex - -import ( - "time" - - "github.com/libp2p/go-libp2p/core/network" - - mp "github.com/libp2p/go-mplex" -) - -// stream implements network.MuxedStream over mplex.Stream. -type stream mp.Stream - -var _ network.MuxedStream = &stream{} - -func (s *stream) Read(b []byte) (n int, err error) { - n, err = s.mplex().Read(b) - if err == mp.ErrStreamReset { - err = network.ErrReset - } - - return n, err -} - -func (s *stream) Write(b []byte) (n int, err error) { - n, err = s.mplex().Write(b) - if err == mp.ErrStreamReset { - err = network.ErrReset - } - - return n, err -} - -func (s *stream) Close() error { - return s.mplex().Close() -} - -func (s *stream) CloseWrite() error { - return s.mplex().CloseWrite() -} - -func (s *stream) CloseRead() error { - return s.mplex().CloseRead() -} - -func (s *stream) Reset() error { - return s.mplex().Reset() -} - -func (s *stream) SetDeadline(t time.Time) error { - return s.mplex().SetDeadline(t) -} - -func (s *stream) SetReadDeadline(t time.Time) error { - return s.mplex().SetReadDeadline(t) -} - -func (s *stream) SetWriteDeadline(t time.Time) error { - return s.mplex().SetWriteDeadline(t) -} - -func (s *stream) mplex() *mp.Stream { - return (*mp.Stream)(s) -} diff --git a/go-libp2p/p2p/muxer/mplex/transport.go b/go-libp2p/p2p/muxer/mplex/transport.go deleted file mode 100644 index 10d54d1..0000000 --- a/go-libp2p/p2p/muxer/mplex/transport.go +++ /dev/null @@ -1,28 +0,0 @@ -package mplex - -import ( - "net" - - "github.com/libp2p/go-libp2p/core/network" - - mp "github.com/libp2p/go-mplex" -) - -// DefaultTransport has default settings for Transport -var DefaultTransport = &Transport{} - -const ID = "/mplex/6.7.0" - -var _ network.Multiplexer = &Transport{} - -// Transport implements mux.Multiplexer that constructs -// mplex-backed muxed connections. -type Transport struct{} - -func (t *Transport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) { - m, err := mp.NewMultiplex(nc, isServer, scope) - if err != nil { - return nil, err - } - return NewMuxedConn(m), nil -} diff --git a/go-libp2p/p2p/muxer/mplex/transport_test.go b/go-libp2p/p2p/muxer/mplex/transport_test.go deleted file mode 100644 index 3a7d00f..0000000 --- a/go-libp2p/p2p/muxer/mplex/transport_test.go +++ /dev/null @@ -1,52 +0,0 @@ -package mplex - -import ( - "errors" - "net" - "testing" - - "github.com/libp2p/go-libp2p/core/network" - test "github.com/libp2p/go-libp2p/p2p/muxer/testsuite" -) - -func TestDefaultTransport(t *testing.T) { - test.SubtestAll(t, DefaultTransport) -} - -type memoryScope struct { - network.PeerScope - limit int - reserved int -} - -func (m *memoryScope) ReserveMemory(size int, prio uint8) error { - if m.reserved+size > m.limit { - return errors.New("too much") - } - m.reserved += size - return nil -} - -func (m *memoryScope) ReleaseMemory(size int) { - m.reserved -= size - if m.reserved < 0 { - panic("too much memory released") - } -} - -type memoryLimitedTransport struct { - Transport -} - -func (t *memoryLimitedTransport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) { - return t.Transport.NewConn(nc, isServer, &memoryScope{ - limit: 3 * 1 << 20, - PeerScope: scope, - }) -} - -func TestDefaultTransportWithMemoryLimit(t *testing.T) { - test.SubtestAll(t, &memoryLimitedTransport{ - Transport: *DefaultTransport, - }) -} diff --git a/go-libp2p/p2p/net/connmgr/connmgr.go b/go-libp2p/p2p/net/connmgr/connmgr.go index b42a122..cf6bb58 100644 --- a/go-libp2p/p2p/net/connmgr/connmgr.go +++ b/go-libp2p/p2p/net/connmgr/connmgr.go @@ -2,6 +2,7 @@ package connmgr import ( "context" + "fmt" "sort" "sync" "sync/atomic" @@ -72,7 +73,7 @@ type segments struct { } func (ss *segments) get(p peer.ID) *segment { - return ss.buckets[byte(p[len(p)-1])] + return ss.buckets[p[len(p)-1]] } func (ss *segments) countPeers() (count int) { @@ -239,6 +240,17 @@ func (cm *BasicConnMgr) IsProtected(id peer.ID, tag string) (protected bool) { return protected } +func (cm *BasicConnMgr) CheckLimit(systemLimit connmgr.GetConnLimiter) error { + if cm.cfg.highWater > systemLimit.GetConnLimit() { + return fmt.Errorf( + "conn manager high watermark limit: %d, exceeds the system connection limit of: %d", + cm.cfg.highWater, + systemLimit.GetConnLimit(), + ) + } + return nil +} + // peerInfo stores metadata for a given peer. type peerInfo struct { id peer.ID diff --git a/go-libp2p/p2p/net/connmgr/connmgr_test.go b/go-libp2p/p2p/net/connmgr/connmgr_test.go index 8b5bbad..2c65725 100644 --- a/go-libp2p/p2p/net/connmgr/connmgr_test.go +++ b/go-libp2p/p2p/net/connmgr/connmgr_test.go @@ -662,7 +662,6 @@ func TestPeerProtectionMultipleTags(t *testing.T) { t.Error("protected connection was closed by connection manager") } } - } func TestPeerProtectionIdempotent(t *testing.T) { @@ -835,7 +834,7 @@ func TestPeerInfoSorting(t *testing.T) { p2 := &peerInfo{id: peer.ID("peer2"), temp: true} pis := peerInfos{p1, p2} pis.SortByValueAndStreams(makeSegmentsWithPeerInfos(pis), false) - require.Equal(t, pis, peerInfos{p2, p1}) + require.Equal(t, peerInfos{p2, p1}, pis) }) t.Run("starts with low-value connections", func(t *testing.T) { @@ -843,7 +842,7 @@ func TestPeerInfoSorting(t *testing.T) { p2 := &peerInfo{id: peer.ID("peer2"), value: 20} pis := peerInfos{p1, p2} pis.SortByValueAndStreams(makeSegmentsWithPeerInfos(pis), false) - require.Equal(t, pis, peerInfos{p2, p1}) + require.Equal(t, peerInfos{p2, p1}, pis) }) t.Run("prefer peers with no streams", func(t *testing.T) { @@ -859,7 +858,7 @@ func TestPeerInfoSorting(t *testing.T) { } pis := peerInfos{p2, p1} pis.SortByValueAndStreams(makeSegmentsWithPeerInfos(pis), false) - require.Equal(t, pis, peerInfos{p1, p2}) + require.Equal(t, peerInfos{p1, p2}, pis) }) t.Run("in a memory emergency, starts with incoming connections and higher streams", func(t *testing.T) { @@ -902,7 +901,7 @@ func TestPeerInfoSorting(t *testing.T) { // p3 is first because it is inactive (no streams). // p4 is second because it has the most streams and we priortize killing // connections with the higher number of streams. - require.Equal(t, pis, peerInfos{p3, p4, p2, p1}) + require.Equal(t, peerInfos{p3, p4, p2, p1}, pis) }) t.Run("in a memory emergency, starts with connections that have many streams", func(t *testing.T) { @@ -921,7 +920,7 @@ func TestPeerInfoSorting(t *testing.T) { } pis := peerInfos{p1, p2} pis.SortByValueAndStreams(makeSegmentsWithPeerInfos(pis), true) - require.Equal(t, pis, peerInfos{p2, p1}) + require.Equal(t, peerInfos{p2, p1}, pis) }) } @@ -966,3 +965,24 @@ func TestSafeConcurrency(t *testing.T) { wg.Wait() }) } + +func TestCheckLimit(t *testing.T) { + low, hi := 1, 2 + cm, err := NewConnManager(low, hi) + require.NoError(t, err) + + err = cm.CheckLimit(testLimitGetter{hi + 1}) + require.NoError(t, err) + err = cm.CheckLimit(testLimitGetter{hi}) + require.NoError(t, err) + err = cm.CheckLimit(testLimitGetter{hi - 1}) + require.Error(t, err) +} + +type testLimitGetter struct { + limit int +} + +func (g testLimitGetter) GetConnLimit() int { + return g.limit +} diff --git a/go-libp2p/p2p/net/connmgr/decay.go b/go-libp2p/p2p/net/connmgr/decay.go index bdac0be..76f1c68 100644 --- a/go-libp2p/p2p/net/connmgr/decay.go +++ b/go-libp2p/p2p/net/connmgr/decay.go @@ -320,7 +320,7 @@ func (t *decayingTag) Bump(p peer.ID, delta int) error { default: return fmt.Errorf( "unable to bump decaying tag for peer %s, tag %s, delta %d; queue full (len=%d)", - p.Pretty(), t.name, delta, len(t.trkr.bumpTagCh)) + p, t.name, delta, len(t.trkr.bumpTagCh)) } } @@ -337,7 +337,7 @@ func (t *decayingTag) Remove(p peer.ID) error { default: return fmt.Errorf( "unable to remove decaying tag for peer %s, tag %s; queue full (len=%d)", - p.Pretty(), t.name, len(t.trkr.removeTagCh)) + p, t.name, len(t.trkr.removeTagCh)) } } diff --git a/go-libp2p/p2p/net/connmgr/decay_test.go b/go-libp2p/p2p/net/connmgr/decay_test.go index e6844f1..d51ca29 100644 --- a/go-libp2p/p2p/net/connmgr/decay_test.go +++ b/go-libp2p/p2p/net/connmgr/decay_test.go @@ -49,7 +49,7 @@ func TestMultipleBumps(t *testing.T) { require.NoError(t, tag.Bump(id, 5)) waitForTag(t, mgr, id) - require.Equal(t, mgr.GetTagInfo(id).Value, 10) + require.Equal(t, 10, mgr.GetTagInfo(id).Value) require.NoError(t, tag.Bump(id, 100)) require.Eventually(t, func() bool { return mgr.GetTagInfo(id).Value == 20 }, 100*time.Millisecond, 10*time.Millisecond, "expected tag value to decay to 20") @@ -77,7 +77,7 @@ func TestMultipleTagsNoDecay(t *testing.T) { // all tags are upper-bounded, so the score must be 300 ti := mgr.GetTagInfo(id) - require.Equal(t, ti.Value, 300) + require.Equal(t, 300, ti.Value) for _, s := range []string{"beep", "bop", "foo"} { if v, ok := ti.Tags[s]; !ok || v != 100 { diff --git a/go-libp2p/p2p/net/gostream/addr.go b/go-libp2p/p2p/net/gostream/addr.go new file mode 100644 index 0000000..49d844f --- /dev/null +++ b/go-libp2p/p2p/net/gostream/addr.go @@ -0,0 +1,14 @@ +package gostream + +import "github.com/libp2p/go-libp2p/core/peer" + +// addr implements net.Addr and holds a libp2p peer ID. +type addr struct{ id peer.ID } + +// Network returns the name of the network that this address belongs to +// (libp2p). +func (a *addr) Network() string { return Network } + +// String returns the peer ID of this address in string form +// (B58-encoded). +func (a *addr) String() string { return a.id.String() } diff --git a/go-libp2p/p2p/net/gostream/conn.go b/go-libp2p/p2p/net/gostream/conn.go new file mode 100644 index 0000000..991dd2f --- /dev/null +++ b/go-libp2p/p2p/net/gostream/conn.go @@ -0,0 +1,43 @@ +package gostream + +import ( + "context" + "net" + + "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/protocol" +) + +// conn is an implementation of net.Conn which wraps +// libp2p streams. +type conn struct { + network.Stream +} + +// newConn creates a conn given a libp2p stream +func newConn(s network.Stream) net.Conn { + return &conn{s} +} + +// LocalAddr returns the local network address. +func (c *conn) LocalAddr() net.Addr { + return &addr{c.Stream.Conn().LocalPeer()} +} + +// RemoteAddr returns the remote network address. +func (c *conn) RemoteAddr() net.Addr { + return &addr{c.Stream.Conn().RemotePeer()} +} + +// Dial opens a stream to the destination address +// (which should parseable to a peer ID) using the given +// host and returns it as a standard net.Conn. +func Dial(ctx context.Context, h host.Host, pid peer.ID, tag protocol.ID) (net.Conn, error) { + s, err := h.NewStream(ctx, pid, tag) + if err != nil { + return nil, err + } + return newConn(s), nil +} diff --git a/go-libp2p/p2p/net/gostream/gostream.go b/go-libp2p/p2p/net/gostream/gostream.go new file mode 100644 index 0000000..a15125b --- /dev/null +++ b/go-libp2p/p2p/net/gostream/gostream.go @@ -0,0 +1,19 @@ +// Package gostream allows to replace the standard net stack in Go +// with [LibP2P](https://github.com/libp2p/libp2p) streams. +// +// Given a libp2p.Host, gostream provides Dial() and Listen() methods which +// return implementations of net.Conn and net.Listener. +// +// Instead of the regular "host:port" addressing, `gostream` uses a Peer ID, +// and rather than a raw TCP connection, gostream will use libp2p's net.Stream. +// This means your connections will take advantage of LibP2P's multi-routes, +// NAT transversal and stream multiplexing. +// +// Note that LibP2P hosts cannot dial to themselves, so there is no possibility +// of using the same Host as server and as client. +package gostream + +// Network is the "net.Addr.Network()" name returned by +// addresses used by gostream connections. In turn, the "net.Addr.String()" will +// be a peer ID. +var Network = "libp2p" diff --git a/go-libp2p/p2p/net/gostream/gostream_test.go b/go-libp2p/p2p/net/gostream/gostream_test.go new file mode 100644 index 0000000..c024cab --- /dev/null +++ b/go-libp2p/p2p/net/gostream/gostream_test.go @@ -0,0 +1,141 @@ +package gostream + +import ( + "bufio" + "context" + "io" + "testing" + "time" + + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/peerstore" + "github.com/libp2p/go-libp2p/core/protocol" + "github.com/multiformats/go-multiaddr" +) + +// newHost illustrates how to build a libp2p host with secio using +// a randomly generated key-pair +func newHost(t *testing.T, listen multiaddr.Multiaddr) host.Host { + h, err := libp2p.New( + libp2p.ListenAddrs(listen), + ) + if err != nil { + t.Fatal(err) + } + return h +} + +func TestServerClient(t *testing.T) { + m1, _ := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/10000") + m2, _ := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/10001") + srvHost := newHost(t, m1) + clientHost := newHost(t, m2) + defer srvHost.Close() + defer clientHost.Close() + + srvHost.Peerstore().AddAddrs(clientHost.ID(), clientHost.Addrs(), peerstore.PermanentAddrTTL) + clientHost.Peerstore().AddAddrs(srvHost.ID(), srvHost.Addrs(), peerstore.PermanentAddrTTL) + + var tag protocol.ID = "/testitytest" + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + done := make(chan struct{}) + go func() { + defer close(done) + listener, err := Listen(srvHost, tag) + if err != nil { + t.Error(err) + return + } + defer listener.Close() + + if listener.Addr().String() != srvHost.ID().String() { + t.Error("bad listener address") + return + } + + servConn, err := listener.Accept() + if err != nil { + t.Error(err) + return + } + defer servConn.Close() + + reader := bufio.NewReader(servConn) + for { + msg, err := reader.ReadString('\n') + if err == io.EOF { + break + } + if err != nil { + t.Error(err) + return + } + if msg != "is libp2p awesome?\n" { + t.Errorf("Bad incoming message: %s", msg) + return + } + + _, err = servConn.Write([]byte("yes it is\n")) + if err != nil { + t.Error(err) + return + } + } + }() + + clientConn, err := Dial(ctx, clientHost, srvHost.ID(), tag) + if err != nil { + t.Fatal(err) + } + + if clientConn.LocalAddr().String() != clientHost.ID().String() { + t.Fatal("Bad LocalAddr") + } + + if clientConn.RemoteAddr().String() != srvHost.ID().String() { + t.Fatal("Bad RemoteAddr") + } + + if clientConn.LocalAddr().Network() != Network { + t.Fatal("Bad Network()") + } + + err = clientConn.SetDeadline(time.Now().Add(time.Second)) + if err != nil { + t.Fatal(err) + } + + err = clientConn.SetReadDeadline(time.Now().Add(time.Second)) + if err != nil { + t.Fatal(err) + } + + err = clientConn.SetWriteDeadline(time.Now().Add(time.Second)) + if err != nil { + t.Fatal(err) + } + + _, err = clientConn.Write([]byte("is libp2p awesome?\n")) + if err != nil { + t.Fatal(err) + } + + reader := bufio.NewReader(clientConn) + resp, err := reader.ReadString('\n') + if err != nil { + t.Fatal(err) + } + + if resp != "yes it is\n" { + t.Errorf("Bad response: %s", resp) + } + + err = clientConn.Close() + if err != nil { + t.Fatal(err) + } + <-done +} diff --git a/go-libp2p/p2p/net/gostream/listener.go b/go-libp2p/p2p/net/gostream/listener.go new file mode 100644 index 0000000..250e688 --- /dev/null +++ b/go-libp2p/p2p/net/gostream/listener.go @@ -0,0 +1,71 @@ +package gostream + +import ( + "context" + "net" + + "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/protocol" +) + +// listener is an implementation of net.Listener which handles +// http-tagged streams from a libp2p connection. +// A listener can be built with Listen() +type listener struct { + host host.Host + ctx context.Context + tag protocol.ID + cancel func() + streamCh chan network.Stream +} + +// Accept returns the next a connection to this listener. +// It blocks if there are no connections. Under the hood, +// connections are libp2p streams. +func (l *listener) Accept() (net.Conn, error) { + select { + case s := <-l.streamCh: + return newConn(s), nil + case <-l.ctx.Done(): + return nil, l.ctx.Err() + } +} + +// Close terminates this listener. It will no longer handle any +// incoming streams +func (l *listener) Close() error { + l.cancel() + l.host.RemoveStreamHandler(l.tag) + return nil +} + +// Addr returns the address for this listener, which is its libp2p Peer ID. +func (l *listener) Addr() net.Addr { + return &addr{l.host.ID()} +} + +// Listen provides a standard net.Listener ready to accept "connections". +// Under the hood, these connections are libp2p streams tagged with the +// given protocol.ID. +func Listen(h host.Host, tag protocol.ID) (net.Listener, error) { + ctx, cancel := context.WithCancel(context.Background()) + + l := &listener{ + host: h, + ctx: ctx, + cancel: cancel, + tag: tag, + streamCh: make(chan network.Stream), + } + + h.SetStreamHandler(tag, func(s network.Stream) { + select { + case l.streamCh <- s: + case <-ctx.Done(): + s.Reset() + } + }) + + return l, nil +} diff --git a/go-libp2p/p2p/net/mock/mock_test.go b/go-libp2p/p2p/net/mock/mock_test.go index 863e54f..aed1254 100644 --- a/go-libp2p/p2p/net/mock/mock_test.go +++ b/go-libp2p/p2p/net/mock/mock_test.go @@ -463,11 +463,11 @@ func TestRateLimiting(t *testing.T) { } rl.UpdateBandwidth(100) - if !within(rl.Limit(1), time.Duration(time.Millisecond*10), time.Millisecond) { + if !within(rl.Limit(1), time.Millisecond*10, time.Millisecond) { t.Fatal() } - if within(rl.Limit(1), time.Duration(time.Millisecond*10), time.Millisecond) { + if within(rl.Limit(1), time.Millisecond*10, time.Millisecond) { t.Fatal() } } diff --git a/go-libp2p/p2p/net/nat/mock_nat_test.go b/go-libp2p/p2p/net/nat/mock_nat_test.go index c7a151f..3e453f6 100644 --- a/go-libp2p/p2p/net/nat/mock_nat_test.go +++ b/go-libp2p/p2p/net/nat/mock_nat_test.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/libp2p/go-nat (interfaces: NAT) +// +// Generated by this command: +// +// mockgen -package nat -destination mock_nat_test.go github.com/libp2p/go-nat NAT +// // Package nat is a generated GoMock package. package nat @@ -10,7 +15,7 @@ import ( reflect "reflect" time "time" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockNAT is a mock of NAT interface. @@ -46,7 +51,7 @@ func (m *MockNAT) AddPortMapping(arg0 context.Context, arg1 string, arg2 int, ar } // AddPortMapping indicates an expected call of AddPortMapping. -func (mr *MockNATMockRecorder) AddPortMapping(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { +func (mr *MockNATMockRecorder) AddPortMapping(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddPortMapping", reflect.TypeOf((*MockNAT)(nil).AddPortMapping), arg0, arg1, arg2, arg3, arg4) } @@ -60,7 +65,7 @@ func (m *MockNAT) DeletePortMapping(arg0 context.Context, arg1 string, arg2 int) } // DeletePortMapping indicates an expected call of DeletePortMapping. -func (mr *MockNATMockRecorder) DeletePortMapping(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockNATMockRecorder) DeletePortMapping(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeletePortMapping", reflect.TypeOf((*MockNAT)(nil).DeletePortMapping), arg0, arg1, arg2) } diff --git a/go-libp2p/p2p/net/nat/nat_test.go b/go-libp2p/p2p/net/nat/nat_test.go index ea47edc..50e1eb3 100644 --- a/go-libp2p/p2p/net/nat/nat_test.go +++ b/go-libp2p/p2p/net/nat/nat_test.go @@ -9,11 +9,11 @@ import ( "github.com/libp2p/go-nat" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) -//go:generate sh -c "go run github.com/golang/mock/mockgen -package nat -destination mock_nat_test.go github.com/libp2p/go-nat NAT" +//go:generate sh -c "go run go.uber.org/mock/mockgen -package nat -destination mock_nat_test.go github.com/libp2p/go-nat NAT" func setupMockNAT(t *testing.T) (mockNAT *MockNAT, reset func()) { t.Helper() diff --git a/go-libp2p/p2p/net/reuseport/dialer.go b/go-libp2p/p2p/net/reuseport/dialer.go index 2efc02d..ec3769a 100644 --- a/go-libp2p/p2p/net/reuseport/dialer.go +++ b/go-libp2p/p2p/net/reuseport/dialer.go @@ -33,7 +33,7 @@ func randAddr(addrs []*net.TCPAddr) *net.TCPAddr { // // In-order: // -// 1. If we're _explicitly_ listening on the prefered source address for the destination address +// 1. If we're _explicitly_ listening on the preferred source address for the destination address // (per the system's routes), we'll use that listener's port as the source port. // 2. If we're listening on one or more _unspecified_ addresses (zero address), we'll pick a source // port from one of these listener's. diff --git a/go-libp2p/p2p/net/reuseport/transport_test.go b/go-libp2p/p2p/net/reuseport/transport_test.go index 88f9cdb..92ccf17 100644 --- a/go-libp2p/p2p/net/reuseport/transport_test.go +++ b/go-libp2p/p2p/net/reuseport/transport_test.go @@ -1,9 +1,11 @@ package reuseport import ( + "context" "net" "runtime" "testing" + "time" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" @@ -64,8 +66,11 @@ func acceptOne(t *testing.T, listener manet.Listener) <-chan manet.Conn { func dialOne(t *testing.T, tr *Transport, listener manet.Listener, expected ...int) int { t.Helper() + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + connChan := acceptOne(t, listener) - c, err := tr.Dial(listener.Multiaddr()) + c, err := tr.DialContext(ctx, listener.Multiaddr()) if err != nil { t.Fatal(err) } diff --git a/go-libp2p/p2p/net/swarm/addrs.go b/go-libp2p/p2p/net/swarm/addrs.go deleted file mode 100644 index 392900e..0000000 --- a/go-libp2p/p2p/net/swarm/addrs.go +++ /dev/null @@ -1,39 +0,0 @@ -package swarm - -import ( - ma "github.com/multiformats/go-multiaddr" - manet "github.com/multiformats/go-multiaddr/net" -) - -// http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml -var lowTimeoutFilters = ma.NewFilters() - -func init() { - for _, p := range []string{ - "/ip4/10.0.0.0/ipcidr/8", - "/ip4/100.64.0.0/ipcidr/10", - "/ip4/169.254.0.0/ipcidr/16", - "/ip4/172.16.0.0/ipcidr/12", - "/ip4/192.0.0.0/ipcidr/24", - "/ip4/192.0.0.0/ipcidr/29", - "/ip4/192.0.0.8/ipcidr/32", - "/ip4/192.0.0.170/ipcidr/32", - "/ip4/192.0.0.171/ipcidr/32", - "/ip4/192.0.2.0/ipcidr/24", - "/ip4/192.168.0.0/ipcidr/16", - "/ip4/198.18.0.0/ipcidr/15", - "/ip4/198.51.100.0/ipcidr/24", - "/ip4/203.0.113.0/ipcidr/24", - "/ip4/240.0.0.0/ipcidr/4", - } { - f, err := ma.NewMultiaddr(p) - if err != nil { - panic("error in lowTimeoutFilters init: " + err.Error()) - } - ipnet, err := manet.MultiaddrToIPNet(f) - if err != nil { - panic("error in lowTimeoutFilters init: " + err.Error()) - } - lowTimeoutFilters.AddFilter(*ipnet, ma.ActionDeny) - } -} diff --git a/go-libp2p/p2p/net/swarm/black_hole_detector.go b/go-libp2p/p2p/net/swarm/black_hole_detector.go index 078b112..dd7849e 100644 --- a/go-libp2p/p2p/net/swarm/black_hole_detector.go +++ b/go-libp2p/p2p/net/swarm/black_hole_detector.go @@ -178,7 +178,7 @@ type blackHoleDetector struct { } // FilterAddrs filters the peer's addresses removing black holed addresses -func (d *blackHoleDetector) FilterAddrs(addrs []ma.Multiaddr) []ma.Multiaddr { +func (d *blackHoleDetector) FilterAddrs(addrs []ma.Multiaddr) (valid []ma.Multiaddr, blackHoled []ma.Multiaddr) { hasUDP, hasIPv6 := false, false for _, a := range addrs { if !manet.IsPublicAddr(a) { @@ -202,6 +202,7 @@ func (d *blackHoleDetector) FilterAddrs(addrs []ma.Multiaddr) []ma.Multiaddr { ipv6Res = d.ipv6.HandleRequest() } + blackHoled = make([]ma.Multiaddr, 0, len(addrs)) return ma.FilterAddrs( addrs, func(a ma.Multiaddr) bool { @@ -218,14 +219,16 @@ func (d *blackHoleDetector) FilterAddrs(addrs []ma.Multiaddr) []ma.Multiaddr { } if udpRes == blackHoleResultBlocked && isProtocolAddr(a, ma.P_UDP) { + blackHoled = append(blackHoled, a) return false } if ipv6Res == blackHoleResultBlocked && isProtocolAddr(a, ma.P_IP6) { + blackHoled = append(blackHoled, a) return false } return true }, - ) + ), blackHoled } // RecordResult updates the state of the relevant `blackHoleFilter`s for addr diff --git a/go-libp2p/p2p/net/swarm/black_hole_detector_test.go b/go-libp2p/p2p/net/swarm/black_hole_detector_test.go index 7b10fc8..1ab2cbe 100644 --- a/go-libp2p/p2p/net/swarm/black_hole_detector_test.go +++ b/go-libp2p/p2p/net/swarm/black_hole_detector_test.go @@ -85,7 +85,7 @@ func TestBlackHoleDetectorInApplicableAddress(t *testing.T) { ma.StringCast("/ip4/192.168.1.5/udp/1234/quic-v1"), } for i := 0; i < 1000; i++ { - filteredAddrs := bhd.FilterAddrs(addrs) + filteredAddrs, _ := bhd.FilterAddrs(addrs) require.ElementsMatch(t, addrs, filteredAddrs) for j := 0; j < len(addrs); j++ { bhd.RecordResult(addrs[j], false) @@ -101,20 +101,29 @@ func TestBlackHoleDetectorUDPDisabled(t *testing.T) { for i := 0; i < 100; i++ { bhd.RecordResult(publicAddr, false) } - addrs := []ma.Multiaddr{publicAddr, privAddr} - require.ElementsMatch(t, addrs, bhd.FilterAddrs(addrs)) + wantAddrs := []ma.Multiaddr{publicAddr, privAddr} + wantRemovedAddrs := make([]ma.Multiaddr, 0) + + gotAddrs, gotRemovedAddrs := bhd.FilterAddrs(wantAddrs) + require.ElementsMatch(t, wantAddrs, gotAddrs) + require.ElementsMatch(t, wantRemovedAddrs, gotRemovedAddrs) } func TestBlackHoleDetectorIPv6Disabled(t *testing.T) { udpConfig := blackHoleConfig{Enabled: true, N: 10, MinSuccesses: 5} bhd := newBlackHoleDetector(udpConfig, blackHoleConfig{Enabled: false}, nil) - publicAddr := ma.StringCast("/ip6/1::1/tcp/1234") + publicAddr := ma.StringCast("/ip6/2001::1/tcp/1234") privAddr := ma.StringCast("/ip6/::1/tcp/1234") - addrs := []ma.Multiaddr{publicAddr, privAddr} for i := 0; i < 100; i++ { bhd.RecordResult(publicAddr, false) } - require.ElementsMatch(t, addrs, bhd.FilterAddrs(addrs)) + + wantAddrs := []ma.Multiaddr{publicAddr, privAddr} + wantRemovedAddrs := make([]ma.Multiaddr, 0) + + gotAddrs, gotRemovedAddrs := bhd.FilterAddrs(wantAddrs) + require.ElementsMatch(t, wantAddrs, gotAddrs) + require.ElementsMatch(t, wantRemovedAddrs, gotRemovedAddrs) } func TestBlackHoleDetectorProbes(t *testing.T) { @@ -122,13 +131,13 @@ func TestBlackHoleDetectorProbes(t *testing.T) { udp: &blackHoleFilter{n: 2, minSuccesses: 1, name: "udp"}, ipv6: &blackHoleFilter{n: 3, minSuccesses: 1, name: "ipv6"}, } - udp6Addr := ma.StringCast("/ip6/1::1/udp/1234/quic-v1") + udp6Addr := ma.StringCast("/ip6/2001::1/udp/1234/quic-v1") addrs := []ma.Multiaddr{udp6Addr} for i := 0; i < 3; i++ { bhd.RecordResult(udp6Addr, false) } for i := 1; i < 100; i++ { - filteredAddrs := bhd.FilterAddrs(addrs) + filteredAddrs, _ := bhd.FilterAddrs(addrs) if i%2 == 0 || i%3 == 0 { if len(filteredAddrs) == 0 { t.Fatalf("expected probe to be allowed irrespective of the state of other black hole filter") @@ -143,11 +152,11 @@ func TestBlackHoleDetectorProbes(t *testing.T) { } func TestBlackHoleDetectorAddrFiltering(t *testing.T) { - udp6Pub := ma.StringCast("/ip6/1::1/udp/1234/quic-v1") + udp6Pub := ma.StringCast("/ip6/2001::1/udp/1234/quic-v1") udp6Pri := ma.StringCast("/ip6/::1/udp/1234/quic-v1") - upd4Pub := ma.StringCast("/ip4/1.2.3.4/udp/1234/quic-v1") + udp4Pub := ma.StringCast("/ip4/1.2.3.4/udp/1234/quic-v1") udp4Pri := ma.StringCast("/ip4/192.168.1.5/udp/1234/quic-v1") - tcp6Pub := ma.StringCast("/ip6/1::1/tcp/1234/quic-v1") + tcp6Pub := ma.StringCast("/ip6/2001::1/tcp/1234/quic-v1") tcp6Pri := ma.StringCast("/ip6/::1/tcp/1234/quic-v1") tcp4Pub := ma.StringCast("/ip4/1.2.3.4/tcp/1234/quic-v1") tcp4Pri := ma.StringCast("/ip4/192.168.1.5/tcp/1234/quic-v1") @@ -158,7 +167,7 @@ func TestBlackHoleDetectorAddrFiltering(t *testing.T) { ipv6: &blackHoleFilter{n: 100, minSuccesses: 10, name: "ipv6"}, } for i := 0; i < 100; i++ { - bhd.RecordResult(upd4Pub, !udpBlocked) + bhd.RecordResult(udp4Pub, !udpBlocked) } for i := 0; i < 100; i++ { bhd.RecordResult(tcp6Pub, !ipv6Blocked) @@ -166,18 +175,27 @@ func TestBlackHoleDetectorAddrFiltering(t *testing.T) { return bhd } - allInput := []ma.Multiaddr{udp6Pub, udp6Pri, upd4Pub, udp4Pri, tcp6Pub, tcp6Pri, + allInput := []ma.Multiaddr{udp6Pub, udp6Pri, udp4Pub, udp4Pri, tcp6Pub, tcp6Pri, tcp4Pub, tcp4Pri} udpBlockedOutput := []ma.Multiaddr{udp6Pri, udp4Pri, tcp6Pub, tcp6Pri, tcp4Pub, tcp4Pri} + udpPublicAddrs := []ma.Multiaddr{udp6Pub, udp4Pub} bhd := makeBHD(true, false) - require.ElementsMatch(t, udpBlockedOutput, bhd.FilterAddrs(allInput)) + gotAddrs, gotRemovedAddrs := bhd.FilterAddrs(allInput) + require.ElementsMatch(t, udpBlockedOutput, gotAddrs) + require.ElementsMatch(t, udpPublicAddrs, gotRemovedAddrs) - ip6BlockedOutput := []ma.Multiaddr{udp6Pri, upd4Pub, udp4Pri, tcp6Pri, tcp4Pub, tcp4Pri} + ip6BlockedOutput := []ma.Multiaddr{udp6Pri, udp4Pub, udp4Pri, tcp6Pri, tcp4Pub, tcp4Pri} + ip6PublicAddrs := []ma.Multiaddr{udp6Pub, tcp6Pub} bhd = makeBHD(false, true) - require.ElementsMatch(t, ip6BlockedOutput, bhd.FilterAddrs(allInput)) + gotAddrs, gotRemovedAddrs = bhd.FilterAddrs(allInput) + require.ElementsMatch(t, ip6BlockedOutput, gotAddrs) + require.ElementsMatch(t, ip6PublicAddrs, gotRemovedAddrs) bothBlockedOutput := []ma.Multiaddr{udp6Pri, udp4Pri, tcp6Pri, tcp4Pub, tcp4Pri} + bothPublicAddrs := []ma.Multiaddr{udp6Pub, tcp6Pub, udp4Pub} bhd = makeBHD(true, true) - require.ElementsMatch(t, bothBlockedOutput, bhd.FilterAddrs(allInput)) + gotAddrs, gotRemovedAddrs = bhd.FilterAddrs(allInput) + require.ElementsMatch(t, bothBlockedOutput, gotAddrs) + require.ElementsMatch(t, bothPublicAddrs, gotRemovedAddrs) } diff --git a/go-libp2p/p2p/net/swarm/connectedness_event_emitter.go b/go-libp2p/p2p/net/swarm/connectedness_event_emitter.go new file mode 100644 index 0000000..07db583 --- /dev/null +++ b/go-libp2p/p2p/net/swarm/connectedness_event_emitter.go @@ -0,0 +1,143 @@ +package swarm + +import ( + "context" + "sync" + + "github.com/libp2p/go-libp2p/core/event" + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" +) + +// connectednessEventEmitter emits PeerConnectednessChanged events. +// We ensure that for any peer we connected to we always sent atleast 1 NotConnected Event after +// the peer disconnects. This is because peers can observe a connection before they are notified +// of the connection by a peer connectedness changed event. +type connectednessEventEmitter struct { + mx sync.RWMutex + // newConns is the channel that holds the peerIDs we recently connected to + newConns chan peer.ID + removeConnsMx sync.Mutex + // removeConns is a slice of peerIDs we have recently closed connections to + removeConns []peer.ID + // lastEvent is the last connectedness event sent for a particular peer. + lastEvent map[peer.ID]network.Connectedness + // connectedness is the function that gives the peers current connectedness state + connectedness func(peer.ID) network.Connectedness + // emitter is the PeerConnectednessChanged event emitter + emitter event.Emitter + wg sync.WaitGroup + removeConnNotif chan struct{} + ctx context.Context + cancel context.CancelFunc +} + +func newConnectednessEventEmitter(connectedness func(peer.ID) network.Connectedness, emitter event.Emitter) *connectednessEventEmitter { + ctx, cancel := context.WithCancel(context.Background()) + c := &connectednessEventEmitter{ + newConns: make(chan peer.ID, 32), + lastEvent: make(map[peer.ID]network.Connectedness), + removeConnNotif: make(chan struct{}, 1), + connectedness: connectedness, + emitter: emitter, + ctx: ctx, + cancel: cancel, + } + c.wg.Add(1) + go c.runEmitter() + return c +} + +func (c *connectednessEventEmitter) AddConn(p peer.ID) { + c.mx.RLock() + defer c.mx.RUnlock() + if c.ctx.Err() != nil { + return + } + + c.newConns <- p +} + +func (c *connectednessEventEmitter) RemoveConn(p peer.ID) { + c.mx.RLock() + defer c.mx.RUnlock() + if c.ctx.Err() != nil { + return + } + + c.removeConnsMx.Lock() + // This queue is roughly bounded by the total number of added connections we + // have. If consumers of connectedness events are slow, we apply + // backpressure to AddConn operations. + // + // We purposefully don't block/backpressure here to avoid deadlocks, since it's + // reasonable for a consumer of the event to want to remove a connection. + c.removeConns = append(c.removeConns, p) + + c.removeConnsMx.Unlock() + + select { + case c.removeConnNotif <- struct{}{}: + default: + } +} + +func (c *connectednessEventEmitter) Close() { + c.cancel() + c.wg.Wait() +} + +func (c *connectednessEventEmitter) runEmitter() { + defer c.wg.Done() + for { + select { + case p := <-c.newConns: + c.notifyPeer(p, true) + case <-c.removeConnNotif: + c.sendConnRemovedNotifications() + case <-c.ctx.Done(): + c.mx.Lock() // Wait for all pending AddConn & RemoveConn operations to complete + defer c.mx.Unlock() + for { + select { + case p := <-c.newConns: + c.notifyPeer(p, true) + case <-c.removeConnNotif: + c.sendConnRemovedNotifications() + default: + return + } + } + } + } +} + +// notifyPeer sends the peer connectedness event using the emitter. +// Use forceNotConnectedEvent = true to send a NotConnected event even if +// no Connected event was sent for this peer. +// In case a peer is disconnected before we sent the Connected event, we still +// send the Disconnected event because a connection to the peer can be observed +// in such cases. +func (c *connectednessEventEmitter) notifyPeer(p peer.ID, forceNotConnectedEvent bool) { + oldState := c.lastEvent[p] + c.lastEvent[p] = c.connectedness(p) + if c.lastEvent[p] == network.NotConnected { + delete(c.lastEvent, p) + } + if (forceNotConnectedEvent && c.lastEvent[p] == network.NotConnected) || c.lastEvent[p] != oldState { + c.emitter.Emit(event.EvtPeerConnectednessChanged{ + Peer: p, + Connectedness: c.lastEvent[p], + }) + } +} + +func (c *connectednessEventEmitter) sendConnRemovedNotifications() { + c.removeConnsMx.Lock() + removeConns := c.removeConns + c.removeConns = nil + c.removeConnsMx.Unlock() + for _, p := range removeConns { + c.notifyPeer(p, false) + } +} diff --git a/go-libp2p/p2p/net/swarm/dial_error.go b/go-libp2p/p2p/net/swarm/dial_error.go index 711ee06..4de6822 100644 --- a/go-libp2p/p2p/net/swarm/dial_error.go +++ b/go-libp2p/p2p/net/swarm/dial_error.go @@ -30,10 +30,7 @@ func (e *DialError) recordErr(addr ma.Multiaddr, err error) { e.Skipped++ return } - e.DialErrors = append(e.DialErrors, TransportError{ - Address: addr, - Cause: err, - }) + e.DialErrors = append(e.DialErrors, TransportError{Address: addr, Cause: err}) } func (e *DialError) Error() string { @@ -51,9 +48,19 @@ func (e *DialError) Error() string { return builder.String() } -// Unwrap implements https://godoc.org/golang.org/x/xerrors#Wrapper. -func (e *DialError) Unwrap() error { - return e.Cause +func (e *DialError) Unwrap() []error { + if e == nil { + return nil + } + + errs := make([]error, len(e.DialErrors)+1) + if e.Cause != nil { + errs = append(errs, e.Cause) + } + for i := 0; i < len(e.DialErrors); i++ { + errs = append(errs, &e.DialErrors[i]) + } + return errs } var _ error = (*DialError)(nil) @@ -68,4 +75,8 @@ func (e *TransportError) Error() string { return fmt.Sprintf("failed to dial %s: %s", e.Address, e.Cause) } +func (e *TransportError) Unwrap() error { + return e.Cause +} + var _ error = (*TransportError)(nil) diff --git a/go-libp2p/p2p/net/swarm/dial_error_test.go b/go-libp2p/p2p/net/swarm/dial_error_test.go new file mode 100644 index 0000000..3231d6f --- /dev/null +++ b/go-libp2p/p2p/net/swarm/dial_error_test.go @@ -0,0 +1,51 @@ +package swarm + +import ( + "net" + "os" + "testing" + + ma "github.com/multiformats/go-multiaddr" + "github.com/stretchr/testify/require" +) + +func TestTransportError(t *testing.T) { + aa := ma.StringCast("/ip4/1.2.3.4/tcp/1234") + te := &TransportError{Address: aa, Cause: ErrDialBackoff} + require.ErrorIs(t, te, ErrDialBackoff, "TransportError should implement Unwrap") +} + +func TestDialError(t *testing.T) { + de := &DialError{Peer: "pid", Cause: ErrGaterDisallowedConnection} + require.ErrorIs(t, de, ErrGaterDisallowedConnection, + "DialError Unwrap should handle DialError.Cause") + require.ErrorIs(t, de, de, "DialError Unwrap should handle match to self") + + aa := ma.StringCast("/ip4/1.2.3.4/tcp/1234") + ab := ma.StringCast("/ip6/1::1/udp/1234/quic-v1") + de = &DialError{ + Peer: "pid", + DialErrors: []TransportError{ + {Address: aa, Cause: ErrDialBackoff}, {Address: ab, Cause: ErrNoTransport}, + }, + } + require.ErrorIs(t, de, ErrDialBackoff, "DialError.Unwrap should traverse TransportErrors") + require.ErrorIs(t, de, ErrNoTransport, "DialError.Unwrap should traverse TransportErrors") + + de = &DialError{ + Peer: "pid", + DialErrors: []TransportError{{Address: ab, Cause: ErrNoTransport}, + // wrapped error 2 levels deep + {Address: aa, Cause: &net.OpError{ + Op: "write", + Net: "tcp", + Err: &os.SyscallError{ + Syscall: "connect", + Err: os.ErrPermission, + }, + }}, + }, + } + require.ErrorIs(t, de, os.ErrPermission, "DialError.Unwrap should traverse TransportErrors") + +} diff --git a/go-libp2p/p2p/net/swarm/dial_ranker.go b/go-libp2p/p2p/net/swarm/dial_ranker.go index 3725884..7e58876 100644 --- a/go-libp2p/p2p/net/swarm/dial_ranker.go +++ b/go-libp2p/p2p/net/swarm/dial_ranker.go @@ -58,8 +58,19 @@ func NoDelayDialRanker(addrs []ma.Multiaddr) []network.AddrDelay { // 3. If a QUIC or WebTransport address is present, TCP addresses dials are delayed relative to the last QUIC dial: // We prefer to end up with a QUIC connection. For public addresses, the delay introduced is 250ms (PublicTCPDelay), // and for private addresses 30ms (PrivateTCPDelay). +// 4. For the TCP addresses we follow a strategy similar to QUIC with an optimisation for handling the long TCP +// handshake time described in 6. If both IPv6 TCP and IPv4 TCP addresses are present, we do a Happy Eyeballs +// style ranking. First dial the IPv6 TCP address with the lowest port. After this, dial the IPv4 TCP address +// with the lowest port delayed by 250ms (PublicTCPDelay) for public addresses, and 30ms (PrivateTCPDelay) +// for local addresses. After this we dial all the rest of the addresses delayed by 250ms (PublicTCPDelay) for +// public addresses, and 30ms (PrivateTCPDelay) for local addresses. +// 5. If only one of TCP IPv6 or TCP IPv4 addresses are present, dial the TCP address with the lowest port +// first. After this we dial the rest of the TCP addresses delayed by 250ms (PublicTCPDelay) for public +// addresses, and 30ms (PrivateTCPDelay) for local addresses. +// 6. When a TCP socket is connected and awaiting security and muxer upgrade, we stop new dials for 2*PrivateTCPDelay +// to allow for the upgrade to complete. // -// We dial lowest ports first for QUIC addresses as they are more likely to be the listen port. +// We dial lowest ports first as they are more likely to be the listen port. func DefaultDialRanker(addrs []ma.Multiaddr) []network.AddrDelay { relay, addrs := filterAddrs(addrs, isRelayAddr) pvt, addrs := filterAddrs(addrs, manet.IsPrivateAddr) @@ -88,22 +99,57 @@ func DefaultDialRanker(addrs []ma.Multiaddr) []network.AddrDelay { // addresses relative to direct addresses. func getAddrDelay(addrs []ma.Multiaddr, tcpDelay time.Duration, quicDelay time.Duration, offset time.Duration) []network.AddrDelay { + if len(addrs) == 0 { + return nil + } sort.Slice(addrs, func(i, j int) bool { return score(addrs[i]) < score(addrs[j]) }) - // If the first address is (QUIC, IPv6), make the second address (QUIC, IPv4). - happyEyeballs := false - if len(addrs) > 0 { + // addrs is now sorted by (Transport, IPVersion). Reorder addrs for happy eyeballs dialing. + // For QUIC and TCP, if we have both IPv6 and IPv4 addresses, move the + // highest priority IPv4 address to the second position. + happyEyeballsQUIC := false + happyEyeballsTCP := false + // tcpStartIdx is the index of the first TCP Address + var tcpStartIdx int + { + i := 0 + // If the first QUIC address is IPv6 move the first QUIC IPv4 address to second position if isQUICAddr(addrs[0]) && isProtocolAddr(addrs[0], ma.P_IP6) { - for i := 1; i < len(addrs); i++ { - if isQUICAddr(addrs[i]) && isProtocolAddr(addrs[i], ma.P_IP4) { - // make IPv4 address the second element - if i > 1 { - a := addrs[i] - copy(addrs[2:], addrs[1:i]) + for j := 1; j < len(addrs); j++ { + if isQUICAddr(addrs[j]) && isProtocolAddr(addrs[j], ma.P_IP4) { + // The first IPv4 address is at position j + // Move the jth element at position 1 shifting the affected elements + if j > 1 { + a := addrs[j] + copy(addrs[2:], addrs[1:j]) addrs[1] = a } - happyEyeballs = true + happyEyeballsQUIC = true + i = j + 1 + break + } + } + } + + for tcpStartIdx = i; tcpStartIdx < len(addrs); tcpStartIdx++ { + if isProtocolAddr(addrs[tcpStartIdx], ma.P_TCP) { + break + } + } + + // If the first TCP address is IPv6 move the first TCP IPv4 address to second position + if tcpStartIdx < len(addrs) && isProtocolAddr(addrs[tcpStartIdx], ma.P_IP6) { + for j := tcpStartIdx + 1; j < len(addrs); j++ { + if isProtocolAddr(addrs[j], ma.P_TCP) && isProtocolAddr(addrs[j], ma.P_IP4) { + // First TCP IPv4 address is at position j, move it to position tcpStartIdx+1 + // which is the second priority TCP address + if j > tcpStartIdx+1 { + a := addrs[j] + copy(addrs[tcpStartIdx+2:], addrs[tcpStartIdx+1:j]) + addrs[tcpStartIdx+1] = a + } + happyEyeballsTCP = true break } } @@ -111,25 +157,42 @@ func getAddrDelay(addrs []ma.Multiaddr, tcpDelay time.Duration, quicDelay time.D } res := make([]network.AddrDelay, 0, len(addrs)) - - var totalTCPDelay time.Duration + var tcpFirstDialDelay time.Duration for i, addr := range addrs { var delay time.Duration switch { case isQUICAddr(addr): - // For QUIC addresses we dial an IPv6 address, then after quicDelay an IPv4 - // address, then after quicDelay we dial rest of the addresses. + // We dial an IPv6 address, then after quicDelay an IPv4 + // address, then after a further quicDelay we dial the rest of the addresses. if i == 1 { delay = quicDelay } - if i > 1 && happyEyeballs { - delay = 2 * quicDelay - } else if i > 1 { - delay = quicDelay + if i > 1 { + // If we have happy eyeballs for QUIC, dials after the second position + // will be delayed by 2*quicDelay + if happyEyeballsQUIC { + delay = 2 * quicDelay + } else { + delay = quicDelay + } } - totalTCPDelay = delay + tcpDelay + tcpFirstDialDelay = delay + tcpDelay case isProtocolAddr(addr, ma.P_TCP): - delay = totalTCPDelay + // We dial an IPv6 address, then after tcpDelay an IPv4 + // address, then after a further tcpDelay we dial the rest of the addresses. + if i == tcpStartIdx+1 { + delay = tcpDelay + } + if i > tcpStartIdx+1 { + // If we have happy eyeballs for TCP, dials after the second position + // will be delayed by 2*tcpDelay + if happyEyeballsTCP { + delay = 2 * tcpDelay + } else { + delay = tcpDelay + } + } + delay += tcpFirstDialDelay } res = append(res, network.AddrDelay{Addr: addr, Delay: offset + delay}) } diff --git a/go-libp2p/p2p/net/swarm/dial_ranker_test.go b/go-libp2p/p2p/net/swarm/dial_ranker_test.go index 60fbfab..5ef3cc2 100644 --- a/go-libp2p/p2p/net/swarm/dial_ranker_test.go +++ b/go-libp2p/p2p/net/swarm/dial_ranker_test.go @@ -20,14 +20,14 @@ func sortAddrDelays(addrDelays []network.AddrDelay) { } func TestNoDelayDialRanker(t *testing.T) { - q1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic") + q1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1") q1v1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1") wt1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1/webtransport/") - q2 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic") + q2 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic-v1") q2v1 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic-v1") - q3 := ma.StringCast("/ip4/1.2.3.4/udp/3/quic") + q3 := ma.StringCast("/ip4/1.2.3.4/udp/3/quic-v1") q3v1 := ma.StringCast("/ip4/1.2.3.4/udp/3/quic-v1") - q4 := ma.StringCast("/ip4/1.2.3.4/udp/4/quic") + q4 := ma.StringCast("/ip4/1.2.3.4/udp/4/quic-v1") t1 := ma.StringCast("/ip4/1.2.3.5/tcp/1/") testCase := []struct { @@ -70,14 +70,10 @@ func TestNoDelayDialRanker(t *testing.T) { } func TestDelayRankerQUICDelay(t *testing.T) { - q1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic") q1v1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1") wt1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1/webtransport/") - q2 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic") q2v1 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic-v1") - q3 := ma.StringCast("/ip4/1.2.3.4/udp/3/quic") q3v1 := ma.StringCast("/ip4/1.2.3.4/udp/3/quic-v1") - q4 := ma.StringCast("/ip4/1.2.3.4/udp/4/quic") q1v16 := ma.StringCast("/ip6/1::2/udp/1/quic-v1") q2v16 := ma.StringCast("/ip6/1::2/udp/2/quic-v1") @@ -90,12 +86,11 @@ func TestDelayRankerQUICDelay(t *testing.T) { }{ { name: "quic-ipv4", - addrs: []ma.Multiaddr{q1, q2, q3, q4}, + addrs: []ma.Multiaddr{q1v1, q2v1, q3v1}, output: []network.AddrDelay{ - {Addr: q1, Delay: 0}, - {Addr: q2, Delay: PublicQUICDelay}, - {Addr: q3, Delay: PublicQUICDelay}, - {Addr: q4, Delay: PublicQUICDelay}, + {Addr: q1v1, Delay: 0}, + {Addr: q2v1, Delay: PublicQUICDelay}, + {Addr: q3v1, Delay: PublicQUICDelay}, }, }, { @@ -109,37 +104,29 @@ func TestDelayRankerQUICDelay(t *testing.T) { }, { name: "quic-ip4-ip6", - addrs: []ma.Multiaddr{q1, q1v16, q2v1, q3, q4}, + addrs: []ma.Multiaddr{q1v16, q2v1}, output: []network.AddrDelay{ {Addr: q1v16, Delay: 0}, {Addr: q2v1, Delay: PublicQUICDelay}, - {Addr: q1, Delay: 2 * PublicQUICDelay}, - {Addr: q3, Delay: 2 * PublicQUICDelay}, - {Addr: q4, Delay: 2 * PublicQUICDelay}, }, }, { name: "quic-quic-v1-webtransport", - addrs: []ma.Multiaddr{q1v16, q1, q2, q3, q4, q1v1, q2v1, q3v1, wt1}, + addrs: []ma.Multiaddr{q1v16, q1v1, q2v1, q3v1, wt1}, output: []network.AddrDelay{ {Addr: q1v16, Delay: 0}, {Addr: q1v1, Delay: PublicQUICDelay}, {Addr: q2v1, Delay: 2 * PublicQUICDelay}, {Addr: q3v1, Delay: 2 * PublicQUICDelay}, - {Addr: q1, Delay: 2 * PublicQUICDelay}, - {Addr: q2, Delay: 2 * PublicQUICDelay}, - {Addr: q3, Delay: 2 * PublicQUICDelay}, - {Addr: q4, Delay: 2 * PublicQUICDelay}, {Addr: wt1, Delay: 2 * PublicQUICDelay}, }, }, { name: "wt-ranking", - addrs: []ma.Multiaddr{q1v16, q2v16, q3v16, q2, wt1}, + addrs: []ma.Multiaddr{q1v16, q2v16, q3v16, wt1}, output: []network.AddrDelay{ {Addr: q1v16, Delay: 0}, - {Addr: q2, Delay: PublicQUICDelay}, - {Addr: wt1, Delay: 2 * PublicQUICDelay}, + {Addr: wt1, Delay: PublicQUICDelay}, {Addr: q2v16, Delay: 2 * PublicQUICDelay}, {Addr: q3v16, Delay: 2 * PublicQUICDelay}, }, @@ -164,11 +151,8 @@ func TestDelayRankerQUICDelay(t *testing.T) { } func TestDelayRankerTCPDelay(t *testing.T) { - q1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic") q1v1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1") - q2 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic") q2v1 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic-v1") - q3 := ma.StringCast("/ip4/1.2.3.4/udp/3/quic") q1v16 := ma.StringCast("/ip6/1::2/udp/1/quic-v1") q2v16 := ma.StringCast("/ip6/1::2/udp/2/quic-v1") @@ -177,6 +161,7 @@ func TestDelayRankerTCPDelay(t *testing.T) { t1 := ma.StringCast("/ip4/1.2.3.5/tcp/1/") t1v6 := ma.StringCast("/ip6/1::2/tcp/1") t2 := ma.StringCast("/ip4/1.2.3.4/tcp/2") + t3 := ma.StringCast("/ip4/1.2.3.4/tcp/3") testCase := []struct { name string @@ -185,39 +170,63 @@ func TestDelayRankerTCPDelay(t *testing.T) { }{ { name: "quic-with-tcp-ip6-ip4", - addrs: []ma.Multiaddr{q1, q1v1, q1v16, q2v16, q3v16, q2v1, t1, t2}, + addrs: []ma.Multiaddr{q1v1, q1v16, q2v16, q3v16, q2v1, t1, t1v6, t2, t3}, output: []network.AddrDelay{ {Addr: q1v16, Delay: 0}, {Addr: q1v1, Delay: PublicQUICDelay}, - {Addr: q1, Delay: 2 * PublicQUICDelay}, {Addr: q2v16, Delay: 2 * PublicQUICDelay}, {Addr: q3v16, Delay: 2 * PublicQUICDelay}, {Addr: q2v1, Delay: 2 * PublicQUICDelay}, - {Addr: t1, Delay: 3 * PublicQUICDelay}, - {Addr: t2, Delay: 3 * PublicQUICDelay}, + {Addr: t1v6, Delay: 3 * PublicQUICDelay}, + {Addr: t1, Delay: 4 * PublicQUICDelay}, + {Addr: t2, Delay: 5 * PublicQUICDelay}, + {Addr: t3, Delay: 5 * PublicQUICDelay}, }, }, { name: "quic-ip4-with-tcp", - addrs: []ma.Multiaddr{q1, q2, q3, t1, t2, t1v6}, + addrs: []ma.Multiaddr{q1v1, t2, t1v6, t1}, output: []network.AddrDelay{ - {Addr: q1, Delay: 0}, - {Addr: q2, Delay: PublicQUICDelay}, - {Addr: q3, Delay: PublicQUICDelay}, - {Addr: t1, Delay: PublicQUICDelay + PublicTCPDelay}, - {Addr: t2, Delay: PublicQUICDelay + PublicTCPDelay}, - {Addr: t1v6, Delay: PublicQUICDelay + PublicTCPDelay}, + {Addr: q1v1, Delay: 0}, + {Addr: t1v6, Delay: PublicQUICDelay}, + {Addr: t1, Delay: 2 * PublicQUICDelay}, + {Addr: t2, Delay: 3 * PublicQUICDelay}, + }, + }, + { + name: "quic-ip4-with-tcp-ipv4", + addrs: []ma.Multiaddr{q1v1, t2, t3, t1}, + output: []network.AddrDelay{ + {Addr: q1v1, Delay: 0}, + {Addr: t1, Delay: PublicTCPDelay}, + {Addr: t2, Delay: 2 * PublicQUICDelay}, + {Addr: t3, Delay: 2 * PublicTCPDelay}, + }, + }, + { + name: "quic-ip4-with-two-tcp", + addrs: []ma.Multiaddr{q1v1, t1v6, t2}, + output: []network.AddrDelay{ + {Addr: q1v1, Delay: 0}, + {Addr: t1v6, Delay: PublicTCPDelay}, + {Addr: t2, Delay: 2 * PublicTCPDelay}, }, }, { name: "tcp-ip4-ip6", - addrs: []ma.Multiaddr{t1, t2, t1v6}, + addrs: []ma.Multiaddr{t1, t2, t1v6, t3}, output: []network.AddrDelay{ {Addr: t1v6, Delay: 0}, - {Addr: t1, Delay: 0}, - {Addr: t2, Delay: 0}, + {Addr: t1, Delay: PublicTCPDelay}, + {Addr: t2, Delay: 2 * PublicTCPDelay}, + {Addr: t3, Delay: 2 * PublicTCPDelay}, }, }, + { + name: "empty", + addrs: []ma.Multiaddr{}, + output: []network.AddrDelay{}, + }, } for _, tc := range testCase { t.Run(tc.name, func(t *testing.T) { @@ -238,8 +247,8 @@ func TestDelayRankerTCPDelay(t *testing.T) { } func TestDelayRankerRelay(t *testing.T) { - q1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic") - q2 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic") + q1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1") + q2 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic-v1") pid := test.RandPeerIDFatal(t) r1 := ma.StringCast(fmt.Sprintf("/ip4/1.2.3.4/tcp/1/p2p-circuit/p2p/%s", pid)) diff --git a/go-libp2p/p2p/net/swarm/dial_sync.go b/go-libp2p/p2p/net/swarm/dial_sync.go index 2a8ff43..3cc8547 100644 --- a/go-libp2p/p2p/net/swarm/dial_sync.go +++ b/go-libp2p/p2p/net/swarm/dial_sync.go @@ -2,6 +2,7 @@ package swarm import ( "context" + "errors" "sync" "github.com/libp2p/go-libp2p/core/network" @@ -11,6 +12,9 @@ import ( // dialWorkerFunc is used by dialSync to spawn a new dial worker type dialWorkerFunc func(peer.ID, <-chan dialRequest) +// errConcurrentDialSuccessful is used to signal that a concurrent dial succeeded +var errConcurrentDialSuccessful = errors.New("concurrent dial successful") + // newDialSync constructs a new dialSync func newDialSync(worker dialWorkerFunc) *dialSync { return &dialSync{ @@ -30,17 +34,12 @@ type dialSync struct { type activeDial struct { refCnt int - ctx context.Context - cancel func() + ctx context.Context + cancelCause func(error) reqch chan dialRequest } -func (ad *activeDial) close() { - ad.cancel() - close(ad.reqch) -} - func (ad *activeDial) dial(ctx context.Context) (*Conn, error) { dialCtx := ad.ctx @@ -74,11 +73,11 @@ func (ds *dialSync) getActiveDial(p peer.ID) (*activeDial, error) { if !ok { // This code intentionally uses the background context. Otherwise, if the first call // to Dial is canceled, subsequent dial calls will also be canceled. - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancelCause(context.Background()) actd = &activeDial{ - ctx: ctx, - cancel: cancel, - reqch: make(chan dialRequest), + ctx: ctx, + cancelCause: cancel, + reqch: make(chan dialRequest), } go ds.dialWorker(p, actd.reqch) ds.dials[p] = actd @@ -96,14 +95,21 @@ func (ds *dialSync) Dial(ctx context.Context, p peer.ID) (*Conn, error) { return nil, err } - defer func() { - ds.mutex.Lock() - defer ds.mutex.Unlock() - ad.refCnt-- - if ad.refCnt == 0 { - ad.close() - delete(ds.dials, p) + conn, err := ad.dial(ctx) + + ds.mutex.Lock() + defer ds.mutex.Unlock() + + ad.refCnt-- + if ad.refCnt == 0 { + if err == nil { + ad.cancelCause(errConcurrentDialSuccessful) + } else { + ad.cancelCause(err) } - }() - return ad.dial(ctx) + close(ad.reqch) + delete(ds.dials, p) + } + + return conn, err } diff --git a/go-libp2p/p2p/net/swarm/dial_test.go b/go-libp2p/p2p/net/swarm/dial_test.go index 324a985..3b139ef 100644 --- a/go-libp2p/p2p/net/swarm/dial_test.go +++ b/go-libp2p/p2p/net/swarm/dial_test.go @@ -562,7 +562,7 @@ func TestDialSimultaneousJoin(t *testing.T) { return } - t.Logf("first dial succedded; conn: %+v", c) + t.Logf("first dial succeeded; conn: %+v", c) connch <- c errs <- nil @@ -587,7 +587,7 @@ func TestDialSimultaneousJoin(t *testing.T) { return } - t.Logf("second dial succedded; conn: %+v", c) + t.Logf("second dial succeeded; conn: %+v", c) connch <- c errs <- nil @@ -605,7 +605,7 @@ func TestDialSimultaneousJoin(t *testing.T) { return } - t.Logf("third dial succedded; conn: %+v", c) + t.Logf("third dial succeeded; conn: %+v", c) connch <- c errs <- nil @@ -642,3 +642,12 @@ func TestDialSelf(t *testing.T) { _, err := s1.DialPeer(context.Background(), s1.LocalPeer()) require.ErrorIs(t, err, swarm.ErrDialToSelf, "expected error from self dial") } + +func TestDialQUICDraft29(t *testing.T) { + s := makeDialOnlySwarm(t) + id := testutil.RandPeerIDFatal(t) + s.Peerstore().AddAddr(id, ma.StringCast("/ip4/127.0.0.1/udp/1234/quic"), time.Hour) + _, err := s.DialPeer(context.Background(), id) + require.ErrorIs(t, err, swarm.ErrQUICDraft29) + require.ErrorIs(t, err, swarm.ErrNoTransport) +} diff --git a/go-libp2p/p2p/net/swarm/dial_worker.go b/go-libp2p/p2p/net/swarm/dial_worker.go index 0334ac8..0cac6e4 100644 --- a/go-libp2p/p2p/net/swarm/dial_worker.go +++ b/go-libp2p/p2p/net/swarm/dial_worker.go @@ -8,15 +8,12 @@ import ( "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" + tpt "github.com/libp2p/go-libp2p/core/transport" ma "github.com/multiformats/go-multiaddr" + manet "github.com/multiformats/go-multiaddr/net" ) -// ///////////////////////////////////////////////////////////////////////////////// -// lo and behold, The Dialer -// TODO explain how all this works -// //////////////////////////////////////////////////////////////////////////////// - // dialRequest is structure used to request dials to the peer associated with a // worker loop type dialRequest struct { @@ -61,15 +58,14 @@ type addrDial struct { conn *Conn // err is the err on dialing the address err error - // requests is the list of pendRequests interested in this dial - // the value in the slice is the request number assigned to this request by the dialWorker - requests []int // dialed indicates whether we have triggered the dial to the address dialed bool // createdAt is the time this struct was created createdAt time.Time // dialRankingDelay is the delay in dialing this address introduced by the ranking logic dialRankingDelay time.Duration + // expectedTCPUpgradeTime is the expected time by which security upgrade will complete + expectedTCPUpgradeTime time.Time } // dialWorker synchronises concurrent dials to a peer. It ensures that we make at most one dial to a @@ -79,17 +75,13 @@ type dialWorker struct { peer peer.ID // reqch is used to send dial requests to the worker. close reqch to end the worker loop reqch <-chan dialRequest - // reqno is the request number used to track different dialRequests for a peer. - // Each incoming request is assigned a reqno. This reqno is used in pendingRequests and in - // addrDial objects in trackedDials to track this request - reqno int - // pendingRequests maps reqno to the pendRequest object for a dialRequest - pendingRequests map[int]*pendRequest - // trackedDials tracks dials to the peers addresses. An entry here is used to ensure that + // pendingRequests is the set of pendingRequests + pendingRequests map[*pendRequest]struct{} + // trackedDials tracks dials to the peer's addresses. An entry here is used to ensure that // we dial an address at most once trackedDials map[string]*addrDial // resch is used to receive response for dials to the peers addresses. - resch chan dialResult + resch chan tpt.DialUpdate connected bool // true when a connection has been successfully established @@ -106,9 +98,9 @@ func newDialWorker(s *Swarm, p peer.ID, reqch <-chan dialRequest, cl Clock) *dia s: s, peer: p, reqch: reqch, - pendingRequests: make(map[int]*pendRequest), + pendingRequests: make(map[*pendRequest]struct{}), trackedDials: make(map[string]*addrDial), - resch: make(chan dialResult), + resch: make(chan tpt.DialUpdate), cl: cl, } } @@ -128,6 +120,8 @@ func (w *dialWorker) loop() { startTime := w.cl.Now() // dialTimer is the dialTimer used to trigger dials dialTimer := w.cl.InstantTimer(startTime.Add(math.MaxInt64)) + defer dialTimer.Stop() + timerRunning := true // scheduleNextDial updates timer for triggering the next dial scheduleNextDial := func() { @@ -135,12 +129,18 @@ func (w *dialWorker) loop() { <-dialTimer.Ch() } timerRunning = false - if dq.len() > 0 { + if dq.Len() > 0 { if dialsInFlight == 0 && !w.connected { // if there are no dials in flight, trigger the next dials immediately dialTimer.Reset(startTime) } else { - dialTimer.Reset(startTime.Add(dq.top().Delay)) + resetTime := startTime.Add(dq.top().Delay) + for _, ad := range w.trackedDials { + if !ad.expectedTCPUpgradeTime.IsZero() && ad.expectedTCPUpgradeTime.After(resetTime) { + resetTime = ad.expectedTCPUpgradeTime + } + } + dialTimer.Reset(resetTime) } timerRunning = true } @@ -171,15 +171,20 @@ loop: // Enqueue the peer's addresses relevant to this request in dq and // track dials to the addresses relevant to this request. - c, err := w.s.bestAcceptableConnToPeer(req.ctx, w.peer) - if c != nil || err != nil { - req.resch <- dialResponse{conn: c, err: err} + c := w.s.bestAcceptableConnToPeer(req.ctx, w.peer) + if c != nil { + req.resch <- dialResponse{conn: c} continue loop } - addrs, err := w.s.addrsForDial(req.ctx, w.peer) + addrs, addrErrs, err := w.s.addrsForDial(req.ctx, w.peer) if err != nil { - req.resch <- dialResponse{err: err} + req.resch <- dialResponse{ + err: &DialError{ + Peer: w.peer, + DialErrors: addrErrs, + Cause: err, + }} continue loop } @@ -191,8 +196,8 @@ loop: // create the pending request object pr := &pendRequest{ req: req, - err: &DialError{Peer: w.peer}, addrs: make(map[string]struct{}, len(addrRanking)), + err: &DialError{Peer: w.peer, DialErrors: addrErrs}, } for _, adelay := range addrRanking { pr.addrs[string(adelay.Addr.Bytes())] = struct{}{} @@ -233,14 +238,13 @@ loop: if len(todial) == 0 && len(tojoin) == 0 { // all request applicable addrs have been dialed, we must have errored + pr.err.Cause = ErrAllDialsFailed req.resch <- dialResponse{err: pr.err} continue loop } - // The request has some pending or new dials. We assign this request a request number. - // This value of w.reqno is used to track this request in all the structures - w.reqno++ - w.pendingRequests[w.reqno] = pr + // The request has some pending or new dials + w.pendingRequests[pr] = struct{}{} for _, ad := range tojoin { if !ad.dialed { @@ -258,7 +262,6 @@ loop: } } // add the request to the addrDial - ad.requests = append(ad.requests, w.reqno) } if len(todial) > 0 { @@ -268,7 +271,6 @@ loop: w.trackedDials[string(a.Bytes())] = &addrDial{ addr: a, ctx: req.ctx, - requests: []int{w.reqno}, createdAt: now, } dq.Add(network.AddrDelay{Addr: a, Delay: addrDelay[string(a.Bytes())]}) @@ -313,16 +315,29 @@ loop: // Update all requests waiting on this address. On success, complete the request. // On error, record the error - dialsInFlight-- ad, ok := w.trackedDials[string(res.Addr.Bytes())] if !ok { log.Errorf("SWARM BUG: no entry for address %s in trackedDials", res.Addr) if res.Conn != nil { res.Conn.Close() } + dialsInFlight-- continue } + // TCP Connection has been established. Wait for connection upgrade on this address + // before making new dials. + if res.Kind == tpt.UpdateKindHandshakeProgressed { + // Only wait for public addresses to complete dialing since private dials + // are quick any way + if manet.IsPublicAddr(res.Addr) { + ad.expectedTCPUpgradeTime = w.cl.Now().Add(PublicTCPDelay) + } + scheduleNextDial() + continue + } + dialsInFlight-- + ad.expectedTCPUpgradeTime = time.Time{} if res.Conn != nil { // we got a connection, add it to the swarm conn, err := w.s.addConn(res.Conn, network.DirOutbound) @@ -333,20 +348,14 @@ loop: continue loop } - // request succeeded, respond to all pending requests - for _, reqno := range ad.requests { - pr, ok := w.pendingRequests[reqno] - if !ok { - // some other dial for this request succeeded before this one - continue + for pr := range w.pendingRequests { + if _, ok := pr.addrs[string(ad.addr.Bytes())]; ok { + pr.req.resch <- dialResponse{conn: conn} + delete(w.pendingRequests, pr) } - pr.req.resch <- dialResponse{conn: conn} - delete(w.pendingRequests, reqno) } ad.conn = conn - ad.requests = nil - if !w.connected { w.connected = true if w.s.metricsTracer != nil { @@ -380,33 +389,27 @@ loop: // dispatches an error to a specific addr dial func (w *dialWorker) dispatchError(ad *addrDial, err error) { ad.err = err - for _, reqno := range ad.requests { - pr, ok := w.pendingRequests[reqno] - if !ok { - // some other dial for this request succeeded before this one - continue - } - + for pr := range w.pendingRequests { // accumulate the error - pr.err.recordErr(ad.addr, err) - - delete(pr.addrs, string(ad.addr.Bytes())) - if len(pr.addrs) == 0 { - // all addrs have erred, dispatch dial error - // but first do a last one check in case an acceptable connection has landed from - // a simultaneous dial that started later and added new acceptable addrs - c, _ := w.s.bestAcceptableConnToPeer(pr.req.ctx, w.peer) - if c != nil { - pr.req.resch <- dialResponse{conn: c} - } else { - pr.req.resch <- dialResponse{err: pr.err} + if _, ok := pr.addrs[string(ad.addr.Bytes())]; ok { + pr.err.recordErr(ad.addr, err) + delete(pr.addrs, string(ad.addr.Bytes())) + if len(pr.addrs) == 0 { + // all addrs have erred, dispatch dial error + // but first do a last one check in case an acceptable connection has landed from + // a simultaneous dial that started later and added new acceptable addrs + c := w.s.bestAcceptableConnToPeer(pr.req.ctx, w.peer) + if c != nil { + pr.req.resch <- dialResponse{conn: c} + } else { + pr.err.Cause = ErrAllDialsFailed + pr.req.resch <- dialResponse{err: pr.err} + } + delete(w.pendingRequests, pr) } - delete(w.pendingRequests, reqno) } } - ad.requests = nil - // if it was a backoff, clear the address dial so that it doesn't inhibit new dial requests. // this is necessary to support active listen scenarios, where a new dial comes in while // another dial is in progress, and needs to do a direct connection without inhibitions from @@ -439,7 +442,7 @@ func newDialQueue() *dialQueue { // Add adds adelay to the queue. If another element exists in the queue with // the same address, it replaces that element. func (dq *dialQueue) Add(adelay network.AddrDelay) { - for i := 0; i < dq.len(); i++ { + for i := 0; i < dq.Len(); i++ { if dq.q[i].Addr.Equal(adelay.Addr) { if dq.q[i].Delay == adelay.Delay { // existing element is the same. nothing to do @@ -452,7 +455,7 @@ func (dq *dialQueue) Add(adelay network.AddrDelay) { } } - for i := 0; i < dq.len(); i++ { + for i := 0; i < dq.Len(); i++ { if dq.q[i].Delay > adelay.Delay { dq.q = append(dq.q, network.AddrDelay{}) // extend the slice copy(dq.q[i+1:], dq.q[i:]) @@ -465,13 +468,13 @@ func (dq *dialQueue) Add(adelay network.AddrDelay) { // NextBatch returns all the elements in the queue with the highest priority func (dq *dialQueue) NextBatch() []network.AddrDelay { - if dq.len() == 0 { + if dq.Len() == 0 { return nil } // i is the index of the second highest priority element var i int - for i = 0; i < dq.len(); i++ { + for i = 0; i < dq.Len(); i++ { if dq.q[i].Delay != dq.q[0].Delay { break } @@ -486,7 +489,7 @@ func (dq *dialQueue) top() network.AddrDelay { return dq.q[0] } -// len returns the number of elements in the queue -func (dq *dialQueue) len() int { +// Len returns the number of elements in the queue +func (dq *dialQueue) Len() int { return len(dq.q) } diff --git a/go-libp2p/p2p/net/swarm/dial_worker_test.go b/go-libp2p/p2p/net/swarm/dial_worker_test.go index 89130ee..9e9465f 100644 --- a/go-libp2p/p2p/net/swarm/dial_worker_test.go +++ b/go-libp2p/p2p/net/swarm/dial_worker_test.go @@ -26,12 +26,13 @@ import ( "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem" "github.com/libp2p/go-libp2p/p2p/muxer/yamux" tptu "github.com/libp2p/go-libp2p/p2p/net/upgrader" - quic "github.com/libp2p/go-libp2p/p2p/transport/quic" + libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic" "github.com/libp2p/go-libp2p/p2p/transport/quicreuse" "github.com/libp2p/go-libp2p/p2p/transport/tcp" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" + "github.com/quic-go/quic-go" "github.com/stretchr/testify/require" ) @@ -61,7 +62,7 @@ func makeSwarm(t *testing.T) *Swarm { t.Fatal(err) } - if err := s.Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic")); err != nil { + if err := s.Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1")); err != nil { t.Fatal(err) } @@ -88,11 +89,11 @@ func makeSwarmWithNoListenAddrs(t *testing.T, opts ...Option) *Swarm { if err := s.AddTransport(tcpTransport); err != nil { t.Fatal(err) } - reuse, err := quicreuse.NewConnManager([32]byte{}) + reuse, err := quicreuse.NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}) if err != nil { t.Fatal(err) } - quicTransport, err := quic.NewTransport(priv, reuse, nil, nil, nil) + quicTransport, err := libp2pquic.NewTransport(priv, reuse, nil, nil, nil) if err != nil { t.Fatal(err) } @@ -234,7 +235,7 @@ func TestDialWorkerLoopFailure(t *testing.T) { _, p2 := newPeer(t) - s1.Peerstore().AddAddrs(p2, []ma.Multiaddr{ma.StringCast("/ip4/11.0.0.1/tcp/1234"), ma.StringCast("/ip4/11.0.0.1/udp/1234/quic")}, peerstore.PermanentAddrTTL) + s1.Peerstore().AddAddrs(p2, []ma.Multiaddr{ma.StringCast("/ip4/11.0.0.1/tcp/1234"), ma.StringCast("/ip4/11.0.0.1/udp/1234/quic-v1")}, peerstore.PermanentAddrTTL) reqch := make(chan dialRequest) resch := make(chan dialResponse) @@ -259,7 +260,7 @@ func TestDialWorkerLoopConcurrentFailure(t *testing.T) { _, p2 := newPeer(t) - s1.Peerstore().AddAddrs(p2, []ma.Multiaddr{ma.StringCast("/ip4/11.0.0.1/tcp/1234"), ma.StringCast("/ip4/11.0.0.1/udp/1234/quic")}, peerstore.PermanentAddrTTL) + s1.Peerstore().AddAddrs(p2, []ma.Multiaddr{ma.StringCast("/ip4/11.0.0.1/tcp/1234"), ma.StringCast("/ip4/11.0.0.1/udp/1234/quic-v1")}, peerstore.PermanentAddrTTL) reqch := make(chan dialRequest) worker := newDialWorker(s1, p2, reqch, nil) @@ -307,7 +308,7 @@ func TestDialWorkerLoopConcurrentMix(t *testing.T) { defer s2.Close() s1.Peerstore().AddAddrs(s2.LocalPeer(), s2.ListenAddresses(), peerstore.PermanentAddrTTL) - s1.Peerstore().AddAddrs(s2.LocalPeer(), []ma.Multiaddr{ma.StringCast("/ip4/11.0.0.1/tcp/1234"), ma.StringCast("/ip4/11.0.0.1/udp/1234/quic")}, peerstore.PermanentAddrTTL) + s1.Peerstore().AddAddrs(s2.LocalPeer(), []ma.Multiaddr{ma.StringCast("/ip4/11.0.0.1/tcp/1234"), ma.StringCast("/ip4/11.0.0.1/udp/1234/quic-v1")}, peerstore.PermanentAddrTTL) reqch := make(chan dialRequest) worker := newDialWorker(s1, s2.LocalPeer(), reqch, nil) @@ -484,8 +485,8 @@ func TestDialQueueNextBatch(t *testing.T) { } } } - if q.len() != 0 { - t.Errorf("expected queue to be empty at end. got: %d", q.len()) + if q.Len() != 0 { + t.Errorf("expected queue to be empty at end. got: %d", q.Len()) } }) } @@ -917,7 +918,7 @@ func TestDialWorkerLoopQuicOverTCP(t *testing.T) { tc := schedulingTestCase{ input: []timedDial{ { - addr: ma.StringCast("/ip4/127.0.0.1/udp/20000/quic"), + addr: ma.StringCast("/ip4/127.0.0.1/udp/20000/quic-v1"), delay: 0, success: true, }, @@ -968,7 +969,7 @@ func TestDialWorkerLoopHolePunching(t *testing.T) { for i := 0; i < len(addrs); i++ { delay := 10 * time.Second if addrs[i].Equal(t1) { - //fire t1 immediately + // fire t1 immediately delay = 0 } else if addrs[i].Equal(t2) { // delay t2 by 100ms @@ -1081,3 +1082,61 @@ func TestDialWorkerLoopAddrDedup(t *testing.T) { t.Errorf("expected a fail response") } } + +func TestDialWorkerLoopTCPConnUpgradeWait(t *testing.T) { + s1 := makeSwarmWithNoListenAddrs(t, WithDialTimeout(10*time.Second)) + s2 := makeSwarmWithNoListenAddrs(t, WithDialTimeout(10*time.Second)) + defer s1.Close() + defer s2.Close() + // Connection to a1 will fail but a1 is a public address so we can test waiting for tcp + // connection established dial update. ipv4only.arpa reserved address. + a1 := ma.StringCast(fmt.Sprintf("/ip4/192.0.0.170/tcp/%d", 10001)) + // Connection to a2 will succeed. + a2 := ma.StringCast(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", 10002)) + s2.Listen(a2) + + s1.Peerstore().AddAddrs(s2.LocalPeer(), []ma.Multiaddr{a1, a2}, peerstore.PermanentAddrTTL) + + rankerCalled := make(chan struct{}) + s1.dialRanker = func(addrs []ma.Multiaddr) []network.AddrDelay { + defer close(rankerCalled) + return []network.AddrDelay{{Addr: a1, Delay: 0}, {Addr: a2, Delay: 100 * time.Millisecond}} + } + + reqch := make(chan dialRequest) + resch := make(chan dialResponse, 2) + cl := newMockClock() + worker := newDialWorker(s1, s2.LocalPeer(), reqch, cl) + go worker.loop() + defer worker.wg.Wait() + defer close(reqch) + + reqch <- dialRequest{ctx: context.Background(), resch: resch} + + <-rankerCalled + // Wait a bit to let the loop make the dial attempt to a1 + time.Sleep(1 * time.Second) + // Send conn established for a1 + worker.resch <- transport.DialUpdate{Kind: transport.UpdateKindHandshakeProgressed, Addr: a1} + // Dial to a2 shouldn't happen even if a2 is scheduled to dial by now + cl.AdvanceBy(200 * time.Millisecond) + select { + case r := <-resch: + t.Fatalf("didn't expect any event on resch %s %s", r.err, r.conn) + case <-time.After(500 * time.Millisecond): + } + + // Dial to a2 should happen now + // This number is high because there's a race between this goroutine advancing the clock + // and the worker loop goroutine processing the TCPConnectionEstablished event. + // In case it processes the event after the previous clock advancement we need to wait + // 2 * PublicTCPDelay. + cl.AdvanceBy(2 * PublicTCPDelay) + select { + case r := <-resch: + require.NoError(t, r.err) + require.NotNil(t, r.conn) + case <-time.After(3 * time.Second): + t.Errorf("expected a fail response") + } +} diff --git a/go-libp2p/p2p/net/swarm/limiter.go b/go-libp2p/p2p/net/swarm/limiter.go index ccfe7d2..f5638bb 100644 --- a/go-libp2p/p2p/net/swarm/limiter.go +++ b/go-libp2p/p2p/net/swarm/limiter.go @@ -13,17 +13,11 @@ import ( ma "github.com/multiformats/go-multiaddr" ) -type dialResult struct { - Conn transport.CapableConn - Addr ma.Multiaddr - Err error -} - type dialJob struct { addr ma.Multiaddr peer peer.ID ctx context.Context - resp chan dialResult + resp chan transport.DialUpdate timeout time.Duration } @@ -45,7 +39,7 @@ type dialLimiter struct { waitingOnPeerLimit map[peer.ID][]*dialJob } -type dialfunc func(context.Context, peer.ID, ma.Multiaddr) (transport.CapableConn, error) +type dialfunc func(context.Context, peer.ID, ma.Multiaddr, chan<- transport.DialUpdate) (transport.CapableConn, error) func newDialLimiter(df dialfunc) *dialLimiter { fd := ConcurrentFdDials @@ -216,9 +210,13 @@ func (dl *dialLimiter) executeDial(j *dialJob) { dctx, cancel := context.WithTimeout(j.ctx, j.timeout) defer cancel() - con, err := dl.dialFunc(dctx, j.peer, j.addr) + con, err := dl.dialFunc(dctx, j.peer, j.addr, j.resp) + kind := transport.UpdateKindDialSuccessful + if err != nil { + kind = transport.UpdateKindDialFailed + } select { - case j.resp <- dialResult{Conn: con, Addr: j.addr, Err: err}: + case j.resp <- transport.DialUpdate{Kind: kind, Conn: con, Addr: j.addr, Err: err}: case <-j.ctx.Done(): if con != nil { con.Close() diff --git a/go-libp2p/p2p/net/swarm/limiter_test.go b/go-libp2p/p2p/net/swarm/limiter_test.go index 046b4c7..8e61958 100644 --- a/go-libp2p/p2p/net/swarm/limiter_test.go +++ b/go-libp2p/p2p/net/swarm/limiter_test.go @@ -39,7 +39,7 @@ func tcpPortOver(a ma.Multiaddr, n int) bool { return pnum > n } -func tryDialAddrs(ctx context.Context, l *dialLimiter, p peer.ID, addrs []ma.Multiaddr, res chan dialResult) { +func tryDialAddrs(ctx context.Context, l *dialLimiter, p peer.ID, addrs []ma.Multiaddr, res chan transport.DialUpdate) { for _, a := range addrs { l.AddDialJob(&dialJob{ ctx: ctx, @@ -51,7 +51,7 @@ func tryDialAddrs(ctx context.Context, l *dialLimiter, p peer.ID, addrs []ma.Mul } func hangDialFunc(hang chan struct{}) dialfunc { - return func(ctx context.Context, p peer.ID, a ma.Multiaddr) (transport.CapableConn, error) { + return func(ctx context.Context, p peer.ID, a ma.Multiaddr, _ chan<- transport.DialUpdate) (transport.CapableConn, error) { if mafmt.UTP.Matches(a) { return transport.CapableConn(nil), nil } @@ -79,7 +79,7 @@ func TestLimiterBasicDials(t *testing.T) { bads := []ma.Multiaddr{addrWithPort(1), addrWithPort(2), addrWithPort(3), addrWithPort(4)} good := addrWithPort(20) - resch := make(chan dialResult) + resch := make(chan transport.DialUpdate) pid := peer.ID("testpeer") ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -130,7 +130,7 @@ func TestFDLimiting(t *testing.T) { goodTCP := addrWithPort(20) ctx := context.Background() - resch := make(chan dialResult) + resch := make(chan transport.DialUpdate) // take all fd limit tokens with hang dials for _, pid := range pids { @@ -188,7 +188,7 @@ func TestFDLimiting(t *testing.T) { func TestTokenRedistribution(t *testing.T) { var lk sync.Mutex hangchs := make(map[peer.ID]chan struct{}) - df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (transport.CapableConn, error) { + df := func(ctx context.Context, p peer.ID, a ma.Multiaddr, _ chan<- transport.DialUpdate) (transport.CapableConn, error) { if tcpPortOver(a, 10) { return (transport.CapableConn)(nil), nil } @@ -205,7 +205,7 @@ func TestTokenRedistribution(t *testing.T) { pids := []peer.ID{"testpeer1", "testpeer2"} ctx := context.Background() - resch := make(chan dialResult) + resch := make(chan transport.DialUpdate) // take all fd limit tokens with hang dials for _, pid := range pids { @@ -281,7 +281,7 @@ func TestTokenRedistribution(t *testing.T) { } func TestStressLimiter(t *testing.T) { - df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (transport.CapableConn, error) { + df := func(ctx context.Context, p peer.ID, a ma.Multiaddr, _ chan<- transport.DialUpdate) (transport.CapableConn, error) { if tcpPortOver(a, 1000) { return transport.CapableConn(nil), nil } @@ -305,7 +305,7 @@ func TestStressLimiter(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - resp := make(chan dialResult) + resp := make(chan transport.DialUpdate) time.Sleep(time.Duration(rand.Intn(10)) * time.Millisecond) for _, i := range rand.Perm(len(addresses)) { l.AddDialJob(&dialJob{ @@ -335,7 +335,7 @@ func TestStressLimiter(t *testing.T) { } func TestFDLimitUnderflow(t *testing.T) { - df := func(ctx context.Context, p peer.ID, addr ma.Multiaddr) (transport.CapableConn, error) { + df := func(ctx context.Context, p peer.ID, addr ma.Multiaddr, _ chan<- transport.DialUpdate) (transport.CapableConn, error) { select { case <-ctx.Done(): case <-time.After(5 * time.Second): @@ -361,7 +361,7 @@ func TestFDLimitUnderflow(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - resp := make(chan dialResult) + resp := make(chan transport.DialUpdate) l.AddDialJob(&dialJob{ addr: addrs[i], ctx: ctx, diff --git a/go-libp2p/p2p/net/swarm/swarm.go b/go-libp2p/p2p/net/swarm/swarm.go index 5155cd2..7897277 100644 --- a/go-libp2p/p2p/net/swarm/swarm.go +++ b/go-libp2p/p2p/net/swarm/swarm.go @@ -17,6 +17,7 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peerstore" "github.com/libp2p/go-libp2p/core/transport" + "golang.org/x/exp/slices" logging "github.com/ipfs/go-log/v2" ma "github.com/multiformats/go-multiaddr" @@ -136,8 +137,8 @@ func WithIPv6BlackHoleConfig(enabled bool, n, min int) Option { // communication. The Chan sends/receives Messages, which note the // destination or source Peer. type Swarm struct { - nextConnID uint64 // guarded by atomic - nextStreamID uint64 // guarded by atomic + nextConnID atomic.Uint64 + nextStreamID atomic.Uint64 // Close refcount. This allows us to fully wait for the swarm to be torn // down before continuing. @@ -172,6 +173,11 @@ type Swarm struct { m map[network.Notifiee]struct{} } + directConnNotifs struct { + sync.Mutex + m map[peer.ID][]chan struct{} + } + transports struct { sync.RWMutex m map[int]transport.Transport @@ -197,9 +203,10 @@ type Swarm struct { dialRanker network.DialRanker - udpBlackHoleConfig blackHoleConfig - ipv6BlackHoleConfig blackHoleConfig - bhd *blackHoleDetector + udpBlackHoleConfig blackHoleConfig + ipv6BlackHoleConfig blackHoleConfig + bhd *blackHoleDetector + connectednessEventEmitter *connectednessEventEmitter } // NewSwarm constructs a Swarm. @@ -231,6 +238,8 @@ func NewSwarm(local peer.ID, peers peerstore.Peerstore, eventBus event.Bus, opts s.listeners.m = make(map[transport.Listener]struct{}) s.transports.m = make(map[int]transport.Transport) s.notifs.m = make(map[network.Notifiee]struct{}) + s.directConnNotifs.m = make(map[peer.ID][]chan struct{}) + s.connectednessEventEmitter = newConnectednessEventEmitter(s.Connectedness, emitter) for _, opt := range opts { if err := opt(s); err != nil { @@ -247,7 +256,6 @@ func NewSwarm(local peer.ID, peers peerstore.Peerstore, eventBus event.Bus, opts s.backf.init(s.ctx) s.bhd = newBlackHoleDetector(s.udpBlackHoleConfig, s.ipv6BlackHoleConfig, s.metricsTracer) - return s, nil } @@ -256,11 +264,14 @@ func (s *Swarm) Close() error { return nil } +// Done returns a channel that is closed when the swarm is closed. +func (s *Swarm) Done() <-chan struct{} { + return s.ctx.Done() +} + func (s *Swarm) close() { s.ctxCancel() - s.emitter.Close() - // Prevents new connections and/or listeners from being added to the swarm. s.listeners.Lock() listeners := s.listeners.m @@ -274,9 +285,10 @@ func (s *Swarm) close() { // Lots of goroutines but we might as well do this in parallel. We want to shut down as fast as // possible. - + s.refs.Add(len(listeners)) for l := range listeners { go func(l transport.Listener) { + defer s.refs.Done() if err := l.Close(); err != nil && err != transport.ErrListenerClosed { log.Errorf("error when shutting down listener: %s", err) } @@ -295,6 +307,8 @@ func (s *Swarm) close() { // Wait for everything to finish. s.refs.Wait() + s.connectednessEventEmitter.Close() + s.emitter.Close() // Now close out any transports (if necessary). Do this after closing // all connections/listeners. @@ -337,13 +351,14 @@ func (s *Swarm) addConn(tc transport.CapableConn, dir network.Direction) (*Conn, } stat.Direction = dir stat.Opened = time.Now() + isLimited := stat.Limited // Wrap and register the connection. c := &Conn{ conn: tc, swarm: s, stat: stat, - id: atomic.AddUint64(&s.nextConnID, 1), + id: s.nextConnID.Add(1), } // we ONLY check upgraded connections here so we can send them a Disconnect message. @@ -353,7 +368,7 @@ func (s *Swarm) addConn(tc transport.CapableConn, dir network.Direction) (*Conn, // TODO Send disconnect with reason here err := tc.Close() if err != nil { - log.Warnf("failed to close connection with peer %s and addr %s; err: %s", p.Pretty(), addr, err) + log.Warnf("failed to close connection with peer %s and addr %s; err: %s", p, addr, err) } return nil, ErrGaterDisallowedConnection } @@ -377,28 +392,34 @@ func (s *Swarm) addConn(tc transport.CapableConn, dir network.Direction) (*Conn, } c.streams.m = make(map[*Stream]struct{}) - isFirstConnection := len(s.conns.m[p]) == 0 s.conns.m[p] = append(s.conns.m[p], c) - // Add two swarm refs: // * One will be decremented after the close notifications fire in Conn.doClose // * The other will be decremented when Conn.start exits. s.refs.Add(2) - // Take the notification lock before releasing the conns lock to block // Disconnect notifications until after the Connect notifications done. + // This lock also ensures that swarm.refs.Wait() exits after we have + // enqueued the peer connectedness changed notification. + // TODO: Fix this fragility by taking a swarm ref for dial worker loop c.notifyLk.Lock() s.conns.Unlock() - // Emit event after releasing `s.conns` lock so that a consumer can still - // use swarm methods that need the `s.conns` lock. - if isFirstConnection { - s.emitter.Emit(event.EvtPeerConnectednessChanged{ - Peer: p, - Connectedness: network.Connected, - }) - } + s.connectednessEventEmitter.AddConn(p) + if !isLimited { + // Notify goroutines waiting for a direct connection + // + // Go routines interested in waiting for direct connection first acquire this lock + // and then acquire s.conns.RLock. Do not acquire this lock before conns.Unlock to + // prevent deadlock. + s.directConnNotifs.Lock() + for _, ch := range s.directConnNotifs.m[p] { + close(ch) + } + delete(s.directConnNotifs.m, p) + s.directConnNotifs.Unlock() + } s.notifyAll(func(f network.Notifiee) { f.Connected(s, c) }) @@ -429,54 +450,110 @@ func (s *Swarm) StreamHandler() network.StreamHandler { // NewStream creates a new stream on any available connection to peer, dialing // if necessary. +// Use network.WithAllowLimitedConn to open a stream over a limited(relayed) +// connection. func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (network.Stream, error) { log.Debugf("[%s] opening stream to peer [%s]", s.local, p) // Algorithm: // 1. Find the best connection, otherwise, dial. - // 2. Try opening a stream. - // 3. If the underlying connection is, in fact, closed, close the outer + // 2. If the best connection is limited, wait for a direct conn via conn + // reversal or hole punching. + // 3. Try opening a stream. + // 4. If the underlying connection is, in fact, closed, close the outer // connection and try again. We do this in case we have a closed // connection but don't notice it until we actually try to open a // stream. // - // Note: We only dial once. - // // TODO: Try all connections even if we get an error opening a stream on // a non-closed connection. - dials := 0 + numDials := 0 for { - // will prefer direct connections over relayed connections for opening streams - c, err := s.bestAcceptableConnToPeer(ctx, p) - if err != nil { - return nil, err - } - + c := s.bestConnToPeer(p) if c == nil { - if nodial, _ := network.GetNoDial(ctx); nodial { + if nodial, _ := network.GetNoDial(ctx); !nodial { + numDials++ + if numDials > DialAttempts { + return nil, errors.New("max dial attempts exceeded") + } + var err error + c, err = s.dialPeer(ctx, p) + if err != nil { + return nil, err + } + } else { return nil, network.ErrNoConn } + } - if dials >= DialAttempts { - return nil, errors.New("max dial attempts exceeded") - } - dials++ - + limitedAllowed, _ := network.GetAllowLimitedConn(ctx) + if !limitedAllowed && c.Stat().Limited { var err error - c, err = s.dialPeer(ctx, p) + c, err = s.waitForDirectConn(ctx, p) if err != nil { return nil, err } } - s, err := c.NewStream(ctx) + str, err := c.NewStream(ctx) if err != nil { if c.conn.IsClosed() { continue } return nil, err } - return s, nil + return str, nil + } +} + +// waitForDirectConn waits for a direct connection established through hole punching or connection reversal. +func (s *Swarm) waitForDirectConn(ctx context.Context, p peer.ID) (*Conn, error) { + s.directConnNotifs.Lock() + c := s.bestConnToPeer(p) + if c == nil { + s.directConnNotifs.Unlock() + return nil, network.ErrNoConn + } else if !c.Stat().Limited { + s.directConnNotifs.Unlock() + return c, nil + } + + // Wait for limited connection to upgrade to a direct connection either by + // connection reversal or hole punching. + ch := make(chan struct{}) + s.directConnNotifs.m[p] = append(s.directConnNotifs.m[p], ch) + s.directConnNotifs.Unlock() + + // apply the DialPeer timeout + ctx, cancel := context.WithTimeout(ctx, network.GetDialPeerTimeout(ctx)) + defer cancel() + + // Wait for notification. + select { + case <-ctx.Done(): + // Remove ourselves from the notification list + s.directConnNotifs.Lock() + defer s.directConnNotifs.Unlock() + + s.directConnNotifs.m[p] = slices.DeleteFunc( + s.directConnNotifs.m[p], + func(c chan struct{}) bool { return c == ch }, + ) + if len(s.directConnNotifs.m[p]) == 0 { + delete(s.directConnNotifs.m, p) + } + return nil, ctx.Err() + case <-ch: + // We do not need to remove ourselves from the list here as the notifier + // clears the map entry + c := s.bestConnToPeer(p) + if c == nil { + return nil, network.ErrNoConn + } + if c.Stat().Limited { + return nil, network.ErrLimitedConn + } + return c, nil } } @@ -495,11 +572,11 @@ func (s *Swarm) ConnsToPeer(p peer.ID) []network.Conn { } func isBetterConn(a, b *Conn) bool { - // If one is transient and not the other, prefer the non-transient connection. - aTransient := a.Stat().Transient - bTransient := b.Stat().Transient - if aTransient != bTransient { - return !aTransient + // If one is limited and not the other, prefer the unlimited connection. + aLimited := a.Stat().Limited + bLimited := b.Stat().Limited + if aLimited != bLimited { + return !aLimited } // If one is direct and not the other, prefer the direct connection. @@ -548,26 +625,17 @@ func (s *Swarm) bestConnToPeer(p peer.ID) *Conn { return best } -// - Returns the best "acceptable" connection, if available. -// - Returns nothing if no such connection exists, but if we should try dialing anyways. -// - Returns an error if no such connection exists, but we should not try dialing. -func (s *Swarm) bestAcceptableConnToPeer(ctx context.Context, p peer.ID) (*Conn, error) { +// bestAcceptableConnToPeer returns the best acceptable connection, considering the passed in ctx. +// If network.WithForceDirectDial is used, it only returns a direct connections, ignoring +// any limited (relayed) connections to the peer. +func (s *Swarm) bestAcceptableConnToPeer(ctx context.Context, p peer.ID) *Conn { conn := s.bestConnToPeer(p) - if conn == nil { - return nil, nil - } forceDirect, _ := network.GetForceDirectDial(ctx) if forceDirect && !isDirectConn(conn) { - return nil, nil + return nil } - - useTransient, _ := network.GetUseTransient(ctx) - if useTransient || !conn.Stat().Transient { - return conn, nil - } - - return nil, network.ErrTransientConn + return conn } func isDirectConn(c *Conn) bool { @@ -579,8 +647,28 @@ func isDirectConn(c *Conn) bool { // To check if we have an open connection, use `s.Connectedness(p) == // network.Connected`. func (s *Swarm) Connectedness(p peer.ID) network.Connectedness { - if s.bestConnToPeer(p) != nil { - return network.Connected + s.conns.RLock() + defer s.conns.RUnlock() + + return s.connectednessUnlocked(p) +} + +// connectednessUnlocked returns the connectedness of a peer. +func (s *Swarm) connectednessUnlocked(p peer.ID) network.Connectedness { + var haveLimited bool + for _, c := range s.conns.m[p] { + if c.IsClosed() { + // These will be garbage collected soon + continue + } + if c.Stat().Limited { + haveLimited = true + } else { + return network.Connected + } + } + if haveLimited { + return network.Limited } return network.NotConnected } @@ -678,24 +766,7 @@ func (s *Swarm) removeConn(c *Conn) { p := c.RemotePeer() s.conns.Lock() - cs := s.conns.m[p] - - if len(cs) == 1 { - delete(s.conns.m, p) - s.conns.Unlock() - - // Emit event after releasing `s.conns` lock so that a consumer can still - // use swarm methods that need the `s.conns` lock. - s.emitter.Emit(event.EvtPeerConnectednessChanged{ - Peer: p, - Connectedness: network.NotConnected, - }) - return - } - - defer s.conns.Unlock() - for i, ci := range cs { if ci == c { // NOTE: We're intentionally preserving order. @@ -707,6 +778,10 @@ func (s *Swarm) removeConn(c *Conn) { break } } + if len(s.conns.m[p]) == 0 { + delete(s.conns.m, p) + } + s.conns.Unlock() } // String returns a string representation of Network. diff --git a/go-libp2p/p2p/net/swarm/swarm_addr_test.go b/go-libp2p/p2p/net/swarm/swarm_addr_test.go index 6cb4f96..435866e 100644 --- a/go-libp2p/p2p/net/swarm/swarm_addr_test.go +++ b/go-libp2p/p2p/net/swarm/swarm_addr_test.go @@ -2,6 +2,7 @@ package swarm_test import ( "context" + "crypto/sha256" "fmt" "testing" @@ -13,15 +14,15 @@ import ( "github.com/libp2p/go-libp2p/p2p/net/swarm" swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing" circuitv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/client" - quic "github.com/libp2p/go-libp2p/p2p/transport/quic" + libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic" "github.com/libp2p/go-libp2p/p2p/transport/quicreuse" "github.com/libp2p/go-libp2p/p2p/transport/tcp" webtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport" - "github.com/minio/sha256-simd" ma "github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multibase" "github.com/multiformats/go-multihash" + "github.com/quic-go/quic-go" "github.com/stretchr/testify/require" ) @@ -81,10 +82,10 @@ func TestDialAddressSelection(t *testing.T) { tcpTr, err := tcp.NewTCPTransport(nil, nil) require.NoError(t, err) require.NoError(t, s.AddTransport(tcpTr)) - reuse, err := quicreuse.NewConnManager([32]byte{}) + reuse, err := quicreuse.NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}) require.NoError(t, err) defer reuse.Close() - quicTr, err := quic.NewTransport(priv, reuse, nil, nil, nil) + quicTr, err := libp2pquic.NewTransport(priv, reuse, nil, nil, nil) require.NoError(t, err) require.NoError(t, s.AddTransport(quicTr)) webtransportTr, err := webtransport.New(priv, nil, reuse, nil, nil) @@ -100,7 +101,7 @@ func TestDialAddressSelection(t *testing.T) { require.NoError(t, s.AddTransport(circuitTr)) require.Equal(t, tcpTr, s.TransportForDialing(ma.StringCast("/ip4/127.0.0.1/tcp/1234"))) - require.Equal(t, quicTr, s.TransportForDialing(ma.StringCast("/ip4/127.0.0.1/udp/1234/quic"))) + require.Equal(t, quicTr, s.TransportForDialing(ma.StringCast("/ip4/127.0.0.1/udp/1234/quic-v1"))) require.Equal(t, circuitTr, s.TransportForDialing(ma.StringCast(fmt.Sprintf("/ip4/127.0.0.1/udp/1234/quic/p2p-circuit/p2p/%s", id)))) require.Equal(t, webtransportTr, s.TransportForDialing(ma.StringCast(fmt.Sprintf("/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/certhash/%s", certHash)))) require.Nil(t, s.TransportForDialing(ma.StringCast("/ip4/1.2.3.4"))) diff --git a/go-libp2p/p2p/net/swarm/swarm_conn.go b/go-libp2p/p2p/net/swarm/swarm_conn.go index e770381..38e942c 100644 --- a/go-libp2p/p2p/net/swarm/swarm_conn.go +++ b/go-libp2p/p2p/net/swarm/swarm_conn.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "sync" - "sync/atomic" "time" ic "github.com/libp2p/go-libp2p/core/crypto" @@ -49,7 +48,7 @@ func (c *Conn) IsClosed() bool { func (c *Conn) ID() string { // format: - - return fmt.Sprintf("%s-%d", c.RemotePeer().Pretty()[0:10], c.id) + return fmt.Sprintf("%s-%d", c.RemotePeer().String()[:10], c.id) } // Close closes this connection. @@ -74,6 +73,11 @@ func (c *Conn) doClose() { c.err = c.conn.Close() + // Send the connectedness event after closing the connection. + // This ensures that both remote connection close and local connection + // close events are sent after the underlying transport connection is closed. + c.swarm.connectednessEventEmitter.RemoveConn(c.RemotePeer()) + // This is just for cleaning up state. The connection has already been closed. // We *could* optimize this but it really isn't worth it. for s := range streams { @@ -86,10 +90,11 @@ func (c *Conn) doClose() { c.notifyLk.Lock() defer c.notifyLk.Unlock() + // Only notify for disconnection if we notified for connection c.swarm.notifyAll(func(f network.Notifiee) { f.Disconnected(c.swarm, c) }) - c.swarm.refs.Done() // taken in Swarm.addConn + c.swarm.refs.Done() }() } @@ -109,7 +114,6 @@ func (c *Conn) start() { go func() { defer c.swarm.refs.Done() defer c.Close() - for { ts, err := c.conn.AcceptStream() if err != nil { @@ -137,6 +141,7 @@ func (c *Conn) start() { if h := c.swarm.StreamHandler(); h != nil { h(s) } + s.completeAcceptStreamGoroutine() }() } }() @@ -147,9 +152,9 @@ func (c *Conn) String() string { " %s (%s)>", c.conn.Transport(), c.conn.LocalMultiaddr(), - c.conn.LocalPeer().Pretty(), + c.conn.LocalPeer(), c.conn.RemoteMultiaddr(), - c.conn.RemotePeer().Pretty(), + c.conn.RemotePeer(), ) } @@ -193,9 +198,9 @@ func (c *Conn) Stat() network.ConnStats { // NewStream returns a new Stream from this connection func (c *Conn) NewStream(ctx context.Context) (network.Stream, error) { - if c.Stat().Transient { - if useTransient, _ := network.GetUseTransient(ctx); !useTransient { - return nil, network.ErrTransientConn + if c.Stat().Limited { + if useLimited, _ := network.GetAllowLimitedConn(ctx); !useLimited { + return nil, network.ErrLimitedConn } } @@ -238,7 +243,8 @@ func (c *Conn) addStream(ts network.MuxedStream, dir network.Direction, scope ne Direction: dir, Opened: time.Now(), }, - id: atomic.AddUint64(&c.swarm.nextStreamID, 1), + id: c.swarm.nextStreamID.Add(1), + acceptStreamGoroutineCompleted: dir != network.DirInbound, } c.stat.NumStreams++ c.streams.m[s] = struct{}{} diff --git a/go-libp2p/p2p/net/swarm/swarm_dial.go b/go-libp2p/p2p/net/swarm/swarm_dial.go index f2df93a..f639ce1 100644 --- a/go-libp2p/p2p/net/swarm/swarm_dial.go +++ b/go-libp2p/p2p/net/swarm/swarm_dial.go @@ -14,8 +14,10 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peerstore" "github.com/libp2p/go-libp2p/core/transport" + ma "github.com/multiformats/go-multiaddr" madns "github.com/multiformats/go-multiaddr-dns" + mafmt "github.com/multiformats/go-multiaddr-fmt" manet "github.com/multiformats/go-multiaddr/net" ) @@ -65,6 +67,19 @@ var ( ErrGaterDisallowedConnection = errors.New("gater disallows connection to peer") ) +// ErrQUICDraft29 wraps ErrNoTransport and provide a more meaningful error message +var ErrQUICDraft29 errQUICDraft29 + +type errQUICDraft29 struct{} + +func (errQUICDraft29) Error() string { + return "QUIC draft-29 has been removed, QUIC (RFC 9000) is accessible with /quic-v1" +} + +func (errQUICDraft29) Unwrap() error { + return ErrNoTransport +} + // DialAttempts governs how many times a goroutine will try to dial a given peer. // Note: this is down to one, as we have _too many dials_ atm. To add back in, // add loop back in Dial(.) @@ -201,7 +216,8 @@ func (db *DialBackoff) cleanup() { } } -// DialPeer connects to a peer. +// DialPeer connects to a peer. Use network.WithForceDirectDial to force a +// direct connection. // // The idea is that the client of Swarm does not need to know what network // the connection will happen over. Swarm can use whichever it choses. @@ -231,15 +247,14 @@ func (s *Swarm) dialPeer(ctx context.Context, p peer.ID) (*Conn, error) { return nil, ErrDialToSelf } - // check if we already have an open (usable) connection first, or can't have a usable - // connection. - conn, err := s.bestAcceptableConnToPeer(ctx, p) - if conn != nil || err != nil { - return conn, err + // check if we already have an open (usable) connection. + conn := s.bestAcceptableConnToPeer(ctx, p) + if conn != nil { + return conn, nil } if s.gater != nil && !s.gater.InterceptPeerDial(p) { - log.Debugf("gater disallowed outbound connection to peer %s", p.Pretty()) + log.Debugf("gater disallowed outbound connection to peer %s", p) return nil, &DialError{Peer: p, Cause: ErrGaterDisallowedConnection} } @@ -280,68 +295,47 @@ func (s *Swarm) dialWorkerLoop(p peer.ID, reqch <-chan dialRequest) { w.loop() } -func (s *Swarm) addrsForDial(ctx context.Context, p peer.ID) ([]ma.Multiaddr, error) { +func (s *Swarm) addrsForDial(ctx context.Context, p peer.ID) (goodAddrs []ma.Multiaddr, addrErrs []TransportError, err error) { peerAddrs := s.peers.Addrs(p) if len(peerAddrs) == 0 { - return nil, ErrNoAddresses - } - - peerAddrsAfterTransportResolved := make([]ma.Multiaddr, 0, len(peerAddrs)) - for _, a := range peerAddrs { - tpt := s.TransportForDialing(a) - resolver, ok := tpt.(transport.Resolver) - if ok { - resolvedAddrs, err := resolver.Resolve(ctx, a) - if err != nil { - log.Warnf("Failed to resolve multiaddr %s by transport %v: %v", a, tpt, err) - continue - } - peerAddrsAfterTransportResolved = append(peerAddrsAfterTransportResolved, resolvedAddrs...) - } else { - peerAddrsAfterTransportResolved = append(peerAddrsAfterTransportResolved, a) - } + return nil, nil, ErrNoAddresses } // Resolve dns or dnsaddrs - resolved, err := s.resolveAddrs(ctx, peer.AddrInfo{ - ID: p, - Addrs: peerAddrsAfterTransportResolved, - }) + resolved, err := s.resolveAddrs(ctx, peer.AddrInfo{ID: p, Addrs: peerAddrs}) if err != nil { - return nil, err + return nil, nil, err } - goodAddrs := s.filterKnownUndialables(p, resolved) + goodAddrs = ma.Unique(resolved) + goodAddrs, addrErrs = s.filterKnownUndialables(p, goodAddrs) if forceDirect, _ := network.GetForceDirectDial(ctx); forceDirect { goodAddrs = ma.FilterAddrs(goodAddrs, s.nonProxyAddr) } - goodAddrs = ma.Unique(goodAddrs) if len(goodAddrs) == 0 { - return nil, ErrNoGoodAddresses + return nil, addrErrs, ErrNoGoodAddresses } s.peers.AddAddrs(p, goodAddrs, peerstore.TempAddrTTL) - return goodAddrs, nil + return goodAddrs, addrErrs, nil } func (s *Swarm) resolveAddrs(ctx context.Context, pi peer.AddrInfo) ([]ma.Multiaddr, error) { - proto := ma.ProtocolWithCode(ma.P_P2P).Name - p2paddr, err := ma.NewMultiaddr("/" + proto + "/" + pi.ID.Pretty()) + p2paddr, err := ma.NewMultiaddr("/" + ma.ProtocolWithCode(ma.P_P2P).Name + "/" + pi.ID.String()) if err != nil { return nil, err } - resolveSteps := 0 - + var resolveSteps int // Recursively resolve all addrs. // // While the toResolve list is non-empty: // * Pop an address off. // * If the address is fully resolved, add it to the resolved list. // * Otherwise, resolve it and add the results to the "to resolve" list. - toResolve := append(([]ma.Multiaddr)(nil), pi.Addrs...) + toResolve := append([]ma.Multiaddr{}, pi.Addrs...) resolved := make([]ma.Multiaddr, 0, len(pi.Addrs)) for len(toResolve) > 0 { // pop the last addr off. @@ -368,6 +362,26 @@ func (s *Swarm) resolveAddrs(ctx context.Context, pi peer.AddrInfo) ([]ma.Multia continue } + tpt := s.TransportForDialing(addr) + resolver, ok := tpt.(transport.Resolver) + if ok { + resolvedAddrs, err := resolver.Resolve(ctx, addr) + if err != nil { + log.Warnf("Failed to resolve multiaddr %s by transport %v: %v", addr, tpt, err) + continue + } + var added bool + for _, a := range resolvedAddrs { + if !addr.Equal(a) { + toResolve = append(toResolve, a) + added = true + } + } + if added { + continue + } + } + // otherwise, resolve it reqaddr := addr.Encapsulate(p2paddr) resaddrs, err := s.maResolver.Resolve(ctx, reqaddr) @@ -388,7 +402,7 @@ func (s *Swarm) resolveAddrs(ctx context.Context, pi peer.AddrInfo) ([]ma.Multia return resolved, nil } -func (s *Swarm) dialNextAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr, resch chan dialResult) error { +func (s *Swarm) dialNextAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr, resch chan transport.DialUpdate) error { // check the dial backoff if forceDirect, _ := network.GetForceDirectDial(ctx); !forceDirect { if s.backf.Backoff(p, addr) { @@ -402,23 +416,20 @@ func (s *Swarm) dialNextAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr, return nil } -func (s *Swarm) canDial(addr ma.Multiaddr) bool { - t := s.TransportForDialing(addr) - return t != nil && t.CanDial(addr) -} - func (s *Swarm) nonProxyAddr(addr ma.Multiaddr) bool { t := s.TransportForDialing(addr) return !t.Proxy() } +var quicDraft29DialMatcher = mafmt.And(mafmt.IP, mafmt.Base(ma.P_UDP), mafmt.Base(ma.P_QUIC)) + // filterKnownUndialables takes a list of multiaddrs, and removes those // that we definitely don't want to dial: addresses configured to be blocked, // IPv6 link-local addresses, addresses without a dial-capable transport, -// addresses that we know to be our own, and addresses with a better tranport +// addresses that we know to be our own, and addresses with a better transport // available. This is an optimization to avoid wasting time on dials that we // know are going to fail or for which we have a better alternative. -func (s *Swarm) filterKnownUndialables(p peer.ID, addrs []ma.Multiaddr) []ma.Multiaddr { +func (s *Swarm) filterKnownUndialables(p peer.ID, addrs []ma.Multiaddr) (goodAddrs []ma.Multiaddr, addrErrs []TransportError) { lisAddrs, _ := s.InterfaceListenAddresses() var ourAddrs []ma.Multiaddr for _, addr := range lisAddrs { @@ -431,35 +442,71 @@ func (s *Swarm) filterKnownUndialables(p peer.ID, addrs []ma.Multiaddr) []ma.Mul }) } - // The order of these two filters is important. If we can only dial /webtransport, - // we don't want to filter /webtransport addresses out because the peer had a /quic-v1 - // address + addrErrs = make([]TransportError, 0, len(addrs)) - // filter addresses we cannot dial - addrs = ma.FilterAddrs(addrs, s.canDial) + // The order of checking for transport and filtering low priority addrs is important. If we + // can only dial /webtransport, we don't want to filter /webtransport addresses out because + // the peer had a /quic-v1 address + + // filter addresses with no transport + addrs = ma.FilterAddrs(addrs, func(a ma.Multiaddr) bool { + if s.TransportForDialing(a) == nil { + e := ErrNoTransport + // We used to support QUIC draft-29 for a long time. + // Provide a more useful error when attempting to dial a QUIC draft-29 address. + if quicDraft29DialMatcher.Matches(a) { + e = ErrQUICDraft29 + } + addrErrs = append(addrErrs, TransportError{Address: a, Cause: e}) + return false + } + return true + }) // filter low priority addresses among the addresses we can dial + // We don't return an error for these addresses addrs = filterLowPriorityAddresses(addrs) // remove black holed addrs - addrs = s.bhd.FilterAddrs(addrs) + addrs, blackHoledAddrs := s.bhd.FilterAddrs(addrs) + for _, a := range blackHoledAddrs { + addrErrs = append(addrErrs, TransportError{Address: a, Cause: ErrDialRefusedBlackHole}) + } return ma.FilterAddrs(addrs, - func(addr ma.Multiaddr) bool { return !ma.Contains(ourAddrs, addr) }, + // Linux and BSD treat an unspecified address when dialing as a localhost address. + // Windows doesn't support this. We filter all such addresses out because peers + // listening on unspecified addresses will advertise more specific addresses. + // https://unix.stackexchange.com/a/419881 + // https://superuser.com/a/1755455 + func(addr ma.Multiaddr) bool { + return !manet.IsIPUnspecified(addr) + }, + func(addr ma.Multiaddr) bool { + if ma.Contains(ourAddrs, addr) { + addrErrs = append(addrErrs, TransportError{Address: addr, Cause: ErrDialToSelf}) + return false + } + return true + }, // TODO: Consider allowing link-local addresses func(addr ma.Multiaddr) bool { return !manet.IsIP6LinkLocal(addr) }, func(addr ma.Multiaddr) bool { - return s.gater == nil || s.gater.InterceptAddrDial(p, addr) + if s.gater != nil && !s.gater.InterceptAddrDial(p, addr) { + addrErrs = append(addrErrs, TransportError{Address: addr, Cause: ErrGaterDisallowedConnection}) + return false + } + return true }, - ) + ), addrErrs } // limitedDial will start a dial to the given peer when // it is able, respecting the various different types of rate // limiting that occur without using extra goroutines per addr -func (s *Swarm) limitedDial(ctx context.Context, p peer.ID, a ma.Multiaddr, resp chan dialResult) { +func (s *Swarm) limitedDial(ctx context.Context, p peer.ID, a ma.Multiaddr, resp chan transport.DialUpdate) { timeout := s.dialTimeout - if lowTimeoutFilters.AddrBlocked(a) && s.dialTimeoutLocal < s.dialTimeout { + if manet.IsPrivateAddr(a) && s.dialTimeoutLocal < s.dialTimeout { timeout = s.dialTimeoutLocal } s.limiter.AddDialJob(&dialJob{ @@ -472,7 +519,7 @@ func (s *Swarm) limitedDial(ctx context.Context, p peer.ID, a ma.Multiaddr, resp } // dialAddr is the actual dial for an addr, indirectly invoked through the limiter -func (s *Swarm) dialAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr) (transport.CapableConn, error) { +func (s *Swarm) dialAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr, updCh chan<- transport.DialUpdate) (transport.CapableConn, error) { // Just to double check. Costs nothing. if s.local == p { return nil, ErrDialToSelf @@ -490,16 +537,22 @@ func (s *Swarm) dialAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr) (tra } start := time.Now() - connC, err := tpt.Dial(ctx, addr, p) + var connC transport.CapableConn + var err error + if du, ok := tpt.(transport.DialUpdater); ok { + connC, err = du.DialWithUpdates(ctx, addr, p, updCh) + } else { + connC, err = tpt.Dial(ctx, addr, p) + } // We're recording any error as a failure here. - // Notably, this also applies to cancelations (i.e. if another dial attempt was faster). + // Notably, this also applies to cancellations (i.e. if another dial attempt was faster). // This is ok since the black hole detector uses a very low threshold (5%). s.bhd.RecordResult(addr, err == nil) if err != nil { if s.metricsTracer != nil { - s.metricsTracer.FailedDialing(addr, err) + s.metricsTracer.FailedDialing(addr, err, context.Cause(ctx)) } return nil, err } diff --git a/go-libp2p/p2p/net/swarm/swarm_dial_test.go b/go-libp2p/p2p/net/swarm/swarm_dial_test.go index 2f6b3f8..83f94b9 100644 --- a/go-libp2p/p2p/net/swarm/swarm_dial_test.go +++ b/go-libp2p/p2p/net/swarm/swarm_dial_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "crypto/rand" + "errors" "net" "sort" "testing" @@ -65,7 +66,7 @@ func TestAddrsForDial(t *testing.T) { ps.AddAddr(otherPeer, ma.StringCast("/dns4/example.com/tcp/1234/wss"), time.Hour) ctx := context.Background() - mas, err := s.addrsForDial(ctx, otherPeer) + mas, _, err := s.addrsForDial(ctx, otherPeer) require.NoError(t, err) require.NotZero(t, len(mas)) @@ -110,10 +111,10 @@ func TestDedupAddrsForDial(t *testing.T) { ps.AddAddr(otherPeer, ma.StringCast("/ip4/1.2.3.4/tcp/1234"), time.Hour) ctx := context.Background() - mas, err := s.addrsForDial(ctx, otherPeer) + mas, _, err := s.addrsForDial(ctx, otherPeer) require.NoError(t, err) - require.Equal(t, 1, len(mas)) + require.Len(t, mas, 1) } func newTestSwarmWithResolver(t *testing.T, resolver *madns.Resolver) *Swarm { @@ -138,7 +139,7 @@ func newTestSwarmWithResolver(t *testing.T, resolver *madns.Resolver) *Swarm { err = s.AddTransport(tpt) require.NoError(t, err) - connmgr, err := quicreuse.NewConnManager(quic.StatelessResetKey{}) + connmgr, err := quicreuse.NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}) require.NoError(t, err) quicTpt, err := libp2pquic.NewTransport(priv, connmgr, nil, nil, &network.NullResourceManager{}) require.NoError(t, err) @@ -166,8 +167,8 @@ func TestAddrResolution(t *testing.T) { addr1 := ma.StringCast("/dnsaddr/example.com") addr2 := ma.StringCast("/ip4/192.0.2.1/tcp/123") - p2paddr2 := ma.StringCast("/ip4/192.0.2.1/tcp/123/p2p/" + p1.Pretty()) - p2paddr3 := ma.StringCast("/ip4/192.0.2.1/tcp/123/p2p/" + p2.Pretty()) + p2paddr2 := ma.StringCast("/ip4/192.0.2.1/tcp/123/p2p/" + p1.String()) + p2paddr3 := ma.StringCast("/ip4/192.0.2.1/tcp/123/p2p/" + p2.String()) backend := &madns.MockResolver{ TXT: map[string][]string{"_dnsaddr.example.com": { @@ -183,7 +184,7 @@ func TestAddrResolution(t *testing.T) { tctx, cancel := context.WithTimeout(ctx, time.Millisecond*100) defer cancel() - mas, err := s.addrsForDial(tctx, p1) + mas, _, err := s.addrsForDial(tctx, p1) require.NoError(t, err) require.Len(t, mas, 1) @@ -196,23 +197,16 @@ func TestAddrResolution(t *testing.T) { } func TestAddrResolutionRecursive(t *testing.T) { - ctx := context.Background() + p1 := test.RandPeerIDFatal(t) + p2 := test.RandPeerIDFatal(t) - p1, err := test.RandPeerID() - if err != nil { - t.Error(err) - } - p2, err := test.RandPeerID() - if err != nil { - t.Error(err) - } addr1 := ma.StringCast("/dnsaddr/example.com") addr2 := ma.StringCast("/ip4/192.0.2.1/tcp/123") - p2paddr1 := ma.StringCast("/dnsaddr/example.com/p2p/" + p1.Pretty()) - p2paddr2 := ma.StringCast("/dnsaddr/example.com/p2p/" + p2.Pretty()) - p2paddr1i := ma.StringCast("/dnsaddr/foo.example.com/p2p/" + p1.Pretty()) - p2paddr2i := ma.StringCast("/dnsaddr/bar.example.com/p2p/" + p2.Pretty()) - p2paddr1f := ma.StringCast("/ip4/192.0.2.1/tcp/123/p2p/" + p1.Pretty()) + p2paddr1 := ma.StringCast("/dnsaddr/example.com/p2p/" + p1.String()) + p2paddr2 := ma.StringCast("/dnsaddr/example.com/p2p/" + p2.String()) + p2paddr1i := ma.StringCast("/dnsaddr/foo.example.com/p2p/" + p1.String()) + p2paddr2i := ma.StringCast("/dnsaddr/bar.example.com/p2p/" + p2.String()) + p2paddr1f := ma.StringCast("/ip4/192.0.2.1/tcp/123/p2p/" + p1.String()) backend := &madns.MockResolver{ TXT: map[string][]string{ @@ -220,28 +214,22 @@ func TestAddrResolutionRecursive(t *testing.T) { "dnsaddr=" + p2paddr1i.String(), "dnsaddr=" + p2paddr2i.String(), }, - "_dnsaddr.foo.example.com": { - "dnsaddr=" + p2paddr1f.String(), - }, - "_dnsaddr.bar.example.com": { - "dnsaddr=" + p2paddr2i.String(), - }, + "_dnsaddr.foo.example.com": {"dnsaddr=" + p2paddr1f.String()}, + "_dnsaddr.bar.example.com": {"dnsaddr=" + p2paddr2i.String()}, }, } resolver, err := madns.NewResolver(madns.WithDefaultResolver(backend)) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) s := newTestSwarmWithResolver(t, resolver) pi1, err := peer.AddrInfoFromP2pAddr(p2paddr1) require.NoError(t, err) - tctx, cancel := context.WithTimeout(ctx, time.Millisecond*100) + tctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*100) defer cancel() s.Peerstore().AddAddrs(pi1.ID, pi1.Addrs, peerstore.TempAddrTTL) - _, err = s.addrsForDial(tctx, p1) + _, _, err = s.addrsForDial(tctx, p1) require.NoError(t, err) addrs1 := s.Peerstore().Addrs(pi1.ID) @@ -253,7 +241,7 @@ func TestAddrResolutionRecursive(t *testing.T) { require.NoError(t, err) s.Peerstore().AddAddrs(pi2.ID, pi2.Addrs, peerstore.TempAddrTTL) - _, err = s.addrsForDial(tctx, p2) + _, _, err = s.addrsForDial(tctx, p2) // This never resolves to a good address require.Equal(t, ErrNoGoodAddresses, err) @@ -262,20 +250,51 @@ func TestAddrResolutionRecursive(t *testing.T) { require.Contains(t, addrs2, addr1) } +// see https://github.com/libp2p/go-libp2p/issues/2562 +func TestAddrResolutionRecursiveTransportSpecific(t *testing.T) { + p := test.RandPeerIDFatal(t) + + backend := &madns.MockResolver{ + IP: map[string][]net.IPAddr{ + "sub.example.com": {net.IPAddr{IP: net.IPv4(1, 2, 3, 4)}}, + }, + TXT: map[string][]string{ + "_dnsaddr.example.com": {"dnsaddr=/dns4/sub.example.com/tcp/443/wss/p2p/" + p.String()}, + }, + } + resolver, err := madns.NewResolver(madns.WithDefaultResolver(backend)) + require.NoError(t, err) + + s := newTestSwarmWithResolver(t, resolver) + pi1, err := peer.AddrInfoFromP2pAddr(ma.StringCast("/dnsaddr/example.com/p2p/" + p.String())) + require.NoError(t, err) + + tctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*100) + defer cancel() + s.Peerstore().AddAddrs(pi1.ID, pi1.Addrs, peerstore.TempAddrTTL) + addrs, _, err := s.addrsForDial(tctx, p) + require.NoError(t, err) + require.Len(t, addrs, 1) + require.Equal(t, "/ip4/1.2.3.4/tcp/443/tls/sni/sub.example.com/ws", addrs[0].String()) +} + func TestAddrsForDialFiltering(t *testing.T) { - q1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic") + q1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1") q1v1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1") wt1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1/webtransport/") - q2 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic") + q2 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic-v1") q2v1 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic-v1") wt2 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic-v1/webtransport/") - q3 := ma.StringCast("/ip4/1.2.3.4/udp/3/quic") + q3 := ma.StringCast("/ip4/1.2.3.4/udp/3/quic-v1") t1 := ma.StringCast("/ip4/1.2.3.4/tcp/1") ws1 := ma.StringCast("/ip4/1.2.3.4/tcp/1/ws") + unSpecQ := ma.StringCast("/ip4/0.0.0.0/udp/2/quic-v1") + unSpecT := ma.StringCast("/ip6/::/tcp/2/") + resolver, err := madns.NewResolver(madns.WithDefaultResolver(&madns.MockResolver{})) require.NoError(t, err) s := newTestSwarmWithResolver(t, resolver) @@ -306,6 +325,11 @@ func TestAddrsForDialFiltering(t *testing.T) { input: append([]ma.Multiaddr{q1}, ourAddrs...), output: []ma.Multiaddr{q1}, }, + { + name: "unspecified-filtered", + input: []ma.Multiaddr{q1v1, t1, unSpecQ, unSpecT}, + output: []ma.Multiaddr{q1v1, t1}, + }, } ctx := context.Background() @@ -315,7 +339,7 @@ func TestAddrsForDialFiltering(t *testing.T) { t.Run(tc.name, func(t *testing.T) { s.Peerstore().ClearAddrs(p1) s.Peerstore().AddAddrs(p1, tc.input, peerstore.PermanentAddrTTL) - result, err := s.addrsForDial(ctx, p1) + result, _, err := s.addrsForDial(ctx, p1) require.NoError(t, err) sort.Slice(result, func(i, j int) bool { return bytes.Compare(result[i].Bytes(), result[j].Bytes()) < 0 }) sort.Slice(tc.output, func(i, j int) bool { return bytes.Compare(tc.output[i].Bytes(), tc.output[j].Bytes()) < 0 }) @@ -342,8 +366,9 @@ func TestBlackHoledAddrBlocked(t *testing.T) { n := 3 s.bhd.ipv6 = &blackHoleFilter{n: n, minSuccesses: 1, name: "IPv6"} - // all dials to the address will fail. RFC6666 Discard Prefix - addr := ma.StringCast("/ip6/0100::1/tcp/54321/") + // All dials to this addr will fail. + // manet.IsPublic is aggressive for IPv6 addresses. Use a NAT64 address. + addr := ma.StringCast("/ip6/64:ff9b::1.2.3.4/tcp/54321/") p, err := test.RandPeerID() if err != nil { @@ -366,10 +391,10 @@ func TestBlackHoledAddrBlocked(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer cancel() conn, err := s.DialPeer(ctx, p) - if conn != nil { - t.Fatalf("expected dial to be blocked") - } - if err != ErrNoGoodAddresses { + require.Nil(t, conn) + var de *DialError + if !errors.As(err, &de) { t.Fatalf("expected to receive an error of type *DialError, got %s of type %T", err, err) } + require.ErrorIs(t, err, ErrDialRefusedBlackHole) } diff --git a/go-libp2p/p2p/net/swarm/swarm_event_test.go b/go-libp2p/p2p/net/swarm/swarm_event_test.go index 86d698d..5010215 100644 --- a/go-libp2p/p2p/net/swarm/swarm_event_test.go +++ b/go-libp2p/p2p/net/swarm/swarm_event_test.go @@ -2,6 +2,7 @@ package swarm_test import ( "context" + "sync" "testing" "time" @@ -12,6 +13,7 @@ import ( swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing" ma "github.com/multiformats/go-multiaddr" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -66,6 +68,10 @@ func TestConnectednessEventsSingleConn(t *testing.T) { } func TestNoDeadlockWhenConsumingConnectednessEvents(t *testing.T) { + ctx := context.Background() + ctx, cancel := context.WithCancel(ctx) + defer cancel() + dialerEventBus := eventbus.NewBus() dialer := swarmt.GenSwarm(t, swarmt.OptDialOnly, swarmt.EventBus(dialerEventBus)) defer dialer.Close() @@ -85,10 +91,6 @@ func TestNoDeadlockWhenConsumingConnectednessEvents(t *testing.T) { sub, err := dialerEventBus.Subscribe(new(event.EvtPeerConnectednessChanged)) require.NoError(t, err) - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - // A slow consumer go func() { for { @@ -113,3 +115,196 @@ func TestNoDeadlockWhenConsumingConnectednessEvents(t *testing.T) { // The test should finish without deadlocking } + +func TestConnectednessEvents(t *testing.T) { + s1, sub1 := newSwarmWithSubscription(t) + const N = 100 + peers := make([]*Swarm, N) + for i := 0; i < N; i++ { + peers[i] = swarmt.GenSwarm(t) + } + + // First check all connected events + done := make(chan struct{}) + go func() { + defer close(done) + for i := 0; i < N; i++ { + e := <-sub1.Out() + evt, ok := e.(event.EvtPeerConnectednessChanged) + if !ok { + t.Error("invalid event received", e) + return + } + if evt.Connectedness != network.Connected { + t.Errorf("invalid event received: expected: Connected, got: %s", evt) + return + } + } + }() + for i := 0; i < N; i++ { + s1.Peerstore().AddAddrs(peers[i].LocalPeer(), []ma.Multiaddr{peers[i].ListenAddresses()[0]}, time.Hour) + _, err := s1.DialPeer(context.Background(), peers[i].LocalPeer()) + require.NoError(t, err) + } + select { + case <-done: + case <-time.After(10 * time.Second): + t.Fatal("expected all connectedness events to be completed") + } + + // Disconnect some peers + done = make(chan struct{}) + go func() { + defer close(done) + for i := 0; i < N/2; i++ { + e := <-sub1.Out() + evt, ok := e.(event.EvtPeerConnectednessChanged) + if !ok { + t.Error("invalid event received", e) + return + } + if evt.Connectedness != network.NotConnected { + t.Errorf("invalid event received: expected: NotConnected, got: %s", evt) + return + } + } + }() + for i := 0; i < N/2; i++ { + err := s1.ClosePeer(peers[i].LocalPeer()) + require.NoError(t, err) + } + select { + case <-done: + case <-time.After(10 * time.Second): + t.Fatal("expected all disconnected events to be completed") + } + + // Check for disconnected events on swarm close + done = make(chan struct{}) + go func() { + defer close(done) + for i := N / 2; i < N; i++ { + e := <-sub1.Out() + evt, ok := e.(event.EvtPeerConnectednessChanged) + if !ok { + t.Error("invalid event received", e) + return + } + if evt.Connectedness != network.NotConnected { + t.Errorf("invalid event received: expected: NotConnected, got: %s", evt) + return + } + } + }() + s1.Close() + select { + case <-done: + case <-time.After(10 * time.Second): + t.Fatal("expected all disconnected events after swarm close to be completed") + } +} + +func TestConnectednessEventDeadlock(t *testing.T) { + s1, sub1 := newSwarmWithSubscription(t) + const N = 100 + peers := make([]*Swarm, N) + for i := 0; i < N; i++ { + peers[i] = swarmt.GenSwarm(t) + } + + // First check all connected events + done := make(chan struct{}) + go func() { + defer close(done) + count := 0 + for count < N { + e := <-sub1.Out() + // sleep to simulate a slow consumer + evt, ok := e.(event.EvtPeerConnectednessChanged) + if !ok { + t.Error("invalid event received", e) + return + } + if evt.Connectedness != network.Connected { + continue + } + count++ + s1.ClosePeer(evt.Peer) + } + }() + for i := 0; i < N; i++ { + s1.Peerstore().AddAddrs(peers[i].LocalPeer(), []ma.Multiaddr{peers[i].ListenAddresses()[0]}, time.Hour) + go func(i int) { + _, err := s1.DialPeer(context.Background(), peers[i].LocalPeer()) + assert.NoError(t, err) + }(i) + } + select { + case <-done: + case <-time.After(100 * time.Second): + t.Fatal("expected all connectedness events to be completed") + } +} + +func TestConnectednessEventDeadlockWithDial(t *testing.T) { + s1, sub1 := newSwarmWithSubscription(t) + const N = 200 + peers := make([]*Swarm, N) + for i := 0; i < N; i++ { + peers[i] = swarmt.GenSwarm(t) + } + peers2 := make([]*Swarm, N) + for i := 0; i < N; i++ { + peers2[i] = swarmt.GenSwarm(t) + } + + // First check all connected events + done := make(chan struct{}) + var subWG sync.WaitGroup + subWG.Add(1) + go func() { + defer subWG.Done() + count := 0 + for { + var e interface{} + select { + case e = <-sub1.Out(): + case <-done: + return + } + // sleep to simulate a slow consumer + evt, ok := e.(event.EvtPeerConnectednessChanged) + if !ok { + t.Error("invalid event received", e) + return + } + if evt.Connectedness != network.Connected { + continue + } + if count < N { + time.Sleep(10 * time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond) + s1.Peerstore().AddAddrs(peers2[count].LocalPeer(), []ma.Multiaddr{peers2[count].ListenAddresses()[0]}, time.Hour) + s1.DialPeer(ctx, peers2[count].LocalPeer()) + count++ + cancel() + } + } + }() + var wg sync.WaitGroup + wg.Add(N) + for i := 0; i < N; i++ { + s1.Peerstore().AddAddrs(peers[i].LocalPeer(), []ma.Multiaddr{peers[i].ListenAddresses()[0]}, time.Hour) + go func(i int) { + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + s1.DialPeer(ctx, peers[i].LocalPeer()) + cancel() + wg.Done() + }(i) + } + wg.Wait() + s1.Close() + + close(done) + subWG.Wait() +} diff --git a/go-libp2p/p2p/net/swarm/swarm_metrics.go b/go-libp2p/p2p/net/swarm/swarm_metrics.go index 28564e9..b5c0f2e 100644 --- a/go-libp2p/p2p/net/swarm/swarm_metrics.go +++ b/go-libp2p/p2p/net/swarm/swarm_metrics.go @@ -128,7 +128,7 @@ type MetricsTracer interface { OpenedConnection(network.Direction, crypto.PubKey, network.ConnectionState, ma.Multiaddr) ClosedConnection(network.Direction, time.Duration, network.ConnectionState, ma.Multiaddr) CompletedHandshake(time.Duration, network.ConnectionState, ma.Multiaddr) - FailedDialing(ma.Multiaddr, error) + FailedDialing(ma.Multiaddr, error, error) DialCompleted(success bool, totalDials int) DialRankingDelay(d time.Duration) UpdatedBlackHoleFilterState(name string, state blackHoleState, nextProbeAfter int, successFraction float64) @@ -166,7 +166,7 @@ func appendConnectionState(tags []string, cs network.ConnectionState) []string { // This shouldn't happen, unless the transport doesn't properly set the Transport field in the ConnectionState. tags = append(tags, "unknown") } else { - tags = append(tags, string(cs.Transport)) + tags = append(tags, cs.Transport) } // These might be empty, depending on the transport. // For example, QUIC doesn't set security nor muxer. @@ -216,18 +216,28 @@ func (m *metricsTracer) CompletedHandshake(t time.Duration, cs network.Connectio connHandshakeLatency.WithLabelValues(*tags...).Observe(t.Seconds()) } -func (m *metricsTracer) FailedDialing(addr ma.Multiaddr, err error) { +func (m *metricsTracer) FailedDialing(addr ma.Multiaddr, dialErr error, cause error) { transport := metricshelper.GetTransport(addr) e := "other" - if errors.Is(err, context.Canceled) { - e = "canceled" - } else if errors.Is(err, context.DeadlineExceeded) { + // dial deadline exceeded or the the parent contexts deadline exceeded + if errors.Is(dialErr, context.DeadlineExceeded) || errors.Is(cause, context.DeadlineExceeded) { e = "deadline" + } else if errors.Is(dialErr, context.Canceled) { + // dial was cancelled. + if errors.Is(cause, context.Canceled) { + // parent context was canceled + e = "application canceled" + } else if errors.Is(cause, errConcurrentDialSuccessful) { + e = "canceled: concurrent dial successful" + } else { + // something else + e = "canceled: other" + } } else { - nerr, ok := err.(net.Error) + nerr, ok := dialErr.(net.Error) if ok && nerr.Timeout() { e = "timeout" - } else if strings.Contains(err.Error(), "connect: connection refused") { + } else if strings.Contains(dialErr.Error(), "connect: connection refused") { e = "connection refused" } } diff --git a/go-libp2p/p2p/net/swarm/swarm_metrics_test.go b/go-libp2p/p2p/net/swarm/swarm_metrics_test.go index 25e13f3..e415c55 100644 --- a/go-libp2p/p2p/net/swarm/swarm_metrics_test.go +++ b/go-libp2p/p2p/net/swarm/swarm_metrics_test.go @@ -29,7 +29,7 @@ func BenchmarkMetricsConnOpen(b *testing.B) { } _, pub, err := crypto.GenerateEd25519Key(rand.Reader) require.NoError(b, err) - quicAddr := ma.StringCast("/ip4/1.2.3.4/udp/1/quic") + quicAddr := ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1") tcpAddr := ma.StringCast("/ip4/1.2.3.4/tcp/1/") tr := NewMetricsTracer() for i := 0; i < b.N; i++ { @@ -53,7 +53,7 @@ func TestMetricsNoAllocNoCover(t *testing.T) { {StreamMultiplexer: "yamux", Security: "tls", Transport: "tcp", UsedEarlyMuxerNegotiation: true}, {StreamMultiplexer: "yamux", Security: "noise", Transport: "tcp", UsedEarlyMuxerNegotiation: false}, {StreamMultiplexer: "", Security: "", Transport: "quic"}, - {StreamMultiplexer: "mplex", Security: "noise", Transport: "tcp"}, + {StreamMultiplexer: "another-yamux", Security: "noise", Transport: "tcp"}, } directions := []network.Direction{network.DirInbound, network.DirOutbound} @@ -91,7 +91,7 @@ func TestMetricsNoAllocNoCover(t *testing.T) { "CompletedHandshake": func() { mt.CompletedHandshake(time.Duration(mrand.Intn(100))*time.Second, randItem(connections), randItem(addrs)) }, - "FailedDialing": func() { mt.FailedDialing(randItem(addrs), randItem(errors)) }, + "FailedDialing": func() { mt.FailedDialing(randItem(addrs), randItem(errors), randItem(errors)) }, "DialCompleted": func() { mt.DialCompleted(mrand.Intn(2) == 1, mrand.Intn(10)) }, "DialRankingDelay": func() { mt.DialRankingDelay(time.Duration(mrand.Intn(1e10))) }, "UpdatedBlackHoleFilterState": func() { diff --git a/go-libp2p/p2p/net/swarm/swarm_stream.go b/go-libp2p/p2p/net/swarm/swarm_stream.go index d372bcd..b7846ad 100644 --- a/go-libp2p/p2p/net/swarm/swarm_stream.go +++ b/go-libp2p/p2p/net/swarm/swarm_stream.go @@ -22,7 +22,10 @@ type Stream struct { conn *Conn scope network.StreamManagementScope - closeOnce sync.Once + closeMx sync.Mutex + isClosed bool + // acceptStreamGoroutineCompleted indicates whether the goroutine handling the incoming stream has exited + acceptStreamGoroutineCompleted bool protocol atomic.Pointer[protocol.ID] @@ -76,7 +79,7 @@ func (s *Stream) Write(p []byte) (int, error) { // resources. func (s *Stream) Close() error { err := s.stream.Close() - s.closeOnce.Do(s.remove) + s.closeAndRemoveStream() return err } @@ -84,10 +87,25 @@ func (s *Stream) Close() error { // associated resources. func (s *Stream) Reset() error { err := s.stream.Reset() - s.closeOnce.Do(s.remove) + s.closeAndRemoveStream() return err } +func (s *Stream) closeAndRemoveStream() { + s.closeMx.Lock() + defer s.closeMx.Unlock() + if s.isClosed { + return + } + s.isClosed = true + // We don't want to keep swarm from closing till the stream handler has exited + s.conn.swarm.refs.Done() + // Cleanup the stream from connection only after the stream handler has completed + if s.acceptStreamGoroutineCompleted { + s.conn.removeStream(s) + } +} + // CloseWrite closes the stream for writing, flushing all data and sending an EOF. // This function does not free resources, call Close or Reset when done with the // stream. @@ -101,9 +119,16 @@ func (s *Stream) CloseRead() error { return s.stream.CloseRead() } -func (s *Stream) remove() { - s.conn.removeStream(s) - s.conn.swarm.refs.Done() +func (s *Stream) completeAcceptStreamGoroutine() { + s.closeMx.Lock() + defer s.closeMx.Unlock() + if s.acceptStreamGoroutineCompleted { + return + } + s.acceptStreamGoroutineCompleted = true + if s.isClosed { + s.conn.removeStream(s) + } } // Protocol returns the protocol negotiated on this stream (if set). diff --git a/go-libp2p/p2p/net/swarm/swarm_test.go b/go-libp2p/p2p/net/swarm/swarm_test.go index 2385545..3d92690 100644 --- a/go-libp2p/p2p/net/swarm/swarm_test.go +++ b/go-libp2p/p2p/net/swarm/swarm_test.go @@ -21,11 +21,11 @@ import ( "github.com/libp2p/go-libp2p/p2p/net/swarm" . "github.com/libp2p/go-libp2p/p2p/net/swarm/testing" - "github.com/golang/mock/gomock" logging "github.com/ipfs/go-log/v2" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) var log = logging.Logger("swarm_test") @@ -390,7 +390,7 @@ func TestTypedNilConn(t *testing.T) { func TestPreventDialListenAddr(t *testing.T) { s := GenSwarm(t, OptDialOnly) - if err := s.Listen(ma.StringCast("/ip4/0.0.0.0/udp/0/quic")); err != nil { + if err := s.Listen(ma.StringCast("/ip4/0.0.0.0/udp/0/quic-v1")); err != nil { t.Fatal(err) } addrs, err := s.InterfaceListenAddresses() @@ -445,16 +445,16 @@ func TestStreamCount(t *testing.T) { <-streamAccepted } require.Eventually(t, func() bool { return len(streams) == 10 }, 5*time.Second, 10*time.Millisecond) - require.Equal(t, countStreams(), 10) + require.Equal(t, 10, countStreams()) (<-streams).Reset() (<-streams).Close() - require.Equal(t, countStreams(), 8) + require.Equal(t, 8, countStreams()) str, err := s1.NewStream(context.Background(), s2.LocalPeer()) require.NoError(t, err) - require.Equal(t, countStreams(), 9) + require.Equal(t, 9, countStreams()) str.Close() - require.Equal(t, countStreams(), 8) + require.Equal(t, 8, countStreams()) } func TestResourceManager(t *testing.T) { @@ -552,7 +552,7 @@ func TestListenCloseCount(t *testing.T) { t.Fatal(err) } listenedAddrs := s.ListenAddresses() - require.Equal(t, 2, len(listenedAddrs)) + require.Len(t, listenedAddrs, 2) var addrToClose ma.Multiaddr for _, addr := range listenedAddrs { if _, err := addr.ValueForProtocol(ma.P_QUIC_V1); err == nil { @@ -564,7 +564,7 @@ func TestListenCloseCount(t *testing.T) { s.ListenClose(addrToClose) remainingAddrs := s.ListenAddresses() - require.Equal(t, 1, len(remainingAddrs)) + require.Len(t, remainingAddrs, 1) _, err := remainingAddrs[0].ValueForProtocol(ma.P_TCP) require.NoError(t, err, "expected the TCP address to still be present") } diff --git a/go-libp2p/p2p/net/swarm/testing/testing.go b/go-libp2p/p2p/net/swarm/testing/testing.go index b052a99..627114f 100644 --- a/go-libp2p/p2p/net/swarm/testing/testing.go +++ b/go-libp2p/p2p/net/swarm/testing/testing.go @@ -21,11 +21,12 @@ import ( "github.com/libp2p/go-libp2p/p2p/muxer/yamux" "github.com/libp2p/go-libp2p/p2p/net/swarm" tptu "github.com/libp2p/go-libp2p/p2p/net/upgrader" - quic "github.com/libp2p/go-libp2p/p2p/transport/quic" + libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic" "github.com/libp2p/go-libp2p/p2p/transport/quicreuse" "github.com/libp2p/go-libp2p/p2p/transport/tcp" ma "github.com/multiformats/go-multiaddr" + "github.com/quic-go/quic-go" "github.com/stretchr/testify/require" ) @@ -175,11 +176,11 @@ func GenSwarm(t *testing.T, opts ...Option) *swarm.Swarm { } } if !cfg.disableQUIC { - reuse, err := quicreuse.NewConnManager([32]byte{}) + reuse, err := quicreuse.NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}) if err != nil { t.Fatal(err) } - quicTransport, err := quic.NewTransport(priv, reuse, nil, cfg.connectionGater, nil) + quicTransport, err := libp2pquic.NewTransport(priv, reuse, nil, cfg.connectionGater, nil) if err != nil { t.Fatal(err) } @@ -187,7 +188,7 @@ func GenSwarm(t *testing.T, opts ...Option) *swarm.Swarm { t.Fatal(err) } if !cfg.dialOnly { - if err := s.Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic")); err != nil { + if err := s.Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1")); err != nil { t.Fatal(err) } } diff --git a/go-libp2p/p2p/net/swarm/util_test.go b/go-libp2p/p2p/net/swarm/util_test.go index 66246b5..ab9baa7 100644 --- a/go-libp2p/p2p/net/swarm/util_test.go +++ b/go-libp2p/p2p/net/swarm/util_test.go @@ -20,7 +20,7 @@ func TestIsFdConsuming(t *testing.T) { isFdConsuming: true, }, "quic": { - addr: "/ip4/127.0.0.1/udp/0/quic", + addr: "/ip4/127.0.0.1/udp/0/quic-v1", isFdConsuming: false, }, "addr-without-registered-transport": { diff --git a/go-libp2p/p2p/net/upgrader/listener.go b/go-libp2p/p2p/net/upgrader/listener.go index 0871d2f..8af2791 100644 --- a/go-libp2p/p2p/net/upgrader/listener.go +++ b/go-libp2p/p2p/net/upgrader/listener.go @@ -37,7 +37,7 @@ type listener struct { // Close closes the listener. func (l *listener) Close() error { - // Do this first to try to get any relevent errors. + // Do this first to try to get any relevant errors. err := l.Listener.Close() l.cancel() diff --git a/go-libp2p/p2p/net/upgrader/listener_test.go b/go-libp2p/p2p/net/upgrader/listener_test.go index 331e973..14800e5 100644 --- a/go-libp2p/p2p/net/upgrader/listener_test.go +++ b/go-libp2p/p2p/net/upgrader/listener_test.go @@ -18,10 +18,10 @@ import ( "github.com/libp2p/go-libp2p/core/transport" "github.com/libp2p/go-libp2p/p2p/net/upgrader" - "github.com/golang/mock/gomock" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) func createListener(t *testing.T, u transport.Upgrader) transport.Listener { @@ -112,7 +112,7 @@ func TestConnectionsClosedIfNotAccepted(t *testing.T) { } time.Sleep(timeout) - require.Nil(<-errCh) + require.NoError(<-errCh) } func TestFailedUpgradeOnListen(t *testing.T) { diff --git a/go-libp2p/p2p/net/upgrader/upgrader.go b/go-libp2p/p2p/net/upgrader/upgrader.go index d18c16e..3a6f8b9 100644 --- a/go-libp2p/p2p/net/upgrader/upgrader.go +++ b/go-libp2p/p2p/net/upgrader/upgrader.go @@ -152,7 +152,8 @@ func (u *upgrader) upgrade(ctx context.Context, t transport.Transport, maconn ma return nil, ipnet.ErrNotInPrivateNetwork } - sconn, security, server, err := u.setupSecurity(ctx, conn, p, dir) + isServer := dir == network.DirInbound + sconn, security, err := u.setupSecurity(ctx, conn, p, isServer) if err != nil { conn.Close() return nil, fmt.Errorf("failed to negotiate security protocol: %w", err) @@ -179,7 +180,7 @@ func (u *upgrader) upgrade(ctx context.Context, t transport.Transport, maconn ma } } - muxer, smconn, err := u.setupMuxer(ctx, sconn, server, connScope.PeerScope()) + muxer, smconn, err := u.setupMuxer(ctx, sconn, isServer, connScope.PeerScope()) if err != nil { sconn.Close() return nil, fmt.Errorf("failed to negotiate stream multiplexer: %w", err) @@ -199,20 +200,17 @@ func (u *upgrader) upgrade(ctx context.Context, t transport.Transport, maconn ma return tc, nil } -func (u *upgrader) setupSecurity(ctx context.Context, conn net.Conn, p peer.ID, dir network.Direction) (sec.SecureConn, protocol.ID, bool, error) { - isServer := dir == network.DirInbound - var st sec.SecureTransport - var err error - st, isServer, err = u.negotiateSecurity(ctx, conn, isServer) +func (u *upgrader) setupSecurity(ctx context.Context, conn net.Conn, p peer.ID, isServer bool) (sec.SecureConn, protocol.ID, error) { + st, err := u.negotiateSecurity(ctx, conn, isServer) if err != nil { - return nil, "", false, err + return nil, "", err } if isServer { sconn, err := st.SecureInbound(ctx, conn, p) - return sconn, st.ID(), true, err + return sconn, st.ID(), err } sconn, err := st.SecureOutbound(ctx, conn, p) - return sconn, st.ID(), false, err + return sconn, st.ID(), err } func (u *upgrader) negotiateMuxer(nc net.Conn, isServer bool) (*StreamMuxer, error) { @@ -308,41 +306,38 @@ func (u *upgrader) getSecurityByID(id protocol.ID) sec.SecureTransport { return nil } -func (u *upgrader) negotiateSecurity(ctx context.Context, insecure net.Conn, server bool) (sec.SecureTransport, bool, error) { +func (u *upgrader) negotiateSecurity(ctx context.Context, insecure net.Conn, server bool) (sec.SecureTransport, error) { type result struct { - proto protocol.ID - iamserver bool - err error + proto protocol.ID + err error } done := make(chan result, 1) go func() { if server { var r result - r.iamserver = true r.proto, _, r.err = u.securityMuxer.Negotiate(insecure) done <- r return } var r result - r.proto, r.iamserver, r.err = mss.SelectWithSimopenOrFail(u.securityIDs, insecure) + r.proto, r.err = mss.SelectOneOf(u.securityIDs, insecure) done <- r }() select { case r := <-done: if r.err != nil { - return nil, false, r.err + return nil, r.err } if s := u.getSecurityByID(r.proto); s != nil { - return s, r.iamserver, nil + return s, nil } - return nil, false, fmt.Errorf("selected unknown security transport: %s", r.proto) + return nil, fmt.Errorf("selected unknown security transport: %s", r.proto) case <-ctx.Done(): - // We *must* do this. We have outstanding work on the connection - // and it's no longer safe to use. + // We *must* do this. We have outstanding work on the connection, and it's no longer safe to use. insecure.Close() <-done // wait to stop using the connection. - return nil, false, ctx.Err() + return nil, ctx.Err() } } diff --git a/go-libp2p/p2p/net/upgrader/upgrader_test.go b/go-libp2p/p2p/net/upgrader/upgrader_test.go index b61ba8a..920ccaa 100644 --- a/go-libp2p/p2p/net/upgrader/upgrader_test.go +++ b/go-libp2p/p2p/net/upgrader/upgrader_test.go @@ -18,10 +18,10 @@ import ( "github.com/libp2p/go-libp2p/p2p/muxer/yamux" "github.com/libp2p/go-libp2p/p2p/net/upgrader" - "github.com/golang/mock/gomock" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) func createUpgrader(t *testing.T) (peer.ID, transport.Upgrader) { diff --git a/go-libp2p/p2p/protocol/circuitv2/client/dial.go b/go-libp2p/p2p/protocol/circuitv2/client/dial.go index ecf5d3a..2716525 100644 --- a/go-libp2p/p2p/protocol/circuitv2/client/dial.go +++ b/go-libp2p/p2p/protocol/circuitv2/client/dial.go @@ -179,7 +179,7 @@ func (c *Client) connect(s network.Stream, dest peer.AddrInfo) (*Conn, error) { // relay connection and we mark the connection as transient. var stat network.ConnStats if limit := msg.GetLimit(); limit != nil { - stat.Transient = true + stat.Limited = true stat.Extra = make(map[interface{}]interface{}) stat.Extra[StatLimitDuration] = time.Duration(limit.GetDuration()) * time.Second stat.Extra[StatLimitData] = limit.GetData() diff --git a/go-libp2p/p2p/protocol/circuitv2/client/handlers.go b/go-libp2p/p2p/protocol/circuitv2/client/handlers.go index 6b5361b..389f0e4 100644 --- a/go-libp2p/p2p/protocol/circuitv2/client/handlers.go +++ b/go-libp2p/p2p/protocol/circuitv2/client/handlers.go @@ -22,6 +22,8 @@ func (c *Client) handleStreamV2(s network.Stream) { defer rd.Close() writeResponse := func(status pbv2.Status) error { + s.SetWriteDeadline(time.Now().Add(StreamTimeout)) + defer s.SetWriteDeadline(time.Time{}) wr := util.NewDelimitedWriter(s) var msg pbv2.StopMessage @@ -67,7 +69,7 @@ func (c *Client) handleStreamV2(s network.Stream) { // relay connection and we mark the connection as transient. var stat network.ConnStats if limit := msg.GetLimit(); limit != nil { - stat.Transient = true + stat.Limited = true stat.Extra = make(map[interface{}]interface{}) stat.Extra[StatLimitDuration] = time.Duration(limit.GetDuration()) * time.Second stat.Extra[StatLimitData] = limit.GetData() diff --git a/go-libp2p/p2p/protocol/circuitv2/client/transport.go b/go-libp2p/p2p/protocol/circuitv2/client/transport.go index e08d557..2c9e49f 100644 --- a/go-libp2p/p2p/protocol/circuitv2/client/transport.go +++ b/go-libp2p/p2p/protocol/circuitv2/client/transport.go @@ -50,6 +50,7 @@ var _ io.Closer = (*Client)(nil) func (c *Client) Dial(ctx context.Context, a ma.Multiaddr, p peer.ID) (transport.CapableConn, error) { connScope, err := c.host.Network().ResourceManager().OpenConnection(network.DirOutbound, false, a) + if err != nil { return nil, err } diff --git a/go-libp2p/p2p/protocol/circuitv2/relay/constraints.go b/go-libp2p/p2p/protocol/circuitv2/relay/constraints.go index 2435308..28698d9 100644 --- a/go-libp2p/p2p/protocol/circuitv2/relay/constraints.go +++ b/go-libp2p/p2p/protocol/circuitv2/relay/constraints.go @@ -29,7 +29,7 @@ type constraints struct { total []time.Time peers map[peer.ID][]time.Time ips map[string][]time.Time - asns map[string][]time.Time + asns map[uint32][]time.Time } // newConstraints creates a new constraints object. @@ -40,7 +40,7 @@ func newConstraints(rc *Resources) *constraints { rc: rc, peers: make(map[peer.ID][]time.Time), ips: make(map[string][]time.Time), - asns: make(map[string][]time.Time), + asns: make(map[uint32][]time.Time), } } @@ -73,10 +73,10 @@ func (c *constraints) AddReservation(p peer.ID, a ma.Multiaddr) error { } var asnReservations []time.Time - var asn string + var asn uint32 if ip.To4() == nil { - asn, _ = asnutil.Store.AsnForIPv6(ip) - if asn != "" { + asn = asnutil.AsnForIPv6(ip) + if asn != 0 { asnReservations = c.asns[asn] if len(asnReservations) >= c.rc.MaxReservationsPerASN { return errTooManyReservationsForASN @@ -93,7 +93,7 @@ func (c *constraints) AddReservation(p peer.ID, a ma.Multiaddr) error { ipReservations = append(ipReservations, expiry) c.ips[ip.String()] = ipReservations - if asn != "" { + if asn != 0 { asnReservations = append(asnReservations, expiry) c.asns[asn] = asnReservations } diff --git a/go-libp2p/p2p/protocol/circuitv2/relay/relay.go b/go-libp2p/p2p/protocol/circuitv2/relay/relay.go index e3c8f47..1629a6d 100644 --- a/go-libp2p/p2p/protocol/circuitv2/relay/relay.go +++ b/go-libp2p/p2p/protocol/circuitv2/relay/relay.go @@ -19,7 +19,6 @@ import ( logging "github.com/ipfs/go-log/v2" pool "github.com/libp2p/go-buffer-pool" - asnutil "github.com/libp2p/go-libp2p-asn-util" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" ) @@ -296,7 +295,7 @@ func (r *Relay) handleConnect(s network.Stream, msg *pbv2.HopMessage) pbv2.Statu destConns := r.conns[dest.ID] if destConns >= r.rc.MaxCircuits { r.mx.Unlock() - log.Debugf("refusing connection from %s to %s; too many connecitons to %s", src, dest.ID, dest.ID) + log.Debugf("refusing connection from %s to %s; too many connections to %s", src, dest.ID, dest.ID) fail(pbv2.Status_RESOURCE_LIMIT_EXCEEDED) return pbv2.Status_RESOURCE_LIMIT_EXCEEDED } @@ -557,6 +556,8 @@ func (r *Relay) handleError(s network.Stream, status pbv2.Status) { } func (r *Relay) writeResponse(s network.Stream, status pbv2.Status, rsvp *pbv2.Reservation, limit *pbv2.Limit) error { + s.SetWriteDeadline(time.Now().Add(StreamTimeout)) + defer s.SetWriteDeadline(time.Time{}) wr := util.NewDelimitedWriter(s) var msg pbv2.HopMessage @@ -624,8 +625,6 @@ func (r *Relay) makeLimitMsg(p peer.ID) *pbv2.Limit { } func (r *Relay) background() { - asnutil.Store.Init() - ticker := time.NewTicker(time.Minute) defer ticker.Stop() diff --git a/go-libp2p/p2p/protocol/circuitv2/relay/relay_test.go b/go-libp2p/p2p/protocol/circuitv2/relay/relay_test.go index a229fe4..e5d32b0 100644 --- a/go-libp2p/p2p/protocol/circuitv2/relay/relay_test.go +++ b/go-libp2p/p2p/protocol/circuitv2/relay/relay_test.go @@ -10,6 +10,7 @@ import ( "time" "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/event" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/metrics" "github.com/libp2p/go-libp2p/core/network" @@ -23,6 +24,7 @@ import ( "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/client" "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/relay" "github.com/libp2p/go-libp2p/p2p/transport/tcp" + "github.com/stretchr/testify/require" ma "github.com/multiformats/go-multiaddr" ) @@ -49,7 +51,8 @@ func getNetHosts(t *testing.T, ctx context.Context, n int) (hosts []host.Host, u } bwr := metrics.NewBandwidthCounter() - netw, err := swarm.NewSwarm(p, ps, eventbus.NewBus(), swarm.WithMetrics(bwr)) + bus := eventbus.NewBus() + netw, err := swarm.NewSwarm(p, ps, bus, swarm.WithMetrics(bwr)) if err != nil { t.Fatal(err) } @@ -70,7 +73,7 @@ func getNetHosts(t *testing.T, ctx context.Context, n int) (hosts []host.Host, u t.Fatal(err) } - h := bhost.NewBlankHost(netw) + h := bhost.NewBlankHost(netw, bhost.WithEventBus(bus)) hosts = append(hosts, h) } @@ -145,20 +148,41 @@ func TestBasicRelay(t *testing.T) { t.Fatal(err) } + sub, err := hosts[2].EventBus().Subscribe(new(event.EvtPeerConnectednessChanged)) + require.NoError(t, err) + err = hosts[2].Connect(ctx, peer.AddrInfo{ID: hosts[0].ID(), Addrs: []ma.Multiaddr{raddr}}) if err != nil { t.Fatal(err) } + for { + var e interface{} + select { + case e = <-sub.Out(): + case <-time.After(2 * time.Second): + t.Fatal("expected limited connectivity event") + } + evt, ok := e.(event.EvtPeerConnectednessChanged) + if !ok { + t.Fatalf("invalid event: %s", e) + } + if evt.Peer == hosts[0].ID() { + if evt.Connectedness != network.Limited { + t.Fatalf("expected limited connectivity %s", evt.Connectedness) + } + break + } + } conns := hosts[2].Network().ConnsToPeer(hosts[0].ID()) if len(conns) != 1 { t.Fatalf("expected 1 connection, but got %d", len(conns)) } - if !conns[0].Stat().Transient { + if !conns[0].Stat().Limited { t.Fatal("expected transient connection") } - s, err := hosts[2].NewStream(network.WithUseTransient(ctx, "test"), hosts[0].ID(), "test") + s, err := hosts[2].NewStream(network.WithAllowLimitedConn(ctx, "test"), hosts[0].ID(), "test") if err != nil { t.Fatal(err) } @@ -229,11 +253,11 @@ func TestRelayLimitTime(t *testing.T) { if len(conns) != 1 { t.Fatalf("expected 1 connection, but got %d", len(conns)) } - if !conns[0].Stat().Transient { + if !conns[0].Stat().Limited { t.Fatal("expected transient connection") } - s, err := hosts[2].NewStream(network.WithUseTransient(ctx, "test"), hosts[0].ID(), "test") + s, err := hosts[2].NewStream(network.WithAllowLimitedConn(ctx, "test"), hosts[0].ID(), "test") if err != nil { t.Fatal(err) } @@ -315,11 +339,11 @@ func TestRelayLimitData(t *testing.T) { if len(conns) != 1 { t.Fatalf("expected 1 connection, but got %d", len(conns)) } - if !conns[0].Stat().Transient { + if !conns[0].Stat().Limited { t.Fatal("expected transient connection") } - s, err := hosts[2].NewStream(network.WithUseTransient(ctx, "test"), hosts[0].ID(), "test") + s, err := hosts[2].NewStream(network.WithAllowLimitedConn(ctx, "test"), hosts[0].ID(), "test") if err != nil { t.Fatal(err) } diff --git a/go-libp2p/p2p/protocol/holepunch/holepunch_test.go b/go-libp2p/p2p/protocol/holepunch/holepunch_test.go index 29d589c..23593c7 100644 --- a/go-libp2p/p2p/protocol/holepunch/holepunch_test.go +++ b/go-libp2p/p2p/protocol/holepunch/holepunch_test.go @@ -96,8 +96,8 @@ func TestNoHolePunchIfDirectConnExists(t *testing.T) { require.GreaterOrEqual(t, nc2, 1) require.NoError(t, hps.DirectConnect(h2.ID())) - require.Equal(t, len(h1.Network().ConnsToPeer(h2.ID())), nc1) - require.Equal(t, len(h2.Network().ConnsToPeer(h1.ID())), nc2) + require.Len(t, h1.Network().ConnsToPeer(h2.ID()), nc1) + require.Len(t, h2.Network().ConnsToPeer(h1.ID()), nc2) require.Empty(t, tr.getEvents()) } @@ -120,13 +120,13 @@ func TestDirectDialWorks(t *testing.T) { h1.Peerstore().AddAddrs(h2.ID(), h2.Addrs(), peerstore.ConnectedAddrTTL) // try to hole punch without any connection and streams, if it works -> it's a direct connection - require.Len(t, h1.Network().ConnsToPeer(h2.ID()), 0) + require.Empty(t, h1.Network().ConnsToPeer(h2.ID())) require.NoError(t, h1ps.DirectConnect(h2.ID())) require.GreaterOrEqual(t, len(h1.Network().ConnsToPeer(h2.ID())), 1) require.GreaterOrEqual(t, len(h2.Network().ConnsToPeer(h1.ID())), 1) events := tr.getEvents() require.Len(t, events, 1) - require.Equal(t, events[0].Type, holepunch.DirectDialEvtT) + require.Equal(t, holepunch.DirectDialEvtT, events[0].Type) } func TestEndToEndSimConnect(t *testing.T) { @@ -247,7 +247,6 @@ func TestFailuresOnInitiator(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } }) - } } @@ -340,7 +339,7 @@ func TestFailuresOnResponder(t *testing.T) { defer h2.Close() defer relay.Close() - s, err := h2.NewStream(network.WithUseTransient(context.Background(), "holepunch"), h1.ID(), holepunch.Protocol) + s, err := h2.NewStream(network.WithAllowLimitedConn(context.Background(), "holepunch"), h1.ID(), holepunch.Protocol) require.NoError(t, err) go tc.initiator(s) @@ -361,7 +360,6 @@ func TestFailuresOnResponder(t *testing.T) { require.Len(t, errs, 1) require.Contains(t, errs[0], tc.errMsg) }) - } } diff --git a/go-libp2p/p2p/protocol/holepunch/holepuncher.go b/go-libp2p/p2p/protocol/holepunch/holepuncher.go index b651bd7..479376e 100644 --- a/go-libp2p/p2p/protocol/holepunch/holepuncher.go +++ b/go-libp2p/p2p/protocol/holepunch/holepuncher.go @@ -174,7 +174,7 @@ func (hp *holePuncher) directConnect(rp peer.ID) error { // initiateHolePunch opens a new hole punching coordination stream, // exchanges the addresses and measures the RTT. func (hp *holePuncher) initiateHolePunch(rp peer.ID) ([]ma.Multiaddr, []ma.Multiaddr, time.Duration, error) { - hpCtx := network.WithUseTransient(hp.ctx, "hole-punch") + hpCtx := network.WithAllowLimitedConn(hp.ctx, "hole-punch") sCtx := network.WithNoDial(hpCtx, "hole-punch") str, err := hp.host.NewStream(sCtx, rp, Protocol) diff --git a/go-libp2p/p2p/protocol/holepunch/metrics_noalloc_test.go b/go-libp2p/p2p/protocol/holepunch/metrics_noalloc_test.go index 968354f..eb04eed 100644 --- a/go-libp2p/p2p/protocol/holepunch/metrics_noalloc_test.go +++ b/go-libp2p/p2p/protocol/holepunch/metrics_noalloc_test.go @@ -14,14 +14,14 @@ func TestNoCoverNoAllocMetrics(t *testing.T) { addrs1 := [][]ma.Multiaddr{ { ma.StringCast("/ip4/0.0.0.0/tcp/1"), - ma.StringCast("/ip4/1.2.3.4/udp/2/quic"), + ma.StringCast("/ip4/1.2.3.4/udp/2/quic-v1"), }, nil, } addrs2 := [][]ma.Multiaddr{ { ma.StringCast("/ip4/1.2.3.4/tcp/3"), - ma.StringCast("/ip4/1.2.3.4/udp/4/quic"), + ma.StringCast("/ip4/1.2.3.4/udp/4/quic-v1"), }, nil, } diff --git a/go-libp2p/p2p/protocol/holepunch/metrics_test.go b/go-libp2p/p2p/protocol/holepunch/metrics_test.go index 6d7bf16..86cb59d 100644 --- a/go-libp2p/p2p/protocol/holepunch/metrics_test.go +++ b/go-libp2p/p2p/protocol/holepunch/metrics_test.go @@ -24,10 +24,8 @@ func TestHolePunchOutcomeCounter(t *testing.T) { t1 := ma.StringCast("/ip4/1.2.3.4/tcp/1") t2 := ma.StringCast("/ip4/1.2.3.4/tcp/2") - q1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic") - q2 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic") - q1v1 := ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1") + q2v1 := ma.StringCast("/ip4/1.2.3.4/udp/2/quic-v1") type testcase struct { name string @@ -39,35 +37,34 @@ func TestHolePunchOutcomeCounter(t *testing.T) { testcases := []testcase{ { name: "connection success", - theirAddrs: []ma.Multiaddr{t1, q1}, - ourAddrs: []ma.Multiaddr{t2, q2}, + theirAddrs: []ma.Multiaddr{t1, q1v1}, + ourAddrs: []ma.Multiaddr{t2, q2v1}, conn: &mockConnMultiaddrs{local: t1, remote: t2}, result: map[[3]string]int{ - [...]string{"ip4", "tcp", "success"}: 1, - [...]string{"ip4", "quic", "cancelled"}: 1, + [...]string{"ip4", "tcp", "success"}: 1, + [...]string{"ip4", "quic-v1", "cancelled"}: 1, }, }, { name: "connection failed", theirAddrs: []ma.Multiaddr{t1}, - ourAddrs: []ma.Multiaddr{t2, q2}, + ourAddrs: []ma.Multiaddr{t2, q2v1}, conn: nil, result: map[[3]string]int{ - [...]string{"ip4", "tcp", "failed"}: 1, - [...]string{"ip4", "quic", "no_suitable_address"}: 1, + [...]string{"ip4", "tcp", "failed"}: 1, + [...]string{"ip4", "quic-v1", "no_suitable_address"}: 1, }, }, { name: "no_suitable_address", - theirAddrs: []ma.Multiaddr{t1, q1}, - ourAddrs: []ma.Multiaddr{t2, q2, q1v1}, - conn: &mockConnMultiaddrs{local: q1, remote: q2}, + theirAddrs: []ma.Multiaddr{t1, q1v1}, + ourAddrs: []ma.Multiaddr{t2, q2v1}, + conn: &mockConnMultiaddrs{local: q1v1, remote: q2v1}, result: map[[3]string]int{ - [...]string{"ip4", "tcp", "cancelled"}: 1, - [...]string{"ip4", "quic", "failed"}: 0, - [...]string{"ip4", "quic", "success"}: 1, - [...]string{"ip4", "tcp", "success"}: 0, - [...]string{"ip4", "quic-v1", "no_suitable_address"}: 1, + [...]string{"ip4", "tcp", "cancelled"}: 1, + [...]string{"ip4", "quic-v1", "failed"}: 0, + [...]string{"ip4", "quic-v1", "success"}: 1, + [...]string{"ip4", "tcp", "success"}: 0, }, }, } diff --git a/go-libp2p/p2p/protocol/holepunch/svc.go b/go-libp2p/p2p/protocol/holepunch/svc.go index 47bf434..9de0a11 100644 --- a/go-libp2p/p2p/protocol/holepunch/svc.go +++ b/go-libp2p/p2p/protocol/holepunch/svc.go @@ -182,7 +182,7 @@ func (s *Service) incomingHolePunch(str network.Stream) (rtt time.Duration, remo } if err := str.Scope().ReserveMemory(maxMsgSize, network.ReservationPriorityAlways); err != nil { - log.Debugf("error reserving memory for stream: %s, err") + log.Debugf("error reserving memory for stream: %s", err) return 0, nil, nil, err } defer str.Scope().ReleaseMemory(maxMsgSize) @@ -196,7 +196,7 @@ func (s *Service) incomingHolePunch(str network.Stream) (rtt time.Duration, remo str.SetDeadline(time.Now().Add(StreamTimeout)) if err := rd.ReadMsg(msg); err != nil { - return 0, nil, nil, fmt.Errorf("failed to read message from initator: %w", err) + return 0, nil, nil, fmt.Errorf("failed to read message from initiator: %w", err) } if t := msg.GetType(); t != pb.HolePunch_CONNECT { return 0, nil, nil, fmt.Errorf("expected CONNECT message from initiator but got %d", t) @@ -218,13 +218,13 @@ func (s *Service) incomingHolePunch(str network.Stream) (rtt time.Duration, remo msg.ObsAddrs = addrsToBytes(ownAddrs) tstart := time.Now() if err := wr.WriteMsg(msg); err != nil { - return 0, nil, nil, fmt.Errorf("failed to write CONNECT message to initator: %w", err) + return 0, nil, nil, fmt.Errorf("failed to write CONNECT message to initiator: %w", err) } // Read SYNC message msg.Reset() if err := rd.ReadMsg(msg); err != nil { - return 0, nil, nil, fmt.Errorf("failed to read message from initator: %w", err) + return 0, nil, nil, fmt.Errorf("failed to read message from initiator: %w", err) } if t := msg.GetType(); t != pb.HolePunch_SYNC { return 0, nil, nil, fmt.Errorf("expected SYNC message from initiator but got %d", t) diff --git a/go-libp2p/p2p/protocol/identify/id.go b/go-libp2p/p2p/protocol/identify/id.go index 6c07dbd..a91cc4f 100644 --- a/go-libp2p/p2p/protocol/identify/id.go +++ b/go-libp2p/p2p/protocol/identify/id.go @@ -34,24 +34,27 @@ import ( var log = logging.Logger("net/identify") +var Timeout = 30 * time.Second // timeout on all incoming Identify interactions + const ( // ID is the protocol.ID of version 1.0.0 of the identify service. ID = "/ipfs/id/1.0.0" // IDPush is the protocol.ID of the Identify push protocol. // It sends full identify messages containing the current state of the peer. IDPush = "/ipfs/id/push/1.0.0" -) -const ServiceName = "libp2p.identify" + ServiceName = "libp2p.identify" -const maxPushConcurrency = 32 - -var Timeout = 60 * time.Second // timeout on all incoming Identify interactions - -const ( - legacyIDSize = 2 * 1024 // 2k Bytes - signedIDSize = 8 * 1024 // 8K - maxMessages = 10 + legacyIDSize = 2 * 1024 + signedIDSize = 8 * 1024 + maxOwnIdentifyMsgSize = 4 * 1024 // smaller than what we accept. This is 4k to be compatible with rust-libp2p + maxMessages = 10 + maxPushConcurrency = 32 + // number of addresses to keep for peers we have disconnected from for peerstore.RecentlyConnectedTTL time + // This number can be small as we already filter peer addresses based on whether the peer is connected to us over + // localhost, private IP or public IP address + recentlyConnectedPeerMaxAddrs = 20 + connectedPeerMaxAddrs = 500 ) var defaultUserAgent = "github.com/libp2p/go-libp2p" @@ -159,7 +162,8 @@ type idService struct { addrMu sync.Mutex // our own observed addresses. - observedAddrs *ObservedAddrManager + observedAddrMgr *ObservedAddrManager + disableObservedAddrManager bool emitters struct { evtPeerProtocolsUpdated event.Emitter @@ -171,6 +175,12 @@ type idService struct { sync.Mutex snapshot identifySnapshot } + + natEmitter *natEmitter +} + +type normalizer interface { + NormalizeMultiaddr(ma.Multiaddr) ma.Multiaddr } // NewIDService constructs a new *idService and activates it by @@ -199,11 +209,27 @@ func NewIDService(h host.Host, opts ...Option) (*idService, error) { metricsTracer: cfg.metricsTracer, } - observedAddrs, err := NewObservedAddrManager(h) - if err != nil { - return nil, fmt.Errorf("failed to create observed address manager: %s", err) + var normalize func(ma.Multiaddr) ma.Multiaddr + if hn, ok := h.(normalizer); ok { + normalize = hn.NormalizeMultiaddr + } + + var err error + if cfg.disableObservedAddrManager { + s.disableObservedAddrManager = true + } else { + observedAddrs, err := NewObservedAddrManager(h.Network().ListenAddresses, + h.Addrs, h.Network().InterfaceListenAddresses, normalize) + if err != nil { + return nil, fmt.Errorf("failed to create observed address manager: %s", err) + } + natEmitter, err := newNATEmitter(h, observedAddrs, time.Minute) + if err != nil { + return nil, fmt.Errorf("failed to create nat emitter: %s", err) + } + s.natEmitter = natEmitter + s.observedAddrMgr = observedAddrs } - s.observedAddrs = observedAddrs s.emitters.evtPeerProtocolsUpdated, err = h.EventBus().Emitter(&event.EvtPeerProtocolsUpdated{}) if err != nil { @@ -341,17 +367,26 @@ func (ids *idService) sendPushes(ctx context.Context) { // Close shuts down the idService func (ids *idService) Close() error { ids.ctxCancel() - ids.observedAddrs.Close() + if !ids.disableObservedAddrManager { + ids.observedAddrMgr.Close() + ids.natEmitter.Close() + } ids.refCount.Wait() return nil } func (ids *idService) OwnObservedAddrs() []ma.Multiaddr { - return ids.observedAddrs.Addrs() + if ids.disableObservedAddrManager { + return nil + } + return ids.observedAddrMgr.Addrs() } func (ids *idService) ObservedAddrsFor(local ma.Multiaddr) []ma.Multiaddr { - return ids.observedAddrs.AddrsFor(local) + if ids.disableObservedAddrManager { + return nil + } + return ids.observedAddrMgr.AddrsFor(local) } // IdentifyConn runs the Identify protocol on a connection. @@ -400,8 +435,6 @@ func (ids *idService) IdentifyWait(c network.Conn) <-chan struct{} { ids.emitters.evtPeerIdentificationFailed.Emit(event.EvtPeerIdentificationFailed{Peer: c.RemotePeer(), Reason: err}) return } - - ids.emitters.evtPeerIdentificationCompleted.Emit(event.EvtPeerIdentificationCompleted{Peer: c.RemotePeer()}) }() return e.IdentifyWaitChan @@ -410,7 +443,7 @@ func (ids *idService) IdentifyWait(c network.Conn) <-chan struct{} { func (ids *idService) identifyConn(c network.Conn) error { ctx, cancel := context.WithTimeout(context.Background(), Timeout) defer cancel() - s, err := c.NewStream(network.WithUseTransient(ctx, "identify")) + s, err := c.NewStream(network.WithAllowLimitedConn(ctx, "identify")) if err != nil { log.Debugw("error opening identify stream", "peer", c.RemotePeer(), "error", err) return err @@ -555,10 +588,18 @@ func readAllIDMessages(r pbio.Reader, finalMsg proto.Message) error { } func (ids *idService) updateSnapshot() (updated bool) { - addrs := ids.Host.Addrs() - slices.SortFunc(addrs, func(a, b ma.Multiaddr) int { return bytes.Compare(a.Bytes(), b.Bytes()) }) protos := ids.Host.Mux().Protocols() slices.Sort(protos) + + addrs := ids.Host.Addrs() + slices.SortFunc(addrs, func(a, b ma.Multiaddr) int { return bytes.Compare(a.Bytes(), b.Bytes()) }) + + usedSpace := len(ids.ProtocolVersion) + len(ids.UserAgent) + for i := 0; i < len(protos); i++ { + usedSpace += len(protos[i]) + } + addrs = trimHostAddrList(addrs, maxOwnIdentifyMsgSize-usedSpace-256) // 256 bytes of buffer + snapshot := identifySnapshot{ addrs: addrs, protocols: protos, @@ -711,8 +752,16 @@ func (ids *idService) consumeMessage(mes *pb.Identify, c network.Conn, isPush bo }) } - // mes.ObservedAddr - ids.consumeObservedAddress(mes.GetObservedAddr(), c) + obsAddr, err := ma.NewMultiaddrBytes(mes.GetObservedAddr()) + if err != nil { + log.Debugf("error parsing received observed addr for %s: %s", c, err) + obsAddr = nil + } + + if obsAddr != nil && !ids.disableObservedAddrManager { + // TODO refactor this to use the emitted events instead of having this func call explicitly. + ids.observedAddrMgr.Record(c, obsAddr) + } // mes.ListenAddrs laddrs := mes.GetListenAddrs() @@ -746,7 +795,8 @@ func (ids *idService) consumeMessage(mes *pb.Identify, c network.Conn, isPush bo // Taking the lock ensures that we don't concurrently process a disconnect. ids.addrMu.Lock() ttl := peerstore.RecentlyConnectedAddrTTL - if ids.Host.Network().Connectedness(p) == network.Connected { + switch ids.Host.Network().Connectedness(p) { + case network.Limited, network.Connected: ttl = peerstore.ConnectedAddrTTL } @@ -763,13 +813,19 @@ func (ids *idService) consumeMessage(mes *pb.Identify, c network.Conn, isPush bo signedAddrs, err := ids.consumeSignedPeerRecord(c.RemotePeer(), signedPeerRecord) if err != nil { log.Debugf("failed to consume signed peer record: %s", err) + signedPeerRecord = nil } else { addrs = signedAddrs } } else { addrs = lmaddrs } - ids.Host.Peerstore().AddAddrs(p, filterAddrs(addrs, c.RemoteMultiaddr()), ttl) + addrs = filterAddrs(addrs, c.RemoteMultiaddr()) + if len(addrs) > connectedPeerMaxAddrs { + addrs = addrs[:connectedPeerMaxAddrs] + } + + ids.Host.Peerstore().AddAddrs(p, addrs, ttl) // Finally, expire all temporary addrs. ids.Host.Peerstore().UpdateAddrs(p, peerstore.TempAddrTTL, 0) @@ -786,6 +842,18 @@ func (ids *idService) consumeMessage(mes *pb.Identify, c network.Conn, isPush bo // get the key from the other side. we may not have it (no-auth transport) ids.consumeReceivedPubKey(c, mes.PublicKey) + + ids.emitters.evtPeerIdentificationCompleted.Emit(event.EvtPeerIdentificationCompleted{ + Peer: c.RemotePeer(), + Conn: c, + ListenAddrs: lmaddrs, + Protocols: mesProtocols, + SignedPeerRecord: signedPeerRecord, + ObservedAddr: obsAddr, + ProtocolVersion: pv, + AgentVersion: av, + }) + } func (ids *idService) consumeSignedPeerRecord(p peer.ID, signedPeerRecord *record.Envelope) ([]ma.Multiaddr, error) { @@ -919,20 +987,6 @@ func HasConsistentTransport(a ma.Multiaddr, green []ma.Multiaddr) bool { return false } -func (ids *idService) consumeObservedAddress(observed []byte, c network.Conn) { - if observed == nil { - return - } - - maddr, err := ma.NewMultiaddrBytes(observed) - if err != nil { - log.Debugf("error parsing received observed addr for %s: %s", c, err) - return - } - - ids.observedAddrs.Record(c, maddr) -} - // addConnWithLock assuems caller holds the connsMu lock func (ids *idService) addConnWithLock(c network.Conn) { _, found := ids.conns[c] @@ -975,13 +1029,36 @@ func (nn *netNotifiee) Disconnected(_ network.Network, c network.Conn) { delete(ids.conns, c) ids.connsMu.Unlock() - if ids.Host.Network().Connectedness(c.RemotePeer()) != network.Connected { - // Last disconnect. - // Undo the setting of addresses to peer.ConnectedAddrTTL we did - ids.addrMu.Lock() - defer ids.addrMu.Unlock() - ids.Host.Peerstore().UpdateAddrs(c.RemotePeer(), peerstore.ConnectedAddrTTL, peerstore.RecentlyConnectedAddrTTL) + if !ids.disableObservedAddrManager { + ids.observedAddrMgr.removeConn(c) } + + // Last disconnect. + // Undo the setting of addresses to peer.ConnectedAddrTTL we did + ids.addrMu.Lock() + defer ids.addrMu.Unlock() + + // This check MUST happen after acquiring the Lock as identify on a different connection + // might be trying to add addresses. + switch ids.Host.Network().Connectedness(c.RemotePeer()) { + case network.Connected, network.Limited: + return + } + // peerstore returns the elements in a random order as it uses a map to store the addresses + addrs := ids.Host.Peerstore().Addrs(c.RemotePeer()) + n := len(addrs) + if n > recentlyConnectedPeerMaxAddrs { + // We want to always save the address we are connected to + for i, a := range addrs { + if a.Equal(c.RemoteMultiaddr()) { + addrs[i], addrs[0] = addrs[0], addrs[i] + } + } + n = recentlyConnectedPeerMaxAddrs + } + ids.Host.Peerstore().UpdateAddrs(c.RemotePeer(), peerstore.ConnectedAddrTTL, peerstore.TempAddrTTL) + ids.Host.Peerstore().AddAddrs(c.RemotePeer(), addrs[:n], peerstore.RecentlyConnectedAddrTTL) + ids.Host.Peerstore().UpdateAddrs(c.RemotePeer(), peerstore.TempAddrTTL, 0) } func (nn *netNotifiee) Listen(n network.Network, a ma.Multiaddr) {} @@ -1000,3 +1077,55 @@ func filterAddrs(addrs []ma.Multiaddr, remote ma.Multiaddr) []ma.Multiaddr { } return ma.FilterAddrs(addrs, manet.IsPublicAddr) } + +func trimHostAddrList(addrs []ma.Multiaddr, maxSize int) []ma.Multiaddr { + totalSize := 0 + for _, a := range addrs { + totalSize += len(a.Bytes()) + } + if totalSize <= maxSize { + return addrs + } + + score := func(addr ma.Multiaddr) int { + var res int + if manet.IsPublicAddr(addr) { + res |= 1 << 12 + } else if !manet.IsIPLoopback(addr) { + res |= 1 << 11 + } + var protocolWeight int + ma.ForEach(addr, func(c ma.Component) bool { + switch c.Protocol().Code { + case ma.P_QUIC_V1: + protocolWeight = 5 + case ma.P_TCP: + protocolWeight = 4 + case ma.P_WSS: + protocolWeight = 3 + case ma.P_WEBTRANSPORT: + protocolWeight = 2 + case ma.P_WEBRTC_DIRECT: + protocolWeight = 1 + case ma.P_P2P: + return false + } + return true + }) + res |= 1 << protocolWeight + return res + } + + slices.SortStableFunc(addrs, func(a, b ma.Multiaddr) int { + return score(b) - score(a) // b-a for reverse order + }) + totalSize = 0 + for i, a := range addrs { + totalSize += len(a.Bytes()) + if totalSize > maxSize { + addrs = addrs[:i] + break + } + } + return addrs +} diff --git a/go-libp2p/p2p/protocol/identify/id_glass_test.go b/go-libp2p/p2p/protocol/identify/id_glass_test.go index 777cef0..3eec26c 100644 --- a/go-libp2p/p2p/protocol/identify/id_glass_test.go +++ b/go-libp2p/p2p/protocol/identify/id_glass_test.go @@ -12,6 +12,7 @@ import ( recordPb "github.com/libp2p/go-libp2p/core/record/pb" blhost "github.com/libp2p/go-libp2p/p2p/host/blank" swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing" + ma "github.com/multiformats/go-multiaddr" "google.golang.org/protobuf/proto" "github.com/stretchr/testify/assert" @@ -173,3 +174,35 @@ func TestInvalidSignedPeerRecord(t *testing.T) { require.True(t, ok) require.Nil(t, cab.GetPeerRecord(h2.ID())) } + +func TestIncomingAddrFilter(t *testing.T) { + lhAddr := ma.StringCast("/ip4/127.0.0.1/udp/123/quic-v1") + privAddr := ma.StringCast("/ip4/192.168.1.101/tcp/123") + pubAddr := ma.StringCast("/ip6/2001::1/udp/123/quic-v1") + pubDNSAddr := ma.StringCast("/dns/example.com/udp/123/quic-v1") + privDNSAddr := ma.StringCast("/dns4/localhost/udp/123/quic-v1") + tests := []struct { + output []ma.Multiaddr + remote ma.Multiaddr + }{ + { + output: []ma.Multiaddr{lhAddr, privAddr, pubAddr, pubDNSAddr, privDNSAddr}, + remote: lhAddr, + }, + { + output: []ma.Multiaddr{privAddr, pubAddr, pubDNSAddr, privDNSAddr}, + remote: privAddr, + }, + { + output: []ma.Multiaddr{pubAddr, pubDNSAddr}, + remote: pubAddr, + }, + } + for _, tc := range tests { + t.Run(fmt.Sprintf("remote:%s", tc.remote), func(t *testing.T) { + input := []ma.Multiaddr{lhAddr, privAddr, pubAddr, pubDNSAddr, privDNSAddr} + got := filterAddrs(input, tc.remote) + require.ElementsMatch(t, tc.output, got, "%s\n%s", tc.output, got) + }) + } +} diff --git a/go-libp2p/p2p/protocol/identify/id_test.go b/go-libp2p/p2p/protocol/identify/id_test.go index b18ba51..a65d64f 100644 --- a/go-libp2p/p2p/protocol/identify/id_test.go +++ b/go-libp2p/p2p/protocol/identify/id_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "slices" "sync" "testing" "time" @@ -18,7 +19,6 @@ import ( "github.com/libp2p/go-libp2p/core/protocol" "github.com/libp2p/go-libp2p/core/record" coretest "github.com/libp2p/go-libp2p/core/test" - basichost "github.com/libp2p/go-libp2p/p2p/host/basic" blhost "github.com/libp2p/go-libp2p/p2p/host/blank" "github.com/libp2p/go-libp2p/p2p/host/eventbus" "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem" @@ -107,101 +107,156 @@ func emitAddrChangeEvt(t *testing.T, h host.Host) { // this is because it used to be concurrent. Now, Dial wait till the // id service is done. func TestIDService(t *testing.T) { - // This test is highly timing dependent, waiting on timeouts/expiration. - oldTTL := peerstore.RecentlyConnectedAddrTTL - peerstore.RecentlyConnectedAddrTTL = 500 * time.Millisecond - t.Cleanup(func() { peerstore.RecentlyConnectedAddrTTL = oldTTL }) + for _, withObsAddrManager := range []bool{false, true} { + t.Run(fmt.Sprintf("withObsAddrManager=%t", withObsAddrManager), func(t *testing.T) { + if race.WithRace() { + t.Skip("This test modifies peerstore.RecentlyConnectedAddrTTL, which is racy.") + } + // This test is highly timing dependent, waiting on timeouts/expiration. + oldTTL := peerstore.RecentlyConnectedAddrTTL + oldTempTTL := peerstore.TempAddrTTL + peerstore.RecentlyConnectedAddrTTL = 500 * time.Millisecond + peerstore.TempAddrTTL = 50 * time.Millisecond + t.Cleanup(func() { + peerstore.RecentlyConnectedAddrTTL = oldTTL + peerstore.TempAddrTTL = oldTempTTL + }) - clk := mockClock.NewMock() - swarm1 := swarmt.GenSwarm(t, swarmt.WithClock(clk)) - swarm2 := swarmt.GenSwarm(t, swarmt.WithClock(clk)) - h1 := blhost.NewBlankHost(swarm1) - h2 := blhost.NewBlankHost(swarm2) + clk := mockClock.NewMock() + swarm1 := swarmt.GenSwarm(t, swarmt.WithClock(clk)) + swarm2 := swarmt.GenSwarm(t, swarmt.WithClock(clk)) + h1 := blhost.NewBlankHost(swarm1) + h2 := blhost.NewBlankHost(swarm2) - h1p := h1.ID() - h2p := h2.ID() + h1p := h1.ID() + h2p := h2.ID() - ids1, err := identify.NewIDService(h1) + opts := []identify.Option{} + if !withObsAddrManager { + opts = append(opts, identify.DisableObservedAddrManager()) + } + ids1, err := identify.NewIDService(h1, opts...) + require.NoError(t, err) + defer ids1.Close() + ids1.Start() + + opts = []identify.Option{} + if !withObsAddrManager { + opts = append(opts, identify.DisableObservedAddrManager()) + } + ids2, err := identify.NewIDService(h2, opts...) + require.NoError(t, err) + defer ids2.Close() + ids2.Start() + + sub, err := ids1.Host.EventBus().Subscribe(new(event.EvtPeerIdentificationCompleted)) + if err != nil { + t.Fatal(err) + } + + testKnowsAddrs(t, h1, h2p, []ma.Multiaddr{}) // nothing + testKnowsAddrs(t, h2, h1p, []ma.Multiaddr{}) // nothing + + // the forgetMe addr represents an address for h1 that h2 has learned out of band + // (not via identify protocol). During the identify exchange, it will be + // forgotten and replaced by the addrs h1 sends. + forgetMe, _ := ma.NewMultiaddr("/ip4/1.2.3.4/tcp/1234") + + h2.Peerstore().AddAddr(h1p, forgetMe, peerstore.RecentlyConnectedAddrTTL) + h2pi := h2.Peerstore().PeerInfo(h2p) + require.NoError(t, h1.Connect(context.Background(), h2pi)) + + h1t2c := h1.Network().ConnsToPeer(h2p) + require.NotEmpty(t, h1t2c, "should have a conn here") + + ids1.IdentifyConn(h1t2c[0]) + + // the idService should be opened automatically, by the network. + // what we should see now is that both peers know about each others listen addresses. + t.Log("test peer1 has peer2 addrs correctly") + testKnowsAddrs(t, h1, h2p, h2.Addrs()) // has them + testHasAgentVersion(t, h1, h2p) + testHasPublicKey(t, h1, h2p, h2.Peerstore().PubKey(h2p)) // h1 should have h2's public key + + // now, this wait we do have to do. it's the wait for the Listening side + // to be done identifying the connection. + c := h2.Network().ConnsToPeer(h1.ID()) + require.NotEmpty(t, c, "should have connection by now at least.") + ids2.IdentifyConn(c[0]) + + // and the protocol versions. + t.Log("test peer2 has peer1 addrs correctly") + testKnowsAddrs(t, h2, h1p, h1.Addrs()) // has them + testHasAgentVersion(t, h2, h1p) + testHasPublicKey(t, h2, h1p, h1.Peerstore().PubKey(h1p)) // h1 should have h2's public key + + // Need both sides to actually notice that the connection has been closed. + sentDisconnect1 := waitForDisconnectNotification(swarm1) + sentDisconnect2 := waitForDisconnectNotification(swarm2) + h1.Network().ClosePeer(h2p) + h2.Network().ClosePeer(h1p) + if len(h2.Network().ConnsToPeer(h1.ID())) != 0 || len(h1.Network().ConnsToPeer(h2.ID())) != 0 { + t.Fatal("should have no connections") + } + + t.Log("testing addrs just after disconnect") + // addresses don't immediately expire on disconnect, so we should still have them + testKnowsAddrs(t, h2, h1p, h1.Addrs()) + testKnowsAddrs(t, h1, h2p, h2.Addrs()) + + <-sentDisconnect1 + <-sentDisconnect2 + + // the addrs had their TTLs reduced on disconnect, and + // will be forgotten soon after + t.Log("testing addrs after TTL expiration") + clk.Add(time.Second) + testKnowsAddrs(t, h1, h2p, []ma.Multiaddr{}) + testKnowsAddrs(t, h2, h1p, []ma.Multiaddr{}) + + // test that we received the "identify completed" event. + select { + case evtAny := <-sub.Out(): + assertCorrectEvtPeerIdentificationCompleted(t, evtAny, h2) + case <-time.After(3 * time.Second): + t.Fatalf("expected EvtPeerIdentificationCompleted event within 10 seconds; none received") + } + }) + } +} + +func assertCorrectEvtPeerIdentificationCompleted(t *testing.T, evtAny interface{}, other host.Host) { + t.Helper() + evt := evtAny.(event.EvtPeerIdentificationCompleted) + require.NotNil(t, evt.Conn) + require.Equal(t, other.ID(), evt.Peer) + + require.Equal(t, len(other.Addrs()), len(evt.ListenAddrs)) + if len(other.Addrs()) == len(evt.ListenAddrs) { + otherAddrsStrings := make([]string, len(other.Addrs())) + evtAddrStrings := make([]string, len(evt.ListenAddrs)) + for i, a := range other.Addrs() { + otherAddrsStrings[i] = a.String() + evtAddrStrings[i] = evt.ListenAddrs[i].String() + } + slices.Sort(otherAddrsStrings) + slices.Sort(evtAddrStrings) + require.Equal(t, otherAddrsStrings, evtAddrStrings) + } + + otherProtos := other.Mux().Protocols() + slices.Sort(otherProtos) + evtProtos := evt.Protocols + slices.Sort(evtProtos) + require.Equal(t, otherProtos, evtProtos) + idFromSignedRecord, err := peer.IDFromPublicKey(evt.SignedPeerRecord.PublicKey) require.NoError(t, err) - defer ids1.Close() - ids1.Start() - - ids2, err := identify.NewIDService(h2) - require.NoError(t, err) - defer ids2.Close() - ids2.Start() - - sub, err := ids1.Host.EventBus().Subscribe(new(event.EvtPeerIdentificationCompleted)) - if err != nil { - t.Fatal(err) - } - - testKnowsAddrs(t, h1, h2p, []ma.Multiaddr{}) // nothing - testKnowsAddrs(t, h2, h1p, []ma.Multiaddr{}) // nothing - - // the forgetMe addr represents an address for h1 that h2 has learned out of band - // (not via identify protocol). During the identify exchange, it will be - // forgotten and replaced by the addrs h1 sends. - forgetMe, _ := ma.NewMultiaddr("/ip4/1.2.3.4/tcp/1234") - - h2.Peerstore().AddAddr(h1p, forgetMe, peerstore.RecentlyConnectedAddrTTL) - h2pi := h2.Peerstore().PeerInfo(h2p) - require.NoError(t, h1.Connect(context.Background(), h2pi)) - - h1t2c := h1.Network().ConnsToPeer(h2p) - require.NotEmpty(t, h1t2c, "should have a conn here") - - ids1.IdentifyConn(h1t2c[0]) - - // the idService should be opened automatically, by the network. - // what we should see now is that both peers know about each others listen addresses. - t.Log("test peer1 has peer2 addrs correctly") - testKnowsAddrs(t, h1, h2p, h2.Addrs()) // has them - testHasAgentVersion(t, h1, h2p) - testHasPublicKey(t, h1, h2p, h2.Peerstore().PubKey(h2p)) // h1 should have h2's public key - - // now, this wait we do have to do. it's the wait for the Listening side - // to be done identifying the connection. - c := h2.Network().ConnsToPeer(h1.ID()) - require.NotEmpty(t, c, "should have connection by now at least.") - ids2.IdentifyConn(c[0]) - - // and the protocol versions. - t.Log("test peer2 has peer1 addrs correctly") - testKnowsAddrs(t, h2, h1p, h1.Addrs()) // has them - testHasAgentVersion(t, h2, h1p) - testHasPublicKey(t, h2, h1p, h1.Peerstore().PubKey(h1p)) // h1 should have h2's public key - - // Need both sides to actually notice that the connection has been closed. - sentDisconnect1 := waitForDisconnectNotification(swarm1) - sentDisconnect2 := waitForDisconnectNotification(swarm2) - h1.Network().ClosePeer(h2p) - h2.Network().ClosePeer(h1p) - if len(h2.Network().ConnsToPeer(h1.ID())) != 0 || len(h1.Network().ConnsToPeer(h2.ID())) != 0 { - t.Fatal("should have no connections") - } - - t.Log("testing addrs just after disconnect") - // addresses don't immediately expire on disconnect, so we should still have them - testKnowsAddrs(t, h2, h1p, h1.Addrs()) - testKnowsAddrs(t, h1, h2p, h2.Addrs()) - - <-sentDisconnect1 - <-sentDisconnect2 - - // the addrs had their TTLs reduced on disconnect, and - // will be forgotten soon after - t.Log("testing addrs after TTL expiration") - clk.Add(time.Second) - testKnowsAddrs(t, h1, h2p, []ma.Multiaddr{}) - testKnowsAddrs(t, h2, h1p, []ma.Multiaddr{}) - - // test that we received the "identify completed" event. - select { - case <-sub.Out(): - case <-time.After(3 * time.Second): - t.Fatalf("expected EvtPeerIdentificationCompleted event within 10 seconds; none received") - } + require.Equal(t, other.ID(), idFromSignedRecord) + require.Equal(t, peer.PeerRecordEnvelopePayloadType, evt.SignedPeerRecord.PayloadType) + var peerRecord peer.PeerRecord + evt.SignedPeerRecord.TypedRecord(&peerRecord) + require.Equal(t, other.ID(), peerRecord.PeerID) + require.Equal(t, other.Addrs(), peerRecord.Addrs) } func TestProtoMatching(t *testing.T) { @@ -565,8 +620,13 @@ func TestLargeIdentifyMessage(t *testing.T) { t.Skip("setting peerstore.RecentlyConnectedAddrTTL is racy") } oldTTL := peerstore.RecentlyConnectedAddrTTL + oldTempTTL := peerstore.TempAddrTTL peerstore.RecentlyConnectedAddrTTL = 500 * time.Millisecond - t.Cleanup(func() { peerstore.RecentlyConnectedAddrTTL = oldTTL }) + peerstore.TempAddrTTL = 50 * time.Millisecond + t.Cleanup(func() { + peerstore.RecentlyConnectedAddrTTL = oldTTL + peerstore.TempAddrTTL = oldTempTTL + }) clk := mockClock.NewMock() swarm1 := swarmt.GenSwarm(t, swarmt.WithClock(clk)) @@ -612,7 +672,7 @@ func TestLargeIdentifyMessage(t *testing.T) { require.NoError(t, h1.Connect(context.Background(), h2pi)) h1t2c := h1.Network().ConnsToPeer(h2p) - require.Equal(t, 1, len(h1t2c), "should have a conn here") + require.Len(t, h1t2c, 1, "should have a conn here") ids1.IdentifyConn(h1t2c[0]) @@ -663,7 +723,8 @@ func TestLargeIdentifyMessage(t *testing.T) { // test that we received the "identify completed" event. select { - case <-sub.Out(): + case evtAny := <-sub.Out(): + assertCorrectEvtPeerIdentificationCompleted(t, evtAny, h2) case <-time.After(3 * time.Second): t.Fatalf("expected EvtPeerIdentificationCompleted event within 3 seconds; none received") } @@ -841,8 +902,10 @@ func TestIncomingIDStreamsTimeout(t *testing.T) { func TestOutOfOrderConnectedNotifs(t *testing.T) { h1, err := libp2p.New(libp2p.NoListenAddrs) require.NoError(t, err) + defer h1.Close() h2, err := libp2p.New(libp2p.ListenAddrs(ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1"))) require.NoError(t, err) + defer h2.Close() doneCh := make(chan struct{}) errCh := make(chan error) @@ -850,11 +913,10 @@ func TestOutOfOrderConnectedNotifs(t *testing.T) { // This callback may be called before identify's Connnected callback completes. If it does, the IdentifyWait should still finish successfully. h1.Network().Notify(&network.NotifyBundle{ ConnectedF: func(n network.Network, c network.Conn) { - bh1 := h1.(*basichost.BasicHost) - idChan := bh1.IDService().IdentifyWait(c) + idChan := h1.(interface{ IDService() identify.IDService }).IDService().IdentifyWait(c) go func() { <-idChan - protos, err := bh1.Peerstore().GetProtocols(h2.ID()) + protos, err := h1.Peerstore().GetProtocols(h2.ID()) if err != nil { errCh <- err } diff --git a/go-libp2p/p2p/protocol/identify/nat_emitter.go b/go-libp2p/p2p/protocol/identify/nat_emitter.go new file mode 100644 index 0000000..fec9b68 --- /dev/null +++ b/go-libp2p/p2p/protocol/identify/nat_emitter.go @@ -0,0 +1,119 @@ +package identify + +import ( + "context" + "fmt" + "sync" + "time" + + "github.com/libp2p/go-libp2p/core/event" + "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/p2p/host/eventbus" +) + +type natEmitter struct { + ctx context.Context + cancel context.CancelFunc + wg sync.WaitGroup + reachabilitySub event.Subscription + reachability network.Reachability + eventInterval time.Duration + + currentUDPNATDeviceType network.NATDeviceType + currentTCPNATDeviceType network.NATDeviceType + emitNATDeviceTypeChanged event.Emitter + + observedAddrMgr *ObservedAddrManager +} + +func newNATEmitter(h host.Host, o *ObservedAddrManager, eventInterval time.Duration) (*natEmitter, error) { + ctx, cancel := context.WithCancel(context.Background()) + n := &natEmitter{ + observedAddrMgr: o, + ctx: ctx, + cancel: cancel, + eventInterval: eventInterval, + } + reachabilitySub, err := h.EventBus().Subscribe(new(event.EvtLocalReachabilityChanged), eventbus.Name("identify (nat emitter)")) + if err != nil { + return nil, fmt.Errorf("failed to subscribe to reachability event: %s", err) + } + n.reachabilitySub = reachabilitySub + + emitter, err := h.EventBus().Emitter(new(event.EvtNATDeviceTypeChanged), eventbus.Stateful) + if err != nil { + return nil, fmt.Errorf("failed to create emitter for NATDeviceType: %s", err) + } + n.emitNATDeviceTypeChanged = emitter + + n.wg.Add(1) + go n.worker() + return n, nil +} + +func (n *natEmitter) worker() { + defer n.wg.Done() + subCh := n.reachabilitySub.Out() + ticker := time.NewTicker(n.eventInterval) + pendingUpdate := false + enoughTimeSinceLastUpdate := true + for { + select { + case evt, ok := <-subCh: + if !ok { + subCh = nil + continue + } + ev, ok := evt.(event.EvtLocalReachabilityChanged) + if !ok { + log.Error("invalid event: %v", evt) + continue + } + n.reachability = ev.Reachability + case <-ticker.C: + enoughTimeSinceLastUpdate = true + if pendingUpdate { + n.maybeNotify() + pendingUpdate = false + enoughTimeSinceLastUpdate = false + } + case <-n.observedAddrMgr.addrRecordedNotif: + pendingUpdate = true + if enoughTimeSinceLastUpdate { + n.maybeNotify() + pendingUpdate = false + enoughTimeSinceLastUpdate = false + } + case <-n.ctx.Done(): + return + } + } +} + +func (n *natEmitter) maybeNotify() { + if n.reachability == network.ReachabilityPrivate { + tcpNATType, udpNATType := n.observedAddrMgr.getNATType() + if tcpNATType != n.currentTCPNATDeviceType { + n.currentTCPNATDeviceType = tcpNATType + n.emitNATDeviceTypeChanged.Emit(event.EvtNATDeviceTypeChanged{ + TransportProtocol: network.NATTransportTCP, + NatDeviceType: n.currentTCPNATDeviceType, + }) + } + if udpNATType != n.currentUDPNATDeviceType { + n.currentUDPNATDeviceType = udpNATType + n.emitNATDeviceTypeChanged.Emit(event.EvtNATDeviceTypeChanged{ + TransportProtocol: network.NATTransportUDP, + NatDeviceType: n.currentUDPNATDeviceType, + }) + } + } +} + +func (n *natEmitter) Close() { + n.cancel() + n.wg.Wait() + n.reachabilitySub.Close() + n.emitNATDeviceTypeChanged.Close() +} diff --git a/go-libp2p/p2p/protocol/identify/obsaddr.go b/go-libp2p/p2p/protocol/identify/obsaddr.go index 3466c56..4437c4b 100644 --- a/go-libp2p/p2p/protocol/identify/obsaddr.go +++ b/go-libp2p/p2p/protocol/identify/obsaddr.go @@ -3,16 +3,12 @@ package identify import ( "context" "fmt" + "net" + "slices" + "sort" "sync" - "time" - "golang.org/x/exp/slices" - - "github.com/libp2p/go-libp2p/core/event" - "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" - "github.com/libp2p/go-libp2p/core/peerstore" - "github.com/libp2p/go-libp2p/p2p/host/eventbus" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" @@ -25,214 +21,252 @@ import ( // the GC rounds set by GCInterval. var ActivationThresh = 4 -// GCInterval specicies how often to make a round cleaning seen events and -// observed addresses. An address will be cleaned if it has not been seen in -// OwnObservedAddressTTL (10 minutes). A "seen" event will be cleaned up if -// it is older than OwnObservedAddressTTL * ActivationThresh (40 minutes). -var GCInterval = 10 * time.Minute - // observedAddrManagerWorkerChannelSize defines how many addresses can be enqueued // for adding to an ObservedAddrManager. var observedAddrManagerWorkerChannelSize = 16 -// maxObservedAddrsPerIPAndTransport is the maximum number of observed addresses -// we will return for each (IPx/TCP or UDP) group. -var maxObservedAddrsPerIPAndTransport = 2 +const maxExternalThinWaistAddrsPerLocalAddr = 3 -// observation records an address observation from an "observer" (where every IP -// address is a unique observer). -type observation struct { - // seenTime is the last time this observation was made. - seenTime time.Time - // inbound indicates whether or not this observation has been made from - // an inbound connection. This remains true even if we an observation - // from a subsequent outbound connection. - inbound bool +// thinWaist is a struct that stores the address along with it's thin waist prefix and rest of the multiaddr +type thinWaist struct { + Addr, TW, Rest ma.Multiaddr } -// observedAddr is an entry for an address reported by our peers. -// We only use addresses that: -// - have been observed at least 4 times in last 40 minutes. (counter symmetric nats) -// - have been observed at least once recently (10 minutes), because our position in the -// network, or network port mapppings, may have changed. -type observedAddr struct { - addr ma.Multiaddr - seenBy map[string]observation // peer(observer) address -> observation info - lastSeen time.Time - numInbound int +// thinWaistWithCount is a thinWaist along with the count of the connection that have it as the local address +type thinWaistWithCount struct { + thinWaist + Count int } -func (oa *observedAddr) activated() bool { - - // We only activate if other peers observed the same address - // of ours at least 4 times. SeenBy peers are removed by GC if - // they say the address more than ttl*ActivationThresh - return len(oa.seenBy) >= ActivationThresh -} - -// GroupKey returns the group in which this observation belongs. Currently, an -// observed address's group is just the address with all ports set to 0. This -// means we can advertise the most commonly observed external ports without -// advertising _every_ observed port. -func (oa *observedAddr) groupKey() string { - key := make([]byte, 0, len(oa.addr.Bytes())) - ma.ForEach(oa.addr, func(c ma.Component) bool { - switch proto := c.Protocol(); proto.Code { - case ma.P_TCP, ma.P_UDP: - key = append(key, proto.VCode...) - key = append(key, 0, 0) // zero in two bytes - default: - key = append(key, c.Bytes()...) +func thinWaistForm(a ma.Multiaddr) (thinWaist, error) { + i := 0 + tw, rest := ma.SplitFunc(a, func(c ma.Component) bool { + if i > 1 { + return true } - return true + switch i { + case 0: + if c.Protocol().Code == ma.P_IP4 || c.Protocol().Code == ma.P_IP6 { + i++ + return false + } + return true + case 1: + if c.Protocol().Code == ma.P_TCP || c.Protocol().Code == ma.P_UDP { + i++ + return false + } + return true + } + return false }) - - return string(key) + if i <= 1 { + return thinWaist{}, fmt.Errorf("not a thinwaist address: %s", a) + } + return thinWaist{Addr: a, TW: tw, Rest: rest}, nil } -type newObservation struct { - conn network.Conn +// getObserver returns the observer for the multiaddress +// For an IPv4 multiaddress the observer is the IP address +// For an IPv6 multiaddress the observer is the first /56 prefix of the IP address +func getObserver(a ma.Multiaddr) (string, error) { + ip, err := manet.ToIP(a) + if err != nil { + return "", err + } + if ip4 := ip.To4(); ip4 != nil { + return ip4.String(), nil + } + // Count /56 prefix as a single observer. + return ip.Mask(net.CIDRMask(56, 128)).String(), nil +} + +// connMultiaddrs provides IsClosed along with network.ConnMultiaddrs. It is easier to mock this than network.Conn +type connMultiaddrs interface { + network.ConnMultiaddrs + IsClosed() bool +} + +// observerSetCacheSize is the number of transport sharing the same thinwaist (tcp, ws, wss), (quic, webtransport, webrtc-direct) +// This is 3 in practice right now, but keep a buffer of 3 extra elements +const observerSetCacheSize = 5 + +// observerSet is the set of observers who have observed ThinWaistAddr +type observerSet struct { + ObservedTWAddr ma.Multiaddr + ObservedBy map[string]int + + mu sync.RWMutex // protects following + cachedMultiaddrs map[string]ma.Multiaddr // cache of localMultiaddr rest(addr - thinwaist) => output multiaddr +} + +func (s *observerSet) cacheMultiaddr(addr ma.Multiaddr) ma.Multiaddr { + if addr == nil { + return s.ObservedTWAddr + } + addrStr := string(addr.Bytes()) + s.mu.RLock() + res, ok := s.cachedMultiaddrs[addrStr] + s.mu.RUnlock() + if ok { + return res + } + + s.mu.Lock() + defer s.mu.Unlock() + // Check if some other go routine added this while we were waiting + res, ok = s.cachedMultiaddrs[addrStr] + if ok { + return res + } + if s.cachedMultiaddrs == nil { + s.cachedMultiaddrs = make(map[string]ma.Multiaddr, observerSetCacheSize) + } + if len(s.cachedMultiaddrs) == observerSetCacheSize { + // remove one entry if we will go over the limit + for k := range s.cachedMultiaddrs { + delete(s.cachedMultiaddrs, k) + break + } + } + s.cachedMultiaddrs[addrStr] = ma.Join(s.ObservedTWAddr, addr) + return s.cachedMultiaddrs[addrStr] +} + +type observation struct { + conn connMultiaddrs observed ma.Multiaddr } -// ObservedAddrManager keeps track of a ObservedAddrs. +// ObservedAddrManager maps connection's local multiaddrs to their externally observable multiaddress type ObservedAddrManager struct { - host host.Host + // Our listen addrs + listenAddrs func() []ma.Multiaddr + // Our listen addrs with interface addrs for unspecified addrs + interfaceListenAddrs func() ([]ma.Multiaddr, error) + // All host addrs + hostAddrs func() []ma.Multiaddr + // Any normalization required before comparing. Useful to remove certhash + normalize func(ma.Multiaddr) ma.Multiaddr + // worker channel for new observations + wch chan observation + // notified on recording an observation + addrRecordedNotif chan struct{} - closeOnce sync.Once - refCount sync.WaitGroup - ctx context.Context // the context is canceled when Close is called + // for closing + wg sync.WaitGroup + ctx context.Context ctxCancel context.CancelFunc - // latest observation from active connections - // we'll "re-observe" these when we gc - activeConnsMu sync.Mutex - // active connection -> most recent observation - activeConns map[network.Conn]ma.Multiaddr - - mu sync.RWMutex - closed bool - // local(internal) address -> list of observed(external) addresses - addrs map[string][]*observedAddr - ttl time.Duration - refreshTimer *time.Timer - - // this is the worker channel - wch chan newObservation - - reachabilitySub event.Subscription - reachability network.Reachability - - currentUDPNATDeviceType network.NATDeviceType - currentTCPNATDeviceType network.NATDeviceType - emitNATDeviceTypeChanged event.Emitter + mu sync.RWMutex + // local thin waist => external thin waist => observerSet + externalAddrs map[string]map[string]*observerSet + // connObservedTWAddrs maps the connection to the last observed thin waist multiaddr on that connection + connObservedTWAddrs map[connMultiaddrs]ma.Multiaddr + // localMultiaddr => thin waist form with the count of the connections the multiaddr + // was seen on for tracking our local listen addresses + localAddrs map[string]*thinWaistWithCount } -// NewObservedAddrManager returns a new address manager using -// peerstore.OwnObservedAddressTTL as the TTL. -func NewObservedAddrManager(host host.Host) (*ObservedAddrManager, error) { - oas := &ObservedAddrManager{ - addrs: make(map[string][]*observedAddr), - ttl: peerstore.OwnObservedAddrTTL, - wch: make(chan newObservation, observedAddrManagerWorkerChannelSize), - host: host, - activeConns: make(map[network.Conn]ma.Multiaddr), - // refresh every ttl/2 so we don't forget observations from connected peers - refreshTimer: time.NewTimer(peerstore.OwnObservedAddrTTL / 2), +// NewObservedAddrManager returns a new address manager using peerstore.OwnObservedAddressTTL as the TTL. +func NewObservedAddrManager(listenAddrs, hostAddrs func() []ma.Multiaddr, + interfaceListenAddrs func() ([]ma.Multiaddr, error), normalize func(ma.Multiaddr) ma.Multiaddr) (*ObservedAddrManager, error) { + if normalize == nil { + normalize = func(addr ma.Multiaddr) ma.Multiaddr { return addr } } - oas.ctx, oas.ctxCancel = context.WithCancel(context.Background()) - - reachabilitySub, err := host.EventBus().Subscribe(new(event.EvtLocalReachabilityChanged), eventbus.Name("identify (obsaddr)")) - if err != nil { - return nil, fmt.Errorf("failed to subscribe to reachability event: %s", err) + o := &ObservedAddrManager{ + externalAddrs: make(map[string]map[string]*observerSet), + connObservedTWAddrs: make(map[connMultiaddrs]ma.Multiaddr), + localAddrs: make(map[string]*thinWaistWithCount), + wch: make(chan observation, observedAddrManagerWorkerChannelSize), + addrRecordedNotif: make(chan struct{}, 1), + listenAddrs: listenAddrs, + interfaceListenAddrs: interfaceListenAddrs, + hostAddrs: hostAddrs, + normalize: normalize, } - oas.reachabilitySub = reachabilitySub + o.ctx, o.ctxCancel = context.WithCancel(context.Background()) - emitter, err := host.EventBus().Emitter(new(event.EvtNATDeviceTypeChanged), eventbus.Stateful) - if err != nil { - return nil, fmt.Errorf("failed to create emitter for NATDeviceType: %s", err) - } - oas.emitNATDeviceTypeChanged = emitter - - oas.host.Network().Notify((*obsAddrNotifiee)(oas)) - oas.refCount.Add(1) - go oas.worker() - return oas, nil + o.wg.Add(1) + go o.worker() + return o, nil } // AddrsFor return all activated observed addresses associated with the given // (resolved) listen address. -func (oas *ObservedAddrManager) AddrsFor(addr ma.Multiaddr) (addrs []ma.Multiaddr) { - oas.mu.RLock() - defer oas.mu.RUnlock() - - if len(oas.addrs) == 0 { +func (o *ObservedAddrManager) AddrsFor(addr ma.Multiaddr) (addrs []ma.Multiaddr) { + if addr == nil { + return nil + } + o.mu.RLock() + defer o.mu.RUnlock() + tw, err := thinWaistForm(o.normalize(addr)) + if err != nil { return nil } - observedAddrs, ok := oas.addrs[string(addr.Bytes())] - if !ok { - return + observerSets := o.getTopExternalAddrs(string(tw.TW.Bytes())) + res := make([]ma.Multiaddr, 0, len(observerSets)) + for _, s := range observerSets { + res = append(res, s.cacheMultiaddr(tw.Rest)) } - - return oas.filter(observedAddrs) + return res } // Addrs return all activated observed addresses -func (oas *ObservedAddrManager) Addrs() []ma.Multiaddr { - oas.mu.RLock() - defer oas.mu.RUnlock() +func (o *ObservedAddrManager) Addrs() []ma.Multiaddr { + o.mu.RLock() + defer o.mu.RUnlock() - if len(oas.addrs) == 0 { - return nil + m := make(map[string][]*observerSet) + for localTWStr := range o.externalAddrs { + m[localTWStr] = append(m[localTWStr], o.getTopExternalAddrs(localTWStr)...) } - - var allObserved []*observedAddr - for _, addrs := range oas.addrs { - allObserved = append(allObserved, addrs...) - } - return oas.filter(allObserved) -} - -func (oas *ObservedAddrManager) filter(observedAddrs []*observedAddr) []ma.Multiaddr { - pmap := make(map[string][]*observedAddr) - now := time.Now() - - for i := range observedAddrs { - a := observedAddrs[i] - if now.Sub(a.lastSeen) <= oas.ttl && a.activated() { - // group addresses by their IPX/Transport Protocol(TCP or UDP) pattern. - pat := a.groupKey() - pmap[pat] = append(pmap[pat], a) - + addrs := make([]ma.Multiaddr, 0, maxExternalThinWaistAddrsPerLocalAddr*5) // assume 5 transports + for _, t := range o.localAddrs { + for _, s := range m[string(t.TW.Bytes())] { + addrs = append(addrs, s.cacheMultiaddr(t.Rest)) } } - - addrs := make([]ma.Multiaddr, 0, len(observedAddrs)) - for pat := range pmap { - s := pmap[pat] - - // We prefer inbound connection observations over outbound. - // For ties, we prefer the ones with more votes. - slices.SortFunc(s, func(first, second *observedAddr) int { - if first.numInbound > second.numInbound { - return 1 - } - return len(first.seenBy) - len(second.seenBy) - }) - - for i := 0; i < maxObservedAddrsPerIPAndTransport && i < len(s); i++ { - addrs = append(addrs, s[i].addr) - } - } - return addrs } -// Record records an address observation, if valid. -func (oas *ObservedAddrManager) Record(conn network.Conn, observed ma.Multiaddr) { +func (o *ObservedAddrManager) getTopExternalAddrs(localTWStr string) []*observerSet { + observerSets := make([]*observerSet, 0, len(o.externalAddrs[localTWStr])) + for _, v := range o.externalAddrs[localTWStr] { + if len(v.ObservedBy) >= ActivationThresh { + observerSets = append(observerSets, v) + } + } + slices.SortFunc(observerSets, func(a, b *observerSet) int { + diff := len(b.ObservedBy) - len(a.ObservedBy) + if diff != 0 { + return diff + } + // In case we have elements with equal counts, + // keep the address list stable by using the lexicographically smaller address + as := a.ObservedTWAddr.String() + bs := b.ObservedTWAddr.String() + if as < bs { + return -1 + } else if as > bs { + return 1 + } else { + return 0 + } + + }) + n := len(observerSets) + if n > maxExternalThinWaistAddrsPerLocalAddr { + n = maxExternalThinWaistAddrsPerLocalAddr + } + return observerSets[:n] +} + +// Record enqueues an observation for recording +func (o *ObservedAddrManager) Record(conn connMultiaddrs, observed ma.Multiaddr) { select { - case oas.wch <- newObservation{ + case o.wch <- observation{ conn: conn, observed: observed, }: @@ -244,182 +278,72 @@ func (oas *ObservedAddrManager) Record(conn network.Conn, observed ma.Multiaddr) } } -func (oas *ObservedAddrManager) worker() { - defer oas.refCount.Done() +func (o *ObservedAddrManager) worker() { + defer o.wg.Done() - ticker := time.NewTicker(GCInterval) - defer ticker.Stop() - - subChan := oas.reachabilitySub.Out() for { select { - case evt, ok := <-subChan: - if !ok { - subChan = nil - continue - } - ev := evt.(event.EvtLocalReachabilityChanged) - oas.reachability = ev.Reachability - case obs := <-oas.wch: - oas.maybeRecordObservation(obs.conn, obs.observed) - case <-ticker.C: - oas.gc() - case <-oas.refreshTimer.C: - oas.refresh() - case <-oas.ctx.Done(): + case obs := <-o.wch: + o.maybeRecordObservation(obs.conn, obs.observed) + case <-o.ctx.Done(): return } } } -func (oas *ObservedAddrManager) refresh() { - oas.activeConnsMu.Lock() - recycledObservations := make([]newObservation, 0, len(oas.activeConns)) - for conn, observed := range oas.activeConns { - recycledObservations = append(recycledObservations, newObservation{ - conn: conn, - observed: observed, - }) +func (o *ObservedAddrManager) shouldRecordObservation(conn connMultiaddrs, observed ma.Multiaddr) (shouldRecord bool, localTW thinWaist, observedTW thinWaist) { + if conn == nil || observed == nil { + return false, thinWaist{}, thinWaist{} } - oas.activeConnsMu.Unlock() - - oas.mu.Lock() - defer oas.mu.Unlock() - for _, obs := range recycledObservations { - oas.recordObservationUnlocked(obs.conn, obs.observed) - } - // refresh every ttl/2 so we don't forget observations from connected peers - oas.refreshTimer.Reset(oas.ttl / 2) -} - -func (oas *ObservedAddrManager) gc() { - oas.mu.Lock() - defer oas.mu.Unlock() - - now := time.Now() - for local, observedAddrs := range oas.addrs { - filteredAddrs := observedAddrs[:0] - for _, a := range observedAddrs { - // clean up SeenBy set - for k, ob := range a.seenBy { - if now.Sub(ob.seenTime) > oas.ttl*time.Duration(ActivationThresh) { - delete(a.seenBy, k) - if ob.inbound { - a.numInbound-- - } - } - } - - // leave only alive observed addresses - if now.Sub(a.lastSeen) <= oas.ttl { - filteredAddrs = append(filteredAddrs, a) - } - } - if len(filteredAddrs) > 0 { - oas.addrs[local] = filteredAddrs - } else { - delete(oas.addrs, local) - } - } -} - -func (oas *ObservedAddrManager) addConn(conn network.Conn, observed ma.Multiaddr) { - oas.activeConnsMu.Lock() - defer oas.activeConnsMu.Unlock() - - // We need to make sure we haven't received a disconnect event for this - // connection yet. The only way to do that right now is to make sure the - // swarm still has the connection. - // - // Doing this under a lock that we _also_ take in a disconnect event - // handler ensures everything happens in the right order. - for _, c := range oas.host.Network().ConnsToPeer(conn.RemotePeer()) { - if c == conn { - oas.activeConns[conn] = observed - return - } - } -} - -func (oas *ObservedAddrManager) removeConn(conn network.Conn) { - // DO NOT remove this lock. - // This ensures we don't call addConn at the same time: - // 1. see that we have a connection and pause inside addConn right before recording it. - // 2. process a disconnect event. - // 3. record the connection (leaking it). - - oas.activeConnsMu.Lock() - delete(oas.activeConns, conn) - oas.activeConnsMu.Unlock() -} - -type normalizeMultiaddrer interface { - NormalizeMultiaddr(addr ma.Multiaddr) ma.Multiaddr -} - -type addrsProvider interface { - Addrs() []ma.Multiaddr -} - -type listenAddrsProvider interface { - ListenAddresses() []ma.Multiaddr - InterfaceListenAddresses() ([]ma.Multiaddr, error) -} - -func shouldRecordObservation(host addrsProvider, network listenAddrsProvider, conn network.ConnMultiaddrs, observed ma.Multiaddr) bool { - // First, determine if this observation is even worth keeping... - // Ignore observations from loopback nodes. We already know our loopback // addresses. if manet.IsIPLoopback(observed) { - return false + return false, thinWaist{}, thinWaist{} } // Provided by NAT64 peers, these addresses are specific to the peer and not publicly routable if manet.IsNAT64IPv4ConvertedIPv6Addr(observed) { - return false + return false, thinWaist{}, thinWaist{} } // we should only use ObservedAddr when our connection's LocalAddr is one // of our ListenAddrs. If we Dial out using an ephemeral addr, knowing that // address's external mapping is not very useful because the port will not be // the same as the listen addr. - ifaceaddrs, err := network.InterfaceListenAddresses() + ifaceaddrs, err := o.interfaceListenAddrs() if err != nil { log.Infof("failed to get interface listen addrs", err) - return false + return false, thinWaist{}, thinWaist{} } - normalizer, canNormalize := host.(normalizeMultiaddrer) - - if canNormalize { - for i, a := range ifaceaddrs { - ifaceaddrs[i] = normalizer.NormalizeMultiaddr(a) - } + for i, a := range ifaceaddrs { + ifaceaddrs[i] = o.normalize(a) } - local := conn.LocalMultiaddr() - if canNormalize { - local = normalizer.NormalizeMultiaddr(local) - } + local := o.normalize(conn.LocalMultiaddr()) - listenAddrs := network.ListenAddresses() - if canNormalize { - for i, a := range listenAddrs { - listenAddrs[i] = normalizer.NormalizeMultiaddr(a) - } + listenAddrs := o.listenAddrs() + for i, a := range listenAddrs { + listenAddrs[i] = o.normalize(a) } if !ma.Contains(ifaceaddrs, local) && !ma.Contains(listenAddrs, local) { // not in our list - return false + return false, thinWaist{}, thinWaist{} } - hostAddrs := host.Addrs() - if canNormalize { - for i, a := range hostAddrs { - hostAddrs[i] = normalizer.NormalizeMultiaddr(a) - } + localTW, err = thinWaistForm(local) + if err != nil { + return false, thinWaist{}, thinWaist{} + } + observedTW, err = thinWaistForm(o.normalize(observed)) + if err != nil { + return false, thinWaist{}, thinWaist{} + } + + hostAddrs := o.hostAddrs() + for i, a := range hostAddrs { + hostAddrs[i] = o.normalize(a) } // We should reject the connection if the observation doesn't match the @@ -431,207 +355,192 @@ func shouldRecordObservation(host addrsProvider, network listenAddrsProvider, co "from", conn.RemoteMultiaddr(), "observed", observed, ) - return false + return false, thinWaist{}, thinWaist{} } - return true + return true, localTW, observedTW } -func (oas *ObservedAddrManager) maybeRecordObservation(conn network.Conn, observed ma.Multiaddr) { - shouldRecord := shouldRecordObservation(oas.host, oas.host.Network(), conn, observed) - if shouldRecord { - // Ok, the observation is good, record it. - log.Debugw("added own observed listen addr", "observed", observed) - defer oas.addConn(conn, observed) - - oas.mu.Lock() - defer oas.mu.Unlock() - oas.recordObservationUnlocked(conn, observed) - - if oas.reachability == network.ReachabilityPrivate { - oas.emitAllNATTypes() - } - } -} - -func (oas *ObservedAddrManager) recordObservationUnlocked(conn network.Conn, observed ma.Multiaddr) { - now := time.Now() - observerString := observerGroup(conn.RemoteMultiaddr()) - localString := string(conn.LocalMultiaddr().Bytes()) - ob := observation{ - seenTime: now, - inbound: conn.Stat().Direction == network.DirInbound, - } - - // check if observed address seen yet, if so, update it - for _, observedAddr := range oas.addrs[localString] { - if observedAddr.addr.Equal(observed) { - // Don't trump an outbound observation with an inbound - // one. - wasInbound := observedAddr.seenBy[observerString].inbound - isInbound := ob.inbound - ob.inbound = isInbound || wasInbound - - if !wasInbound && isInbound { - observedAddr.numInbound++ - } - - observedAddr.seenBy[observerString] = ob - observedAddr.lastSeen = now - return - } - } - - // observed address not seen yet, append it - oa := &observedAddr{ - addr: observed, - seenBy: map[string]observation{ - observerString: ob, - }, - lastSeen: now, - } - if ob.inbound { - oa.numInbound++ - } - oas.addrs[localString] = append(oas.addrs[localString], oa) -} - -// For a given transport Protocol (TCP/UDP): -// -// 1. If we have an activated address, we are behind an Cone NAT. -// With regards to RFC 3489, this could be either a Full Cone NAT, a Restricted Cone NAT or a -// Port Restricted Cone NAT. However, we do NOT differentiate between them here and simply classify all such NATs as a Cone NAT. -// -// 2. If four different peers observe a different address for us on outbound connections, we -// are MOST probably behind a Symmetric NAT. -// -// Please see the documentation on the enumerations for `network.NATDeviceType` for more details about these NAT Device types -// and how they relate to NAT traversal via Hole Punching. -func (oas *ObservedAddrManager) emitAllNATTypes() { - var allObserved []*observedAddr - for _, addrs := range oas.addrs { - allObserved = append(allObserved, addrs...) - } - - hasChanged, natType := oas.emitSpecificNATType(allObserved, ma.P_TCP, network.NATTransportTCP, oas.currentTCPNATDeviceType) - if hasChanged { - oas.currentTCPNATDeviceType = natType - } - - hasChanged, natType = oas.emitSpecificNATType(allObserved, ma.P_UDP, network.NATTransportUDP, oas.currentUDPNATDeviceType) - if hasChanged { - oas.currentUDPNATDeviceType = natType - } -} - -// returns true along with the new NAT device type if the NAT device type for the given protocol has changed. -// returns false otherwise. -func (oas *ObservedAddrManager) emitSpecificNATType(addrs []*observedAddr, protoCode int, transportProto network.NATTransportProtocol, - currentNATType network.NATDeviceType) (bool, network.NATDeviceType) { - now := time.Now() - seenBy := make(map[string]struct{}) - cnt := 0 - - for _, oa := range addrs { - _, err := oa.addr.ValueForProtocol(protoCode) - if err != nil { - continue - } - - // if we have an activated addresses, it's a Cone NAT. - if now.Sub(oa.lastSeen) <= oas.ttl && oa.activated() { - if currentNATType != network.NATDeviceTypeCone { - oas.emitNATDeviceTypeChanged.Emit(event.EvtNATDeviceTypeChanged{ - TransportProtocol: transportProto, - NatDeviceType: network.NATDeviceTypeCone, - }) - return true, network.NATDeviceTypeCone - } - - // our current NAT Device Type is already CONE, nothing to do here. - return false, 0 - } - - // An observed address on an outbound connection that has ONLY been seen by one peer - if now.Sub(oa.lastSeen) <= oas.ttl && oa.numInbound == 0 && len(oa.seenBy) == 1 { - cnt++ - for s := range oa.seenBy { - seenBy[s] = struct{}{} - } - } - } - - // If four different peers observe a different address for us on each of four outbound connections, we - // are MOST probably behind a Symmetric NAT. - if cnt >= ActivationThresh && len(seenBy) >= ActivationThresh { - if currentNATType != network.NATDeviceTypeSymmetric { - oas.emitNATDeviceTypeChanged.Emit(event.EvtNATDeviceTypeChanged{ - TransportProtocol: transportProto, - NatDeviceType: network.NATDeviceTypeSymmetric, - }) - return true, network.NATDeviceTypeSymmetric - } - } - - return false, 0 -} - -func (oas *ObservedAddrManager) Close() error { - oas.closeOnce.Do(func() { - oas.ctxCancel() - - oas.mu.Lock() - oas.closed = true - oas.refreshTimer.Stop() - oas.mu.Unlock() - - oas.refCount.Wait() - oas.reachabilitySub.Close() - oas.host.Network().StopNotify((*obsAddrNotifiee)(oas)) - }) - return nil -} - -// observerGroup is a function that determines what part of -// a multiaddr counts as a different observer. for example, -// two ipfs nodes at the same IP/TCP transport would get -// the exact same NAT mapping; they would count as the -// same observer. This may protect against NATs who assign -// different ports to addresses at different IP hosts, but -// not TCP ports. -// -// Here, we use the root multiaddr address. This is mostly -// IP addresses. In practice, this is what we want. -func observerGroup(m ma.Multiaddr) string { - // TODO: If IPv6 rolls out we should mark /64 routing zones as one group - first, _ := ma.SplitFirst(m) - return string(first.Bytes()) -} - -// SetTTL sets the TTL of an observed address manager. -func (oas *ObservedAddrManager) SetTTL(ttl time.Duration) { - oas.mu.Lock() - defer oas.mu.Unlock() - if oas.closed { +func (o *ObservedAddrManager) maybeRecordObservation(conn connMultiaddrs, observed ma.Multiaddr) { + shouldRecord, localTW, observedTW := o.shouldRecordObservation(conn, observed) + if !shouldRecord { return } - oas.ttl = ttl - // refresh every ttl/2 so we don't forget observations from connected peers - oas.refreshTimer.Reset(ttl / 2) + log.Debugw("added own observed listen addr", "observed", observed) + + o.mu.Lock() + defer o.mu.Unlock() + o.recordObservationUnlocked(conn, localTW, observedTW) + select { + case o.addrRecordedNotif <- struct{}{}: + default: + } } -// TTL gets the TTL of an observed address manager. -func (oas *ObservedAddrManager) TTL() time.Duration { - oas.mu.RLock() - defer oas.mu.RUnlock() - return oas.ttl +func (o *ObservedAddrManager) recordObservationUnlocked(conn connMultiaddrs, localTW, observedTW thinWaist) { + if conn.IsClosed() { + // dont record if the connection is already closed. Any previous observations will be removed in + // the disconnected callback + return + } + localTWStr := string(localTW.TW.Bytes()) + observedTWStr := string(observedTW.TW.Bytes()) + observer, err := getObserver(conn.RemoteMultiaddr()) + if err != nil { + return + } + + prevObservedTWAddr, ok := o.connObservedTWAddrs[conn] + if !ok { + t, ok := o.localAddrs[string(localTW.Addr.Bytes())] + if !ok { + t = &thinWaistWithCount{ + thinWaist: localTW, + } + o.localAddrs[string(localTW.Addr.Bytes())] = t + } + t.Count++ + } else { + if prevObservedTWAddr.Equal(observedTW.TW) { + // we have received the same observation again, nothing to do + return + } + // if we have a previous entry remove it from externalAddrs + o.removeExternalAddrsUnlocked(observer, localTWStr, string(prevObservedTWAddr.Bytes())) + // no need to change the localAddrs map here + } + o.connObservedTWAddrs[conn] = observedTW.TW + o.addExternalAddrsUnlocked(observedTW.TW, observer, localTWStr, observedTWStr) } -type obsAddrNotifiee ObservedAddrManager - -func (on *obsAddrNotifiee) Listen(n network.Network, a ma.Multiaddr) {} -func (on *obsAddrNotifiee) ListenClose(n network.Network, a ma.Multiaddr) {} -func (on *obsAddrNotifiee) Connected(n network.Network, v network.Conn) {} -func (on *obsAddrNotifiee) Disconnected(n network.Network, v network.Conn) { - (*ObservedAddrManager)(on).removeConn(v) +func (o *ObservedAddrManager) removeExternalAddrsUnlocked(observer, localTWStr, observedTWStr string) { + s, ok := o.externalAddrs[localTWStr][observedTWStr] + if !ok { + return + } + s.ObservedBy[observer]-- + if s.ObservedBy[observer] <= 0 { + delete(s.ObservedBy, observer) + } + if len(s.ObservedBy) == 0 { + delete(o.externalAddrs[localTWStr], observedTWStr) + } + if len(o.externalAddrs[localTWStr]) == 0 { + delete(o.externalAddrs, localTWStr) + } +} + +func (o *ObservedAddrManager) addExternalAddrsUnlocked(observedTWAddr ma.Multiaddr, observer, localTWStr, observedTWStr string) { + s, ok := o.externalAddrs[localTWStr][observedTWStr] + if !ok { + s = &observerSet{ + ObservedTWAddr: observedTWAddr, + ObservedBy: make(map[string]int), + } + if _, ok := o.externalAddrs[localTWStr]; !ok { + o.externalAddrs[localTWStr] = make(map[string]*observerSet) + } + o.externalAddrs[localTWStr][observedTWStr] = s + } + s.ObservedBy[observer]++ +} + +func (o *ObservedAddrManager) removeConn(conn connMultiaddrs) { + if conn == nil { + return + } + o.mu.Lock() + defer o.mu.Unlock() + + // normalize before obtaining the thinWaist so that we are always dealing + // with the normalized form of the address + localTW, err := thinWaistForm(o.normalize(conn.LocalMultiaddr())) + if err != nil { + return + } + t, ok := o.localAddrs[string(localTW.Addr.Bytes())] + if !ok { + return + } + t.Count-- + if t.Count <= 0 { + delete(o.localAddrs, string(localTW.Addr.Bytes())) + } + + observedTWAddr, ok := o.connObservedTWAddrs[conn] + if !ok { + return + } + delete(o.connObservedTWAddrs, conn) + observer, err := getObserver(conn.RemoteMultiaddr()) + if err != nil { + return + } + + o.removeExternalAddrsUnlocked(observer, string(localTW.TW.Bytes()), string(observedTWAddr.Bytes())) + select { + case o.addrRecordedNotif <- struct{}{}: + default: + } +} + +func (o *ObservedAddrManager) getNATType() (tcpNATType, udpNATType network.NATDeviceType) { + o.mu.RLock() + defer o.mu.RUnlock() + + var tcpCounts, udpCounts []int + var tcpTotal, udpTotal int + for _, m := range o.externalAddrs { + isTCP := false + for _, v := range m { + if _, err := v.ObservedTWAddr.ValueForProtocol(ma.P_TCP); err == nil { + isTCP = true + } + break + } + for _, v := range m { + if isTCP { + tcpCounts = append(tcpCounts, len(v.ObservedBy)) + tcpTotal += len(v.ObservedBy) + } else { + udpCounts = append(udpCounts, len(v.ObservedBy)) + udpTotal += len(v.ObservedBy) + } + } + } + + sort.Sort(sort.Reverse(sort.IntSlice(tcpCounts))) + sort.Sort(sort.Reverse(sort.IntSlice(udpCounts))) + + tcpTopCounts, udpTopCounts := 0, 0 + for i := 0; i < maxExternalThinWaistAddrsPerLocalAddr && i < len(tcpCounts); i++ { + tcpTopCounts += tcpCounts[i] + } + for i := 0; i < maxExternalThinWaistAddrsPerLocalAddr && i < len(udpCounts); i++ { + udpTopCounts += udpCounts[i] + } + + // If the top elements cover more than 1/2 of all the observations, there's a > 50% chance that + // hole punching based on outputs of observed address manager will succeed + if tcpTotal >= 3*maxExternalThinWaistAddrsPerLocalAddr { + if tcpTopCounts >= tcpTotal/2 { + tcpNATType = network.NATDeviceTypeCone + } else { + tcpNATType = network.NATDeviceTypeSymmetric + } + } + if udpTotal >= 3*maxExternalThinWaistAddrsPerLocalAddr { + if udpTopCounts >= udpTotal/2 { + udpNATType = network.NATDeviceTypeCone + } else { + udpNATType = network.NATDeviceTypeSymmetric + } + } + return +} + +func (o *ObservedAddrManager) Close() error { + o.ctxCancel() + o.wg.Wait() + return nil } diff --git a/go-libp2p/p2p/protocol/identify/obsaddr_glass_test.go b/go-libp2p/p2p/protocol/identify/obsaddr_glass_test.go index f96d3a3..31fd4f5 100644 --- a/go-libp2p/p2p/protocol/identify/obsaddr_glass_test.go +++ b/go-libp2p/p2p/protocol/identify/obsaddr_glass_test.go @@ -5,77 +5,16 @@ package identify import ( "fmt" + "sync/atomic" "testing" ma "github.com/multiformats/go-multiaddr" "github.com/stretchr/testify/require" ) -func TestObservedAddrGroupKey(t *testing.T) { - oa1 := &observedAddr{addr: ma.StringCast("/ip4/1.2.3.4/tcp/2345")} - oa2 := &observedAddr{addr: ma.StringCast("/ip4/1.2.3.4/tcp/1231")} - oa3 := &observedAddr{addr: ma.StringCast("/ip4/1.2.3.5/tcp/1231")} - oa4 := &observedAddr{addr: ma.StringCast("/ip4/1.2.3.4/udp/1231")} - oa5 := &observedAddr{addr: ma.StringCast("/ip4/1.2.3.4/udp/1531")} - oa6 := &observedAddr{addr: ma.StringCast("/ip4/1.2.3.4/udp/1531/quic")} - oa7 := &observedAddr{addr: ma.StringCast("/ip4/1.2.3.4/udp/1111/quic")} - oa8 := &observedAddr{addr: ma.StringCast("/ip4/1.2.3.5/udp/1111/quic")} - - // different ports, same IP => same key - require.Equal(t, oa1.groupKey(), oa2.groupKey()) - // different IPs => different key - require.NotEqual(t, oa2.groupKey(), oa3.groupKey()) - // same port, different protos => different keys - require.NotEqual(t, oa3.groupKey(), oa4.groupKey()) - // same port, same address, different protos => different keys - require.NotEqual(t, oa2.groupKey(), oa4.groupKey()) - // udp works as well - require.Equal(t, oa4.groupKey(), oa5.groupKey()) - // udp and quic are different - require.NotEqual(t, oa5.groupKey(), oa6.groupKey()) - // quic works as well - require.Equal(t, oa6.groupKey(), oa7.groupKey()) - require.NotEqual(t, oa7.groupKey(), oa8.groupKey()) -} - -type mockHost struct { - addrs []ma.Multiaddr - listenAddrs []ma.Multiaddr - ifaceListenAddrs []ma.Multiaddr -} - -// InterfaceListenAddresses implements listenAddrsProvider -func (h *mockHost) InterfaceListenAddresses() ([]ma.Multiaddr, error) { - return h.ifaceListenAddrs, nil -} - -// ListenAddresses implements listenAddrsProvider -func (h *mockHost) ListenAddresses() []ma.Multiaddr { - return h.listenAddrs -} - -// Addrs implements addrsProvider -func (h *mockHost) Addrs() []ma.Multiaddr { - return h.addrs -} - -// NormalizeMultiaddr implements normalizeMultiaddrer -func (h *mockHost) NormalizeMultiaddr(m ma.Multiaddr) ma.Multiaddr { - original := m - for { - rest, tail := ma.SplitLast(m) - if rest == nil { - return original - } - if tail.Protocol().Code == ma.P_WEBTRANSPORT { - return m - } - m = rest - } -} - type mockConn struct { local, remote ma.Multiaddr + isClosed atomic.Bool } // LocalMultiaddr implements connMultiaddrProvider @@ -88,21 +27,30 @@ func (c *mockConn) RemoteMultiaddr() ma.Multiaddr { return c.remote } +func (c *mockConn) Close() { + c.isClosed.Store(true) +} + +func (c *mockConn) IsClosed() bool { + return c.isClosed.Load() +} + func TestShouldRecordObservationWithWebTransport(t *testing.T) { listenAddr := ma.StringCast("/ip4/0.0.0.0/udp/0/quic-v1/webtransport/certhash/uEgNmb28") ifaceAddr := ma.StringCast("/ip4/10.0.0.2/udp/9999/quic-v1/webtransport/certhash/uEgNmb28") - h := &mockHost{ - listenAddrs: []ma.Multiaddr{listenAddr}, - ifaceListenAddrs: []ma.Multiaddr{ifaceAddr}, - addrs: []ma.Multiaddr{listenAddr}, - } + listenAddrs := func() []ma.Multiaddr { return []ma.Multiaddr{listenAddr} } + ifaceListenAddrs := func() ([]ma.Multiaddr, error) { return []ma.Multiaddr{ifaceAddr}, nil } + addrs := func() []ma.Multiaddr { return []ma.Multiaddr{listenAddr} } + c := &mockConn{ local: listenAddr, remote: ma.StringCast("/ip4/1.2.3.6/udp/1236/quic-v1/webtransport"), } observedAddr := ma.StringCast("/ip4/1.2.3.4/udp/1231/quic-v1/webtransport") - - require.True(t, shouldRecordObservation(h, h, c, observedAddr)) + o, err := NewObservedAddrManager(listenAddrs, addrs, ifaceListenAddrs, normalize) + require.NoError(t, err) + shouldRecord, _, _ := o.shouldRecordObservation(c, observedAddr) + require.True(t, shouldRecord) } func TestShouldRecordObservationWithNAT64Addr(t *testing.T) { @@ -111,11 +59,11 @@ func TestShouldRecordObservationWithNAT64Addr(t *testing.T) { listenAddr2 := ma.StringCast("/ip6/::/tcp/1234") ifaceAddr2 := ma.StringCast("/ip6/1::1/tcp/4321") - h := &mockHost{ - listenAddrs: []ma.Multiaddr{listenAddr1, listenAddr2}, - ifaceListenAddrs: []ma.Multiaddr{ifaceAddr1, ifaceAddr2}, - addrs: []ma.Multiaddr{listenAddr1, listenAddr2}, - } + var ( + listenAddrs = func() []ma.Multiaddr { return []ma.Multiaddr{listenAddr1, listenAddr2} } + ifaceListenAddrs = func() ([]ma.Multiaddr, error) { return []ma.Multiaddr{ifaceAddr1, ifaceAddr2}, nil } + addrs = func() []ma.Multiaddr { return []ma.Multiaddr{listenAddr1, listenAddr2} } + ) c := &mockConn{ local: listenAddr1, remote: ma.StringCast("/ip4/1.2.3.6/tcp/4321"), @@ -142,12 +90,70 @@ func TestShouldRecordObservationWithNAT64Addr(t *testing.T) { failureReason: "NAT64 IPv6 address shouldn't be observed", }, } + + o, err := NewObservedAddrManager(listenAddrs, addrs, ifaceListenAddrs, normalize) + require.NoError(t, err) for i, tc := range cases { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { - if shouldRecordObservation(h, h, c, tc.addr) != tc.want { + if shouldRecord, _, _ := o.shouldRecordObservation(c, tc.addr); shouldRecord != tc.want { t.Fatalf("%s %s", tc.addr, tc.failureReason) } }) } } + +func TestThinWaistForm(t *testing.T) { + tc := []struct { + input string + tw string + rest string + err bool + }{{ + input: "/ip4/1.2.3.4/tcp/1", + tw: "/ip4/1.2.3.4/tcp/1", + rest: "", + }, { + input: "/ip4/1.2.3.4/tcp/1/ws", + tw: "/ip4/1.2.3.4/tcp/1", + rest: "/ws", + }, { + input: "/ip4/127.0.0.1/udp/1/quic-v1", + tw: "/ip4/127.0.0.1/udp/1", + rest: "/quic-v1", + }, { + input: "/ip4/1.2.3.4/udp/1/quic-v1/webtransport", + tw: "/ip4/1.2.3.4/udp/1", + rest: "/quic-v1/webtransport", + }, { + input: "/ip4/1.2.3.4/", + err: true, + }, { + input: "/tcp/1", + err: true, + }, { + input: "/ip6/::1/tcp/1", + tw: "/ip6/::1/tcp/1", + rest: "", + }} + for i, tt := range tc { + t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + inputAddr := ma.StringCast(tt.input) + tw, err := thinWaistForm(inputAddr) + if tt.err { + require.Equal(t, tw, thinWaist{}) + require.Error(t, err) + return + } + wantTW := ma.StringCast(tt.tw) + var restTW ma.Multiaddr + if tt.rest != "" { + restTW = ma.StringCast(tt.rest) + } + require.Equal(t, tw.Addr, inputAddr, "%s %s", tw.Addr, inputAddr) + require.Equal(t, wantTW, tw.TW, "%s %s", tw.TW, wantTW) + require.Equal(t, restTW, tw.Rest, "%s %s", restTW, tw.Rest) + }) + } + +} diff --git a/go-libp2p/p2p/protocol/identify/obsaddr_test.go b/go-libp2p/p2p/protocol/identify/obsaddr_test.go index 2987b01..9c2d8de 100644 --- a/go-libp2p/p2p/protocol/identify/obsaddr_test.go +++ b/go-libp2p/p2p/protocol/identify/obsaddr_test.go @@ -1,436 +1,662 @@ -package identify_test +package identify import ( - "crypto/rand" + crand "crypto/rand" + "fmt" + "net" "testing" "time" - ic "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/event" - "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" - "github.com/libp2p/go-libp2p/core/peer" + blankhost "github.com/libp2p/go-libp2p/p2p/host/blank" "github.com/libp2p/go-libp2p/p2p/host/eventbus" - mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" - "github.com/libp2p/go-libp2p/p2p/protocol/identify" + swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing" ma "github.com/multiformats/go-multiaddr" + manet "github.com/multiformats/go-multiaddr/net" "github.com/stretchr/testify/require" ) -type harness struct { - t *testing.T - - mocknet mocknet.Mocknet - host host.Host - - oas *identify.ObservedAddrManager +func newConn(local, remote ma.Multiaddr) *mockConn { + return &mockConn{local: local, remote: remote} } -func (h *harness) add(observer ma.Multiaddr) peer.ID { - // create a new fake peer. - sk, _, err := ic.GenerateECDSAKeyPair(rand.Reader) - if err != nil { - h.t.Fatal(err) - } - h2, err := h.mocknet.AddPeer(sk, observer) - if err != nil { - h.t.Fatal(err) - } - _, err = h.mocknet.LinkPeers(h.host.ID(), h2.ID()) - if err != nil { - h.t.Fatal(err) - } - return h2.ID() -} - -func (h *harness) conn(observer peer.ID) network.Conn { - c, err := h.mocknet.ConnectPeers(h.host.ID(), observer) - if err != nil { - h.t.Fatal(err) - } - if c.Stat().Direction != network.DirOutbound { - h.t.Fatal("expected conn direction to be outbound") - } - return c -} - -func (h *harness) connInbound(observer peer.ID) network.Conn { - c, err := h.mocknet.ConnectPeers(observer, h.host.ID()) - if err != nil { - h.t.Fatal(err) - } - - c = mocknet.ConnComplement(c) - if c.Stat().Direction != network.DirInbound { - h.t.Fatal("expected conn direction to be inbound") - } - return c -} - -func (h *harness) observe(observed ma.Multiaddr, observer peer.ID) network.Conn { - c := h.conn(observer) - h.oas.Record(c, observed) - time.Sleep(200 * time.Millisecond) // let the worker run - return c -} - -func (h *harness) observeInbound(observed ma.Multiaddr, observer peer.ID) network.Conn { - c := h.connInbound(observer) - h.oas.Record(c, observed) - time.Sleep(200 * time.Millisecond) // let the worker run - return c -} - -func newHarness(t *testing.T) harness { - return newHarnessWithMa(t, ma.StringCast("/ip4/127.0.0.1/tcp/10086")) -} - -func newHarnessWithMa(t *testing.T, listenAddr ma.Multiaddr) harness { - mn := mocknet.New() - sk, _, err := ic.GenerateECDSAKeyPair(rand.Reader) - require.NoError(t, err) - h, err := mn.AddPeer(sk, listenAddr) - require.NoError(t, err) - oas, err := identify.NewObservedAddrManager(h) - require.NoError(t, err) - t.Cleanup(func() { - mn.Close() - oas.Close() - }) - return harness{ - oas: oas, - mocknet: mn, - host: h, - t: t, - } -} - -// TestObsAddrSet -func TestObsAddrSet(t *testing.T) { - addrsMatch := func(a, b []ma.Multiaddr) bool { - if len(a) != len(b) { - return false +func normalize(addr ma.Multiaddr) ma.Multiaddr { + for { + out, last := ma.SplitLast(addr) + if last == nil { + return addr } - for _, aa := range a { - if !ma.Contains(b, aa) { - return false + if _, err := last.ValueForProtocol(ma.P_CERTHASH); err != nil { + return addr + } + addr = out + } +} + +func addrsEqual(a, b []ma.Multiaddr) bool { + if len(b) != len(a) { + return false + } + for _, x := range b { + found := false + for _, y := range a { + if y.Equal(x) { + found = true + break } } - return true - } - - a1 := ma.StringCast("/ip4/1.2.3.4/tcp/1231") - a2 := ma.StringCast("/ip4/1.2.3.4/tcp/1232") - a3 := ma.StringCast("/ip4/1.2.3.4/tcp/1233") - a4 := ma.StringCast("/ip4/1.2.3.4/tcp/1234") - a5 := ma.StringCast("/ip4/1.2.3.4/tcp/1235") - - b1 := ma.StringCast("/ip4/1.2.3.6/tcp/1236") - b2 := ma.StringCast("/ip4/1.2.3.7/tcp/1237") - b3 := ma.StringCast("/ip4/1.2.3.8/tcp/1237") - b4 := ma.StringCast("/ip4/1.2.3.9/tcp/1237") - b5 := ma.StringCast("/ip4/1.2.3.10/tcp/1237") - - harness := newHarness(t) - if !addrsMatch(harness.oas.Addrs(), nil) { - t.Error("addrs should be empty") - } - - pa4 := harness.add(a4) - pa5 := harness.add(a5) - - pb1 := harness.add(b1) - pb2 := harness.add(b2) - pb3 := harness.add(b3) - pb4 := harness.add(b4) - pb5 := harness.add(b5) - - harness.observe(a1, pa4) - harness.observe(a2, pa4) - harness.observe(a3, pa4) - - // these are all different so we should not yet get them. - if !addrsMatch(harness.oas.Addrs(), nil) { - t.Error("addrs should _still_ be empty (once)") - } - - // same observer, so should not yet get them. - harness.observe(a1, pa4) - harness.observe(a2, pa4) - harness.observe(a3, pa4) - if !addrsMatch(harness.oas.Addrs(), nil) { - t.Error("addrs should _still_ be empty (same obs)") - } - - // different observer, but same observer group. - harness.observe(a1, pa5) - harness.observe(a2, pa5) - harness.observe(a3, pa5) - if !addrsMatch(harness.oas.Addrs(), nil) { - t.Error("addrs should _still_ be empty (same obs group)") - } - - harness.observe(a1, pb1) - harness.observe(a1, pb2) - harness.observe(a1, pb3) - if !addrsMatch(harness.oas.Addrs(), []ma.Multiaddr{a1}) { - t.Error("addrs should only have a1") - } - - harness.observe(a2, pa5) - harness.observe(a1, pa5) - harness.observe(a1, pa5) - harness.observe(a2, pb1) - harness.observe(a1, pb1) - harness.observe(a1, pb1) - harness.observe(a2, pb2) - harness.observe(a1, pb2) - harness.observe(a1, pb2) - harness.observe(a2, pb4) - harness.observe(a2, pb5) - if !addrsMatch(harness.oas.Addrs(), []ma.Multiaddr{a1, a2}) { - t.Error("addrs should only have a1, a2") - } - - // force a refresh. - harness.oas.SetTTL(time.Millisecond * 200) - require.Eventuallyf(t, - func() bool { return addrsMatch(harness.oas.Addrs(), []ma.Multiaddr{a1, a2}) }, - time.Second, - 50*time.Millisecond, - "addrs should only have %s, %s; have %s", a1, a2, harness.oas.Addrs(), - ) - - // disconnect from all but b5. - for _, p := range harness.host.Network().Peers() { - if p == pb5 { - continue + if !found { + return false } - harness.host.Network().ClosePeer(p) } - - // Wait for all other addresses to time out. - // After that, we hould still have a2. - require.Eventuallyf(t, - func() bool { return addrsMatch(harness.oas.Addrs(), []ma.Multiaddr{a2}) }, - time.Second, - 50*time.Millisecond, - "should only have a2 (%s), have: %v", a2, harness.oas.Addrs(), - ) - harness.host.Network().ClosePeer(pb5) - - // wait for all addresses to timeout - require.Eventually(t, - func() bool { return len(harness.oas.Addrs()) == 0 }, - 400*time.Millisecond, - 20*time.Millisecond, - "addrs should have timed out", - ) + for _, x := range a { + found := false + for _, y := range b { + if y.Equal(x) { + found = true + break + } + } + if !found { + return false + } + } + return true } -func TestObservedAddrFiltering(t *testing.T) { - harness := newHarness(t) - require.Empty(t, harness.oas.Addrs()) - - // IP4/TCP - it1 := ma.StringCast("/ip4/1.2.3.4/tcp/1231") - it2 := ma.StringCast("/ip4/1.2.3.4/tcp/1232") - it3 := ma.StringCast("/ip4/1.2.3.4/tcp/1233") - it4 := ma.StringCast("/ip4/1.2.3.4/tcp/1234") - it5 := ma.StringCast("/ip4/1.2.3.4/tcp/1235") - it6 := ma.StringCast("/ip4/1.2.3.4/tcp/1236") - it7 := ma.StringCast("/ip4/1.2.3.4/tcp/1237") - - // observers - b1 := ma.StringCast("/ip4/1.2.3.6/tcp/1236") - b2 := ma.StringCast("/ip4/1.2.3.7/tcp/1237") - b3 := ma.StringCast("/ip4/1.2.3.8/tcp/1237") - b4 := ma.StringCast("/ip4/1.2.3.9/tcp/1237") - b5 := ma.StringCast("/ip4/1.2.3.10/tcp/1237") - - b6 := ma.StringCast("/ip4/1.2.3.11/tcp/1237") - b7 := ma.StringCast("/ip4/1.2.3.12/tcp/1237") - - // These are all observers in the same group. - b8 := ma.StringCast("/ip4/1.2.3.13/tcp/1237") - b9 := ma.StringCast("/ip4/1.2.3.13/tcp/1238") - b10 := ma.StringCast("/ip4/1.2.3.13/tcp/1239") - - peers := []peer.ID{ - harness.add(b1), - harness.add(b2), - harness.add(b3), - harness.add(b4), - harness.add(b5), - - harness.add(b6), - harness.add(b7), - - harness.add(b8), - harness.add(b9), - harness.add(b10), - } - for i := 0; i < 4; i++ { - harness.observe(it1, peers[i]) - harness.observe(it2, peers[i]) - harness.observe(it3, peers[i]) - harness.observe(it4, peers[i]) - harness.observe(it5, peers[i]) - harness.observe(it6, peers[i]) - harness.observe(it7, peers[i]) +func TestObservedAddrManager(t *testing.T) { + tcp4ListenAddr := ma.StringCast("/ip4/192.168.1.100/tcp/1") + quic4ListenAddr := ma.StringCast("/ip4/0.0.0.0/udp/1/quic-v1") + webTransport4ListenAddr := ma.StringCast("/ip4/0.0.0.0/udp/1/quic-v1/webtransport/certhash/uEgNmb28") + tcp6ListenAddr := ma.StringCast("/ip6/2004::1/tcp/1") + quic6ListenAddr := ma.StringCast("/ip6/::/udp/1/quic-v1") + webTransport6ListenAddr := ma.StringCast("/ip6/::/udp/1/quic-v1/webtransport/certhash/uEgNmb28") + newObservedAddrMgr := func() *ObservedAddrManager { + listenAddrs := []ma.Multiaddr{ + tcp4ListenAddr, quic4ListenAddr, webTransport4ListenAddr, tcp6ListenAddr, quic6ListenAddr, webTransport6ListenAddr, + } + listenAddrsFunc := func() []ma.Multiaddr { + return listenAddrs + } + interfaceListenAddrsFunc := func() ([]ma.Multiaddr, error) { + return listenAddrs, nil + } + o, err := NewObservedAddrManager(listenAddrsFunc, listenAddrsFunc, + interfaceListenAddrsFunc, normalize) + if err != nil { + t.Fatal(err) + } + return o } - harness.observe(it1, peers[4]) - harness.observe(it7, peers[4]) + checkAllEntriesRemoved := func(o *ObservedAddrManager) bool { + return len(o.Addrs()) == 0 && len(o.externalAddrs) == 0 && len(o.connObservedTWAddrs) == 0 && len(o.localAddrs) == 0 + } + t.Run("Single Observation", func(t *testing.T) { + o := newObservedAddrMgr() + defer o.Close() + observed := ma.StringCast("/ip4/2.2.2.2/tcp/2") + c1 := newConn(tcp4ListenAddr, ma.StringCast("/ip4/1.2.3.1/tcp/1")) + c2 := newConn(tcp4ListenAddr, ma.StringCast("/ip4/1.2.3.2/tcp/1")) + c3 := newConn(tcp4ListenAddr, ma.StringCast("/ip4/1.2.3.3/tcp/1")) + c4 := newConn(tcp4ListenAddr, ma.StringCast("/ip4/1.2.3.4/tcp/1")) + o.Record(c1, observed) + o.Record(c2, observed) + o.Record(c3, observed) + o.Record(c4, observed) + require.Eventually(t, func() bool { + return addrsEqual(o.Addrs(), []ma.Multiaddr{observed}) + }, 1*time.Second, 100*time.Millisecond) + o.removeConn(c1) + o.removeConn(c2) + o.removeConn(c3) + o.removeConn(c4) + require.Eventually(t, func() bool { + return checkAllEntriesRemoved(o) + }, 1*time.Second, 100*time.Millisecond) + }) - addrs := harness.oas.Addrs() - require.Len(t, addrs, 2) - require.Contains(t, addrs, it1) - require.Contains(t, addrs, it7) + t.Run("WebTransport inferred from QUIC", func(t *testing.T) { + o := newObservedAddrMgr() + defer o.Close() + observedQuic := ma.StringCast("/ip4/2.2.2.2/udp/2/quic-v1") + observedWebTransport := ma.StringCast("/ip4/2.2.2.2/udp/2/quic-v1/webtransport") + c1 := newConn(quic4ListenAddr, ma.StringCast("/ip4/1.2.3.1/udp/1/quic-v1")) + c2 := newConn(quic4ListenAddr, ma.StringCast("/ip4/1.2.3.2/udp/1/quic-v1")) + c3 := newConn(webTransport4ListenAddr, ma.StringCast("/ip4/1.2.3.3/udp/1/quic-v1/webtransport")) + c4 := newConn(webTransport4ListenAddr, ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1/webtransport")) + o.Record(c1, observedQuic) + o.Record(c2, observedQuic) + o.Record(c3, observedWebTransport) + o.Record(c4, observedWebTransport) + require.Eventually(t, func() bool { + return addrsEqual(o.Addrs(), []ma.Multiaddr{observedQuic, observedWebTransport}) + }, 1*time.Second, 100*time.Millisecond) + o.removeConn(c1) + o.removeConn(c2) + o.removeConn(c3) + o.removeConn(c4) + require.Eventually(t, func() bool { + return checkAllEntriesRemoved(o) + }, 1*time.Second, 100*time.Millisecond) + }) - // Bump the number of observations so 1 & 7 have 7 observations. - harness.observe(it1, peers[5]) - harness.observe(it1, peers[6]) - harness.observe(it7, peers[5]) - harness.observe(it7, peers[6]) + t.Run("SameObservers", func(t *testing.T) { + o := newObservedAddrMgr() + defer o.Close() - // Add an observation from IP 1.2.3.13 - // 2 & 3 now have 5 observations - harness.observe(it2, peers[7]) - harness.observe(it3, peers[7]) + observedQuic := ma.StringCast("/ip4/2.2.2.2/udp/2/quic-v1") - addrs = harness.oas.Addrs() - require.Len(t, addrs, 2) - require.Contains(t, addrs, it1) - require.Contains(t, addrs, it7) + const N = 4 // ActivationThresh + var ob1, ob2 [N]connMultiaddrs + for i := 0; i < N; i++ { + ob1[i] = newConn(quic4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/udp/1/quic-v1", i))) + ob2[i] = newConn(quic4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/udp/1/quic-v1", i))) + } + for i := 0; i < N-1; i++ { + o.Record(ob1[i], observedQuic) + o.Record(ob2[i], observedQuic) + } + time.Sleep(100 * time.Millisecond) + require.Equal(t, o.Addrs(), []ma.Multiaddr{}) - // Add an inbound observation from IP 1.2.3.13, it should override the - // existing observation and it should make these addresses win even - // though we have fewer observations. - // - // 2 & 3 now have 6 observations. - harness.observeInbound(it2, peers[8]) - harness.observeInbound(it3, peers[8]) - addrs = harness.oas.Addrs() - require.Len(t, addrs, 2) - require.Contains(t, addrs, it2) - require.Contains(t, addrs, it3) + // We should have a valid address now + o.Record(ob1[N-1], observedQuic) + o.Record(ob2[N-1], observedQuic) + require.Eventually(t, func() bool { + return addrsEqual(o.Addrs(), []ma.Multiaddr{observedQuic}) + }, 2*time.Second, 100*time.Millisecond) - // Adding an outbound observation shouldn't "downgrade" it. - // - // 2 & 3 now have 7 observations. - harness.observe(it2, peers[9]) - harness.observe(it3, peers[9]) - addrs = harness.oas.Addrs() - require.Len(t, addrs, 2) - require.Contains(t, addrs, it2) - require.Contains(t, addrs, it3) + // Now disconnect first observer group + for i := 0; i < N; i++ { + o.removeConn(ob1[i]) + } + time.Sleep(100 * time.Millisecond) + if !addrsEqual(o.Addrs(), []ma.Multiaddr{observedQuic}) { + t.Fatalf("address removed too earyly %v %v", o.Addrs(), observedQuic) + } + + // Now disconnect the second group to check cleanup + for i := 0; i < N; i++ { + o.removeConn(ob2[i]) + } + require.Eventually(t, func() bool { + return checkAllEntriesRemoved(o) + }, 2*time.Second, 100*time.Millisecond) + }) + t.Run("SameObserversDifferentAddrs", func(t *testing.T) { + o := newObservedAddrMgr() + defer o.Close() + + observedQuic1 := ma.StringCast("/ip4/2.2.2.2/udp/2/quic-v1") + observedQuic2 := ma.StringCast("/ip4/2.2.2.2/udp/3/quic-v1") + + const N = 4 // ActivationThresh + var ob1, ob2 [N]connMultiaddrs + for i := 0; i < N; i++ { + ob1[i] = newConn(quic4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/udp/1/quic-v1", i))) + ob2[i] = newConn(quic4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/udp/1/quic-v1", i))) + } + for i := 0; i < N-1; i++ { + o.Record(ob1[i], observedQuic1) + o.Record(ob2[i], observedQuic2) + } + time.Sleep(100 * time.Millisecond) + require.Equal(t, o.Addrs(), []ma.Multiaddr{}) + + // We should have a valid address now + o.Record(ob1[N-1], observedQuic1) + o.Record(ob2[N-1], observedQuic2) + require.Eventually(t, func() bool { + return addrsEqual(o.Addrs(), []ma.Multiaddr{observedQuic1, observedQuic2}) + }, 2*time.Second, 100*time.Millisecond) + + // Now disconnect first observer group + for i := 0; i < N; i++ { + o.removeConn(ob1[i]) + } + time.Sleep(100 * time.Millisecond) + if !addrsEqual(o.Addrs(), []ma.Multiaddr{observedQuic2}) { + t.Fatalf("address removed too earyly %v %v", o.Addrs(), observedQuic2) + } + + // Now disconnect the second group to check cleanup + for i := 0; i < N; i++ { + o.removeConn(ob2[i]) + } + require.Eventually(t, func() bool { + return checkAllEntriesRemoved(o) + }, 2*time.Second, 100*time.Millisecond) + }) + + t.Run("Old observations discarded", func(t *testing.T) { + o := newObservedAddrMgr() + defer o.Close() + c1 := newConn(quic4ListenAddr, ma.StringCast("/ip4/1.2.3.1/udp/1/quic-v1")) + c2 := newConn(quic4ListenAddr, ma.StringCast("/ip4/1.2.3.2/udp/1/quic-v1")) + c3 := newConn(webTransport4ListenAddr, ma.StringCast("/ip4/1.2.3.3/udp/1/quic-v1/webtransport")) + c4 := newConn(webTransport4ListenAddr, ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1/webtransport")) + var observedQuic, observedWebTransport ma.Multiaddr + for i := 0; i < 10; i++ { + // Change the IP address in each observation + observedQuic = ma.StringCast(fmt.Sprintf("/ip4/2.2.2.%d/udp/2/quic-v1", i)) + observedWebTransport = ma.StringCast(fmt.Sprintf("/ip4/2.2.2.%d/udp/2/quic-v1/webtransport", i)) + o.Record(c1, observedQuic) + o.Record(c2, observedQuic) + o.Record(c3, observedWebTransport) + o.Record(c4, observedWebTransport) + time.Sleep(20 * time.Millisecond) + } + + require.Eventually(t, func() bool { + return addrsEqual(o.Addrs(), []ma.Multiaddr{observedQuic, observedWebTransport}) + }, 1*time.Second, 100*time.Millisecond) + + tw, err := thinWaistForm(quic4ListenAddr) + require.NoError(t, err) + require.Less(t, len(o.externalAddrs[string(tw.TW.Bytes())]), 2) + + require.Equal(t, o.AddrsFor(webTransport4ListenAddr), []ma.Multiaddr{observedWebTransport}) + require.Equal(t, o.AddrsFor(quic4ListenAddr), []ma.Multiaddr{observedQuic}) + + o.removeConn(c1) + o.removeConn(c2) + o.removeConn(c3) + o.removeConn(c4) + require.Eventually(t, func() bool { + return checkAllEntriesRemoved(o) + }, 1*time.Second, 100*time.Millisecond) + }) + + t.Run("Many connection many observations", func(t *testing.T) { + o := newObservedAddrMgr() + defer o.Close() + const N = 100 + var tcpConns, quicConns, webTransportConns [N]*mockConn + for i := 0; i < N; i++ { + tcpConns[i] = newConn(tcp4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/tcp/1", i))) + quicConns[i] = newConn(quic4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/udp/1/quic-v1", i))) + webTransportConns[i] = newConn(webTransport4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/udp/1/quic-v1/webtransport", i))) + } + var observedQuic, observedWebTransport, observedTCP ma.Multiaddr + for i := 0; i < N; i++ { + for j := 0; j < 5; j++ { + // ip addr has the form 2.2.. + observedQuic = ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.%d/udp/2/quic-v1", i/10, j)) + observedWebTransport = ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.%d/udp/2/quic-v1/webtransport", i/10, j)) + observedTCP = ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.%d/tcp/2", i/10, j)) + o.Record(tcpConns[i], observedTCP) + o.Record(quicConns[i], observedQuic) + o.Record(webTransportConns[i], observedWebTransport) + time.Sleep(10 * time.Millisecond) + } + } + // At this point we have 10 groups of N / 10 with 10 observations for every connection + // The output should remain stable + require.Eventually(t, func() bool { + return len(o.Addrs()) == 3*maxExternalThinWaistAddrsPerLocalAddr + }, 1*time.Second, 100*time.Millisecond) + addrs := o.Addrs() + for i := 0; i < 10; i++ { + require.ElementsMatch(t, o.Addrs(), addrs, "%s %s", o.Addrs(), addrs) + time.Sleep(10 * time.Millisecond) + } + + // Now we bias a few address counts and check for sorting correctness + var resTCPAddrs, resQuicAddrs, resWebTransportAddrs [maxExternalThinWaistAddrsPerLocalAddr]ma.Multiaddr + for i := 0; i < maxExternalThinWaistAddrsPerLocalAddr; i++ { + resTCPAddrs[i] = ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.4/tcp/2", 9-i)) + resQuicAddrs[i] = ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.4/udp/2/quic-v1", 9-i)) + resWebTransportAddrs[i] = ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.4/udp/2/quic-v1/webtransport", 9-i)) + o.Record(tcpConns[i], resTCPAddrs[i]) + o.Record(quicConns[i], resQuicAddrs[i]) + o.Record(webTransportConns[i], resWebTransportAddrs[i]) + time.Sleep(10 * time.Millisecond) + } + var allAddrs []ma.Multiaddr + allAddrs = append(allAddrs, resTCPAddrs[:]...) + allAddrs = append(allAddrs, resQuicAddrs[:]...) + allAddrs = append(allAddrs, resWebTransportAddrs[:]...) + require.Eventually(t, func() bool { + return addrsEqual(o.Addrs(), allAddrs) + }, 1*time.Second, 100*time.Millisecond) + + for i := 0; i < N; i++ { + o.removeConn(tcpConns[i]) + o.removeConn(quicConns[i]) + o.removeConn(webTransportConns[i]) + } + require.Eventually(t, func() bool { + return checkAllEntriesRemoved(o) + }, 1*time.Second, 100*time.Millisecond) + }) + + t.Run("WebTransport certhash", func(t *testing.T) { + o := newObservedAddrMgr() + observedWebTransport := ma.StringCast("/ip4/2.2.2.2/udp/1/quic-v1/webtransport") + c1 := newConn(webTransport4ListenAddr, ma.StringCast("/ip4/1.2.3.1/udp/1/quic-v1/webtransport")) + c2 := newConn(webTransport4ListenAddr, ma.StringCast("/ip4/1.2.3.2/udp/1/quic-v1/webtransport")) + c3 := newConn(webTransport4ListenAddr, ma.StringCast("/ip4/1.2.3.3/udp/1/quic-v1/webtransport")) + c4 := newConn(webTransport4ListenAddr, ma.StringCast("/ip4/1.2.3.4/udp/1/quic-v1/webtransport")) + o.Record(c1, observedWebTransport) + o.Record(c2, observedWebTransport) + o.Record(c3, observedWebTransport) + o.Record(c4, observedWebTransport) + require.Eventually(t, func() bool { + return addrsEqual(o.Addrs(), []ma.Multiaddr{observedWebTransport}) + }, 1*time.Second, 100*time.Millisecond) + o.removeConn(c1) + o.removeConn(c2) + o.removeConn(c3) + o.removeConn(c4) + require.Eventually(t, func() bool { + return checkAllEntriesRemoved(o) + }, 1*time.Second, 100*time.Millisecond) + }) + + t.Run("getNATType", func(t *testing.T) { + o := newObservedAddrMgr() + defer o.Close() + + observedWebTransport := ma.StringCast("/ip4/2.2.2.2/udp/1/quic-v1/webtransport") + var udpConns [5 * maxExternalThinWaistAddrsPerLocalAddr]connMultiaddrs + for i := 0; i < len(udpConns); i++ { + udpConns[i] = newConn(webTransport4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/udp/1/quic-v1/webtransport", i))) + o.Record(udpConns[i], observedWebTransport) + time.Sleep(10 * time.Millisecond) + } + require.Eventually(t, func() bool { + return addrsEqual(o.Addrs(), []ma.Multiaddr{observedWebTransport}) + }, 1*time.Second, 100*time.Millisecond) + + tcpNAT, udpNAT := o.getNATType() + require.Equal(t, tcpNAT, network.NATDeviceTypeUnknown) + require.Equal(t, udpNAT, network.NATDeviceTypeCone) + }) + t.Run("NATTypeSymmetric", func(t *testing.T) { + o := newObservedAddrMgr() + defer o.Close() + const N = 100 + var tcpConns, quicConns [N]*mockConn + for i := 0; i < N; i++ { + tcpConns[i] = newConn(tcp4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/tcp/1", i))) + quicConns[i] = newConn(quic4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/udp/1/quic-v1", i))) + } + var observedQuic, observedTCP ma.Multiaddr + for i := 0; i < N; i++ { + // ip addr has the form 2.2..2 + observedQuic = ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.2/udp/2/quic-v1", i%20)) + observedTCP = ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.2/tcp/2", i%20)) + o.Record(tcpConns[i], observedTCP) + o.Record(quicConns[i], observedQuic) + time.Sleep(10 * time.Millisecond) + } + // At this point we have 20 groups with 5 observations for every connection + // The output should remain stable + require.Eventually(t, func() bool { + return len(o.Addrs()) == 2*maxExternalThinWaistAddrsPerLocalAddr + }, 1*time.Second, 100*time.Millisecond) + + tcpNAT, udpNAT := o.getNATType() + require.Equal(t, tcpNAT, network.NATDeviceTypeSymmetric) + require.Equal(t, udpNAT, network.NATDeviceTypeSymmetric) + + for i := 0; i < N; i++ { + o.removeConn(tcpConns[i]) + o.removeConn(quicConns[i]) + } + require.Eventually(t, func() bool { + return checkAllEntriesRemoved(o) + }, 1*time.Second, 100*time.Millisecond) + }) + t.Run("Nill Input", func(t *testing.T) { + o := newObservedAddrMgr() + defer o.Close() + o.maybeRecordObservation(nil, nil) + remoteAddr := ma.StringCast("/ip4/1.2.3.4/tcp/1") + o.maybeRecordObservation(newConn(tcp4ListenAddr, remoteAddr), nil) + o.maybeRecordObservation(nil, remoteAddr) + o.AddrsFor(nil) + o.removeConn(nil) + }) + + t.Run("Nat Emitter", func(t *testing.T) { + o := newObservedAddrMgr() + defer o.Close() + bus := eventbus.NewBus() + + s := swarmt.GenSwarm(t, swarmt.EventBus(bus)) + h := blankhost.NewBlankHost(s, blankhost.WithEventBus(bus)) + defer h.Close() + // make reachability private + emitter, err := bus.Emitter(new(event.EvtLocalReachabilityChanged), eventbus.Stateful) + require.NoError(t, err) + emitter.Emit(event.EvtLocalReachabilityChanged{Reachability: network.ReachabilityPrivate}) + + // start nat emitter + n, err := newNATEmitter(h, o, 10*time.Millisecond) + require.NoError(t, err) + defer n.Close() + + sub, err := bus.Subscribe(new(event.EvtNATDeviceTypeChanged)) + require.NoError(t, err) + observedWebTransport := ma.StringCast("/ip4/2.2.2.2/udp/1/quic-v1/webtransport") + var udpConns [5 * maxExternalThinWaistAddrsPerLocalAddr]connMultiaddrs + for i := 0; i < len(udpConns); i++ { + udpConns[i] = newConn(webTransport4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/udp/1/quic-v1/webtransport", i))) + o.Record(udpConns[i], observedWebTransport) + time.Sleep(10 * time.Millisecond) + } + require.Eventually(t, func() bool { + return addrsEqual(o.Addrs(), []ma.Multiaddr{observedWebTransport}) + }, 1*time.Second, 100*time.Millisecond) + + var e interface{} + select { + case e = <-sub.Out(): + case <-time.After(2 * time.Second): + t.Fatalf("expected NAT change event") + } + evt := e.(event.EvtNATDeviceTypeChanged) + require.Equal(t, evt.TransportProtocol, network.NATTransportUDP) + require.Equal(t, evt.NatDeviceType, network.NATDeviceTypeCone) + }) + t.Run("Many connection many observations IP4 And IP6", func(t *testing.T) { + o := newObservedAddrMgr() + defer o.Close() + const N = 100 + var tcp4Conns, quic4Conns, webTransport4Conns [N]*mockConn + var tcp6Conns, quic6Conns, webTransport6Conns [N]*mockConn + for i := 0; i < N; i++ { + tcp4Conns[i] = newConn(tcp4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/tcp/1", i))) + quic4Conns[i] = newConn(quic4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/udp/1/quic-v1", i))) + webTransport4Conns[i] = newConn(webTransport4ListenAddr, ma.StringCast(fmt.Sprintf("/ip4/1.2.3.%d/udp/1/quic-v1/webtransport", i))) + + tcp6Conns[i] = newConn(tcp6ListenAddr, ma.StringCast(fmt.Sprintf("/ip6/20%02x::/tcp/1", i))) + quic6Conns[i] = newConn(quic6ListenAddr, ma.StringCast(fmt.Sprintf("/ip6/20%02x::/udp/1/quic-v1", i))) + webTransport6Conns[i] = newConn(webTransport6ListenAddr, ma.StringCast(fmt.Sprintf("/ip6/20%02x::/udp/1/quic-v1/webtransport", i))) + } + var observedQUIC4, observedWebTransport4, observedTCP4 ma.Multiaddr + var observedQUIC6, observedWebTransport6, observedTCP6 ma.Multiaddr + for i := 0; i < N; i++ { + for j := 0; j < 5; j++ { + // ip addr has the form 2.2.. + observedQUIC4 = ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.%d/udp/2/quic-v1", i/10, j)) + observedWebTransport4 = ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.%d/udp/2/quic-v1/webtransport", i/10, j)) + observedTCP4 = ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.%d/tcp/2", i/10, j)) + + // ip addr has the form 20XX::YY + observedQUIC6 = ma.StringCast(fmt.Sprintf("/ip6/20%02x::%02x/udp/2/quic-v1", i/10, j)) + observedWebTransport6 = ma.StringCast(fmt.Sprintf("/ip6/20%02x::%02x/udp/2/quic-v1/webtransport", i/10, j)) + observedTCP6 = ma.StringCast(fmt.Sprintf("/ip6/20%02x::%02x/tcp/2", i/10, j)) + + o.maybeRecordObservation(tcp4Conns[i], observedTCP4) + o.maybeRecordObservation(quic4Conns[i], observedQUIC4) + o.maybeRecordObservation(webTransport4Conns[i], observedWebTransport4) + + o.maybeRecordObservation(tcp6Conns[i], observedTCP6) + o.maybeRecordObservation(quic6Conns[i], observedQUIC6) + o.maybeRecordObservation(webTransport6Conns[i], observedWebTransport6) + } + } + // At this point we have 10 groups of N / 10 with 10 observations for every connection + // The output should remain stable + require.Eventually(t, func() bool { + return len(o.Addrs()) == 2*3*maxExternalThinWaistAddrsPerLocalAddr + }, 1*time.Second, 100*time.Millisecond) + addrs := o.Addrs() + for i := 0; i < 10; i++ { + require.ElementsMatch(t, o.Addrs(), addrs, "%s %s", o.Addrs(), addrs) + time.Sleep(10 * time.Millisecond) + } + + // Now we bias a few address counts and check for sorting correctness + var resTCPAddrs, resQuicAddrs, resWebTransportAddrs []ma.Multiaddr + + for i, idx := 0, 0; i < maxExternalThinWaistAddrsPerLocalAddr; i++ { + resTCPAddrs = append(resTCPAddrs, ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.4/tcp/2", 9-i))) + resQuicAddrs = append(resQuicAddrs, ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.4/udp/2/quic-v1", 9-i))) + resWebTransportAddrs = append(resWebTransportAddrs, ma.StringCast(fmt.Sprintf("/ip4/2.2.%d.4/udp/2/quic-v1/webtransport", 9-i))) + + o.maybeRecordObservation(tcp4Conns[i], resTCPAddrs[idx]) + o.maybeRecordObservation(quic4Conns[i], resQuicAddrs[idx]) + o.maybeRecordObservation(webTransport4Conns[i], resWebTransportAddrs[idx]) + idx++ + + resTCPAddrs = append(resTCPAddrs, ma.StringCast(fmt.Sprintf("/ip6/20%02x::04/tcp/2", 9-i))) + resQuicAddrs = append(resQuicAddrs, ma.StringCast(fmt.Sprintf("/ip6/20%02x::04/udp/2/quic-v1", 9-i))) + resWebTransportAddrs = append(resWebTransportAddrs, ma.StringCast(fmt.Sprintf("/ip6/20%02x::04/udp/2/quic-v1/webtransport", 9-i))) + o.maybeRecordObservation(tcp6Conns[i], resTCPAddrs[idx]) + o.maybeRecordObservation(quic6Conns[i], resQuicAddrs[idx]) + o.maybeRecordObservation(webTransport6Conns[i], resWebTransportAddrs[idx]) + idx++ + } + var allAddrs []ma.Multiaddr + allAddrs = append(allAddrs, resTCPAddrs[:]...) + allAddrs = append(allAddrs, resQuicAddrs[:]...) + allAddrs = append(allAddrs, resWebTransportAddrs[:]...) + require.Eventually(t, func() bool { + return addrsEqual(o.Addrs(), allAddrs) + }, 1*time.Second, 100*time.Millisecond) + + for i := 0; i < N; i++ { + o.removeConn(tcp4Conns[i]) + o.removeConn(quic4Conns[i]) + o.removeConn(webTransport4Conns[i]) + o.removeConn(tcp6Conns[i]) + o.removeConn(quic6Conns[i]) + o.removeConn(webTransport6Conns[i]) + } + require.Eventually(t, func() bool { + return checkAllEntriesRemoved(o) + }, 1*time.Second, 100*time.Millisecond) + }) } -func TestEmitNATDeviceTypeSymmetric(t *testing.T) { - harness := newHarness(t) - require.Empty(t, harness.oas.Addrs()) - emitter, err := harness.host.EventBus().Emitter(new(event.EvtLocalReachabilityChanged), eventbus.Stateful) - require.NoError(t, err) - require.NoError(t, emitter.Emit(event.EvtLocalReachabilityChanged{Reachability: network.ReachabilityPrivate})) - - // TCP - it1 := ma.StringCast("/ip4/1.2.3.4/tcp/1231") - it2 := ma.StringCast("/ip4/1.2.3.4/tcp/1232") - it3 := ma.StringCast("/ip4/1.2.3.4/tcp/1233") - it4 := ma.StringCast("/ip4/1.2.3.4/tcp/1234") - - // observers - b1 := ma.StringCast("/ip4/1.2.3.6/tcp/1236") - b2 := ma.StringCast("/ip4/1.2.3.7/tcp/1237") - b3 := ma.StringCast("/ip4/1.2.3.8/tcp/1237") - b4 := ma.StringCast("/ip4/1.2.3.9/tcp/1237") - - peers := []peer.ID{ - harness.add(b1), - harness.add(b2), - harness.add(b3), - harness.add(b4), +func genIPMultiaddr(ip6 bool) ma.Multiaddr { + var ipB [16]byte + crand.Read(ipB[:]) + var ip net.IP + if ip6 { + ip = net.IP(ipB[:]) + } else { + ip = net.IP(ipB[:4]) } - - harness.observe(it1, peers[0]) - harness.observe(it2, peers[1]) - harness.observe(it3, peers[2]) - harness.observe(it4, peers[3]) - - sub, err := harness.host.EventBus().Subscribe(new(event.EvtNATDeviceTypeChanged)) - require.NoError(t, err) - select { - case ev := <-sub.Out(): - evt := ev.(event.EvtNATDeviceTypeChanged) - require.Equal(t, network.NATDeviceTypeSymmetric, evt.NatDeviceType) - require.Equal(t, network.NATTransportTCP, evt.TransportProtocol) - case <-time.After(5 * time.Second): - t.Fatal("did not get Symmetric NAT event") - } - + addr, _ := manet.FromIP(ip) + return addr } -func TestEmitNATDeviceTypeCone(t *testing.T) { - harness := newHarness(t) - require.Empty(t, harness.oas.Addrs()) - emitter, err := harness.host.EventBus().Emitter(new(event.EvtLocalReachabilityChanged), eventbus.Stateful) - require.NoError(t, err) - require.NoError(t, emitter.Emit(event.EvtLocalReachabilityChanged{Reachability: network.ReachabilityPrivate})) - - it1 := ma.StringCast("/ip4/1.2.3.4/tcp/1231") - it2 := ma.StringCast("/ip4/1.2.3.4/tcp/1231") - it3 := ma.StringCast("/ip4/1.2.3.4/tcp/1231") - it4 := ma.StringCast("/ip4/1.2.3.4/tcp/1231") - - // observers - b1 := ma.StringCast("/ip4/1.2.3.6/tcp/1236") - b2 := ma.StringCast("/ip4/1.2.3.7/tcp/1237") - b3 := ma.StringCast("/ip4/1.2.3.8/tcp/1237") - b4 := ma.StringCast("/ip4/1.2.3.9/tcp/1237") - - peers := []peer.ID{ - harness.add(b1), - harness.add(b2), - harness.add(b3), - harness.add(b4), +func FuzzObservedAddrManager(f *testing.F) { + protos := []string{ + "/webrtc-direct", + "/quic-v1", + "/quic-v1/webtransport", + } + tcp4 := ma.StringCast("/ip4/192.168.1.100/tcp/1") + quic4 := ma.StringCast("/ip4/0.0.0.0/udp/1/quic-v1") + wt4 := ma.StringCast("/ip4/0.0.0.0/udp/1/quic-v1/webtransport/certhash/uEgNmb28") + tcp6 := ma.StringCast("/ip6/1::1/tcp/1") + quic6 := ma.StringCast("/ip6/::/udp/1/quic-v1") + wt6 := ma.StringCast("/ip6/::/udp/1/quic-v1/webtransport/certhash/uEgNmb28") + newObservedAddrMgr := func() *ObservedAddrManager { + listenAddrs := []ma.Multiaddr{ + tcp4, quic4, wt4, tcp6, quic6, wt6, + } + listenAddrsFunc := func() []ma.Multiaddr { + return listenAddrs + } + interfaceListenAddrsFunc := func() ([]ma.Multiaddr, error) { + return listenAddrs, nil + } + o, err := NewObservedAddrManager(listenAddrsFunc, listenAddrsFunc, + interfaceListenAddrsFunc, normalize) + if err != nil { + panic(err) + } + return o } - harness.observe(it1, peers[0]) - harness.observe(it2, peers[1]) - harness.observe(it3, peers[2]) - harness.observe(it4, peers[3]) + f.Fuzz(func(t *testing.T, port uint16) { + addrs := []ma.Multiaddr{genIPMultiaddr(true), genIPMultiaddr(false)} + n := len(addrs) + for i := 0; i < n; i++ { + addrs = append(addrs, addrs[i].Encapsulate(ma.StringCast(fmt.Sprintf("/tcp/%d", port)))) + addrs = append(addrs, addrs[i].Encapsulate(ma.StringCast(fmt.Sprintf("/udp/%d", port)))) + addrs = append(addrs, ma.StringCast(fmt.Sprintf("/tcp/%d", port))) + addrs = append(addrs, ma.StringCast(fmt.Sprintf("/udp/%d", port))) + } + n = len(addrs) + for i := 0; i < n; i++ { + for j := 0; j < len(protos); j++ { + protoAddr := ma.StringCast(protos[j]) + addrs = append(addrs, addrs[i].Encapsulate(protoAddr)) + addrs = append(addrs, protoAddr) + } + } + o := newObservedAddrMgr() + defer o.Close() + for i := 0; i < len(addrs); i++ { + for _, l := range o.listenAddrs() { + c := newConn(l, addrs[i]) + o.maybeRecordObservation(c, addrs[i]) + o.maybeRecordObservation(c, nil) + o.maybeRecordObservation(nil, addrs[i]) + o.removeConn(c) + } + } + }) +} - sub, err := harness.host.EventBus().Subscribe(new(event.EvtNATDeviceTypeChanged)) - require.NoError(t, err) - select { - case ev := <-sub.Out(): - evt := ev.(event.EvtNATDeviceTypeChanged) - require.Equal(t, network.NATDeviceTypeCone, evt.NatDeviceType) - case <-time.After(5 * time.Second): - t.Fatal("did not get Cone NAT event") +func TestObserver(t *testing.T) { + tests := []struct { + addr ma.Multiaddr + want string + }{ + { + addr: ma.StringCast("/ip4/1.2.3.4/tcp/1"), + want: "1.2.3.4", + }, + { + addr: ma.StringCast("/ip4/192.168.0.1/tcp/1"), + want: "192.168.0.1", + }, + { + addr: ma.StringCast("/ip6/200::1/udp/1/quic-v1"), + want: "200::", + }, + { + addr: ma.StringCast("/ip6/::1/udp/1/quic-v1"), + want: "::", + }, + } + + for i, tc := range tests { + t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + got, err := getObserver(tc.addr) + require.NoError(t, err) + require.Equal(t, got, tc.want) + }) } } - -func TestObserveWebtransport(t *testing.T) { - listenAddr := ma.StringCast("/ip4/1.2.3.4/udp/9999/quic-v1/webtransport/certhash/uEgNmb28") - observedAddr := ma.StringCast("/ip4/1.2.3.4/udp/1231/quic-v1/webtransport") - - harness := newHarnessWithMa(t, listenAddr) - - pb1 := harness.add(ma.StringCast("/ip4/1.2.3.6/udp/1236/quic-v1/webtransport")) - pb2 := harness.add(ma.StringCast("/ip4/1.2.3.7/udp/1237/quic-v1/webtransport")) - pb3 := harness.add(ma.StringCast("/ip4/1.2.3.8/udp/1237/quic-v1/webtransport")) - pb4 := harness.add(ma.StringCast("/ip4/1.2.3.9/udp/1237/quic-v1/webtransport")) - pb5 := harness.add(ma.StringCast("/ip4/1.2.3.10/udp/1237/quic-v1/webtransport")) - - harness.observe(observedAddr, pb1) - harness.observe(observedAddr, pb2) - harness.observe(observedAddr, pb3) - harness.observe(observedAddr, pb4) - harness.observe(observedAddr, pb5) - - require.Equal(t, 1, len(harness.oas.Addrs())) - require.Equal(t, "/ip4/1.2.3.4/udp/1231/quic-v1/webtransport", harness.oas.Addrs()[0].String()) -} diff --git a/go-libp2p/p2p/protocol/identify/opts.go b/go-libp2p/p2p/protocol/identify/opts.go index f188665..bd0fd89 100644 --- a/go-libp2p/p2p/protocol/identify/opts.go +++ b/go-libp2p/p2p/protocol/identify/opts.go @@ -1,10 +1,11 @@ package identify type config struct { - protocolVersion string - userAgent string - disableSignedPeerRecord bool - metricsTracer MetricsTracer + protocolVersion string + userAgent string + disableSignedPeerRecord bool + metricsTracer MetricsTracer + disableObservedAddrManager bool } // Option is an option function for identify. @@ -38,3 +39,11 @@ func WithMetricsTracer(tr MetricsTracer) Option { cfg.metricsTracer = tr } } + +// DisableObservedAddrManager disables the observed address manager. It also +// effectively disables the nat emitter and EvtNATDeviceTypeChanged +func DisableObservedAddrManager() Option { + return func(cfg *config) { + cfg.disableObservedAddrManager = true + } +} diff --git a/go-libp2p/p2p/protocol/ping/ping.go b/go-libp2p/p2p/protocol/ping/ping.go index 6ff5c3f..9a67715 100644 --- a/go-libp2p/p2p/protocol/ping/ping.go +++ b/go-libp2p/p2p/protocol/ping/ping.go @@ -111,7 +111,7 @@ func pingError(err error) chan Result { // Ping pings the remote peer until the context is canceled, returning a stream // of RTTs or errors. func Ping(ctx context.Context, h host.Host, p peer.ID) <-chan Result { - s, err := h.NewStream(network.WithUseTransient(ctx, "ping"), p, ID) + s, err := h.NewStream(network.WithAllowLimitedConn(ctx, "ping"), p, ID) if err != nil { return pingError(err) } @@ -158,11 +158,10 @@ func Ping(ctx context.Context, h host.Host, p peer.ID) <-chan Result { } } }() - go func() { + context.AfterFunc(ctx, func() { // forces the ping to abort. - <-ctx.Done() s.Reset() - }() + }) return out } diff --git a/go-libp2p/p2p/security/noise/LICENSE.md b/go-libp2p/p2p/security/noise/LICENSE.md deleted file mode 100644 index 15601cb..0000000 --- a/go-libp2p/p2p/security/noise/LICENSE.md +++ /dev/null @@ -1,229 +0,0 @@ -The contents of this repository are Copyright (c) corresponding authors and -contributors, licensed under the `Permissive License Stack` meaning either of: - -- Apache-2.0 Software License: https://www.apache.org/licenses/LICENSE-2.0 - ([...4tr2kfsq](https://gateway.ipfs.io/ipfs/bafkreiankqxazcae4onkp436wag2lj3ccso4nawxqkkfckd6cg4tr2kfsq)) - -- MIT Software License: https://opensource.org/licenses/MIT - ([...vljevcba](https://gateway.ipfs.io/ipfs/bafkreiepofszg4gfe2gzuhojmksgemsub2h4uy2gewdnr35kswvljevcba)) - -You may not use the contents of this repository except in compliance -with one of the listed Licenses. For an extended clarification of the -intent behind the choice of Licensing please refer to -https://protocol.ai/blog/announcing-the-permissive-license-stack/ - -Unless required by applicable law or agreed to in writing, software -distributed under the terms listed in this notice is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -either express or implied. See each License for the specific language -governing permissions and limitations under that License. - - -`SPDX-License-Identifier: Apache-2.0 OR MIT` - -Verbatim copies of both licenses are included below: - -
Apache-2.0 Software License - -``` - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS -``` -
- -
MIT Software License - -``` -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -``` -
diff --git a/go-libp2p/p2p/security/noise/handshake.go b/go-libp2p/p2p/security/noise/handshake.go index e1a18e9..4760768 100644 --- a/go-libp2p/p2p/security/noise/handshake.go +++ b/go-libp2p/p2p/security/noise/handshake.go @@ -5,18 +5,17 @@ import ( "crypto/rand" "encoding/binary" "fmt" - "hash" "os" "runtime/debug" "time" "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/sec" "github.com/libp2p/go-libp2p/p2p/security/noise/pb" "github.com/flynn/noise" pool "github.com/libp2p/go-buffer-pool" - "github.com/minio/sha256-simd" "google.golang.org/protobuf/proto" ) @@ -26,15 +25,8 @@ import ( // our libp2p identity key. const payloadSigPrefix = "noise-libp2p-static-key:" -type minioSHAFn struct{} - -func (h minioSHAFn) Hash() hash.Hash { return sha256.New() } -func (h minioSHAFn) HashName() string { return "SHA256" } - -var shaHashFn noise.HashFunc = minioSHAFn{} - // All noise session share a fixed cipher suite -var cipherSuite = noise.NewCipherSuite(noise.DH25519, noise.CipherChaChaPoly, shaHashFn) +var cipherSuite = noise.NewCipherSuite(noise.DH25519, noise.CipherChaChaPoly, noise.HashSHA256) // runHandshake exchanges handshake messages with the remote peer to establish // a noise-libp2p session. It blocks until the handshake completes or fails. @@ -276,7 +268,7 @@ func (s *secureSession) handleRemoteHandshakePayload(payload []byte, remoteStati // check the peer ID if enabled if s.checkPeerID && s.remoteID != id { - return nil, fmt.Errorf("peer id mismatch: expected %s, but remote key matches %s", s.remoteID.Pretty(), id.Pretty()) + return nil, sec.ErrPeerIDMismatch{Expected: s.remoteID, Actual: id} } // verify payload is signed by asserted remote libp2p key. diff --git a/go-libp2p/p2p/security/noise/transport_test.go b/go-libp2p/p2p/security/noise/transport_test.go index 42477f8..ea7916f 100644 --- a/go-libp2p/p2p/security/noise/transport_test.go +++ b/go-libp2p/p2p/security/noise/transport_test.go @@ -182,16 +182,16 @@ func TestPeerIDMatch(t *testing.T) { defer close(done) conn, err := initTransport.SecureOutbound(context.Background(), init, respTransport.localID) assert.NoError(t, err) - assert.Equal(t, conn.RemotePeer(), respTransport.localID) + assert.Equal(t, respTransport.localID, conn.RemotePeer()) b := make([]byte, 6) _, err = conn.Read(b) assert.NoError(t, err) - assert.Equal(t, b, []byte("foobar")) + assert.Equal(t, []byte("foobar"), b) }() conn, err := respTransport.SecureInbound(context.Background(), resp, initTransport.localID) require.NoError(t, err) - require.Equal(t, conn.RemotePeer(), initTransport.localID) + require.Equal(t, initTransport.localID, conn.RemotePeer()) _, err = conn.Write([]byte("foobar")) require.NoError(t, err) } @@ -212,7 +212,10 @@ func TestPeerIDMismatchOutboundFailsHandshake(t *testing.T) { initErr := <-errChan require.Error(t, initErr, "expected initiator to fail with peer ID mismatch error") - require.Contains(t, initErr.Error(), "but remote key matches") + var mismatchErr sec.ErrPeerIDMismatch + require.ErrorAs(t, initErr, &mismatchErr) + require.Equal(t, mismatchErr.Expected, peer.ID("a-random-peer-id")) + require.Equal(t, mismatchErr.Actual, respTransport.localID) } func TestPeerIDMismatchInboundFailsHandshake(t *testing.T) { @@ -231,6 +234,10 @@ func TestPeerIDMismatchInboundFailsHandshake(t *testing.T) { _, err := respTransport.SecureInbound(context.Background(), resp, "a-random-peer-id") require.Error(t, err, "expected responder to fail with peer ID mismatch error") + var mismatchErr sec.ErrPeerIDMismatch + require.ErrorAs(t, err, &mismatchErr) + require.Equal(t, mismatchErr.Expected, peer.ID("a-random-peer-id")) + require.Equal(t, mismatchErr.Actual, initTransport.localID) <-done } @@ -347,7 +354,7 @@ func TestBufferEqEncPayload(t *testing.T) { afterLen, err := respConn.Read(after) require.NoError(t, err) - require.Equal(t, len(before), afterLen) + require.Len(t, before, afterLen) require.Equal(t, before, after[:len(before)]) } @@ -367,7 +374,7 @@ func TestBufferEqDecryptedPayload(t *testing.T) { afterLen, err := respConn.Read(after) require.NoError(t, err) - require.Equal(t, len(before), afterLen) + require.Len(t, before, afterLen) require.Equal(t, before, after[:len(before)]) } @@ -386,7 +393,7 @@ func TestReadUnencryptedFails(t *testing.T) { copy(msg[LengthPrefixLength:], before) n, err := initConn.insecureConn.Write(msg) require.NoError(t, err) - require.Equal(t, len(msg), n) + require.Len(t, msg, n) after := make([]byte, len(msg)+1) afterLen, err := respConn.Read(after) @@ -407,7 +414,7 @@ func TestReadUnencryptedFails(t *testing.T) { copy(msg[LengthPrefixLength:], before) n, err = initConn.insecureConn.Write(msg) require.NoError(t, err) - require.Equal(t, len(msg), n) + require.Len(t, msg, n) after = make([]byte, 1) afterLen, err = respConn.Read(after) @@ -588,7 +595,6 @@ func TestEarlyDataRejected(t *testing.T) { clientErr, serverErr := handshake(t, sendingEDH, receivingEDH) require.Error(t, clientErr) require.EqualError(t, serverErr, "nope") - }) t.Run("server sending", func(t *testing.T) { diff --git a/go-libp2p/p2p/security/tls/LICENSE.md b/go-libp2p/p2p/security/tls/LICENSE.md deleted file mode 100644 index a94e82c..0000000 --- a/go-libp2p/p2p/security/tls/LICENSE.md +++ /dev/null @@ -1,7 +0,0 @@ -Copyright 2018 Marten Seemann - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/go-libp2p/p2p/security/tls/cmd/tlsdiag/client.go b/go-libp2p/p2p/security/tls/cmd/tlsdiag/client.go index 3868afe..a29189a 100644 --- a/go-libp2p/p2p/security/tls/cmd/tlsdiag/client.go +++ b/go-libp2p/p2p/security/tls/cmd/tlsdiag/client.go @@ -33,7 +33,7 @@ func StartClient() error { if err != nil { return err } - fmt.Printf(" Peer ID: %s\n", id.Pretty()) + fmt.Printf(" Peer ID: %s\n", id) tp, err := libp2ptls.New(libp2ptls.ID, priv, nil) if err != nil { return err @@ -53,7 +53,7 @@ func StartClient() error { if err != nil { return err } - fmt.Printf("Authenticated server: %s\n", sconn.RemotePeer().Pretty()) + fmt.Printf("Authenticated server: %s\n", sconn.RemotePeer()) data, err := io.ReadAll(sconn) if err != nil { return err diff --git a/go-libp2p/p2p/security/tls/cmd/tlsdiag/server.go b/go-libp2p/p2p/security/tls/cmd/tlsdiag/server.go index 76c45a1..cd702a7 100644 --- a/go-libp2p/p2p/security/tls/cmd/tlsdiag/server.go +++ b/go-libp2p/p2p/security/tls/cmd/tlsdiag/server.go @@ -26,7 +26,7 @@ func StartServer() error { if err != nil { return err } - fmt.Printf(" Peer ID: %s\n", id.Pretty()) + fmt.Printf(" Peer ID: %s\n", id) tp, err := libp2ptls.New(libp2ptls.ID, priv, nil) if err != nil { return err @@ -38,7 +38,7 @@ func StartServer() error { } fmt.Printf("Listening for new connections on %s\n", ln.Addr()) fmt.Printf("Now run the following command in a separate terminal:\n") - fmt.Printf("\tgo run cmd/tlsdiag.go client -p %d -id %s\n", *port, id.Pretty()) + fmt.Printf("\tgo run cmd/tlsdiag.go client -p %d -id %s\n", *port, id) for { conn, err := ln.Accept() @@ -61,7 +61,7 @@ func handleConn(tp *libp2ptls.Transport, conn net.Conn) error { if err != nil { return err } - fmt.Printf("Authenticated client: %s\n", sconn.RemotePeer().Pretty()) + fmt.Printf("Authenticated client: %s\n", sconn.RemotePeer()) fmt.Fprintf(sconn, "Hello client!") fmt.Printf("Closing connection to %s\n", conn.RemoteAddr()) return sconn.Close() diff --git a/go-libp2p/p2p/security/tls/crypto.go b/go-libp2p/p2p/security/tls/crypto.go index b8f23f3..70a594d 100644 --- a/go-libp2p/p2p/security/tls/crypto.go +++ b/go-libp2p/p2p/security/tls/crypto.go @@ -11,6 +11,7 @@ import ( "encoding/asn1" "errors" "fmt" + "io" "math/big" "os" "runtime/debug" @@ -18,6 +19,7 @@ import ( ic "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/sec" ) const certValidityPeriod = 100 * 365 * 24 * time.Hour // ~100 years @@ -40,6 +42,7 @@ type Identity struct { // IdentityConfig is used to configure an Identity type IdentityConfig struct { CertTemplate *x509.Certificate + KeyLogWriter io.Writer } // IdentityOption transforms an IdentityConfig to apply optional settings. @@ -52,6 +55,18 @@ func WithCertTemplate(template *x509.Certificate) IdentityOption { } } +// WithKeyLogWriter optionally specifies a destination for TLS master secrets +// in NSS key log format that can be used to allow external programs +// such as Wireshark to decrypt TLS connections. +// See https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format. +// Use of KeyLogWriter compromises security and should only be +// used for debugging. +func WithKeyLogWriter(w io.Writer) IdentityOption { + return func(c *IdentityConfig) { + c.KeyLogWriter = w + } +} + // NewIdentity creates a new identity func NewIdentity(privKey ic.PrivKey, opts ...IdentityOption) (*Identity, error) { config := IdentityConfig{} @@ -82,6 +97,7 @@ func NewIdentity(privKey ic.PrivKey, opts ...IdentityOption) (*Identity, error) }, NextProtos: []string{alpn}, SessionTicketsDisabled: true, + KeyLogWriter: config.KeyLogWriter, }, }, nil } @@ -129,7 +145,7 @@ func (i *Identity) ConfigForPeer(remote peer.ID) (*tls.Config, <-chan ic.PubKey) if err != nil { peerID = peer.ID(fmt.Sprintf("(not determined: %s)", err.Error())) } - return fmt.Errorf("peer IDs don't match: expected %s, got %s", remote, peerID) + return sec.ErrPeerIDMismatch{Expected: remote, Actual: peerID} } keyCh <- pubKey return nil diff --git a/go-libp2p/p2p/security/tls/crypto_test.go b/go-libp2p/p2p/security/tls/crypto_test.go index 872f588..efec949 100644 --- a/go-libp2p/p2p/security/tls/crypto_test.go +++ b/go-libp2p/p2p/security/tls/crypto_test.go @@ -19,31 +19,31 @@ func TestNewIdentityCertificates(t *testing.T) { t.Run("NewIdentity with default template", func(t *testing.T) { // Generate an identity using the default template id, err := NewIdentity(key) - assert.NoError(t, err) + require.NoError(t, err) // Extract the x509 certificate x509Cert, err := x509.ParseCertificate(id.config.Certificates[0].Certificate[0]) - assert.NoError(t, err) + require.NoError(t, err) // verify the common name and email are not set - assert.Empty(t, x509Cert.Subject.CommonName) - assert.Empty(t, x509Cert.EmailAddresses) + require.Empty(t, x509Cert.Subject.CommonName) + require.Empty(t, x509Cert.EmailAddresses) }) t.Run("NewIdentity with custom template", func(t *testing.T) { tmpl, err := certTemplate() - assert.NoError(t, err) + require.NoError(t, err) tmpl.Subject.CommonName = cn tmpl.EmailAddresses = []string{email} // Generate an identity using the custom template id, err := NewIdentity(key, WithCertTemplate(tmpl)) - assert.NoError(t, err) + require.NoError(t, err) // Extract the x509 certificate x509Cert, err := x509.ParseCertificate(id.config.Certificates[0].Certificate[0]) - assert.NoError(t, err) + require.NoError(t, err) // verify the common name and email are set assert.Equal(t, cn, x509Cert.Subject.CommonName) diff --git a/go-libp2p/p2p/security/tls/extension_test.go b/go-libp2p/p2p/security/tls/extension_test.go index f50695a..6bed725 100644 --- a/go-libp2p/p2p/security/tls/extension_test.go +++ b/go-libp2p/p2p/security/tls/extension_test.go @@ -7,7 +7,7 @@ import ( ) func TestExtensionGenerating(t *testing.T) { - require.Equal(t, getPrefixedExtensionID([]int{13, 37}), []int{1, 3, 6, 1, 4, 1, 53594, 13, 37}) + require.Equal(t, []int{1, 3, 6, 1, 4, 1, 53594, 13, 37}, getPrefixedExtensionID([]int{13, 37})) } func TestExtensionComparison(t *testing.T) { diff --git a/go-libp2p/p2p/security/tls/transport.go b/go-libp2p/p2p/security/tls/transport.go index 7c28efe..0c494a7 100644 --- a/go-libp2p/p2p/security/tls/transport.go +++ b/go-libp2p/p2p/security/tls/transport.go @@ -113,7 +113,7 @@ func (t *Transport) SecureOutbound(ctx context.Context, insecure net.Conn, p pee for _, muxer := range t.muxers { muxers = append(muxers, (string)(muxer)) } - // Prepend the prefered muxers list to TLS config. + // Prepend the preferred muxers list to TLS config. config.NextProtos = append(muxers, config.NextProtos...) cs, err := t.handshake(ctx, tls.Client(insecure, config), keyCh) if err != nil { diff --git a/go-libp2p/p2p/security/tls/transport_test.go b/go-libp2p/p2p/security/tls/transport_test.go index 2d3c2d9..b53d9bf 100644 --- a/go-libp2p/p2p/security/tls/transport_test.go +++ b/go-libp2p/p2p/security/tls/transport_test.go @@ -46,7 +46,7 @@ func createPeer(t *testing.T) (peer.ID, ic.PrivKey) { require.NoError(t, err) id, err := peer.IDFromPrivateKey(priv) require.NoError(t, err) - t.Logf("using a %s key: %s", priv.Type(), id.Pretty()) + t.Logf("using a %s key: %s", priv.Type(), id) return id, priv } @@ -121,7 +121,7 @@ func TestHandshakeSucceeds(t *testing.T) { b := make([]byte, 6) _, err = clientConn.Read(b) require.NoError(t, err) - require.Equal(t, string(b), "foobar") + require.Equal(t, "foobar", string(b)) } // Use standard transports with default TLS configuration @@ -245,21 +245,21 @@ func TestHandshakeWithNextProtoSucceeds(t *testing.T) { } defer serverConn.Close() - require.Equal(t, clientConn.LocalPeer(), clientID) - require.Equal(t, serverConn.LocalPeer(), serverID) - require.Equal(t, clientConn.RemotePeer(), serverID) - require.Equal(t, serverConn.RemotePeer(), clientID) + require.Equal(t, clientID, clientConn.LocalPeer()) + require.Equal(t, serverID, serverConn.LocalPeer()) + require.Equal(t, serverID, clientConn.RemotePeer()) + require.Equal(t, clientID, serverConn.RemotePeer()) require.True(t, clientConn.RemotePublicKey().Equals(serverKey.GetPublic()), "server public key mismatch") require.True(t, serverConn.RemotePublicKey().Equals(clientKey.GetPublic()), "client public key mismatch") - require.Equal(t, clientConn.ConnState().StreamMultiplexer, expectedMuxer) - require.Equal(t, clientConn.ConnState().UsedEarlyMuxerNegotiation, expectedMuxer != "") + require.Equal(t, expectedMuxer, clientConn.ConnState().StreamMultiplexer) + require.Equal(t, expectedMuxer != "", clientConn.ConnState().UsedEarlyMuxerNegotiation) // exchange some data _, err = serverConn.Write([]byte("foobar")) require.NoError(t, err) b := make([]byte, 6) _, err = clientConn.Read(b) require.NoError(t, err) - require.Equal(t, string(b), "foobar") + require.Equal(t, "foobar", string(b)) } // Iterate through the StreamMultiplexer combinations. @@ -376,7 +376,10 @@ func TestPeerIDMismatch(t *testing.T) { thirdPartyID, _ := createPeer(t) _, err = clientTransport.SecureOutbound(context.Background(), clientInsecureConn, thirdPartyID) require.Error(t, err) - require.Contains(t, err.Error(), "peer IDs don't match") + var mismatchErr sec.ErrPeerIDMismatch + require.ErrorAs(t, err, &mismatchErr) + require.Equal(t, mismatchErr.Expected, thirdPartyID) + require.Equal(t, mismatchErr.Actual, serverID) var serverErr error select { @@ -392,8 +395,8 @@ func TestPeerIDMismatch(t *testing.T) { clientInsecureConn, serverInsecureConn := connect(t) errChan := make(chan error) + thirdPartyID, _ := createPeer(t) go func() { - thirdPartyID, _ := createPeer(t) // expect the wrong peer ID _, err := serverTransport.SecureInbound(context.Background(), serverInsecureConn, thirdPartyID) errChan <- err @@ -412,7 +415,10 @@ func TestPeerIDMismatch(t *testing.T) { t.Fatal("expected handshake to return on the server side") } require.Error(t, serverErr) - require.Contains(t, serverErr.Error(), "peer IDs don't match") + var mismatchErr sec.ErrPeerIDMismatch + require.ErrorAs(t, serverErr, &mismatchErr) + require.Equal(t, mismatchErr.Expected, thirdPartyID) + require.Equal(t, mismatchErr.Actual, clientTransport.localPeer) }) } diff --git a/go-libp2p/p2p/test/basichost/basic_host_test.go b/go-libp2p/p2p/test/basichost/basic_host_test.go index 6b010ed..9cd442d 100644 --- a/go-libp2p/p2p/test/basichost/basic_host_test.go +++ b/go-libp2p/p2p/test/basichost/basic_host_test.go @@ -3,14 +3,20 @@ package basichost import ( "context" "fmt" + "strings" "testing" + "time" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/peerstore" "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/client" "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/relay" + libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc" + libp2pwebtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport" ma "github.com/multiformats/go-multiaddr" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -18,12 +24,14 @@ func TestNoStreamOverTransientConnection(t *testing.T) { h1, err := libp2p.New( libp2p.NoListenAddrs, libp2p.EnableRelay(), + libp2p.ResourceManager(&network.NullResourceManager{}), ) require.NoError(t, err) h2, err := libp2p.New( libp2p.NoListenAddrs, libp2p.EnableRelay(), + libp2p.ResourceManager(&network.NullResourceManager{}), ) require.NoError(t, err) @@ -62,11 +70,132 @@ func TestNoStreamOverTransientConnection(t *testing.T) { err = h1.Connect(context.Background(), h2Info) require.NoError(t, err) - ctx := network.WithNoDial(context.Background(), "test") + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + ctx = network.WithNoDial(ctx, "test") _, err = h1.NewStream(ctx, h2.ID(), "/testprotocol") - require.ErrorIs(t, err, network.ErrTransientConn) + require.Error(t, err) - _, err = h1.NewStream(network.WithUseTransient(context.Background(), "test"), h2.ID(), "/testprotocol") + _, err = h1.NewStream(network.WithAllowLimitedConn(context.Background(), "test"), h2.ID(), "/testprotocol") require.NoError(t, err) } + +func TestNewStreamTransientConnection(t *testing.T) { + h1, err := libp2p.New( + libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1"), + libp2p.EnableRelay(), + libp2p.ResourceManager(&network.NullResourceManager{}), + ) + require.NoError(t, err) + + h2, err := libp2p.New( + libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1"), + libp2p.EnableRelay(), + libp2p.ResourceManager(&network.NullResourceManager{}), + ) + require.NoError(t, err) + + relay1, err := libp2p.New() + require.NoError(t, err) + + _, err = relay.New(relay1) + require.NoError(t, err) + + relay1info := peer.AddrInfo{ + ID: relay1.ID(), + Addrs: relay1.Addrs(), + } + err = h1.Connect(context.Background(), relay1info) + require.NoError(t, err) + + err = h2.Connect(context.Background(), relay1info) + require.NoError(t, err) + + h2.SetStreamHandler("/testprotocol", func(s network.Stream) { + fmt.Println("testprotocol") + + // End the example + s.Close() + }) + + _, err = client.Reserve(context.Background(), h2, relay1info) + require.NoError(t, err) + + relayaddr := ma.StringCast("/p2p/" + relay1info.ID.String() + "/p2p-circuit/p2p/" + h2.ID().String()) + + h1.Peerstore().AddAddr(h2.ID(), relayaddr, peerstore.TempAddrTTL) + + // NewStream should block transient connections till we have a direct connection + ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) + defer cancel() + s, err := h1.NewStream(ctx, h2.ID(), "/testprotocol") + require.ErrorIs(t, err, context.DeadlineExceeded) + require.Nil(t, s) + + // NewStream should return a stream if a direct connection is established + // while waiting + done := make(chan bool, 2) + go func() { + h1.Peerstore().AddAddrs(h2.ID(), h2.Addrs(), peerstore.TempAddrTTL) + ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + ctx = network.WithNoDial(ctx, "test") + s, err = h1.NewStream(ctx, h2.ID(), "/testprotocol") + require.NoError(t, err) + require.NotNil(t, s) + defer s.Close() + require.Equal(t, network.DirInbound, s.Conn().Stat().Direction) + done <- true + }() + go func() { + // connect h2 to h1 simulating connection reversal + h2.Peerstore().AddAddrs(h1.ID(), h1.Addrs(), peerstore.TempAddrTTL) + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() + ctx = network.WithForceDirectDial(ctx, "test") + err := h2.Connect(ctx, peer.AddrInfo{ID: h1.ID()}) + assert.NoError(t, err) + done <- true + }() + <-done + <-done +} + +func TestAddrFactorCertHashAppend(t *testing.T) { + wtAddr := "/ip4/1.2.3.4/udp/1/quic-v1/webtransport" + webrtcAddr := "/ip4/1.2.3.4/udp/2/webrtc-direct" + addrsFactory := func(addrs []ma.Multiaddr) []ma.Multiaddr { + return append(addrs, + ma.StringCast(wtAddr), + ma.StringCast(webrtcAddr), + ) + } + h, err := libp2p.New( + libp2p.AddrsFactory(addrsFactory), + libp2p.Transport(libp2pwebrtc.New), + libp2p.Transport(libp2pwebtransport.New), + libp2p.ListenAddrStrings( + "/ip4/0.0.0.0/udp/0/quic-v1/webtransport", + "/ip4/0.0.0.0/udp/0/webrtc-direct", + ), + ) + require.NoError(t, err) + require.Eventually(t, func() bool { + addrs := h.Addrs() + var hasWebRTC, hasWebTransport bool + for _, addr := range addrs { + if strings.HasPrefix(addr.String(), webrtcAddr) { + if _, err := addr.ValueForProtocol(ma.P_CERTHASH); err == nil { + hasWebRTC = true + } + } + if strings.HasPrefix(addr.String(), wtAddr) { + if _, err := addr.ValueForProtocol(ma.P_CERTHASH); err == nil { + hasWebTransport = true + } + } + } + return hasWebRTC && hasWebTransport + }, 5*time.Second, 100*time.Millisecond) +} diff --git a/go-libp2p/p2p/test/negotiation/muxer_test.go b/go-libp2p/p2p/test/negotiation/muxer_test.go index 9301e66..52c6622 100644 --- a/go-libp2p/p2p/test/negotiation/muxer_test.go +++ b/go-libp2p/p2p/test/negotiation/muxer_test.go @@ -11,7 +11,6 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/protocol" "github.com/libp2p/go-libp2p/core/sec/insecure" - "github.com/libp2p/go-libp2p/p2p/muxer/mplex" "github.com/libp2p/go-libp2p/p2p/muxer/yamux" "github.com/libp2p/go-libp2p/p2p/security/noise" tls "github.com/libp2p/go-libp2p/p2p/security/tls" @@ -21,8 +20,8 @@ import ( ) var ( - yamuxOpt = libp2p.Muxer("/yamux", yamux.DefaultTransport) - mplexOpt = libp2p.Muxer("/mplex", mplex.DefaultTransport) + yamuxOpt = libp2p.Muxer("/yamux", yamux.DefaultTransport) + anotherYamuxOpt = libp2p.Muxer("/another-yamux", yamux.DefaultTransport) ) type testcase struct { @@ -43,32 +42,32 @@ func TestMuxerNegotiation(t *testing.T) { testcases := []testcase{ { Name: "server and client have the same preference", - ServerPreference: []libp2p.Option{yamuxOpt, mplexOpt}, - ClientPreference: []libp2p.Option{yamuxOpt, mplexOpt}, + ServerPreference: []libp2p.Option{yamuxOpt, anotherYamuxOpt}, + ClientPreference: []libp2p.Option{yamuxOpt, anotherYamuxOpt}, Expected: "/yamux", }, { Name: "client only supports one muxer", - ServerPreference: []libp2p.Option{yamuxOpt, mplexOpt}, + ServerPreference: []libp2p.Option{yamuxOpt, anotherYamuxOpt}, ClientPreference: []libp2p.Option{yamuxOpt}, Expected: "/yamux", }, { Name: "server only supports one muxer", ServerPreference: []libp2p.Option{yamuxOpt}, - ClientPreference: []libp2p.Option{mplexOpt, yamuxOpt}, + ClientPreference: []libp2p.Option{anotherYamuxOpt, yamuxOpt}, Expected: "/yamux", }, { Name: "client preference preferred", - ServerPreference: []libp2p.Option{yamuxOpt, mplexOpt}, - ClientPreference: []libp2p.Option{mplexOpt, yamuxOpt}, - Expected: "/mplex", + ServerPreference: []libp2p.Option{yamuxOpt, anotherYamuxOpt}, + ClientPreference: []libp2p.Option{anotherYamuxOpt, yamuxOpt}, + Expected: "/another-yamux", }, { Name: "no preference overlap", ServerPreference: []libp2p.Option{yamuxOpt}, - ClientPreference: []libp2p.Option{mplexOpt}, + ClientPreference: []libp2p.Option{anotherYamuxOpt}, Error: "failed to negotiate stream multiplexer: protocols not supported", }, } diff --git a/go-libp2p/p2p/test/notifications/notification_test.go b/go-libp2p/p2p/test/notifications/notification_test.go index b6159ac..eb26a3f 100644 --- a/go-libp2p/p2p/test/notifications/notification_test.go +++ b/go-libp2p/p2p/test/notifications/notification_test.go @@ -41,7 +41,7 @@ func TestListenAddressNotif(t *testing.T) { ev := e.(event.EvtLocalAddressesUpdated) require.Empty(t, ev.Removed) require.Len(t, ev.Current, 1) - require.Equal(t, ev.Current[0].Action, event.Added) + require.Equal(t, event.Added, ev.Current[0].Action) initialAddr = ev.Current[0].Address portStr, err := initialAddr.ValueForProtocol(ma.P_TCP) require.NoError(t, err) diff --git a/go-libp2p/p2p/test/quic/quic_test.go b/go-libp2p/p2p/test/quic/quic_test.go index 0603c89..fe52119 100644 --- a/go-libp2p/p2p/test/quic/quic_test.go +++ b/go-libp2p/p2p/test/quic/quic_test.go @@ -26,103 +26,12 @@ func getQUICMultiaddrCode(addr ma.Multiaddr) int { return 0 } -func TestQUICVersions(t *testing.T) { - h1, err := libp2p.New( - libp2p.Transport(libp2pquic.NewTransport), - libp2p.Transport(webtransport.New), - libp2p.ListenAddrStrings( - "/ip4/127.0.0.1/udp/12345/quic", // QUIC draft-29 - "/ip4/127.0.0.1/udp/12345/quic-v1", // QUIC v1 - ), - ) - require.NoError(t, err) - defer h1.Close() - - addrs := h1.Addrs() - require.Len(t, addrs, 2) - var quicDraft29Addr, quicV1Addr ma.Multiaddr - for _, addr := range addrs { - switch getQUICMultiaddrCode(addr) { - case ma.P_QUIC: - quicDraft29Addr = addr - case ma.P_QUIC_V1: - quicV1Addr = addr - } - } - require.NotNil(t, quicDraft29Addr, "expected to be listening on a QUIC draft-29 address") - require.NotNil(t, quicV1Addr, "expected to be listening on a QUIC v1 address") - - ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) - defer cancel() - // connect using QUIC draft-29 - h2, err := libp2p.New( - libp2p.Transport(libp2pquic.NewTransport), - ) - require.NoError(t, err) - require.NoError(t, h2.Connect(ctx, peer.AddrInfo{ID: h1.ID(), Addrs: []ma.Multiaddr{quicDraft29Addr}})) - conns := h2.Network().ConnsToPeer(h1.ID()) - require.Len(t, conns, 1) - require.Equal(t, ma.P_QUIC, getQUICMultiaddrCode(conns[0].LocalMultiaddr())) - require.Equal(t, ma.P_QUIC, getQUICMultiaddrCode(conns[0].RemoteMultiaddr())) - h2.Close() - - // connect using QUIC v1 - h3, err := libp2p.New( - libp2p.Transport(libp2pquic.NewTransport), - ) - require.NoError(t, err) - require.NoError(t, h3.Connect(ctx, peer.AddrInfo{ID: h1.ID(), Addrs: []ma.Multiaddr{quicV1Addr}})) - conns = h3.Network().ConnsToPeer(h1.ID()) - require.Len(t, conns, 1) - require.Equal(t, ma.P_QUIC_V1, getQUICMultiaddrCode(conns[0].LocalMultiaddr())) - require.Equal(t, ma.P_QUIC_V1, getQUICMultiaddrCode(conns[0].RemoteMultiaddr())) - h3.Close() -} - -func TestDisableQUICDraft29(t *testing.T) { - h1, err := libp2p.New( - libp2p.QUICReuse(quicreuse.NewConnManager, quicreuse.DisableDraft29()), - libp2p.Transport(libp2pquic.NewTransport), - libp2p.Transport(webtransport.New), - libp2p.ListenAddrStrings( - "/ip4/127.0.0.1/udp/12346/quic", // QUIC draft-29 - "/ip4/127.0.0.1/udp/12346/quic-v1", // QUIC v1 - ), - ) - require.NoError(t, err) - defer h1.Close() - - addrs := h1.Addrs() - require.Len(t, addrs, 1) - require.Equal(t, ma.P_QUIC_V1, getQUICMultiaddrCode(addrs[0])) - - // connect using QUIC draft-29 - h2, err := libp2p.New( - libp2p.Transport(libp2pquic.NewTransport), - ) - require.NoError(t, err) - defer h2.Close() - // We disabled QUIC Version Negotiation, so we will _not_ receive a Version Negotiation packet. - // Instead, the connection will run into the context timeout. - ctx, cancel := context.WithTimeout(context.Background(), 300*time.Microsecond) - defer cancel() - require.ErrorIs(t, - h2.Connect(ctx, peer.AddrInfo{ID: h1.ID(), Addrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/udp/12346/quic")}}), - context.DeadlineExceeded, - ) - // make sure that dialing QUIC v1 works - ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - require.NoError(t, h2.Connect(ctx, peer.AddrInfo{ID: h1.ID(), Addrs: []ma.Multiaddr{addrs[0]}})) -} - func TestQUICAndWebTransport(t *testing.T) { h1, err := libp2p.New( libp2p.QUICReuse(quicreuse.NewConnManager), libp2p.Transport(libp2pquic.NewTransport), libp2p.Transport(webtransport.New), libp2p.ListenAddrStrings( - "/ip4/127.0.0.1/udp/12347/quic/", "/ip4/127.0.0.1/udp/12347/quic-v1", "/ip4/127.0.0.1/udp/12347/quic-v1/webtransport", ), @@ -131,19 +40,16 @@ func TestQUICAndWebTransport(t *testing.T) { defer h1.Close() addrs := h1.Addrs() - require.Len(t, addrs, 3) - var quicDraft29Addr, quicV1Addr, webtransportAddr ma.Multiaddr + require.Len(t, addrs, 2) + var quicV1Addr, webtransportAddr ma.Multiaddr for _, addr := range addrs { if _, err := addr.ValueForProtocol(ma.P_WEBTRANSPORT); err == nil { webtransportAddr = addr } else if _, err := addr.ValueForProtocol(ma.P_QUIC_V1); err == nil { quicV1Addr = addr - } else { - quicDraft29Addr = addr } } require.NotNil(t, webtransportAddr, "expected to have a WebTransport address") - require.NotNil(t, quicDraft29Addr, "expected to have a QUIC draft-29 address") require.NotNil(t, quicV1Addr, "expected to have a QUIC v1 address") ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) @@ -165,36 +71,14 @@ func TestQUICAndWebTransport(t *testing.T) { } h2.Close() - // then test that we can dial a QUIC draft-29 - h3, err := libp2p.New( - libp2p.Transport(libp2pquic.NewTransport), - libp2p.NoListenAddrs, - ) - require.NoError(t, err) - require.NoError(t, h3.Connect(ctx, peer.AddrInfo{ - ID: h1.ID(), - // a libp2p host will prefer dialing v1 if it supports both versions, - // so we need to filter the addresses so it thinks that h1 only supports draft-29 - Addrs: ma.FilterAddrs(h1.Addrs(), func(addr ma.Multiaddr) bool { _, err := addr.ValueForProtocol(ma.P_QUIC); return err == nil }), - })) - for _, conns := range [][]network.Conn{h3.Network().ConnsToPeer(h1.ID()), h1.Network().ConnsToPeer(h3.ID())} { - require.Len(t, conns, 1) - if _, err := conns[0].LocalMultiaddr().ValueForProtocol(ma.P_WEBTRANSPORT); err == nil { - t.Fatalf("expected a QUIC connection, got a WebTransport connection (%s <-> %s)", conns[0].LocalMultiaddr(), conns[0].RemoteMultiaddr()) - } - require.Equal(t, ma.P_QUIC, getQUICMultiaddrCode(conns[0].LocalMultiaddr())) - require.Equal(t, ma.P_QUIC, getQUICMultiaddrCode(conns[0].RemoteMultiaddr())) - } - h3.Close() - // finally, test that we can dial a WebTransport connection - h4, err := libp2p.New( + h3, err := libp2p.New( libp2p.Transport(webtransport.New), libp2p.NoListenAddrs, ) require.NoError(t, err) - require.NoError(t, h4.Connect(ctx, peer.AddrInfo{ID: h1.ID(), Addrs: h1.Addrs()})) - for _, conns := range [][]network.Conn{h4.Network().ConnsToPeer(h1.ID()), h1.Network().ConnsToPeer(h4.ID())} { + require.NoError(t, h3.Connect(ctx, peer.AddrInfo{ID: h1.ID(), Addrs: h1.Addrs()})) + for _, conns := range [][]network.Conn{h3.Network().ConnsToPeer(h1.ID()), h1.Network().ConnsToPeer(h3.ID())} { require.Len(t, conns, 1) if _, err := conns[0].LocalMultiaddr().ValueForProtocol(ma.P_WEBTRANSPORT); err != nil { t.Fatalf("expected a WebTransport connection, got a QUIC connection (%s <-> %s)", conns[0].LocalMultiaddr(), conns[0].RemoteMultiaddr()) @@ -202,5 +86,5 @@ func TestQUICAndWebTransport(t *testing.T) { require.Equal(t, ma.P_QUIC_V1, getQUICMultiaddrCode(conns[0].LocalMultiaddr())) require.Equal(t, ma.P_QUIC_V1, getQUICMultiaddrCode(conns[0].RemoteMultiaddr())) } - h4.Close() + h3.Close() } diff --git a/go-libp2p/p2p/test/security/bench_test.go b/go-libp2p/p2p/test/security/bench_test.go new file mode 100644 index 0000000..fb50e3f --- /dev/null +++ b/go-libp2p/p2p/test/security/bench_test.go @@ -0,0 +1,130 @@ +package benchmark + +import ( + "context" + crand "crypto/rand" + "io" + "net" + "sync" + "testing" + + "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/sec" + "github.com/libp2p/go-libp2p/p2p/security/noise" + tls "github.com/libp2p/go-libp2p/p2p/security/tls" + "github.com/stretchr/testify/assert" +) + +type Factory func(*testing.B, crypto.PrivKey) sec.SecureTransport + +func benchmarkThroughput(b *testing.B, size int, factory Factory) { + privA, pubA, err := crypto.GenerateEd25519Key(crand.Reader) + assert.NoError(b, err) + idA, err := peer.IDFromPublicKey(pubA) + assert.NoError(b, err) + tptA := factory(b, privA) + + privB, pubB, err := crypto.GenerateEd25519Key(crand.Reader) + assert.NoError(b, err) + idB, err := peer.IDFromPublicKey(pubB) + assert.NoError(b, err) + tptB := factory(b, privB) + + // pipe here serialize the decryption and encryption, we might want both parallelised to reduce context switching impact on the benchmark. + // https://github.com/golang/go/issues/34502 would be ideal for the parallel usecase. + p1, p2 := net.Pipe() + var ready sync.Mutex // wait for completed handshake + var finished sync.Mutex // wait until all data has been received + ready.Lock() + finished.Lock() + go func() { + defer finished.Unlock() + conn, err := tptB.SecureInbound(context.Background(), p2, idA) + assert.NoError(b, err) + ready.Unlock() + + _, err = io.Copy(io.Discard, conn) + assert.NoError(b, err) + }() + + conn, err := tptA.SecureOutbound(context.Background(), p1, idB) + assert.NoError(b, err) + ready.Lock() + + buf := make([]byte, size) + b.SetBytes(int64(len(buf))) + b.ResetTimer() + + for i := b.N; i != 0; i-- { + _, err = conn.Write(buf[:]) + assert.NoError(b, err) + } + conn.Close() + + finished.Lock() +} +func benchmarkHandshakes(b *testing.B, factory Factory) { + privA, pubA, err := crypto.GenerateEd25519Key(crand.Reader) + assert.NoError(b, err) + idA, err := peer.IDFromPublicKey(pubA) + assert.NoError(b, err) + tptA := factory(b, privA) + + privB, pubB, err := crypto.GenerateEd25519Key(crand.Reader) + assert.NoError(b, err) + idB, err := peer.IDFromPublicKey(pubB) + assert.NoError(b, err) + tptB := factory(b, privB) + + pipes := make(chan net.Conn, 1) + + var finished sync.Mutex // wait until all data has been transferred + finished.Lock() + go func() { + defer finished.Unlock() + var throwAway [1]byte + for p := range pipes { + conn, err := tptB.SecureInbound(context.Background(), p, idA) + assert.NoError(b, err) + _, err = conn.Read(throwAway[:]) // read because currently the tls transport handshake when calling Read. + assert.ErrorIs(b, err, io.EOF) + } + }() + b.ResetTimer() + + for i := b.N; i != 0; i-- { + p1, p2 := net.Pipe() + pipes <- p2 + conn, err := tptA.SecureOutbound(context.Background(), p1, idB) + assert.NoError(b, err) + assert.NoError(b, conn.Close()) + } + close(pipes) + + finished.Lock() +} + +func bench(b *testing.B, factory Factory) { + b.Run("throughput", func(b *testing.B) { + b.Run("32KiB", func(b *testing.B) { benchmarkThroughput(b, 32*1024, factory) }) + b.Run("1MiB", func(b *testing.B) { benchmarkThroughput(b, 1024*1024, factory) }) + }) + b.Run("handshakes", func(b *testing.B) { benchmarkHandshakes(b, factory) }) +} + +func BenchmarkNoise(b *testing.B) { + bench(b, func(b *testing.B, priv crypto.PrivKey) sec.SecureTransport { + tpt, err := noise.New("", priv, nil) + assert.NoError(b, err) + return tpt + }) +} + +func BenchmarkTLS(b *testing.B) { + bench(b, func(b *testing.B, priv crypto.PrivKey) sec.SecureTransport { + tpt, err := tls.New("", priv, nil) + assert.NoError(b, err) + return tpt + }) +} diff --git a/go-libp2p/p2p/test/swarm/swarm_test.go b/go-libp2p/p2p/test/swarm/swarm_test.go new file mode 100644 index 0000000..10298f5 --- /dev/null +++ b/go-libp2p/p2p/test/swarm/swarm_test.go @@ -0,0 +1,245 @@ +package swarm_test + +import ( + "context" + "io" + "sync" + "testing" + "time" + + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/peerstore" + rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" + "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/client" + "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/relay" + ma "github.com/multiformats/go-multiaddr" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestDialPeerTransientConnection(t *testing.T) { + h1, err := libp2p.New( + libp2p.NoListenAddrs, + libp2p.EnableRelay(), + ) + require.NoError(t, err) + + h2, err := libp2p.New( + libp2p.NoListenAddrs, + libp2p.EnableRelay(), + ) + require.NoError(t, err) + + relay1, err := libp2p.New() + require.NoError(t, err) + + _, err = relay.New(relay1) + require.NoError(t, err) + + relay1info := peer.AddrInfo{ + ID: relay1.ID(), + Addrs: relay1.Addrs(), + } + err = h1.Connect(context.Background(), relay1info) + require.NoError(t, err) + + err = h2.Connect(context.Background(), relay1info) + require.NoError(t, err) + + _, err = client.Reserve(context.Background(), h2, relay1info) + require.NoError(t, err) + + relayaddr := ma.StringCast("/p2p/" + relay1info.ID.String() + "/p2p-circuit/p2p/" + h2.ID().String()) + + h1.Peerstore().AddAddr(h2.ID(), relayaddr, peerstore.TempAddrTTL) + + // swarm.DialPeer should connect over transient connections + conn1, err := h1.Network().DialPeer(context.Background(), h2.ID()) + require.NoError(t, err) + require.NotNil(t, conn1) + + // Test that repeated calls return the same connection. + conn2, err := h1.Network().DialPeer(context.Background(), h2.ID()) + require.NoError(t, err) + require.NotNil(t, conn2) + + require.Equal(t, conn1, conn2) + + // swarm.DialPeer should fail if forceDirect is used + ctx := network.WithForceDirectDial(context.Background(), "test") + conn, err := h1.Network().DialPeer(ctx, h2.ID()) + require.Error(t, err) + require.Nil(t, conn) +} + +func TestNewStreamTransientConnection(t *testing.T) { + h1, err := libp2p.New( + libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1"), + libp2p.EnableRelay(), + ) + require.NoError(t, err) + + h2, err := libp2p.New( + libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1"), + libp2p.EnableRelay(), + ) + require.NoError(t, err) + + relay1, err := libp2p.New() + require.NoError(t, err) + + _, err = relay.New(relay1) + require.NoError(t, err) + + relay1info := peer.AddrInfo{ + ID: relay1.ID(), + Addrs: relay1.Addrs(), + } + err = h1.Connect(context.Background(), relay1info) + require.NoError(t, err) + + err = h2.Connect(context.Background(), relay1info) + require.NoError(t, err) + + _, err = client.Reserve(context.Background(), h2, relay1info) + require.NoError(t, err) + + relayaddr := ma.StringCast("/p2p/" + relay1info.ID.String() + "/p2p-circuit/p2p/" + h2.ID().String()) + + h1.Peerstore().AddAddr(h2.ID(), relayaddr, peerstore.TempAddrTTL) + + // WithAllowLimitedConn should succeed + ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) + defer cancel() + ctx = network.WithAllowLimitedConn(ctx, "test") + s, err := h1.Network().NewStream(ctx, h2.ID()) + require.NoError(t, err) + require.NotNil(t, s) + defer s.Close() + + // Without WithAllowLimitedConn should fail with context deadline exceeded + ctx, cancel = context.WithTimeout(context.Background(), 200*time.Millisecond) + defer cancel() + s, err = h1.Network().NewStream(ctx, h2.ID()) + require.ErrorIs(t, err, context.DeadlineExceeded) + require.Nil(t, s) + + // Provide h2's direct address to h1. + h1.Peerstore().AddAddrs(h2.ID(), h2.Addrs(), peerstore.TempAddrTTL) + // network.NoDial should also fail + ctx, cancel = context.WithTimeout(context.Background(), 200*time.Millisecond) + defer cancel() + ctx = network.WithNoDial(ctx, "test") + s, err = h1.Network().NewStream(ctx, h2.ID()) + require.ErrorIs(t, err, context.DeadlineExceeded) + require.Nil(t, s) + + done := make(chan bool, 2) + // NewStream should return a stream if an incoming direct connection is established + go func() { + ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + ctx = network.WithNoDial(ctx, "test") + s, err = h1.Network().NewStream(ctx, h2.ID()) + assert.NoError(t, err) + assert.NotNil(t, s) + defer s.Close() + require.Equal(t, network.DirInbound, s.Conn().Stat().Direction) + done <- true + }() + go func() { + // connect h2 to h1 simulating connection reversal + h2.Peerstore().AddAddrs(h1.ID(), h1.Addrs(), peerstore.TempAddrTTL) + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() + ctx = network.WithForceDirectDial(ctx, "test") + err := h2.Connect(ctx, peer.AddrInfo{ID: h1.ID()}) + assert.NoError(t, err) + done <- true + }() + + <-done + <-done +} + +func TestLimitStreamsWhenHangingHandlers(t *testing.T) { + var partial rcmgr.PartialLimitConfig + const streamLimit = 10 + partial.System.Streams = streamLimit + mgr, err := rcmgr.NewResourceManager(rcmgr.NewFixedLimiter(partial.Build(rcmgr.InfiniteLimits))) + require.NoError(t, err) + + maddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/0/quic-v1") + require.NoError(t, err) + + receiver, err := libp2p.New( + libp2p.ResourceManager(mgr), + libp2p.ListenAddrs(maddr), + ) + require.NoError(t, err) + t.Cleanup(func() { receiver.Close() }) + + var wg sync.WaitGroup + wg.Add(1) + + const pid = "/test" + receiver.SetStreamHandler(pid, func(s network.Stream) { + defer s.Close() + s.Write([]byte{42}) + wg.Wait() + }) + + // Open streamLimit streams + success := 0 + // we make a lot of tries because identify and identify push take up a few streams + for i := 0; i < 1000 && success < streamLimit; i++ { + mgr, err = rcmgr.NewResourceManager(rcmgr.NewFixedLimiter(rcmgr.InfiniteLimits)) + require.NoError(t, err) + + sender, err := libp2p.New(libp2p.ResourceManager(mgr)) + require.NoError(t, err) + t.Cleanup(func() { sender.Close() }) + + sender.Peerstore().AddAddrs(receiver.ID(), receiver.Addrs(), peerstore.PermanentAddrTTL) + + s, err := sender.NewStream(context.Background(), receiver.ID(), pid) + if err != nil { + continue + } + + var b [1]byte + _, err = io.ReadFull(s, b[:]) + if err == nil { + success++ + } + sender.Close() + } + require.Equal(t, streamLimit, success) + // We have the maximum number of streams open. Next call should fail. + mgr, err = rcmgr.NewResourceManager(rcmgr.NewFixedLimiter(rcmgr.InfiniteLimits)) + require.NoError(t, err) + + sender, err := libp2p.New(libp2p.ResourceManager(mgr)) + require.NoError(t, err) + t.Cleanup(func() { sender.Close() }) + + sender.Peerstore().AddAddrs(receiver.ID(), receiver.Addrs(), peerstore.PermanentAddrTTL) + + _, err = sender.NewStream(context.Background(), receiver.ID(), pid) + require.Error(t, err) + + // Close the open streams + wg.Done() + + // Next call should succeed + require.Eventually(t, func() bool { + s, err := sender.NewStream(context.Background(), receiver.ID(), pid) + if err == nil { + s.Close() + return true + } + return false + }, 5*time.Second, 100*time.Millisecond) +} diff --git a/go-libp2p/p2p/test/transport/deadline_test.go b/go-libp2p/p2p/test/transport/deadline_test.go new file mode 100644 index 0000000..55fa7a4 --- /dev/null +++ b/go-libp2p/p2p/test/transport/deadline_test.go @@ -0,0 +1,94 @@ +package transport_integration + +import ( + "context" + "net" + "testing" + "time" + + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/stretchr/testify/require" +) + +func TestReadWriteDeadlines(t *testing.T) { + // Send a lot of data so that writes have to flush (can't just buffer it all) + sendBuf := make([]byte, 10<<20) + for _, tc := range transportsToTest { + t.Run(tc.Name, func(t *testing.T) { + listener := tc.HostGenerator(t, TransportTestCaseOpts{}) + defer listener.Close() + dialer := tc.HostGenerator(t, TransportTestCaseOpts{NoListen: true}) + defer dialer.Close() + + require.NoError(t, dialer.Connect(context.Background(), peer.AddrInfo{ + ID: listener.ID(), + Addrs: listener.Addrs(), + })) + + // This simply stalls + listener.SetStreamHandler("/stall", func(s network.Stream) { + time.Sleep(time.Hour) + s.Close() + }) + + t.Run("ReadDeadline", func(t *testing.T) { + s, err := dialer.NewStream(context.Background(), listener.ID(), "/stall") + require.NoError(t, err) + defer s.Close() + + start := time.Now() + // Set a deadline + s.SetReadDeadline(time.Now().Add(10 * time.Millisecond)) + buf := make([]byte, 1) + _, err = s.Read(buf) + require.Error(t, err) + var nerr net.Error + require.ErrorAs(t, err, &nerr) + require.True(t, nerr.Timeout()) + require.Less(t, time.Since(start), 1*time.Second) + }) + + t.Run("WriteDeadline", func(t *testing.T) { + s, err := dialer.NewStream(context.Background(), listener.ID(), "/stall") + require.NoError(t, err) + defer s.Close() + + // Set a deadline + s.SetWriteDeadline(time.Now().Add(10 * time.Millisecond)) + start := time.Now() + _, err = s.Write(sendBuf) + require.Error(t, err) + require.True(t, err.(net.Error).Timeout()) + require.Less(t, time.Since(start), 1*time.Second) + }) + + // Like the above, but with SetDeadline + t.Run("SetDeadline", func(t *testing.T) { + for _, op := range []string{"Read", "Write"} { + t.Run(op, func(t *testing.T) { + s, err := dialer.NewStream(context.Background(), listener.ID(), "/stall") + require.NoError(t, err) + defer s.Close() + + // Set a deadline + s.SetDeadline(time.Now().Add(10 * time.Millisecond)) + start := time.Now() + + if op == "Read" { + buf := make([]byte, 1) + _, err = s.Read(buf) + } else { + _, err = s.Write(sendBuf) + } + require.Error(t, err) + var nerr net.Error + require.ErrorAs(t, err, &nerr) + require.True(t, nerr.Timeout()) + require.Less(t, time.Since(start), 1*time.Second) + }) + } + }) + }) + } +} diff --git a/go-libp2p/p2p/test/transport/gating_test.go b/go-libp2p/p2p/test/transport/gating_test.go index 426fc90..df53da6 100644 --- a/go-libp2p/p2p/test/transport/gating_test.go +++ b/go-libp2p/p2p/test/transport/gating_test.go @@ -2,6 +2,7 @@ package transport_integration import ( "context" + "strings" "testing" "time" @@ -12,12 +13,12 @@ import ( "github.com/libp2p/go-libp2p-testing/race" - "github.com/golang/mock/gomock" ma "github.com/multiformats/go-multiaddr" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) -//go:generate go run github.com/golang/mock/mockgen -package transport_integration -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater +//go:generate go run go.uber.org/mock/mockgen -package transport_integration -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater func stripCertHash(addr ma.Multiaddr) ma.Multiaddr { for { @@ -88,6 +89,8 @@ func TestInterceptSecuredOutgoing(t *testing.T) { h1 := tc.HostGenerator(t, TransportTestCaseOpts{NoListen: true, ConnGater: connGater}) h2 := tc.HostGenerator(t, TransportTestCaseOpts{}) + defer h1.Close() + defer h2.Close() require.Len(t, h2.Addrs(), 1) require.Len(t, h2.Addrs(), 1) @@ -97,7 +100,7 @@ func TestInterceptSecuredOutgoing(t *testing.T) { connGater.EXPECT().InterceptPeerDial(h2.ID()).Return(true), connGater.EXPECT().InterceptAddrDial(h2.ID(), gomock.Any()).Return(true), connGater.EXPECT().InterceptSecured(network.DirOutbound, h2.ID(), gomock.Any()).Do(func(_ network.Direction, _ peer.ID, addrs network.ConnMultiaddrs) { - // remove the certhash component from WebTransport addresses + // remove the certhash component from WebTransport and WebRTC addresses require.Equal(t, stripCertHash(h2.Addrs()[0]).String(), addrs.RemoteMultiaddr().String()) }), ) @@ -120,6 +123,8 @@ func TestInterceptUpgradedOutgoing(t *testing.T) { h1 := tc.HostGenerator(t, TransportTestCaseOpts{NoListen: true, ConnGater: connGater}) h2 := tc.HostGenerator(t, TransportTestCaseOpts{}) + defer h1.Close() + defer h2.Close() require.Len(t, h2.Addrs(), 1) require.Len(t, h2.Addrs(), 1) @@ -154,19 +159,35 @@ func TestInterceptAccept(t *testing.T) { h1 := tc.HostGenerator(t, TransportTestCaseOpts{NoListen: true}) h2 := tc.HostGenerator(t, TransportTestCaseOpts{ConnGater: connGater}) + defer h1.Close() + defer h2.Close() require.Len(t, h2.Addrs(), 1) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() // The basic host dials the first connection. - connGater.EXPECT().InterceptAccept(gomock.Any()).Do(func(addrs network.ConnMultiaddrs) { - // remove the certhash component from WebTransport addresses - require.Equal(t, stripCertHash(h2.Addrs()[0]), addrs.LocalMultiaddr()) - }) + if strings.Contains(tc.Name, "WebRTC") { + // In WebRTC, retransmissions of the STUN packet might cause us to create multiple connections, + // if the first connection attempt is rejected. + connGater.EXPECT().InterceptAccept(gomock.Any()).Do(func(addrs network.ConnMultiaddrs) { + // remove the certhash component from WebTransport addresses + require.Equal(t, stripCertHash(h2.Addrs()[0]), addrs.LocalMultiaddr()) + }).AnyTimes() + } else { + connGater.EXPECT().InterceptAccept(gomock.Any()).Do(func(addrs network.ConnMultiaddrs) { + // remove the certhash component from WebTransport addresses + require.Equal(t, stripCertHash(h2.Addrs()[0]), addrs.LocalMultiaddr()) + }) + } + h1.Peerstore().AddAddrs(h2.ID(), h2.Addrs(), time.Hour) _, err := h1.NewStream(ctx, h2.ID(), protocol.TestingID) require.Error(t, err) - require.NotErrorIs(t, err, context.DeadlineExceeded) + if _, err := h2.Addrs()[0].ValueForProtocol(ma.P_WEBRTC_DIRECT); err != nil { + // WebRTC rejects connection attempt before an error can be sent to the client. + // This means that the connection attempt will time out. + require.NotErrorIs(t, err, context.DeadlineExceeded) + } }) } } @@ -183,6 +204,8 @@ func TestInterceptSecuredIncoming(t *testing.T) { h1 := tc.HostGenerator(t, TransportTestCaseOpts{NoListen: true}) h2 := tc.HostGenerator(t, TransportTestCaseOpts{ConnGater: connGater}) + defer h1.Close() + defer h2.Close() require.Len(t, h2.Addrs(), 1) ctx, cancel := context.WithTimeout(context.Background(), time.Second) @@ -214,6 +237,8 @@ func TestInterceptUpgradedIncoming(t *testing.T) { h1 := tc.HostGenerator(t, TransportTestCaseOpts{NoListen: true}) h2 := tc.HostGenerator(t, TransportTestCaseOpts{ConnGater: connGater}) + defer h1.Close() + defer h2.Close() require.Len(t, h2.Addrs(), 1) ctx, cancel := context.WithTimeout(context.Background(), time.Second) diff --git a/go-libp2p/p2p/test/transport/mock_connection_gater_test.go b/go-libp2p/p2p/test/transport/mock_connection_gater_test.go index d6efc8b..d617f72 100644 --- a/go-libp2p/p2p/test/transport/mock_connection_gater_test.go +++ b/go-libp2p/p2p/test/transport/mock_connection_gater_test.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/libp2p/go-libp2p/core/connmgr (interfaces: ConnectionGater) +// +// Generated by this command: +// +// mockgen -package transport_integration -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater +// // Package transport_integration is a generated GoMock package. package transport_integration @@ -7,11 +12,11 @@ package transport_integration import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" control "github.com/libp2p/go-libp2p/core/control" network "github.com/libp2p/go-libp2p/core/network" peer "github.com/libp2p/go-libp2p/core/peer" multiaddr "github.com/multiformats/go-multiaddr" + gomock "go.uber.org/mock/gomock" ) // MockConnectionGater is a mock of ConnectionGater interface. @@ -46,7 +51,7 @@ func (m *MockConnectionGater) InterceptAccept(arg0 network.ConnMultiaddrs) bool } // InterceptAccept indicates an expected call of InterceptAccept. -func (mr *MockConnectionGaterMockRecorder) InterceptAccept(arg0 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptAccept(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptAccept", reflect.TypeOf((*MockConnectionGater)(nil).InterceptAccept), arg0) } @@ -60,7 +65,7 @@ func (m *MockConnectionGater) InterceptAddrDial(arg0 peer.ID, arg1 multiaddr.Mul } // InterceptAddrDial indicates an expected call of InterceptAddrDial. -func (mr *MockConnectionGaterMockRecorder) InterceptAddrDial(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptAddrDial(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptAddrDial", reflect.TypeOf((*MockConnectionGater)(nil).InterceptAddrDial), arg0, arg1) } @@ -74,7 +79,7 @@ func (m *MockConnectionGater) InterceptPeerDial(arg0 peer.ID) bool { } // InterceptPeerDial indicates an expected call of InterceptPeerDial. -func (mr *MockConnectionGaterMockRecorder) InterceptPeerDial(arg0 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptPeerDial(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptPeerDial", reflect.TypeOf((*MockConnectionGater)(nil).InterceptPeerDial), arg0) } @@ -88,7 +93,7 @@ func (m *MockConnectionGater) InterceptSecured(arg0 network.Direction, arg1 peer } // InterceptSecured indicates an expected call of InterceptSecured. -func (mr *MockConnectionGaterMockRecorder) InterceptSecured(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptSecured(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptSecured", reflect.TypeOf((*MockConnectionGater)(nil).InterceptSecured), arg0, arg1, arg2) } @@ -103,7 +108,7 @@ func (m *MockConnectionGater) InterceptUpgraded(arg0 network.Conn) (bool, contro } // InterceptUpgraded indicates an expected call of InterceptUpgraded. -func (mr *MockConnectionGaterMockRecorder) InterceptUpgraded(arg0 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptUpgraded(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptUpgraded", reflect.TypeOf((*MockConnectionGater)(nil).InterceptUpgraded), arg0) } diff --git a/go-libp2p/p2p/test/transport/rcmgr_test.go b/go-libp2p/p2p/test/transport/rcmgr_test.go index 378d1f9..c19a05d 100644 --- a/go-libp2p/p2p/test/transport/rcmgr_test.go +++ b/go-libp2p/p2p/test/transport/rcmgr_test.go @@ -9,14 +9,15 @@ import ( "testing" "time" - gomock "github.com/golang/mock/gomock" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" mocknetwork "github.com/libp2p/go-libp2p/core/network/mocks" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/p2p/protocol/identify" "github.com/libp2p/go-libp2p/p2p/protocol/ping" + "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) func TestResourceManagerIsUsed(t *testing.T) { @@ -55,7 +56,7 @@ func TestResourceManagerIsUsed(t *testing.T) { } expectFd := true - if strings.Contains(tc.Name, "QUIC") || strings.Contains(tc.Name, "WebTransport") { + if strings.Contains(tc.Name, "QUIC") || strings.Contains(tc.Name, "WebTransport") || strings.Contains(tc.Name, "WebRTC") { expectFd = false } @@ -86,7 +87,11 @@ func TestResourceManagerIsUsed(t *testing.T) { } return nil }) - connScope.EXPECT().Done() + if tc.Name == "WebRTC" { + // webrtc receive buffer is a fix sized buffer allocated up front + connScope.EXPECT().ReserveMemory(gomock.Any(), gomock.Any()) + } + connScope.EXPECT().Done().MinTimes(1) var allStreamsDone sync.WaitGroup diff --git a/go-libp2p/p2p/test/transport/transport_test.go b/go-libp2p/p2p/test/transport/transport_test.go index e960806..e39b72a 100644 --- a/go-libp2p/p2p/test/transport/transport_test.go +++ b/go-libp2p/p2p/test/transport/transport_test.go @@ -9,6 +9,7 @@ import ( "io" "net" "runtime" + "strings" "sync" "sync/atomic" "testing" @@ -20,10 +21,16 @@ import ( "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/sec" + rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" "github.com/libp2p/go-libp2p/p2p/muxer/yamux" + "github.com/libp2p/go-libp2p/p2p/net/swarm" "github.com/libp2p/go-libp2p/p2p/protocol/ping" "github.com/libp2p/go-libp2p/p2p/security/noise" tls "github.com/libp2p/go-libp2p/p2p/security/tls" + libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc" + + "github.com/multiformats/go-multiaddr" "github.com/stretchr/testify/require" ) @@ -130,6 +137,21 @@ var transportsToTest = []TransportTestCase{ return h }, }, + { + Name: "WebRTC", + HostGenerator: func(t *testing.T, opts TransportTestCaseOpts) host.Host { + libp2pOpts := transformOpts(opts) + libp2pOpts = append(libp2pOpts, libp2p.Transport(libp2pwebrtc.New)) + if opts.NoListen { + libp2pOpts = append(libp2pOpts, libp2p.NoListenAddrs) + } else { + libp2pOpts = append(libp2pOpts, libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/webrtc-direct")) + } + h, err := libp2p.New(libp2pOpts...) + require.NoError(t, err) + return h + }, + }, } func TestPing(t *testing.T) { @@ -225,7 +247,7 @@ func TestLotsOfDataManyStreams(t *testing.T) { // 64k buffer const bufSize = 64 << 10 sendBuf := [bufSize]byte{} - const totalStreams = 512 + const totalStreams = 500 const parallel = 8 // Total sends are > 20MiB require.Greater(t, len(sendBuf)*totalStreams, 20<<20) @@ -357,8 +379,20 @@ func TestMoreStreamsThanOurLimits(t *testing.T) { const streamCount = 1024 for _, tc := range transportsToTest { t.Run(tc.Name, func(t *testing.T) { - listener := tc.HostGenerator(t, TransportTestCaseOpts{}) - dialer := tc.HostGenerator(t, TransportTestCaseOpts{NoListen: true}) + if strings.Contains(tc.Name, "WebRTC") { + t.Skip("This test potentially exhausts the uint16 WebRTC stream ID space.") + } + listenerLimits := rcmgr.PartialLimitConfig{ + PeerDefault: rcmgr.ResourceLimits{ + Streams: 32, + StreamsInbound: 16, + StreamsOutbound: 16, + }, + } + r, err := rcmgr.NewResourceManager(rcmgr.NewFixedLimiter(listenerLimits.Build(rcmgr.DefaultLimits.AutoScale()))) + require.NoError(t, err) + listener := tc.HostGenerator(t, TransportTestCaseOpts{ResourceManager: r}) + dialer := tc.HostGenerator(t, TransportTestCaseOpts{NoListen: true, NoRcmgr: true}) defer listener.Close() defer dialer.Close() @@ -370,101 +404,133 @@ func TestMoreStreamsThanOurLimits(t *testing.T) { var handledStreams atomic.Int32 var sawFirstErr atomic.Bool - semaphore := make(chan struct{}, streamCount) - // Start with a single stream at a time. If that works, we'll increase the number of concurrent streams. - semaphore <- struct{}{} + workQueue := make(chan struct{}, streamCount) + for i := 0; i < streamCount; i++ { + workQueue <- struct{}{} + } + close(workQueue) listener.SetStreamHandler("echo", func(s network.Stream) { + // Wait a bit so that we have more parallel streams open at the same time + time.Sleep(time.Millisecond * 10) io.Copy(s, s) s.Close() }) wg := sync.WaitGroup{} - wg.Add(streamCount) errCh := make(chan error, 1) var completedStreams atomic.Int32 - for i := 0; i < streamCount; i++ { - go func() { - <-semaphore - var didErr bool - defer wg.Done() - defer completedStreams.Add(1) - defer func() { - select { - case semaphore <- struct{}{}: - default: - } - if !didErr && !sawFirstErr.Load() { - // No error! We can add one more stream to our concurrency limit. - select { - case semaphore <- struct{}{}: - default: - } - } - }() - var s network.Stream - var err error - // maxRetries is an arbitrary retry amount if there's any error. - maxRetries := streamCount * 4 - shouldRetry := func(err error) bool { - didErr = true - sawFirstErr.Store(true) - maxRetries-- - if maxRetries == 0 || len(errCh) > 0 { - select { - case errCh <- errors.New("max retries exceeded"): - default: - } - return false - } - return true + const maxWorkerCount = streamCount + workerCount := 4 + + var startWorker func(workerIdx int) + startWorker = func(workerIdx int) { + wg.Add(1) + defer wg.Done() + for { + _, ok := <-workQueue + if !ok { + return } - for { - s, err = dialer.NewStream(context.Background(), listener.ID(), "echo") - if err != nil { - if shouldRetry(err) { + // Inline function so we can use defer + func() { + var didErr bool + defer completedStreams.Add(1) + defer func() { + // Only the first worker adds more workers + if workerIdx == 0 && !didErr && !sawFirstErr.Load() { + nextWorkerCount := workerCount * 2 + if nextWorkerCount < maxWorkerCount { + for i := workerCount; i < nextWorkerCount; i++ { + go startWorker(i) + } + workerCount = nextWorkerCount + } + } + }() + + var s network.Stream + var err error + // maxRetries is an arbitrary retry amount if there's any error. + maxRetries := streamCount * 4 + shouldRetry := func(err error) bool { + didErr = true + sawFirstErr.Store(true) + maxRetries-- + if maxRetries == 0 || len(errCh) > 0 { + select { + case errCh <- errors.New("max retries exceeded"): + default: + } + return false + } + return true + } + + for { + s, err = dialer.NewStream(context.Background(), listener.ID(), "echo") + if err != nil { + if shouldRetry(err) { + time.Sleep(50 * time.Millisecond) + continue + } + t.Logf("opening stream failed: %v", err) + return + } + err = func(s network.Stream) error { + defer s.Close() + err = s.SetDeadline(time.Now().Add(100 * time.Millisecond)) + if err != nil { + return err + } + + _, err = s.Write([]byte("hello")) + if err != nil { + return err + } + + err = s.CloseWrite() + if err != nil { + return err + } + + b, err := io.ReadAll(s) + if err != nil { + return err + } + if !bytes.Equal(b, []byte("hello")) { + return errors.New("received data does not match sent data") + } + handledStreams.Add(1) + + return nil + }(s) + if err != nil && shouldRetry(err) { time.Sleep(50 * time.Millisecond) continue } + return } - err = func(s network.Stream) error { - defer s.Close() - _, err = s.Write([]byte("hello")) - if err != nil { - return err - } - - err = s.CloseWrite() - if err != nil { - return err - } - - b, err := io.ReadAll(s) - if err != nil { - return err - } - if !bytes.Equal(b, []byte("hello")) { - return errors.New("received data does not match sent data") - } - handledStreams.Add(1) - - return nil - }(s) - if err != nil && shouldRetry(err) { - time.Sleep(50 * time.Millisecond) - continue - } - return - } - }() + }() + } } + + // Create any initial parallel workers + for i := 1; i < workerCount; i++ { + go startWorker(i) + } + + // Start the first worker + startWorker(0) + wg.Wait() close(errCh) require.NoError(t, <-errCh) require.Equal(t, streamCount, int(handledStreams.Load())) + require.True(t, sawFirstErr.Load(), "Expected to see an error from the peer") }) } } @@ -552,8 +618,8 @@ func TestStreamReadDeadline(t *testing.T) { _, err = s.Read([]byte{0}) require.Error(t, err) require.Contains(t, err.Error(), "deadline") - nerr, ok := err.(net.Error) - require.True(t, ok, "expected a net.Error") + var nerr net.Error + require.ErrorAs(t, err, &nerr, "expected a net.Error") require.True(t, nerr.Timeout(), "expected net.Error.Timeout() == true") // now test that the stream is still usable s.SetReadDeadline(time.Time{}) @@ -566,3 +632,59 @@ func TestStreamReadDeadline(t *testing.T) { }) } } + +func TestDiscoverPeerIDFromSecurityNegotiation(t *testing.T) { + // extracts the peerID of the dialed peer from the error + extractPeerIDFromError := func(inputErr error) (peer.ID, error) { + var dialErr *swarm.DialError + if !errors.As(inputErr, &dialErr) { + return "", inputErr + } + innerErr := dialErr.DialErrors[0].Cause + + var peerIDMismatchErr sec.ErrPeerIDMismatch + if errors.As(innerErr, &peerIDMismatchErr) { + return peerIDMismatchErr.Actual, nil + } + + return "", inputErr + } + + for _, tc := range transportsToTest { + t.Run(tc.Name, func(t *testing.T) { + h1 := tc.HostGenerator(t, TransportTestCaseOpts{}) + h2 := tc.HostGenerator(t, TransportTestCaseOpts{NoListen: true}) + defer h1.Close() + defer h2.Close() + + // runs a test to verify we can extract the peer ID from a target with just its address + t.Helper() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + // Use a bogus peer ID so that when we connect to the target we get an error telling + // us the targets real peer ID + bogusPeerId, err := peer.Decode("QmadAdJ3f63JyNs65X7HHzqDwV53ynvCcKtNFvdNaz3nhk") + require.NoError(t, err, "the hard coded bogus peerID is invalid") + + ai := &peer.AddrInfo{ + ID: bogusPeerId, + Addrs: []multiaddr.Multiaddr{h1.Addrs()[0]}, + } + + // Try connecting with the bogus peer ID + err = h2.Connect(ctx, *ai) + require.Error(t, err, "somehow we successfully connected to a bogus peerID!") + + // Extract the actual peer ID from the error + newPeerId, err := extractPeerIDFromError(err) + require.NoError(t, err) + ai.ID = newPeerId + // Make sure the new ID is what we expected + require.Equal(t, h1.ID(), ai.ID) + + // and just to double-check try connecting again to make sure it works + require.NoError(t, h2.Connect(ctx, *ai)) + }) + } +} diff --git a/go-libp2p/p2p/transport/quic/cmd/client/main.go b/go-libp2p/p2p/transport/quic/cmd/client/main.go index f33d65e..5736d89 100644 --- a/go-libp2p/p2p/transport/quic/cmd/client/main.go +++ b/go-libp2p/p2p/transport/quic/cmd/client/main.go @@ -1,20 +1,11 @@ package main import ( - "context" - "crypto/rand" "fmt" - "io" "log" "os" - "github.com/libp2p/go-libp2p/p2p/transport/quicreuse" - - ic "github.com/libp2p/go-libp2p/core/crypto" - "github.com/libp2p/go-libp2p/core/peer" - libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic" - - ma "github.com/multiformats/go-multiaddr" + cmdlib "github.com/libp2p/go-libp2p/p2p/transport/quic/cmd/lib" ) func main() { @@ -22,57 +13,7 @@ func main() { fmt.Printf("Usage: %s ", os.Args[0]) return } - if err := run(os.Args[1], os.Args[2]); err != nil { + if err := cmdlib.RunClient(os.Args[1], os.Args[2]); err != nil { log.Fatalf(err.Error()) } } - -func run(raddr string, p string) error { - peerID, err := peer.Decode(p) - if err != nil { - return err - } - addr, err := ma.NewMultiaddr(raddr) - if err != nil { - return err - } - priv, _, err := ic.GenerateECDSAKeyPair(rand.Reader) - if err != nil { - return err - } - - reuse, err := quicreuse.NewConnManager([32]byte{}) - if err != nil { - return err - } - t, err := libp2pquic.NewTransport(priv, reuse, nil, nil, nil) - if err != nil { - return err - } - - log.Printf("Dialing %s\n", addr.String()) - conn, err := t.Dial(context.Background(), addr, peerID) - if err != nil { - return err - } - defer conn.Close() - str, err := conn.OpenStream(context.Background()) - if err != nil { - return err - } - defer str.Close() - const msg = "Hello world!" - log.Printf("Sending: %s\n", msg) - if _, err := str.Write([]byte(msg)); err != nil { - return err - } - if err := str.CloseWrite(); err != nil { - return err - } - data, err := io.ReadAll(str) - if err != nil { - return err - } - log.Printf("Received: %s\n", data) - return nil -} diff --git a/go-libp2p/p2p/transport/quic/cmd/lib/lib.go b/go-libp2p/p2p/transport/quic/cmd/lib/lib.go new file mode 100644 index 0000000..fd2a270 --- /dev/null +++ b/go-libp2p/p2p/transport/quic/cmd/lib/lib.go @@ -0,0 +1,129 @@ +package cmdlib + +import ( + "context" + "crypto/rand" + "fmt" + "io" + "log" + + ic "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/peer" + tpt "github.com/libp2p/go-libp2p/core/transport" + libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic" + "github.com/libp2p/go-libp2p/p2p/transport/quicreuse" + + ma "github.com/multiformats/go-multiaddr" + "github.com/quic-go/quic-go" +) + +func RunClient(raddr string, p string) error { + peerID, err := peer.Decode(p) + if err != nil { + return err + } + addr, err := ma.NewMultiaddr(raddr) + if err != nil { + return err + } + priv, _, err := ic.GenerateECDSAKeyPair(rand.Reader) + if err != nil { + return err + } + + reuse, err := quicreuse.NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}) + if err != nil { + return err + } + t, err := libp2pquic.NewTransport(priv, reuse, nil, nil, nil) + if err != nil { + return err + } + + log.Printf("Dialing %s\n", addr.String()) + conn, err := t.Dial(context.Background(), addr, peerID) + if err != nil { + return err + } + defer conn.Close() + str, err := conn.OpenStream(context.Background()) + if err != nil { + return err + } + defer str.Close() + const msg = "Hello world!" + log.Printf("Sending: %s\n", msg) + if _, err := str.Write([]byte(msg)); err != nil { + return err + } + if err := str.CloseWrite(); err != nil { + return err + } + data, err := io.ReadAll(str) + if err != nil { + return err + } + log.Printf("Received: %s\n", data) + return nil +} + +func RunServer(port string, location chan peer.AddrInfo) error { + addr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/0.0.0.0/udp/%s/quic-v1", port)) + if err != nil { + return err + } + priv, _, err := ic.GenerateECDSAKeyPair(rand.Reader) + if err != nil { + return err + } + peerID, err := peer.IDFromPrivateKey(priv) + if err != nil { + return err + } + + reuse, err := quicreuse.NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}) + if err != nil { + return err + } + t, err := libp2pquic.NewTransport(priv, reuse, nil, nil, nil) + if err != nil { + return err + } + + ln, err := t.Listen(addr) + if err != nil { + return err + } + fmt.Printf("Listening. Now run: go run cmd/client/main.go %s %s\n", ln.Multiaddr(), peerID) + if location != nil { + location <- peer.AddrInfo{ID: peerID, Addrs: []ma.Multiaddr{ln.Multiaddr()}} + } + for { + conn, err := ln.Accept() + if err != nil { + return err + } + log.Printf("Accepted new connection from %s (%s)\n", conn.RemotePeer(), conn.RemoteMultiaddr()) + go func() { + if err := handleConn(conn); err != nil { + log.Printf("handling conn failed: %s", err.Error()) + } + }() + } +} + +func handleConn(conn tpt.CapableConn) error { + str, err := conn.AcceptStream() + if err != nil { + return err + } + data, err := io.ReadAll(str) + if err != nil { + return err + } + log.Printf("Received: %s\n", data) + if _, err := str.Write(data); err != nil { + return err + } + return str.Close() +} diff --git a/go-libp2p/p2p/transport/quic/cmd/lib/lib_test.go b/go-libp2p/p2p/transport/quic/cmd/lib/lib_test.go new file mode 100644 index 0000000..1058b07 --- /dev/null +++ b/go-libp2p/p2p/transport/quic/cmd/lib/lib_test.go @@ -0,0 +1,30 @@ +package cmdlib + +import ( + "testing" + + "github.com/libp2p/go-libp2p/core/peer" + "github.com/multiformats/go-multiaddr" +) + +func TestCmd(t *testing.T) { + serverLocation := make(chan peer.AddrInfo) + go RunServer("0", serverLocation) + + l := <-serverLocation + + ip, rest := multiaddr.SplitFirst(l.Addrs[0]) + if ip.Protocol().Code == multiaddr.P_IP4 && ip.Value() == "0.0.0.0" { + // Windows can't dial to 0.0.0.0 so replace with localhost + var err error + ip, err = multiaddr.NewComponent("ip4", "127.0.0.1") + if err != nil { + t.Fatal(err) + } + } + + err := RunClient(multiaddr.Join(ip, rest).String(), l.ID.String()) + if err != nil { + t.Fatal(err) + } +} diff --git a/go-libp2p/p2p/transport/quic/cmd/server/main.go b/go-libp2p/p2p/transport/quic/cmd/server/main.go index e5144f4..ef3f90a 100644 --- a/go-libp2p/p2p/transport/quic/cmd/server/main.go +++ b/go-libp2p/p2p/transport/quic/cmd/server/main.go @@ -1,20 +1,11 @@ package main import ( - "crypto/rand" "fmt" - "io" "log" "os" - "github.com/libp2p/go-libp2p/p2p/transport/quicreuse" - - ic "github.com/libp2p/go-libp2p/core/crypto" - "github.com/libp2p/go-libp2p/core/peer" - tpt "github.com/libp2p/go-libp2p/core/transport" - libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic" - - ma "github.com/multiformats/go-multiaddr" + cmdlib "github.com/libp2p/go-libp2p/p2p/transport/quic/cmd/lib" ) func main() { @@ -22,65 +13,7 @@ func main() { fmt.Printf("Usage: %s ", os.Args[0]) return } - if err := run(os.Args[1]); err != nil { + if err := cmdlib.RunServer(os.Args[1], nil); err != nil { log.Fatalf(err.Error()) } } - -func run(port string) error { - addr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/0.0.0.0/udp/%s/quic", port)) - if err != nil { - return err - } - priv, _, err := ic.GenerateECDSAKeyPair(rand.Reader) - if err != nil { - return err - } - peerID, err := peer.IDFromPrivateKey(priv) - if err != nil { - return err - } - - reuse, err := quicreuse.NewConnManager([32]byte{}) - if err != nil { - return err - } - t, err := libp2pquic.NewTransport(priv, reuse, nil, nil, nil) - if err != nil { - return err - } - - ln, err := t.Listen(addr) - if err != nil { - return err - } - fmt.Printf("Listening. Now run: go run cmd/client/main.go %s %s\n", ln.Multiaddr(), peerID) - for { - conn, err := ln.Accept() - if err != nil { - return err - } - log.Printf("Accepted new connection from %s (%s)\n", conn.RemotePeer(), conn.RemoteMultiaddr()) - go func() { - if err := handleConn(conn); err != nil { - log.Printf("handling conn failed: %s", err.Error()) - } - }() - } -} - -func handleConn(conn tpt.CapableConn) error { - str, err := conn.AcceptStream() - if err != nil { - return err - } - data, err := io.ReadAll(str) - if err != nil { - return err - } - log.Printf("Received: %s\n", data) - if _, err := str.Write(data); err != nil { - return err - } - return str.Close() -} diff --git a/go-libp2p/p2p/transport/quic/conn_test.go b/go-libp2p/p2p/transport/quic/conn_test.go index 189a38d..d3e27a7 100644 --- a/go-libp2p/p2p/transport/quic/conn_test.go +++ b/go-libp2p/p2p/transport/quic/conn_test.go @@ -20,14 +20,14 @@ import ( tpt "github.com/libp2p/go-libp2p/core/transport" "github.com/libp2p/go-libp2p/p2p/transport/quicreuse" - "github.com/golang/mock/gomock" ma "github.com/multiformats/go-multiaddr" "github.com/quic-go/quic-go" quicproxy "github.com/quic-go/quic-go/integrationtests/tools/proxy" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) -//go:generate sh -c "go run github.com/golang/mock/mockgen -package libp2pquic -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && go run golang.org/x/tools/cmd/goimports -w mock_connection_gater_test.go" +//go:generate sh -c "go run go.uber.org/mock/mockgen -package libp2pquic -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && go run golang.org/x/tools/cmd/goimports -w mock_connection_gater_test.go" type connTestCase struct { Name string @@ -35,8 +35,8 @@ type connTestCase struct { } var connTestCases = []*connTestCase{ - {"reuseport_on", []quicreuse.Option{quicreuse.DisableDraft29()}}, - {"reuseport_off", []quicreuse.Option{quicreuse.DisableReuseport(), quicreuse.DisableDraft29()}}, + {"reuseport_on", []quicreuse.Option{}}, + {"reuseport_off", []quicreuse.Option{quicreuse.DisableReuseport()}}, } func createPeer(t *testing.T) (peer.ID, ic.PrivKey) { @@ -55,7 +55,7 @@ func createPeer(t *testing.T) (peer.ID, ic.PrivKey) { require.NoError(t, err) id, err := peer.IDFromPrivateKey(priv) require.NoError(t, err) - t.Logf("using a %s key: %s", priv.Type(), id.Pretty()) + t.Logf("using a %s key: %s", priv.Type(), id) return id, priv } @@ -69,7 +69,7 @@ func runServer(t *testing.T, tr tpt.Transport, addr string) tpt.Listener { func newConnManager(t *testing.T, opts ...quicreuse.Option) *quicreuse.ConnManager { t.Helper() - cm, err := quicreuse.NewConnManager([32]byte{}, opts...) + cm, err := quicreuse.NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}, opts...) require.NoError(t, err) t.Cleanup(func() { cm.Close() }) return cm @@ -674,110 +674,3 @@ func TestHolePunching(t *testing.T) { <-done1 <-done2 } - -func TestGetErrorWhenListeningWithDraft29WhenDisabled(t *testing.T) { - _, serverKey := createPeer(t) - - t1, err := NewTransport(serverKey, newConnManager(t, quicreuse.DisableDraft29()), nil, nil, nil) - require.NoError(t, err) - defer t1.(io.Closer).Close() - laddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/0/quic") - require.NoError(t, err) - _, err = t1.Listen(laddr) - require.Error(t, err) -} - -func TestClientCanDialDifferentQUICVersions(t *testing.T) { - type testCase struct { - name string - serverDisablesDraft29 bool - } - - testCases := []testCase{ - { - name: "Client dials quic-v1 on a quic-v1 only server", - serverDisablesDraft29: true, - }, - { - name: "Client dials both draft 29 and v1 on server that supports both", - serverDisablesDraft29: false, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - serverID, serverKey := createPeer(t) - _, clientKey := createPeer(t) - - var serverOpts []quicreuse.Option - if tc.serverDisablesDraft29 { - serverOpts = append(serverOpts, quicreuse.DisableDraft29()) - } - - t1, err := NewTransport(serverKey, newConnManager(t, serverOpts...), nil, nil, nil) - require.NoError(t, err) - defer t1.(io.Closer).Close() - laddr := ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1") - ln1, err := t1.Listen(laddr) - require.NoError(t, err) - t.Cleanup(func() { ln1.Close() }) - - mas := []ma.Multiaddr{ln1.Multiaddr()} - var ln2 tpt.Listener - if !tc.serverDisablesDraft29 { - laddrDraft29 := ma.StringCast("/ip4/127.0.0.1/udp/0/quic") - ln2, err = t1.Listen(laddrDraft29) - require.NoError(t, err) - t.Cleanup(func() { ln2.Close() }) - mas = append(mas, ln2.Multiaddr()) - } - - t2, err := NewTransport(clientKey, newConnManager(t), nil, nil, nil) - require.NoError(t, err) - defer t2.(io.Closer).Close() - - ctx := context.Background() - - for _, a := range mas { - _, v, err := quicreuse.FromQuicMultiaddr(a) - require.NoError(t, err) - - done := make(chan struct{}) - go func() { - defer close(done) - var conn tpt.CapableConn - var err error - if v == quic.Version1 { - conn, err = ln1.Accept() - } else if v == quic.VersionDraft29 { - conn, err = ln2.Accept() - } else { - panic("unexpected version") - } - require.NoError(t, err) - - _, versionConnLocal, err := quicreuse.FromQuicMultiaddr(conn.LocalMultiaddr()) - require.NoError(t, err) - _, versionConnRemote, err := quicreuse.FromQuicMultiaddr(conn.RemoteMultiaddr()) - require.NoError(t, err) - - require.Equal(t, v, versionConnLocal) - require.Equal(t, v, versionConnRemote) - }() - - conn, err := t2.Dial(ctx, a, serverID) - require.NoError(t, err) - _, versionConnLocal, err := quicreuse.FromQuicMultiaddr(conn.LocalMultiaddr()) - require.NoError(t, err) - _, versionConnRemote, err := quicreuse.FromQuicMultiaddr(conn.RemoteMultiaddr()) - require.NoError(t, err) - - require.Equal(t, v, versionConnLocal) - require.Equal(t, v, versionConnRemote) - - <-done - conn.Close() - } - }) - } -} diff --git a/go-libp2p/p2p/transport/quic/listener.go b/go-libp2p/p2p/transport/quic/listener.go index 73bb502..d49b686 100644 --- a/go-libp2p/p2p/transport/quic/listener.go +++ b/go-libp2p/p2p/transport/quic/listener.go @@ -29,9 +29,6 @@ type listener struct { func newListener(ln quicreuse.Listener, t *transport, localPeer peer.ID, key ic.PrivKey, rcmgr network.ResourceManager) (listener, error) { localMultiaddrs := make(map[quic.VersionNumber]ma.Multiaddr) for _, addr := range ln.Multiaddrs() { - if _, err := addr.ValueForProtocol(ma.P_QUIC); err == nil { - localMultiaddrs[quic.VersionDraft29] = addr - } if _, err := addr.ValueForProtocol(ma.P_QUIC_V1); err == nil { localMultiaddrs[quic.Version1] = addr } diff --git a/go-libp2p/p2p/transport/quic/listener_test.go b/go-libp2p/p2p/transport/quic/listener_test.go index f62cddc..d739c82 100644 --- a/go-libp2p/p2p/transport/quic/listener_test.go +++ b/go-libp2p/p2p/transport/quic/listener_test.go @@ -34,41 +34,31 @@ func TestListenAddr(t *testing.T) { defer tr.(io.Closer).Close() t.Run("for IPv4", func(t *testing.T) { - localAddr := ma.StringCast("/ip4/127.0.0.1/udp/0/quic") - ln, err := tr.Listen(localAddr) - require.NoError(t, err) localAddrV1 := ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1") - ln2, err := tr.Listen(localAddrV1) + ln, err := tr.Listen(localAddrV1) require.NoError(t, err) defer ln.Close() - defer ln2.Close() port := ln.Addr().(*net.UDPAddr).Port require.NotZero(t, port) var multiaddrsStrings []string - for _, a := range []ma.Multiaddr{ln.Multiaddr(), ln2.Multiaddr()} { + for _, a := range []ma.Multiaddr{ln.Multiaddr()} { multiaddrsStrings = append(multiaddrsStrings, a.String()) } - require.Contains(t, multiaddrsStrings, fmt.Sprintf("/ip4/127.0.0.1/udp/%d/quic", port)) require.Contains(t, multiaddrsStrings, fmt.Sprintf("/ip4/127.0.0.1/udp/%d/quic-v1", port)) }) t.Run("for IPv6", func(t *testing.T) { - localAddr := ma.StringCast("/ip6/::/udp/0/quic") - ln, err := tr.Listen(localAddr) - require.NoError(t, err) localAddrV1 := ma.StringCast("/ip6/::/udp/0/quic-v1") - ln2, err := tr.Listen(localAddrV1) + ln, err := tr.Listen(localAddrV1) require.NoError(t, err) defer ln.Close() - defer ln2.Close() port := ln.Addr().(*net.UDPAddr).Port require.NotZero(t, port) var multiaddrsStrings []string - for _, a := range []ma.Multiaddr{ln.Multiaddr(), ln2.Multiaddr()} { + for _, a := range []ma.Multiaddr{ln.Multiaddr()} { multiaddrsStrings = append(multiaddrsStrings, a.String()) } - require.Contains(t, multiaddrsStrings, fmt.Sprintf("/ip6/::/udp/%d/quic", port)) require.Contains(t, multiaddrsStrings, fmt.Sprintf("/ip6/::/udp/%d/quic-v1", port)) }) } @@ -76,7 +66,7 @@ func TestListenAddr(t *testing.T) { func TestAccepting(t *testing.T) { tr := newTransport(t, nil) defer tr.(io.Closer).Close() - ln, err := tr.Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic")) + ln, err := tr.Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1")) require.NoError(t, err) done := make(chan struct{}) go func() { @@ -100,7 +90,7 @@ func TestAccepting(t *testing.T) { func TestAcceptAfterClose(t *testing.T) { tr := newTransport(t, nil) defer tr.(io.Closer).Close() - ln, err := tr.Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic")) + ln, err := tr.Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1")) require.NoError(t, err) require.NoError(t, ln.Close()) _, err = ln.Accept() @@ -112,23 +102,14 @@ func TestCorrectNumberOfVirtualListeners(t *testing.T) { tpt := tr.(*transport) defer tr.(io.Closer).Close() - localAddr := ma.StringCast("/ip4/127.0.0.1/udp/0/quic") - udpAddr, _, err := quicreuse.FromQuicMultiaddr(localAddr) - require.NoError(t, err) - - ln, err := tr.Listen(localAddr) - require.NoError(t, err) - require.Equal(t, 1, len(tpt.listeners[udpAddr.String()])) localAddrV1 := ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1") - ln2, err := tr.Listen(localAddrV1) + ln, err := tr.Listen(localAddrV1) + require.NoError(t, err) + udpAddr, _, err := quicreuse.FromQuicMultiaddr(localAddrV1) require.NoError(t, err) require.NoError(t, err) - require.Equal(t, 2, len(tpt.listeners[udpAddr.String()])) - + require.Len(t, tpt.listeners[udpAddr.String()], 1) ln.Close() - require.Equal(t, 1, len(tpt.listeners[udpAddr.String()])) - ln2.Close() - require.Equal(t, 0, len(tpt.listeners[udpAddr.String()])) - + require.Empty(t, tpt.listeners[udpAddr.String()]) } diff --git a/go-libp2p/p2p/transport/quic/mock_connection_gater_test.go b/go-libp2p/p2p/transport/quic/mock_connection_gater_test.go index 4ee4008..8e23aad 100644 --- a/go-libp2p/p2p/transport/quic/mock_connection_gater_test.go +++ b/go-libp2p/p2p/transport/quic/mock_connection_gater_test.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/libp2p/go-libp2p/core/connmgr (interfaces: ConnectionGater) +// +// Generated by this command: +// +// mockgen -package libp2pquic -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater +// // Package libp2pquic is a generated GoMock package. package libp2pquic @@ -7,11 +12,11 @@ package libp2pquic import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" control "github.com/libp2p/go-libp2p/core/control" network "github.com/libp2p/go-libp2p/core/network" peer "github.com/libp2p/go-libp2p/core/peer" multiaddr "github.com/multiformats/go-multiaddr" + gomock "go.uber.org/mock/gomock" ) // MockConnectionGater is a mock of ConnectionGater interface. @@ -46,7 +51,7 @@ func (m *MockConnectionGater) InterceptAccept(arg0 network.ConnMultiaddrs) bool } // InterceptAccept indicates an expected call of InterceptAccept. -func (mr *MockConnectionGaterMockRecorder) InterceptAccept(arg0 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptAccept(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptAccept", reflect.TypeOf((*MockConnectionGater)(nil).InterceptAccept), arg0) } @@ -60,7 +65,7 @@ func (m *MockConnectionGater) InterceptAddrDial(arg0 peer.ID, arg1 multiaddr.Mul } // InterceptAddrDial indicates an expected call of InterceptAddrDial. -func (mr *MockConnectionGaterMockRecorder) InterceptAddrDial(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptAddrDial(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptAddrDial", reflect.TypeOf((*MockConnectionGater)(nil).InterceptAddrDial), arg0, arg1) } @@ -74,7 +79,7 @@ func (m *MockConnectionGater) InterceptPeerDial(arg0 peer.ID) bool { } // InterceptPeerDial indicates an expected call of InterceptPeerDial. -func (mr *MockConnectionGaterMockRecorder) InterceptPeerDial(arg0 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptPeerDial(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptPeerDial", reflect.TypeOf((*MockConnectionGater)(nil).InterceptPeerDial), arg0) } @@ -88,7 +93,7 @@ func (m *MockConnectionGater) InterceptSecured(arg0 network.Direction, arg1 peer } // InterceptSecured indicates an expected call of InterceptSecured. -func (mr *MockConnectionGaterMockRecorder) InterceptSecured(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptSecured(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptSecured", reflect.TypeOf((*MockConnectionGater)(nil).InterceptSecured), arg0, arg1, arg2) } @@ -103,7 +108,7 @@ func (m *MockConnectionGater) InterceptUpgraded(arg0 network.Conn) (bool, contro } // InterceptUpgraded indicates an expected call of InterceptUpgraded. -func (mr *MockConnectionGaterMockRecorder) InterceptUpgraded(arg0 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptUpgraded(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptUpgraded", reflect.TypeOf((*MockConnectionGater)(nil).InterceptUpgraded), arg0) } diff --git a/go-libp2p/p2p/transport/quic/transport.go b/go-libp2p/p2p/transport/quic/transport.go index aef3f4c..18d198b 100644 --- a/go-libp2p/p2p/transport/quic/transport.go +++ b/go-libp2p/p2p/transport/quic/transport.go @@ -268,8 +268,8 @@ loop: } } -// Don't use mafmt.QUIC as we don't want to dial DNS addresses. Just /ip{4,6}/udp/quic -var dialMatcher = mafmt.And(mafmt.IP, mafmt.Base(ma.P_UDP), mafmt.Or(mafmt.Base(ma.P_QUIC), mafmt.Base(ma.P_QUIC_V1))) +// Don't use mafmt.QUIC as we don't want to dial DNS addresses. Just /ip{4,6}/udp/quic-v1 +var dialMatcher = mafmt.And(mafmt.IP, mafmt.Base(ma.P_UDP), mafmt.Base(ma.P_QUIC_V1)) // CanDial determines if we can dial to an address func (t *transport) CanDial(addr ma.Multiaddr) bool { diff --git a/go-libp2p/p2p/transport/quic/transport_test.go b/go-libp2p/p2p/transport/quic/transport_test.go index 3eab828..41e7e4e 100644 --- a/go-libp2p/p2p/transport/quic/transport_test.go +++ b/go-libp2p/p2p/transport/quic/transport_test.go @@ -30,13 +30,10 @@ func TestQUICProtocol(t *testing.T) { defer tr.(io.Closer).Close() protocols := tr.Protocols() - if len(protocols) > 2 { - t.Fatalf("expected at most two protocols, got %v", protocols) + if len(protocols) > 1 { + t.Fatalf("expected at most one protocol, got %v", protocols) } - if protocols[0] != ma.P_QUIC { - t.Fatalf("expected the supported protocol to be draft 29 QUIC, got %d", protocols[0]) - } - if protocols[1] != ma.P_QUIC_V1 { + if protocols[0] != ma.P_QUIC_V1 { t.Fatalf("expected the supported protocol to be QUIC v1, got %d", protocols[0]) } } @@ -48,11 +45,12 @@ func TestCanDial(t *testing.T) { invalid := []string{ "/ip4/127.0.0.1/udp/1234", "/ip4/5.5.5.5/tcp/1234", - "/dns/google.com/udp/443/quic", + "/dns/google.com/udp/443/quic-v1", + "/ip4/127.0.0.1/udp/1234/quic", } valid := []string{ - "/ip4/127.0.0.1/udp/1234/quic", - "/ip4/5.5.5.5/udp/0/quic", + "/ip4/127.0.0.1/udp/1234/quic-v1", + "/ip4/5.5.5.5/udp/0/quic-v1", } for _, s := range invalid { invalidAddr, err := ma.NewMultiaddr(s) diff --git a/go-libp2p/p2p/transport/quicreuse/config.go b/go-libp2p/p2p/transport/quicreuse/config.go index 76a2c8c..92c881e 100644 --- a/go-libp2p/p2p/transport/quicreuse/config.go +++ b/go-libp2p/p2p/transport/quicreuse/config.go @@ -1,7 +1,6 @@ package quicreuse import ( - "net" "time" "github.com/quic-go/quic-go" @@ -12,14 +11,8 @@ var quicConfig = &quic.Config{ MaxIncomingUniStreams: 5, // allow some unidirectional streams, in case we speak WebTransport MaxStreamReceiveWindow: 10 * (1 << 20), // 10 MB MaxConnectionReceiveWindow: 15 * (1 << 20), // 15 MB - RequireAddressValidation: func(net.Addr) bool { - // TODO(#1535): require source address validation when under load - return false - }, - KeepAlivePeriod: 15 * time.Second, - Versions: []quic.VersionNumber{quic.VersionDraft29, quic.Version1}, + KeepAlivePeriod: 15 * time.Second, + Versions: []quic.VersionNumber{quic.Version1}, // We don't use datagrams (yet), but this is necessary for WebTransport EnableDatagrams: true, - // The multiaddress encodes the QUIC version, thus there's no need to send Version Negotiation packets. - DisableVersionNegotiationPackets: true, } diff --git a/go-libp2p/p2p/transport/quicreuse/connmgr.go b/go-libp2p/p2p/transport/quicreuse/connmgr.go index c12b866..ec2b7b2 100644 --- a/go-libp2p/p2p/transport/quicreuse/connmgr.go +++ b/go-libp2p/p2p/transport/quicreuse/connmgr.go @@ -16,7 +16,6 @@ import ( type ConnManager struct { reuseUDP4 *reuse reuseUDP6 *reuse - enableDraft29 bool enableReuseport bool enableMetrics bool @@ -26,8 +25,8 @@ type ConnManager struct { quicListenersMu sync.Mutex quicListeners map[string]quicListenerEntry - srk quic.StatelessResetKey - mt *metricsTracer + srk quic.StatelessResetKey + tokenKey quic.TokenGeneratorKey } type quicListenerEntry struct { @@ -35,12 +34,12 @@ type quicListenerEntry struct { ln *quicListener } -func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (*ConnManager, error) { +func NewConnManager(statelessResetKey quic.StatelessResetKey, tokenKey quic.TokenGeneratorKey, opts ...Option) (*ConnManager, error) { cm := &ConnManager{ enableReuseport: true, - enableDraft29: true, quicListeners: make(map[string]quicListenerEntry), srk: statelessResetKey, + tokenKey: tokenKey, } for _, o := range opts { if err := o(cm); err != nil { @@ -50,29 +49,20 @@ func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (* quicConf := quicConfig.Clone() - if cm.enableMetrics { - cm.mt = newMetricsTracer() - } - quicConf.Tracer = func(ctx context.Context, p quiclogging.Perspective, ci quic.ConnectionID) quiclogging.ConnectionTracer { - tracers := make([]quiclogging.ConnectionTracer, 0, 2) + quicConf.Tracer = func(ctx context.Context, p quiclogging.Perspective, ci quic.ConnectionID) *quiclogging.ConnectionTracer { + var tracer *quiclogging.ConnectionTracer if qlogTracerDir != "" { - tracers = append(tracers, qloggerForDir(qlogTracerDir, p, ci)) + tracer = qloggerForDir(qlogTracerDir, p, ci) } - if cm.mt != nil { - tracers = append(tracers, cm.mt.TracerForConnection(ctx, p, ci)) - } - return quiclogging.NewMultiplexedConnectionTracer(tracers...) + return tracer } serverConfig := quicConf.Clone() - if !cm.enableDraft29 { - serverConfig.Versions = []quic.VersionNumber{quic.Version1} - } cm.clientConfig = quicConf cm.serverConfig = serverConfig if cm.enableReuseport { - cm.reuseUDP4 = newReuse(&statelessResetKey, cm.mt) - cm.reuseUDP6 = newReuse(&statelessResetKey, cm.mt) + cm.reuseUDP4 = newReuse(&statelessResetKey, &tokenKey) + cm.reuseUDP6 = newReuse(&statelessResetKey, &tokenKey) } return cm, nil } @@ -89,12 +79,6 @@ func (c *ConnManager) getReuse(network string) (*reuse, error) { } func (c *ConnManager) ListenQUIC(addr ma.Multiaddr, tlsConf *tls.Config, allowWindowIncrease func(conn quic.Connection, delta uint64) bool) (Listener, error) { - if !c.enableDraft29 { - if _, err := addr.ValueForProtocol(ma.P_QUIC); err == nil { - return nil, errors.New("can't listen on `/quic` multiaddr (QUIC draft 29 version) when draft 29 support is disabled") - } - } - netw, host, err := manet.DialArgs(addr) if err != nil { return nil, err @@ -114,7 +98,7 @@ func (c *ConnManager) ListenQUIC(addr ma.Multiaddr, tlsConf *tls.Config, allowWi if err != nil { return nil, err } - ln, err := newQuicListener(tr, c.serverConfig, c.enableDraft29) + ln, err := newQuicListener(tr, c.serverConfig) if err != nil { return nil, err } @@ -156,15 +140,18 @@ func (c *ConnManager) transportForListen(network string, laddr *net.UDPAddr) (re return reuse.TransportForListen(network, laddr) } - conn, err := listenAndOptimize(network, laddr) + conn, err := net.ListenUDP(network, laddr) if err != nil { return nil, err } - tr := &singleOwnerTransport{Transport: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn} - if c.mt != nil { - tr.Transport.Tracer = c.mt - } - return tr, nil + return &singleOwnerTransport{ + packetConn: conn, + Transport: quic.Transport{ + Conn: conn, + StatelessResetKey: &c.srk, + TokenGeneratorKey: &c.tokenKey, + }, + }, nil } func (c *ConnManager) DialQUIC(ctx context.Context, raddr ma.Multiaddr, tlsConf *tls.Config, allowWindowIncrease func(conn quic.Connection, delta uint64) bool) (quic.Connection, error) { @@ -183,8 +170,6 @@ func (c *ConnManager) DialQUIC(ctx context.Context, raddr ma.Multiaddr, tlsConf if v == quic.Version1 { // The endpoint has explicit support for QUIC v1, so we'll only use that version. quicConf.Versions = []quic.VersionNumber{quic.Version1} - } else if v == quic.VersionDraft29 { - quicConf.Versions = []quic.VersionNumber{quic.VersionDraft29} } else { return nil, errors.New("unknown QUIC version") } @@ -217,22 +202,14 @@ func (c *ConnManager) TransportForDial(network string, raddr *net.UDPAddr) (refC case "udp6": laddr = &net.UDPAddr{IP: net.IPv6zero, Port: 0} } - conn, err := listenAndOptimize(network, laddr) + conn, err := net.ListenUDP(network, laddr) if err != nil { return nil, err } - tr := &singleOwnerTransport{Transport: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn} - if c.mt != nil { - tr.Transport.Tracer = c.mt - } - - return tr, nil + return &singleOwnerTransport{Transport: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn}, nil } func (c *ConnManager) Protocols() []int { - if c.enableDraft29 { - return []int{ma.P_QUIC, ma.P_QUIC_V1} - } return []int{ma.P_QUIC_V1} } @@ -246,11 +223,6 @@ func (c *ConnManager) Close() error { return c.reuseUDP4.Close() } -// listenAndOptimize same as net.ListenUDP, but also calls quic.OptimizeConn -func listenAndOptimize(network string, laddr *net.UDPAddr) (net.PacketConn, error) { - conn, err := net.ListenUDP(network, laddr) - if err != nil { - return nil, err - } - return quic.OptimizeConn(conn) +func (c *ConnManager) ClientConfig() *quic.Config { + return c.clientConfig } diff --git a/go-libp2p/p2p/transport/quicreuse/connmgr_test.go b/go-libp2p/p2p/transport/quicreuse/connmgr_test.go index 92c7e31..f3576a3 100644 --- a/go-libp2p/p2p/transport/quicreuse/connmgr_test.go +++ b/go-libp2p/p2p/transport/quicreuse/connmgr_test.go @@ -39,18 +39,6 @@ func checkClosed(t *testing.T, cm *ConnManager) { require.Eventually(t, func() bool { return !isGarbageCollectorRunning() }, 200*time.Millisecond, 10*time.Millisecond) } -func TestListenQUICDraft29Disabled(t *testing.T) { - cm, err := NewConnManager([32]byte{}, DisableDraft29(), DisableReuseport()) - require.NoError(t, err) - defer cm.Close() - _, err = cm.ListenQUIC(ma.StringCast("/ip4/127.0.0.1/udp/0/quic"), &tls.Config{}, nil) - require.EqualError(t, err, "can't listen on `/quic` multiaddr (QUIC draft 29 version) when draft 29 support is disabled") - ln, err := cm.ListenQUIC(ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1"), &tls.Config{NextProtos: []string{"proto"}}, nil) - require.NoError(t, err) - require.NoError(t, ln.Close()) - require.False(t, isGarbageCollectorRunning()) -} - func TestListenOnSameProto(t *testing.T) { t.Run("with reuseport", func(t *testing.T) { testListenOnSameProto(t, true) @@ -66,7 +54,7 @@ func testListenOnSameProto(t *testing.T, enableReuseport bool) { if !enableReuseport { opts = append(opts, DisableReuseport()) } - cm, err := NewConnManager([32]byte{}, opts...) + cm, err := NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}, opts...) require.NoError(t, err) defer checkClosed(t, cm) defer cm.Close() @@ -95,7 +83,7 @@ func TestConnectionPassedToQUICForListening(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("skipping on windows. Windows doesn't support these optimizations") } - cm, err := NewConnManager([32]byte{}, DisableReuseport()) + cm, err := NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}, DisableReuseport()) require.NoError(t, err) defer cm.Close() @@ -119,7 +107,7 @@ func TestConnectionPassedToQUICForListening(t *testing.T) { func TestAcceptErrorGetCleanedUp(t *testing.T) { raddr := ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1") - cm, err := NewConnManager([32]byte{}, DisableReuseport()) + cm, err := NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}, DisableReuseport()) require.NoError(t, err) defer cm.Close() @@ -155,7 +143,7 @@ func TestConnectionPassedToQUICForDialing(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("skipping on windows. Windows doesn't support these optimizations") } - cm, err := NewConnManager([32]byte{}, DisableReuseport()) + cm, err := NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}, DisableReuseport()) require.NoError(t, err) defer cm.Close() @@ -230,7 +218,7 @@ func testListener(t *testing.T, enableReuseport bool) { if !enableReuseport { opts = append(opts, DisableReuseport()) } - cm, err := NewConnManager([32]byte{}, opts...) + cm, err := NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}, opts...) require.NoError(t, err) id1, tlsConf1 := getTLSConfForProto(t, "proto1") diff --git a/go-libp2p/p2p/transport/quicreuse/listener.go b/go-libp2p/p2p/transport/quicreuse/listener.go index 50b7934..4ee2004 100644 --- a/go-libp2p/p2p/transport/quicreuse/listener.go +++ b/go-libp2p/p2p/transport/quicreuse/listener.go @@ -38,20 +38,13 @@ type quicListener struct { protocols map[string]protoConf } -func newQuicListener(tr refCountedQuicTransport, quicConfig *quic.Config, enableDraft29 bool) (*quicListener, error) { +func newQuicListener(tr refCountedQuicTransport, quicConfig *quic.Config) (*quicListener, error) { localMultiaddrs := make([]ma.Multiaddr, 0, 2) a, err := ToQuicMultiaddr(tr.LocalAddr(), quic.Version1) if err != nil { return nil, err } localMultiaddrs = append(localMultiaddrs, a) - if enableDraft29 { - a, err := ToQuicMultiaddr(tr.LocalAddr(), quic.VersionDraft29) - if err != nil { - return nil, err - } - localMultiaddrs = append(localMultiaddrs, a) - } cl := &quicListener{ protocols: map[string]protoConf{}, running: make(chan struct{}), @@ -59,6 +52,7 @@ func newQuicListener(tr refCountedQuicTransport, quicConfig *quic.Config, enable addrs: localMultiaddrs, } tlsConf := &tls.Config{ + SessionTicketsDisabled: true, // This is set for the config for client, but we set it here as well: https://github.com/quic-go/quic-go/issues/4029 GetConfigForClient: func(info *tls.ClientHelloInfo) (*tls.Config, error) { cl.protocolsMu.Lock() defer cl.protocolsMu.Unlock() @@ -89,7 +83,7 @@ func (l *quicListener) allowWindowIncrease(conn quic.Connection, delta uint64) b l.protocolsMu.Lock() defer l.protocolsMu.Unlock() - conf, ok := l.protocols[conn.ConnectionState().TLS.ConnectionState.NegotiatedProtocol] + conf, ok := l.protocols[conn.ConnectionState().TLS.NegotiatedProtocol] if !ok { return false } diff --git a/go-libp2p/p2p/transport/quicreuse/options.go b/go-libp2p/p2p/transport/quicreuse/options.go index a700a05..c325069 100644 --- a/go-libp2p/p2p/transport/quicreuse/options.go +++ b/go-libp2p/p2p/transport/quicreuse/options.go @@ -9,16 +9,6 @@ func DisableReuseport() Option { } } -// DisableDraft29 disables support for QUIC draft-29. -// This option should be set, unless support for this legacy QUIC version is needed for backwards compatibility. -// Support for QUIC draft-29 is already deprecated and will be removed in the future, see https://github.com/libp2p/go-libp2p/issues/1841. -func DisableDraft29() Option { - return func(m *ConnManager) error { - m.enableDraft29 = false - return nil - } -} - // EnableMetrics enables Prometheus metrics collection. func EnableMetrics() Option { return func(m *ConnManager) error { diff --git a/go-libp2p/p2p/transport/quicreuse/quic_multiaddr.go b/go-libp2p/p2p/transport/quicreuse/quic_multiaddr.go index 12eb7d8..3da4721 100644 --- a/go-libp2p/p2p/transport/quicreuse/quic_multiaddr.go +++ b/go-libp2p/p2p/transport/quicreuse/quic_multiaddr.go @@ -10,8 +10,7 @@ import ( ) var ( - quicV1MA = ma.StringCast("/quic-v1") - quicDraft29MA = ma.StringCast("/quic") + quicV1MA = ma.StringCast("/quic-v1") ) func ToQuicMultiaddr(na net.Addr, version quic.VersionNumber) (ma.Multiaddr, error) { @@ -20,8 +19,6 @@ func ToQuicMultiaddr(na net.Addr, version quic.VersionNumber) (ma.Multiaddr, err return nil, err } switch version { - case quic.VersionDraft29: - return udpMA.Encapsulate(quicDraft29MA), nil case quic.Version1: return udpMA.Encapsulate(quicV1MA), nil default: @@ -34,9 +31,6 @@ func FromQuicMultiaddr(addr ma.Multiaddr) (*net.UDPAddr, quic.VersionNumber, err var partsBeforeQUIC []ma.Multiaddr ma.ForEach(addr, func(c ma.Component) bool { switch c.Protocol().Code { - case ma.P_QUIC: - version = quic.VersionDraft29 - return false case ma.P_QUIC_V1: version = quic.Version1 return false diff --git a/go-libp2p/p2p/transport/quicreuse/quic_multiaddr_test.go b/go-libp2p/p2p/transport/quicreuse/quic_multiaddr_test.go index 23a8b0b..a6242e2 100644 --- a/go-libp2p/p2p/transport/quicreuse/quic_multiaddr_test.go +++ b/go-libp2p/p2p/transport/quicreuse/quic_multiaddr_test.go @@ -11,26 +11,16 @@ import ( func TestConvertToQuicMultiaddr(t *testing.T) { addr := &net.UDPAddr{IP: net.IPv4(192, 168, 0, 42), Port: 1337} - maddr, err := ToQuicMultiaddr(addr, quic.VersionDraft29) + maddr, err := ToQuicMultiaddr(addr, quic.Version1) require.NoError(t, err) - require.Equal(t, maddr.String(), "/ip4/192.168.0.42/udp/1337/quic") + require.Equal(t, "/ip4/192.168.0.42/udp/1337/quic-v1", maddr.String()) } func TestConvertToQuicV1Multiaddr(t *testing.T) { addr := &net.UDPAddr{IP: net.IPv4(192, 168, 0, 42), Port: 1337} maddr, err := ToQuicMultiaddr(addr, quic.Version1) require.NoError(t, err) - require.Equal(t, maddr.String(), "/ip4/192.168.0.42/udp/1337/quic-v1") -} - -func TestConvertFromQuicDraft29Multiaddr(t *testing.T) { - maddr, err := ma.NewMultiaddr("/ip4/192.168.0.42/udp/1337/quic") - require.NoError(t, err) - udpAddr, v, err := FromQuicMultiaddr(maddr) - require.NoError(t, err) - require.Equal(t, udpAddr.IP, net.IPv4(192, 168, 0, 42)) - require.Equal(t, udpAddr.Port, 1337) - require.Equal(t, v, quic.VersionDraft29) + require.Equal(t, "/ip4/192.168.0.42/udp/1337/quic-v1", maddr.String()) } func TestConvertFromQuicV1Multiaddr(t *testing.T) { @@ -38,7 +28,7 @@ func TestConvertFromQuicV1Multiaddr(t *testing.T) { require.NoError(t, err) udpAddr, v, err := FromQuicMultiaddr(maddr) require.NoError(t, err) - require.Equal(t, udpAddr.IP, net.IPv4(192, 168, 0, 42)) - require.Equal(t, udpAddr.Port, 1337) - require.Equal(t, v, quic.Version1) + require.Equal(t, net.IPv4(192, 168, 0, 42), udpAddr.IP) + require.Equal(t, 1337, udpAddr.Port) + require.Equal(t, quic.Version1, v) } diff --git a/go-libp2p/p2p/transport/quicreuse/reuse.go b/go-libp2p/p2p/transport/quicreuse/reuse.go index 1584b29..dc2b33b 100644 --- a/go-libp2p/p2p/transport/quicreuse/reuse.go +++ b/go-libp2p/p2p/transport/quicreuse/reuse.go @@ -51,8 +51,7 @@ func (c *singleOwnerTransport) Close() error { } func (c *singleOwnerTransport) WriteTo(b []byte, addr net.Addr) (int, error) { - // Safe because we called quic.OptimizeConn ourselves. - return c.packetConn.WriteTo(b, addr) + return c.Transport.WriteTo(b, addr) } // Constant. Defined as variables to simplify testing. @@ -86,8 +85,7 @@ func (c *refcountedTransport) Close() error { } func (c *refcountedTransport) WriteTo(b []byte, addr net.Addr) (int, error) { - // Safe because we called quic.OptimizeConn ourselves. - return c.packetConn.WriteTo(b, addr) + return c.Transport.WriteTo(b, addr) } func (c *refcountedTransport) LocalAddr() net.Addr { @@ -125,10 +123,10 @@ type reuse struct { globalDialers map[int]*refcountedTransport statelessResetKey *quic.StatelessResetKey - metricsTracer *metricsTracer + tokenGeneratorKey *quic.TokenGeneratorKey } -func newReuse(srk *quic.StatelessResetKey, mt *metricsTracer) *reuse { +func newReuse(srk *quic.StatelessResetKey, tokenKey *quic.TokenGeneratorKey) *reuse { r := &reuse{ unicast: make(map[string]map[int]*refcountedTransport), globalListeners: make(map[int]*refcountedTransport), @@ -136,7 +134,7 @@ func newReuse(srk *quic.StatelessResetKey, mt *metricsTracer) *reuse { closeChan: make(chan struct{}), gcStopChan: make(chan struct{}), statelessResetKey: srk, - metricsTracer: mt, + tokenGeneratorKey: tokenKey, } go r.gc() return r @@ -265,17 +263,15 @@ func (r *reuse) transportForDialLocked(network string, source *net.IP) (*refcoun case "udp6": addr = &net.UDPAddr{IP: net.IPv6zero, Port: 0} } - conn, err := listenAndOptimize(network, addr) + conn, err := net.ListenUDP(network, addr) if err != nil { return nil, err } tr := &refcountedTransport{Transport: quic.Transport{ Conn: conn, StatelessResetKey: r.statelessResetKey, + TokenGeneratorKey: r.tokenGeneratorKey, }, packetConn: conn} - if r.metricsTracer != nil { - tr.Transport.Tracer = r.metricsTracer - } r.globalDialers[conn.LocalAddr().(*net.UDPAddr).Port] = tr return tr, nil } @@ -314,19 +310,18 @@ func (r *reuse) TransportForListen(network string, laddr *net.UDPAddr) (*refcoun } } - conn, err := listenAndOptimize(network, laddr) + conn, err := net.ListenUDP(network, laddr) if err != nil { return nil, err } localAddr := conn.LocalAddr().(*net.UDPAddr) - tr := &refcountedTransport{Transport: quic.Transport{ - Conn: conn, - StatelessResetKey: r.statelessResetKey, - }, packetConn: conn} - if r.metricsTracer != nil { - tr.Transport.Tracer = r.metricsTracer + tr := &refcountedTransport{ + Transport: quic.Transport{ + Conn: conn, + StatelessResetKey: r.statelessResetKey, + }, + packetConn: conn, } - tr.IncreaseCount() // Deal with listen on a global address diff --git a/go-libp2p/p2p/transport/quicreuse/reuse_test.go b/go-libp2p/p2p/transport/quicreuse/reuse_test.go index b373f31..b463094 100644 --- a/go-libp2p/p2p/transport/quicreuse/reuse_test.go +++ b/go-libp2p/p2p/transport/quicreuse/reuse_test.go @@ -69,7 +69,7 @@ func TestReuseListenOnAllIPv4(t *testing.T) { require.NoError(t, err) conn, err := reuse.TransportForListen("udp4", addr) require.NoError(t, err) - require.Equal(t, conn.GetCount(), 1) + require.Equal(t, 1, conn.GetCount()) } func TestReuseListenOnAllIPv6(t *testing.T) { @@ -82,7 +82,7 @@ func TestReuseListenOnAllIPv6(t *testing.T) { tr, err := reuse.TransportForListen("udp6", addr) require.NoError(t, err) defer tr.Close() - require.Equal(t, tr.GetCount(), 1) + require.Equal(t, 1, tr.GetCount()) } func TestReuseCreateNewGlobalConnOnDial(t *testing.T) { @@ -93,10 +93,10 @@ func TestReuseCreateNewGlobalConnOnDial(t *testing.T) { require.NoError(t, err) conn, err := reuse.TransportForDial("udp4", addr) require.NoError(t, err) - require.Equal(t, conn.GetCount(), 1) + require.Equal(t, 1, conn.GetCount()) laddr := conn.LocalAddr().(*net.UDPAddr) - require.Equal(t, laddr.IP.String(), "0.0.0.0") - require.NotEqual(t, laddr.Port, 0) + require.Equal(t, "0.0.0.0", laddr.IP.String()) + require.NotEqual(t, 0, laddr.Port) } func TestReuseConnectionWhenDialing(t *testing.T) { @@ -107,13 +107,13 @@ func TestReuseConnectionWhenDialing(t *testing.T) { require.NoError(t, err) lconn, err := reuse.TransportForListen("udp4", addr) require.NoError(t, err) - require.Equal(t, lconn.GetCount(), 1) + require.Equal(t, 1, lconn.GetCount()) // dial raddr, err := net.ResolveUDPAddr("udp4", "1.1.1.1:1234") require.NoError(t, err) conn, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) - require.Equal(t, conn.GetCount(), 2) + require.Equal(t, 2, conn.GetCount()) } func TestReuseConnectionWhenListening(t *testing.T) { @@ -127,8 +127,8 @@ func TestReuseConnectionWhenListening(t *testing.T) { laddr := &net.UDPAddr{IP: net.IPv4zero, Port: tr.LocalAddr().(*net.UDPAddr).Port} lconn, err := reuse.TransportForListen("udp4", laddr) require.NoError(t, err) - require.Equal(t, lconn.GetCount(), 2) - require.Equal(t, tr.GetCount(), 2) + require.Equal(t, 2, lconn.GetCount()) + require.Equal(t, 2, tr.GetCount()) } func TestReuseConnectionWhenDialBeforeListen(t *testing.T) { @@ -151,15 +151,15 @@ func TestReuseConnectionWhenDialBeforeListen(t *testing.T) { require.NoError(t, err) tr, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) - require.Equal(t, tr, lTr) - require.Equal(t, tr.GetCount(), 2) + require.Equal(t, lTr, tr) + require.Equal(t, 2, tr.GetCount()) // a listener on an unspecified port should reuse the dialer laddr2 := &net.UDPAddr{IP: net.IPv4zero, Port: 0} lconn2, err := reuse.TransportForListen("udp4", laddr2) require.NoError(t, err) - require.Equal(t, lconn2, rTr) - require.Equal(t, lconn2.GetCount(), 2) + require.Equal(t, rTr, lconn2) + require.Equal(t, 2, lconn2.GetCount()) } func TestReuseListenOnSpecificInterface(t *testing.T) { @@ -181,11 +181,11 @@ func TestReuseListenOnSpecificInterface(t *testing.T) { require.NoError(t, err) lconn, err := reuse.TransportForListen("udp4", addr) require.NoError(t, err) - require.Equal(t, lconn.GetCount(), 1) + require.Equal(t, 1, lconn.GetCount()) // dial conn, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) - require.Equal(t, conn.GetCount(), 1) + require.Equal(t, 1, conn.GetCount()) } func TestReuseGarbageCollect(t *testing.T) { @@ -216,13 +216,13 @@ func TestReuseGarbageCollect(t *testing.T) { require.NoError(t, err) dTr, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) - require.Equal(t, dTr.GetCount(), 1) + require.Equal(t, 1, dTr.GetCount()) addr, err := net.ResolveUDPAddr("udp4", "0.0.0.0:1234") require.NoError(t, err) lTr, err := reuse.TransportForListen("udp4", addr) require.NoError(t, err) - require.Equal(t, lTr.GetCount(), 1) + require.Equal(t, 1, lTr.GetCount()) closeTime := time.Now() lTr.DecreaseCount() @@ -233,7 +233,7 @@ func TestReuseGarbageCollect(t *testing.T) { if closeTime.Add(maxUnusedDuration).Before(time.Now()) { break } - require.Equal(t, num, 2) + require.Equal(t, 2, num) time.Sleep(2 * time.Millisecond) } require.Eventually(t, func() bool { return numGlobals() == 0 }, 4*garbageCollectInterval, 10*time.Millisecond) diff --git a/go-libp2p/p2p/transport/quicreuse/tracer.go b/go-libp2p/p2p/transport/quicreuse/tracer.go index 1386a5c..16c7dce 100644 --- a/go-libp2p/p2p/transport/quicreuse/tracer.go +++ b/go-libp2p/p2p/transport/quicreuse/tracer.go @@ -24,7 +24,7 @@ func init() { qlogTracerDir = os.Getenv("QLOGDIR") } -func qloggerForDir(qlogDir string, p logging.Perspective, ci quic.ConnectionID) logging.ConnectionTracer { +func qloggerForDir(qlogDir string, p logging.Perspective, ci quic.ConnectionID) *logging.ConnectionTracer { // create the QLOGDIR, if it doesn't exist if err := os.MkdirAll(qlogDir, 0777); err != nil { log.Errorf("creating the QLOGDIR failed: %s", err) diff --git a/go-libp2p/p2p/transport/quicreuse/tracer_metrics.go b/go-libp2p/p2p/transport/quicreuse/tracer_metrics.go deleted file mode 100644 index 03e73fd..0000000 --- a/go-libp2p/p2p/transport/quicreuse/tracer_metrics.go +++ /dev/null @@ -1,372 +0,0 @@ -package quicreuse - -import ( - "context" - "errors" - "fmt" - "net" - "sync" - "time" - - "github.com/prometheus/client_golang/prometheus" - "github.com/quic-go/quic-go" - "github.com/quic-go/quic-go/logging" -) - -var ( - bytesTransferred *prometheus.CounterVec - newConns *prometheus.CounterVec - closedConns *prometheus.CounterVec - sentPackets *prometheus.CounterVec - rcvdPackets *prometheus.CounterVec - bufferedPackets *prometheus.CounterVec - droppedPackets *prometheus.CounterVec - lostPackets *prometheus.CounterVec - connErrors *prometheus.CounterVec -) - -type aggregatingCollector struct { - mutex sync.Mutex - - conns map[string] /* conn ID */ *metricsConnTracer - rtts prometheus.Histogram - connDurations prometheus.Histogram -} - -func newAggregatingCollector() *aggregatingCollector { - return &aggregatingCollector{ - conns: make(map[string]*metricsConnTracer), - rtts: prometheus.NewHistogram(prometheus.HistogramOpts{ - Name: "quic_smoothed_rtt", - Help: "Smoothed RTT", - Buckets: prometheus.ExponentialBuckets(0.001, 1.25, 40), // 1ms to ~6000ms - }), - connDurations: prometheus.NewHistogram(prometheus.HistogramOpts{ - Name: "quic_connection_duration", - Help: "Connection Duration", - Buckets: prometheus.ExponentialBuckets(1, 1.5, 40), // 1s to ~12 weeks - }), - } -} - -var _ prometheus.Collector = &aggregatingCollector{} - -func (c *aggregatingCollector) Describe(descs chan<- *prometheus.Desc) { - descs <- c.rtts.Desc() - descs <- c.connDurations.Desc() -} - -func (c *aggregatingCollector) Collect(metrics chan<- prometheus.Metric) { - now := time.Now() - c.mutex.Lock() - for _, conn := range c.conns { - if rtt, valid := conn.getSmoothedRTT(); valid { - c.rtts.Observe(rtt.Seconds()) - } - c.connDurations.Observe(now.Sub(conn.startTime).Seconds()) - } - c.mutex.Unlock() - metrics <- c.rtts - metrics <- c.connDurations -} - -func (c *aggregatingCollector) AddConn(id string, t *metricsConnTracer) { - c.mutex.Lock() - c.conns[id] = t - c.mutex.Unlock() -} - -func (c *aggregatingCollector) RemoveConn(id string) { - c.mutex.Lock() - delete(c.conns, id) - c.mutex.Unlock() -} - -var collector *aggregatingCollector - -var initMetricsOnce sync.Once - -func initMetrics() { - const ( - direction = "direction" - encLevel = "encryption_level" - ) - - closedConns = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "quic_connections_closed_total", - Help: "closed QUIC connection", - }, - []string{direction}, - ) - prometheus.MustRegister(closedConns) - newConns = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "quic_connections_new_total", - Help: "new QUIC connection", - }, - []string{direction, "handshake_successful"}, - ) - prometheus.MustRegister(newConns) - bytesTransferred = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "quic_transferred_bytes", - Help: "QUIC bytes transferred", - }, - []string{direction}, // TODO: this is confusing. Other times, we use direction for the perspective - ) - prometheus.MustRegister(bytesTransferred) - sentPackets = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "quic_packets_sent_total", - Help: "QUIC packets sent", - }, - []string{encLevel}, - ) - prometheus.MustRegister(sentPackets) - rcvdPackets = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "quic_packets_rcvd_total", - Help: "QUIC packets received", - }, - []string{encLevel}, - ) - prometheus.MustRegister(rcvdPackets) - bufferedPackets = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "quic_packets_buffered_total", - Help: "Buffered packets", - }, - []string{"packet_type"}, - ) - prometheus.MustRegister(bufferedPackets) - droppedPackets = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "quic_packets_dropped_total", - Help: "Dropped packets", - }, - []string{"packet_type", "reason"}, - ) - prometheus.MustRegister(droppedPackets) - connErrors = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "quic_connection_errors_total", - Help: "QUIC connection errors", - }, - []string{"side", "error_code"}, - ) - prometheus.MustRegister(connErrors) - lostPackets = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "quic_packets_lost_total", - Help: "QUIC lost received", - }, - []string{encLevel, "reason"}, - ) - prometheus.MustRegister(lostPackets) - collector = newAggregatingCollector() - prometheus.MustRegister(collector) -} - -type metricsTracer struct { - logging.NullTracer -} - -var _ logging.Tracer = &metricsTracer{} - -func newMetricsTracer() *metricsTracer { - initMetricsOnce.Do(func() { initMetrics() }) - return &metricsTracer{} -} - -func (m *metricsTracer) TracerForConnection(_ context.Context, p logging.Perspective, connID logging.ConnectionID) logging.ConnectionTracer { - return &metricsConnTracer{perspective: p, connID: connID} -} - -func (m *metricsTracer) SentPacket(_ net.Addr, _ *logging.Header, size logging.ByteCount, _ []logging.Frame) { - bytesTransferred.WithLabelValues("sent").Add(float64(size)) -} - -type metricsConnTracer struct { - logging.NullConnectionTracer - - perspective logging.Perspective - startTime time.Time - connID logging.ConnectionID - handshakeComplete bool - - mutex sync.Mutex - numRTTMeasurements int - rtt time.Duration -} - -var _ logging.ConnectionTracer = &metricsConnTracer{} - -func (m *metricsConnTracer) getDirection() string { - if m.perspective == logging.PerspectiveClient { - return "outgoing" - } - return "incoming" -} - -func (m *metricsConnTracer) getEncLevel(packetType logging.PacketType) string { - switch packetType { - case logging.PacketType0RTT: - return "0-RTT" - case logging.PacketTypeInitial: - return "Initial" - case logging.PacketTypeHandshake: - return "Handshake" - case logging.PacketTypeRetry: - return "Retry" - case logging.PacketType1RTT: - return "1-RTT" - default: - return "unknown" - } -} - -func (m *metricsConnTracer) StartedConnection(net.Addr, net.Addr, logging.ConnectionID, logging.ConnectionID) { - m.startTime = time.Now() - collector.AddConn(m.connID.String(), m) -} - -func (m *metricsConnTracer) ClosedConnection(e error) { - var ( - applicationErr *quic.ApplicationError - transportErr *quic.TransportError - statelessResetErr *quic.StatelessResetError - vnErr *quic.VersionNegotiationError - idleTimeoutErr *quic.IdleTimeoutError - handshakeTimeoutErr *quic.HandshakeTimeoutError - remote bool - desc string - ) - - switch { - case errors.As(e, &applicationErr): - return - case errors.As(e, &transportErr): - remote = transportErr.Remote - desc = transportErr.ErrorCode.String() - case errors.As(e, &statelessResetErr): - remote = true - desc = "stateless_reset" - case errors.As(e, &vnErr): - desc = "version_negotiation" - case errors.As(e, &idleTimeoutErr): - desc = "idle_timeout" - case errors.As(e, &handshakeTimeoutErr): - desc = "handshake_timeout" - default: - desc = fmt.Sprintf("unknown error: %v", e) - } - - side := "local" - if remote { - side = "remote" - } - connErrors.WithLabelValues(side, desc).Inc() -} -func (m *metricsConnTracer) SentPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, _ *logging.AckFrame, _ []logging.Frame) { - bytesTransferred.WithLabelValues("sent").Add(float64(size)) - sentPackets.WithLabelValues(m.getEncLevel(logging.PacketTypeFromHeader(&hdr.Header))).Inc() -} - -func (m *metricsConnTracer) ReceivedVersionNegotiationPacket(dst, src logging.ArbitraryLenConnectionID, v []logging.VersionNumber) { - bytesTransferred.WithLabelValues("rcvd").Add(1 /* header form byte */ + 4 /* version number */ + 2 /* src and dest conn id length fields */ + float64(dst.Len()+src.Len()) + float64(4*len(v))) - rcvdPackets.WithLabelValues("Version Negotiation").Inc() -} - -func (m *metricsConnTracer) ReceivedRetry(*logging.Header) { - rcvdPackets.WithLabelValues("Retry").Inc() -} - -func (m *metricsConnTracer) ReceivedPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, _ []logging.Frame) { - bytesTransferred.WithLabelValues("rcvd").Add(float64(size)) - rcvdPackets.WithLabelValues(m.getEncLevel(logging.PacketTypeFromHeader(&hdr.Header))).Inc() -} - -func (m *metricsConnTracer) BufferedPacket(packetType logging.PacketType, _ logging.ByteCount) { - bufferedPackets.WithLabelValues(m.getEncLevel(packetType)).Inc() -} - -func (m *metricsConnTracer) DroppedPacket(packetType logging.PacketType, size logging.ByteCount, r logging.PacketDropReason) { - bytesTransferred.WithLabelValues("rcvd").Add(float64(size)) - var reason string - switch r { - case logging.PacketDropKeyUnavailable: - reason = "key_unavailable" - case logging.PacketDropUnknownConnectionID: - reason = "unknown_connection_id" - case logging.PacketDropHeaderParseError: - reason = "header_parse_error" - case logging.PacketDropPayloadDecryptError: - reason = "payload_decrypt_error" - case logging.PacketDropProtocolViolation: - reason = "protocol_violation" - case logging.PacketDropDOSPrevention: - reason = "dos_prevention" - case logging.PacketDropUnsupportedVersion: - reason = "unsupported_version" - case logging.PacketDropUnexpectedPacket: - reason = "unexpected_packet" - case logging.PacketDropUnexpectedSourceConnectionID: - reason = "unexpected_source_connection_id" - case logging.PacketDropUnexpectedVersion: - reason = "unexpected_version" - case logging.PacketDropDuplicate: - reason = "duplicate" - default: - reason = "unknown" - } - droppedPackets.WithLabelValues(m.getEncLevel(packetType), reason).Inc() -} - -func (m *metricsConnTracer) UpdatedMetrics(rttStats *logging.RTTStats, cwnd, bytesInFlight logging.ByteCount, packetsInFlight int) { - m.mutex.Lock() - m.rtt = rttStats.SmoothedRTT() - m.numRTTMeasurements++ - m.mutex.Unlock() -} - -func (m *metricsConnTracer) LostPacket(level logging.EncryptionLevel, _ logging.PacketNumber, r logging.PacketLossReason) { - var reason string - switch r { - case logging.PacketLossReorderingThreshold: - reason = "reordering_threshold" - case logging.PacketLossTimeThreshold: - reason = "time_threshold" - default: - reason = "unknown" - } - lostPackets.WithLabelValues(level.String(), reason).Inc() -} - -func (m *metricsConnTracer) DroppedEncryptionLevel(level logging.EncryptionLevel) { - if level == logging.EncryptionHandshake { - m.handleHandshakeComplete() - } -} - -func (m *metricsConnTracer) Close() { - if m.handshakeComplete { - closedConns.WithLabelValues(m.getDirection()).Inc() - } else { - newConns.WithLabelValues(m.getDirection(), "false").Inc() - } - collector.RemoveConn(m.connID.String()) -} - -func (m *metricsConnTracer) handleHandshakeComplete() { - m.handshakeComplete = true - newConns.WithLabelValues(m.getDirection(), "true").Inc() -} - -func (m *metricsConnTracer) getSmoothedRTT() (rtt time.Duration, valid bool) { - m.mutex.Lock() - rtt = m.rtt - valid = m.numRTTMeasurements > 10 - m.mutex.Unlock() - return -} diff --git a/go-libp2p/p2p/transport/quicreuse/tracer_test.go b/go-libp2p/p2p/transport/quicreuse/tracer_test.go index 5d1d74f..3347c5f 100644 --- a/go-libp2p/p2p/transport/quicreuse/tracer_test.go +++ b/go-libp2p/p2p/transport/quicreuse/tracer_test.go @@ -33,12 +33,12 @@ func TestSaveQlog(t *testing.T) { qlogDir := createLogDir(t) logger := newQlogger(qlogDir, logging.PerspectiveServer, quic.ConnectionIDFromBytes([]byte{0xde, 0xad, 0xbe, 0xef})) file := getFile(t, qlogDir) - require.Equal(t, string(file.Name()[0]), ".") + require.Equal(t, ".", string(file.Name()[0])) require.Truef(t, strings.HasSuffix(file.Name(), ".qlog.swp"), "expected %s to have the .qlog.swp file ending", file.Name()) // close the logger. This should move the file. require.NoError(t, logger.Close()) file = getFile(t, qlogDir) - require.NotEqual(t, string(file.Name()[0]), ".") + require.NotEqual(t, ".", string(file.Name()[0])) require.Truef(t, strings.HasSuffix(file.Name(), ".qlog.zst"), "expected %s to have the .qlog.zst file ending", file.Name()) require.Contains(t, file.Name(), "server") require.Contains(t, file.Name(), "deadbeef") @@ -66,10 +66,10 @@ func TestQlogCompression(t *testing.T) { require.NoError(t, logger.Close()) compressed, err := os.ReadFile(qlogDir + "/" + getFile(t, qlogDir).Name()) require.NoError(t, err) - require.NotEqual(t, compressed, "foobar") + require.NotEqual(t, "foobar", compressed) c, err := zstd.NewReader(bytes.NewReader(compressed)) require.NoError(t, err) data, err := io.ReadAll(c) require.NoError(t, err) - require.Equal(t, data, []byte("foobar")) + require.Equal(t, []byte("foobar"), data) } diff --git a/go-libp2p/p2p/transport/tcp/metrics.go b/go-libp2p/p2p/transport/tcp/metrics.go index fc2add4..4434b03 100644 --- a/go-libp2p/p2p/transport/tcp/metrics.go +++ b/go-libp2p/p2p/transport/tcp/metrics.go @@ -1,4 +1,4 @@ -//go:build !windows +//go:build !windows && !riscv64 && !loong64 package tcp diff --git a/go-libp2p/p2p/transport/tcp/metrics_general.go b/go-libp2p/p2p/transport/tcp/metrics_general.go index 6b67283..419fff3 100644 --- a/go-libp2p/p2p/transport/tcp/metrics_general.go +++ b/go-libp2p/p2p/transport/tcp/metrics_general.go @@ -1,4 +1,4 @@ -//go:build !linux && !darwin && !windows +//go:build !linux && !darwin && !windows && !riscv64 && !loong64 package tcp diff --git a/go-libp2p/p2p/transport/tcp/metrics_windows.go b/go-libp2p/p2p/transport/tcp/metrics_none.go similarity index 68% rename from go-libp2p/p2p/transport/tcp/metrics_windows.go rename to go-libp2p/p2p/transport/tcp/metrics_none.go index 7142e7d..8538b30 100644 --- a/go-libp2p/p2p/transport/tcp/metrics_windows.go +++ b/go-libp2p/p2p/transport/tcp/metrics_none.go @@ -1,4 +1,6 @@ -//go:build windows +// riscv64 see: https://github.com/marten-seemann/tcp/pull/1 + +//go:build windows || riscv64 || loong64 package tcp diff --git a/go-libp2p/p2p/transport/tcp/tcp.go b/go-libp2p/p2p/transport/tcp/tcp.go index f277b3f..d52bb96 100644 --- a/go-libp2p/p2p/transport/tcp/tcp.go +++ b/go-libp2p/p2p/transport/tcp/tcp.go @@ -131,6 +131,7 @@ type TcpTransport struct { } var _ transport.Transport = &TcpTransport{} +var _ transport.DialUpdater = &TcpTransport{} // NewTCPTransport creates a tcp transport object that tracks dialers and listeners // created. It represents an entire TCP stack (though it might not necessarily be). @@ -176,13 +177,17 @@ func (t *TcpTransport) maDial(ctx context.Context, raddr ma.Multiaddr) (manet.Co // Dial dials the peer at the remote address. func (t *TcpTransport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (transport.CapableConn, error) { + return t.DialWithUpdates(ctx, raddr, p, nil) +} + +func (t *TcpTransport) DialWithUpdates(ctx context.Context, raddr ma.Multiaddr, p peer.ID, updateChan chan<- transport.DialUpdate) (transport.CapableConn, error) { connScope, err := t.rcmgr.OpenConnection(network.DirOutbound, true, raddr) if err != nil { log.Debugw("resource manager blocked outgoing connection", "peer", p, "addr", raddr, "error", err) return nil, err } - c, err := t.dialWithScope(ctx, raddr, p, connScope) + c, err := t.dialWithScope(ctx, raddr, p, connScope, updateChan) if err != nil { connScope.Done() return nil, err @@ -190,7 +195,7 @@ func (t *TcpTransport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) return c, nil } -func (t *TcpTransport) dialWithScope(ctx context.Context, raddr ma.Multiaddr, p peer.ID, connScope network.ConnManagementScope) (transport.CapableConn, error) { +func (t *TcpTransport) dialWithScope(ctx context.Context, raddr ma.Multiaddr, p peer.ID, connScope network.ConnManagementScope, updateChan chan<- transport.DialUpdate) (transport.CapableConn, error) { if err := connScope.SetPeer(p); err != nil { log.Debugw("resource manager blocked outgoing connection for peer", "peer", p, "addr", raddr, "error", err) return nil, err @@ -212,6 +217,13 @@ func (t *TcpTransport) dialWithScope(ctx context.Context, raddr ma.Multiaddr, p return nil, err } } + if updateChan != nil { + select { + case updateChan <- transport.DialUpdate{Kind: transport.UpdateKindHandshakeProgressed, Addr: raddr}: + default: + // It is better to skip the update than to delay upgrading the connection + } + } direction := network.DirOutbound if ok, isClient, _ := network.GetSimultaneousConnect(ctx); ok && !isClient { direction = network.DirInbound diff --git a/go-libp2p/p2p/transport/tcp/tcp_test.go b/go-libp2p/p2p/transport/tcp/tcp_test.go index 05b6cb9..a57a65e 100644 --- a/go-libp2p/p2p/transport/tcp/tcp_test.go +++ b/go-libp2p/p2p/transport/tcp/tcp_test.go @@ -16,9 +16,10 @@ import ( tptu "github.com/libp2p/go-libp2p/p2p/net/upgrader" ttransport "github.com/libp2p/go-libp2p/p2p/transport/testsuite" - "github.com/golang/mock/gomock" ma "github.com/multiformats/go-multiaddr" + manet "github.com/multiformats/go-multiaddr/net" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) var muxers = []tptu.StreamMuxer{{ID: "/yamux", Muxer: yamux.DefaultTransport}} @@ -147,6 +148,54 @@ func TestTcpTransportCantListenUtp(t *testing.T) { envReuseportVal = true } +func TestDialWithUpdates(t *testing.T) { + peerA, ia := makeInsecureMuxer(t) + _, ib := makeInsecureMuxer(t) + + ua, err := tptu.New(ia, muxers, nil, nil, nil) + require.NoError(t, err) + ta, err := NewTCPTransport(ua, nil) + require.NoError(t, err) + ln, err := ta.Listen(ma.StringCast("/ip4/127.0.0.1/tcp/0")) + require.NoError(t, err) + defer ln.Close() + + ub, err := tptu.New(ib, muxers, nil, nil, nil) + require.NoError(t, err) + tb, err := NewTCPTransport(ub, nil) + require.NoError(t, err) + + updCh := make(chan transport.DialUpdate, 1) + conn, err := tb.DialWithUpdates(context.Background(), ln.Multiaddr(), peerA, updCh) + upd := <-updCh + require.Equal(t, transport.UpdateKindHandshakeProgressed, upd.Kind) + require.NotNil(t, conn) + require.NoError(t, err) + + acceptAndClose := func() manet.Listener { + li, err := manet.Listen(ma.StringCast("/ip4/127.0.0.1/tcp/0")) + if err != nil { + t.Fatal(err) + } + go func() { + conn, err := li.Accept() + if err != nil { + return + } + conn.Close() + }() + return li + } + li := acceptAndClose() + defer li.Close() + // This dial will fail as acceptAndClose will not upgrade the connection + conn, err = tb.DialWithUpdates(context.Background(), li.Multiaddr(), peerA, updCh) + upd = <-updCh + require.Equal(t, transport.UpdateKindHandshakeProgressed, upd.Kind) + require.Nil(t, conn) + require.Error(t, err) +} + func makeInsecureMuxer(t *testing.T) (peer.ID, []sec.SecureTransport) { t.Helper() priv, _, err := crypto.GenerateKeyPair(crypto.Ed25519, 256) diff --git a/go-libp2p/p2p/transport/webrtc/connection.go b/go-libp2p/p2p/transport/webrtc/connection.go new file mode 100644 index 0000000..cd28ec3 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/connection.go @@ -0,0 +1,255 @@ +package libp2pwebrtc + +import ( + "context" + "errors" + "fmt" + "math" + "net" + "sync" + "sync/atomic" + + ic "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" + tpt "github.com/libp2p/go-libp2p/core/transport" + + ma "github.com/multiformats/go-multiaddr" + "github.com/pion/datachannel" + "github.com/pion/webrtc/v3" +) + +var _ tpt.CapableConn = &connection{} + +const maxAcceptQueueLen = 256 + +type errConnectionTimeout struct{} + +var _ net.Error = &errConnectionTimeout{} + +func (errConnectionTimeout) Error() string { return "connection timeout" } +func (errConnectionTimeout) Timeout() bool { return true } +func (errConnectionTimeout) Temporary() bool { return false } + +type dataChannel struct { + stream datachannel.ReadWriteCloser + channel *webrtc.DataChannel +} + +type connection struct { + pc *webrtc.PeerConnection + transport *WebRTCTransport + scope network.ConnManagementScope + + closeOnce sync.Once + closeErr error + + localPeer peer.ID + localMultiaddr ma.Multiaddr + + remotePeer peer.ID + remoteKey ic.PubKey + remoteMultiaddr ma.Multiaddr + + m sync.Mutex + streams map[uint16]*stream + nextStreamID atomic.Int32 + + acceptQueue chan dataChannel + + ctx context.Context + cancel context.CancelFunc +} + +func newConnection( + direction network.Direction, + pc *webrtc.PeerConnection, + transport *WebRTCTransport, + scope network.ConnManagementScope, + + localPeer peer.ID, + localMultiaddr ma.Multiaddr, + + remotePeer peer.ID, + remoteKey ic.PubKey, + remoteMultiaddr ma.Multiaddr, + incomingDataChannels chan dataChannel, +) (*connection, error) { + ctx, cancel := context.WithCancel(context.Background()) + c := &connection{ + pc: pc, + transport: transport, + scope: scope, + + localPeer: localPeer, + localMultiaddr: localMultiaddr, + + remotePeer: remotePeer, + remoteKey: remoteKey, + remoteMultiaddr: remoteMultiaddr, + ctx: ctx, + cancel: cancel, + streams: make(map[uint16]*stream), + + acceptQueue: incomingDataChannels, + } + switch direction { + case network.DirInbound: + c.nextStreamID.Store(1) + case network.DirOutbound: + // stream ID 0 is used for the Noise handshake stream + c.nextStreamID.Store(2) + } + + pc.OnConnectionStateChange(c.onConnectionStateChange) + return c, nil +} + +// ConnState implements transport.CapableConn +func (c *connection) ConnState() network.ConnectionState { + return network.ConnectionState{Transport: "webrtc-direct"} +} + +// Close closes the underlying peerconnection. +func (c *connection) Close() error { + c.closeOnce.Do(func() { c.closeWithError(errors.New("connection closed")) }) + return nil +} + +// closeWithError is used to Close the connection when the underlying DTLS connection fails +func (c *connection) closeWithError(err error) { + c.closeErr = err + // cancel must be called after closeErr is set. This ensures interested goroutines waiting on + // ctx.Done can read closeErr without holding the conn lock. + c.cancel() + // closing peerconnection will close the datachannels associated with the streams + c.pc.Close() + + c.m.Lock() + streams := c.streams + c.streams = nil + c.m.Unlock() + for _, s := range streams { + s.closeForShutdown(err) + } + c.scope.Done() +} + +func (c *connection) IsClosed() bool { + return c.ctx.Err() != nil +} + +func (c *connection) OpenStream(ctx context.Context) (network.MuxedStream, error) { + if c.IsClosed() { + return nil, c.closeErr + } + + id := c.nextStreamID.Add(2) - 2 + if id > math.MaxUint16 { + return nil, errors.New("exhausted stream ID space") + } + streamID := uint16(id) + dc, err := c.pc.CreateDataChannel("", &webrtc.DataChannelInit{ID: &streamID}) + if err != nil { + return nil, err + } + rwc, err := c.detachChannel(ctx, dc) + if err != nil { + dc.Close() + return nil, fmt.Errorf("detach channel failed for stream(%d): %w", streamID, err) + } + str := newStream(dc, rwc, func() { c.removeStream(streamID) }) + if err := c.addStream(str); err != nil { + str.Reset() + return nil, fmt.Errorf("failed to add stream(%d) to connection: %w", streamID, err) + } + return str, nil +} + +func (c *connection) AcceptStream() (network.MuxedStream, error) { + select { + case <-c.ctx.Done(): + return nil, c.closeErr + case dc := <-c.acceptQueue: + str := newStream(dc.channel, dc.stream, func() { c.removeStream(*dc.channel.ID()) }) + if err := c.addStream(str); err != nil { + str.Reset() + return nil, err + } + return str, nil + } +} + +func (c *connection) LocalPeer() peer.ID { return c.localPeer } +func (c *connection) RemotePeer() peer.ID { return c.remotePeer } +func (c *connection) RemotePublicKey() ic.PubKey { return c.remoteKey } +func (c *connection) LocalMultiaddr() ma.Multiaddr { return c.localMultiaddr } +func (c *connection) RemoteMultiaddr() ma.Multiaddr { return c.remoteMultiaddr } +func (c *connection) Scope() network.ConnScope { return c.scope } +func (c *connection) Transport() tpt.Transport { return c.transport } + +func (c *connection) addStream(str *stream) error { + c.m.Lock() + defer c.m.Unlock() + if c.streams == nil { + return c.closeErr + } + if _, ok := c.streams[str.id]; ok { + return errors.New("stream ID already exists") + } + c.streams[str.id] = str + return nil +} + +func (c *connection) removeStream(id uint16) { + c.m.Lock() + defer c.m.Unlock() + delete(c.streams, id) +} + +func (c *connection) onConnectionStateChange(state webrtc.PeerConnectionState) { + if state == webrtc.PeerConnectionStateFailed || state == webrtc.PeerConnectionStateClosed { + c.closeOnce.Do(func() { + c.closeWithError(errConnectionTimeout{}) + }) + } +} + +// detachChannel detaches an outgoing channel by taking into account the context +// passed to `OpenStream` as well the closure of the underlying peerconnection +// +// The underlying SCTP stream for a datachannel implements a net.Conn interface. +// However, the datachannel creates a goroutine which continuously reads from +// the SCTP stream and surfaces the data using an OnMessage callback. +// +// The actual abstractions are as follows: webrtc.DataChannel +// wraps pion.DataChannel, which wraps sctp.Stream. +// +// The goroutine for reading, Detach method, +// and the OnMessage callback are present at the webrtc.DataChannel level. +// Detach provides us abstracted access to the underlying pion.DataChannel, +// which allows us to issue Read calls to the datachannel. +// This was desired because it was not feasible to introduce backpressure +// with the OnMessage callbacks. The tradeoff is a change in the semantics of +// the OnOpen callback, and having to force close Read locally. +func (c *connection) detachChannel(ctx context.Context, dc *webrtc.DataChannel) (datachannel.ReadWriteCloser, error) { + done := make(chan struct{}) + + var rwc datachannel.ReadWriteCloser + var err error + // OnOpen will return immediately for detached datachannels + // refer: https://github.com/pion/webrtc/blob/7ab3174640b3ce15abebc2516a2ca3939b5f105f/datachannel.go#L278-L282 + dc.OnOpen(func() { + rwc, err = dc.Detach() + // this is safe since the function should return instantly if the peerconnection is closed + close(done) + }) + select { + case <-c.ctx.Done(): + return nil, c.closeErr + case <-ctx.Done(): + return nil, ctx.Err() + case <-done: + return rwc, err + } +} diff --git a/go-libp2p/p2p/transport/webrtc/fingerprint.go b/go-libp2p/p2p/transport/webrtc/fingerprint.go new file mode 100644 index 0000000..fd71586 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/fingerprint.go @@ -0,0 +1,53 @@ +package libp2pwebrtc + +import ( + "crypto" + "crypto/x509" + "errors" + + ma "github.com/multiformats/go-multiaddr" + "github.com/multiformats/go-multibase" + mh "github.com/multiformats/go-multihash" + "github.com/pion/webrtc/v3" +) + +// parseFingerprint is forked from pion to avoid bytes to string alloc, +// and to avoid the entire hex interspersing when we do not need it anyway + +var errHashUnavailable = errors.New("fingerprint: hash algorithm is not linked into the binary") + +// parseFingerprint creates a fingerprint for a certificate using the specified hash algorithm +func parseFingerprint(cert *x509.Certificate, algo crypto.Hash) ([]byte, error) { + if !algo.Available() { + return nil, errHashUnavailable + } + h := algo.New() + // Hash.Writer is specified to be never returning an error. + // https://golang.org/pkg/hash/#Hash + h.Write(cert.Raw) + return h.Sum(nil), nil +} + +func decodeRemoteFingerprint(maddr ma.Multiaddr) (*mh.DecodedMultihash, error) { + remoteFingerprintMultibase, err := maddr.ValueForProtocol(ma.P_CERTHASH) + if err != nil { + return nil, err + } + _, data, err := multibase.Decode(remoteFingerprintMultibase) + if err != nil { + return nil, err + } + return mh.Decode(data) +} + +func encodeDTLSFingerprint(fp webrtc.DTLSFingerprint) (string, error) { + digest, err := decodeInterspersedHexFromASCIIString(fp.Value) + if err != nil { + return "", err + } + encoded, err := mh.Encode(digest, mh.SHA2_256) + if err != nil { + return "", err + } + return multibase.Encode(multibase.Base64url, encoded) +} diff --git a/go-libp2p/p2p/transport/webrtc/hex.go b/go-libp2p/p2p/transport/webrtc/hex.go new file mode 100644 index 0000000..4820365 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/hex.go @@ -0,0 +1,70 @@ +package libp2pwebrtc + +// The code in this file is adapted from the Go standard library's hex package. +// As found in https://cs.opensource.google/go/go/+/refs/tags/go1.20.2:src/encoding/hex/hex.go +// +// The reason we adapted the original code is to allow us to deal with interspersed requirements +// while at the same time hex encoding/decoding, without having to do so in two passes. + +import ( + "encoding/hex" + "errors" +) + +// encodeInterspersedHex encodes a byte slice into a string of hex characters, +// separating each encoded byte with a colon (':'). +// +// Example: { 0x01, 0x02, 0x03 } -> "01:02:03" +func encodeInterspersedHex(src []byte) string { + if len(src) == 0 { + return "" + } + s := hex.EncodeToString(src) + n := len(s) + // Determine number of colons + colons := n / 2 + if n%2 == 0 { + colons-- + } + buffer := make([]byte, n+colons) + + for i, j := 0, 0; i < n; i, j = i+2, j+3 { + copy(buffer[j:j+2], s[i:i+2]) + if j+3 < len(buffer) { + buffer[j+2] = ':' + } + } + return string(buffer) +} + +var errUnexpectedIntersperseHexChar = errors.New("unexpected character in interspersed hex string") + +// decodeInterspersedHexFromASCIIString decodes an ASCII string of hex characters into a byte slice, +// where the hex characters are expected to be separated by a colon (':'). +// +// NOTE that this function returns an error in case the input string contains non-ASCII characters. +// +// Example: "01:02:03" -> { 0x01, 0x02, 0x03 } +func decodeInterspersedHexFromASCIIString(s string) ([]byte, error) { + n := len(s) + buffer := make([]byte, n/3*2+n%3) + j := 0 + for i := 0; i < n; i++ { + if i%3 == 2 { + if s[i] != ':' { + return nil, errUnexpectedIntersperseHexChar + } + } else { + if s[i] == ':' { + return nil, errUnexpectedIntersperseHexChar + } + buffer[j] = s[i] + j++ + } + } + dst := make([]byte, hex.DecodedLen(len(buffer))) + if _, err := hex.Decode(dst, buffer); err != nil { + return nil, err + } + return dst, nil +} diff --git a/go-libp2p/p2p/transport/webrtc/hex_test.go b/go-libp2p/p2p/transport/webrtc/hex_test.go new file mode 100644 index 0000000..c8a7147 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/hex_test.go @@ -0,0 +1,132 @@ +package libp2pwebrtc + +import ( + "encoding/hex" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestEncodeInterspersedHex(t *testing.T) { + b, err := hex.DecodeString("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") + require.NoError(t, err) + require.Equal(t, "ba:78:16:bf:8f:01:cf:ea:41:41:40:de:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:ff:61:f2:00:15:ad", encodeInterspersedHex(b)) +} + +func BenchmarkEncodeInterspersedHex(b *testing.B) { + data, err := hex.DecodeString("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") + require.NoError(b, err) + + for i := 0; i < b.N; i++ { + encodeInterspersedHex(data) + } +} + +func TestDecodeInterpersedHexStringLowerCase(t *testing.T) { + b, err := decodeInterspersedHexFromASCIIString("ba:78:16:bf:8f:01:cf:ea:41:41:40:de:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:ff:61:f2:00:15:ad") + require.NoError(t, err) + require.Equal(t, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", hex.EncodeToString(b)) +} + +func TestDecodeInterpersedHexStringMixedCase(t *testing.T) { + b, err := decodeInterspersedHexFromASCIIString("Ba:78:16:BF:8F:01:cf:ea:41:41:40:De:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:FF:61:f2:00:15:ad") + require.NoError(t, err) + require.Equal(t, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", hex.EncodeToString(b)) +} + +func TestDecodeInterpersedHexStringOneByte(t *testing.T) { + b, err := decodeInterspersedHexFromASCIIString("ba") + require.NoError(t, err) + require.Equal(t, "ba", hex.EncodeToString(b)) +} + +func TestDecodeInterpersedHexBytesLowerCase(t *testing.T) { + b, err := decodeInterspersedHexFromASCIIString("ba:78:16:bf:8f:01:cf:ea:41:41:40:de:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:ff:61:f2:00:15:ad") + require.NoError(t, err) + require.Equal(t, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", hex.EncodeToString(b)) +} + +func BenchmarkDecode(b *testing.B) { + for i := 0; i < b.N; i++ { + _, err := decodeInterspersedHexFromASCIIString("ba:78:16:bf:8f:01:cf:ea:41:41:40:de:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:ff:61:f2:00:15:ad") + require.NoError(b, err) + } +} + +func TestDecodeInterpersedHexBytesMixedCase(t *testing.T) { + b, err := decodeInterspersedHexFromASCIIString("Ba:78:16:BF:8F:01:cf:ea:41:41:40:De:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:FF:61:f2:00:15:ad") + require.NoError(t, err) + require.Equal(t, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", hex.EncodeToString(b)) +} + +func TestDecodeInterpersedHexBytesOneByte(t *testing.T) { + b, err := decodeInterspersedHexFromASCIIString("ba") + require.NoError(t, err) + require.Equal(t, "ba", hex.EncodeToString(b)) +} + +func TestEncodeInterperseHexNilSlice(t *testing.T) { + require.Equal(t, "", encodeInterspersedHex(nil)) + require.Equal(t, "", encodeInterspersedHex([]byte{})) +} + +func TestDecodeInterspersedHexEmpty(t *testing.T) { + b, err := decodeInterspersedHexFromASCIIString("") + require.NoError(t, err) + require.Equal(t, []byte{}, b) +} + +func TestDecodeInterpersedHexFromASCIIStringEmpty(t *testing.T) { + b, err := decodeInterspersedHexFromASCIIString("") + require.NoError(t, err) + require.Equal(t, []byte{}, b) +} + +func TestDecodeInterpersedHexInvalid(t *testing.T) { + for _, v := range []string{"0", "0000", "000"} { + _, err := decodeInterspersedHexFromASCIIString(v) + require.Error(t, err) + } +} + +func TestDecodeInterpersedHexValid(t *testing.T) { + b, err := decodeInterspersedHexFromASCIIString("00") + require.NoError(t, err) + require.Equal(t, []byte{0}, b) +} + +func TestDecodeInterpersedHexFromASCIIStringInvalid(t *testing.T) { + for _, v := range []string{"0", "0000", "000"} { + _, err := decodeInterspersedHexFromASCIIString(v) + require.Error(t, err) + } +} + +func TestDecodeInterpersedHexFromASCIIStringValid(t *testing.T) { + b, err := decodeInterspersedHexFromASCIIString("00") + require.NoError(t, err) + require.Equal(t, []byte{0}, b) +} + +func FuzzInterpersedHex(f *testing.F) { + f.Fuzz(func(t *testing.T, b []byte) { + decoded, err := decodeInterspersedHexFromASCIIString(string(b)) + if err != nil { + return + } + encoded := encodeInterspersedHex(decoded) + require.Equal(t, strings.ToLower(string(b)), encoded) + }) +} + +func FuzzInterspersedHexASCII(f *testing.F) { + f.Fuzz(func(t *testing.T, s string) { + decoded, err := decodeInterspersedHexFromASCIIString(s) + if err != nil { + return + } + encoded := encodeInterspersedHex(decoded) + require.Equal(t, strings.ToLower(s), encoded) + }) +} diff --git a/go-libp2p/p2p/transport/webrtc/listener.go b/go-libp2p/p2p/transport/webrtc/listener.go new file mode 100644 index 0000000..1834fc8 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/listener.go @@ -0,0 +1,350 @@ +package libp2pwebrtc + +import ( + "context" + "crypto" + "encoding/hex" + "errors" + "fmt" + "net" + "strings" + "sync" + "time" + + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" + tpt "github.com/libp2p/go-libp2p/core/transport" + "github.com/libp2p/go-libp2p/p2p/transport/webrtc/udpmux" + + ma "github.com/multiformats/go-multiaddr" + manet "github.com/multiformats/go-multiaddr/net" + "github.com/multiformats/go-multibase" + "github.com/multiformats/go-multihash" + "github.com/pion/webrtc/v3" +) + +type connMultiaddrs struct { + local, remote ma.Multiaddr +} + +var _ network.ConnMultiaddrs = &connMultiaddrs{} + +func (c *connMultiaddrs) LocalMultiaddr() ma.Multiaddr { return c.local } +func (c *connMultiaddrs) RemoteMultiaddr() ma.Multiaddr { return c.remote } + +const ( + candidateSetupTimeout = 20 * time.Second + DefaultMaxInFlightConnections = 10 +) + +type listener struct { + transport *WebRTCTransport + + mux *udpmux.UDPMux + + config webrtc.Configuration + localFingerprint webrtc.DTLSFingerprint + localFingerprintMultibase string + + localAddr net.Addr + localMultiaddr ma.Multiaddr + + // buffered incoming connections + acceptQueue chan tpt.CapableConn + + // used to control the lifecycle of the listener + ctx context.Context + cancel context.CancelFunc + wg sync.WaitGroup +} + +var _ tpt.Listener = &listener{} + +func newListener(transport *WebRTCTransport, laddr ma.Multiaddr, socket net.PacketConn, config webrtc.Configuration) (*listener, error) { + localFingerprints, err := config.Certificates[0].GetFingerprints() + if err != nil { + return nil, err + } + + localMh, err := hex.DecodeString(strings.ReplaceAll(localFingerprints[0].Value, ":", "")) + if err != nil { + return nil, err + } + localMhBuf, err := multihash.Encode(localMh, multihash.SHA2_256) + if err != nil { + return nil, err + } + localFpMultibase, err := multibase.Encode(multibase.Base64url, localMhBuf) + if err != nil { + return nil, err + } + + l := &listener{ + transport: transport, + config: config, + localFingerprint: localFingerprints[0], + localFingerprintMultibase: localFpMultibase, + localMultiaddr: laddr, + localAddr: socket.LocalAddr(), + acceptQueue: make(chan tpt.CapableConn), + } + + l.ctx, l.cancel = context.WithCancel(context.Background()) + l.mux = udpmux.NewUDPMux(socket) + l.mux.Start() + + l.wg.Add(1) + go func() { + defer l.wg.Done() + l.listen() + }() + + return l, err +} + +func (l *listener) listen() { + // Accepting a connection requires instantiating a peerconnection and a noise connection + // which is expensive. We therefore limit the number of in-flight connection requests. A + // connection is considered to be in flight from the instant it is handled until it is + // dequeued by a call to Accept, or errors out in some way. + inFlightSemaphore := make(chan struct{}, l.transport.maxInFlightConnections) + for { + select { + case inFlightSemaphore <- struct{}{}: + case <-l.ctx.Done(): + return + } + + candidate, err := l.mux.Accept(l.ctx) + if err != nil { + if l.ctx.Err() == nil { + log.Debugf("accepting candidate failed: %s", err) + } + return + } + + go func() { + defer func() { <-inFlightSemaphore }() + + ctx, cancel := context.WithTimeout(l.ctx, candidateSetupTimeout) + defer cancel() + + conn, err := l.handleCandidate(ctx, candidate) + if err != nil { + l.mux.RemoveConnByUfrag(candidate.Ufrag) + log.Debugf("could not accept connection: %s: %v", candidate.Ufrag, err) + return + } + + select { + case <-ctx.Done(): + log.Warn("could not push connection: ctx done") + conn.Close() + case l.acceptQueue <- conn: + // acceptQueue is an unbuffered channel, so this blocks until the connection is accepted. + } + }() + } +} + +func (l *listener) handleCandidate(ctx context.Context, candidate udpmux.Candidate) (tpt.CapableConn, error) { + remoteMultiaddr, err := manet.FromNetAddr(candidate.Addr) + if err != nil { + return nil, err + } + if l.transport.gater != nil { + localAddr, _ := ma.SplitFunc(l.localMultiaddr, func(c ma.Component) bool { return c.Protocol().Code == ma.P_CERTHASH }) + if !l.transport.gater.InterceptAccept(&connMultiaddrs{local: localAddr, remote: remoteMultiaddr}) { + // The connection attempt is rejected before we can send the client an error. + // This means that the connection attempt will time out. + return nil, errors.New("connection gated") + } + } + scope, err := l.transport.rcmgr.OpenConnection(network.DirInbound, false, remoteMultiaddr) + if err != nil { + return nil, err + } + conn, err := l.setupConnection(ctx, scope, remoteMultiaddr, candidate) + if err != nil { + scope.Done() + return nil, err + } + if l.transport.gater != nil && !l.transport.gater.InterceptSecured(network.DirInbound, conn.RemotePeer(), conn) { + conn.Close() + return nil, errors.New("connection gated") + } + return conn, nil +} + +func (l *listener) setupConnection( + ctx context.Context, scope network.ConnManagementScope, + remoteMultiaddr ma.Multiaddr, candidate udpmux.Candidate, +) (tConn tpt.CapableConn, err error) { + var w webRTCConnection + defer func() { + if err != nil { + if w.PeerConnection != nil { + _ = w.PeerConnection.Close() + } + if tConn != nil { + _ = tConn.Close() + } + } + }() + + settingEngine := webrtc.SettingEngine{LoggerFactory: pionLoggerFactory} + settingEngine.SetAnsweringDTLSRole(webrtc.DTLSRoleServer) + settingEngine.SetICECredentials(candidate.Ufrag, candidate.Ufrag) + settingEngine.SetLite(true) + settingEngine.SetICEUDPMux(l.mux) + settingEngine.SetIncludeLoopbackCandidate(true) + settingEngine.DisableCertificateFingerprintVerification(true) + settingEngine.SetICETimeouts( + l.transport.peerConnectionTimeouts.Disconnect, + l.transport.peerConnectionTimeouts.Failed, + l.transport.peerConnectionTimeouts.Keepalive, + ) + // This is higher than the path MTU due to a bug in the sctp chunking logic. + // Remove this after https://github.com/pion/sctp/pull/301 is included + // in a release. + settingEngine.SetReceiveMTU(udpmux.ReceiveBufSize) + settingEngine.DetachDataChannels() + settingEngine.SetSCTPMaxReceiveBufferSize(sctpReceiveBufferSize) + if err := scope.ReserveMemory(sctpReceiveBufferSize, network.ReservationPriorityMedium); err != nil { + return nil, err + } + + w, err = newWebRTCConnection(settingEngine, l.config) + if err != nil { + return nil, fmt.Errorf("instantiating peer connection failed: %w", err) + } + + errC := addOnConnectionStateChangeCallback(w.PeerConnection) + // Infer the client SDP from the incoming STUN message by setting the ice-ufrag. + if err := w.PeerConnection.SetRemoteDescription(webrtc.SessionDescription{ + SDP: createClientSDP(candidate.Addr, candidate.Ufrag), + Type: webrtc.SDPTypeOffer, + }); err != nil { + return nil, err + } + answer, err := w.PeerConnection.CreateAnswer(nil) + if err != nil { + return nil, err + } + if err := w.PeerConnection.SetLocalDescription(answer); err != nil { + return nil, err + } + + select { + case <-ctx.Done(): + return nil, ctx.Err() + case err := <-errC: + if err != nil { + return nil, fmt.Errorf("peer connection failed for ufrag: %s", candidate.Ufrag) + } + } + + // Run the noise handshake. + rwc, err := detachHandshakeDataChannel(ctx, w.HandshakeDataChannel) + if err != nil { + return nil, err + } + handshakeChannel := newStream(w.HandshakeDataChannel, rwc, func() {}) + // we do not yet know A's peer ID so accept any inbound + remotePubKey, err := l.transport.noiseHandshake(ctx, w.PeerConnection, handshakeChannel, "", crypto.SHA256, true) + if err != nil { + return nil, err + } + remotePeer, err := peer.IDFromPublicKey(remotePubKey) + if err != nil { + return nil, err + } + // earliest point where we know the remote's peerID + if err := scope.SetPeer(remotePeer); err != nil { + return nil, err + } + + localMultiaddrWithoutCerthash, _ := ma.SplitFunc(l.localMultiaddr, func(c ma.Component) bool { return c.Protocol().Code == ma.P_CERTHASH }) + conn, err := newConnection( + network.DirInbound, + w.PeerConnection, + l.transport, + scope, + l.transport.localPeerId, + localMultiaddrWithoutCerthash, + remotePeer, + remotePubKey, + remoteMultiaddr, + w.IncomingDataChannels, + ) + if err != nil { + return nil, err + } + + return conn, err +} + +func (l *listener) Accept() (tpt.CapableConn, error) { + select { + case <-l.ctx.Done(): + return nil, tpt.ErrListenerClosed + case conn := <-l.acceptQueue: + return conn, nil + } +} + +func (l *listener) Close() error { + select { + case <-l.ctx.Done(): + default: + } + l.cancel() + l.mux.Close() + l.wg.Wait() +loop: + for { + select { + case conn := <-l.acceptQueue: + conn.Close() + default: + break loop + } + } + return nil +} + +func (l *listener) Addr() net.Addr { + return l.localAddr +} + +func (l *listener) Multiaddr() ma.Multiaddr { + return l.localMultiaddr +} + +// addOnConnectionStateChangeCallback adds the OnConnectionStateChange to the PeerConnection. +// The channel returned here: +// * is closed when the state changes to Connection +// * receives an error when the state changes to Failed +// * doesn't receive anything (nor is closed) when the state changes to Disconnected +func addOnConnectionStateChangeCallback(pc *webrtc.PeerConnection) <-chan error { + errC := make(chan error, 1) + var once sync.Once + pc.OnConnectionStateChange(func(state webrtc.PeerConnectionState) { + switch state { + case webrtc.PeerConnectionStateConnected: + once.Do(func() { close(errC) }) + case webrtc.PeerConnectionStateFailed: + once.Do(func() { + errC <- errors.New("peerconnection failed") + close(errC) + }) + case webrtc.PeerConnectionStateDisconnected: + // the connection can move to a disconnected state and back to a connected state without ICE renegotiation. + // This could happen when underlying UDP packets are lost, and therefore the connection moves to the disconnected state. + // If the connection then receives packets on the connection, it can move back to the connected state. + // If no packets are received until the failed timeout is triggered, the connection moves to the failed state. + log.Warn("peerconnection disconnected") + } + }) + return errC +} diff --git a/go-libp2p/p2p/transport/webrtc/logger.go b/go-libp2p/p2p/transport/webrtc/logger.go new file mode 100644 index 0000000..ac9fab7 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/logger.go @@ -0,0 +1,58 @@ +package libp2pwebrtc + +import ( + logging "github.com/ipfs/go-log/v2" + pionLogging "github.com/pion/logging" +) + +var log = logging.Logger("webrtc-transport") + +// pionLog is the logger provided to pion for internal logging +var pionLog = logging.Logger("webrtc-transport-pion") + +// pionLogger wraps the StandardLogger interface to provide a LeveledLogger interface +// as expected by pion +type pionLogger struct { + logging.StandardLogger +} + +var pLog = pionLogger{pionLog} + +var _ pionLogging.LeveledLogger = pLog + +func (l pionLogger) Debug(s string) { + l.StandardLogger.Debug(s) +} + +func (l pionLogger) Error(s string) { + l.StandardLogger.Error(s) +} + +func (l pionLogger) Info(s string) { + l.StandardLogger.Info(s) +} +func (l pionLogger) Warn(s string) { + l.StandardLogger.Warn(s) +} + +func (l pionLogger) Trace(s string) { + l.StandardLogger.Debug(s) +} + +func (l pionLogger) Tracef(s string, args ...interface{}) { + l.StandardLogger.Debugf(s, args...) +} + +// loggerFactory returns pLog for all new logger instances +type loggerFactory struct{} + +// NewLogger returns pLog for all new logger instances. Internally pion creates lots of +// separate logging objects unnecessarily. To avoid the allocations we use a single log +// object for all of pion logging. +func (loggerFactory) NewLogger(scope string) pionLogging.LeveledLogger { + return pLog +} + +var _ pionLogging.LoggerFactory = loggerFactory{} + +var pionLoggerFactory = loggerFactory{} diff --git a/go-libp2p/p2p/transport/webrtc/message.go b/go-libp2p/p2p/transport/webrtc/message.go new file mode 100644 index 0000000..8b57fc8 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/message.go @@ -0,0 +1,3 @@ +package libp2pwebrtc + +//go:generate protoc --go_out=. --go_opt=Mpb/message.proto=./pb pb/message.proto diff --git a/go-libp2p/p2p/transport/webrtc/pb/generate.go b/go-libp2p/p2p/transport/webrtc/pb/generate.go new file mode 100644 index 0000000..5785a95 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/pb/generate.go @@ -0,0 +1,3 @@ +package pb + +//go:generate protoc --go_out=. --go_opt=paths=source_relative -I . message.proto diff --git a/go-libp2p/p2p/transport/webrtc/pb/message.pb.go b/go-libp2p/p2p/transport/webrtc/pb/message.pb.go new file mode 100644 index 0000000..384bddd --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/pb/message.pb.go @@ -0,0 +1,231 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.30.0 +// protoc v3.21.12 +// source: message.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Message_Flag int32 + +const ( + // The sender will no longer send messages on the stream. + Message_FIN Message_Flag = 0 + // The sender will no longer read messages on the stream. Incoming data is + // being discarded on receipt. + Message_STOP_SENDING Message_Flag = 1 + // The sender abruptly terminates the sending part of the stream. The + // receiver can discard any data that it already received on that stream. + Message_RESET Message_Flag = 2 + // Sending the FIN_ACK flag acknowledges the previous receipt of a message + // with the FIN flag set. Receiving a FIN_ACK flag gives the recipient + // confidence that the remote has received all sent messages. + Message_FIN_ACK Message_Flag = 3 +) + +// Enum value maps for Message_Flag. +var ( + Message_Flag_name = map[int32]string{ + 0: "FIN", + 1: "STOP_SENDING", + 2: "RESET", + 3: "FIN_ACK", + } + Message_Flag_value = map[string]int32{ + "FIN": 0, + "STOP_SENDING": 1, + "RESET": 2, + "FIN_ACK": 3, + } +) + +func (x Message_Flag) Enum() *Message_Flag { + p := new(Message_Flag) + *p = x + return p +} + +func (x Message_Flag) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (Message_Flag) Descriptor() protoreflect.EnumDescriptor { + return file_message_proto_enumTypes[0].Descriptor() +} + +func (Message_Flag) Type() protoreflect.EnumType { + return &file_message_proto_enumTypes[0] +} + +func (x Message_Flag) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Do not use. +func (x *Message_Flag) UnmarshalJSON(b []byte) error { + num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b) + if err != nil { + return err + } + *x = Message_Flag(num) + return nil +} + +// Deprecated: Use Message_Flag.Descriptor instead. +func (Message_Flag) EnumDescriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{0, 0} +} + +type Message struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Flag *Message_Flag `protobuf:"varint,1,opt,name=flag,enum=Message_Flag" json:"flag,omitempty"` + Message []byte `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"` +} + +func (x *Message) Reset() { + *x = Message{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Message) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Message) ProtoMessage() {} + +func (x *Message) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Message.ProtoReflect.Descriptor instead. +func (*Message) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{0} +} + +func (x *Message) GetFlag() Message_Flag { + if x != nil && x.Flag != nil { + return *x.Flag + } + return Message_FIN +} + +func (x *Message) GetMessage() []byte { + if x != nil { + return x.Message + } + return nil +} + +var File_message_proto protoreflect.FileDescriptor + +var file_message_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x81, 0x01, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x21, 0x0a, 0x04, 0x66, + 0x6c, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0d, 0x2e, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x2e, 0x46, 0x6c, 0x61, 0x67, 0x52, 0x04, 0x66, 0x6c, 0x61, 0x67, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x39, 0x0a, 0x04, 0x46, 0x6c, 0x61, 0x67, + 0x12, 0x07, 0x0a, 0x03, 0x46, 0x49, 0x4e, 0x10, 0x00, 0x12, 0x10, 0x0a, 0x0c, 0x53, 0x54, 0x4f, + 0x50, 0x5f, 0x53, 0x45, 0x4e, 0x44, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x52, + 0x45, 0x53, 0x45, 0x54, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x46, 0x49, 0x4e, 0x5f, 0x41, 0x43, + 0x4b, 0x10, 0x03, 0x42, 0x35, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x6c, 0x69, 0x62, 0x70, 0x32, 0x70, 0x2f, 0x67, 0x6f, 0x2d, 0x6c, 0x69, 0x62, 0x70, + 0x32, 0x70, 0x2f, 0x70, 0x32, 0x70, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, + 0x2f, 0x77, 0x65, 0x62, 0x72, 0x74, 0x63, 0x2f, 0x70, 0x62, +} + +var ( + file_message_proto_rawDescOnce sync.Once + file_message_proto_rawDescData = file_message_proto_rawDesc +) + +func file_message_proto_rawDescGZIP() []byte { + file_message_proto_rawDescOnce.Do(func() { + file_message_proto_rawDescData = protoimpl.X.CompressGZIP(file_message_proto_rawDescData) + }) + return file_message_proto_rawDescData +} + +var file_message_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_message_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_message_proto_goTypes = []interface{}{ + (Message_Flag)(0), // 0: Message.Flag + (*Message)(nil), // 1: Message +} +var file_message_proto_depIdxs = []int32{ + 0, // 0: Message.flag:type_name -> Message.Flag + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_message_proto_init() } +func file_message_proto_init() { + if File_message_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_message_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Message); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_message_proto_rawDesc, + NumEnums: 1, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_message_proto_goTypes, + DependencyIndexes: file_message_proto_depIdxs, + EnumInfos: file_message_proto_enumTypes, + MessageInfos: file_message_proto_msgTypes, + }.Build() + File_message_proto = out.File + file_message_proto_rawDesc = nil + file_message_proto_goTypes = nil + file_message_proto_depIdxs = nil +} diff --git a/go-libp2p/p2p/transport/webrtc/pb/message.proto b/go-libp2p/p2p/transport/webrtc/pb/message.proto new file mode 100644 index 0000000..aab885b --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/pb/message.proto @@ -0,0 +1,24 @@ +syntax = "proto2"; + +option go_package = "github.com/libp2p/go-libp2p/p2p/transport/webrtc/pb"; + +message Message { + enum Flag { + // The sender will no longer send messages on the stream. + FIN = 0; + // The sender will no longer read messages on the stream. Incoming data is + // being discarded on receipt. + STOP_SENDING = 1; + // The sender abruptly terminates the sending part of the stream. The + // receiver can discard any data that it already received on that stream. + RESET = 2; + // Sending the FIN_ACK flag acknowledges the previous receipt of a message + // with the FIN flag set. Receiving a FIN_ACK flag gives the recipient + // confidence that the remote has received all sent messages. + FIN_ACK = 3; + } + + optional Flag flag=1; + + optional bytes message = 2; +} diff --git a/go-libp2p/p2p/transport/webrtc/sdp.go b/go-libp2p/p2p/transport/webrtc/sdp.go new file mode 100644 index 0000000..878b668 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/sdp.go @@ -0,0 +1,143 @@ +package libp2pwebrtc + +import ( + "crypto" + "fmt" + "net" + "strings" + + "github.com/multiformats/go-multihash" +) + +// clientSDP describes an SDP format string which can be used +// to infer a client's SDP offer from the incoming STUN message. +// The fingerprint used to render a client SDP is arbitrary since +// it fingerprint verification is disabled in favour of a noise +// handshake. The max message size is fixed to 16384 bytes. +const clientSDP = `v=0 +o=- 0 0 IN %[1]s %[2]s +s=- +c=IN %[1]s %[2]s +t=0 0 + +m=application %[3]d UDP/DTLS/SCTP webrtc-datachannel +a=mid:0 +a=ice-options:ice2 +a=ice-ufrag:%[4]s +a=ice-pwd:%[4]s +a=fingerprint:sha-256 ba:78:16:bf:8f:01:cf:ea:41:41:40:de:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:ff:61:f2:00:15:ad +a=setup:actpass +a=sctp-port:5000 +a=max-message-size:16384 +` + +func createClientSDP(addr *net.UDPAddr, ufrag string) string { + ipVersion := "IP4" + if addr.IP.To4() == nil { + ipVersion = "IP6" + } + return fmt.Sprintf( + clientSDP, + ipVersion, + addr.IP, + addr.Port, + ufrag, + ) +} + +// serverSDP defines an SDP format string used by a dialer +// to infer the SDP answer of a server based on the provided +// multiaddr, and the locally set ICE credentials. The max +// message size is fixed to 16384 bytes. +const serverSDP = `v=0 +o=- 0 0 IN %[1]s %[2]s +s=- +t=0 0 +a=ice-lite +m=application %[3]d UDP/DTLS/SCTP webrtc-datachannel +c=IN %[1]s %[2]s +a=mid:0 +a=ice-options:ice2 +a=ice-ufrag:%[4]s +a=ice-pwd:%[4]s +a=fingerprint:%[5]s + +a=setup:passive +a=sctp-port:5000 +a=max-message-size:16384 +a=candidate:1 1 UDP 1 %[2]s %[3]d typ host +a=end-of-candidates +` + +func createServerSDP(addr *net.UDPAddr, ufrag string, fingerprint multihash.DecodedMultihash) (string, error) { + ipVersion := "IP4" + if addr.IP.To4() == nil { + ipVersion = "IP6" + } + + sdpString, err := getSupportedSDPString(fingerprint.Code) + if err != nil { + return "", err + } + + var builder strings.Builder + builder.Grow(len(fingerprint.Digest)*3 + 8) + builder.WriteString(sdpString) + builder.WriteByte(' ') + builder.WriteString(encodeInterspersedHex(fingerprint.Digest)) + fp := builder.String() + + return fmt.Sprintf( + serverSDP, + ipVersion, + addr.IP, + addr.Port, + ufrag, + fp, + ), nil +} + +// getSupportedSDPHash converts a multihash code to the +// corresponding crypto.Hash for supported protocols. If a +// crypto.Hash cannot be found, it returns `(0, false)` +func getSupportedSDPHash(code uint64) (crypto.Hash, bool) { + switch code { + case multihash.MD5: + return crypto.MD5, true + case multihash.SHA1: + return crypto.SHA1, true + case multihash.SHA3_224: + return crypto.SHA3_224, true + case multihash.SHA2_256: + return crypto.SHA256, true + case multihash.SHA3_384: + return crypto.SHA3_384, true + case multihash.SHA2_512: + return crypto.SHA512, true + default: + return 0, false + } +} + +// getSupportedSDPString converts a multihash code +// to a string format recognised by pion for fingerprint +// algorithms +func getSupportedSDPString(code uint64) (string, error) { + // values based on (cryto.Hash).String() + switch code { + case multihash.MD5: + return "md5", nil + case multihash.SHA1: + return "sha-1", nil + case multihash.SHA3_224: + return "sha3-224", nil + case multihash.SHA2_256: + return "sha-256", nil + case multihash.SHA3_384: + return "sha3-384", nil + case multihash.SHA2_512: + return "sha-512", nil + default: + return "", fmt.Errorf("unsupported hash code (%d)", code) + } +} diff --git a/go-libp2p/p2p/transport/webrtc/sdp_test.go b/go-libp2p/p2p/transport/webrtc/sdp_test.go new file mode 100644 index 0000000..2e7ac5b --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/sdp_test.go @@ -0,0 +1,101 @@ +package libp2pwebrtc + +import ( + "encoding/hex" + "net" + "testing" + + "github.com/multiformats/go-multihash" + "github.com/stretchr/testify/require" +) + +const expectedServerSDP = `v=0 +o=- 0 0 IN IP4 0.0.0.0 +s=- +t=0 0 +a=ice-lite +m=application 37826 UDP/DTLS/SCTP webrtc-datachannel +c=IN IP4 0.0.0.0 +a=mid:0 +a=ice-options:ice2 +a=ice-ufrag:d2c0fc07-8bb3-42ae-bae2-a6fce8a0b581 +a=ice-pwd:d2c0fc07-8bb3-42ae-bae2-a6fce8a0b581 +a=fingerprint:sha-256 ba:78:16:bf:8f:01:cf:ea:41:41:40:de:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:ff:61:f2:00:15:ad + +a=setup:passive +a=sctp-port:5000 +a=max-message-size:16384 +a=candidate:1 1 UDP 1 0.0.0.0 37826 typ host +a=end-of-candidates +` + +func TestRenderServerSDP(t *testing.T) { + encoded, err := hex.DecodeString("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") + require.NoError(t, err) + + testMultihash := multihash.DecodedMultihash{ + Code: multihash.SHA2_256, + Name: multihash.Codes[multihash.SHA2_256], + Digest: encoded, + Length: len(encoded), + } + addr := &net.UDPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 37826} + ufrag := "d2c0fc07-8bb3-42ae-bae2-a6fce8a0b581" + fingerprint := testMultihash + + sdp, err := createServerSDP(addr, ufrag, fingerprint) + require.NoError(t, err) + require.Equal(t, expectedServerSDP, sdp) +} + +const expectedClientSDP = `v=0 +o=- 0 0 IN IP4 0.0.0.0 +s=- +c=IN IP4 0.0.0.0 +t=0 0 + +m=application 37826 UDP/DTLS/SCTP webrtc-datachannel +a=mid:0 +a=ice-options:ice2 +a=ice-ufrag:d2c0fc07-8bb3-42ae-bae2-a6fce8a0b581 +a=ice-pwd:d2c0fc07-8bb3-42ae-bae2-a6fce8a0b581 +a=fingerprint:sha-256 ba:78:16:bf:8f:01:cf:ea:41:41:40:de:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:ff:61:f2:00:15:ad +a=setup:actpass +a=sctp-port:5000 +a=max-message-size:16384 +` + +func TestRenderClientSDP(t *testing.T) { + addr := &net.UDPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 37826} + ufrag := "d2c0fc07-8bb3-42ae-bae2-a6fce8a0b581" + sdp := createClientSDP(addr, ufrag) + require.Equal(t, expectedClientSDP, sdp) +} + +func BenchmarkRenderClientSDP(b *testing.B) { + addr := &net.UDPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 37826} + ufrag := "d2c0fc07-8bb3-42ae-bae2-a6fce8a0b581" + + for i := 0; i < b.N; i++ { + createClientSDP(addr, ufrag) + } +} + +func BenchmarkRenderServerSDP(b *testing.B) { + encoded, _ := hex.DecodeString("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") + + testMultihash := multihash.DecodedMultihash{ + Code: multihash.SHA2_256, + Name: multihash.Codes[multihash.SHA2_256], + Digest: encoded, + Length: len(encoded), + } + addr := &net.UDPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 37826} + ufrag := "d2c0fc07-8bb3-42ae-bae2-a6fce8a0b581" + fingerprint := testMultihash + + for i := 0; i < b.N; i++ { + createServerSDP(addr, ufrag, fingerprint) + } + +} diff --git a/go-libp2p/p2p/transport/webrtc/stream.go b/go-libp2p/p2p/transport/webrtc/stream.go new file mode 100644 index 0000000..56f869f --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/stream.go @@ -0,0 +1,281 @@ +package libp2pwebrtc + +import ( + "errors" + "os" + "sync" + "time" + + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/p2p/transport/webrtc/pb" + "github.com/libp2p/go-msgio/pbio" + + "github.com/pion/datachannel" + "github.com/pion/webrtc/v3" +) + +const ( + // maxMessageSize is the maximum message size of the Protobuf message we send / receive. + maxMessageSize = 16384 + // maxSendBuffer is the maximum data we enqueue on the underlying data channel for writes. + // The underlying SCTP layer has an unbounded buffer for writes. We limit the amount enqueued + // per stream is limited to avoid a single stream monopolizing the entire connection. + maxSendBuffer = 2 * maxMessageSize + // sendBufferLowThreshold is the threshold below which we write more data on the underlying + // data channel. We want a notification as soon as we can write 1 full sized message. + sendBufferLowThreshold = maxSendBuffer - maxMessageSize + // maxTotalControlMessagesSize is the maximum total size of all control messages we will + // write on this stream. + // 4 control messages of size 10 bytes + 10 bytes buffer. This number doesn't need to be + // exact. In the worst case, we enqueue these many bytes more in the webrtc peer connection + // send queue. + maxTotalControlMessagesSize = 50 + + // Proto overhead assumption is 5 bytes + protoOverhead = 5 + // Varint overhead is assumed to be 2 bytes. This is safe since + // 1. This is only used and when writing message, and + // 2. We only send messages in chunks of `maxMessageSize - varintOverhead` + // which includes the data and the protobuf header. Since `maxMessageSize` + // is less than or equal to 2 ^ 14, the varint will not be more than + // 2 bytes in length. + varintOverhead = 2 + // maxFINACKWait is the maximum amount of time a stream will wait to read + // FIN_ACK before closing the data channel + maxFINACKWait = 10 * time.Second +) + +type receiveState uint8 + +const ( + receiveStateReceiving receiveState = iota + receiveStateDataRead // received and read the FIN + receiveStateReset // either by calling CloseRead locally, or by receiving +) + +type sendState uint8 + +const ( + sendStateSending sendState = iota + sendStateDataSent + sendStateDataReceived + sendStateReset +) + +// Package pion detached data channel into a net.Conn +// and then a network.MuxedStream +type stream struct { + mx sync.Mutex + + // readerMx ensures that only a single goroutine reads from the reader. Read is not threadsafe + // But we may need to read from reader for control messages from a different goroutine. + readerMx sync.Mutex + reader pbio.Reader + + // this buffer is limited up to a single message. Reason we need it + // is because a reader might read a message midway, and so we need a + // wait to buffer that for as long as the remaining part is not (yet) read + nextMessage *pb.Message + receiveState receiveState + + writer pbio.Writer // concurrent writes prevented by mx + writeStateChanged chan struct{} + sendState sendState + writeDeadline time.Time + + controlMessageReaderOnce sync.Once + // controlMessageReaderEndTime is the end time for reading FIN_ACK from the control + // message reader. We cannot rely on SetReadDeadline to do this since that is prone to + // race condition where a previous deadline timer fires after the latest call to + // SetReadDeadline + // See: https://github.com/pion/sctp/pull/290 + controlMessageReaderEndTime time.Time + + onDoneOnce sync.Once + onDone func() + id uint16 // for logging purposes + dataChannel *datachannel.DataChannel + closeForShutdownErr error +} + +var _ network.MuxedStream = &stream{} + +func newStream( + channel *webrtc.DataChannel, + rwc datachannel.ReadWriteCloser, + onDone func(), +) *stream { + s := &stream{ + reader: pbio.NewDelimitedReader(rwc, maxMessageSize), + writer: pbio.NewDelimitedWriter(rwc), + writeStateChanged: make(chan struct{}, 1), + id: *channel.ID(), + dataChannel: rwc.(*datachannel.DataChannel), + onDone: onDone, + } + s.dataChannel.SetBufferedAmountLowThreshold(sendBufferLowThreshold) + s.dataChannel.OnBufferedAmountLow(func() { + s.notifyWriteStateChanged() + + }) + return s +} + +func (s *stream) Close() error { + s.mx.Lock() + isClosed := s.closeForShutdownErr != nil + s.mx.Unlock() + if isClosed { + return nil + } + defer s.cleanup() + closeWriteErr := s.CloseWrite() + closeReadErr := s.CloseRead() + if closeWriteErr != nil || closeReadErr != nil { + s.Reset() + return errors.Join(closeWriteErr, closeReadErr) + } + + s.mx.Lock() + if s.controlMessageReaderEndTime.IsZero() { + s.controlMessageReaderEndTime = time.Now().Add(maxFINACKWait) + s.setDataChannelReadDeadline(time.Now().Add(-1 * time.Hour)) + } + s.mx.Unlock() + return nil +} + +func (s *stream) Reset() error { + s.mx.Lock() + isClosed := s.closeForShutdownErr != nil + s.mx.Unlock() + if isClosed { + return nil + } + + defer s.cleanup() + cancelWriteErr := s.cancelWrite() + closeReadErr := s.CloseRead() + s.setDataChannelReadDeadline(time.Now().Add(-1 * time.Hour)) + return errors.Join(closeReadErr, cancelWriteErr) +} + +func (s *stream) closeForShutdown(closeErr error) { + defer s.cleanup() + + s.mx.Lock() + defer s.mx.Unlock() + + s.closeForShutdownErr = closeErr + s.notifyWriteStateChanged() +} + +func (s *stream) SetDeadline(t time.Time) error { + _ = s.SetReadDeadline(t) + return s.SetWriteDeadline(t) +} + +// processIncomingFlag process the flag on an incoming message +// It needs to be called while the mutex is locked. +func (s *stream) processIncomingFlag(flag *pb.Message_Flag) { + if flag == nil { + return + } + + switch *flag { + case pb.Message_STOP_SENDING: + // We must process STOP_SENDING after sending a FIN(sendStateDataSent). Remote peer + // may not send a FIN_ACK once it has sent a STOP_SENDING + if s.sendState == sendStateSending || s.sendState == sendStateDataSent { + s.sendState = sendStateReset + } + s.notifyWriteStateChanged() + case pb.Message_FIN_ACK: + s.sendState = sendStateDataReceived + s.notifyWriteStateChanged() + case pb.Message_FIN: + if s.receiveState == receiveStateReceiving { + s.receiveState = receiveStateDataRead + } + if err := s.writer.WriteMsg(&pb.Message{Flag: pb.Message_FIN_ACK.Enum()}); err != nil { + log.Debugf("failed to send FIN_ACK: %s", err) + // Remote has finished writing all the data It'll stop waiting for the + // FIN_ACK eventually or will be notified when we close the datachannel + } + s.spawnControlMessageReader() + case pb.Message_RESET: + if s.receiveState == receiveStateReceiving { + s.receiveState = receiveStateReset + } + s.spawnControlMessageReader() + } +} + +// spawnControlMessageReader is used for processing control messages after the reader is closed. +func (s *stream) spawnControlMessageReader() { + s.controlMessageReaderOnce.Do(func() { + // Spawn a goroutine to ensure that we're not holding any locks + go func() { + // cleanup the sctp deadline timer goroutine + defer s.setDataChannelReadDeadline(time.Time{}) + + defer s.dataChannel.Close() + + // Unblock any Read call waiting on reader.ReadMsg + s.setDataChannelReadDeadline(time.Now().Add(-1 * time.Hour)) + + s.readerMx.Lock() + // We have the lock: any readers blocked on reader.ReadMsg have exited. + s.mx.Lock() + defer s.mx.Unlock() + // From this point onwards only this goroutine will do reader.ReadMsg. + // We just wanted to ensure any exising readers have exited. + // Read calls from this point onwards will exit immediately on checking + // s.readState + s.readerMx.Unlock() + + if s.nextMessage != nil { + s.processIncomingFlag(s.nextMessage.Flag) + s.nextMessage = nil + } + var msg pb.Message + for { + // Connection closed. No need to cleanup the data channel. + if s.closeForShutdownErr != nil { + return + } + // Write half of the stream completed. + if s.sendState == sendStateDataReceived || s.sendState == sendStateReset { + return + } + // FIN_ACK wait deadling exceeded. + if !s.controlMessageReaderEndTime.IsZero() && time.Now().After(s.controlMessageReaderEndTime) { + return + } + + s.setDataChannelReadDeadline(s.controlMessageReaderEndTime) + s.mx.Unlock() + err := s.reader.ReadMsg(&msg) + s.mx.Lock() + if err != nil { + // We have to manually manage deadline exceeded errors since pion/sctp can + // return deadline exceeded error for cancelled deadlines + // see: https://github.com/pion/sctp/pull/290/files + if errors.Is(err, os.ErrDeadlineExceeded) { + continue + } + return + } + s.processIncomingFlag(msg.Flag) + } + }() + }) +} + +func (s *stream) cleanup() { + s.onDoneOnce.Do(func() { + if s.onDone != nil { + s.onDone() + } + }) +} diff --git a/go-libp2p/p2p/transport/webrtc/stream_read.go b/go-libp2p/p2p/transport/webrtc/stream_read.go new file mode 100644 index 0000000..80d99ea --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/stream_read.go @@ -0,0 +1,113 @@ +package libp2pwebrtc + +import ( + "io" + "time" + + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/p2p/transport/webrtc/pb" +) + +func (s *stream) Read(b []byte) (int, error) { + s.readerMx.Lock() + defer s.readerMx.Unlock() + + s.mx.Lock() + defer s.mx.Unlock() + + if s.closeForShutdownErr != nil { + return 0, s.closeForShutdownErr + } + switch s.receiveState { + case receiveStateDataRead: + return 0, io.EOF + case receiveStateReset: + return 0, network.ErrReset + } + + if len(b) == 0 { + return 0, nil + } + + var read int + for { + if s.nextMessage == nil { + // load the next message + s.mx.Unlock() + var msg pb.Message + err := s.reader.ReadMsg(&msg) + s.mx.Lock() + if err != nil { + // connection was closed + if s.closeForShutdownErr != nil { + return 0, s.closeForShutdownErr + } + if err == io.EOF { + // if the channel was properly closed, return EOF + if s.receiveState == receiveStateDataRead { + return 0, io.EOF + } + // This case occurs when remote closes the datachannel without writing a FIN + // message. Some implementations discard the buffered data on closing the + // datachannel. For these implementations a stream reset will be observed as an + // abrupt closing of the datachannel. + s.receiveState = receiveStateReset + return 0, network.ErrReset + } + if s.receiveState == receiveStateReset { + return 0, network.ErrReset + } + if s.receiveState == receiveStateDataRead { + return 0, io.EOF + } + return 0, err + } + s.nextMessage = &msg + } + + if len(s.nextMessage.Message) > 0 { + n := copy(b, s.nextMessage.Message) + read += n + s.nextMessage.Message = s.nextMessage.Message[n:] + return read, nil + } + + // process flags on the message after reading all the data + s.processIncomingFlag(s.nextMessage.Flag) + s.nextMessage = nil + if s.closeForShutdownErr != nil { + return read, s.closeForShutdownErr + } + switch s.receiveState { + case receiveStateDataRead: + return read, io.EOF + case receiveStateReset: + return read, network.ErrReset + } + } +} + +func (s *stream) SetReadDeadline(t time.Time) error { + s.mx.Lock() + defer s.mx.Unlock() + if s.receiveState == receiveStateReceiving { + s.setDataChannelReadDeadline(t) + } + return nil +} + +func (s *stream) setDataChannelReadDeadline(t time.Time) error { + return s.dataChannel.SetReadDeadline(t) +} + +func (s *stream) CloseRead() error { + s.mx.Lock() + defer s.mx.Unlock() + var err error + if s.receiveState == receiveStateReceiving && s.closeForShutdownErr == nil { + err = s.writer.WriteMsg(&pb.Message{Flag: pb.Message_STOP_SENDING.Enum()}) + s.receiveState = receiveStateReset + } + s.spawnControlMessageReader() + return err +} diff --git a/go-libp2p/p2p/transport/webrtc/stream_test.go b/go-libp2p/p2p/transport/webrtc/stream_test.go new file mode 100644 index 0000000..0f57f44 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/stream_test.go @@ -0,0 +1,563 @@ +package libp2pwebrtc + +import ( + "crypto/rand" + "errors" + "io" + "os" + "sync/atomic" + "testing" + "time" + + "github.com/libp2p/go-libp2p/p2p/transport/webrtc/pb" + "github.com/libp2p/go-msgio/pbio" + "google.golang.org/protobuf/proto" + + "github.com/libp2p/go-libp2p/core/network" + + "github.com/pion/datachannel" + "github.com/pion/sctp" + "github.com/pion/webrtc/v3" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +type detachedChan struct { + rwc datachannel.ReadWriteCloser + dc *webrtc.DataChannel +} + +func getDetachedDataChannels(t *testing.T) (detachedChan, detachedChan) { + s := webrtc.SettingEngine{} + s.SetIncludeLoopbackCandidate(true) + s.DetachDataChannels() + api := webrtc.NewAPI(webrtc.WithSettingEngine(s)) + + offerPC, err := api.NewPeerConnection(webrtc.Configuration{}) + require.NoError(t, err) + t.Cleanup(func() { offerPC.Close() }) + offerRWCChan := make(chan detachedChan, 1) + offerDC, err := offerPC.CreateDataChannel("data", nil) + require.NoError(t, err) + offerDC.OnOpen(func() { + rwc, err := offerDC.Detach() + require.NoError(t, err) + offerRWCChan <- detachedChan{rwc: rwc, dc: offerDC} + }) + + answerPC, err := api.NewPeerConnection(webrtc.Configuration{}) + require.NoError(t, err) + + answerChan := make(chan detachedChan, 1) + answerPC.OnDataChannel(func(dc *webrtc.DataChannel) { + dc.OnOpen(func() { + rwc, err := dc.Detach() + require.NoError(t, err) + answerChan <- detachedChan{rwc: rwc, dc: dc} + }) + }) + t.Cleanup(func() { answerPC.Close() }) + + // Set ICE Candidate handlers. As soon as a PeerConnection has gathered a candidate send it to the other peer + answerPC.OnICECandidate(func(candidate *webrtc.ICECandidate) { + if candidate != nil { + require.NoError(t, offerPC.AddICECandidate(candidate.ToJSON())) + } + }) + offerPC.OnICECandidate(func(candidate *webrtc.ICECandidate) { + if candidate != nil { + require.NoError(t, answerPC.AddICECandidate(candidate.ToJSON())) + } + }) + + // Set the handler for Peer connection state + // This will notify you when the peer has connected/disconnected + offerPC.OnConnectionStateChange(func(s webrtc.PeerConnectionState) { + if s == webrtc.PeerConnectionStateFailed { + t.Log("peer connection failed on offerer") + } + }) + + // Set the handler for Peer connection state + // This will notify you when the peer has connected/disconnected + answerPC.OnConnectionStateChange(func(s webrtc.PeerConnectionState) { + if s == webrtc.PeerConnectionStateFailed { + t.Log("peer connection failed on answerer") + } + }) + + // Now, create an offer + offer, err := offerPC.CreateOffer(nil) + require.NoError(t, err) + require.NoError(t, answerPC.SetRemoteDescription(offer)) + require.NoError(t, offerPC.SetLocalDescription(offer)) + + answer, err := answerPC.CreateAnswer(nil) + require.NoError(t, err) + require.NoError(t, offerPC.SetRemoteDescription(answer)) + require.NoError(t, answerPC.SetLocalDescription(answer)) + + return <-answerChan, <-offerRWCChan +} + +// assertDataChannelOpen checks if the datachannel is open. +// It sends empty messages on the data channel to check if the channel is still open. +// The control message reader goroutine depends on exclusive access to datachannel.Read +// so we have to depend on Write to determine whether the channel has been closed. +func assertDataChannelOpen(t *testing.T, dc *datachannel.DataChannel) { + t.Helper() + emptyMsg := &pb.Message{} + msg, err := proto.Marshal(emptyMsg) + if err != nil { + t.Fatal("unexpected mashalling error", err) + } + for i := 0; i < 3; i++ { + _, err := dc.Write(msg) + if err != nil { + t.Fatal("unexpected write err: ", err) + } + time.Sleep(50 * time.Millisecond) + } +} + +// assertDataChannelClosed checks if the datachannel is closed. +// It sends empty messages on the data channel to check if the channel has been closed. +// The control message reader goroutine depends on exclusive access to datachannel.Read +// so we have to depend on Write to determine whether the channel has been closed. +func assertDataChannelClosed(t *testing.T, dc *datachannel.DataChannel) { + t.Helper() + emptyMsg := &pb.Message{} + msg, err := proto.Marshal(emptyMsg) + if err != nil { + t.Fatal("unexpected mashalling error", err) + } + for i := 0; i < 5; i++ { + _, err := dc.Write(msg) + if err != nil { + if errors.Is(err, sctp.ErrStreamClosed) { + return + } else { + t.Fatal("unexpected write err: ", err) + } + } + time.Sleep(50 * time.Millisecond) + } +} + +func TestStreamSimpleReadWriteClose(t *testing.T) { + client, server := getDetachedDataChannels(t) + + var clientDone, serverDone atomic.Bool + clientStr := newStream(client.dc, client.rwc, func() { clientDone.Store(true) }) + serverStr := newStream(server.dc, server.rwc, func() { serverDone.Store(true) }) + + // send a foobar from the client + n, err := clientStr.Write([]byte("foobar")) + require.NoError(t, err) + require.Equal(t, 6, n) + require.NoError(t, clientStr.CloseWrite()) + // writing after closing should error + _, err = clientStr.Write([]byte("foobar")) + require.Error(t, err) + require.False(t, clientDone.Load()) + + // now read all the data on the server side + b, err := io.ReadAll(serverStr) + require.NoError(t, err) + require.Equal(t, []byte("foobar"), b) + // reading again should give another io.EOF + n, err = serverStr.Read(make([]byte, 10)) + require.Zero(t, n) + require.ErrorIs(t, err, io.EOF) + require.False(t, serverDone.Load()) + + // send something back + _, err = serverStr.Write([]byte("lorem ipsum")) + require.NoError(t, err) + require.NoError(t, serverStr.CloseWrite()) + + // and read it at the client + require.False(t, clientDone.Load()) + b, err = io.ReadAll(clientStr) + require.NoError(t, err) + require.Equal(t, []byte("lorem ipsum"), b) + + // stream is only cleaned up on calling Close or Reset + clientStr.Close() + serverStr.Close() + require.Eventually(t, func() bool { return clientDone.Load() }, 5*time.Second, 100*time.Millisecond) + // Need to call Close for cleanup. Otherwise the FIN_ACK is never read + require.NoError(t, serverStr.Close()) + require.Eventually(t, func() bool { return serverDone.Load() }, 5*time.Second, 100*time.Millisecond) +} + +func TestStreamPartialReads(t *testing.T) { + client, server := getDetachedDataChannels(t) + + clientStr := newStream(client.dc, client.rwc, func() {}) + serverStr := newStream(server.dc, server.rwc, func() {}) + + _, err := serverStr.Write([]byte("foobar")) + require.NoError(t, err) + require.NoError(t, serverStr.CloseWrite()) + + n, err := clientStr.Read([]byte{}) // empty read + require.NoError(t, err) + require.Zero(t, n) + b := make([]byte, 3) + n, err = clientStr.Read(b) + require.Equal(t, 3, n) + require.NoError(t, err) + require.Equal(t, []byte("foo"), b) + b, err = io.ReadAll(clientStr) + require.NoError(t, err) + require.Equal(t, []byte("bar"), b) +} + +func TestStreamSkipEmptyFrames(t *testing.T) { + client, server := getDetachedDataChannels(t) + + clientStr := newStream(client.dc, client.rwc, func() {}) + serverStr := newStream(server.dc, server.rwc, func() {}) + + for i := 0; i < 10; i++ { + require.NoError(t, serverStr.writer.WriteMsg(&pb.Message{})) + } + require.NoError(t, serverStr.writer.WriteMsg(&pb.Message{Message: []byte("foo")})) + for i := 0; i < 10; i++ { + require.NoError(t, serverStr.writer.WriteMsg(&pb.Message{})) + } + require.NoError(t, serverStr.writer.WriteMsg(&pb.Message{Message: []byte("bar")})) + for i := 0; i < 10; i++ { + require.NoError(t, serverStr.writer.WriteMsg(&pb.Message{})) + } + require.NoError(t, serverStr.writer.WriteMsg(&pb.Message{Flag: pb.Message_FIN.Enum()})) + + var read []byte + var count int + for i := 0; i < 100; i++ { + b := make([]byte, 10) + count++ + n, err := clientStr.Read(b) + read = append(read, b[:n]...) + if err == io.EOF { + break + } + require.NoError(t, err) + } + require.LessOrEqual(t, count, 3, "should've taken a maximum of 3 reads") + require.Equal(t, []byte("foobar"), read) +} + +func TestStreamReadReturnsOnClose(t *testing.T) { + client, _ := getDetachedDataChannels(t) + + clientStr := newStream(client.dc, client.rwc, func() {}) + errChan := make(chan error, 1) + go func() { + _, err := clientStr.Read([]byte{0}) + errChan <- err + }() + time.Sleep(100 * time.Millisecond) // give the Read call some time to hit the loop + require.NoError(t, clientStr.Close()) + select { + case err := <-errChan: + require.ErrorIs(t, err, network.ErrReset) + case <-time.After(500 * time.Millisecond): + t.Fatal("timeout") + } + + _, err := clientStr.Read([]byte{0}) + require.ErrorIs(t, err, network.ErrReset) +} + +func TestStreamResets(t *testing.T) { + client, server := getDetachedDataChannels(t) + + var clientDone, serverDone atomic.Bool + clientStr := newStream(client.dc, client.rwc, func() { clientDone.Store(true) }) + serverStr := newStream(server.dc, server.rwc, func() { serverDone.Store(true) }) + + // send a foobar from the client + _, err := clientStr.Write([]byte("foobar")) + require.NoError(t, err) + _, err = serverStr.Write([]byte("lorem ipsum")) + require.NoError(t, err) + require.NoError(t, clientStr.Reset()) // resetting resets both directions + require.True(t, clientDone.Load()) + // attempting to write more data should result in a reset error + _, err = clientStr.Write([]byte("foobar")) + require.ErrorIs(t, err, network.ErrReset) + // read what the server sent + b, err := io.ReadAll(clientStr) + require.Empty(t, b) + require.ErrorIs(t, err, network.ErrReset) + + // read the data on the server side + require.False(t, serverDone.Load()) + b, err = io.ReadAll(serverStr) + require.Equal(t, []byte("foobar"), b) + require.ErrorIs(t, err, network.ErrReset) + require.Eventually(t, func() bool { + _, err := serverStr.Write([]byte("foobar")) + return errors.Is(err, network.ErrReset) + }, time.Second, 50*time.Millisecond) + serverStr.Close() + require.Eventually(t, func() bool { + return serverDone.Load() + }, time.Second, 50*time.Millisecond) +} + +func TestStreamReadDeadlineAsync(t *testing.T) { + client, server := getDetachedDataChannels(t) + + clientStr := newStream(client.dc, client.rwc, func() {}) + serverStr := newStream(server.dc, server.rwc, func() {}) + + timeout := 100 * time.Millisecond + if os.Getenv("CI") != "" { + timeout *= 5 + } + start := time.Now() + clientStr.SetReadDeadline(start.Add(timeout)) + _, err := clientStr.Read([]byte{0}) + require.ErrorIs(t, err, os.ErrDeadlineExceeded) + took := time.Since(start) + require.GreaterOrEqual(t, took, timeout) + require.LessOrEqual(t, took, timeout*3/2) + // repeated calls should return immediately + start = time.Now() + _, err = clientStr.Read([]byte{0}) + require.ErrorIs(t, err, os.ErrDeadlineExceeded) + require.LessOrEqual(t, time.Since(start), timeout/3) + // clear the deadline + clientStr.SetReadDeadline(time.Time{}) + _, err = serverStr.Write([]byte("foobar")) + require.NoError(t, err) + _, err = clientStr.Read([]byte{0}) + require.NoError(t, err) + require.LessOrEqual(t, time.Since(start), timeout/3) +} + +func TestStreamWriteDeadlineAsync(t *testing.T) { + client, server := getDetachedDataChannels(t) + + clientStr := newStream(client.dc, client.rwc, func() {}) + serverStr := newStream(server.dc, server.rwc, func() {}) + _ = serverStr + + b := make([]byte, 1024) + rand.Read(b) + start := time.Now() + timeout := 100 * time.Millisecond + if os.Getenv("CI") != "" { + timeout *= 5 + } + clientStr.SetWriteDeadline(start.Add(timeout)) + var hitDeadline bool + for i := 0; i < 2000; i++ { + if _, err := clientStr.Write(b); err != nil { + t.Logf("wrote %d kB", i) + require.ErrorIs(t, err, os.ErrDeadlineExceeded) + hitDeadline = true + break + } + } + require.True(t, hitDeadline) + took := time.Since(start) + require.GreaterOrEqual(t, took, timeout) + require.LessOrEqual(t, took, timeout*3/2) +} + +func TestStreamReadAfterClose(t *testing.T) { + client, server := getDetachedDataChannels(t) + + clientStr := newStream(client.dc, client.rwc, func() {}) + serverStr := newStream(server.dc, server.rwc, func() {}) + + serverStr.Close() + b := make([]byte, 1) + _, err := clientStr.Read(b) + require.Equal(t, io.EOF, err) + _, err = clientStr.Read(nil) + require.Equal(t, io.EOF, err) + + client, server = getDetachedDataChannels(t) + + clientStr = newStream(client.dc, client.rwc, func() {}) + serverStr = newStream(server.dc, server.rwc, func() {}) + + serverStr.Reset() + b = make([]byte, 1) + _, err = clientStr.Read(b) + require.ErrorIs(t, err, network.ErrReset) + _, err = clientStr.Read(nil) + require.ErrorIs(t, err, network.ErrReset) +} + +func TestStreamCloseAfterFINACK(t *testing.T) { + client, server := getDetachedDataChannels(t) + + done := make(chan bool, 1) + clientStr := newStream(client.dc, client.rwc, func() { done <- true }) + serverStr := newStream(server.dc, server.rwc, func() {}) + + go func() { + err := clientStr.Close() + assert.NoError(t, err) + }() + + select { + case <-done: + case <-time.After(200 * time.Millisecond): + t.Fatalf("Close should signal OnDone immediately") + } + + // Reading FIN_ACK on server should trigger data channel close on the client + b := make([]byte, 1) + _, err := serverStr.Read(b) + require.Error(t, err) + require.ErrorIs(t, err, io.EOF) + assertDataChannelClosed(t, client.rwc.(*datachannel.DataChannel)) +} + +// TestStreamFinAckAfterStopSending tests that FIN_ACK is sent even after the write half +// of the stream is closed. +func TestStreamFinAckAfterStopSending(t *testing.T) { + client, server := getDetachedDataChannels(t) + + done := make(chan bool, 1) + clientStr := newStream(client.dc, client.rwc, func() { done <- true }) + serverStr := newStream(server.dc, server.rwc, func() {}) + + go func() { + clientStr.CloseRead() + clientStr.Write([]byte("hello world")) + done <- true + err := clientStr.Close() + assert.NoError(t, err) + }() + <-done + + select { + case <-done: + case <-time.After(500 * time.Millisecond): + t.Errorf("Close should signal onDone immediately") + } + + // serverStr has write half closed and read half open + // serverStr should still send FIN_ACK + b := make([]byte, 24) + _, err := serverStr.Read(b) + require.NoError(t, err) + serverStr.Close() // Sends stop_sending, fin + assertDataChannelClosed(t, server.rwc.(*datachannel.DataChannel)) + assertDataChannelClosed(t, client.rwc.(*datachannel.DataChannel)) +} + +func TestStreamConcurrentClose(t *testing.T) { + client, server := getDetachedDataChannels(t) + + start := make(chan bool, 2) + done := make(chan bool, 2) + clientStr := newStream(client.dc, client.rwc, func() { done <- true }) + serverStr := newStream(server.dc, server.rwc, func() { done <- true }) + + go func() { + start <- true + clientStr.Close() + }() + go func() { + start <- true + serverStr.Close() + }() + <-start + <-start + + select { + case <-done: + case <-time.After(2 * time.Second): + t.Fatalf("concurrent close should succeed quickly") + } + select { + case <-done: + case <-time.After(2 * time.Second): + t.Fatalf("concurrent close should succeed quickly") + } + + // Wait for FIN_ACK AND datachannel close + assertDataChannelClosed(t, client.rwc.(*datachannel.DataChannel)) + assertDataChannelClosed(t, server.rwc.(*datachannel.DataChannel)) + +} + +func TestStreamResetAfterClose(t *testing.T) { + client, server := getDetachedDataChannels(t) + + done := make(chan bool, 2) + clientStr := newStream(client.dc, client.rwc, func() { done <- true }) + clientStr.Close() + + select { + case <-done: + case <-time.After(500 * time.Millisecond): + t.Fatalf("Close should run cleanup immediately") + } + // The server data channel should still be open + assertDataChannelOpen(t, server.rwc.(*datachannel.DataChannel)) + clientStr.Reset() + // Reset closes the datachannels + assertDataChannelClosed(t, server.rwc.(*datachannel.DataChannel)) + assertDataChannelClosed(t, client.rwc.(*datachannel.DataChannel)) + select { + case <-done: + t.Fatalf("onDone should not be called twice") + case <-time.After(50 * time.Millisecond): + } +} + +func TestStreamDataChannelCloseOnFINACK(t *testing.T) { + client, server := getDetachedDataChannels(t) + + done := make(chan bool, 1) + clientStr := newStream(client.dc, client.rwc, func() { done <- true }) + + clientStr.Close() + + select { + case <-time.After(500 * time.Millisecond): + t.Fatalf("Close should run cleanup immediately") + case <-done: + } + + // sending FIN_ACK closes the datachannel + serverWriter := pbio.NewDelimitedWriter(server.rwc) + err := serverWriter.WriteMsg(&pb.Message{Flag: pb.Message_FIN_ACK.Enum()}) + require.NoError(t, err) + + assertDataChannelClosed(t, server.rwc.(*datachannel.DataChannel)) + assertDataChannelClosed(t, client.rwc.(*datachannel.DataChannel)) +} + +func TestStreamChunking(t *testing.T) { + client, server := getDetachedDataChannels(t) + + clientStr := newStream(client.dc, client.rwc, func() {}) + serverStr := newStream(server.dc, server.rwc, func() {}) + + const N = (16 << 10) + 1000 + go func() { + data := make([]byte, N) + _, err := clientStr.Write(data) + require.NoError(t, err) + }() + + data := make([]byte, N) + n, err := serverStr.Read(data) + require.NoError(t, err) + require.LessOrEqual(t, n, 16<<10) + + nn, err := serverStr.Read(data) + require.NoError(t, err) + require.Equal(t, nn+n, N) +} diff --git a/go-libp2p/p2p/transport/webrtc/stream_write.go b/go-libp2p/p2p/transport/webrtc/stream_write.go new file mode 100644 index 0000000..534a8d8 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/stream_write.go @@ -0,0 +1,157 @@ +package libp2pwebrtc + +import ( + "errors" + "os" + "time" + + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/p2p/transport/webrtc/pb" +) + +var errWriteAfterClose = errors.New("write after close") + +// If we have less space than minMessageSize, we don't put a new message on the data channel. +// Instead, we wait until more space opens up. +const minMessageSize = 1 << 10 + +func (s *stream) Write(b []byte) (int, error) { + s.mx.Lock() + defer s.mx.Unlock() + + if s.closeForShutdownErr != nil { + return 0, s.closeForShutdownErr + } + switch s.sendState { + case sendStateReset: + return 0, network.ErrReset + case sendStateDataSent, sendStateDataReceived: + return 0, errWriteAfterClose + } + + if !s.writeDeadline.IsZero() && time.Now().After(s.writeDeadline) { + return 0, os.ErrDeadlineExceeded + } + + var writeDeadlineTimer *time.Timer + defer func() { + if writeDeadlineTimer != nil { + writeDeadlineTimer.Stop() + } + }() + + var n int + var msg pb.Message + for len(b) > 0 { + if s.closeForShutdownErr != nil { + return n, s.closeForShutdownErr + } + switch s.sendState { + case sendStateReset: + return n, network.ErrReset + case sendStateDataSent, sendStateDataReceived: + return n, errWriteAfterClose + } + + writeDeadline := s.writeDeadline + // deadline deleted, stop and remove the timer + if writeDeadline.IsZero() && writeDeadlineTimer != nil { + writeDeadlineTimer.Stop() + writeDeadlineTimer = nil + } + var writeDeadlineChan <-chan time.Time + if !writeDeadline.IsZero() { + if writeDeadlineTimer == nil { + writeDeadlineTimer = time.NewTimer(time.Until(writeDeadline)) + } else { + if !writeDeadlineTimer.Stop() { + <-writeDeadlineTimer.C + } + writeDeadlineTimer.Reset(time.Until(writeDeadline)) + } + writeDeadlineChan = writeDeadlineTimer.C + } + + availableSpace := s.availableSendSpace() + if availableSpace < minMessageSize { + s.mx.Unlock() + select { + case <-writeDeadlineChan: + s.mx.Lock() + return n, os.ErrDeadlineExceeded + case <-s.writeStateChanged: + } + s.mx.Lock() + continue + } + end := maxMessageSize + if end > availableSpace { + end = availableSpace + } + end -= protoOverhead + varintOverhead + if end > len(b) { + end = len(b) + } + msg = pb.Message{Message: b[:end]} + if err := s.writer.WriteMsg(&msg); err != nil { + return n, err + } + n += end + b = b[end:] + } + return n, nil +} + +func (s *stream) SetWriteDeadline(t time.Time) error { + s.mx.Lock() + defer s.mx.Unlock() + s.writeDeadline = t + s.notifyWriteStateChanged() + return nil +} + +func (s *stream) availableSendSpace() int { + buffered := int(s.dataChannel.BufferedAmount()) + availableSpace := maxSendBuffer - buffered + if availableSpace+maxTotalControlMessagesSize < 0 { // this should never happen, but better check + log.Errorw("data channel buffered more data than the maximum amount", "max", maxSendBuffer, "buffered", buffered) + } + return availableSpace +} + +func (s *stream) cancelWrite() error { + s.mx.Lock() + defer s.mx.Unlock() + + // There's no need to reset the write half if the write half has been closed + // successfully or has been reset previously + if s.sendState == sendStateDataReceived || s.sendState == sendStateReset { + return nil + } + s.sendState = sendStateReset + // Remove reference to this stream from data channel + s.dataChannel.OnBufferedAmountLow(nil) + s.notifyWriteStateChanged() + return s.writer.WriteMsg(&pb.Message{Flag: pb.Message_RESET.Enum()}) +} + +func (s *stream) CloseWrite() error { + s.mx.Lock() + defer s.mx.Unlock() + + if s.sendState != sendStateSending { + return nil + } + s.sendState = sendStateDataSent + // Remove reference to this stream from data channel + s.dataChannel.OnBufferedAmountLow(nil) + s.notifyWriteStateChanged() + return s.writer.WriteMsg(&pb.Message{Flag: pb.Message_FIN.Enum()}) +} + +func (s *stream) notifyWriteStateChanged() { + select { + case s.writeStateChanged <- struct{}{}: + default: + } +} diff --git a/go-libp2p/p2p/transport/webrtc/transport.go b/go-libp2p/p2p/transport/webrtc/transport.go new file mode 100644 index 0000000..b04753e --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/transport.go @@ -0,0 +1,651 @@ +// Package libp2pwebrtc implements the WebRTC transport for go-libp2p, +// as described in https://github.com/libp2p/specs/tree/master/webrtc. +// +// At this point, this package is EXPERIMENTAL, and the WebRTC transport is not enabled by default. +// While we're fairly confident that the implementation correctly implements the specification, +// we're not making any guarantees regarding its security (especially regarding resource exhaustion attacks). +// Fixes, even for security-related issues, will be conducted in the open. +// +// Experimentation is encouraged. Please open an issue if you encounter any problems with this transport. +// +// The udpmux subpackage contains the logic for multiplexing multiple WebRTC (ICE) +// connections over a single UDP socket. +package libp2pwebrtc + +import ( + "context" + "crypto" + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "crypto/x509" + "encoding/binary" + "errors" + "fmt" + "net" + "time" + + mrand "golang.org/x/exp/rand" + "google.golang.org/protobuf/proto" + + "github.com/libp2p/go-libp2p/core/connmgr" + ic "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/pnet" + "github.com/libp2p/go-libp2p/core/sec" + tpt "github.com/libp2p/go-libp2p/core/transport" + "github.com/libp2p/go-libp2p/p2p/security/noise" + "github.com/libp2p/go-libp2p/p2p/transport/webrtc/pb" + "github.com/libp2p/go-msgio" + + ma "github.com/multiformats/go-multiaddr" + manet "github.com/multiformats/go-multiaddr/net" + "github.com/multiformats/go-multihash" + + "github.com/pion/datachannel" + "github.com/pion/webrtc/v3" +) + +var webrtcComponent *ma.Component + +func init() { + var err error + webrtcComponent, err = ma.NewComponent(ma.ProtocolWithCode(ma.P_WEBRTC_DIRECT).Name, "") + if err != nil { + log.Fatal(err) + } +} + +const ( + // handshakeChannelNegotiated is used to specify that the + // handshake data channel does not need negotiation via DCEP. + // A constant is used since the `DataChannelInit` struct takes + // references instead of values. + handshakeChannelNegotiated = true + // handshakeChannelID is the agreed ID for the handshake data + // channel. A constant is used since the `DataChannelInit` struct takes + // references instead of values. We specify the type here as this + // value is only ever copied and passed by reference + handshakeChannelID = uint16(0) +) + +// timeout values for the peerconnection +// https://github.com/pion/webrtc/blob/v3.1.50/settingengine.go#L102-L109 +const ( + DefaultDisconnectedTimeout = 20 * time.Second + DefaultFailedTimeout = 30 * time.Second + DefaultKeepaliveTimeout = 15 * time.Second + + sctpReceiveBufferSize = 100_000 +) + +type WebRTCTransport struct { + webrtcConfig webrtc.Configuration + rcmgr network.ResourceManager + gater connmgr.ConnectionGater + privKey ic.PrivKey + noiseTpt *noise.Transport + localPeerId peer.ID + + // timeouts + peerConnectionTimeouts iceTimeouts + + // in-flight connections + maxInFlightConnections uint32 +} + +var _ tpt.Transport = &WebRTCTransport{} + +type Option func(*WebRTCTransport) error + +type iceTimeouts struct { + Disconnect time.Duration + Failed time.Duration + Keepalive time.Duration +} + +func New(privKey ic.PrivKey, psk pnet.PSK, gater connmgr.ConnectionGater, rcmgr network.ResourceManager, opts ...Option) (*WebRTCTransport, error) { + if psk != nil { + log.Error("WebRTC doesn't support private networks yet.") + return nil, fmt.Errorf("WebRTC doesn't support private networks yet") + } + if rcmgr == nil { + rcmgr = &network.NullResourceManager{} + } + localPeerID, err := peer.IDFromPrivateKey(privKey) + if err != nil { + return nil, fmt.Errorf("get local peer ID: %w", err) + } + // We use elliptic P-256 since it is widely supported by browsers. + // + // Implementation note: Testing with the browser, + // it seems like Chromium only supports ECDSA P-256 or RSA key signatures in the webrtc TLS certificate. + // We tried using P-228 and P-384 which caused the DTLS handshake to fail with Illegal Parameter + // + // Please refer to this is a list of suggested algorithms for the WebCrypto API. + // The algorithm for generating a certificate for an RTCPeerConnection + // must adhere to the WebCrpyto API. From my observation, + // RSA and ECDSA P-256 is supported on almost all browsers. + // Ed25519 is not present on the list. + pk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + return nil, fmt.Errorf("generate key for cert: %w", err) + } + cert, err := webrtc.GenerateCertificate(pk) + if err != nil { + return nil, fmt.Errorf("generate certificate: %w", err) + } + config := webrtc.Configuration{ + Certificates: []webrtc.Certificate{*cert}, + } + noiseTpt, err := noise.New(noise.ID, privKey, nil) + if err != nil { + return nil, fmt.Errorf("unable to create noise transport: %w", err) + } + transport := &WebRTCTransport{ + rcmgr: rcmgr, + gater: gater, + webrtcConfig: config, + privKey: privKey, + noiseTpt: noiseTpt, + localPeerId: localPeerID, + + peerConnectionTimeouts: iceTimeouts{ + Disconnect: DefaultDisconnectedTimeout, + Failed: DefaultFailedTimeout, + Keepalive: DefaultKeepaliveTimeout, + }, + + maxInFlightConnections: DefaultMaxInFlightConnections, + } + for _, opt := range opts { + if err := opt(transport); err != nil { + return nil, err + } + } + return transport, nil +} + +func (t *WebRTCTransport) Protocols() []int { + return []int{ma.P_WEBRTC_DIRECT} +} + +func (t *WebRTCTransport) Proxy() bool { + return false +} + +func (t *WebRTCTransport) CanDial(addr ma.Multiaddr) bool { + isValid, n := IsWebRTCDirectMultiaddr(addr) + return isValid && n > 0 +} + +// Listen returns a listener for addr. +// +// The IP, Port combination for addr must be exclusive to this listener as a WebRTC listener cannot +// be multiplexed on the same port as other UDP based transports like QUIC and WebTransport. +// See https://github.com/libp2p/go-libp2p/issues/2446 for details. +func (t *WebRTCTransport) Listen(addr ma.Multiaddr) (tpt.Listener, error) { + addr, wrtcComponent := ma.SplitLast(addr) + isWebrtc := wrtcComponent.Equal(webrtcComponent) + if !isWebrtc { + return nil, fmt.Errorf("must listen on webrtc multiaddr") + } + nw, host, err := manet.DialArgs(addr) + if err != nil { + return nil, fmt.Errorf("listener could not fetch dialargs: %w", err) + } + udpAddr, err := net.ResolveUDPAddr(nw, host) + if err != nil { + return nil, fmt.Errorf("listener could not resolve udp address: %w", err) + } + + socket, err := net.ListenUDP(nw, udpAddr) + if err != nil { + return nil, fmt.Errorf("listen on udp: %w", err) + } + + listener, err := t.listenSocket(socket) + if err != nil { + socket.Close() + return nil, err + } + return listener, nil +} + +func (t *WebRTCTransport) listenSocket(socket *net.UDPConn) (tpt.Listener, error) { + listenerMultiaddr, err := manet.FromNetAddr(socket.LocalAddr()) + if err != nil { + return nil, err + } + + listenerFingerprint, err := t.getCertificateFingerprint() + if err != nil { + return nil, err + } + + encodedLocalFingerprint, err := encodeDTLSFingerprint(listenerFingerprint) + if err != nil { + return nil, err + } + + certComp, err := ma.NewComponent(ma.ProtocolWithCode(ma.P_CERTHASH).Name, encodedLocalFingerprint) + if err != nil { + return nil, err + } + listenerMultiaddr = listenerMultiaddr.Encapsulate(webrtcComponent).Encapsulate(certComp) + + return newListener( + t, + listenerMultiaddr, + socket, + t.webrtcConfig, + ) +} + +func (t *WebRTCTransport) Dial(ctx context.Context, remoteMultiaddr ma.Multiaddr, p peer.ID) (tpt.CapableConn, error) { + scope, err := t.rcmgr.OpenConnection(network.DirOutbound, false, remoteMultiaddr) + if err != nil { + return nil, err + } + if err := scope.SetPeer(p); err != nil { + scope.Done() + return nil, err + } + conn, err := t.dial(ctx, scope, remoteMultiaddr, p) + if err != nil { + scope.Done() + return nil, err + } + return conn, nil +} + +func (t *WebRTCTransport) dial(ctx context.Context, scope network.ConnManagementScope, remoteMultiaddr ma.Multiaddr, p peer.ID) (tConn tpt.CapableConn, err error) { + var w webRTCConnection + defer func() { + if err != nil { + if w.PeerConnection != nil { + _ = w.PeerConnection.Close() + } + if tConn != nil { + _ = tConn.Close() + } + } + }() + + remoteMultihash, err := decodeRemoteFingerprint(remoteMultiaddr) + if err != nil { + return nil, fmt.Errorf("decode fingerprint: %w", err) + } + remoteHashFunction, ok := getSupportedSDPHash(remoteMultihash.Code) + if !ok { + return nil, fmt.Errorf("unsupported hash function: %w", nil) + } + + rnw, rhost, err := manet.DialArgs(remoteMultiaddr) + if err != nil { + return nil, fmt.Errorf("generate dial args: %w", err) + } + + raddr, err := net.ResolveUDPAddr(rnw, rhost) + if err != nil { + return nil, fmt.Errorf("resolve udp address: %w", err) + } + + // Instead of encoding the local fingerprint we + // generate a random UUID as the connection ufrag. + // The only requirement here is that the ufrag and password + // must be equal, which will allow the server to determine + // the password using the STUN message. + ufrag := genUfrag() + + settingEngine := webrtc.SettingEngine{ + LoggerFactory: pionLoggerFactory, + } + settingEngine.SetICECredentials(ufrag, ufrag) + settingEngine.DetachDataChannels() + // use the first best address candidate + settingEngine.SetPrflxAcceptanceMinWait(0) + settingEngine.SetICETimeouts( + t.peerConnectionTimeouts.Disconnect, + t.peerConnectionTimeouts.Failed, + t.peerConnectionTimeouts.Keepalive, + ) + // By default, webrtc will not collect candidates on the loopback address. + // This is disallowed in the ICE specification. However, implementations + // do not strictly follow this, for eg. Chrome gathers TCP loopback candidates. + // If you run pion on a system with only the loopback interface UP, + // it will not connect to anything. + settingEngine.SetIncludeLoopbackCandidate(true) + settingEngine.SetSCTPMaxReceiveBufferSize(sctpReceiveBufferSize) + if err := scope.ReserveMemory(sctpReceiveBufferSize, network.ReservationPriorityMedium); err != nil { + return nil, err + } + + w, err = newWebRTCConnection(settingEngine, t.webrtcConfig) + if err != nil { + return nil, fmt.Errorf("instantiating peer connection failed: %w", err) + } + + errC := addOnConnectionStateChangeCallback(w.PeerConnection) + + // do offer-answer exchange + offer, err := w.PeerConnection.CreateOffer(nil) + if err != nil { + return nil, fmt.Errorf("create offer: %w", err) + } + + err = w.PeerConnection.SetLocalDescription(offer) + if err != nil { + return nil, fmt.Errorf("set local description: %w", err) + } + + answerSDPString, err := createServerSDP(raddr, ufrag, *remoteMultihash) + if err != nil { + return nil, fmt.Errorf("render server SDP: %w", err) + } + + answer := webrtc.SessionDescription{SDP: answerSDPString, Type: webrtc.SDPTypeAnswer} + err = w.PeerConnection.SetRemoteDescription(answer) + if err != nil { + return nil, fmt.Errorf("set remote description: %w", err) + } + + // await peerconnection opening + select { + case err := <-errC: + if err != nil { + return nil, err + } + case <-ctx.Done(): + return nil, errors.New("peerconnection opening timed out") + } + + // We are connected, run the noise handshake + detached, err := detachHandshakeDataChannel(ctx, w.HandshakeDataChannel) + if err != nil { + return nil, err + } + channel := newStream(w.HandshakeDataChannel, detached, func() {}) + + remotePubKey, err := t.noiseHandshake(ctx, w.PeerConnection, channel, p, remoteHashFunction, false) + if err != nil { + return nil, err + } + + // Setup local and remote address for the connection + cp, err := w.HandshakeDataChannel.Transport().Transport().ICETransport().GetSelectedCandidatePair() + if cp == nil { + return nil, errors.New("ice connection did not have selected candidate pair: nil result") + } + if err != nil { + return nil, fmt.Errorf("ice connection did not have selected candidate pair: error: %w", err) + } + // the local address of the selected candidate pair should be the local address for the connection + localAddr, err := manet.FromNetAddr(&net.UDPAddr{IP: net.ParseIP(cp.Local.Address), Port: int(cp.Local.Port)}) + if err != nil { + return nil, err + } + remoteMultiaddrWithoutCerthash, _ := ma.SplitFunc(remoteMultiaddr, func(c ma.Component) bool { return c.Protocol().Code == ma.P_CERTHASH }) + + conn, err := newConnection( + network.DirOutbound, + w.PeerConnection, + t, + scope, + t.localPeerId, + localAddr, + p, + remotePubKey, + remoteMultiaddrWithoutCerthash, + w.IncomingDataChannels, + ) + if err != nil { + return nil, err + } + + if t.gater != nil && !t.gater.InterceptSecured(network.DirOutbound, p, conn) { + return nil, fmt.Errorf("secured connection gated") + } + return conn, nil +} + +func genUfrag() string { + const ( + uFragAlphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" + uFragPrefix = "libp2p+webrtc+v1/" + uFragIdLength = 32 + uFragIdOffset = len(uFragPrefix) + uFragLength = uFragIdOffset + uFragIdLength + ) + + seed := [8]byte{} + rand.Read(seed[:]) + r := mrand.New(mrand.NewSource(binary.BigEndian.Uint64(seed[:]))) + b := make([]byte, uFragLength) + for i := uFragIdOffset; i < uFragLength; i++ { + b[i] = uFragAlphabet[r.Intn(len(uFragAlphabet))] + } + return string(b) +} + +func (t *WebRTCTransport) getCertificateFingerprint() (webrtc.DTLSFingerprint, error) { + fps, err := t.webrtcConfig.Certificates[0].GetFingerprints() + if err != nil { + return webrtc.DTLSFingerprint{}, err + } + return fps[0], nil +} + +func (t *WebRTCTransport) generateNoisePrologue(pc *webrtc.PeerConnection, hash crypto.Hash, inbound bool) ([]byte, error) { + raw := pc.SCTP().Transport().GetRemoteCertificate() + cert, err := x509.ParseCertificate(raw) + if err != nil { + return nil, err + } + + // NOTE: should we want we can fork the cert code as well to avoid + // all the extra allocations due to unneeded string interspersing (hex) + localFp, err := t.getCertificateFingerprint() + if err != nil { + return nil, err + } + + remoteFpBytes, err := parseFingerprint(cert, hash) + if err != nil { + return nil, err + } + + localFpBytes, err := decodeInterspersedHexFromASCIIString(localFp.Value) + if err != nil { + return nil, err + } + + localEncoded, err := multihash.Encode(localFpBytes, multihash.SHA2_256) + if err != nil { + log.Debugf("could not encode multihash for local fingerprint") + return nil, err + } + remoteEncoded, err := multihash.Encode(remoteFpBytes, multihash.SHA2_256) + if err != nil { + log.Debugf("could not encode multihash for remote fingerprint") + return nil, err + } + + result := []byte("libp2p-webrtc-noise:") + if inbound { + result = append(result, remoteEncoded...) + result = append(result, localEncoded...) + } else { + result = append(result, localEncoded...) + result = append(result, remoteEncoded...) + } + return result, nil +} + +func (t *WebRTCTransport) noiseHandshake(ctx context.Context, pc *webrtc.PeerConnection, s *stream, peer peer.ID, hash crypto.Hash, inbound bool) (ic.PubKey, error) { + prologue, err := t.generateNoisePrologue(pc, hash, inbound) + if err != nil { + return nil, fmt.Errorf("generate prologue: %w", err) + } + opts := make([]noise.SessionOption, 0, 2) + opts = append(opts, noise.Prologue(prologue)) + if peer == "" { + opts = append(opts, noise.DisablePeerIDCheck()) + } + sessionTransport, err := t.noiseTpt.WithSessionOptions(opts...) + if err != nil { + return nil, fmt.Errorf("failed to instantiate Noise transport: %w", err) + } + var secureConn sec.SecureConn + if inbound { + secureConn, err = sessionTransport.SecureOutbound(ctx, netConnWrapper{s}, peer) + if err != nil { + return nil, fmt.Errorf("failed to secure inbound connection: %w", err) + } + } else { + secureConn, err = sessionTransport.SecureInbound(ctx, netConnWrapper{s}, peer) + if err != nil { + return nil, fmt.Errorf("failed to secure outbound connection: %w", err) + } + } + return secureConn.RemotePublicKey(), nil +} + +func (t *WebRTCTransport) AddCertHashes(addr ma.Multiaddr) (ma.Multiaddr, bool) { + listenerFingerprint, err := t.getCertificateFingerprint() + if err != nil { + return nil, false + } + + encodedLocalFingerprint, err := encodeDTLSFingerprint(listenerFingerprint) + if err != nil { + return nil, false + } + + certComp, err := ma.NewComponent(ma.ProtocolWithCode(ma.P_CERTHASH).Name, encodedLocalFingerprint) + if err != nil { + return nil, false + } + return addr.Encapsulate(certComp), true +} + +type netConnWrapper struct { + *stream +} + +func (netConnWrapper) LocalAddr() net.Addr { return nil } +func (netConnWrapper) RemoteAddr() net.Addr { return nil } +func (w netConnWrapper) Close() error { + // Close called while running the security handshake is an error and we should Reset the + // stream in that case rather than gracefully closing + w.stream.Reset() + return nil +} + +// detachHandshakeDataChannel detaches the handshake data channel +func detachHandshakeDataChannel(ctx context.Context, dc *webrtc.DataChannel) (datachannel.ReadWriteCloser, error) { + done := make(chan struct{}) + var rwc datachannel.ReadWriteCloser + var err error + dc.OnOpen(func() { + defer close(done) + rwc, err = dc.Detach() + }) + // this is safe since for detached datachannels, the peerconnection runs the onOpen + // callback immediately if the SCTP transport is also connected. + select { + case <-done: + return rwc, err + case <-ctx.Done(): + return nil, ctx.Err() + } +} + +// webRTCConnection holds the webrtc.PeerConnection with the handshake channel and the queue for +// incoming data channels created by the peer. +// +// When creating a webrtc.PeerConnection, It is important to set the OnDataChannel handler upfront +// before connecting with the peer. If the handler's set up after connecting with the peer, there's +// a small window of time where datachannels created by the peer may not surface to us and cause a +// memory leak. +type webRTCConnection struct { + PeerConnection *webrtc.PeerConnection + HandshakeDataChannel *webrtc.DataChannel + IncomingDataChannels chan dataChannel +} + +func newWebRTCConnection(settings webrtc.SettingEngine, config webrtc.Configuration) (webRTCConnection, error) { + api := webrtc.NewAPI(webrtc.WithSettingEngine(settings)) + pc, err := api.NewPeerConnection(config) + if err != nil { + return webRTCConnection{}, fmt.Errorf("failed to create peer connection: %w", err) + } + + negotiated, id := handshakeChannelNegotiated, handshakeChannelID + handshakeDataChannel, err := pc.CreateDataChannel("", &webrtc.DataChannelInit{ + Negotiated: &negotiated, + ID: &id, + }) + if err != nil { + pc.Close() + return webRTCConnection{}, fmt.Errorf("failed to create handshake channel: %w", err) + } + + incomingDataChannels := make(chan dataChannel, maxAcceptQueueLen) + pc.OnDataChannel(func(dc *webrtc.DataChannel) { + dc.OnOpen(func() { + rwc, err := dc.Detach() + if err != nil { + log.Warnf("could not detach datachannel: id: %d", *dc.ID()) + return + } + select { + case incomingDataChannels <- dataChannel{rwc, dc}: + default: + log.Warnf("connection busy, rejecting stream") + b, _ := proto.Marshal(&pb.Message{Flag: pb.Message_RESET.Enum()}) + w := msgio.NewWriter(rwc) + w.WriteMsg(b) + rwc.Close() + } + }) + }) + return webRTCConnection{ + PeerConnection: pc, + HandshakeDataChannel: handshakeDataChannel, + IncomingDataChannels: incomingDataChannels, + }, nil +} + +// IsWebRTCDirectMultiaddr returns whether addr is a /webrtc-direct multiaddr with the count of certhashes +// in addr +func IsWebRTCDirectMultiaddr(addr ma.Multiaddr) (bool, int) { + var foundUDP, foundWebRTC bool + certHashCount := 0 + ma.ForEach(addr, func(c ma.Component) bool { + if !foundUDP { + if c.Protocol().Code == ma.P_UDP { + foundUDP = true + } + return true + } + if !foundWebRTC && foundUDP { + // protocol after udp must be webrtc-direct + if c.Protocol().Code != ma.P_WEBRTC_DIRECT { + return false + } + foundWebRTC = true + return true + } + if foundWebRTC { + if c.Protocol().Code == ma.P_CERTHASH { + certHashCount++ + } else { + return false + } + } + return true + }) + return foundUDP && foundWebRTC, certHashCount +} diff --git a/go-libp2p/p2p/transport/webrtc/transport_test.go b/go-libp2p/p2p/transport/webrtc/transport_test.go new file mode 100644 index 0000000..a3054a8 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/transport_test.go @@ -0,0 +1,862 @@ +package libp2pwebrtc + +import ( + "context" + "crypto/rand" + "encoding/hex" + "fmt" + "io" + "net" + "os" + "strings" + "sync" + "sync/atomic" + "testing" + "time" + + "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" + ma "github.com/multiformats/go-multiaddr" + manet "github.com/multiformats/go-multiaddr/net" + "github.com/multiformats/go-multibase" + "github.com/multiformats/go-multihash" + quicproxy "github.com/quic-go/quic-go/integrationtests/tools/proxy" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "golang.org/x/crypto/sha3" +) + +func getTransport(t *testing.T, opts ...Option) (*WebRTCTransport, peer.ID) { + t.Helper() + privKey, _, err := crypto.GenerateKeyPair(crypto.Ed25519, -1) + require.NoError(t, err) + rcmgr := &network.NullResourceManager{} + transport, err := New(privKey, nil, nil, rcmgr, opts...) + require.NoError(t, err) + peerID, err := peer.IDFromPrivateKey(privKey) + require.NoError(t, err) + t.Cleanup(func() { rcmgr.Close() }) + return transport, peerID +} + +func TestIsWebRTCDirectMultiaddr(t *testing.T) { + invalid := []string{ + "/ip4/1.2.3.4/tcp/10/", + "/ip6/1::3/udp/100/quic-v1/", + "/ip4/1.2.3.4/udp/1/quic-v1/webrtc-direct", + } + + valid := []struct { + addr string + count int + }{ + { + addr: "/ip4/1.2.3.4/udp/1234/webrtc-direct", + count: 0, + }, + { + addr: "/dns/test.test/udp/1234/webrtc-direct", + count: 0, + }, + { + addr: "/ip4/1.2.3.4/udp/1234/webrtc-direct/certhash/uEiAsGPzpiPGQzSlVHRXrUCT5EkTV7YFrV4VZ3hpEKTd_zg", + count: 1, + }, + { + addr: "/ip6/0:0:0:0:0:0:0:1/udp/1234/webrtc-direct/certhash/uEiAsGPzpiPGQzSlVHRXrUCT5EkTV7YFrV4VZ3hpEKTd_zg", + count: 1, + }, + { + addr: "/dns/test.test/udp/1234/webrtc-direct/certhash/uEiAsGPzpiPGQzSlVHRXrUCT5EkTV7YFrV4VZ3hpEKTd_zg", + count: 1, + }, + { + addr: "/dns/test.test/udp/1234/webrtc-direct/certhash/uEiAsGPzpiPGQzSlVHRXrUCT5EkTV7YFrV4VZ3hpEKTd_zg/certhash/uEiAsGPzpiPGQzSlVHRXrUCT5EkTV7ZGrV4VZ3hpEKTd_zg", + count: 2, + }, + } + + for _, addr := range invalid { + a := ma.StringCast(addr) + isValid, n := IsWebRTCDirectMultiaddr(a) + require.Equal(t, 0, n) + require.False(t, isValid) + } + + for _, tc := range valid { + a := ma.StringCast(tc.addr) + isValid, n := IsWebRTCDirectMultiaddr(a) + require.Equal(t, tc.count, n) + require.True(t, isValid) + } +} + +func TestTransportWebRTC_CanDial(t *testing.T) { + tr, _ := getTransport(t) + invalid := []string{ + "/ip4/1.2.3.4/udp/1234/webrtc-direct", + "/dns/test.test/udp/1234/webrtc-direct", + } + + valid := []string{ + "/ip4/1.2.3.4/udp/1234/webrtc-direct/certhash/uEiAsGPzpiPGQzSlVHRXrUCT5EkTV7YFrV4VZ3hpEKTd_zg", + "/ip6/0:0:0:0:0:0:0:1/udp/1234/webrtc-direct/certhash/uEiAsGPzpiPGQzSlVHRXrUCT5EkTV7YFrV4VZ3hpEKTd_zg", + "/ip6/::1/udp/1234/webrtc-direct/certhash/uEiAsGPzpiPGQzSlVHRXrUCT5EkTV7YFrV4VZ3hpEKTd_zg", + "/dns/test.test/udp/1234/webrtc-direct/certhash/uEiAsGPzpiPGQzSlVHRXrUCT5EkTV7YFrV4VZ3hpEKTd_zg", + } + + for _, addr := range invalid { + a := ma.StringCast(addr) + require.False(t, tr.CanDial(a)) + } + + for _, addr := range valid { + a := ma.StringCast(addr) + require.True(t, tr.CanDial(a), addr) + } +} + +func TestTransportAddCertHasher(t *testing.T) { + tr, _ := getTransport(t) + addrs := []string{ + "/ip4/1.2.3.4/udp/1/webrtc-direct", + "/ip6/1::3/udp/2/webrtc-direct", + } + for _, a := range addrs { + addr, added := tr.AddCertHashes(ma.StringCast(a)) + require.True(t, added) + _, err := addr.ValueForProtocol(ma.P_CERTHASH) + require.NoError(t, err) + require.True(t, strings.HasPrefix(addr.String(), a)) + } +} + +func TestTransportWebRTC_ListenFailsOnNonWebRTCMultiaddr(t *testing.T) { + tr, _ := getTransport(t) + testAddrs := []string{ + "/ip4/0.0.0.0/udp/0", + "/ip4/0.0.0.0/tcp/0/wss", + } + for _, addr := range testAddrs { + listenMultiaddr, err := ma.NewMultiaddr(addr) + require.NoError(t, err) + listener, err := tr.Listen(listenMultiaddr) + require.Error(t, err) + require.Nil(t, listener) + } +} + +// using assert inside goroutines, refer: https://github.com/stretchr/testify/issues/772#issuecomment-945166599 +func TestTransportWebRTC_DialFailsOnUnsupportedHashFunction(t *testing.T) { + tr, _ := getTransport(t) + hash := sha3.New512() + certhash := func() string { + _, err := hash.Write([]byte("test-data")) + require.NoError(t, err) + mh, err := multihash.Encode(hash.Sum([]byte{}), multihash.SHA3_512) + require.NoError(t, err) + certhash, err := multibase.Encode(multibase.Base58BTC, mh) + require.NoError(t, err) + return certhash + }() + testaddr, err := ma.NewMultiaddr("/ip4/1.2.3.4/udp/1234/webrtc-direct/certhash/" + certhash) + require.NoError(t, err) + _, err = tr.Dial(context.Background(), testaddr, "") + require.ErrorContains(t, err, "unsupported hash function") +} + +func TestTransportWebRTC_CanListenSingle(t *testing.T) { + tr, listeningPeer := getTransport(t) + tr1, connectingPeer := getTransport(t) + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + + listener, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer listener.Close() + + done := make(chan struct{}) + go func() { + _, err := tr1.Dial(context.Background(), listener.Multiaddr(), listeningPeer) + assert.NoError(t, err) + close(done) + }() + + conn, err := listener.Accept() + require.NoError(t, err) + require.NotNil(t, conn) + + require.Equal(t, connectingPeer, conn.RemotePeer()) + select { + case <-done: + case <-time.After(10 * time.Second): + t.FailNow() + } +} + +// WithListenerMaxInFlightConnections sets the maximum number of connections that are in-flight, i.e +// they are being negotiated, or are waiting to be accepted. +func WithListenerMaxInFlightConnections(m uint32) Option { + return func(t *WebRTCTransport) error { + if m == 0 { + t.maxInFlightConnections = DefaultMaxInFlightConnections + } else { + t.maxInFlightConnections = m + } + return nil + } +} + +func TestTransportWebRTC_CanListenMultiple(t *testing.T) { + count := 3 + tr, listeningPeer := getTransport(t, WithListenerMaxInFlightConnections(uint32(count))) + + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + listener, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer listener.Close() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + var wg sync.WaitGroup + go func() { + for i := 0; i < count; i++ { + conn, err := listener.Accept() + assert.NoError(t, err) + assert.NotNil(t, conn) + defer conn.Close() + } + wg.Wait() + cancel() + }() + + for i := 0; i < count; i++ { + wg.Add(1) + go func() { + defer wg.Done() + ctr, _ := getTransport(t) + conn, err := ctr.Dial(ctx, listener.Multiaddr(), listeningPeer) + select { + case <-ctx.Done(): + default: + assert.NoError(t, err) + assert.NotNil(t, conn) + t.Cleanup(func() { conn.Close() }) + } + }() + } + + select { + case <-ctx.Done(): + case <-time.After(30 * time.Second): + t.Fatalf("timed out") + } +} + +func TestTransportWebRTC_CanCreateSuccessiveConnections(t *testing.T) { + tr, listeningPeer := getTransport(t) + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + listener, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer listener.Close() + + count := 2 + + var wg sync.WaitGroup + wg.Add(count) + go func() { + for i := 0; i < count; i++ { + ctr, _ := getTransport(t) + conn, err := ctr.Dial(context.Background(), listener.Multiaddr(), listeningPeer) + require.NoError(t, err) + require.Equal(t, conn.RemotePeer(), listeningPeer) + t.Cleanup(func() { conn.Close() }) + wg.Done() + } + }() + + for i := 0; i < count; i++ { + conn, err := listener.Accept() + require.NoError(t, err) + defer conn.Close() + } + wg.Wait() +} + +func TestTransportWebRTC_ListenerCanCreateStreams(t *testing.T) { + tr, listeningPeer := getTransport(t) + tr1, connectingPeer := getTransport(t) + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + listener, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer listener.Close() + + streamChan := make(chan network.MuxedStream) + go func() { + conn, err := tr1.Dial(context.Background(), listener.Multiaddr(), listeningPeer) + require.NoError(t, err) + t.Cleanup(func() { conn.Close() }) + t.Logf("connection opened by dialer") + + stream, err := conn.AcceptStream() + require.NoError(t, err) + t.Logf("dialer accepted stream") + streamChan <- stream + }() + + conn, err := listener.Accept() + require.NoError(t, err) + defer conn.Close() + require.Equal(t, connectingPeer, conn.RemotePeer()) + t.Logf("listener accepted connection") + + stream, err := conn.OpenStream(context.Background()) + require.NoError(t, err) + t.Logf("listener opened stream") + _, err = stream.Write([]byte("test")) + require.NoError(t, err) + + var str network.MuxedStream + select { + case str = <-streamChan: + case <-time.After(3 * time.Second): + t.Fatal("stream opening timed out") + } + buf := make([]byte, 100) + stream.SetReadDeadline(time.Now().Add(3 * time.Second)) + n, err := str.Read(buf) + require.NoError(t, err) + require.Equal(t, "test", string(buf[:n])) +} + +func TestTransportWebRTC_DialerCanCreateStreams(t *testing.T) { + tr, listeningPeer := getTransport(t) + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + listener, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer listener.Close() + + tr1, connectingPeer := getTransport(t) + done := make(chan struct{}) + + go func() { + lconn, err := listener.Accept() + require.NoError(t, err) + require.Equal(t, connectingPeer, lconn.RemotePeer()) + defer lconn.Close() + + stream, err := lconn.AcceptStream() + require.NoError(t, err) + buf := make([]byte, 100) + n, err := stream.Read(buf) + require.NoError(t, err) + require.Equal(t, "test", string(buf[:n])) + + close(done) + }() + + go func() { + conn, err := tr1.Dial(context.Background(), listener.Multiaddr(), listeningPeer) + require.NoError(t, err) + defer conn.Close() + t.Logf("dialer opened connection") + stream, err := conn.OpenStream(context.Background()) + require.NoError(t, err) + t.Logf("dialer opened stream") + _, err = stream.Write([]byte("test")) + require.NoError(t, err) + <-done + }() + + select { + case <-done: + case <-time.After(10 * time.Second): + t.Fatal("timed out") + } +} + +func TestTransportWebRTC_DialerCanCreateStreamsMultiple(t *testing.T) { + tr, listeningPeer := getTransport(t) + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + listener, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer listener.Close() + + tr1, connectingPeer := getTransport(t) + readerDone := make(chan struct{}) + + const ( + numListeners = 10 + numStreams = 100 + numWriters = 10 + size = 20 << 10 + ) + + go func() { + lconn, err := listener.Accept() + require.NoError(t, err) + require.Equal(t, connectingPeer, lconn.RemotePeer()) + defer lconn.Close() + var wg sync.WaitGroup + var doneStreams atomic.Int32 + for i := 0; i < numListeners; i++ { + wg.Add(1) + go func() { + defer wg.Done() + for { + var nn int32 + if nn = doneStreams.Add(1); nn > int32(numStreams) { + return + } + s, err := lconn.AcceptStream() + require.NoError(t, err) + n, err := io.Copy(s, s) + require.Equal(t, n, int64(size)) + require.NoError(t, err) + s.Close() + } + }() + } + wg.Wait() + readerDone <- struct{}{} + }() + + conn, err := tr1.Dial(context.Background(), listener.Multiaddr(), listeningPeer) + require.NoError(t, err) + defer conn.Close() + + var writerWG sync.WaitGroup + var cnt atomic.Int32 + var streamsStarted atomic.Int32 + for i := 0; i < numWriters; i++ { + writerWG.Add(1) + go func() { + defer writerWG.Done() + buf := make([]byte, size) + for { + var nn int32 + if nn = streamsStarted.Add(1); nn > int32(numStreams) { + return + } + rand.Read(buf) + + s, err := conn.OpenStream(context.Background()) + require.NoError(t, err) + n, err := s.Write(buf) + require.Equal(t, n, size) + require.NoError(t, err) + s.CloseWrite() + resp := make([]byte, size+10) + n, err = io.ReadFull(s, resp) + require.ErrorIs(t, err, io.ErrUnexpectedEOF) + require.Equal(t, n, size) + if string(buf) != string(resp[:size]) { + t.Errorf("bytes not equal: %d %d", len(buf), len(resp)) + } + s.Close() + t.Log("completed stream: ", cnt.Add(1), s.(*stream).id) + } + }() + } + writerWG.Wait() + select { + case <-readerDone: + case <-time.After(100 * time.Second): + t.Fatal("timed out") + } +} + +func TestTransportWebRTC_Deadline(t *testing.T) { + tr, listeningPeer := getTransport(t) + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + listener, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer listener.Close() + tr1, connectingPeer := getTransport(t) + + t.Run("SetReadDeadline", func(t *testing.T) { + go func() { + lconn, err := listener.Accept() + require.NoError(t, err) + t.Cleanup(func() { lconn.Close() }) + require.Equal(t, connectingPeer, lconn.RemotePeer()) + _, err = lconn.AcceptStream() + require.NoError(t, err) + }() + + conn, err := tr1.Dial(context.Background(), listener.Multiaddr(), listeningPeer) + require.NoError(t, err) + defer conn.Close() + stream, err := conn.OpenStream(context.Background()) + require.NoError(t, err) + + // deadline set to the past + stream.SetReadDeadline(time.Now().Add(-200 * time.Millisecond)) + _, err = stream.Read([]byte{0, 0}) + require.ErrorIs(t, err, os.ErrDeadlineExceeded) + + // future deadline exceeded + stream.SetReadDeadline(time.Now().Add(100 * time.Millisecond)) + _, err = stream.Read([]byte{0, 0}) + require.ErrorIs(t, err, os.ErrDeadlineExceeded) + }) + + t.Run("SetWriteDeadline", func(t *testing.T) { + go func() { + lconn, err := listener.Accept() + require.NoError(t, err) + t.Cleanup(func() { lconn.Close() }) + require.Equal(t, connectingPeer, lconn.RemotePeer()) + _, err = lconn.AcceptStream() + require.NoError(t, err) + }() + + conn, err := tr1.Dial(context.Background(), listener.Multiaddr(), listeningPeer) + require.NoError(t, err) + defer conn.Close() + stream, err := conn.OpenStream(context.Background()) + require.NoError(t, err) + + stream.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)) + largeBuffer := make([]byte, 2*1024*1024) + _, err = stream.Write(largeBuffer) + require.ErrorIs(t, err, os.ErrDeadlineExceeded) + + stream.SetWriteDeadline(time.Now().Add(-200 * time.Millisecond)) + smallBuffer := make([]byte, 1024) + _, err = stream.Write(smallBuffer) + require.ErrorIs(t, err, os.ErrDeadlineExceeded) + }) +} + +func TestTransportWebRTC_StreamWriteBufferContention(t *testing.T) { + tr, listeningPeer := getTransport(t) + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + listener, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer listener.Close() + + tr1, connectingPeer := getTransport(t) + + var wg sync.WaitGroup + wg.Add(3) + go func() { + defer wg.Done() + lconn, err := listener.Accept() + require.NoError(t, err) + t.Cleanup(func() { lconn.Close() }) + require.Equal(t, connectingPeer, lconn.RemotePeer()) + for i := 0; i < 2; i++ { + go func() { + defer wg.Done() + _, err := lconn.AcceptStream() + require.NoError(t, err) + }() + } + }() + + conn, err := tr1.Dial(context.Background(), listener.Multiaddr(), listeningPeer) + require.NoError(t, err) + defer conn.Close() + + errC := make(chan error) + // writers + for i := 0; i < 2; i++ { + go func() { + stream, err := conn.OpenStream(context.Background()) + require.NoError(t, err) + + stream.SetWriteDeadline(time.Now().Add(200 * time.Millisecond)) + largeBuffer := make([]byte, 2*1024*1024) + _, err = stream.Write(largeBuffer) + errC <- err + }() + } + + require.ErrorIs(t, <-errC, os.ErrDeadlineExceeded) + require.ErrorIs(t, <-errC, os.ErrDeadlineExceeded) + wg.Wait() +} + +func TestTransportWebRTC_RemoteReadsAfterClose(t *testing.T) { + tr, listeningPeer := getTransport(t) + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + listener, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer listener.Close() + + tr1, _ := getTransport(t) + + done := make(chan error) + go func() { + lconn, err := listener.Accept() + if err != nil { + done <- err + return + } + t.Cleanup(func() { lconn.Close() }) + + stream, err := lconn.AcceptStream() + if err != nil { + done <- err + return + } + _, err = stream.Write([]byte{1, 2, 3, 4}) + if err != nil { + done <- err + return + } + err = stream.Close() + if err != nil { + done <- err + return + } + close(done) + }() + + conn, err := tr1.Dial(context.Background(), listener.Multiaddr(), listeningPeer) + require.NoError(t, err) + defer conn.Close() + // create a stream + stream, err := conn.OpenStream(context.Background()) + + require.NoError(t, err) + // require write and close to complete + require.NoError(t, <-done) + stream.SetReadDeadline(time.Now().Add(5 * time.Second)) + + buf := make([]byte, 10) + n, err := stream.Read(buf) + require.NoError(t, err) + require.Equal(t, 4, n) +} + +func TestTransportWebRTC_RemoteReadsAfterClose2(t *testing.T) { + tr, listeningPeer := getTransport(t) + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + listener, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer listener.Close() + + tr1, _ := getTransport(t) + + awaitStreamClosure := make(chan struct{}) + readBytesResult := make(chan int) + done := make(chan error) + go func() { + lconn, err := listener.Accept() + if err != nil { + done <- err + return + } + defer lconn.Close() + stream, err := lconn.AcceptStream() + if err != nil { + done <- err + return + } + + <-awaitStreamClosure + buf := make([]byte, 16) + n, err := stream.Read(buf) + if err != nil { + done <- err + return + } + readBytesResult <- n + close(done) + }() + + conn, err := tr1.Dial(context.Background(), listener.Multiaddr(), listeningPeer) + require.NoError(t, err) + defer conn.Close() + // create a stream + stream, err := conn.OpenStream(context.Background()) + require.NoError(t, err) + _, err = stream.Write([]byte{1, 2, 3, 4}) + require.NoError(t, err) + err = stream.Close() + require.NoError(t, err) + // signal stream closure + close(awaitStreamClosure) + require.Equal(t, 4, <-readBytesResult) +} + +func TestTransportWebRTC_Close(t *testing.T) { + tr, listeningPeer := getTransport(t) + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + listener, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer listener.Close() + + tr1, connectingPeer := getTransport(t) + + t.Run("RemoteClosesStream", func(t *testing.T) { + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + lconn, err := listener.Accept() + require.NoError(t, err) + t.Cleanup(func() { lconn.Close() }) + require.Equal(t, connectingPeer, lconn.RemotePeer()) + stream, err := lconn.AcceptStream() + require.NoError(t, err) + time.Sleep(100 * time.Millisecond) + _ = stream.Close() + }() + + buf := make([]byte, 2) + + conn, err := tr1.Dial(context.Background(), listener.Multiaddr(), listeningPeer) + require.NoError(t, err) + defer conn.Close() + stream, err := conn.OpenStream(context.Background()) + require.NoError(t, err) + + err = stream.SetReadDeadline(time.Now().Add(2 * time.Second)) + require.NoError(t, err) + _, err = stream.Read(buf) + require.ErrorIs(t, err, io.EOF) + + wg.Wait() + }) +} + +func TestTransportWebRTC_PeerConnectionDTLSFailed(t *testing.T) { + tr, listeningPeer := getTransport(t) + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + ln, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer ln.Close() + + encoded, err := hex.DecodeString("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") + require.NoError(t, err) + encodedCerthash, err := multihash.Encode(encoded, multihash.SHA2_256) + require.NoError(t, err) + badEncodedCerthash, err := multibase.Encode(multibase.Base58BTC, encodedCerthash) + require.NoError(t, err) + badCerthash, err := ma.NewMultiaddr(fmt.Sprintf("/certhash/%s", badEncodedCerthash)) + require.NoError(t, err) + badMultiaddr, _ := ma.SplitFunc(ln.Multiaddr(), func(c ma.Component) bool { return c.Protocol().Code == ma.P_CERTHASH }) + badMultiaddr = badMultiaddr.Encapsulate(badCerthash) + + tr1, _ := getTransport(t) + conn, err := tr1.Dial(context.Background(), badMultiaddr, listeningPeer) + require.Error(t, err) + require.ErrorContains(t, err, "failed") + require.Nil(t, conn) +} + +func TestConnectionTimeoutOnListener(t *testing.T) { + tr, listeningPeer := getTransport(t) + tr.peerConnectionTimeouts.Disconnect = 100 * time.Millisecond + tr.peerConnectionTimeouts.Failed = 150 * time.Millisecond + tr.peerConnectionTimeouts.Keepalive = 50 * time.Millisecond + + listenMultiaddr := ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct") + ln, err := tr.Listen(listenMultiaddr) + require.NoError(t, err) + defer ln.Close() + + var drop atomic.Bool + proxy, err := quicproxy.NewQuicProxy("127.0.0.1:0", &quicproxy.Opts{ + RemoteAddr: fmt.Sprintf("127.0.0.1:%d", ln.Addr().(*net.UDPAddr).Port), + DropPacket: func(quicproxy.Direction, []byte) bool { return drop.Load() }, + }) + require.NoError(t, err) + defer proxy.Close() + + tr1, connectingPeer := getTransport(t) + go func() { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + addr, err := manet.FromNetAddr(proxy.LocalAddr()) + require.NoError(t, err) + _, webrtcComponent := ma.SplitFunc(ln.Multiaddr(), func(c ma.Component) bool { return c.Protocol().Code == ma.P_WEBRTC_DIRECT }) + addr = addr.Encapsulate(webrtcComponent) + conn, err := tr1.Dial(ctx, addr, listeningPeer) + require.NoError(t, err) + t.Cleanup(func() { conn.Close() }) + str, err := conn.OpenStream(ctx) + require.NoError(t, err) + str.Write([]byte("foobar")) + }() + + conn, err := ln.Accept() + require.NoError(t, err) + require.Equal(t, connectingPeer, conn.RemotePeer()) + defer conn.Close() + + str, err := conn.AcceptStream() + require.NoError(t, err) + _, err = str.Write([]byte("test")) + require.NoError(t, err) + // start dropping all packets + drop.Store(true) + start := time.Now() + for { + if _, err := str.Write([]byte("test")); err != nil { + if os.IsTimeout(err) { + break + } + // If we write when a connection timeout happens, sctp provides + // a "stream closed" error. This occurs concurrently with the + // callback we receive for connection timeout. + // Test once more after sleep that we provide the correct error. + if strings.Contains(err.Error(), "stream closed") { + time.Sleep(50 * time.Millisecond) + _, err = str.Write([]byte("test")) + require.True(t, os.IsTimeout(err), "invalid error type: %v", err) + } else { + t.Fatal("invalid error type", err) + } + break + } + + if time.Since(start) > 5*time.Second { + t.Fatal("timeout") + } + // make sure to not write too often, we don't want to fill the flow control window + time.Sleep(20 * time.Millisecond) + } + // make sure that accepting a stream also returns an error... + _, err = conn.AcceptStream() + require.True(t, os.IsTimeout(err)) + // ... as well as opening a new stream + _, err = conn.OpenStream(context.Background()) + require.True(t, os.IsTimeout(err)) +} + +func TestMaxInFlightRequests(t *testing.T) { + const count = 3 + tr, listeningPeer := getTransport(t, + WithListenerMaxInFlightConnections(count), + ) + ln, err := tr.Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/webrtc-direct")) + require.NoError(t, err) + defer ln.Close() + + var wg sync.WaitGroup + var success, fails atomic.Int32 + for i := 0; i < count+1; i++ { + wg.Add(1) + go func() { + defer wg.Done() + dialer, _ := getTransport(t) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() + if conn, err := dialer.Dial(ctx, ln.Multiaddr(), listeningPeer); err == nil { + success.Add(1) + t.Cleanup(func() { conn.Close() }) + } else { + t.Log("failed to dial:", err) + fails.Add(1) + } + }() + } + wg.Wait() + require.Equal(t, count, int(success.Load()), "expected exactly 3 dial successes") + require.Equal(t, 1, int(fails.Load()), "expected exactly 1 dial failure") +} diff --git a/go-libp2p/p2p/transport/webrtc/udpmux/mux.go b/go-libp2p/p2p/transport/webrtc/udpmux/mux.go new file mode 100644 index 0000000..98e60e3 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/udpmux/mux.go @@ -0,0 +1,298 @@ +package udpmux + +import ( + "bytes" + "context" + "fmt" + "io" + "net" + "strings" + "sync" + + logging "github.com/ipfs/go-log/v2" + pool "github.com/libp2p/go-buffer-pool" + "github.com/pion/ice/v2" + "github.com/pion/stun" +) + +var log = logging.Logger("webrtc-udpmux") + +// ReceiveBufSize is the size of the buffer used to receive packets from the PacketConn. +// It is fine for this number to be higher than the actual path MTU as this value is not +// used to decide the packet size on the write path. +const ReceiveBufSize = 1500 + +type Candidate struct { + Ufrag string + Addr *net.UDPAddr +} + +// UDPMux multiplexes multiple ICE connections over a single net.PacketConn, +// generally a UDP socket. +// +// The connections are indexed by (ufrag, IP address family) and by remote +// address from which the connection has received valid STUN/RTC packets. +// +// When a new packet is received on the underlying net.PacketConn, we +// first check the address map to see if there is a connection associated with the +// remote address: +// If found, we pass the packet to that connection. +// Otherwise, we check to see if the packet is a STUN packet. +// If it is, we read the ufrag from the STUN packet and use it to check if there +// is a connection associated with the (ufrag, IP address family) pair. +// If found we add the association to the address map. +type UDPMux struct { + socket net.PacketConn + + queue chan Candidate + + mx sync.Mutex + // ufragMap allows us to multiplex incoming STUN packets based on ufrag + ufragMap map[ufragConnKey]*muxedConnection + // addrMap allows us to correctly direct incoming packets after the connection + // is established and ufrag isn't available on all packets + addrMap map[string]*muxedConnection + // ufragAddrMap allows cleaning up all addresses from the addrMap once the connection is closed + // During the ICE connectivity checks, the same ufrag might be used on multiple addresses. + ufragAddrMap map[ufragConnKey][]net.Addr + + // the context controls the lifecycle of the mux + wg sync.WaitGroup + ctx context.Context + cancel context.CancelFunc +} + +var _ ice.UDPMux = &UDPMux{} + +func NewUDPMux(socket net.PacketConn) *UDPMux { + ctx, cancel := context.WithCancel(context.Background()) + mux := &UDPMux{ + ctx: ctx, + cancel: cancel, + socket: socket, + ufragMap: make(map[ufragConnKey]*muxedConnection), + addrMap: make(map[string]*muxedConnection), + ufragAddrMap: make(map[ufragConnKey][]net.Addr), + queue: make(chan Candidate, 32), + } + + return mux +} + +func (mux *UDPMux) Start() { + mux.wg.Add(1) + go func() { + defer mux.wg.Done() + mux.readLoop() + }() +} + +// GetListenAddresses implements ice.UDPMux +func (mux *UDPMux) GetListenAddresses() []net.Addr { + return []net.Addr{mux.socket.LocalAddr()} +} + +// GetConn implements ice.UDPMux +// It creates a net.PacketConn for a given ufrag if an existing one cannot be found. +// We differentiate IPv4 and IPv6 addresses, since a remote is can be reachable at multiple different +// UDP addresses of the same IP address family (eg. server-reflexive addresses and peer-reflexive addresses). +func (mux *UDPMux) GetConn(ufrag string, addr net.Addr) (net.PacketConn, error) { + a, ok := addr.(*net.UDPAddr) + if !ok { + return nil, fmt.Errorf("unexpected address type: %T", addr) + } + select { + case <-mux.ctx.Done(): + return nil, io.ErrClosedPipe + default: + isIPv6 := ok && a.IP.To4() == nil + _, conn := mux.getOrCreateConn(ufrag, isIPv6, mux, addr) + return conn, nil + } +} + +// Close implements ice.UDPMux +func (mux *UDPMux) Close() error { + select { + case <-mux.ctx.Done(): + return nil + default: + } + mux.cancel() + mux.socket.Close() + mux.wg.Wait() + return nil +} + +// writeTo writes a packet to the underlying net.PacketConn +func (mux *UDPMux) writeTo(buf []byte, addr net.Addr) (int, error) { + return mux.socket.WriteTo(buf, addr) +} + +func (mux *UDPMux) readLoop() { + for { + select { + case <-mux.ctx.Done(): + return + default: + } + + buf := pool.Get(ReceiveBufSize) + + n, addr, err := mux.socket.ReadFrom(buf) + if err != nil { + if strings.Contains(err.Error(), "use of closed network connection") { + log.Debugf("readLoop exiting: socket %s closed", mux.socket.LocalAddr()) + } else { + log.Errorf("error reading from socket %s: %v", mux.socket.LocalAddr(), err) + } + pool.Put(buf) + return + } + buf = buf[:n] + + if processed := mux.processPacket(buf, addr); !processed { + pool.Put(buf) + } + } +} + +func (mux *UDPMux) processPacket(buf []byte, addr net.Addr) (processed bool) { + udpAddr, ok := addr.(*net.UDPAddr) + if !ok { + log.Errorf("received a non-UDP address: %s", addr) + return false + } + isIPv6 := udpAddr.IP.To4() == nil + + // Connections are indexed by remote address. We first + // check if the remote address has a connection associated + // with it. If yes, we push the received packet to the connection + mux.mx.Lock() + conn, ok := mux.addrMap[addr.String()] + mux.mx.Unlock() + if ok { + if err := conn.Push(buf, addr); err != nil { + log.Debugf("could not push packet: %v", err) + return false + } + return true + } + + if !stun.IsMessage(buf) { + log.Debug("incoming message is not a STUN message") + return false + } + + msg := &stun.Message{Raw: buf} + if err := msg.Decode(); err != nil { + log.Debugf("failed to decode STUN message: %s", err) + return false + } + if msg.Type != stun.BindingRequest { + log.Debugf("incoming message should be a STUN binding request, got %s", msg.Type) + return false + } + + ufrag, err := ufragFromSTUNMessage(msg) + if err != nil { + log.Debugf("could not find STUN username: %s", err) + return false + } + + connCreated, conn := mux.getOrCreateConn(ufrag, isIPv6, mux, udpAddr) + if connCreated { + select { + case mux.queue <- Candidate{Addr: udpAddr, Ufrag: ufrag}: + default: + log.Debugw("queue full, dropping incoming candidate", "ufrag", ufrag, "addr", udpAddr) + conn.Close() + return false + } + } + + if err := conn.Push(buf, addr); err != nil { + log.Debugf("could not push packet: %v", err) + return false + } + return true +} + +func (mux *UDPMux) Accept(ctx context.Context) (Candidate, error) { + select { + case c := <-mux.queue: + return c, nil + case <-ctx.Done(): + return Candidate{}, ctx.Err() + case <-mux.ctx.Done(): + return Candidate{}, mux.ctx.Err() + } +} + +type ufragConnKey struct { + ufrag string + isIPv6 bool +} + +// ufragFromSTUNMessage returns the local or ufrag +// from the STUN username attribute. Local ufrag is the ufrag of the +// peer which initiated the connectivity check, e.g in a connectivity +// check from A to B, the username attribute will be B_ufrag:A_ufrag +// with the local ufrag value being A_ufrag. In case of ice-lite, the +// localUfrag value will always be the remote peer's ufrag since ICE-lite +// implementations do not generate connectivity checks. In our specific +// case, since the local and remote ufrag is equal, we can return +// either value. +func ufragFromSTUNMessage(msg *stun.Message) (string, error) { + attr, err := msg.Get(stun.AttrUsername) + if err != nil { + return "", err + } + index := bytes.Index(attr, []byte{':'}) + if index == -1 { + return "", fmt.Errorf("invalid STUN username attribute") + } + return string(attr[index+1:]), nil +} + +// RemoveConnByUfrag removes the connection associated with the ufrag and all the +// addresses associated with that connection. This method is called by pion when +// a peerconnection is closed. +func (mux *UDPMux) RemoveConnByUfrag(ufrag string) { + if ufrag == "" { + return + } + + mux.mx.Lock() + defer mux.mx.Unlock() + + for _, isIPv6 := range [...]bool{true, false} { + key := ufragConnKey{ufrag: ufrag, isIPv6: isIPv6} + if _, ok := mux.ufragMap[key]; ok { + delete(mux.ufragMap, key) + for _, addr := range mux.ufragAddrMap[key] { + delete(mux.addrMap, addr.String()) + } + delete(mux.ufragAddrMap, key) + } + } +} + +func (mux *UDPMux) getOrCreateConn(ufrag string, isIPv6 bool, _ *UDPMux, addr net.Addr) (created bool, _ *muxedConnection) { + key := ufragConnKey{ufrag: ufrag, isIPv6: isIPv6} + + mux.mx.Lock() + defer mux.mx.Unlock() + + if conn, ok := mux.ufragMap[key]; ok { + mux.addrMap[addr.String()] = conn + mux.ufragAddrMap[key] = append(mux.ufragAddrMap[key], addr) + return false, conn + } + + conn := newMuxedConnection(mux, func() { mux.RemoveConnByUfrag(ufrag) }) + mux.ufragMap[key] = conn + mux.addrMap[addr.String()] = conn + mux.ufragAddrMap[key] = append(mux.ufragAddrMap[key], addr) + return true, conn +} diff --git a/go-libp2p/p2p/transport/webrtc/udpmux/mux_test.go b/go-libp2p/p2p/transport/webrtc/udpmux/mux_test.go new file mode 100644 index 0000000..298e5c9 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/udpmux/mux_test.go @@ -0,0 +1,248 @@ +package udpmux + +import ( + "context" + "fmt" + "net" + "testing" + "time" + + "github.com/pion/stun" + "github.com/stretchr/testify/require" +) + +func getSTUNBindingRequest(ufrag string) *stun.Message { + msg := stun.New() + msg.SetType(stun.BindingRequest) + uattr := stun.RawAttribute{ + Type: stun.AttrUsername, + Value: []byte(fmt.Sprintf("%s:%s", ufrag, ufrag)), // This is the format we expect in our connections + } + uattr.AddTo(msg) + msg.Encode() + return msg +} + +func setupMapping(t *testing.T, ufrag string, from net.PacketConn, m *UDPMux) { + t.Helper() + msg := getSTUNBindingRequest(ufrag) + _, err := from.WriteTo(msg.Raw, m.GetListenAddresses()[0]) + require.NoError(t, err) +} + +func newPacketConn(t *testing.T) net.PacketConn { + t.Helper() + udpPort0 := &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 0} + c, err := net.ListenUDP("udp", udpPort0) + require.NoError(t, err) + t.Cleanup(func() { c.Close() }) + return c +} + +func TestAccept(t *testing.T) { + c := newPacketConn(t) + defer c.Close() + m := NewUDPMux(c) + m.Start() + defer m.Close() + + ufrags := []string{"a", "b", "c", "d"} + conns := make([]net.PacketConn, len(ufrags)) + for i, ufrag := range ufrags { + conns[i] = newPacketConn(t) + setupMapping(t, ufrag, conns[i], m) + } + for i, ufrag := range ufrags { + c, err := m.Accept(context.Background()) + require.NoError(t, err) + require.Equal(t, c.Ufrag, ufrag) + require.Equal(t, c.Addr, conns[i].LocalAddr()) + } + + for i, ufrag := range ufrags { + // should not be accepted + setupMapping(t, ufrag, conns[i], m) + ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) + defer cancel() + _, err := m.Accept(ctx) + require.Error(t, err) + + // should not be accepted + cc := newPacketConn(t) + setupMapping(t, ufrag, cc, m) + ctx, cancel = context.WithTimeout(context.Background(), 100*time.Millisecond) + defer cancel() + _, err = m.Accept(ctx) + require.Error(t, err) + } +} + +func TestGetConn(t *testing.T) { + c := newPacketConn(t) + m := NewUDPMux(c) + m.Start() + defer m.Close() + + ufrags := []string{"a", "b", "c", "d"} + conns := make([]net.PacketConn, len(ufrags)) + for i, ufrag := range ufrags { + conns[i] = newPacketConn(t) + setupMapping(t, ufrag, conns[i], m) + } + for i, ufrag := range ufrags { + c, err := m.Accept(context.Background()) + require.NoError(t, err) + require.Equal(t, c.Ufrag, ufrag) + require.Equal(t, c.Addr, conns[i].LocalAddr()) + } + + for i, ufrag := range ufrags { + c, err := m.GetConn(ufrag, conns[i].LocalAddr()) + require.NoError(t, err) + msg := make([]byte, 100) + _, _, err = c.ReadFrom(msg) + require.NoError(t, err) + } + + for i, ufrag := range ufrags { + cc := newPacketConn(t) + // setupMapping of cc to ufrags[0] and remove the stun binding request from the queue + setupMapping(t, ufrag, cc, m) + mc, err := m.GetConn(ufrag, cc.LocalAddr()) + require.NoError(t, err) + msg := make([]byte, 100) + _, _, err = mc.ReadFrom(msg) + require.NoError(t, err) + + // Write from new connection should provide the new address on ReadFrom + _, err = cc.WriteTo([]byte("test1"), c.LocalAddr()) + require.NoError(t, err) + n, addr, err := mc.ReadFrom(msg) + require.NoError(t, err) + require.Equal(t, addr, cc.LocalAddr()) + require.Equal(t, "test1", string(msg[:n])) + + // Write from original connection should provide the original address + _, err = conns[i].WriteTo([]byte("test2"), c.LocalAddr()) + require.NoError(t, err) + n, addr, err = mc.ReadFrom(msg) + require.NoError(t, err) + require.Equal(t, addr, conns[i].LocalAddr()) + require.Equal(t, "test2", string(msg[:n])) + } +} + +func TestRemoveConnByUfrag(t *testing.T) { + c := newPacketConn(t) + m := NewUDPMux(c) + m.Start() + defer m.Close() + + // Map each ufrag to two addresses + ufrag := "a" + count := 10 + conns := make([]net.PacketConn, count) + for i := 0; i < 10; i++ { + conns[i] = newPacketConn(t) + setupMapping(t, ufrag, conns[i], m) + } + mc, err := m.GetConn(ufrag, conns[0].LocalAddr()) + require.NoError(t, err) + for i := 0; i < 10; i++ { + mc1, err := m.GetConn(ufrag, conns[i].LocalAddr()) + require.NoError(t, err) + if mc1 != mc { + t.Fatalf("expected the two muxed connections to be same") + } + } + + // Now remove the ufrag + m.RemoveConnByUfrag(ufrag) + + // All connections should now be associated with b + ufrag = "b" + for i := 0; i < 10; i++ { + setupMapping(t, ufrag, conns[i], m) + } + mc, err = m.GetConn(ufrag, conns[0].LocalAddr()) + require.NoError(t, err) + for i := 0; i < 10; i++ { + mc1, err := m.GetConn(ufrag, conns[i].LocalAddr()) + require.NoError(t, err) + if mc1 != mc { + t.Fatalf("expected the two muxed connections to be same") + } + } + + // Should be different even if the address is the same + mc1, err := m.GetConn("a", conns[0].LocalAddr()) + require.NoError(t, err) + if mc1 == mc { + t.Fatalf("expected the two connections to be different") + } +} + +func TestMuxedConnection(t *testing.T) { + c := newPacketConn(t) + m := NewUDPMux(c) + m.Start() + defer m.Close() + + msgCount := 3 + connCount := 3 + + ufrags := []string{"a", "b", "c"} + addrUfragMap := make(map[string]string) + ufragConnsMap := make(map[string][]net.PacketConn) + for _, ufrag := range ufrags { + for i := 0; i < connCount; i++ { + cc := newPacketConn(t) + addrUfragMap[cc.LocalAddr().String()] = ufrag + ufragConnsMap[ufrag] = append(ufragConnsMap[ufrag], cc) + } + } + + done := make(chan bool, len(ufrags)) + for _, ufrag := range ufrags { + go func(ufrag string) { + for _, cc := range ufragConnsMap[ufrag] { + setupMapping(t, ufrag, cc, m) + for j := 0; j < msgCount; j++ { + cc.WriteTo([]byte(ufrag), c.LocalAddr()) + } + } + done <- true + }(ufrag) + } + for i := 0; i < len(ufrags); i++ { + <-done + } + + for _, ufrag := range ufrags { + mc, err := m.GetConn(ufrag, c.LocalAddr()) // the address is irrelevant + require.NoError(t, err) + msgs := 0 + stunRequests := 0 + msg := make([]byte, 1500) + addrPacketCount := make(map[string]int) + for i := 0; i < connCount; i++ { + for j := 0; j < msgCount+1; j++ { + n, addr1, err := mc.ReadFrom(msg) + require.NoError(t, err) + require.Equal(t, addrUfragMap[addr1.String()], ufrag) + addrPacketCount[addr1.String()]++ + if stun.IsMessage(msg[:n]) { + stunRequests++ + } else { + msgs++ + } + } + } + for addr, v := range addrPacketCount { + require.Equal(t, v, msgCount+1) // msgCount msgs + 1 STUN binding request + delete(addrUfragMap, addr) + } + require.Len(t, addrPacketCount, connCount) + } + require.Empty(t, addrUfragMap) +} diff --git a/go-libp2p/p2p/transport/webrtc/udpmux/muxed_connection.go b/go-libp2p/p2p/transport/webrtc/udpmux/muxed_connection.go new file mode 100644 index 0000000..2af5d33 --- /dev/null +++ b/go-libp2p/p2p/transport/webrtc/udpmux/muxed_connection.go @@ -0,0 +1,112 @@ +package udpmux + +import ( + "context" + "errors" + "net" + "time" + + pool "github.com/libp2p/go-buffer-pool" +) + +type packet struct { + buf []byte + addr net.Addr +} + +var _ net.PacketConn = &muxedConnection{} + +const queueLen = 128 + +// muxedConnection provides a net.PacketConn abstraction +// over packetQueue and adds the ability to store addresses +// from which this connection (indexed by ufrag) received +// data. +type muxedConnection struct { + ctx context.Context + cancel context.CancelFunc + onClose func() + queue chan packet + mux *UDPMux +} + +var _ net.PacketConn = &muxedConnection{} + +func newMuxedConnection(mux *UDPMux, onClose func()) *muxedConnection { + ctx, cancel := context.WithCancel(mux.ctx) + return &muxedConnection{ + ctx: ctx, + cancel: cancel, + queue: make(chan packet, queueLen), + onClose: onClose, + mux: mux, + } +} + +func (c *muxedConnection) Push(buf []byte, addr net.Addr) error { + select { + case <-c.ctx.Done(): + return errors.New("closed") + default: + } + select { + case c.queue <- packet{buf: buf, addr: addr}: + return nil + default: + return errors.New("queue full") + } +} + +func (c *muxedConnection) ReadFrom(buf []byte) (int, net.Addr, error) { + select { + case p := <-c.queue: + n := copy(buf, p.buf) // This might discard parts of the packet, if p is too short + if n < len(p.buf) { + log.Debugf("short read, had %d, read %d", len(p.buf), n) + } + pool.Put(p.buf) + return n, p.addr, nil + case <-c.ctx.Done(): + return 0, nil, c.ctx.Err() + } +} + +func (c *muxedConnection) WriteTo(p []byte, addr net.Addr) (n int, err error) { + return c.mux.writeTo(p, addr) +} + +func (c *muxedConnection) Close() error { + select { + case <-c.ctx.Done(): + return nil + default: + } + c.onClose() + c.cancel() + // drain the packet queue + for { + select { + case p := <-c.queue: + pool.Put(p.buf) + default: + return nil + } + } +} + +func (c *muxedConnection) LocalAddr() net.Addr { return c.mux.socket.LocalAddr() } + +func (*muxedConnection) SetDeadline(t time.Time) error { + // no deadline is desired here + return nil +} + +func (*muxedConnection) SetReadDeadline(t time.Time) error { + // no read deadline is desired here + return nil +} + +func (*muxedConnection) SetWriteDeadline(t time.Time) error { + // no write deadline is desired here + return nil +} diff --git a/go-libp2p/p2p/transport/websocket/addrs_test.go b/go-libp2p/p2p/transport/websocket/addrs_test.go index e2779fd..3c5ba50 100644 --- a/go-libp2p/p2p/transport/websocket/addrs_test.go +++ b/go-libp2p/p2p/transport/websocket/addrs_test.go @@ -73,9 +73,9 @@ func TestListeningOnDNSAddr(t *testing.T) { require.NoError(t, err) addr := ln.Multiaddr() first, rest := ma.SplitFirst(addr) - require.Equal(t, first.Protocol().Code, ma.P_DNS) - require.Equal(t, first.Value(), "localhost") + require.Equal(t, ma.P_DNS, first.Protocol().Code) + require.Equal(t, "localhost", first.Value()) next, _ := ma.SplitFirst(rest) - require.Equal(t, next.Protocol().Code, ma.P_TCP) - require.NotEqual(t, next.Value(), "0") + require.Equal(t, ma.P_TCP, next.Protocol().Code) + require.NotEqual(t, 0, next.Value()) } diff --git a/go-libp2p/p2p/transport/websocket/websocket.go b/go-libp2p/p2p/transport/websocket/websocket.go index e196512..5142ca9 100644 --- a/go-libp2p/p2p/transport/websocket/websocket.go +++ b/go-libp2p/p2p/transport/websocket/websocket.go @@ -120,7 +120,7 @@ func (t *WebsocketTransport) Proxy() bool { return false } -func (t *WebsocketTransport) Resolve(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error) { +func (t *WebsocketTransport) Resolve(_ context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error) { parsed, err := parseWebsocketMultiaddr(maddr) if err != nil { return nil, err @@ -136,7 +136,7 @@ func (t *WebsocketTransport) Resolve(ctx context.Context, maddr ma.Multiaddr) ([ // We don't have an sni component, we'll use dns/dnsaddr ma.ForEach(parsed.restMultiaddr, func(c ma.Component) bool { switch c.Protocol().Code { - case ma.P_DNS, ma.P_DNS4, ma.P_DNS6, ma.P_DNSADDR: + case ma.P_DNS, ma.P_DNS4, ma.P_DNS6: // err shouldn't happen since this means we couldn't parse a dns hostname for an sni value. parsed.sni, err = ma.NewComponent("sni", c.Value()) return false diff --git a/go-libp2p/p2p/transport/websocket/websocket_test.go b/go-libp2p/p2p/transport/websocket/websocket_test.go index aa06c62..2023ee3 100644 --- a/go-libp2p/p2p/transport/websocket/websocket_test.go +++ b/go-libp2p/p2p/transport/websocket/websocket_test.go @@ -525,12 +525,13 @@ func TestWriteZero(t *testing.T) { func TestResolveMultiaddr(t *testing.T) { // map[unresolved]resolved testCases := map[string]string{ + "/dns/example.com/tcp/1234/wss": "/dns/example.com/tcp/1234/tls/sni/example.com/ws", "/dns4/example.com/tcp/1234/wss": "/dns4/example.com/tcp/1234/tls/sni/example.com/ws", "/dns6/example.com/tcp/1234/wss": "/dns6/example.com/tcp/1234/tls/sni/example.com/ws", - "/dnsaddr/example.com/tcp/1234/wss": "/dnsaddr/example.com/tcp/1234/tls/sni/example.com/ws", + "/dnsaddr/example.com/tcp/1234/wss": "/dnsaddr/example.com/tcp/1234/wss", "/dns4/example.com/tcp/1234/tls/ws": "/dns4/example.com/tcp/1234/tls/sni/example.com/ws", "/dns6/example.com/tcp/1234/tls/ws": "/dns6/example.com/tcp/1234/tls/sni/example.com/ws", - "/dnsaddr/example.com/tcp/1234/tls/ws": "/dnsaddr/example.com/tcp/1234/tls/sni/example.com/ws", + "/dnsaddr/example.com/tcp/1234/tls/ws": "/dnsaddr/example.com/tcp/1234/tls/ws", } for unresolved, expectedMA := range testCases { diff --git a/go-libp2p/p2p/transport/webtransport/cert_manager_test.go b/go-libp2p/p2p/transport/webtransport/cert_manager_test.go index 29999a8..942d471 100644 --- a/go-libp2p/p2p/transport/webtransport/cert_manager_test.go +++ b/go-libp2p/p2p/transport/webtransport/cert_manager_test.go @@ -166,7 +166,7 @@ func TestGetCurrentBucketStartTimeIsWithinBounds(t *testing.T) { offset = offset % certValidity // Bound this to 100 years - timeSinceUnixEpoch = time.Duration(timeSinceUnixEpoch % (time.Hour * 24 * 365 * 100)) + timeSinceUnixEpoch = timeSinceUnixEpoch % (time.Hour * 24 * 365 * 100) // Start a bit further in the future to avoid edge cases around epoch timeSinceUnixEpoch += time.Hour * 24 * 365 start := time.UnixMilli(timeSinceUnixEpoch.Milliseconds()) diff --git a/go-libp2p/p2p/transport/webtransport/listener.go b/go-libp2p/p2p/transport/webtransport/listener.go index 337239f..2a7c354 100644 --- a/go-libp2p/p2p/transport/webtransport/listener.go +++ b/go-libp2p/p2p/transport/webtransport/listener.go @@ -212,5 +212,14 @@ func (l *listener) Close() error { l.reuseListener.Close() err := l.server.Close() <-l.serverClosed +loop: + for { + select { + case conn := <-l.queue: + conn.Close() + default: + break loop + } + } return err } diff --git a/go-libp2p/p2p/transport/webtransport/mock_connection_gater_test.go b/go-libp2p/p2p/transport/webtransport/mock_connection_gater_test.go index c6e7dba..245d254 100644 --- a/go-libp2p/p2p/transport/webtransport/mock_connection_gater_test.go +++ b/go-libp2p/p2p/transport/webtransport/mock_connection_gater_test.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/libp2p/go-libp2p/core/connmgr (interfaces: ConnectionGater) +// +// Generated by this command: +// +// mockgen -package libp2pwebtransport_test -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater +// // Package libp2pwebtransport_test is a generated GoMock package. package libp2pwebtransport_test @@ -7,11 +12,11 @@ package libp2pwebtransport_test import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" control "github.com/libp2p/go-libp2p/core/control" network "github.com/libp2p/go-libp2p/core/network" peer "github.com/libp2p/go-libp2p/core/peer" multiaddr "github.com/multiformats/go-multiaddr" + gomock "go.uber.org/mock/gomock" ) // MockConnectionGater is a mock of ConnectionGater interface. @@ -46,7 +51,7 @@ func (m *MockConnectionGater) InterceptAccept(arg0 network.ConnMultiaddrs) bool } // InterceptAccept indicates an expected call of InterceptAccept. -func (mr *MockConnectionGaterMockRecorder) InterceptAccept(arg0 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptAccept(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptAccept", reflect.TypeOf((*MockConnectionGater)(nil).InterceptAccept), arg0) } @@ -60,7 +65,7 @@ func (m *MockConnectionGater) InterceptAddrDial(arg0 peer.ID, arg1 multiaddr.Mul } // InterceptAddrDial indicates an expected call of InterceptAddrDial. -func (mr *MockConnectionGaterMockRecorder) InterceptAddrDial(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptAddrDial(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptAddrDial", reflect.TypeOf((*MockConnectionGater)(nil).InterceptAddrDial), arg0, arg1) } @@ -74,7 +79,7 @@ func (m *MockConnectionGater) InterceptPeerDial(arg0 peer.ID) bool { } // InterceptPeerDial indicates an expected call of InterceptPeerDial. -func (mr *MockConnectionGaterMockRecorder) InterceptPeerDial(arg0 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptPeerDial(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptPeerDial", reflect.TypeOf((*MockConnectionGater)(nil).InterceptPeerDial), arg0) } @@ -88,7 +93,7 @@ func (m *MockConnectionGater) InterceptSecured(arg0 network.Direction, arg1 peer } // InterceptSecured indicates an expected call of InterceptSecured. -func (mr *MockConnectionGaterMockRecorder) InterceptSecured(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptSecured(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptSecured", reflect.TypeOf((*MockConnectionGater)(nil).InterceptSecured), arg0, arg1, arg2) } @@ -103,7 +108,7 @@ func (m *MockConnectionGater) InterceptUpgraded(arg0 network.Conn) (bool, contro } // InterceptUpgraded indicates an expected call of InterceptUpgraded. -func (mr *MockConnectionGaterMockRecorder) InterceptUpgraded(arg0 interface{}) *gomock.Call { +func (mr *MockConnectionGaterMockRecorder) InterceptUpgraded(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterceptUpgraded", reflect.TypeOf((*MockConnectionGater)(nil).InterceptUpgraded), arg0) } diff --git a/go-libp2p/p2p/transport/webtransport/multiaddr.go b/go-libp2p/p2p/transport/webtransport/multiaddr.go index d6930af..bd90638 100644 --- a/go-libp2p/p2p/transport/webtransport/multiaddr.go +++ b/go-libp2p/p2p/transport/webtransport/multiaddr.go @@ -89,17 +89,23 @@ func IsWebtransportMultiaddr(multiaddr ma.Multiaddr) (bool, int) { certhashCount := 0 ma.ForEach(multiaddr, func(c ma.Component) bool { - if c.Protocol().Code == ma.P_QUIC_V1 && state == init { - state = foundUDP - } - if c.Protocol().Code == ma.P_QUIC_V1 && state == foundUDP { - state = foundQuicV1 - } - if c.Protocol().Code == ma.P_WEBTRANSPORT && state == foundQuicV1 { - state = foundWebTransport - } - if c.Protocol().Code == ma.P_CERTHASH && state == foundWebTransport { - certhashCount++ + switch c.Protocol().Code { + case ma.P_UDP: + if state == init { + state = foundUDP + } + case ma.P_QUIC_V1: + if state == foundUDP { + state = foundQuicV1 + } + case ma.P_WEBTRANSPORT: + if state == foundQuicV1 { + state = foundWebTransport + } + case ma.P_CERTHASH: + if state == foundWebTransport { + certhashCount++ + } } return true }) diff --git a/go-libp2p/p2p/transport/webtransport/multiaddr_test.go b/go-libp2p/p2p/transport/webtransport/multiaddr_test.go index 4e9d7c3..3f0a3ec 100644 --- a/go-libp2p/p2p/transport/webtransport/multiaddr_test.go +++ b/go-libp2p/p2p/transport/webtransport/multiaddr_test.go @@ -117,6 +117,7 @@ func TestIsWebtransportMultiaddr(t *testing.T) { {addr: "/ip4/1.2.3.4/udp/60042/quic-v1/webtransport/certhash/" + fooHash, want: true, certhashCount: 1}, {addr: "/ip4/1.2.3.4/udp/60042/quic-v1/webtransport/certhash/" + fooHash + "/certhash/" + barHash, want: true, certhashCount: 2}, {addr: "/dns4/example.com/udp/60042/quic-v1/webtransport/certhash/" + fooHash, want: true, certhashCount: 1}, + {addr: "/dns4/example.com/tcp/60042/quic-v1/webtransport/certhash/" + fooHash, want: false}, {addr: "/dns4/example.com/udp/60042/webrtc/certhash/" + fooHash, want: false}, } diff --git a/go-libp2p/p2p/transport/webtransport/transport.go b/go-libp2p/p2p/transport/webtransport/transport.go index 957d2ff..9717270 100644 --- a/go-libp2p/p2p/transport/webtransport/transport.go +++ b/go-libp2p/p2p/transport/webtransport/transport.go @@ -79,7 +79,7 @@ type transport struct { noise *noise.Transport connMx sync.Mutex - conns map[uint64]*conn // using quic-go's ConnectionTracingKey as map key + conns map[quic.ConnectionTracingID]*conn // using quic-go's ConnectionTracingKey as map key } var _ tpt.Transport = &transport{} @@ -105,7 +105,7 @@ func New(key ic.PrivKey, psk pnet.PSK, connManager *quicreuse.ConnManager, gater gater: gater, clock: clock.New(), connManager: connManager, - conns: map[uint64]*conn{}, + conns: map[quic.ConnectionTracingID]*conn{}, } for _, opt := range opts { if err := opt(t); err != nil { @@ -203,11 +203,10 @@ func (t *transport) dial(ctx context.Context, addr ma.Multiaddr, url, sni string return nil, err } dialer := webtransport.Dialer{ - RoundTripper: &http3.RoundTripper{ - Dial: func(ctx context.Context, addr string, tlsCfg *tls.Config, cfg *quic.Config) (quic.EarlyConnection, error) { - return conn.(quic.EarlyConnection), nil - }, + DialAddr: func(ctx context.Context, addr string, tlsCfg *tls.Config, cfg *quic.Config) (quic.EarlyConnection, error) { + return conn.(quic.EarlyConnection), nil }, + QUICConfig: t.connManager.ClientConfig().Clone(), } rsp, sess, err := dialer.Dial(ctx, url, nil) if err != nil { @@ -348,7 +347,7 @@ func (t *transport) allowWindowIncrease(conn quic.Connection, size uint64) bool t.connMx.Lock() defer t.connMx.Unlock() - c, ok := t.conns[conn.Context().Value(quic.ConnectionTracingKey).(uint64)] + c, ok := t.conns[conn.Context().Value(quic.ConnectionTracingKey).(quic.ConnectionTracingID)] if !ok { return false } @@ -357,13 +356,13 @@ func (t *transport) allowWindowIncrease(conn quic.Connection, size uint64) bool func (t *transport) addConn(sess *webtransport.Session, c *conn) { t.connMx.Lock() - t.conns[sess.Context().Value(quic.ConnectionTracingKey).(uint64)] = c + t.conns[sess.Context().Value(quic.ConnectionTracingKey).(quic.ConnectionTracingID)] = c t.connMx.Unlock() } func (t *transport) removeConn(sess *webtransport.Session) { t.connMx.Lock() - delete(t.conns, sess.Context().Value(quic.ConnectionTracingKey).(uint64)) + delete(t.conns, sess.Context().Value(quic.ConnectionTracingKey).(quic.ConnectionTracingID)) t.connMx.Unlock() } diff --git a/go-libp2p/p2p/transport/webtransport/transport_test.go b/go-libp2p/p2p/transport/webtransport/transport_test.go index 749d12f..f6c850a 100644 --- a/go-libp2p/p2p/transport/webtransport/transport_test.go +++ b/go-libp2p/p2p/transport/webtransport/transport_test.go @@ -28,7 +28,6 @@ import ( libp2pwebtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport" "github.com/benbjohnson/clock" - "github.com/golang/mock/gomock" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" "github.com/multiformats/go-multibase" @@ -37,6 +36,7 @@ import ( "github.com/quic-go/quic-go/http3" quicproxy "github.com/quic-go/quic-go/integrationtests/tools/proxy" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) const clockSkewAllowance = time.Hour @@ -97,7 +97,7 @@ func getCerthashComponent(t *testing.T, b []byte) ma.Multiaddr { func newConnManager(t *testing.T, opts ...quicreuse.Option) *quicreuse.ConnManager { t.Helper() - cm, err := quicreuse.NewConnManager([32]byte{}, opts...) + cm, err := quicreuse.NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}, opts...) require.NoError(t, err) t.Cleanup(func() { cm.Close() }) return cm @@ -178,7 +178,7 @@ func TestHashVerification(t *testing.T) { var trErr *quic.TransportError require.ErrorAs(t, err, &trErr) require.Equal(t, quic.TransportErrorCode(0x12a), trErr.ErrorCode) - require.Contains(t, trErr.ErrorMessage, "cert hash not found") + require.Contains(t, errors.Unwrap(trErr).Error(), "cert hash not found") }) t.Run("fails when adding a wrong hash", func(t *testing.T) { @@ -360,7 +360,7 @@ func TestResourceManagerListening(t *testing.T) { } // TODO: unify somehow. We do the same in libp2pquic. -//go:generate sh -c "go run github.com/golang/mock/mockgen -package libp2pwebtransport_test -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && go run golang.org/x/tools/cmd/goimports -w mock_connection_gater_test.go" +//go:generate sh -c "go run go.uber.org/mock/mockgen -package libp2pwebtransport_test -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && go run golang.org/x/tools/cmd/goimports -w mock_connection_gater_test.go" func TestConnectionGaterDialing(t *testing.T) { ctrl := gomock.NewController(t) @@ -650,7 +650,7 @@ func serverSendsBackValidCert(t *testing.T, timeSinceUnixEpoch time.Duration, ke } // Bound this to 100 years - timeSinceUnixEpoch = time.Duration(timeSinceUnixEpoch % (time.Hour * 24 * 365 * 100)) + timeSinceUnixEpoch = timeSinceUnixEpoch % (time.Hour * 24 * 365 * 100) // Start a bit further in the future to avoid edge cases around epoch timeSinceUnixEpoch += time.Hour * 24 * 365 start := time.UnixMilli(timeSinceUnixEpoch.Milliseconds()) @@ -729,7 +729,7 @@ func TestServerRotatesCertCorrectly(t *testing.T) { } // Bound this to 100 years - timeSinceUnixEpoch = time.Duration(timeSinceUnixEpoch % (time.Hour * 24 * 365 * 100)) + timeSinceUnixEpoch = timeSinceUnixEpoch % (time.Hour * 24 * 365 * 100) // Start a bit further in the future to avoid edge cases around epoch timeSinceUnixEpoch += time.Hour * 24 * 365 start := time.UnixMilli(timeSinceUnixEpoch.Milliseconds()) diff --git a/go-libp2p/package-list.json b/go-libp2p/package-list.json deleted file mode 100644 index fec3fac..0000000 --- a/go-libp2p/package-list.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "columns": [ - "Name", - "CI/Travis", - "Coverage", - "Description" - ], - "rows": [ - "Libp2p", - ["libp2p/go-libp2p", "go-libp2p", "go-libp2p entry point"], - ["libp2p/go-libp2p-core", "go-libp2p-core", "core interfaces, types, and abstractions"], - ["libp2p/go-libp2p-blankhost", "go-libp2p-blankhost", "minimal implementation of the \"host\" interface"], - - "Network", - ["libp2p/go-libp2p-swarm", "go-libp2p-swarm", "reference implementation of network state machine"], - - "Transport", - ["libp2p/go-ws-transport", "go-ws-transport", "WebSocket transport"], - ["libp2p/go-tcp-transport", "go-tcp-transport", "TCP transport"], - ["libp2p/go-libp2p-quic-transport", "go-libp2p-quic-transport", "QUIC transport"], - ["libp2p/go-udp-transport", "go-udp-transport", "UDP transport"], - ["libp2p/go-utp-transport", "go-utp-transport", "uTorrent transport (UTP)"], - ["libp2p/go-libp2p-circuit", "go-libp2p-circuit", "relay transport"], - ["libp2p/go-libp2p-transport-upgrader", "go-libp2p-transport-upgrader", "upgrades multiaddr-net connections into full libp2p transports"], - ["libp2p/go-libp2p-reuseport-transport", "go-libp2p-reuseport-transport", "partial transport for building transports that reuse ports"], - - "Encrypted Channels", - ["libp2p/go-libp2p-secio", "go-libp2p-secio", "SecIO crypto channel"], - ["libp2p/go-libp2p-tls-transport", "go-libp2p-tls-transport", "TLS 1.3+ crypto channel"], - ["libp2p/go-conn-security-multistream", "go-conn-security-multistream", "multistream multiplexed meta crypto channel"], - - "Private Network", - ["libp2p/go-libp2p-pnet", "go-libp2p-pnet", "reference private networking implementation"], - - "Stream Muxers", - ["libp2p/go-libp2p-yamux", "go-libp2p-yamux", "YAMUX stream multiplexer"], - ["libp2p/go-libp2p-mplex", "go-libp2p-mplex", "MPLEX stream multiplexer"], - - "NAT Traversal", - ["libp2p/go-libp2p-nat", "go-libp2p-nat"], - - "Peerstore", - ["libp2p/go-libp2p-peerstore", "go-libp2p-peerstore", "reference implementation of peer metadata storage component"], - - "Connection Manager", - ["libp2p/go-libp2p-connmgr", "go-libp2p-connmgr", "reference implementation of connection manager"], - - "Routing", - ["libp2p/go-libp2p-record", "go-libp2p-record", "record type and validator logic"], - ["libp2p/go-libp2p-kad-dht", "go-libp2p-kad-dht", "Kademlia-like router"], - ["libp2p/go-libp2p-kbucket", "go-libp2p-kbucket", "Kademlia routing table helper types"], - ["libp2p/go-libp2p-coral-dht", "go-libp2p-coral-dht", "Router based on Coral DHT"], - ["libp2p/go-libp2p-pubsub-router", "go-libp2p-pubsub-router", "record-store over pubsub adapter"], - - "Consensus", - ["libp2p/go-libp2p-consensus", "go-libp2p-consensus", "consensus protocols interfaces"], - ["libp2p/go-libp2p-raft", "go-libp2p-raft", "consensus implementation over raft"], - - "Pubsub", - ["libp2p/go-libp2p-pubsub", "go-libp2p-pubsub", "multiple pubsub over libp2p implementations"], - - "RPC", - ["libp2p/go-libp2p-gorpc", "go-libp2p-gorpc", "a simple RPC library for libp2p"], - - "Utilities/miscellaneous", - ["libp2p/go-libp2p-loggables", "go-libp2p-loggables", "logging helpers"], - ["libp2p/go-maddr-filter", "go-maddr-filter", "multiaddr filtering helpers"], - ["libp2p/go-libp2p-netutil", "go-libp2p-netutil", "misc utilities"], - ["libp2p/go-msgio", "go-msgio", "length prefixed data channel"], - ["libp2p/go-addr-util", "go-addr-util", "address utilities for libp2p swarm"], - ["libp2p/go-buffer-pool", "go-buffer-pool", "a variable size buffer pool for go"], - ["libp2p/go-libp2p-routing-helpers", "go-libp2p-routing-helpers", "routing helpers"], - ["libp2p/go-reuseport", "go-reuseport", "enables reuse of addresses"], - ["libp2p/go-sockaddr", "go-sockaddr", "utils for sockaddr conversions"], - ["libp2p/go-flow-metrics", "go-flow-metrics", "metrics library"], - ["libp2p/go-libp2p-gostream", "go-libp2p-gostream", "Go 'net' wrappers for libp2p"], - ["libp2p/go-libp2p-http", "go-libp2p-http", "HTTP on top of libp2p streams"], - - "Testing and examples", - ["libp2p/go-libp2p-testing", "go-libp2p-testing", "a collection of testing utilities for libp2p"] - ] -} diff --git a/go-libp2p/test-plans/PingDockerfile b/go-libp2p/test-plans/PingDockerfile index 1f19562..5c413aa 100644 --- a/go-libp2p/test-plans/PingDockerfile +++ b/go-libp2p/test-plans/PingDockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 # This is run from the parent directory to copy the whole go-libp2p codebase -FROM golang:1.19-alpine AS builder +FROM golang:1.21-alpine AS builder WORKDIR /app/ @@ -14,4 +14,4 @@ FROM alpine WORKDIR /app COPY --from=builder /testplan /testplan -ENTRYPOINT [ "/testplan"] \ No newline at end of file +ENTRYPOINT [ "/testplan"] diff --git a/go-libp2p/test-plans/README.md b/go-libp2p/test-plans/README.md index 1d180aa..0606f85 100644 --- a/go-libp2p/test-plans/README.md +++ b/go-libp2p/test-plans/README.md @@ -10,10 +10,10 @@ can dial/listen for ourselves we can do the following: 1. Start redis (needed by the tests): `docker run --rm -it -p 6379:6379 redis/redis-stack`. -2. In one terminal run the dialer: `REDIS_ADDR=localhost:6379 ip="0.0.0.0" +2. In one terminal run the dialer: `redis_addr=localhost:6379 ip="0.0.0.0" transport=quic-v1 security=quic muxer=quic is_dialer="true" go run ./cmd/ping` -3. In another terminal, run the listener: `REDIS_ADDR=localhost:6379 +3. In another terminal, run the listener: `redis_addr=localhost:6379 ip="0.0.0.0" transport=quic-v1 security=quic muxer=quic is_dialer="false" go run ./cmd/ping` @@ -29,9 +29,9 @@ the following (from the root directory of this repository): 1. Build the image: `docker build -t go-libp2p-head -f test-plans/PingDockerfile .`. 2. Build the images for all released versions in `libp2p/test-plans`: `(cd /libp2p/test-plans/multidim-interop/ && make)`. + to >/libp2p/test-plans/transport-interop/ && make)`. 3. Run the test: ``` -GO_LIBP2P="$PWD"; (cd /libp2p/test-plans/multidim-interop/ && npm run test -- --extra-version=$GO_LIBP2P/test-plans/ping-version.json --name-filter="go-libp2p-head") +GO_LIBP2P="$PWD"; (cd /libp2p/test-plans/transport-interop/ && npm run test -- --extra-version=$GO_LIBP2P/test-plans/ping-version.json --name-filter="go-libp2p-head") ``` diff --git a/go-libp2p/test-plans/cmd/ping/main.go b/go-libp2p/test-plans/cmd/ping/main.go index 24a3dbc..c836a72 100644 --- a/go-libp2p/test-plans/cmd/ping/main.go +++ b/go-libp2p/test-plans/cmd/ping/main.go @@ -15,13 +15,14 @@ import ( "strconv" "time" + libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc" + "github.com/go-redis/redis/v8" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/p2p/muxer/mplex" "github.com/libp2p/go-libp2p/p2p/muxer/yamux" "github.com/libp2p/go-libp2p/p2p/protocol/ping" - noise "github.com/libp2p/go-libp2p/p2p/security/noise" + "github.com/libp2p/go-libp2p/p2p/security/noise" libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls" libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic" "github.com/libp2p/go-libp2p/p2p/transport/tcp" @@ -98,15 +99,15 @@ func main() { case "tcp": options = append(options, libp2p.Transport(tcp.NewTCPTransport)) listenAddr = fmt.Sprintf("/ip4/%s/tcp/0", ip) - case "quic": - options = append(options, libp2p.Transport(libp2pquic.NewTransport)) - listenAddr = fmt.Sprintf("/ip4/%s/udp/0/quic", ip) case "quic-v1": options = append(options, libp2p.Transport(libp2pquic.NewTransport)) listenAddr = fmt.Sprintf("/ip4/%s/udp/0/quic-v1", ip) case "webtransport": options = append(options, libp2p.Transport(libp2pwebtransport.New)) listenAddr = fmt.Sprintf("/ip4/%s/udp/0/quic-v1/webtransport", ip) + case "webrtc-direct": + options = append(options, libp2p.Transport(libp2pwebrtc.New)) + listenAddr = fmt.Sprintf("/ip4/%s/udp/0/webrtc-direct", ip) default: log.Fatalf("Unsupported transport: %s", transport) } @@ -116,13 +117,11 @@ func main() { var skipMuxer bool var skipSecureChannel bool switch transport { - case "quic": - fallthrough case "quic-v1": fallthrough case "webtransport": fallthrough - case "webrtc": + case "webrtc-direct": skipMuxer = true skipSecureChannel = true } @@ -142,8 +141,6 @@ func main() { switch muxer { case "yamux": options = append(options, libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport)) - case "mplex": - options = append(options, libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport)) default: log.Fatalf("Unsupported muxer: %s", muxer) } diff --git a/go-libp2p/test-plans/go.mod b/go-libp2p/test-plans/go.mod index c752cbe..64361ed 100644 --- a/go-libp2p/test-plans/go.mod +++ b/go-libp2p/test-plans/go.mod @@ -1,11 +1,11 @@ module github.com/libp2p/go-libp2p/test-plans/m/v2 -go 1.19 +go 1.21 require ( github.com/go-redis/redis/v8 v8.11.5 github.com/libp2p/go-libp2p v0.0.0 - github.com/multiformats/go-multiaddr v0.10.1 + github.com/multiformats/go-multiaddr v0.12.4 ) require ( @@ -14,43 +14,40 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/containerd/cgroups v1.1.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/docker/go-units v0.5.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect - github.com/flynn/noise v1.0.0 // indirect + github.com/flynn/noise v1.1.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/mock v1.6.0 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/gopacket v1.1.19 // indirect - github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect - github.com/gorilla/websocket v1.5.0 // indirect - github.com/huin/goupnp v1.2.0 // indirect + github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect + github.com/google/uuid v1.4.0 // indirect + github.com/gorilla/websocket v1.5.1 // indirect + github.com/huin/goupnp v1.3.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect - github.com/klauspost/compress v1.16.7 // indirect - github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/klauspost/compress v1.17.8 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/koron/go-ssdp v0.0.4 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect - github.com/libp2p/go-cidranger v1.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect - github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect - github.com/libp2p/go-mplex v0.7.0 // indirect + github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect github.com/libp2p/go-nat v0.2.0 // indirect github.com/libp2p/go-netroute v0.2.1 // indirect - github.com/libp2p/go-reuseport v0.3.0 // indirect + github.com/libp2p/go-reuseport v0.4.0 // indirect github.com/libp2p/go-yamux/v4 v4.0.1 // indirect github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect - github.com/mattn/go-isatty v0.0.19 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/miekg/dns v1.1.55 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/miekg/dns v1.1.58 // indirect github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect github.com/minio/sha256-simd v1.0.1 // indirect @@ -62,37 +59,54 @@ require ( github.com/multiformats/go-multibase v0.2.0 // indirect github.com/multiformats/go-multicodec v0.9.0 // indirect github.com/multiformats/go-multihash v0.2.3 // indirect - github.com/multiformats/go-multistream v0.4.1 // indirect + github.com/multiformats/go-multistream v0.5.0 // indirect github.com/multiformats/go-varint v0.0.7 // indirect - github.com/onsi/ginkgo/v2 v2.11.0 // indirect - github.com/opencontainers/runtime-spec v1.0.2 // indirect + github.com/onsi/ginkgo/v2 v2.15.0 // indirect + github.com/opencontainers/runtime-spec v1.2.0 // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect + github.com/pion/datachannel v1.5.6 // indirect + github.com/pion/dtls/v2 v2.2.11 // indirect + github.com/pion/ice/v2 v2.3.24 // indirect + github.com/pion/interceptor v0.1.29 // indirect + github.com/pion/logging v0.2.2 // indirect + github.com/pion/mdns v0.0.12 // indirect + github.com/pion/randutil v0.1.0 // indirect + github.com/pion/rtcp v1.2.14 // indirect + github.com/pion/rtp v1.8.6 // indirect + github.com/pion/sctp v1.8.16 // indirect + github.com/pion/sdp/v3 v3.0.9 // indirect + github.com/pion/srtp/v2 v2.0.18 // indirect + github.com/pion/stun v0.6.1 // indirect + github.com/pion/transport/v2 v2.2.5 // indirect + github.com/pion/turn/v2 v2.1.6 // indirect + github.com/pion/webrtc/v3 v3.2.40 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/prometheus/client_golang v1.15.1 // indirect - github.com/prometheus/client_model v0.4.0 // indirect - github.com/prometheus/common v0.44.0 // indirect - github.com/prometheus/procfs v0.10.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/client_golang v1.19.1 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.48.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/qtls-go1-19 v0.3.3 // indirect - github.com/quic-go/qtls-go1-20 v0.2.3 // indirect - github.com/quic-go/quic-go v0.36.3 // indirect - github.com/quic-go/webtransport-go v0.5.3 // indirect + github.com/quic-go/quic-go v0.44.0 // indirect + github.com/quic-go/webtransport-go v0.8.0 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - go.uber.org/atomic v1.11.0 // indirect - go.uber.org/dig v1.17.0 // indirect - go.uber.org/fx v1.20.0 // indirect + github.com/stretchr/testify v1.9.0 // indirect + go.uber.org/dig v1.17.1 // indirect + go.uber.org/fx v1.21.1 // indirect + go.uber.org/mock v0.4.0 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.11.0 // indirect - golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect - golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.12.0 // indirect - golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.10.0 // indirect - golang.org/x/text v0.11.0 // indirect - golang.org/x/tools v0.11.0 // indirect - google.golang.org/protobuf v1.31.0 // indirect + go.uber.org/zap v1.27.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + golang.org/x/tools v0.21.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.2.1 // indirect ) diff --git a/go-libp2p/test-plans/go.sum b/go-libp2p/test-plans/go.sum index f5d7baf..63eac7a 100644 --- a/go-libp2p/test-plans/go.sum +++ b/go-libp2p/test-plans/go.sum @@ -37,8 +37,9 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= @@ -49,16 +50,18 @@ github.com/elastic/gosigar v0.12.0/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0 github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/4= github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= -github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= +github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg= +github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= @@ -75,39 +78,37 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 h1:n6vlPhxsA+BW/XsS5+uqi7GyzaLa5MH7qlSLBZtRdiA= -github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 h1:E/LAvt58di64hlYjx7AsNS6C/ysHWYo+2qPCZKTQhRo= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= -github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY= -github.com/huin/goupnp v1.2.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= +github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= +github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= -github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= -github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= @@ -120,38 +121,37 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= -github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= -github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= +github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= -github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c= -github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic= github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM= github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= -github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= -github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w= +github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94= +github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= -github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY= -github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU= +github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk= github.com/libp2p/go-nat v0.2.0/go.mod h1:3MJr+GRpRkyT65EpVPBstXLvOlAPzUVlG6Pwg9ohLJk= github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU= github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ= -github.com/libp2p/go-reuseport v0.3.0 h1:iiZslO5byUYZEg9iCwJGf5h+sf1Agmqx2V2FDjPyvUw= -github.com/libp2p/go-reuseport v0.3.0/go.mod h1:laea40AimhtfEqysZ71UpYj4S+R9VpH8PgqLo7L+SwI= +github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s= +github.com/libp2p/go-reuseport v0.4.0/go.mod h1:ZtI03j/wO5hZVDFo2jKywN6bYKWLOy8Se6DrI2E1cLU= github.com/libp2p/go-yamux/v4 v4.0.1 h1:FfDR4S1wj6Bw2Pqbc8Uz7pCxeRBPbwsBbEdfwiCypkQ= github.com/libp2p/go-yamux/v4 v4.0.1/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4= github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= @@ -159,15 +159,13 @@ github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= -github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo= -github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= +github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4= +github.com/miekg/dns v1.1.58/go.mod h1:Ypv+3b/KadlvW9vJfXOTf300O4UqaHFzFCuHz+rPkBY= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c h1:bzE/A84HN25pxAuk9Eej1Kz9OUelF97nAc82bDquQI8= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c/go.mod h1:0SQS9kMwD2VsyFEB++InYyBJroV/FRmBgcydeSUcJms= github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b h1:z78hV3sbSMAUoyUMM0I83AUIT6Hu17AWfgjzIbtrYFc= @@ -189,8 +187,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= -github.com/multiformats/go-multiaddr v0.10.1 h1:HghtFrWyZEPrpTvgAMFJi6gFdgHfs2cb0pyfDsk+lqU= -github.com/multiformats/go-multiaddr v0.10.1/go.mod h1:jLEZsA61rwWNZQTHHnqq2HNa+4os/Hz54eqiRnsRqYQ= +github.com/multiformats/go-multiaddr v0.12.4 h1:rrKqpY9h+n80EwhhC/kkcunCZZ7URIF8yN1WEUt2Hvc= +github.com/multiformats/go-multiaddr v0.12.4/go.mod h1:sBXrNzucqkFJhvKOiwwLyqamGa/P5EIXNPLovyhQCII= github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= @@ -202,53 +200,98 @@ github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI1 github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= -github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3de4741sbiSdfo= -github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= +github.com/multiformats/go-multistream v0.5.0 h1:5htLSLl7lvJk3xx3qT/8Zm9J4K8vEOf/QGkvOGQAyiE= +github.com/multiformats/go-multistream v0.5.0/go.mod h1:n6tMZiwiP2wUsR8DgfDWw1dydlEqV3l6N3/GBsX6ILA= github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY= +github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= -github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= -github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc= -github.com/opencontainers/runtime-spec v1.0.2 h1:UfAcuLBJB9Coz72x1hgl8O5RVzTdNiaglX6v2DM6FI0= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= +github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= +github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= +github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= +github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk= +github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= +github.com/pion/datachannel v1.5.6 h1:1IxKJntfSlYkpUj8LlYRSWpYiTTC02nUrOE8T3DqGeg= +github.com/pion/datachannel v1.5.6/go.mod h1:1eKT6Q85pRnr2mHiWHxJwO50SfZRtWHTsNIVb/NfGW4= +github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s= +github.com/pion/dtls/v2 v2.2.11 h1:9U/dpCYl1ySttROPWJgqWKEylUdT0fXp/xst6JwY5Ks= +github.com/pion/dtls/v2 v2.2.11/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE= +github.com/pion/ice/v2 v2.3.24 h1:RYgzhH/u5lH0XO+ABatVKCtRd+4U1GEaCXSMjNr13tI= +github.com/pion/ice/v2 v2.3.24/go.mod h1:KXJJcZK7E8WzrBEYnV4UtqEZsGeWfHxsNqhVcVvgjxw= +github.com/pion/interceptor v0.1.29 h1:39fsnlP1U8gw2JzOFWdfCU82vHvhW9o0rZnZF56wF+M= +github.com/pion/interceptor v0.1.29/go.mod h1:ri+LGNjRUc5xUNtDEPzfdkmSqISixVTBF/z/Zms/6T4= +github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY= +github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms= +github.com/pion/mdns v0.0.12 h1:CiMYlY+O0azojWDmxdNr7ADGrnZ+V6Ilfner+6mSVK8= +github.com/pion/mdns v0.0.12/go.mod h1:VExJjv8to/6Wqm1FXK+Ii/Z9tsVk/F5sD/N70cnYFbk= +github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= +github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= +github.com/pion/rtcp v1.2.12/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= +github.com/pion/rtcp v1.2.14 h1:KCkGV3vJ+4DAJmvP0vaQShsb0xkRfWkO540Gy102KyE= +github.com/pion/rtcp v1.2.14/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= +github.com/pion/rtp v1.8.3/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= +github.com/pion/rtp v1.8.6 h1:MTmn/b0aWWsAzux2AmP8WGllusBVw4NPYPVFFd7jUPw= +github.com/pion/rtp v1.8.6/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= +github.com/pion/sctp v1.8.13/go.mod h1:YKSgO/bO/6aOMP9LCie1DuD7m+GamiK2yIiPM6vH+GA= +github.com/pion/sctp v1.8.16 h1:PKrMs+o9EMLRvFfXq59WFsC+V8mN1wnKzqrv+3D/gYY= +github.com/pion/sctp v1.8.16/go.mod h1:P6PbDVA++OJMrVNg2AL3XtYHV4uD6dvfyOovCgMs0PE= +github.com/pion/sdp/v3 v3.0.9 h1:pX++dCHoHUwq43kuwf3PyJfHlwIj4hXA7Vrifiq0IJY= +github.com/pion/sdp/v3 v3.0.9/go.mod h1:B5xmvENq5IXJimIO4zfp6LAe1fD9N+kFv+V/1lOdz8M= +github.com/pion/srtp/v2 v2.0.18 h1:vKpAXfawO9RtTRKZJbG4y0v1b11NZxQnxRl85kGuUlo= +github.com/pion/srtp/v2 v2.0.18/go.mod h1:0KJQjA99A6/a0DOVTu1PhDSw0CXF2jTkqOoMg3ODqdA= +github.com/pion/stun v0.6.1 h1:8lp6YejULeHBF8NmV8e2787BogQhduZugh5PdhDyyN4= +github.com/pion/stun v0.6.1/go.mod h1:/hO7APkX4hZKu/D0f2lHzNyvdkTGtIy3NDmLR7kSz/8= +github.com/pion/transport/v2 v2.2.1/go.mod h1:cXXWavvCnFF6McHTft3DWS9iic2Mftcz1Aq29pGcU5g= +github.com/pion/transport/v2 v2.2.2/go.mod h1:OJg3ojoBJopjEeECq2yJdXH9YVrUJ1uQ++NjXLOUorc= +github.com/pion/transport/v2 v2.2.3/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= +github.com/pion/transport/v2 v2.2.4/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= +github.com/pion/transport/v2 v2.2.5 h1:iyi25i/21gQck4hfRhomF6SktmUQjRsRW4WJdhfc3Kc= +github.com/pion/transport/v2 v2.2.5/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= +github.com/pion/transport/v3 v3.0.1/go.mod h1:UY7kiITrlMv7/IKgd5eTUcaahZx5oUN3l9SzK5f5xE0= +github.com/pion/transport/v3 v3.0.2 h1:r+40RJR25S9w3jbA6/5uEPTzcdn7ncyU44RWCbHkLg4= +github.com/pion/transport/v3 v3.0.2/go.mod h1:nIToODoOlb5If2jF9y2Igfx3PFYWfuXi37m0IlWa/D0= +github.com/pion/turn/v2 v2.1.3/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= +github.com/pion/turn/v2 v2.1.6 h1:Xr2niVsiPTB0FPtt+yAWKFUkU1eotQbGgpTIld4x1Gc= +github.com/pion/turn/v2 v2.1.6/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= +github.com/pion/webrtc/v3 v3.2.40 h1:Wtfi6AZMQg+624cvCXUuSmrKWepSB7zfgYDOYqsSOVU= +github.com/pion/webrtc/v3 v3.2.40/go.mod h1:M1RAe3TNTD1tzyvqHrbVODfwdPGSXOUo/OgpoGGJqFY= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI= -github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk= +github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= +github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= -github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY= -github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= +github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= +github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= -github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/qtls-go1-19 v0.3.3 h1:wznEHvJwd+2X3PqftRha0SUKmGsnb6dfArMhy9PeJVE= -github.com/quic-go/qtls-go1-19 v0.3.3/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.2.3 h1:m575dovXn1y2ATOb1XrRFcrv0F+EQmlowTkoraNkDPI= -github.com/quic-go/qtls-go1-20 v0.2.3/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.36.3 h1:f+yOqeGhMoRX7/M3wmEw/djhzKWr15FtQysox85/834= -github.com/quic-go/quic-go v0.36.3/go.mod h1:qxQumdeKw5GmWs1OsTZZnOxzSI+RJWuhf1O8FN35L2o= -github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= -github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= +github.com/quic-go/quic-go v0.44.0 h1:So5wOr7jyO4vzL2sd8/pD9Kesciv91zSk8BoFngItQ0= +github.com/quic-go/quic-go v0.44.0/go.mod h1:z4cx/9Ny9UtGITIPzmPTXh1ULfOyWh4qGQlpnPcWmek= +github.com/quic-go/webtransport-go v0.8.0 h1:HxSrwun11U+LlmwpgM1kEqIqH90IT4N8auv/cD7QFJg= +github.com/quic-go/webtransport-go v0.8.0/go.mod h1:N99tjprW432Ut5ONql/aUhSLT0YVSlwHohQsuac9WaM= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= @@ -281,12 +324,20 @@ github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= @@ -294,22 +345,24 @@ github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMI github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= -go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI= -go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU= -go.uber.org/fx v1.20.0 h1:ZMC/pnRvhsthOZh9MZjMq5U8Or3mA9zBSPaLnzs3ihQ= -go.uber.org/fx v1.20.0/go.mod h1:qCUj0btiR3/JnanEr1TYEePfSw6o/4qYJscgvzQ5Ub0= +go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc= +go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE= +go.uber.org/fx v1.21.1 h1:RqBh3cYdzZS0uqwVeEjOX2p73dddLpym315myy/Bpb0= +go.uber.org/fx v1.21.1/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= -go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -320,11 +373,18 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= +golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw= -golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -334,8 +394,10 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -352,8 +414,17 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= -golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= +golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -367,8 +438,10 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -384,19 +457,47 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= +golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= +golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -408,10 +509,11 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= -golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw= +golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -432,22 +534,23 @@ google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmE google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/go-libp2p/test-plans/ping-version.json b/go-libp2p/test-plans/ping-version.json index b7ad530..705934f 100644 --- a/go-libp2p/test-plans/ping-version.json +++ b/go-libp2p/test-plans/ping-version.json @@ -5,16 +5,15 @@ "tcp", "ws", "wss", - "quic", "quic-v1", - "webtransport" + "webtransport", + "webrtc-direct" ], "secureChannels": [ "tls", "noise" ], "muxers": [ - "mplex", "yamux" ] -} \ No newline at end of file +} diff --git a/go-libp2p/tools.go b/go-libp2p/tools.go index 46a8037..7a650d9 100644 --- a/go-libp2p/tools.go +++ b/go-libp2p/tools.go @@ -3,7 +3,7 @@ package libp2p import ( - _ "github.com/golang/mock/mockgen" + _ "go.uber.org/mock/mockgen" _ "golang.org/x/tools/cmd/goimports" _ "google.golang.org/protobuf/cmd/protoc-gen-go" ) diff --git a/go-libp2p/version.json b/go-libp2p/version.json index a99fc2b..fb0aea4 100644 --- a/go-libp2p/version.json +++ b/go-libp2p/version.json @@ -1,3 +1,3 @@ { - "version": "v0.29.0" + "version": "v0.35.0" } diff --git a/go.mod b/go.mod index 8308f25..ec72743 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module source.quilibrium.com/quilibrium/monorepo -go 1.18 \ No newline at end of file +go 1.18 diff --git a/node/app/db_console.go b/node/app/db_console.go index f1bdbdc..5ced8fc 100644 --- a/node/app/db_console.go +++ b/node/app/db_console.go @@ -819,16 +819,11 @@ func FetchTokenBalance(client protobufs.NodeServiceClient) (TokenBalance, error) return TokenBalance{}, errors.Wrap(err, "error getting token info") } - conversionFactor, _ := new(big.Int).SetString("1DCD65000", 16) - - owned := new(big.Int).SetBytes(info.OwnedTokens) - owned.Div(owned, conversionFactor) - + // owned := new(big.Int).SetBytes(info.OwnedTokens) unconfirmedOwned := new(big.Int).SetBytes(info.UnconfirmedOwnedTokens) - unconfirmedOwned.Div(unconfirmedOwned, conversionFactor) return TokenBalance{ - Owned: owned, + // Owned: owned, UnconfirmedOwned: unconfirmedOwned, }, nil } @@ -869,26 +864,26 @@ func logoVersion(width int) string { out += " ..---'''' ''''---..\n" out += " .---'' ''---.\n" out += " .-' '-.\n" - out += " ..-' ..--'''''''''''%######################\n" - out += " .' .--'' #################\n" - out += " .'' ..-' ###############\n" - out += " ' ' ##############\n" - out += " '' .'' ############&\n" - out += " ' '' ############\n" - out += " ' ' ########## &###########\n" - out += " ' ' ############## ###########\n" - out += " ' ' ############## ##########&\n" - out += " ' ' ############## ##########\n" - out += "' ' ########## ##########\n" - out += "' ' ##########\n" - out += "' ' &#########\n" - out += "' ' ####### ####### ##########\n" - out += "' ' &######################### ##########\n" - out += " ' ' ##############% ############## &##########\n" - out += " ' ' &############## ############### ##########\n" - out += " ' ' ############### ##############% ###########\n" - out += " ' '. ########## ############### ########\n" - out += " '. . ##### ##############% ####\n" + out += " ..-' ..--''''''''''''''--.. '-..\n" + out += " .' .--'' ''--. ''.\n" + out += " .'' ..-' ''-. '.\n" + out += " ' ' ''. '.\n" + out += " '' .'' '. '\n" + out += " ' '' '. '\n" + out += " ' ' ########## . '\n" + out += " ' ' ############## ' '\n" + out += " ' ' ############## ' '\n" + out += " ' ' ############## ' '\n" + out += "' ' ########## ' '\n" + out += "' ' ' '\n" + out += "' ' ' '\n" + out += "' ' ####### ####### ' '\n" + out += "' ' &######################### ' '\n" + out += "' ' ##############% ############## ' '\n" + out += " ' ' &############## ############### ' '\n" + out += " ' ' ############### ##############% '. '\n" + out += " ' '. ########## ############### '-. '\n" + out += " '. . ##### ##############% '-.'\n" out += " ' '. ###############\n" out += " '. '.. ##############%\n" out += " '. '-. ###############\n" @@ -899,11 +894,11 @@ func logoVersion(width int) string { out += " ''---.. ...---'' ##\n" out += " ''----------''\n" out += " \n" - out += " Quilibrium Node - v" + config.GetVersionString() + " – Nebula\n" + out += " Quilibrium Node - v" + config.GetVersionString() + " – Betelgeuse\n" out += " \n" out += " DB Console\n" } else { - out = "Quilibrium Node - v" + config.GetVersionString() + " – Nebula - DB Console\n" + out = "Quilibrium Node - v" + config.GetVersionString() + " – Betelgeuse - DB Console\n" } return out } diff --git a/node/app/node.go b/node/app/node.go index d6e172e..93406bc 100644 --- a/node/app/node.go +++ b/node/app/node.go @@ -1,27 +1,28 @@ package app import ( - "bytes" "errors" + "fmt" "go.uber.org/zap" + "golang.org/x/crypto/sha3" "source.quilibrium.com/quilibrium/monorepo/node/consensus" "source.quilibrium.com/quilibrium/monorepo/node/consensus/master" + "source.quilibrium.com/quilibrium/monorepo/node/crypto" "source.quilibrium.com/quilibrium/monorepo/node/execution" - "source.quilibrium.com/quilibrium/monorepo/node/execution/intrinsics/ceremony/application" "source.quilibrium.com/quilibrium/monorepo/node/keys" "source.quilibrium.com/quilibrium/monorepo/node/p2p" "source.quilibrium.com/quilibrium/monorepo/node/store" - "source.quilibrium.com/quilibrium/monorepo/node/tries" ) type Node struct { - logger *zap.Logger - clockStore store.ClockStore - keyManager keys.KeyManager - pubSub p2p.PubSub - execEngines map[string]execution.ExecutionEngine - engine consensus.ConsensusEngine + logger *zap.Logger + dataProofStore store.DataProofStore + clockStore store.ClockStore + keyManager keys.KeyManager + pubSub p2p.PubSub + execEngines map[string]execution.ExecutionEngine + engine consensus.ConsensusEngine } type DHTNode struct { @@ -40,6 +41,7 @@ func newDHTNode( func newNode( logger *zap.Logger, + dataProofStore store.DataProofStore, clockStore store.ClockStore, keyManager keys.KeyManager, pubSub p2p.PubSub, @@ -54,6 +56,7 @@ func newNode( return &Node{ logger, + dataProofStore, clockStore, keyManager, pubSub, @@ -62,78 +65,115 @@ func newNode( }, nil } -func (n *Node) RunRepair() { - intrinsicFilter := append( - p2p.GetBloomFilter(application.CEREMONY_ADDRESS, 256, 3), - p2p.GetBloomFilterIndices(application.CEREMONY_ADDRESS, 65536, 24)..., - ) - n.logger.Info("check store and repair if needed, this may take a few minutes") - proverTrie := &tries.RollingFrecencyCritbitTrie{} - head, err := n.clockStore.GetLatestDataClockFrame(intrinsicFilter, proverTrie) - if err == nil && head != nil { - for head != nil && head.FrameNumber != 0 { - prev := head - head, err = n.clockStore.GetStagedDataClockFrame( - intrinsicFilter, - head.FrameNumber-1, - head.ParentSelector, - true, - ) - if err != nil { - panic(err) - } - compare, _, err := n.clockStore.GetDataClockFrame( - intrinsicFilter, - prev.FrameNumber-1, - true, - ) - if err != nil { - panic(err) - } - if !bytes.Equal(head.Output, compare.Output) { - n.logger.Warn( - "repairing frame", - zap.Uint64("frame_number", head.FrameNumber), - ) - head, err = n.clockStore.GetStagedDataClockFrame( - intrinsicFilter, - prev.FrameNumber-1, - prev.ParentSelector, - true, - ) - if err != nil { - panic(err) - } +func (n *Node) VerifyProofIntegrity() { + i, _, _, e := n.dataProofStore.GetLatestDataTimeProof(n.pubSub.GetPeerID()) + if e != nil { + panic(e) + } + dataProver := crypto.NewKZGInclusionProver(n.logger) + wesoProver := crypto.NewWesolowskiFrameProver(n.logger) - txn, err := n.clockStore.NewTransaction() - if err != nil { - panic(err) - } + for j := int(i); j >= 0; j-- { + fmt.Println(j) + _, _, input, o, err := n.dataProofStore.GetDataTimeProof(n.pubSub.GetPeerID(), uint32(j)) + if err != nil { + panic(err) + } + idx, idxProof, idxCommit, idxKP := master.GetOutputs(o) - selector, err := head.GetSelector() - if err != nil { - panic(err) - } + ip := sha3.Sum512(idxProof) - err = n.clockStore.CommitDataClockFrame( - intrinsicFilter, - head.FrameNumber, - selector.FillBytes(make([]byte, 32)), - proverTrie, - txn, - true, - ) - if err != nil { - panic(err) - } + v, err := dataProver.VerifyRaw(ip[:], idxCommit, int(idx), idxKP, 128) + if err != nil { + panic(err) + } - if err = txn.Commit(); err != nil { - panic(err) - } - } + if !v { + panic("bad kzg proof") + } + wp := []byte{} + wp = append(wp, n.pubSub.GetPeerID()...) + wp = append(wp, input...) + fmt.Printf("%x\n", wp) + v = wesoProver.VerifyChallengeProof(wp, uint32(j), idx, idxProof) + if !v { + panic("bad weso proof") } } - n.logger.Info("check complete") +} + +func (n *Node) RunRepair() { + // intrinsicFilter := append( + // p2p.GetBloomFilter(application.CEREMONY_ADDRESS, 256, 3), + // p2p.GetBloomFilterIndices(application.CEREMONY_ADDRESS, 65536, 24)..., + // ) + // n.logger.Info("check store and repair if needed, this may take a few minutes") + // proverTrie := &tries.RollingFrecencyCritbitTrie{} + // head, err := n.clockStore.GetLatestDataClockFrame(intrinsicFilter, proverTrie) + // if err == nil && head != nil { + // for head != nil && head.FrameNumber != 0 { + // prev := head + // head, err = n.clockStore.GetStagedDataClockFrame( + // intrinsicFilter, + // head.FrameNumber-1, + // head.ParentSelector, + // true, + // ) + // if err != nil { + // panic(err) + // } + // compare, _, err := n.clockStore.GetDataClockFrame( + // intrinsicFilter, + // prev.FrameNumber-1, + // true, + // ) + // if err != nil { + // panic(err) + // } + // if !bytes.Equal(head.Output, compare.Output) { + // n.logger.Warn( + // "repairing frame", + // zap.Uint64("frame_number", head.FrameNumber), + // ) + // head, err = n.clockStore.GetStagedDataClockFrame( + // intrinsicFilter, + // prev.FrameNumber-1, + // prev.ParentSelector, + // true, + // ) + // if err != nil { + // panic(err) + // } + + // txn, err := n.clockStore.NewTransaction() + // if err != nil { + // panic(err) + // } + + // selector, err := head.GetSelector() + // if err != nil { + // panic(err) + // } + + // err = n.clockStore.CommitDataClockFrame( + // intrinsicFilter, + // head.FrameNumber, + // selector.FillBytes(make([]byte, 32)), + // proverTrie, + // txn, + // true, + // ) + // if err != nil { + // panic(err) + // } + + // if err = txn.Commit(); err != nil { + // panic(err) + // } + // } + // } + // } + // n.logger.Info("check complete") } func (d *DHTNode) Start() { @@ -173,6 +213,10 @@ func (n *Node) GetClockStore() store.ClockStore { return n.clockStore } +func (n *Node) GetDataProofStore() store.DataProofStore { + return n.dataProofStore +} + func (n *Node) GetKeyManager() keys.KeyManager { return n.keyManager } diff --git a/node/app/wire_gen.go b/node/app/wire_gen.go index 232e93d..a2ef0a9 100644 --- a/node/app/wire_gen.go +++ b/node/app/wire_gen.go @@ -38,17 +38,19 @@ func NewDebugNode(configConfig *config.Config, selfTestReport *protobufs.SelfTes zapLogger := debugLogger() dbConfig := configConfig.DB pebbleDB := store.NewPebbleDB(dbConfig) + pebbleDataProofStore := store.NewPebbleDataProofStore(pebbleDB, zapLogger) pebbleClockStore := store.NewPebbleClockStore(pebbleDB, zapLogger) keyConfig := configConfig.Key fileKeyManager := keys.NewFileKeyManager(keyConfig, zapLogger) p2PConfig := configConfig.P2P blossomSub := p2p.NewBlossomSub(p2PConfig, zapLogger) engineConfig := configConfig.Engine + kzgInclusionProver := crypto.NewKZGInclusionProver(zapLogger) wesolowskiFrameProver := crypto.NewWesolowskiFrameProver(zapLogger) masterTimeReel := time.NewMasterTimeReel(zapLogger, pebbleClockStore, engineConfig, wesolowskiFrameProver) inMemoryPeerInfoManager := p2p.NewInMemoryPeerInfoManager(zapLogger) - masterClockConsensusEngine := master.NewMasterClockConsensusEngine(engineConfig, zapLogger, pebbleClockStore, fileKeyManager, blossomSub, wesolowskiFrameProver, masterTimeReel, inMemoryPeerInfoManager, selfTestReport) - node, err := newNode(zapLogger, pebbleClockStore, fileKeyManager, blossomSub, masterClockConsensusEngine) + masterClockConsensusEngine := master.NewMasterClockConsensusEngine(engineConfig, zapLogger, pebbleDataProofStore, pebbleClockStore, fileKeyManager, blossomSub, kzgInclusionProver, wesolowskiFrameProver, masterTimeReel, inMemoryPeerInfoManager, selfTestReport) + node, err := newNode(zapLogger, pebbleDataProofStore, pebbleClockStore, fileKeyManager, blossomSub, masterClockConsensusEngine) if err != nil { return nil, err } @@ -59,17 +61,19 @@ func NewNode(configConfig *config.Config, selfTestReport *protobufs.SelfTestRepo zapLogger := logger() dbConfig := configConfig.DB pebbleDB := store.NewPebbleDB(dbConfig) + pebbleDataProofStore := store.NewPebbleDataProofStore(pebbleDB, zapLogger) pebbleClockStore := store.NewPebbleClockStore(pebbleDB, zapLogger) keyConfig := configConfig.Key fileKeyManager := keys.NewFileKeyManager(keyConfig, zapLogger) p2PConfig := configConfig.P2P blossomSub := p2p.NewBlossomSub(p2PConfig, zapLogger) engineConfig := configConfig.Engine + kzgInclusionProver := crypto.NewKZGInclusionProver(zapLogger) wesolowskiFrameProver := crypto.NewWesolowskiFrameProver(zapLogger) masterTimeReel := time.NewMasterTimeReel(zapLogger, pebbleClockStore, engineConfig, wesolowskiFrameProver) inMemoryPeerInfoManager := p2p.NewInMemoryPeerInfoManager(zapLogger) - masterClockConsensusEngine := master.NewMasterClockConsensusEngine(engineConfig, zapLogger, pebbleClockStore, fileKeyManager, blossomSub, wesolowskiFrameProver, masterTimeReel, inMemoryPeerInfoManager, selfTestReport) - node, err := newNode(zapLogger, pebbleClockStore, fileKeyManager, blossomSub, masterClockConsensusEngine) + masterClockConsensusEngine := master.NewMasterClockConsensusEngine(engineConfig, zapLogger, pebbleDataProofStore, pebbleClockStore, fileKeyManager, blossomSub, kzgInclusionProver, wesolowskiFrameProver, masterTimeReel, inMemoryPeerInfoManager, selfTestReport) + node, err := newNode(zapLogger, pebbleDataProofStore, pebbleClockStore, fileKeyManager, blossomSub, masterClockConsensusEngine) if err != nil { return nil, err } diff --git a/node/build.sh b/node/build.sh new file mode 100755 index 0000000..4d90933 --- /dev/null +++ b/node/build.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -euxo pipefail + +# This script builds the node binary for the current platform and statically links it with VDF static lib. +# Assumes that the VDF library has been built by running the generate.sh script in the `../vdf` directory. + +ROOT_DIR="${ROOT_DIR:-$( cd "$(dirname "$(realpath "$( dirname "${BASH_SOURCE[0]}" )")")" >/dev/null 2>&1 && pwd )}" + +NODE_DIR="$ROOT_DIR/node" +BINARIES_DIR="$ROOT_DIR/target/release" + +pushd "$NODE_DIR" > /dev/null + +export CGO_ENABLED=1 +export GOEXPERIMENT=arenas + +os_type="$(uname)" +case "$os_type" in + "Darwin") + # Check if the architecture is ARM + if [[ "$(uname -m)" == "arm64" ]]; then + # MacOS ld doesn't support -Bstatic and -Bdynamic, so it's important that there is only a static version of the library + go build -ldflags "-linkmode 'external' -extldflags '-L$BINARIES_DIR -lvdf -ldl -lm'" "$@" + else + echo "Unsupported platform" + exit 1 + fi + ;; + "Linux") + go build -ldflags "-linkmode 'external' -extldflags '-L$BINARIES_DIR -Wl,-Bstatic -lvdf -Wl,-Bdynamic -ldl -lm'" "$@" + ;; + *) + echo "Unsupported platform" + exit 1 + ;; +esac diff --git a/node/config/config.go b/node/config/config.go index 414693e..624537b 100644 --- a/node/config/config.go +++ b/node/config/config.go @@ -9,6 +9,7 @@ import ( "io/fs" "os" "path/filepath" + "strings" "github.com/cloudflare/circl/sign/ed448" "github.com/libp2p/go-libp2p/core/crypto" @@ -45,31 +46,31 @@ func NewConfig(configPath string) (*Config, error) { } var BootstrapPeers = []string{ - "/dns/bootstrap.quilibrium.com/udp/8336/quic/p2p/Qme3g6rJWuz8HVXxpDb7aV2hiFq8bZJNqxMmwzmASzfq1M", - "/dns/quaalude.quilibrium.com/udp/8336/quic/p2p/QmYruNcruYNgyTKeUqJSxjbuTFYWYDw2r5df9YKMGWCRKA", - "/dns/quecifer.quilibrium.com/udp/8336/quic/p2p/QmdWF9bGTH5mwJXkxrG859HA5r34MxXtMSTuEikSMDSESv", - "/dns/quantum.quilibrium.com/udp/8336/quic/p2p/QmbmVeKnSWK9HHAQHSS714XU3gx77TrS356JmHmKFj7q7M", - "/dns/quidditas.quilibrium.com/udp/8336/quic/p2p/QmR1rF5E9zAob9FZyMF7uTUM27D7GYtX9RaiSsNY9UP72J", - "/dns/quillon.quilibrium.com/udp/8336/quic/p2p/QmWgHv6z3tyimW4JvrvYRgsJEimgV7J2xbE7QEpFNPvAnB", - "/dns/quidditch.quilibrium.com/udp/8336/quic/p2p/QmbZEGuinaCndj4XLb6fteZmjmP3C1Tsgijmc5BGuUk8Ma", - "/dns/quagmire.quilibrium.com/udp/8336/quic/p2p/QmaQ9KAaKtqXhYSQ5ARQNnn8B8474cWGvvD6PgJ4gAtMrx", - "/ip4/204.186.74.46/udp/8316/quic/p2p/QmeqBjm3iX7sdTieyto1gys5ruQrQNPKfaTGcVQQWJPYDV", - "/ip4/103.219.170.9/udp/8336/quic/p2p/QmfEdMfmdhNoYuGVhhw5LBApHHG1rbVAHXwGWpW8s9bXeg", - "/ip4/185.143.102.84/udp/8336/quic/p2p/Qmce68gLLq9eMdwCcmd1ptfoC2nVoe861LF1cjdVHC2DwK", - "/ip4/65.109.17.13/udp/8336/quic/p2p/Qmc35n99eojSvW3PkbfBczJoSX92WmnnKh3Fg114ok3oo4", - "/ip4/65.108.194.84/udp/8336/quic/p2p/QmP8C7g9ZRiWzhqN2AgFu5onS6HwHzR6Vv1TCHxAhnCSnq", - "/dns/quil.dfcnodes.eu/udp/8336/quic/p2p/QmQaFmbYVrKSwoen5UQdaqyDq4QhXfSSLDVnYpYD4SF9tX", - "/ip4/87.98.167.207/udp/8336/quic/p2p/QmafiAXLu1JWktyfzDtD67i78GRBYCfQ4doTfq7pp7wfQ1", - "/ip4/216.244.76.122/udp/8336/quic/p2p/QmUSbMytVBUYiiGE266aZHrHrP17vLx5UJFd7o74HkDoaV", - "/ip4/216.244.79.194/udp/8336/quic/p2p/QmQn3bWk5aqaNSv9dwPjBg4qdeGBGNEB72tvuhgEc64Ki5", + "/dns/bootstrap.quilibrium.com/udp/8336/quic-v1/p2p/Qme3g6rJWuz8HVXxpDb7aV2hiFq8bZJNqxMmwzmASzfq1M", + "/dns/quaalude.quilibrium.com/udp/8336/quic-v1/p2p/QmYruNcruYNgyTKeUqJSxjbuTFYWYDw2r5df9YKMGWCRKA", + "/dns/quecifer.quilibrium.com/udp/8336/quic-v1/p2p/QmdWF9bGTH5mwJXkxrG859HA5r34MxXtMSTuEikSMDSESv", + "/dns/quantum.quilibrium.com/udp/8336/quic-v1/p2p/QmbmVeKnSWK9HHAQHSS714XU3gx77TrS356JmHmKFj7q7M", + "/dns/quidditas.quilibrium.com/udp/8336/quic-v1/p2p/QmR1rF5E9zAob9FZyMF7uTUM27D7GYtX9RaiSsNY9UP72J", + "/dns/quillon.quilibrium.com/udp/8336/quic-v1/p2p/QmWgHv6z3tyimW4JvrvYRgsJEimgV7J2xbE7QEpFNPvAnB", + "/dns/quidditch.quilibrium.com/udp/8336/quic-v1/p2p/QmbZEGuinaCndj4XLb6fteZmjmP3C1Tsgijmc5BGuUk8Ma", + "/dns/quagmire.quilibrium.com/udp/8336/quic-v1/p2p/QmaQ9KAaKtqXhYSQ5ARQNnn8B8474cWGvvD6PgJ4gAtMrx", + "/ip4/204.186.74.46/udp/8316/quic-v1/p2p/QmeqBjm3iX7sdTieyto1gys5ruQrQNPKfaTGcVQQWJPYDV", + "/ip4/103.219.170.9/udp/8336/quic-v1/p2p/QmfEdMfmdhNoYuGVhhw5LBApHHG1rbVAHXwGWpW8s9bXeg", + "/ip4/185.143.102.84/udp/8336/quic-v1/p2p/Qmce68gLLq9eMdwCcmd1ptfoC2nVoe861LF1cjdVHC2DwK", + "/ip4/65.109.17.13/udp/8336/quic-v1/p2p/Qmc35n99eojSvW3PkbfBczJoSX92WmnnKh3Fg114ok3oo4", + "/ip4/65.108.194.84/udp/8336/quic-v1/p2p/QmP8C7g9ZRiWzhqN2AgFu5onS6HwHzR6Vv1TCHxAhnCSnq", + "/dns/quil.dfcnodes.eu/udp/8336/quic-v1/p2p/QmQaFmbYVrKSwoen5UQdaqyDq4QhXfSSLDVnYpYD4SF9tX", + "/ip4/87.98.167.207/udp/8336/quic-v1/p2p/QmafiAXLu1JWktyfzDtD67i78GRBYCfQ4doTfq7pp7wfQ1", + "/ip4/216.244.76.122/udp/8336/quic-v1/p2p/QmUSbMytVBUYiiGE266aZHrHrP17vLx5UJFd7o74HkDoaV", + "/ip4/216.244.79.194/udp/8336/quic-v1/p2p/QmQn3bWk5aqaNSv9dwPjBg4qdeGBGNEB72tvuhgEc64Ki5", // purged peers (keep your node online to return to this list) - // "/ip4/204.186.74.47/udp/8317/quic/p2p/Qmd233pLUDvcDW3ama27usfbG1HxKNh1V9dmWVW1SXp1pd", - // "/ip4/186.233.184.181/udp/8336/quic/p2p/QmW6QDvKuYqJYYMP5tMZSp12X3nexywK28tZNgqtqNpEDL", - // "/dns/quil.zanshindojo.org/udp/8336/quic/p2p/QmXbbmtS5D12rEc4HWiHWr6e83SCE4jeThPP4VJpAQPvXq", - // "/ip4/144.76.104.93/udp/8336/quic/p2p/QmZejZ8DBGQ6foX9recW73GA6TqL6hCMX9ETWWW1Fb8xtx", - // "/ip4/207.246.81.38/udp/8336/quic/p2p/QmPBYgDy7snHon7PAn8nv1shApQBQz1iHb2sBBS8QSgQwW", - // "/dns/abyssia.fr/udp/8336/quic/p2p/QmS7C1UhN8nvzLJgFFf1uspMRrXjJqThHNN6AyEXp6oVUB", - // "/ip4/51.15.18.247/udp/8336/quic/p2p/QmYVaHXdFmHFeTa6oPixgjMVag6Ex7gLjE559ejJddwqzu", + // "/ip4/204.186.74.47/udp/8317/quic-v1/p2p/Qmd233pLUDvcDW3ama27usfbG1HxKNh1V9dmWVW1SXp1pd", + // "/ip4/186.233.184.181/udp/8336/quic-v1/p2p/QmW6QDvKuYqJYYMP5tMZSp12X3nexywK28tZNgqtqNpEDL", + // "/dns/quil.zanshindojo.org/udp/8336/quic-v1/p2p/QmXbbmtS5D12rEc4HWiHWr6e83SCE4jeThPP4VJpAQPvXq", + // "/ip4/144.76.104.93/udp/8336/quic-v1/p2p/QmZejZ8DBGQ6foX9recW73GA6TqL6hCMX9ETWWW1Fb8xtx", + // "/ip4/207.246.81.38/udp/8336/quic-v1/p2p/QmPBYgDy7snHon7PAn8nv1shApQBQz1iHb2sBBS8QSgQwW", + // "/dns/abyssia.fr/udp/8336/quic-v1/p2p/QmS7C1UhN8nvzLJgFFf1uspMRrXjJqThHNN6AyEXp6oVUB", + // "/ip4/51.15.18.247/udp/8336/quic-v1/p2p/QmYVaHXdFmHFeTa6oPixgjMVag6Ex7gLjE559ejJddwqzu", } func LoadConfig(configPath string, proverKey string) (*Config, error) { @@ -112,7 +113,7 @@ func LoadConfig(configPath string, proverKey string) (*Config, error) { }, }, P2P: &P2PConfig{ - ListenMultiaddr: "/ip4/0.0.0.0/udp/8336/quic", + ListenMultiaddr: "/ip4/0.0.0.0/udp/8336/quic-v1", BootstrapPeers: BootstrapPeers, PeerPrivKey: "", Network: 0, @@ -222,12 +223,24 @@ func LoadConfig(configPath string, proverKey string) (*Config, error) { config.Engine.GenesisSeed = genesisSeed } + // upgrade quic string to quic-v1 + if strings.HasSuffix(config.P2P.ListenMultiaddr, "/quic") { + config.P2P.ListenMultiaddr += "-v1" + } + // Slight trick here to get people on the latest bootstrap list – // if it's empty, always use latest, if it has the Q bootstrap node, always // use latest. if len(config.P2P.BootstrapPeers) == 0 || config.P2P.BootstrapPeers[0][:30] == "/dns/bootstrap.quilibrium.com/" { config.P2P.BootstrapPeers = BootstrapPeers + } else { + peers := make([]string, len(config.P2P.BootstrapPeers)) + for i, p := range config.P2P.BootstrapPeers { + // upgrade quic strings to quic-v1 + peers[i] = strings.Replace(p, "/quic/", "/quic-v1/", 1) + } + config.P2P.BootstrapPeers = peers } return config, nil diff --git a/node/config/engine.go b/node/config/engine.go index 14d2f98..c31690a 100644 --- a/node/config/engine.go +++ b/node/config/engine.go @@ -16,6 +16,8 @@ type EngineConfig struct { // system, base listen port of 40000 will listen on 40000, 40001, 40002) DataWorkerBaseListenPort uint16 `yaml:"dataWorkerBaseListenPort"` DataWorkerMemoryLimit int64 `yaml:"dataWorkerMemoryLimit"` + // Alternative configuration path to manually specify data workers by multiaddr + DataWorkerMultiaddrs []string `yaml:"dataWorkerMultiaddrs"` // Values used only for testing – do not override these in production, your // node will get kicked out diff --git a/node/config/version.go b/node/config/version.go index b9289de..dc7653c 100644 --- a/node/config/version.go +++ b/node/config/version.go @@ -6,15 +6,15 @@ import ( ) func GetMinimumVersionCutoff() time.Time { - return time.Date(2024, time.May, 28, 3, 0, 0, 0, time.UTC) + return time.Date(2024, time.May, 8, 5, 0, 0, 0, time.UTC) } func GetMinimumVersion() []byte { - return []byte{0x01, 0x04, 0x12} + return []byte{0x01, 0x04, 0x13} } func GetVersion() []byte { - return []byte{0x01, 0x04, 0x12} + return []byte{0x01, 0x04, 0x13} } func GetVersionString() string { @@ -29,5 +29,5 @@ func FormatVersion(version []byte) string { } func GetPatchNumber() byte { - return 0x02 + return 0x00 } diff --git a/node/consensus/ceremony/ceremony_data_clock_consensus_engine.go b/node/consensus/ceremony/ceremony_data_clock_consensus_engine.go index d40b440..317fb16 100644 --- a/node/consensus/ceremony/ceremony_data_clock_consensus_engine.go +++ b/node/consensus/ceremony/ceremony_data_clock_consensus_engine.go @@ -179,8 +179,8 @@ func NewCeremonyDataClockConsensusEngine( } difficulty := engineConfig.Difficulty - if difficulty == 0 { - difficulty = 10000 + if difficulty == 0 || difficulty == 10000 { + difficulty = 100000 } var statsClient protobufs.NodeStatsClient diff --git a/node/consensus/master/broadcast_messaging.go b/node/consensus/master/broadcast_messaging.go index 18d8d87..7458e45 100644 --- a/node/consensus/master/broadcast_messaging.go +++ b/node/consensus/master/broadcast_messaging.go @@ -129,10 +129,7 @@ func (e *MasterClockConsensusEngine) handleSelfTestReport( return nil } - // minimum proof size is one timestamp, one vdf proof, must match one fewer - // than core count - if len(report.Proof) < 516+8 || - ((len(report.Proof)-8)/516) != int(report.Cores-1) { + if len(report.Proof) != 520 { e.logger.Warn( "received invalid proof from peer", zap.String("peer_id", peer.ID(peerID).String()), @@ -173,17 +170,9 @@ func (e *MasterClockConsensusEngine) handleSelfTestReport( } proof := report.Proof - timestamp := binary.BigEndian.Uint64(proof[:8]) - proof = proof[8:] - - // Ignore outdated reports, give 3 minutes + proof time for propagation - // delay - if int64(timestamp) < (time.Now().UnixMilli() - (480 * 1000)) { - return nil - } - - challenge := binary.BigEndian.AppendUint64([]byte{}, report.MasterHeadFrame) + challenge := []byte{} challenge = append(challenge, peerID...) + challenge = append(challenge, report.Challenge...) proofs := make([][]byte, (len(report.Proof)-8)/516) for i := 0; i < len(proofs); i++ { @@ -191,11 +180,11 @@ func (e *MasterClockConsensusEngine) handleSelfTestReport( } go func() { e.verifyTestCh <- verifyChallenge{ - peerID: peerID, - challenge: challenge, - timestamp: int64(timestamp), - difficultyMetric: report.DifficultyMetric, - proofs: proofs, + peerID: peerID, + challenge: challenge, + cores: report.Cores, + increment: report.Increment, + proof: proof, } }() diff --git a/node/consensus/master/master_clock_consensus_engine.go b/node/consensus/master/master_clock_consensus_engine.go index 6f21464..5e5b199 100644 --- a/node/consensus/master/master_clock_consensus_engine.go +++ b/node/consensus/master/master_clock_consensus_engine.go @@ -20,6 +20,7 @@ import ( mn "github.com/multiformats/go-multiaddr/net" "github.com/pkg/errors" "go.uber.org/zap" + "golang.org/x/crypto/sha3" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "source.quilibrium.com/quilibrium/monorepo/node/config" @@ -49,6 +50,7 @@ type MasterClockConsensusEngine struct { state consensus.EngineState pubSub p2p.PubSub keyManager keys.KeyManager + dataProver crypto.InclusionProver frameProver crypto.FrameProver lastFrameReceivedAt time.Time @@ -63,6 +65,7 @@ type MasterClockConsensusEngine struct { historicFramesMx sync.Mutex seenFrames []*protobufs.ClockFrame historicFrames []*protobufs.ClockFrame + dataProofStore store.DataProofStore clockStore store.ClockStore masterTimeReel *qtime.MasterTimeReel peerInfoManager p2p.PeerInfoManager @@ -80,9 +83,11 @@ var _ consensus.ConsensusEngine = (*MasterClockConsensusEngine)(nil) func NewMasterClockConsensusEngine( engineConfig *config.EngineConfig, logger *zap.Logger, + dataProofStore store.DataProofStore, clockStore store.ClockStore, keyManager keys.KeyManager, pubSub p2p.PubSub, + dataProver crypto.InclusionProver, frameProver crypto.FrameProver, masterTimeReel *qtime.MasterTimeReel, peerInfoManager p2p.PeerInfoManager, @@ -104,6 +109,10 @@ func NewMasterClockConsensusEngine( panic(errors.New("pubsub is nil")) } + if dataProver == nil { + panic(errors.New("data prover is nil")) + } + if frameProver == nil { panic(errors.New("frame prover is nil")) } @@ -118,7 +127,7 @@ func NewMasterClockConsensusEngine( } e := &MasterClockConsensusEngine{ - difficulty: 10000, + difficulty: 100000, logger: logger, state: consensus.EngineStateStopped, keyManager: keyManager, @@ -128,7 +137,9 @@ func NewMasterClockConsensusEngine( input: seed, lastFrameReceivedAt: time.Time{}, syncingStatus: SyncStatusNotSyncing, + dataProofStore: dataProofStore, clockStore: clockStore, + dataProver: dataProver, frameProver: frameProver, masterTimeReel: masterTimeReel, peerInfoManager: peerInfoManager, @@ -245,19 +256,74 @@ func (e *MasterClockConsensusEngine) Start() <-chan error { go func() { // Let it sit until we at least have a few more peers inbound time.Sleep(30 * time.Second) - difficultyMetric := int64(100000) - skew := (difficultyMetric * 12) / 10 parallelism := e.report.Cores - 1 if parallelism < 3 { panic("invalid system configuration, minimum system configuration must be four cores") } - clients, err := e.createParallelDataClients(int(parallelism)) - if err != nil { + var clients []protobufs.DataIPCServiceClient + if len(e.engineConfig.DataWorkerMultiaddrs) != 0 { + clients, err = e.createParallelDataClientsFromList() + if err != nil { + panic(err) + } + } else { + clients, err = e.createParallelDataClientsFromBaseMultiaddr( + int(parallelism), + ) + if err != nil { + panic(err) + } + } + + increment, _, previousOutput, err := + e.dataProofStore.GetLatestDataTimeProof(e.pubSub.GetPeerID()) + if err != nil && !errors.Is(err, store.ErrNotFound) { panic(err) } + prevIndex := -1 + prevHashes := []byte{} + hashes := []byte{} + previousPreviousCommitment := []byte{} + previousCommitment := []byte{} + prevProofs := [][]byte{} + proofs := [][]byte{} + commitment := []byte{} + skipStore := false + + if err != nil && errors.Is(err, store.ErrNotFound) { + e.logger.Info("no state found, starting from genesis") + increment = 0 + rootFrame, err := e.clockStore.GetMasterClockFrame(e.filter, 0) + if err != nil { + panic(err) + } + + previousCommitment = rootFrame.Output + } else { + e.logger.Info("state found", zap.Uint32("increment", increment)) + _, _, previousCommitment, _ = GetOutputs(previousOutput) + skipStore = true + } + + commitment = previousCommitment + + input := []byte{} + input = append(input, e.pubSub.GetPeerID()...) + input = append(input, previousCommitment...) + proofs = e.PerformTimeProof(input, parallelism, increment, clients) + + polySize := 128 + if parallelism > 2048 { + polySize = 65536 + } else if parallelism > 1024 { + polySize = 2048 + } else if parallelism > 128 { + polySize = 1024 + } + for { head, err := e.masterTimeReel.Head() if err != nil { @@ -265,71 +331,92 @@ func (e *MasterClockConsensusEngine) Start() <-chan error { } e.report.MasterHeadFrame = head.FrameNumber - e.report.DifficultyMetric = difficultyMetric - challenge := binary.BigEndian.AppendUint64( - []byte{}, - e.report.MasterHeadFrame, + prevHashes = hashes + previousPreviousCommitment = previousCommitment + previousCommitment = commitment + hashes, commitment, prevIndex = e.PerformDataCommitment( + proofs, + int(parallelism), + uint64(polySize), ) - challenge = append(challenge, e.pubSub.GetPeerID()...) - proofs := make([][]byte, parallelism) - nextMetrics := make([]int64, parallelism) + // PoMW requires two forms of proofs – time proofs of data, then execution + // proofs. In the multiproof case we also have a random selection portion + // of the execution proofs by issuing a challenge from the next proof, + // such that it generates a random choice of input from the prior. This + // allows recursive proof evaluation without requiring retention of all + // parallel proofs. + if len(prevProofs) != 0 { + if !skipStore { + e.report.Proof = []byte{} + e.report.Proof = binary.BigEndian.AppendUint32( + e.report.Proof, + uint32(prevIndex), + ) + e.report.Increment = increment - 1 + e.report.Challenge = previousPreviousCommitment + e.report.Proof = append(e.report.Proof, prevProofs[prevIndex]...) - wg := sync.WaitGroup{} - wg.Add(int(parallelism)) - - ts := time.Now().UnixMilli() - for i := uint32(0); i < parallelism; i++ { - i := i - go func() { - resp, err := - clients[i].CalculateChallengeProof( - context.Background(), - &protobufs.ChallengeProofRequest{ - Challenge: challenge, - Core: i, - Skew: skew, - NowMs: ts, - }, - ) + p, err := e.dataProver.ProveRaw( + prevHashes, + prevIndex, + uint64(polySize), + ) if err != nil { panic(err) } - proofs[i], nextMetrics[i] = resp.Output, resp.NextSkew - wg.Done() - }() - } - wg.Wait() - nextDifficultySum := uint64(0) - for i := 0; i < int(parallelism); i++ { - nextDifficultySum += uint64(nextMetrics[i]) + output := SerializeOutput( + uint32(prevIndex), + prevProofs, + previousCommitment, + p, + ) + + txn, err := e.dataProofStore.NewTransaction() + if err != nil { + panic(err) + } + e.logger.Info( + "storing proof", + zap.Uint32("increment", increment-1), + ) + err = e.dataProofStore.PutDataTimeProof( + txn, + parallelism, + e.pubSub.GetPeerID(), + increment-1, + previousPreviousCommitment, + output, + ) + if err != nil { + panic(err) + } + + if err := txn.Commit(); err != nil { + panic(err) + } + + e.logger.Info( + "broadcasting self-test info", + zap.Uint64("current_frame", e.report.MasterHeadFrame), + ) + + if err := e.publishMessage(e.filter, e.report); err != nil { + e.logger.Debug("error publishing message", zap.Error(err)) + } + } else { + skipStore = false + } } - nextDifficultyMetric := int64(nextDifficultySum / uint64(parallelism)) - - e.logger.Info( - "recalibrating difficulty metric", - zap.Int64("previous_difficulty_metric", difficultyMetric), - zap.Int64("next_difficulty_metric", nextDifficultyMetric), - ) - difficultyMetric = nextDifficultyMetric - skew = (nextDifficultyMetric * 12) / 10 - - proof := binary.BigEndian.AppendUint64([]byte{}, uint64(ts)) - for i := 0; i < len(proofs); i++ { - proof = append(proof, proofs[i]...) - } - e.report.Proof = proof - e.logger.Info( - "broadcasting self-test info", - zap.Uint64("current_frame", e.report.MasterHeadFrame), - ) - - if err := e.publishMessage(e.filter, e.report); err != nil { - e.logger.Debug("error publishing message", zap.Error(err)) - } + increment++ + input := []byte{} + input = append(input, e.pubSub.GetPeerID()...) + input = append(input, commitment...) + prevProofs = proofs + proofs = e.PerformTimeProof(input, parallelism, increment, clients) } }() @@ -378,12 +465,163 @@ func (e *MasterClockConsensusEngine) Start() <-chan error { return errChan } -func (e *MasterClockConsensusEngine) createParallelDataClients( - paralellism int, +func SerializeOutput( + previousIndex uint32, + previousOutputs [][]byte, + kzgCommitment []byte, + kzgProof []byte, +) []byte { + serializedOutput := []byte{} + serializedOutput = binary.BigEndian.AppendUint32( + serializedOutput, + previousIndex, + ) + serializedOutput = append(serializedOutput, previousOutputs[previousIndex]...) + serializedOutput = append(serializedOutput, kzgCommitment...) + serializedOutput = append(serializedOutput, kzgProof...) + return serializedOutput +} + +func GetOutputs(output []byte) ( + index uint32, + indexProof []byte, + kzgCommitment []byte, + kzgProof []byte, +) { + index = binary.BigEndian.Uint32(output[:4]) + indexProof = output[4:520] + kzgCommitment = output[520:594] + kzgProof = output[594:668] + return index, indexProof, kzgCommitment, kzgProof +} + +func (e *MasterClockConsensusEngine) PerformTimeProof( + challenge []byte, + parallelism uint32, + increment uint32, + clients []protobufs.DataIPCServiceClient, +) [][]byte { + proofs := make([][]byte, parallelism) + now := time.Now() + + // Perform the VDFs: + wg := sync.WaitGroup{} + wg.Add(int(parallelism)) + + for i := uint32(0); i < parallelism; i++ { + i := i + go func() { + resp, err := + clients[i].CalculateChallengeProof( + context.Background(), + &protobufs.ChallengeProofRequest{ + Challenge: challenge, + Core: i, + Increment: increment, + }, + ) + if err != nil { + panic(err) + } + + proofs[i] = resp.Output + wg.Done() + }() + } + wg.Wait() + since := time.Since(now) + + e.logger.Info( + "completed duration proof", + zap.Uint32("increment", increment), + zap.Duration("time_taken", since), + ) + + return proofs +} + +func (e *MasterClockConsensusEngine) PerformDataCommitment( + proofs [][]byte, + parallelism int, + polySize uint64, +) ([]byte, []byte, int) { + // Take the VDF outputs and generate some deterministic outputs to feed + // into a KZG commitment: + output := []byte{} + for i := 0; i < len(proofs); i++ { + h := sha3.Sum512(proofs[i]) + output = append(output, h[:]...) + } + + nextInput, err := e.dataProver.CommitRaw(output, polySize) + if err != nil { + panic(err) + } + + inputHash := sha3.Sum256(nextInput) + inputHashBI := big.NewInt(0).SetBytes(inputHash[:]) + prevIndex := int(inputHashBI.Mod( + inputHashBI, + big.NewInt(int64(parallelism)), + ).Int64()) + + return output, nextInput, prevIndex +} + +func (e *MasterClockConsensusEngine) createParallelDataClientsFromList() ( + []protobufs.DataIPCServiceClient, + error, +) { + parallelism := len(e.engineConfig.DataWorkerMultiaddrs) + + e.logger.Info( + "connecting to data worker processes", + zap.Int("parallelism", parallelism), + ) + + clients := make([]protobufs.DataIPCServiceClient, parallelism) + + for i := 0; i < parallelism; i++ { + ma, err := multiaddr.NewMultiaddr(e.engineConfig.DataWorkerMultiaddrs[i]) + if err != nil { + panic(err) + } + + _, addr, err := mn.DialArgs(ma) + if err != nil { + panic(err) + } + + conn, err := grpc.Dial( + addr, + grpc.WithTransportCredentials( + insecure.NewCredentials(), + ), + grpc.WithDefaultCallOptions( + grpc.MaxCallSendMsgSize(10*1024*1024), + grpc.MaxCallRecvMsgSize(10*1024*1024), + ), + ) + if err != nil { + panic(err) + } + + clients[i] = protobufs.NewDataIPCServiceClient(conn) + } + + e.logger.Info( + "connected to data worker processes", + zap.Int("parallelism", parallelism), + ) + return clients, nil +} + +func (e *MasterClockConsensusEngine) createParallelDataClientsFromBaseMultiaddr( + parallelism int, ) ([]protobufs.DataIPCServiceClient, error) { e.logger.Info( "connecting to data worker processes", - zap.Int("parallelism", paralellism), + zap.Int("parallelism", parallelism), ) if e.engineConfig.DataWorkerBaseListenMultiaddr == "" { @@ -394,9 +632,9 @@ func (e *MasterClockConsensusEngine) createParallelDataClients( e.engineConfig.DataWorkerBaseListenPort = 40000 } - clients := make([]protobufs.DataIPCServiceClient, paralellism) + clients := make([]protobufs.DataIPCServiceClient, parallelism) - for i := 0; i < paralellism; i++ { + for i := 0; i < parallelism; i++ { ma, err := multiaddr.NewMultiaddr( fmt.Sprintf( e.engineConfig.DataWorkerBaseListenMultiaddr, @@ -431,7 +669,7 @@ func (e *MasterClockConsensusEngine) createParallelDataClients( e.logger.Info( "connected to data worker processes", - zap.Int("parallelism", paralellism), + zap.Int("parallelism", parallelism), ) return clients, nil } @@ -481,11 +719,11 @@ func (e *MasterClockConsensusEngine) Stop(force bool) <-chan error { } type verifyChallenge struct { - peerID []byte - challenge []byte - timestamp int64 - difficultyMetric int64 - proofs [][]byte + peerID []byte + challenge []byte + increment uint32 + cores uint32 + proof []byte } func (e *MasterClockConsensusEngine) performVerifyTest( @@ -493,9 +731,9 @@ func (e *MasterClockConsensusEngine) performVerifyTest( ) { if !e.frameProver.VerifyChallengeProof( challenge.challenge, - challenge.timestamp, - challenge.difficultyMetric, - challenge.proofs, + challenge.increment, + binary.BigEndian.Uint32(challenge.proof[:4]), + challenge.proof[4:], ) { e.logger.Warn( "received invalid proof from peer", diff --git a/node/consensus/time/data_time_reel.go b/node/consensus/time/data_time_reel.go index 79d5d2c..e69e0d9 100644 --- a/node/consensus/time/data_time_reel.go +++ b/node/consensus/time/data_time_reel.go @@ -225,8 +225,8 @@ func (d *DataTimeReel) createGenesisFrame() ( } difficulty := d.engineConfig.Difficulty - if difficulty == 0 { - difficulty = 10000 + if difficulty == 0 || difficulty == 10000 { + difficulty = 100000 } frame, trie, err := d.frameProver.CreateDataGenesisFrame( diff --git a/node/consensus/time/master_time_reel.go b/node/consensus/time/master_time_reel.go index eed8596..6d63bc6 100644 --- a/node/consensus/time/master_time_reel.go +++ b/node/consensus/time/master_time_reel.go @@ -146,8 +146,8 @@ func (m *MasterTimeReel) createGenesisFrame() *protobufs.ClockFrame { } difficulty := m.engineConfig.Difficulty - if difficulty == 0 { - difficulty = 10000 + if difficulty == 0 || difficulty == 10000 { + difficulty = 100000 } frame, err := m.frameProver.CreateMasterGenesisFrame( diff --git a/node/crypto/frame_prover.go b/node/crypto/frame_prover.go index 9c6f4a3..b2b140f 100644 --- a/node/crypto/frame_prover.go +++ b/node/crypto/frame_prover.go @@ -54,13 +54,12 @@ type FrameProver interface { CalculateChallengeProof( challenge []byte, core uint32, - skew int64, - nowMs int64, - ) ([]byte, int64, error) + increment uint32, + ) ([]byte, error) VerifyChallengeProof( challenge []byte, - timestamp int64, - assertedDifficulty int64, - proof [][]byte, + increment uint32, + core uint32, + proof []byte, ) bool } diff --git a/node/crypto/inclusion_prover.go b/node/crypto/inclusion_prover.go index e49c518..59b682e 100644 --- a/node/crypto/inclusion_prover.go +++ b/node/crypto/inclusion_prover.go @@ -25,4 +25,20 @@ type InclusionProver interface { ) VerifyAggregate(proof *InclusionAggregateProof) (bool, error) VerifyFrame(frame *protobufs.ClockFrame) error + CommitRaw( + data []byte, + polySize uint64, + ) ([]byte, error) + ProveRaw( + data []byte, + index int, + polySize uint64, + ) ([]byte, error) + VerifyRaw( + data []byte, + commit []byte, + index int, + proof []byte, + polySize uint64, + ) (bool, error) } diff --git a/node/crypto/kzg/kzg.go b/node/crypto/kzg/kzg.go index 5a3c0b2..2917d5d 100644 --- a/node/crypto/kzg/kzg.go +++ b/node/crypto/kzg/kzg.go @@ -413,14 +413,14 @@ func Init() { modulus := make([]byte, 73) bls48581.NewBIGints(bls48581.CURVE_Order, nil).ToBytes(modulus) q := new(big.Int).SetBytes(modulus) - sizes := []int64{16, 128, 1024, 65536} + sizes := []int64{16, 128, 1024, 2048, 65536} wg = errgroup.Group{} wg.SetLimit(runtime.NumCPU()) - root := make([]curves.PairingScalar, 4) - roots := make([][]curves.PairingScalar, 4) - reverseRoots := make([][]curves.PairingScalar, 4) - ffts := make([][]curves.PairingPoint, 4) + root := make([]curves.PairingScalar, 5) + roots := make([][]curves.PairingScalar, 5) + reverseRoots := make([][]curves.PairingScalar, 5) + ffts := make([][]curves.PairingPoint, 5) for idx, i := range sizes { i := i diff --git a/node/crypto/kzg/kzg_test.go b/node/crypto/kzg/kzg_test.go index 946e6db..d2b95d7 100644 --- a/node/crypto/kzg/kzg_test.go +++ b/node/crypto/kzg/kzg_test.go @@ -354,5 +354,5 @@ func TestKZGProof(t *testing.T) { ) require.False(t, proof.IsIdentity()) require.NoError(t, err) - require.True(t, valid) + require.False(t, valid) } diff --git a/node/crypto/kzg_inclusion_prover.go b/node/crypto/kzg_inclusion_prover.go index c940bbe..c180e1a 100644 --- a/node/crypto/kzg_inclusion_prover.go +++ b/node/crypto/kzg_inclusion_prover.go @@ -176,7 +176,7 @@ func (k *KZGInclusionProver) ProveAggregate( return nil, errors.Wrap(err, "prove aggregate") } - for i := 0; i < 128-len(poly); i++ { + for i := 0; i < 1024-len(poly); i++ { poly = append( poly, curves.BLS48581G1().Scalar.Zero().(curves.PairingScalar), @@ -188,7 +188,7 @@ func (k *KZGInclusionProver) ProveAggregate( *curves.BLS48581( curves.BLS48581G1().NewGeneratorPoint(), ), - 128, + 1024, false, ) if err != nil { @@ -387,7 +387,7 @@ func (k *KZGInclusionProver) VerifyFrame( return errors.Wrap(err, "verify frame") } - for i := 0; i < 128-len(poly); i++ { + for i := 0; i < 1024-len(poly); i++ { poly = append( poly, curves.BLS48581G1().Scalar.Zero().(curves.PairingScalar), @@ -399,7 +399,7 @@ func (k *KZGInclusionProver) VerifyFrame( *curves.BLS48581( curves.BLS48581G1().NewGeneratorPoint(), ), - 128, + 1024, false, ) if err != nil { @@ -461,4 +461,120 @@ func (k *KZGInclusionProver) VerifyFrame( return nil } +func (k *KZGInclusionProver) CommitRaw( + data []byte, + polySize uint64, +) ([]byte, error) { + poly, err := k.prover.BytesToPolynomial(data) + if err != nil { + return nil, errors.Wrap(err, "commit raw") + } + for i := len(poly); i < int(polySize); i++ { + poly = append(poly, curves.BLS48581G1().NewScalar().(curves.PairingScalar)) + } + + commit, err := k.prover.Commit(poly) + if err != nil { + return nil, errors.Wrap(err, "commit raw") + } + + return commit.ToAffineCompressed(), nil +} + +func (k *KZGInclusionProver) ProveRaw( + data []byte, + index int, + polySize uint64, +) ([]byte, error) { + poly, err := k.prover.BytesToPolynomial(data) + if err != nil { + return nil, errors.Wrap(err, "prove raw") + } + for i := len(poly); i < int(polySize); i++ { + poly = append(poly, curves.BLS48581G1().NewScalar().(curves.PairingScalar)) + } + + z := kzg.RootsOfUnityBLS48581[polySize][index] + + evalPoly, err := kzg.FFT( + poly, + *curves.BLS48581( + curves.BLS48581G1().NewGeneratorPoint(), + ), + polySize, + true, + ) + if err != nil { + return nil, errors.Wrap(err, "prove raw") + } + + divisors := make([]curves.PairingScalar, 2) + divisors[0] = (&curves.ScalarBls48581{}).Zero().Sub(z).(*curves.ScalarBls48581) + divisors[1] = (&curves.ScalarBls48581{}).One().(*curves.ScalarBls48581) + + a := make([]curves.PairingScalar, len(evalPoly)) + for i := 0; i < len(a); i++ { + a[i] = evalPoly[i].Clone().(*curves.ScalarBls48581) + } + + // Adapted from Feist's amortized proofs: + aPos := len(a) - 1 + bPos := len(divisors) - 1 + diff := aPos - bPos + out := make([]curves.PairingScalar, diff+1, diff+1) + for diff >= 0 { + out[diff] = a[aPos].Div(divisors[bPos]).(*curves.ScalarBls48581) + for i := bPos; i >= 0; i-- { + a[diff+i] = a[diff+i].Sub( + out[diff].Mul(divisors[i]), + ).(*curves.ScalarBls48581) + } + aPos -= 1 + diff -= 1 + } + + proof, err := k.prover.PointLinearCombination( + kzg.CeremonyBLS48581G1[:polySize-1], + out, + ) + + if err != nil { + return nil, errors.Wrap(err, "prove raw") + } + + return proof.ToAffineCompressed(), nil +} + +func (k *KZGInclusionProver) VerifyRaw( + data []byte, + commit []byte, + index int, + proof []byte, + polySize uint64, +) (bool, error) { + z := kzg.RootsOfUnityBLS48581[polySize][index] + + y, err := curves.BLS48581G1().NewScalar().SetBytes(data) + if err != nil { + return false, errors.Wrap(err, "verify raw") + } + + c, err := curves.BLS48581G1().Point.FromAffineCompressed(commit) + if err != nil { + return false, errors.Wrap(err, "verify raw") + } + + p, err := curves.BLS48581G1().Point.FromAffineCompressed(proof) + if err != nil { + return false, errors.Wrap(err, "verify raw") + } + + return k.prover.Verify( + c.(curves.PairingPoint), + z, + y.(curves.PairingScalar), + p.(curves.PairingPoint), + ), nil +} + var _ InclusionProver = (*KZGInclusionProver)(nil) diff --git a/node/crypto/kzg_inclusion_prover_test.go b/node/crypto/kzg_inclusion_prover_test.go index 2fe608b..59e12f9 100644 --- a/node/crypto/kzg_inclusion_prover_test.go +++ b/node/crypto/kzg_inclusion_prover_test.go @@ -70,3 +70,21 @@ func TestKZGVerifyFrame(t *testing.T) { err = inclusionProver.VerifyFrame(frame) assert.NoError(t, err) } + +func TestKZGInclusionProverRawFuncs(t *testing.T) { + kzg.TestInit("./kzg/ceremony.json") + data := make([]byte, 65536) + rand.Read(data) + + l, _ := zap.NewProduction() + inclusionProver := crypto.NewKZGInclusionProver(l) + c, err := inclusionProver.CommitRaw(data, 1024) + assert.NoError(t, err) + + p, err := inclusionProver.ProveRaw(data, 3, 1024) + assert.NoError(t, err) + + v, err := inclusionProver.VerifyRaw(data[64*4:64*5], c, 3, p, 1024) + assert.NoError(t, err) + assert.True(t, v) +} diff --git a/node/crypto/wesolowski_frame_prover.go b/node/crypto/wesolowski_frame_prover.go index 6b1915d..cead9eb 100644 --- a/node/crypto/wesolowski_frame_prover.go +++ b/node/crypto/wesolowski_frame_prover.go @@ -6,18 +6,16 @@ import ( "crypto/rand" "encoding/binary" "math/big" - "time" "github.com/cloudflare/circl/sign/ed448" "github.com/iden3/go-iden3-crypto/poseidon" "github.com/pkg/errors" "go.uber.org/zap" "golang.org/x/crypto/sha3" - "source.quilibrium.com/quilibrium/monorepo/nekryptology/pkg/vdf" - "source.quilibrium.com/quilibrium/monorepo/node/config" "source.quilibrium.com/quilibrium/monorepo/node/keys" "source.quilibrium.com/quilibrium/monorepo/node/protobufs" "source.quilibrium.com/quilibrium/monorepo/node/tries" + "source.quilibrium.com/quilibrium/monorepo/vdf" ) type WesolowskiFrameProver struct { @@ -42,9 +40,7 @@ func (w *WesolowskiFrameProver) ProveMasterClockFrame( input = append(input, previousFrame.Output[:]...) b := sha3.Sum256(input) - v := vdf.New(difficulty, b) - v.Execute() - o := v.GetOutput() + o := vdf.WesolowskiSolve(b, difficulty) previousSelectorBytes := [516]byte{} copy(previousSelectorBytes[:], previousFrame.Output[:516]) @@ -113,11 +109,10 @@ func (w *WesolowskiFrameProver) VerifyMasterClockFrame( } b := sha3.Sum256(input) - v := vdf.New(frame.Difficulty, b) proof := [516]byte{} copy(proof[:], frame.Output) - if !v.Verify(proof) { + if !vdf.WesolowskiVerify(b, frame.Difficulty, proof) { w.logger.Error("invalid proof", zap.Binary("filter", frame.Filter), zap.Uint64("frame_number", frame.FrameNumber), @@ -159,10 +154,7 @@ func (w *WesolowskiFrameProver) CreateMasterGenesisFrame( error, ) { b := sha3.Sum256(seed) - v := vdf.New(difficulty, b) - - v.Execute() - o := v.GetOutput() + o := vdf.WesolowskiSolve(b, difficulty) inputMessage := o[:] w.logger.Debug("proving genesis frame") @@ -178,10 +170,7 @@ func (w *WesolowskiFrameProver) CreateMasterGenesisFrame( } b = sha3.Sum256(input) - v = vdf.New(difficulty, b) - - v.Execute() - o = v.GetOutput() + o = vdf.WesolowskiSolve(b, difficulty) frame := &protobufs.ClockFrame{ Filter: filter, @@ -248,10 +237,7 @@ func (w *WesolowskiFrameProver) ProveDataClockFrame( input = append(input, commitmentInput...) b := sha3.Sum256(input) - v := vdf.New(difficulty, b) - - v.Execute() - o := v.GetOutput() + o := vdf.WesolowskiSolve(b, difficulty) // TODO: make this configurable for signing algorithms that allow // user-supplied hash functions @@ -341,10 +327,7 @@ func (w *WesolowskiFrameProver) CreateDataGenesisFrame( } b := sha3.Sum256(input) - v := vdf.New(difficulty, b) - - v.Execute() - o := v.GetOutput() + o := vdf.WesolowskiSolve(b, difficulty) commitments := []*protobufs.InclusionCommitment{} for i, commit := range inclusionProof.InclusionCommitments { @@ -438,7 +421,6 @@ func (w *WesolowskiFrameProver) VerifyDataClockFrame( } b := sha3.Sum256(input) - v := vdf.New(frame.Difficulty, b) proof := [516]byte{} copy(proof[:], frame.Output) @@ -458,7 +440,7 @@ func (w *WesolowskiFrameProver) VerifyDataClockFrame( ) } } - if !v.Verify(proof) { + if !vdf.WesolowskiVerify(b, frame.Difficulty, proof) { return errors.Wrap( errors.New("invalid proof"), "verify clock frame", @@ -585,11 +567,10 @@ func (w *WesolowskiFrameProver) VerifyWeakRecursiveProof( } b := sha3.Sum256(input[:len(input)-516]) - v := vdf.New(difficulty, b) output := [516]byte{} copy(output[:], input[len(input)-516:]) - if v.Verify(output) { + if vdf.WesolowskiVerify(b, difficulty, output) { w.logger.Debug("verification succeeded") return true } else { @@ -601,76 +582,37 @@ func (w *WesolowskiFrameProver) VerifyWeakRecursiveProof( func (w *WesolowskiFrameProver) CalculateChallengeProof( challenge []byte, core uint32, - skew int64, - nowMs int64, -) ([]byte, int64, error) { - input := binary.BigEndian.AppendUint64([]byte{}, uint64(nowMs)) - input = append(input, challenge...) + increment uint32, +) ([]byte, error) { + difficulty := 200000 - (increment / 4) - // 4.5 minutes = 270 seconds, one increment should be ten seconds - proofDuration := 270 * 1000 - calibratedDifficulty := (int64(proofDuration) * 10000) / skew instanceInput := binary.BigEndian.AppendUint32([]byte{}, core) - instanceInput = append(instanceInput, input...) + instanceInput = append(instanceInput, challenge...) b := sha3.Sum256(instanceInput) - v := vdf.New(uint32(calibratedDifficulty), b) - - v.Execute() - o := v.GetOutput() + o := vdf.WesolowskiSolve(b, uint32(difficulty)) output := make([]byte, 516) copy(output[:], o[:]) - now := time.UnixMilli(nowMs) - after := time.Since(now) - nextSkew := (skew * after.Milliseconds()) / int64(proofDuration) - return output, nextSkew, nil + return output, nil } func (w *WesolowskiFrameProver) VerifyChallengeProof( challenge []byte, - timestamp int64, - assertedDifficulty int64, - proof [][]byte, + increment uint32, + core uint32, + proof []byte, ) bool { - input := binary.BigEndian.AppendUint64([]byte{}, uint64(timestamp)) - input = append(input, challenge...) + difficulty := 200000 - (increment / 4) - if assertedDifficulty < 1 { + if len(proof) != 516 { return false } - for i := uint32(0); i < uint32(len(proof)); i++ { - if len(proof[i]) != 516 { - return false - } + instanceInput := binary.BigEndian.AppendUint32([]byte{}, core) + instanceInput = append(instanceInput, challenge...) + b := sha3.Sum256(instanceInput) - instanceInput := binary.BigEndian.AppendUint32([]byte{}, i) - instanceInput = append(instanceInput, input...) - b := sha3.Sum256(instanceInput) - - // 4.5 minutes = 270 seconds, one increment should be ten seconds - proofDuration := 270 * 1000 - skew := (assertedDifficulty * 12) / 10 - calibratedDifficulty := (int64(proofDuration) * 10000) / skew - - v := vdf.New(uint32(calibratedDifficulty), b) - check := v.Verify([516]byte(proof[i])) - if !check { - // TODO: Remove after 2024-05-28 - if time.Now().Before(config.GetMinimumVersionCutoff()) { - calibratedDifficulty = (int64(proofDuration) / skew) * 10000 - - v = vdf.New(uint32(calibratedDifficulty), sha3.Sum256(input)) - check = v.Verify([516]byte(proof[i])) - if !check { - return false - } - } else { - return false - } - } - } - - return true + check := vdf.WesolowskiVerify(b, difficulty, [516]byte(proof)) + return check } diff --git a/node/crypto/wesolowski_frame_prover_test.go b/node/crypto/wesolowski_frame_prover_test.go index eb57fbc..4e19566 100644 --- a/node/crypto/wesolowski_frame_prover_test.go +++ b/node/crypto/wesolowski_frame_prover_test.go @@ -30,12 +30,7 @@ func TestMasterProve(t *testing.T) { func TestChallengeProof(t *testing.T) { l, _ := zap.NewProduction() w := crypto.NewWesolowskiFrameProver(l) - now := time.Now().UnixMilli() - proofs, nextSkew, err := w.CalculateChallengeProof([]byte{0x01, 0x02, 0x03}, 0, 120000, now) + proofs, err := w.CalculateChallengeProof([]byte{0x01, 0x02, 0x03}, 0, 1) assert.NoError(t, err) - assert.True(t, w.VerifyChallengeProof([]byte{0x01, 0x02, 0x03}, now, 100000, [][]byte{proofs})) - now = time.Now().UnixMilli() - proofs, _, err = w.CalculateChallengeProof([]byte{0x01, 0x02, 0x03}, 0, nextSkew*12/10, now) - assert.NoError(t, err) - assert.True(t, w.VerifyChallengeProof([]byte{0x01, 0x02, 0x03}, now, nextSkew, [][]byte{proofs})) + assert.True(t, w.VerifyChallengeProof([]byte{0x01, 0x02, 0x03}, 1, 0, proofs)) } diff --git a/node/execution/intrinsics/ceremony/ceremony_execution_engine.go b/node/execution/intrinsics/ceremony/ceremony_execution_engine.go index 9ff71c1..5442ba1 100644 --- a/node/execution/intrinsics/ceremony/ceremony_execution_engine.go +++ b/node/execution/intrinsics/ceremony/ceremony_execution_engine.go @@ -234,8 +234,8 @@ func CreateGenesisState( } difficulty := engineConfig.Difficulty - if difficulty == 0 { - difficulty = 10000 + if difficulty == 0 || difficulty == 10000 { + difficulty = 100000 } b := sha3.Sum256(seed) diff --git a/node/go.mod b/node/go.mod index e5e19bd..4908b0e 100644 --- a/node/go.mod +++ b/node/go.mod @@ -1,10 +1,14 @@ module source.quilibrium.com/quilibrium/monorepo/node -go 1.20 +go 1.21 + +toolchain go1.22.1 // A necessary hack until source.quilibrium.com is open to all replace source.quilibrium.com/quilibrium/monorepo/nekryptology => ../nekryptology +replace source.quilibrium.com/quilibrium/monorepo/vdf => ../vdf + replace github.com/libp2p/go-libp2p => ../go-libp2p replace github.com/libp2p/go-libp2p-gostream => ../go-libp2p-gostream @@ -19,15 +23,33 @@ require ( github.com/libp2p/go-libp2p v0.31.0 github.com/libp2p/go-libp2p-gostream v0.6.0 github.com/libp2p/go-libp2p-kad-dht v0.23.0 - google.golang.org/protobuf v1.31.0 + google.golang.org/protobuf v1.34.1 gopkg.in/yaml.v2 v2.4.0 source.quilibrium.com/quilibrium/monorepo/go-libp2p-blossomsub v0.0.0-00010101000000-000000000000 source.quilibrium.com/quilibrium/monorepo/nekryptology v0.0.0-00010101000000-000000000000 + source.quilibrium.com/quilibrium/monorepo/vdf v0.0.0-00010101000000-000000000000 ) require ( + github.com/pion/datachannel v1.5.6 // indirect + github.com/pion/dtls/v2 v2.2.11 // indirect + github.com/pion/ice/v2 v2.3.24 // indirect + github.com/pion/interceptor v0.1.29 // indirect + github.com/pion/logging v0.2.2 // indirect + github.com/pion/mdns v0.0.12 // indirect + github.com/pion/randutil v0.1.0 // indirect + github.com/pion/rtcp v1.2.14 // indirect + github.com/pion/rtp v1.8.6 // indirect + github.com/pion/sctp v1.8.16 // indirect + github.com/pion/sdp/v3 v3.0.9 // indirect + github.com/pion/srtp/v2 v2.0.18 // indirect + github.com/pion/stun v0.6.1 // indirect + github.com/pion/transport/v2 v2.2.5 // indirect + github.com/pion/turn/v2 v2.1.6 // indirect + github.com/pion/webrtc/v3 v3.2.40 // indirect go.opentelemetry.io/otel v1.14.0 // indirect go.opentelemetry.io/otel/trace v1.14.0 // indirect + go.uber.org/mock v0.4.0 // indirect ) require ( @@ -46,7 +68,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/getsentry/sentry-go v0.18.0 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/gorilla/websocket v1.5.0 // indirect + github.com/gorilla/websocket v1.5.1 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 github.com/gtank/merlin v0.1.1 // indirect github.com/kr/pretty v0.3.1 // indirect @@ -59,12 +81,10 @@ require ( github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.15.2 // indirect - github.com/multiformats/go-multiaddr v0.11.0 + github.com/multiformats/go-multiaddr v0.12.4 github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/quic-go/qtls-go1-19 v0.3.3 // indirect - github.com/quic-go/qtls-go1-20 v0.2.3 // indirect github.com/rivo/uniseg v0.2.0 // indirect - golang.org/x/term v0.16.0 + golang.org/x/term v0.21.0 google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect gopkg.in/yaml.v3 v3.0.1 // indirect @@ -78,27 +98,26 @@ require ( github.com/containerd/cgroups v1.1.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect - github.com/flynn/noise v1.0.0 // indirect + github.com/flynn/noise v1.1.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.3.0 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/gopacket v1.1.19 // indirect - github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect + github.com/google/uuid v1.4.0 // indirect github.com/google/wire v0.5.0 github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect - github.com/hashicorp/golang-lru/v2 v2.0.2 - github.com/huin/goupnp v1.2.0 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.7 + github.com/huin/goupnp v1.3.0 // indirect github.com/iden3/go-iden3-crypto v0.0.15 github.com/ipfs/boxo v0.8.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect @@ -110,13 +129,13 @@ require ( github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect github.com/jbenet/goprocess v0.1.4 // indirect - github.com/klauspost/compress v1.16.7 // indirect - github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/klauspost/compress v1.17.8 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/koron/go-ssdp v0.0.4 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-cidranger v1.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect - github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect + github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect github.com/libp2p/go-libp2p-kbucket v0.5.0 // indirect github.com/libp2p/go-libp2p-record v0.2.0 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect @@ -125,9 +144,8 @@ require ( github.com/libp2p/go-reuseport v0.4.0 // indirect github.com/libp2p/go-yamux/v4 v4.0.1 // indirect github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect - github.com/mattn/go-isatty v0.0.19 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/miekg/dns v1.1.55 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/miekg/dns v1.1.58 // indirect github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect github.com/minio/sha256-simd v1.0.1 // indirect @@ -139,39 +157,39 @@ require ( github.com/multiformats/go-multibase v0.2.0 // indirect github.com/multiformats/go-multicodec v0.9.0 // indirect github.com/multiformats/go-multihash v0.2.3 // indirect - github.com/multiformats/go-multistream v0.4.1 // indirect + github.com/multiformats/go-multistream v0.5.0 // indirect github.com/multiformats/go-varint v0.0.7 // indirect - github.com/onsi/ginkgo/v2 v2.11.0 // indirect - github.com/opencontainers/runtime-spec v1.1.0 // indirect + github.com/onsi/ginkgo/v2 v2.15.0 // indirect + github.com/opencontainers/runtime-spec v1.2.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect - github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect + github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 github.com/pkg/errors v0.9.1 github.com/polydawn/refmt v0.89.0 // indirect - github.com/prometheus/client_golang v1.16.0 // indirect - github.com/prometheus/client_model v0.4.0 // indirect - github.com/prometheus/common v0.44.0 // indirect - github.com/prometheus/procfs v0.11.1 // indirect + github.com/prometheus/client_golang v1.19.1 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.48.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/quic-go v0.36.3 // indirect - github.com/quic-go/webtransport-go v0.5.3 // indirect + github.com/quic-go/quic-go v0.44.0 // indirect + github.com/quic-go/webtransport-go v0.8.0 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect go.opencensus.io v0.24.0 // indirect - go.uber.org/dig v1.17.0 // indirect - go.uber.org/fx v1.20.0 // indirect + go.uber.org/dig v1.17.1 // indirect + go.uber.org/fx v1.21.1 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.26.0 - golang.org/x/crypto v0.18.0 - golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect - golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.20.0 // indirect - golang.org/x/sync v0.6.0 - golang.org/x/sys v0.16.0 // indirect - golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect + go.uber.org/zap v1.27.0 + golang.org/x/crypto v0.24.0 + golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sync v0.7.0 + golang.org/x/sys v0.21.0 + golang.org/x/text v0.16.0 // indirect + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect gonum.org/v1/gonum v0.11.0 // indirect google.golang.org/grpc v1.58.2 lukechampine.com/blake3 v1.2.1 // indirect diff --git a/node/go.sum b/node/go.sum index 477ae9e..10ddb19 100644 --- a/node/go.sum +++ b/node/go.sum @@ -53,11 +53,13 @@ github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEM github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4= +github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895 h1:XANOgPYtvELQ/h4IrmPAohXqe2pWA8Bwhejr3VQoZsA= +github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895/go.mod h1:aPd7gM9ov9M8v32Yy5NJrDyOcD8z642dqs+F0CeNXfA= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= @@ -84,8 +86,9 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= @@ -99,11 +102,12 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= -github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= +github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg= +github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= @@ -111,9 +115,11 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= +github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= +github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= @@ -129,13 +135,13 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE= +github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -160,28 +166,31 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f h1:pDhu5sgp8yJlEF/g6osliIIpF9K4F5jvkULXa4daRDQ= -github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 h1:E/LAvt58di64hlYjx7AsNS6C/ysHWYo+2qPCZKTQhRo= +github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/subcommands v1.0.1/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/wire v0.5.0 h1:I7ELFeVBr3yfPIcc8+MWvrjk+3VjbcSzoXm3JVa+jD8= github.com/google/wire v0.5.0/go.mod h1:ngWDr9Qvq3yZA10YrxfyGELY/AFWGVpy9c1LTRi1EoU= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRidnzC1Oq86fpX1q/iEv2KJdrCtttYjT4= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk= @@ -195,11 +204,11 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/golang-lru/v2 v2.0.2 h1:Dwmkdr5Nc/oBiXgJS3CDHNhJtIHkuZ3DZF5twqnfBdU= -github.com/hashicorp/golang-lru/v2 v2.0.2/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY= -github.com/huin/goupnp v1.2.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= +github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= +github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= github.com/iden3/go-iden3-crypto v0.0.15 h1:4MJYlrot1l31Fzlo2sF56u7EVFeHHJkxGXXZCtESgK4= github.com/iden3/go-iden3-crypto v0.0.15/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= github.com/ipfs/boxo v0.8.0 h1:UdjAJmHzQHo/j3g3b1bAcAXCj/GM6iTwvSlBDvPBNBs= @@ -229,19 +238,22 @@ github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZl github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= -github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= -github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= -github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= +github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -261,8 +273,8 @@ github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38y github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic= github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM= github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= -github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= -github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w= +github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94= +github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8= github.com/libp2p/go-libp2p-kad-dht v0.23.0 h1:sxE6LxLopp79eLeV695n7+c77V/Vn4AMF28AdM/XFqM= github.com/libp2p/go-libp2p-kad-dht v0.23.0/go.mod h1:oO5N308VT2msnQI6qi5M61wzPmJYg7Tr9e16m5n7uDU= github.com/libp2p/go-libp2p-kbucket v0.5.0 h1:g/7tVm8ACHDxH29BGrpsQlnNeu+6OF1A9bno/4/U1oA= @@ -270,6 +282,7 @@ github.com/libp2p/go-libp2p-kbucket v0.5.0/go.mod h1:zGzGCpQd78b5BNTDGHNDLaTt9aD github.com/libp2p/go-libp2p-record v0.2.0 h1:oiNUOCWno2BFuxt3my4i1frNrt7PerzB3queqa1NkQ0= github.com/libp2p/go-libp2p-record v0.2.0/go.mod h1:I+3zMkvvg5m2OcSdoL0KPljyJyvNDFGKX7QdlpYUcwk= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= +github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk= @@ -287,20 +300,18 @@ github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= -github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo= -github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= +github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4= +github.com/miekg/dns v1.1.58/go.mod h1:Ypv+3b/KadlvW9vJfXOTf300O4UqaHFzFCuHz+rPkBY= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c h1:bzE/A84HN25pxAuk9Eej1Kz9OUelF97nAc82bDquQI8= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c/go.mod h1:0SQS9kMwD2VsyFEB++InYyBJroV/FRmBgcydeSUcJms= github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b h1:z78hV3sbSMAUoyUMM0I83AUIT6Hu17AWfgjzIbtrYFc= @@ -315,6 +326,7 @@ github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dz github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= @@ -333,8 +345,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= -github.com/multiformats/go-multiaddr v0.11.0 h1:XqGyJ8ufbCE0HmTDwx2kPdsrQ36AGPZNZX6s6xfJH10= -github.com/multiformats/go-multiaddr v0.11.0/go.mod h1:gWUm0QLR4thQ6+ZF6SXUw8YjtwQSPapICM+NmCkxHSM= +github.com/multiformats/go-multiaddr v0.12.4 h1:rrKqpY9h+n80EwhhC/kkcunCZZ7URIF8yN1WEUt2Hvc= +github.com/multiformats/go-multiaddr v0.12.4/go.mod h1:sBXrNzucqkFJhvKOiwwLyqamGa/P5EIXNPLovyhQCII= github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= @@ -347,30 +359,77 @@ github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= -github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3de4741sbiSdfo= -github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= +github.com/multiformats/go-multistream v0.5.0 h1:5htLSLl7lvJk3xx3qT/8Zm9J4K8vEOf/QGkvOGQAyiE= +github.com/multiformats/go-multistream v0.5.0/go.mod h1:n6tMZiwiP2wUsR8DgfDWw1dydlEqV3l6N3/GBsX6ILA= github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= -github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= +github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= +github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc= +github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= +github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= -github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bll4AjJ9odEGpg= -github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= +github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk= +github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= +github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= +github.com/pion/datachannel v1.5.6 h1:1IxKJntfSlYkpUj8LlYRSWpYiTTC02nUrOE8T3DqGeg= +github.com/pion/datachannel v1.5.6/go.mod h1:1eKT6Q85pRnr2mHiWHxJwO50SfZRtWHTsNIVb/NfGW4= +github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s= +github.com/pion/dtls/v2 v2.2.11 h1:9U/dpCYl1ySttROPWJgqWKEylUdT0fXp/xst6JwY5Ks= +github.com/pion/dtls/v2 v2.2.11/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE= +github.com/pion/ice/v2 v2.3.24 h1:RYgzhH/u5lH0XO+ABatVKCtRd+4U1GEaCXSMjNr13tI= +github.com/pion/ice/v2 v2.3.24/go.mod h1:KXJJcZK7E8WzrBEYnV4UtqEZsGeWfHxsNqhVcVvgjxw= +github.com/pion/interceptor v0.1.29 h1:39fsnlP1U8gw2JzOFWdfCU82vHvhW9o0rZnZF56wF+M= +github.com/pion/interceptor v0.1.29/go.mod h1:ri+LGNjRUc5xUNtDEPzfdkmSqISixVTBF/z/Zms/6T4= +github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY= +github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms= +github.com/pion/mdns v0.0.12 h1:CiMYlY+O0azojWDmxdNr7ADGrnZ+V6Ilfner+6mSVK8= +github.com/pion/mdns v0.0.12/go.mod h1:VExJjv8to/6Wqm1FXK+Ii/Z9tsVk/F5sD/N70cnYFbk= +github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= +github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= +github.com/pion/rtcp v1.2.12/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= +github.com/pion/rtcp v1.2.14 h1:KCkGV3vJ+4DAJmvP0vaQShsb0xkRfWkO540Gy102KyE= +github.com/pion/rtcp v1.2.14/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= +github.com/pion/rtp v1.8.3/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= +github.com/pion/rtp v1.8.6 h1:MTmn/b0aWWsAzux2AmP8WGllusBVw4NPYPVFFd7jUPw= +github.com/pion/rtp v1.8.6/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= +github.com/pion/sctp v1.8.13/go.mod h1:YKSgO/bO/6aOMP9LCie1DuD7m+GamiK2yIiPM6vH+GA= +github.com/pion/sctp v1.8.16 h1:PKrMs+o9EMLRvFfXq59WFsC+V8mN1wnKzqrv+3D/gYY= +github.com/pion/sctp v1.8.16/go.mod h1:P6PbDVA++OJMrVNg2AL3XtYHV4uD6dvfyOovCgMs0PE= +github.com/pion/sdp/v3 v3.0.9 h1:pX++dCHoHUwq43kuwf3PyJfHlwIj4hXA7Vrifiq0IJY= +github.com/pion/sdp/v3 v3.0.9/go.mod h1:B5xmvENq5IXJimIO4zfp6LAe1fD9N+kFv+V/1lOdz8M= +github.com/pion/srtp/v2 v2.0.18 h1:vKpAXfawO9RtTRKZJbG4y0v1b11NZxQnxRl85kGuUlo= +github.com/pion/srtp/v2 v2.0.18/go.mod h1:0KJQjA99A6/a0DOVTu1PhDSw0CXF2jTkqOoMg3ODqdA= +github.com/pion/stun v0.6.1 h1:8lp6YejULeHBF8NmV8e2787BogQhduZugh5PdhDyyN4= +github.com/pion/stun v0.6.1/go.mod h1:/hO7APkX4hZKu/D0f2lHzNyvdkTGtIy3NDmLR7kSz/8= +github.com/pion/transport/v2 v2.2.1/go.mod h1:cXXWavvCnFF6McHTft3DWS9iic2Mftcz1Aq29pGcU5g= +github.com/pion/transport/v2 v2.2.2/go.mod h1:OJg3ojoBJopjEeECq2yJdXH9YVrUJ1uQ++NjXLOUorc= +github.com/pion/transport/v2 v2.2.3/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= +github.com/pion/transport/v2 v2.2.4/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= +github.com/pion/transport/v2 v2.2.5 h1:iyi25i/21gQck4hfRhomF6SktmUQjRsRW4WJdhfc3Kc= +github.com/pion/transport/v2 v2.2.5/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= +github.com/pion/transport/v3 v3.0.1/go.mod h1:UY7kiITrlMv7/IKgd5eTUcaahZx5oUN3l9SzK5f5xE0= +github.com/pion/transport/v3 v3.0.2 h1:r+40RJR25S9w3jbA6/5uEPTzcdn7ncyU44RWCbHkLg4= +github.com/pion/transport/v3 v3.0.2/go.mod h1:nIToODoOlb5If2jF9y2Igfx3PFYWfuXi37m0IlWa/D0= +github.com/pion/turn/v2 v2.1.3/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= +github.com/pion/turn/v2 v2.1.6 h1:Xr2niVsiPTB0FPtt+yAWKFUkU1eotQbGgpTIld4x1Gc= +github.com/pion/turn/v2 v2.1.6/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= +github.com/pion/webrtc/v3 v3.2.40 h1:Wtfi6AZMQg+624cvCXUuSmrKWepSB7zfgYDOYqsSOVU= +github.com/pion/webrtc/v3 v3.2.40/go.mod h1:M1RAe3TNTD1tzyvqHrbVODfwdPGSXOUo/OgpoGGJqFY= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -380,28 +439,24 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/polydawn/refmt v0.89.0 h1:ADJTApkvkeBZsN0tBTx8QjpD9JkmxbKp0cxfr9qszm4= github.com/polydawn/refmt v0.89.0/go.mod h1:/zvteZs/GwLtCgZ4BL6CBsk9IKIlexP43ObX9AxTqTw= github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8= -github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc= +github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= +github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= -github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY= -github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= +github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= +github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI= -github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/qtls-go1-19 v0.3.3 h1:wznEHvJwd+2X3PqftRha0SUKmGsnb6dfArMhy9PeJVE= -github.com/quic-go/qtls-go1-19 v0.3.3/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.2.3 h1:m575dovXn1y2ATOb1XrRFcrv0F+EQmlowTkoraNkDPI= -github.com/quic-go/qtls-go1-20 v0.2.3/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.36.3 h1:f+yOqeGhMoRX7/M3wmEw/djhzKWr15FtQysox85/834= -github.com/quic-go/quic-go v0.36.3/go.mod h1:qxQumdeKw5GmWs1OsTZZnOxzSI+RJWuhf1O8FN35L2o= -github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= -github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= +github.com/quic-go/quic-go v0.44.0 h1:So5wOr7jyO4vzL2sd8/pD9Kesciv91zSk8BoFngItQ0= +github.com/quic-go/quic-go v0.44.0/go.mod h1:z4cx/9Ny9UtGITIPzmPTXh1ULfOyWh4qGQlpnPcWmek= +github.com/quic-go/webtransport-go v0.8.0 h1:HxSrwun11U+LlmwpgM1kEqIqH90IT4N8auv/cD7QFJg= +github.com/quic-go/webtransport-go v0.8.0/go.mod h1:N99tjprW432Ut5ONql/aUhSLT0YVSlwHohQsuac9WaM= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -449,6 +504,7 @@ github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -457,8 +513,10 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= @@ -471,6 +529,7 @@ github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= @@ -480,13 +539,15 @@ go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyK go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= -go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI= -go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU= -go.uber.org/fx v1.20.0 h1:ZMC/pnRvhsthOZh9MZjMq5U8Or3mA9zBSPaLnzs3ihQ= -go.uber.org/fx v1.20.0/go.mod h1:qCUj0btiR3/JnanEr1TYEePfSw6o/4qYJscgvzQ5Ub0= +go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc= +go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE= +go.uber.org/fx v1.21.1 h1:RqBh3cYdzZS0uqwVeEjOX2p73dddLpym315myy/Bpb0= +go.uber.org/fx v1.21.1/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -494,8 +555,8 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8 go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= -go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= -go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -510,11 +571,16 @@ golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ= -golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -528,6 +594,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -546,8 +614,15 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -561,8 +636,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -579,22 +654,47 @@ golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= +golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= +golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= +golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -612,10 +712,11 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 h1:Vve/L0v7CXXuxUmaMGIEK/dEeq7uiqb5qBgQrZzIE7E= golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -637,6 +738,7 @@ google.golang.org/genproto v0.0.0-20190306203927-b5d61aea6440/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 h1:L6iMMGrtzgHsWofoFcihmDEMYeDR9KN/ThbPWGrh++g= +google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5/go.mod h1:oH/ZOT02u4kWEp7oYBGYFFkCdKS/uYR9Z7+0/xuuFp8= google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d h1:DoPTO70H+bcDXcd39vOqb2viZxgqeBeSGtZ55yZU4/Q= google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4= @@ -662,10 +764,11 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/node/main.go b/node/main.go index 137f556..f7ffce3 100644 --- a/node/main.go +++ b/node/main.go @@ -11,6 +11,7 @@ import ( "fmt" "io/fs" "log" + "math/big" "os" "os/exec" "os/signal" @@ -102,8 +103,8 @@ var ( ) signatureCheck = flag.Bool( "signature-check", - true, - "enables or disables signature validation (default true)", + signatureCheckDefault(), + "enables or disables signature validation (default true or value of QUILIBRIUM_SIGNATURE_CHECK env var)", ) core = flag.Int( "core", @@ -137,6 +138,20 @@ var signatories = []string{ "a114b061f8d35e3f3497c8c43d83ba6b4af67aa7b39b743b1b0a35f2d66110b5051dd3d86f69b57122a35b64e624b8180bee63b6152fce4280", } +func signatureCheckDefault() bool { + envVarValue, envVarExists := os.LookupEnv("QUILIBRIUM_SIGNATURE_CHECK") + if envVarExists { + def, err := strconv.ParseBool(envVarValue) + if err == nil { + return def + } else { + fmt.Println("Invalid environment variable QUILIBRIUM_SIGNATURE_CHECK, must be 'true' or 'false'. Got: " + envVarValue) + } + } + + return true +} + func main() { flag.Parse() @@ -206,6 +221,8 @@ func main() { fmt.Println("Signature check passed") } + } else { + fmt.Println("Signature check disabled, skipping...") } if *memprofile != "" { @@ -273,9 +290,6 @@ func main() { return } - done := make(chan os.Signal, 1) - signal.Notify(done, syscall.SIGINT, syscall.SIGTERM) - if !*dbConsole && *core == 0 { printLogo() printVersion() @@ -320,6 +334,8 @@ func main() { } if *dhtOnly { + done := make(chan os.Signal, 1) + signal.Notify(done, syscall.SIGINT, syscall.SIGTERM) dht, err := app.NewDHTNode(nodeConfig) if err != nil { panic(err) @@ -352,7 +368,7 @@ func main() { nodeConfig.Engine.DataWorkerBaseListenPort = 40000 } - if *parentProcess == 0 { + if *parentProcess == 0 && len(nodeConfig.Engine.DataWorkerMultiaddrs) == 0 { panic("parent process pid not specified") } @@ -365,6 +381,11 @@ func main() { nodeConfig.Engine.DataWorkerBaseListenMultiaddr, int(nodeConfig.Engine.DataWorkerBaseListenPort)+*core-1, ) + + if len(nodeConfig.Engine.DataWorkerMultiaddrs) != 0 { + rpcMultiaddr = nodeConfig.Engine.DataWorkerMultiaddrs[*core-1] + } + srv, err := rpc.NewDataWorkerIPCServer( rpcMultiaddr, l, @@ -384,12 +405,15 @@ func main() { } fmt.Println("Loading ceremony state and starting node...") - go spawnDataWorkers() + go spawnDataWorkers(nodeConfig) kzg.Init() report := RunSelfTestIfNeeded(*configDirectory, nodeConfig) + RunMigrationIfNeeded(*configDirectory, nodeConfig) + done := make(chan os.Signal, 1) + signal.Notify(done, syscall.SIGINT, syscall.SIGTERM) var node *app.Node if *debug { node, err = app.NewDebugNode(nodeConfig, report) @@ -407,6 +431,7 @@ func main() { nodeConfig.ListenGRPCMultiaddr, nodeConfig.ListenRestMultiaddr, node.GetLogger(), + node.GetDataProofStore(), node.GetClockStore(), node.GetKeyManager(), node.GetPubSub(), @@ -434,7 +459,14 @@ func main() { var dataWorkers []*exec.Cmd -func spawnDataWorkers() { +func spawnDataWorkers(nodeConfig *config.Config) { + if len(nodeConfig.Engine.DataWorkerMultiaddrs) != 0 { + fmt.Println( + "Data workers configured by multiaddr, be sure these are running...", + ) + return + } + process, err := os.Executable() if err != nil { panic(err) @@ -454,7 +486,7 @@ func spawnDataWorkers() { args = append(args, os.Args[1:]...) cmd := exec.Command(process, args...) cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr + cmd.Stderr = os.Stdout err := cmd.Start() if err != nil { panic(err) @@ -497,6 +529,56 @@ func RunCompaction(clockStore *store.PebbleClockStore) { fmt.Println("compaction complete") } +func RunMigrationIfNeeded( + configDir string, + nodeConfig *config.Config, +) { + shouldMigrate := false + migrationInfo := []byte{0x00, 0x00, 0x00} + _, err := os.Stat(filepath.Join(configDir, "MIGRATIONS")) + if err != nil && os.IsNotExist(err) { + fmt.Println("Migrations file not found, will perform migration...") + shouldMigrate = true + } + + if !shouldMigrate { + migrationInfo, err = os.ReadFile(filepath.Join(configDir, "MIGRATIONS")) + if err != nil { + panic(err) + } + + if len(migrationInfo) < 3 || + !bytes.Equal(migrationInfo, []byte{0x01, 0x04, 0x013}) { + fmt.Println("Migrations file outdated, will perform migration...") + shouldMigrate = true + } + } + + // If subsequent migrations arise, we will need to distinguish by version + if shouldMigrate { + fmt.Println("Running migration...") + + // Easiest migration in the world. + err := os.RemoveAll(filepath.Join(configDir, "store")) + if err != nil { + fmt.Println("ERROR: Could not remove store, please be sure to do this before restarting the node.") + panic(err) + } + + err = os.WriteFile( + filepath.Join(configDir, "MIGRATIONS"), + []byte{0x01, 0x04, 0x13}, + fs.FileMode(0600), + ) + if err != nil { + fmt.Println("ERROR: Could not save migration file.") + panic(err) + } + + fmt.Println("Migration completed.") + } +} + func RunSelfTestIfNeeded( configDir string, nodeConfig *config.Config, @@ -504,6 +586,10 @@ func RunSelfTestIfNeeded( logger, _ := zap.NewProduction() cores := runtime.GOMAXPROCS(0) + if len(nodeConfig.Engine.DataWorkerMultiaddrs) != 0 { + cores = len(nodeConfig.Engine.DataWorkerMultiaddrs) + 1 + } + memory := memory.TotalMemory() d, err := os.Stat(filepath.Join(configDir, "store")) if d == nil { @@ -539,8 +625,8 @@ func RunSelfTestIfNeeded( report := &protobufs.SelfTestReport{} difficulty := nodeConfig.Engine.Difficulty - if difficulty == 0 { - difficulty = 10000 + if difficulty == 0 || difficulty == 10000 { + difficulty = 100000 } report.Difficulty = difficulty @@ -756,8 +842,11 @@ func printBalance(config *config.Config) { panic(err) } - fmt.Println("Owned balance:", balance.Owned, "QUIL") - fmt.Println("Unconfirmed balance:", balance.UnconfirmedOwned, "QUIL") + // fmt.Println("Owned balance:", balance.Owned, "QUIL") + conversionFactor, _ := new(big.Int).SetString("1DCD65000", 16) + r := new(big.Rat).SetFrac(balance.UnconfirmedOwned, conversionFactor) + fmt.Println("Note: Balance is strictly rewards earned with 1.4.19+, check https://www.quilibrium.com/rewards for more info about previous rewards.") + fmt.Println("Unclaimed balance:", r.FloatString(12), "QUIL") } func printPeerID(p2pConfig *config.P2PConfig) { @@ -812,26 +901,26 @@ func printLogo() { fmt.Println(" ..---'''' ''''---..") fmt.Println(" .---'' ''---.") fmt.Println(" .-' '-.") - fmt.Println(" ..-' ..--'''''''''''%######################") - fmt.Println(" .' .--'' #################") - fmt.Println(" .'' ..-' ###############") - fmt.Println(" ' ' ##############") - fmt.Println(" '' .'' ############&") - fmt.Println(" ' '' ############") - fmt.Println(" ' ' ########## &###########") - fmt.Println(" ' ' ############## ###########") - fmt.Println(" ' ' ############## ##########&") - fmt.Println(" ' ' ############## ##########") - fmt.Println("' ' ########## ##########") - fmt.Println("' ' ##########") - fmt.Println("' ' &#########") - fmt.Println("' ' ####### ####### ##########") - fmt.Println("' ' &######################### ##########") - fmt.Println(" ' ' ##############% ############## &##########") - fmt.Println(" ' ' &############## ############### ##########") - fmt.Println(" ' ' ############### ##############% ###########") - fmt.Println(" ' '. ########## ############### ########") - fmt.Println(" '. . ##### ##############% ####") + fmt.Println(" ..-' ..--''''''''''''''--.. '-..") + fmt.Println(" .' .--'' ''--. ''.") + fmt.Println(" .'' ..-' ''-. '.") + fmt.Println(" ' ' ''. '.") + fmt.Println(" '' .'' '. '") + fmt.Println(" ' '' '. '") + fmt.Println(" ' ' ########## . '") + fmt.Println(" ' ' ############## ' '") + fmt.Println(" ' ' ############## ' '") + fmt.Println(" ' ' ############## ' '") + fmt.Println("' ' ########## ' '") + fmt.Println("' ' ' '") + fmt.Println("' ' ' '") + fmt.Println("' ' ####### ####### ' '") + fmt.Println("' ' &######################### ' '") + fmt.Println("' ' ##############% ############## ' '") + fmt.Println(" ' ' &############## ############### ' '") + fmt.Println(" ' ' ############### ##############% '. '") + fmt.Println(" ' '. ########## ############### '-. '") + fmt.Println(" '. . ##### ##############% '-.'") fmt.Println(" ' '. ###############") fmt.Println(" '. '.. ##############%") fmt.Println(" '. '-. ###############") @@ -850,5 +939,5 @@ func printVersion() { patchString = fmt.Sprintf("-p%d", patch) } fmt.Println(" ") - fmt.Println(" Quilibrium Node - v" + config.GetVersionString() + patchString + " – Nebula") + fmt.Println(" Quilibrium Node - v" + config.GetVersionString() + patchString + " – Betelgeuse") } diff --git a/node/node-1.4.18-darwin-arm64.dgst b/node/node-1.4.18-darwin-arm64.dgst deleted file mode 100644 index c8d67e2..0000000 --- a/node/node-1.4.18-darwin-arm64.dgst +++ /dev/null @@ -1 +0,0 @@ -SHA3-256(node-1.4.18-darwin-arm64)= 0f666d6c3814f96bebce455034fe6a44b64f223b4e313ac506f42fa2371ac30d diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.1 b/node/node-1.4.18-darwin-arm64.dgst.sig.1 deleted file mode 100644 index f2f6a14..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.1 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.12 b/node/node-1.4.18-darwin-arm64.dgst.sig.12 deleted file mode 100644 index d3137d9..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.12 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.13 b/node/node-1.4.18-darwin-arm64.dgst.sig.13 deleted file mode 100644 index 8e00e26..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.13 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.14 b/node/node-1.4.18-darwin-arm64.dgst.sig.14 deleted file mode 100644 index 939b099..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.14 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.15 b/node/node-1.4.18-darwin-arm64.dgst.sig.15 deleted file mode 100644 index fff4fac..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.15 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.16 b/node/node-1.4.18-darwin-arm64.dgst.sig.16 deleted file mode 100644 index 9807929..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.16 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.17 b/node/node-1.4.18-darwin-arm64.dgst.sig.17 deleted file mode 100644 index c719e16..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.17 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.2 b/node/node-1.4.18-darwin-arm64.dgst.sig.2 deleted file mode 100644 index 9e05512..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.2 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.3 b/node/node-1.4.18-darwin-arm64.dgst.sig.3 deleted file mode 100644 index 901b0ad..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.3 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.4 b/node/node-1.4.18-darwin-arm64.dgst.sig.4 deleted file mode 100644 index 433eedc..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.4 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.5 b/node/node-1.4.18-darwin-arm64.dgst.sig.5 deleted file mode 100644 index 0e52649..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.5 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.6 b/node/node-1.4.18-darwin-arm64.dgst.sig.6 deleted file mode 100644 index d4d68d9..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.6 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.8 b/node/node-1.4.18-darwin-arm64.dgst.sig.8 deleted file mode 100644 index cbf75a3..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.8 and /dev/null differ diff --git a/node/node-1.4.18-darwin-arm64.dgst.sig.9 b/node/node-1.4.18-darwin-arm64.dgst.sig.9 deleted file mode 100644 index 7157385..0000000 Binary files a/node/node-1.4.18-darwin-arm64.dgst.sig.9 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst b/node/node-1.4.18-linux-amd64.dgst deleted file mode 100644 index f619e63..0000000 --- a/node/node-1.4.18-linux-amd64.dgst +++ /dev/null @@ -1 +0,0 @@ -SHA3-256(node-1.4.18-linux-amd64)= f2da38a5c8d4257767f4a9659ca9c05d4cf312fd7294e6a18847c8923f6815a0 diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.1 b/node/node-1.4.18-linux-amd64.dgst.sig.1 deleted file mode 100644 index a7949bc..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.1 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.12 b/node/node-1.4.18-linux-amd64.dgst.sig.12 deleted file mode 100644 index b4fd9f5..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.12 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.13 b/node/node-1.4.18-linux-amd64.dgst.sig.13 deleted file mode 100644 index bd9c141..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.13 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.14 b/node/node-1.4.18-linux-amd64.dgst.sig.14 deleted file mode 100644 index 206197d..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.14 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.15 b/node/node-1.4.18-linux-amd64.dgst.sig.15 deleted file mode 100644 index 32ee7f4..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.15 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.16 b/node/node-1.4.18-linux-amd64.dgst.sig.16 deleted file mode 100644 index 490e99a..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.16 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.17 b/node/node-1.4.18-linux-amd64.dgst.sig.17 deleted file mode 100644 index ea5e17f..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.17 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.2 b/node/node-1.4.18-linux-amd64.dgst.sig.2 deleted file mode 100644 index 0e07cb9..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.2 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.3 b/node/node-1.4.18-linux-amd64.dgst.sig.3 deleted file mode 100644 index 825eca9..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.3 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.4 b/node/node-1.4.18-linux-amd64.dgst.sig.4 deleted file mode 100644 index dc59ed7..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.4 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.5 b/node/node-1.4.18-linux-amd64.dgst.sig.5 deleted file mode 100644 index 23cf3ed..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.5 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.6 b/node/node-1.4.18-linux-amd64.dgst.sig.6 deleted file mode 100644 index 3ea21bc..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.6 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.8 b/node/node-1.4.18-linux-amd64.dgst.sig.8 deleted file mode 100644 index 435ff71..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.8 and /dev/null differ diff --git a/node/node-1.4.18-linux-amd64.dgst.sig.9 b/node/node-1.4.18-linux-amd64.dgst.sig.9 deleted file mode 100644 index d39a4f6..0000000 Binary files a/node/node-1.4.18-linux-amd64.dgst.sig.9 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst b/node/node-1.4.18-linux-arm64.dgst deleted file mode 100644 index 79e41a2..0000000 --- a/node/node-1.4.18-linux-arm64.dgst +++ /dev/null @@ -1 +0,0 @@ -SHA3-256(node-1.4.18-linux-arm64)= e12e14a18a491921fcdd4ffe6e9792f1e195abf4950fe56316219f920867c45a diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.1 b/node/node-1.4.18-linux-arm64.dgst.sig.1 deleted file mode 100644 index 10dd863..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.1 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.12 b/node/node-1.4.18-linux-arm64.dgst.sig.12 deleted file mode 100644 index a5bd10d..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.12 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.13 b/node/node-1.4.18-linux-arm64.dgst.sig.13 deleted file mode 100644 index 70d157c..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.13 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.14 b/node/node-1.4.18-linux-arm64.dgst.sig.14 deleted file mode 100644 index 3ee2e94..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.14 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.15 b/node/node-1.4.18-linux-arm64.dgst.sig.15 deleted file mode 100644 index afbc1c5..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.15 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.16 b/node/node-1.4.18-linux-arm64.dgst.sig.16 deleted file mode 100644 index 71c3e87..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.16 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.17 b/node/node-1.4.18-linux-arm64.dgst.sig.17 deleted file mode 100644 index aacb133..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.17 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.2 b/node/node-1.4.18-linux-arm64.dgst.sig.2 deleted file mode 100644 index d7bdcc3..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.2 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.3 b/node/node-1.4.18-linux-arm64.dgst.sig.3 deleted file mode 100644 index 293207a..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.3 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.4 b/node/node-1.4.18-linux-arm64.dgst.sig.4 deleted file mode 100644 index c8376d0..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.4 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.5 b/node/node-1.4.18-linux-arm64.dgst.sig.5 deleted file mode 100644 index 5985fcf..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.5 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.6 b/node/node-1.4.18-linux-arm64.dgst.sig.6 deleted file mode 100644 index b9c5782..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.6 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.8 b/node/node-1.4.18-linux-arm64.dgst.sig.8 deleted file mode 100644 index 2026957..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.8 and /dev/null differ diff --git a/node/node-1.4.18-linux-arm64.dgst.sig.9 b/node/node-1.4.18-linux-arm64.dgst.sig.9 deleted file mode 100644 index 8295904..0000000 Binary files a/node/node-1.4.18-linux-arm64.dgst.sig.9 and /dev/null differ diff --git a/node/node-1.4.19-darwin-arm64.dgst b/node/node-1.4.19-darwin-arm64.dgst new file mode 100644 index 0000000..5cb06fe --- /dev/null +++ b/node/node-1.4.19-darwin-arm64.dgst @@ -0,0 +1 @@ +SHA3-256(node-1.4.19-darwin-arm64)= 924122929b306554820ffcee0c2137ec44762da2b24890775f39409059750901 diff --git a/node/node-1.4.19-darwin-arm64.dgst.sig.1 b/node/node-1.4.19-darwin-arm64.dgst.sig.1 new file mode 100644 index 0000000..98dab0b Binary files /dev/null and b/node/node-1.4.19-darwin-arm64.dgst.sig.1 differ diff --git a/node/node-1.4.19-darwin-arm64.dgst.sig.13 b/node/node-1.4.19-darwin-arm64.dgst.sig.13 new file mode 100644 index 0000000..d9d8696 Binary files /dev/null and b/node/node-1.4.19-darwin-arm64.dgst.sig.13 differ diff --git a/node/node-1.4.19-darwin-arm64.dgst.sig.15 b/node/node-1.4.19-darwin-arm64.dgst.sig.15 new file mode 100644 index 0000000..c4f7357 Binary files /dev/null and b/node/node-1.4.19-darwin-arm64.dgst.sig.15 differ diff --git a/node/node-1.4.19-darwin-arm64.dgst.sig.16 b/node/node-1.4.19-darwin-arm64.dgst.sig.16 new file mode 100644 index 0000000..e391635 Binary files /dev/null and b/node/node-1.4.19-darwin-arm64.dgst.sig.16 differ diff --git a/node/node-1.4.19-darwin-arm64.dgst.sig.2 b/node/node-1.4.19-darwin-arm64.dgst.sig.2 new file mode 100644 index 0000000..4438124 Binary files /dev/null and b/node/node-1.4.19-darwin-arm64.dgst.sig.2 differ diff --git a/node/node-1.4.19-darwin-arm64.dgst.sig.3 b/node/node-1.4.19-darwin-arm64.dgst.sig.3 new file mode 100644 index 0000000..8e200b2 Binary files /dev/null and b/node/node-1.4.19-darwin-arm64.dgst.sig.3 differ diff --git a/node/node-1.4.19-darwin-arm64.dgst.sig.4 b/node/node-1.4.19-darwin-arm64.dgst.sig.4 new file mode 100644 index 0000000..d4fb712 Binary files /dev/null and b/node/node-1.4.19-darwin-arm64.dgst.sig.4 differ diff --git a/node/node-1.4.19-darwin-arm64.dgst.sig.6 b/node/node-1.4.19-darwin-arm64.dgst.sig.6 new file mode 100644 index 0000000..bf4630f Binary files /dev/null and b/node/node-1.4.19-darwin-arm64.dgst.sig.6 differ diff --git a/node/node-1.4.19-darwin-arm64.dgst.sig.8 b/node/node-1.4.19-darwin-arm64.dgst.sig.8 new file mode 100644 index 0000000..ded7847 Binary files /dev/null and b/node/node-1.4.19-darwin-arm64.dgst.sig.8 differ diff --git a/node/node-1.4.19-linux-amd64.dgst b/node/node-1.4.19-linux-amd64.dgst new file mode 100644 index 0000000..9cd8b55 --- /dev/null +++ b/node/node-1.4.19-linux-amd64.dgst @@ -0,0 +1 @@ +SHA3-256(node-1.4.19-linux-amd64)= e13e48d20dc674d8604212e2aba3195c98322d6be1e09b9fa8bbf6ec68c77277 diff --git a/node/node-1.4.19-linux-amd64.dgst.sig.1 b/node/node-1.4.19-linux-amd64.dgst.sig.1 new file mode 100644 index 0000000..a6e834e Binary files /dev/null and b/node/node-1.4.19-linux-amd64.dgst.sig.1 differ diff --git a/node/node-1.4.19-linux-amd64.dgst.sig.13 b/node/node-1.4.19-linux-amd64.dgst.sig.13 new file mode 100644 index 0000000..4e3af9f Binary files /dev/null and b/node/node-1.4.19-linux-amd64.dgst.sig.13 differ diff --git a/node/node-1.4.19-linux-amd64.dgst.sig.15 b/node/node-1.4.19-linux-amd64.dgst.sig.15 new file mode 100644 index 0000000..50484ab Binary files /dev/null and b/node/node-1.4.19-linux-amd64.dgst.sig.15 differ diff --git a/node/node-1.4.19-linux-amd64.dgst.sig.16 b/node/node-1.4.19-linux-amd64.dgst.sig.16 new file mode 100644 index 0000000..900e4ab Binary files /dev/null and b/node/node-1.4.19-linux-amd64.dgst.sig.16 differ diff --git a/node/node-1.4.19-linux-amd64.dgst.sig.2 b/node/node-1.4.19-linux-amd64.dgst.sig.2 new file mode 100644 index 0000000..4d29451 Binary files /dev/null and b/node/node-1.4.19-linux-amd64.dgst.sig.2 differ diff --git a/node/node-1.4.19-linux-amd64.dgst.sig.3 b/node/node-1.4.19-linux-amd64.dgst.sig.3 new file mode 100644 index 0000000..4b3919e Binary files /dev/null and b/node/node-1.4.19-linux-amd64.dgst.sig.3 differ diff --git a/node/node-1.4.19-linux-amd64.dgst.sig.4 b/node/node-1.4.19-linux-amd64.dgst.sig.4 new file mode 100644 index 0000000..f44d3f0 Binary files /dev/null and b/node/node-1.4.19-linux-amd64.dgst.sig.4 differ diff --git a/node/node-1.4.19-linux-amd64.dgst.sig.6 b/node/node-1.4.19-linux-amd64.dgst.sig.6 new file mode 100644 index 0000000..d930528 Binary files /dev/null and b/node/node-1.4.19-linux-amd64.dgst.sig.6 differ diff --git a/node/node-1.4.19-linux-amd64.dgst.sig.8 b/node/node-1.4.19-linux-amd64.dgst.sig.8 new file mode 100644 index 0000000..aaa6dcf Binary files /dev/null and b/node/node-1.4.19-linux-amd64.dgst.sig.8 differ diff --git a/node/node-1.4.19-linux-arm64.dgst b/node/node-1.4.19-linux-arm64.dgst new file mode 100644 index 0000000..a35672e --- /dev/null +++ b/node/node-1.4.19-linux-arm64.dgst @@ -0,0 +1 @@ +SHA3-256(node-1.4.19-linux-arm64)= 1fed24e340c40d609649a62eed4993046d683421f2730eea68f4178781caa6f2 diff --git a/node/node-1.4.19-linux-arm64.dgst.sig.1 b/node/node-1.4.19-linux-arm64.dgst.sig.1 new file mode 100644 index 0000000..87e9476 Binary files /dev/null and b/node/node-1.4.19-linux-arm64.dgst.sig.1 differ diff --git a/node/node-1.4.19-linux-arm64.dgst.sig.13 b/node/node-1.4.19-linux-arm64.dgst.sig.13 new file mode 100644 index 0000000..b300288 Binary files /dev/null and b/node/node-1.4.19-linux-arm64.dgst.sig.13 differ diff --git a/node/node-1.4.19-linux-arm64.dgst.sig.15 b/node/node-1.4.19-linux-arm64.dgst.sig.15 new file mode 100644 index 0000000..27fc431 Binary files /dev/null and b/node/node-1.4.19-linux-arm64.dgst.sig.15 differ diff --git a/node/node-1.4.19-linux-arm64.dgst.sig.16 b/node/node-1.4.19-linux-arm64.dgst.sig.16 new file mode 100644 index 0000000..9efa7ce Binary files /dev/null and b/node/node-1.4.19-linux-arm64.dgst.sig.16 differ diff --git a/node/node-1.4.19-linux-arm64.dgst.sig.2 b/node/node-1.4.19-linux-arm64.dgst.sig.2 new file mode 100644 index 0000000..a26c684 Binary files /dev/null and b/node/node-1.4.19-linux-arm64.dgst.sig.2 differ diff --git a/node/node-1.4.19-linux-arm64.dgst.sig.3 b/node/node-1.4.19-linux-arm64.dgst.sig.3 new file mode 100644 index 0000000..6960541 Binary files /dev/null and b/node/node-1.4.19-linux-arm64.dgst.sig.3 differ diff --git a/node/node-1.4.19-linux-arm64.dgst.sig.4 b/node/node-1.4.19-linux-arm64.dgst.sig.4 new file mode 100644 index 0000000..af35b39 Binary files /dev/null and b/node/node-1.4.19-linux-arm64.dgst.sig.4 differ diff --git a/node/node-1.4.19-linux-arm64.dgst.sig.6 b/node/node-1.4.19-linux-arm64.dgst.sig.6 new file mode 100644 index 0000000..ca5849c Binary files /dev/null and b/node/node-1.4.19-linux-arm64.dgst.sig.6 differ diff --git a/node/node-1.4.19-linux-arm64.dgst.sig.8 b/node/node-1.4.19-linux-arm64.dgst.sig.8 new file mode 100644 index 0000000..9d3f95f Binary files /dev/null and b/node/node-1.4.19-linux-arm64.dgst.sig.8 differ diff --git a/node/p2p/blossomsub.go b/node/p2p/blossomsub.go index f16fe9c..76c0253 100644 --- a/node/p2p/blossomsub.go +++ b/node/p2p/blossomsub.go @@ -61,7 +61,7 @@ var BITMASK_ALL = []byte{ // While we iterate through these next phases, we're going to aggressively // enforce keeping updated. This will be achieved through announce strings // that will vary with each update -var ANNOUNCE_PREFIX = "quilibrium-1.4.18-nebula-" +var ANNOUNCE_PREFIX = "quilibrium-1.4.19-betelgeuse-" func getPeerID(p2pConfig *config.P2PConfig) peer.ID { peerPrivKey, err := hex.DecodeString(p2pConfig.PeerPrivKey) @@ -341,7 +341,8 @@ func initDHT( if isBootstrapPeer { kademliaDHT, err = dht.New(ctx, h, dht.Mode(dht.ModeServer)) } else { - kademliaDHT, err = dht.New(ctx, h, dht.Mode(dht.ModeAuto)) + // until libp2p gets their shit together, set this as a client only: + kademliaDHT, err = dht.New(ctx, h, dht.Mode(dht.ModeClient)) } if err != nil { panic(err) @@ -583,18 +584,18 @@ func discoverPeers( continue } - logger.Debug("found peer", zap.String("peer_id", peer.ID.Pretty())) + logger.Debug("found peer", zap.String("peer_id", peer.ID.String())) err := h.Connect(ctx, peer) if err != nil { logger.Debug( "error while connecting to blossomsub peer", - zap.String("peer_id", peer.ID.Pretty()), + zap.String("peer_id", peer.ID.String()), zap.Error(err), ) } else { logger.Debug( "connected to peer", - zap.String("peer_id", peer.ID.Pretty()), + zap.String("peer_id", peer.ID.String()), ) } } diff --git a/node/protobufs/data.pb.go b/node/protobufs/data.pb.go index 538d8ab..cac5e5b 100644 --- a/node/protobufs/data.pb.go +++ b/node/protobufs/data.pb.go @@ -27,8 +27,7 @@ type ChallengeProofRequest struct { Challenge []byte `protobuf:"bytes,1,opt,name=challenge,proto3" json:"challenge,omitempty"` Core uint32 `protobuf:"varint,2,opt,name=core,proto3" json:"core,omitempty"` - Skew int64 `protobuf:"varint,3,opt,name=skew,proto3" json:"skew,omitempty"` - NowMs int64 `protobuf:"varint,4,opt,name=now_ms,json=nowMs,proto3" json:"now_ms,omitempty"` + Increment uint32 `protobuf:"varint,3,opt,name=increment,proto3" json:"increment,omitempty"` } func (x *ChallengeProofRequest) Reset() { @@ -77,16 +76,9 @@ func (x *ChallengeProofRequest) GetCore() uint32 { return 0 } -func (x *ChallengeProofRequest) GetSkew() int64 { +func (x *ChallengeProofRequest) GetIncrement() uint32 { if x != nil { - return x.Skew - } - return 0 -} - -func (x *ChallengeProofRequest) GetNowMs() int64 { - if x != nil { - return x.NowMs + return x.Increment } return 0 } @@ -96,8 +88,7 @@ type ChallengeProofResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Output []byte `protobuf:"bytes,1,opt,name=output,proto3" json:"output,omitempty"` - NextSkew int64 `protobuf:"varint,2,opt,name=next_skew,json=nextSkew,proto3" json:"next_skew,omitempty"` + Output []byte `protobuf:"bytes,1,opt,name=output,proto3" json:"output,omitempty"` } func (x *ChallengeProofResponse) Reset() { @@ -139,44 +130,35 @@ func (x *ChallengeProofResponse) GetOutput() []byte { return nil } -func (x *ChallengeProofResponse) GetNextSkew() int64 { - if x != nil { - return x.NextSkew - } - return 0 -} - var File_data_proto protoreflect.FileDescriptor var file_data_proto_rawDesc = []byte{ 0x0a, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x17, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x64, 0x61, - 0x74, 0x61, 0x2e, 0x70, 0x62, 0x22, 0x74, 0x0a, 0x15, 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, + 0x74, 0x61, 0x2e, 0x70, 0x62, 0x22, 0x67, 0x0a, 0x15, 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x63, 0x6f, 0x72, 0x65, - 0x12, 0x12, 0x0a, 0x04, 0x73, 0x6b, 0x65, 0x77, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, - 0x73, 0x6b, 0x65, 0x77, 0x12, 0x15, 0x0a, 0x06, 0x6e, 0x6f, 0x77, 0x5f, 0x6d, 0x73, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x6e, 0x6f, 0x77, 0x4d, 0x73, 0x22, 0x4d, 0x0a, 0x16, 0x43, - 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x12, 0x1b, 0x0a, - 0x09, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x73, 0x6b, 0x65, 0x77, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, - 0x52, 0x08, 0x6e, 0x65, 0x78, 0x74, 0x53, 0x6b, 0x65, 0x77, 0x32, 0x8c, 0x01, 0x0a, 0x0e, 0x44, - 0x61, 0x74, 0x61, 0x49, 0x50, 0x43, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x7a, 0x0a, - 0x17, 0x43, 0x61, 0x6c, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x65, 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, - 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2e, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, - 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x2e, - 0x70, 0x62, 0x2e, 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, - 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, - 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x2e, - 0x70, 0x62, 0x2e, 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, - 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3a, 0x5a, 0x38, 0x73, 0x6f, 0x75, - 0x72, 0x63, 0x65, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2f, 0x6d, 0x6f, - 0x6e, 0x6f, 0x72, 0x65, 0x70, 0x6f, 0x2f, 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x09, 0x69, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x30, + 0x0a, 0x16, 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x32, 0x8c, 0x01, 0x0a, 0x0e, 0x44, 0x61, 0x74, 0x61, 0x49, 0x50, 0x43, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x7a, 0x0a, 0x17, 0x43, 0x61, 0x6c, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x65, + 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2e, + 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, + 0x2e, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, + 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, + 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, + 0x2e, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, + 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, + 0x3a, 0x5a, 0x38, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, + 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, + 0x69, 0x75, 0x6d, 0x2f, 0x6d, 0x6f, 0x6e, 0x6f, 0x72, 0x65, 0x70, 0x6f, 0x2f, 0x6e, 0x6f, 0x64, + 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( diff --git a/node/protobufs/data.proto b/node/protobufs/data.proto index 1e959c6..8082065 100644 --- a/node/protobufs/data.proto +++ b/node/protobufs/data.proto @@ -7,13 +7,11 @@ option go_package = "source.quilibrium.com/quilibrium/monorepo/node/protobufs"; message ChallengeProofRequest { bytes challenge = 1; uint32 core = 2; - int64 skew = 3; - int64 now_ms = 4; + uint32 increment = 3; } message ChallengeProofResponse { bytes output = 1; - int64 next_skew = 2; } service DataIPCService { diff --git a/node/protobufs/node.pb.go b/node/protobufs/node.pb.go index c666428..f745e9f 100644 --- a/node/protobufs/node.pb.go +++ b/node/protobufs/node.pb.go @@ -1096,6 +1096,10 @@ type SelfTestReport struct { MasterHeadFrame uint64 `protobuf:"varint,15,opt,name=master_head_frame,json=masterHeadFrame,proto3" json:"master_head_frame,omitempty"` // A challenge proof Proof []byte `protobuf:"bytes,16,opt,name=proof,proto3" json:"proof,omitempty"` + // The challenge, minus the peer id + Challenge []byte `protobuf:"bytes,17,opt,name=challenge,proto3" json:"challenge,omitempty"` + // The increment value + Increment uint32 `protobuf:"varint,18,opt,name=increment,proto3" json:"increment,omitempty"` } func (x *SelfTestReport) Reset() { @@ -1242,6 +1246,20 @@ func (x *SelfTestReport) GetProof() []byte { return nil } +func (x *SelfTestReport) GetChallenge() []byte { + if x != nil { + return x.Challenge + } + return nil +} + +func (x *SelfTestReport) GetIncrement() uint32 { + if x != nil { + return x.Increment + } + return 0 +} + type ValidationMessage struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1467,6 +1485,8 @@ type PeerManifest struct { MasterHeadFrame uint64 `protobuf:"varint,16,opt,name=master_head_frame,json=masterHeadFrame,proto3" json:"master_head_frame,omitempty"` // The last time seen tick LastSeen int64 `protobuf:"varint,17,opt,name=last_seen,json=lastSeen,proto3" json:"last_seen,omitempty"` + // The increment of the node + Increment uint32 `protobuf:"varint,18,opt,name=increment,proto3" json:"increment,omitempty"` } func (x *PeerManifest) Reset() { @@ -1620,6 +1640,13 @@ func (x *PeerManifest) GetLastSeen() int64 { return 0 } +func (x *PeerManifest) GetIncrement() uint32 { + if x != nil { + return x.Increment + } + return 0 +} + type PeerManifestsResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1798,7 +1825,7 @@ var file_node_proto_rawDesc = []byte{ 0x63, 0x6f, 0x6c, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x12, 0x2f, 0x0a, 0x13, 0x61, 0x64, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x5f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x12, 0x61, 0x64, 0x64, 0x69, - 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x22, 0x90, + 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x22, 0xcc, 0x05, 0x0a, 0x0e, 0x53, 0x65, 0x6c, 0x66, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, @@ -1840,152 +1867,158 @@ var file_node_proto_rawDesc = []byte{ 0x72, 0x61, 0x6d, 0x65, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x48, 0x65, 0x61, 0x64, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, - 0x66, 0x22, 0x33, 0x0a, 0x11, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x62, 0x0a, 0x0b, 0x53, 0x79, 0x6e, 0x63, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x53, 0x0a, 0x0e, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x73, 0x5f, - 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2c, 0x2e, - 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, - 0x63, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x6c, 0x6f, 0x63, 0x6b, 0x46, 0x72, - 0x61, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x0d, 0x66, 0x72, 0x61, - 0x6d, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x66, 0x0a, 0x0c, 0x53, 0x79, - 0x6e, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x56, 0x0a, 0x0f, 0x66, 0x72, - 0x61, 0x6d, 0x65, 0x73, 0x5f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, - 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x63, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x70, 0x62, 0x2e, 0x43, - 0x6c, 0x6f, 0x63, 0x6b, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x52, 0x0e, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x22, 0x19, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x50, 0x65, 0x65, 0x72, 0x4d, 0x61, 0x6e, - 0x69, 0x66, 0x65, 0x73, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0xae, 0x05, - 0x0a, 0x0c, 0x50, 0x65, 0x65, 0x72, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x12, 0x17, - 0x0a, 0x07, 0x70, 0x65, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x06, 0x70, 0x65, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x69, 0x66, 0x66, 0x69, - 0x63, 0x75, 0x6c, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x64, 0x69, 0x66, - 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x12, 0x2b, 0x0a, 0x11, 0x64, 0x69, 0x66, 0x66, 0x69, - 0x63, 0x75, 0x6c, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x10, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x4d, 0x65, - 0x74, 0x72, 0x69, 0x63, 0x12, 0x28, 0x0a, 0x10, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x5f, 0x31, - 0x36, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, - 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x31, 0x36, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x2a, - 0x0a, 0x11, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x5f, 0x31, 0x32, 0x38, 0x5f, 0x6d, 0x65, 0x74, - 0x72, 0x69, 0x63, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0f, 0x63, 0x6f, 0x6d, 0x6d, 0x69, - 0x74, 0x31, 0x32, 0x38, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x2c, 0x0a, 0x12, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x5f, 0x31, 0x30, 0x32, 0x34, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, - 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x10, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x31, 0x30, - 0x32, 0x34, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x2e, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x6d, - 0x69, 0x74, 0x5f, 0x36, 0x35, 0x35, 0x33, 0x36, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, - 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x11, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x36, 0x35, 0x35, - 0x33, 0x36, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x26, 0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x6f, - 0x66, 0x5f, 0x31, 0x36, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x08, 0x20, 0x01, 0x28, - 0x03, 0x52, 0x0d, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x31, 0x36, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, - 0x12, 0x28, 0x0a, 0x10, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x5f, 0x31, 0x32, 0x38, 0x5f, 0x6d, 0x65, - 0x74, 0x72, 0x69, 0x63, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x70, 0x72, 0x6f, 0x6f, - 0x66, 0x31, 0x32, 0x38, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x2a, 0x0a, 0x11, 0x70, 0x72, - 0x6f, 0x6f, 0x66, 0x5f, 0x31, 0x30, 0x32, 0x34, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, - 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x31, 0x30, 0x32, 0x34, - 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x2c, 0x0a, 0x12, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x5f, - 0x36, 0x35, 0x35, 0x33, 0x36, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x0b, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x10, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x36, 0x35, 0x35, 0x33, 0x36, 0x4d, 0x65, - 0x74, 0x72, 0x69, 0x63, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x72, 0x65, 0x73, 0x18, 0x0c, 0x20, - 0x01, 0x28, 0x0d, 0x52, 0x05, 0x63, 0x6f, 0x72, 0x65, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, - 0x6d, 0x6f, 0x72, 0x79, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6d, 0x65, 0x6d, 0x6f, - 0x72, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x18, 0x0e, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x12, 0x47, 0x0a, 0x0c, - 0x63, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x69, 0x65, 0x73, 0x18, 0x0f, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, - 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x61, 0x70, - 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x52, 0x0c, 0x63, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, - 0x69, 0x74, 0x69, 0x65, 0x73, 0x12, 0x2a, 0x0a, 0x11, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x5f, - 0x68, 0x65, 0x61, 0x64, 0x5f, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x18, 0x10, 0x20, 0x01, 0x28, 0x04, - 0x52, 0x0f, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x48, 0x65, 0x61, 0x64, 0x46, 0x72, 0x61, 0x6d, - 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x73, 0x65, 0x65, 0x6e, 0x18, 0x11, - 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x6c, 0x61, 0x73, 0x74, 0x53, 0x65, 0x65, 0x6e, 0x22, 0x65, - 0x0a, 0x15, 0x50, 0x65, 0x65, 0x72, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x73, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4c, 0x0a, 0x0e, 0x70, 0x65, 0x65, 0x72, 0x5f, - 0x6d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x25, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, - 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x4d, 0x61, - 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x52, 0x0d, 0x70, 0x65, 0x65, 0x72, 0x4d, 0x61, 0x6e, 0x69, - 0x66, 0x65, 0x73, 0x74, 0x73, 0x32, 0xd7, 0x01, 0x0a, 0x11, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6b, 0x0a, 0x11, 0x50, - 0x65, 0x72, 0x66, 0x6f, 0x72, 0x6d, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x12, 0x2a, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, - 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x2a, 0x2e, 0x71, - 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, - 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x55, 0x0a, 0x04, 0x53, 0x79, 0x6e, 0x63, - 0x12, 0x24, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, - 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x79, 0x6e, 0x63, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, - 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, - 0x2e, 0x53, 0x79, 0x6e, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x32, - 0xf6, 0x05, 0x0a, 0x0b, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, - 0x5f, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x73, 0x12, 0x29, 0x2e, 0x71, - 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, - 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, - 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, - 0x62, 0x2e, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x68, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x49, 0x6e, 0x66, 0x6f, - 0x12, 0x2c, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, - 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x72, - 0x61, 0x6d, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, + 0x66, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x18, 0x11, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x12, + 0x1c, 0x0a, 0x09, 0x69, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x12, 0x20, 0x01, + 0x28, 0x0d, 0x52, 0x09, 0x69, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x33, 0x0a, + 0x11, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x22, 0x62, 0x0a, 0x0b, 0x53, 0x79, 0x6e, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x53, 0x0a, 0x0e, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x73, 0x5f, 0x72, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2c, 0x2e, 0x71, 0x75, 0x69, 0x6c, + 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x63, 0x6c, 0x6f, 0x63, + 0x6b, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x6c, 0x6f, 0x63, 0x6b, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x0d, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x66, 0x0a, 0x0c, 0x53, 0x79, 0x6e, 0x63, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x56, 0x0a, 0x0f, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x73, + 0x5f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x2d, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, + 0x65, 0x2e, 0x63, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x6c, 0x6f, 0x63, 0x6b, + 0x46, 0x72, 0x61, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x52, 0x0e, + 0x66, 0x72, 0x61, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, + 0x0a, 0x17, 0x47, 0x65, 0x74, 0x50, 0x65, 0x65, 0x72, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, + 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0xcc, 0x05, 0x0a, 0x0c, 0x50, 0x65, + 0x65, 0x72, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x65, + 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x70, 0x65, 0x65, + 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, + 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, + 0x6c, 0x74, 0x79, 0x12, 0x2b, 0x0a, 0x11, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, + 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x10, + 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, + 0x12, 0x28, 0x0a, 0x10, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x5f, 0x31, 0x36, 0x5f, 0x6d, 0x65, + 0x74, 0x72, 0x69, 0x63, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x63, 0x6f, 0x6d, 0x6d, + 0x69, 0x74, 0x31, 0x36, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x2a, 0x0a, 0x11, 0x63, 0x6f, + 0x6d, 0x6d, 0x69, 0x74, 0x5f, 0x31, 0x32, 0x38, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0f, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x31, 0x32, 0x38, + 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x2c, 0x0a, 0x12, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, + 0x5f, 0x31, 0x30, 0x32, 0x34, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x06, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x10, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x31, 0x30, 0x32, 0x34, 0x4d, 0x65, + 0x74, 0x72, 0x69, 0x63, 0x12, 0x2e, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x5f, 0x36, + 0x35, 0x35, 0x33, 0x36, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x07, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x11, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x36, 0x35, 0x35, 0x33, 0x36, 0x4d, 0x65, + 0x74, 0x72, 0x69, 0x63, 0x12, 0x26, 0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x5f, 0x31, 0x36, + 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x70, + 0x72, 0x6f, 0x6f, 0x66, 0x31, 0x36, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x28, 0x0a, 0x10, + 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x5f, 0x31, 0x32, 0x38, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, + 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x31, 0x32, 0x38, + 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x2a, 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x5f, + 0x31, 0x30, 0x32, 0x34, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x0a, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x0f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x31, 0x30, 0x32, 0x34, 0x4d, 0x65, 0x74, 0x72, + 0x69, 0x63, 0x12, 0x2c, 0x0a, 0x12, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x5f, 0x36, 0x35, 0x35, 0x33, + 0x36, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x03, 0x52, 0x10, + 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x36, 0x35, 0x35, 0x33, 0x36, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, + 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x72, 0x65, 0x73, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x05, 0x63, 0x6f, 0x72, 0x65, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, + 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x12, 0x18, + 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x07, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x12, 0x47, 0x0a, 0x0c, 0x63, 0x61, 0x70, 0x61, + 0x62, 0x69, 0x6c, 0x69, 0x74, 0x69, 0x65, 0x73, 0x18, 0x0f, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, - 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x49, 0x6e, - 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x65, 0x0a, 0x0b, 0x47, 0x65, - 0x74, 0x50, 0x65, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x2b, 0x2e, 0x71, 0x75, 0x69, 0x6c, + 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, + 0x69, 0x74, 0x79, 0x52, 0x0c, 0x63, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x69, 0x65, + 0x73, 0x12, 0x2a, 0x0a, 0x11, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x68, 0x65, 0x61, 0x64, + 0x5f, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x18, 0x10, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x6d, 0x61, + 0x73, 0x74, 0x65, 0x72, 0x48, 0x65, 0x61, 0x64, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x12, 0x1b, 0x0a, + 0x09, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x73, 0x65, 0x65, 0x6e, 0x18, 0x11, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x08, 0x6c, 0x61, 0x73, 0x74, 0x53, 0x65, 0x65, 0x6e, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x6e, + 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x12, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x69, + 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x65, 0x0a, 0x15, 0x50, 0x65, 0x65, 0x72, + 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x4c, 0x0a, 0x0e, 0x70, 0x65, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x69, 0x66, 0x65, + 0x73, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, - 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x65, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, - 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, - 0x2e, 0x50, 0x65, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x65, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, - 0x12, 0x2b, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, - 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x4e, 0x6f, - 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, - 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, - 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6e, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x4e, - 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x2e, 0x2e, 0x71, 0x75, 0x69, + 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, + 0x52, 0x0d, 0x70, 0x65, 0x65, 0x72, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x73, 0x32, + 0xd7, 0x01, 0x0a, 0x11, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6b, 0x0a, 0x11, 0x50, 0x65, 0x72, 0x66, 0x6f, 0x72, 0x6d, + 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x2a, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, - 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x49, - 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x71, 0x75, 0x69, + 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x2a, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, + 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, + 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x12, 0x55, 0x0a, 0x04, 0x53, 0x79, 0x6e, 0x63, 0x12, 0x24, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, - 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x49, 0x6e, 0x66, 0x6f, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x68, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x54, - 0x6f, 0x6b, 0x65, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x2c, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, - 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, - 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, + 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x79, 0x6e, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x25, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, + 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x79, 0x6e, 0x63, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x32, 0xf6, 0x05, 0x0a, 0x0b, 0x4e, 0x6f, + 0x64, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5f, 0x0a, 0x09, 0x47, 0x65, 0x74, + 0x46, 0x72, 0x61, 0x6d, 0x65, 0x73, 0x12, 0x29, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, - 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x74, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x50, 0x65, 0x65, 0x72, 0x4d, 0x61, 0x6e, - 0x69, 0x66, 0x65, 0x73, 0x74, 0x73, 0x12, 0x30, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, - 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, - 0x2e, 0x47, 0x65, 0x74, 0x50, 0x65, 0x65, 0x72, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, - 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2e, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, + 0x2e, 0x47, 0x65, 0x74, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x27, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, + 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x72, 0x61, 0x6d, + 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x68, 0x0a, 0x0c, 0x47, 0x65, + 0x74, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x2c, 0x2e, 0x71, 0x75, 0x69, + 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, + 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x49, 0x6e, 0x66, + 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, - 0x70, 0x62, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x73, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xcf, 0x01, 0x0a, 0x09, 0x4e, 0x6f, 0x64, - 0x65, 0x53, 0x74, 0x61, 0x74, 0x73, 0x12, 0x60, 0x0a, 0x0b, 0x50, 0x75, 0x74, 0x4e, 0x6f, 0x64, - 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x2b, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, - 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, - 0x50, 0x75, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, - 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x75, 0x74, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x60, 0x0a, 0x0b, 0x50, 0x75, 0x74, 0x50, - 0x65, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x2b, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, + 0x70, 0x62, 0x2e, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x65, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x50, 0x65, 0x65, 0x72, 0x49, + 0x6e, 0x66, 0x6f, 0x12, 0x2b, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, + 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, + 0x74, 0x50, 0x65, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x29, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, + 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x49, + 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x65, 0x0a, 0x0b, 0x47, + 0x65, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x2b, 0x2e, 0x71, 0x75, 0x69, + 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, + 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, - 0x62, 0x2e, 0x50, 0x75, 0x74, 0x50, 0x65, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, - 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x50, - 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3a, 0x5a, 0x38, 0x73, 0x6f, - 0x75, 0x72, 0x63, 0x65, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2f, 0x6d, - 0x6f, 0x6e, 0x6f, 0x72, 0x65, 0x70, 0x6f, 0x2f, 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x62, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x6e, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, + 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x2e, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, + 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x47, + 0x65, 0x74, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, + 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x4e, + 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x68, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x49, 0x6e, + 0x66, 0x6f, 0x12, 0x2c, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, + 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, + 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x2a, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, + 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, + 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x74, 0x0a, 0x10, + 0x47, 0x65, 0x74, 0x50, 0x65, 0x65, 0x72, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x73, + 0x12, 0x30, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, + 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x65, + 0x65, 0x72, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x2e, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, + 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x65, 0x65, + 0x72, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x32, 0xcf, 0x01, 0x0a, 0x09, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x73, + 0x12, 0x60, 0x0a, 0x0b, 0x50, 0x75, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, + 0x2b, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, + 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x75, 0x74, 0x4e, 0x6f, 0x64, + 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x71, + 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, + 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x60, 0x0a, 0x0b, 0x50, 0x75, 0x74, 0x50, 0x65, 0x65, 0x72, 0x49, 0x6e, 0x66, + 0x6f, 0x12, 0x2b, 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, + 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x75, 0x74, 0x50, + 0x65, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, + 0x2e, 0x71, 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x6e, 0x6f, 0x64, 0x65, + 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3a, 0x5a, 0x38, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x71, + 0x75, 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x71, 0x75, + 0x69, 0x6c, 0x69, 0x62, 0x72, 0x69, 0x75, 0x6d, 0x2f, 0x6d, 0x6f, 0x6e, 0x6f, 0x72, 0x65, 0x70, + 0x6f, 0x2f, 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x73, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/node/protobufs/node.proto b/node/protobufs/node.proto index 3116196..e8b7f91 100644 --- a/node/protobufs/node.proto +++ b/node/protobufs/node.proto @@ -157,6 +157,10 @@ message SelfTestReport { uint64 master_head_frame = 15; // A challenge proof bytes proof = 16; + // The challenge, minus the peer id + bytes challenge = 17; + // The increment value + uint32 increment = 18; } message ValidationMessage { @@ -220,6 +224,8 @@ message PeerManifest { uint64 master_head_frame = 16; // The last time seen tick int64 last_seen = 17; + // The increment of the node + uint32 increment = 18; } message PeerManifestsResponse { diff --git a/node/rpc/data_worker_ipc_server.go b/node/rpc/data_worker_ipc_server.go index 068979a..04952aa 100644 --- a/node/rpc/data_worker_ipc_server.go +++ b/node/rpc/data_worker_ipc_server.go @@ -39,19 +39,17 @@ func (r *DataWorkerIPCServer) CalculateChallengeProof( ) } - proof, nextSkew, err := r.prover.CalculateChallengeProof( + proof, err := r.prover.CalculateChallengeProof( req.Challenge, uint32(r.coreId), - req.Skew, - req.NowMs, + req.Increment, ) if err != nil { return nil, errors.Wrap(err, "calculate challenge proof") } return &protobufs.ChallengeProofResponse{ - Output: proof, - NextSkew: nextSkew, + Output: proof, }, nil } @@ -91,7 +89,12 @@ func (r *DataWorkerIPCServer) Start() error { go r.monitorParent() + r.logger.Info( + "data worker listening", + zap.String("address", r.listenAddrGRPC), + ) if err := s.Serve(mn.NetListener(lis)); err != nil { + r.logger.Error("terminating server", zap.Error(err)) panic(err) } @@ -99,6 +102,14 @@ func (r *DataWorkerIPCServer) Start() error { } func (r *DataWorkerIPCServer) monitorParent() { + if r.parentProcessId == 0 { + r.logger.Info( + "no parent process id specified, running in detached worker mode", + zap.Uint32("core_id", r.coreId), + ) + return + } + for { time.Sleep(1 * time.Second) proc, err := os.FindProcess(r.parentProcessId) diff --git a/node/rpc/node_rpc_server.go b/node/rpc/node_rpc_server.go index 13a53a3..19f660e 100644 --- a/node/rpc/node_rpc_server.go +++ b/node/rpc/node_rpc_server.go @@ -3,7 +3,6 @@ package rpc import ( "bytes" "context" - "math/big" "net/http" "source.quilibrium.com/quilibrium/monorepo/node/config" @@ -11,7 +10,6 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" - "github.com/iden3/go-iden3-crypto/poseidon" "github.com/multiformats/go-multiaddr" mn "github.com/multiformats/go-multiaddr/net" "github.com/pkg/errors" @@ -21,12 +19,10 @@ import ( "google.golang.org/grpc/reflection" "source.quilibrium.com/quilibrium/monorepo/node/consensus/master" "source.quilibrium.com/quilibrium/monorepo/node/execution" - "source.quilibrium.com/quilibrium/monorepo/node/execution/intrinsics/ceremony/application" "source.quilibrium.com/quilibrium/monorepo/node/keys" "source.quilibrium.com/quilibrium/monorepo/node/p2p" "source.quilibrium.com/quilibrium/monorepo/node/protobufs" "source.quilibrium.com/quilibrium/monorepo/node/store" - "source.quilibrium.com/quilibrium/monorepo/node/tries" ) type RPCServer struct { @@ -34,6 +30,7 @@ type RPCServer struct { listenAddrGRPC string listenAddrHTTP string logger *zap.Logger + dataProofStore store.DataProofStore clockStore store.ClockStore keyManager keys.KeyManager pubSub p2p.PubSub @@ -192,136 +189,142 @@ func (r *RPCServer) GetPeerInfo( return resp, nil } +// Only returns the active amounts earned under 1.4.19 until 2.0 func (r *RPCServer) GetTokenInfo( ctx context.Context, req *protobufs.GetTokenInfoRequest, ) (*protobufs.TokenInfoResponse, error) { - provingKey, err := r.keyManager.GetRawKey( - "default-proving-key", - ) - if err != nil { - return nil, errors.Wrap(err, "get token info") - } + // provingKey, err := r.keyManager.GetRawKey( + // "default-proving-key", + // ) + // if err != nil { + // return nil, errors.Wrap(err, "get token info") + // } - peerBytes := r.pubSub.GetPeerID() - peerAddr, err := poseidon.HashBytes(peerBytes) - if err != nil { - panic(err) - } + // peerBytes := r.pubSub.GetPeerID() + // peerAddr, err := poseidon.HashBytes(peerBytes) + // if err != nil { + // panic(err) + // } - addr, err := poseidon.HashBytes(provingKey.PublicKey) - if err != nil { - panic(err) - } + // addr, err := poseidon.HashBytes(provingKey.PublicKey) + // if err != nil { + // panic(err) + // } - addrBytes := addr.Bytes() - addrBytes = append(make([]byte, 32-len(addrBytes)), addrBytes...) + // addrBytes := addr.Bytes() + // addrBytes = append(make([]byte, 32-len(addrBytes)), addrBytes...) - peerAddrBytes := peerAddr.Bytes() - peerAddrBytes = append(make([]byte, 32-len(peerAddrBytes)), peerAddrBytes...) + // peerAddrBytes := peerAddr.Bytes() + // peerAddrBytes = append(make([]byte, 32-len(peerAddrBytes)), peerAddrBytes...) - frame, err := r.clockStore.GetLatestDataClockFrame( - append( - p2p.GetBloomFilter(application.CEREMONY_ADDRESS, 256, 3), - p2p.GetBloomFilterIndices(application.CEREMONY_ADDRESS, 65536, 24)..., - ), - nil, - ) - if err != nil { - return nil, errors.Wrap(err, "get token info") - } + // frame, err := r.clockStore.GetLatestDataClockFrame( + // append( + // p2p.GetBloomFilter(application.CEREMONY_ADDRESS, 256, 3), + // p2p.GetBloomFilterIndices(application.CEREMONY_ADDRESS, 65536, 24)..., + // ), + // nil, + // ) + // if err != nil { + // return nil, errors.Wrap(err, "get token info") + // } - confirmed, err := application.MaterializeApplicationFromFrame(frame) - if err != nil { - return nil, errors.Wrap(err, "get token info") - } + // confirmed, err := application.MaterializeApplicationFromFrame(frame) + // if err != nil { + // return nil, errors.Wrap(err, "get token info") + // } - confirmedTotal := new(big.Int) - ownedTotal := new(big.Int) - if confirmed.RewardTrie.Root == nil || - (confirmed.RewardTrie.Root.External == nil && - confirmed.RewardTrie.Root.Internal == nil) { - return &protobufs.TokenInfoResponse{ - ConfirmedTokenSupply: confirmedTotal.FillBytes(make([]byte, 32)), - UnconfirmedTokenSupply: confirmedTotal.FillBytes(make([]byte, 32)), - OwnedTokens: ownedTotal.FillBytes(make([]byte, 32)), - UnconfirmedOwnedTokens: ownedTotal.FillBytes(make([]byte, 32)), - }, nil - } + // confirmedTotal := new(big.Int) + // ownedTotal := new(big.Int) + // if confirmed.RewardTrie.Root == nil || + // (confirmed.RewardTrie.Root.External == nil && + // confirmed.RewardTrie.Root.Internal == nil) { + // return &protobufs.TokenInfoResponse{ + // ConfirmedTokenSupply: confirmedTotal.FillBytes(make([]byte, 32)), + // UnconfirmedTokenSupply: confirmedTotal.FillBytes(make([]byte, 32)), + // OwnedTokens: ownedTotal.FillBytes(make([]byte, 32)), + // UnconfirmedOwnedTokens: ownedTotal.FillBytes(make([]byte, 32)), + // }, nil + // } - limbs := []*tries.RewardInternalNode{} - if confirmed.RewardTrie.Root.Internal != nil { - limbs = append(limbs, confirmed.RewardTrie.Root.Internal) - } else { - confirmedTotal = confirmedTotal.Add( - confirmedTotal, - new(big.Int).SetUint64(confirmed.RewardTrie.Root.External.Total), - ) - if bytes.Equal( - confirmed.RewardTrie.Root.External.Key, - addrBytes, - ) { - ownedTotal = ownedTotal.Add( - ownedTotal, - new(big.Int).SetUint64(confirmed.RewardTrie.Root.External.Total), - ) - } - } + // limbs := []*tries.RewardInternalNode{} + // if confirmed.RewardTrie.Root.Internal != nil { + // limbs = append(limbs, confirmed.RewardTrie.Root.Internal) + // } else { + // confirmedTotal = confirmedTotal.Add( + // confirmedTotal, + // new(big.Int).SetUint64(confirmed.RewardTrie.Root.External.Total), + // ) + // if bytes.Equal( + // confirmed.RewardTrie.Root.External.Key, + // addrBytes, + // ) { + // ownedTotal = ownedTotal.Add( + // ownedTotal, + // new(big.Int).SetUint64(confirmed.RewardTrie.Root.External.Total), + // ) + // } + // } - for len(limbs) != 0 { - nextLimbs := []*tries.RewardInternalNode{} - for _, limb := range limbs { - for _, child := range limb.Child { - child := child - if child.Internal != nil { - nextLimbs = append(nextLimbs, child.Internal) - } else { - confirmedTotal = confirmedTotal.Add( - confirmedTotal, - new(big.Int).SetUint64(child.External.Total), - ) - if bytes.Equal( - child.External.Key, - addrBytes, - ) { - ownedTotal = ownedTotal.Add( - ownedTotal, - new(big.Int).SetUint64(child.External.Total), - ) - } - if bytes.Equal( - child.External.Key, - peerAddrBytes, - ) { - ownedTotal = ownedTotal.Add( - ownedTotal, - new(big.Int).SetUint64(child.External.Total), - ) - } - } - } - } - limbs = nextLimbs - } + // for len(limbs) != 0 { + // nextLimbs := []*tries.RewardInternalNode{} + // for _, limb := range limbs { + // for _, child := range limb.Child { + // child := child + // if child.Internal != nil { + // nextLimbs = append(nextLimbs, child.Internal) + // } else { + // confirmedTotal = confirmedTotal.Add( + // confirmedTotal, + // new(big.Int).SetUint64(child.External.Total), + // ) + // if bytes.Equal( + // child.External.Key, + // addrBytes, + // ) { + // ownedTotal = ownedTotal.Add( + // ownedTotal, + // new(big.Int).SetUint64(child.External.Total), + // ) + // } + // if bytes.Equal( + // child.External.Key, + // peerAddrBytes, + // ) { + // ownedTotal = ownedTotal.Add( + // ownedTotal, + // new(big.Int).SetUint64(child.External.Total), + // ) + // } + // } + // } + // } + // limbs = nextLimbs + // } - if err != nil { - return nil, errors.Wrap(err, "get token info") - } + // if err != nil { + // return nil, errors.Wrap(err, "get token info") + // } // 1 QUIL = 0x1DCD65000 units - conversionFactor, ok := new(big.Int).SetString("1DCD65000", 16) - if !ok { - return nil, errors.Wrap(err, "get token info") + // conversionFactor, ok := new(big.Int).SetString("1DCD65000", 16) + // if !ok { + // return nil, errors.Wrap(err, "get token info") + // } + + total, err := r.dataProofStore.GetTotalReward(r.pubSub.GetPeerID()) + if err != nil { + panic(err) } - confirmedTotal = confirmedTotal.Mul(confirmedTotal, conversionFactor) - ownedTotal = ownedTotal.Mul(ownedTotal, conversionFactor) + // confirmedTotal = confirmedTotal.Mul(confirmedTotal, conversionFactor) + // ownedTotal = ownedTotal.Mul(ownedTotal, conversionFactor) return &protobufs.TokenInfoResponse{ - ConfirmedTokenSupply: confirmedTotal.FillBytes(make([]byte, 32)), - UnconfirmedTokenSupply: confirmedTotal.FillBytes(make([]byte, 32)), - OwnedTokens: ownedTotal.FillBytes(make([]byte, 32)), - UnconfirmedOwnedTokens: ownedTotal.FillBytes(make([]byte, 32)), + // ConfirmedTokenSupply: confirmedTotal.FillBytes(make([]byte, 32)), + // UnconfirmedTokenSupply: confirmedTotal.FillBytes(make([]byte, 32)), + // OwnedTokens: ownedTotal.FillBytes(make([]byte, 32)), + UnconfirmedOwnedTokens: total.FillBytes(make([]byte, 32)), }, nil } @@ -336,6 +339,7 @@ func NewRPCServer( listenAddrGRPC string, listenAddrHTTP string, logger *zap.Logger, + dataProofStore store.DataProofStore, clockStore store.ClockStore, keyManager keys.KeyManager, pubSub p2p.PubSub, @@ -346,6 +350,7 @@ func NewRPCServer( listenAddrGRPC: listenAddrGRPC, listenAddrHTTP: listenAddrHTTP, logger: logger, + dataProofStore: dataProofStore, clockStore: clockStore, keyManager: keyManager, pubSub: pubSub, diff --git a/node/store/data_proof.go b/node/store/data_proof.go index bce779b..841e5c1 100644 --- a/node/store/data_proof.go +++ b/node/store/data_proof.go @@ -3,6 +3,7 @@ package store import ( "encoding/binary" "fmt" + "math/big" "github.com/cockroachdb/pebble" "github.com/pkg/errors" @@ -27,6 +28,27 @@ type DataProofStore interface { aggregateProof *protobufs.InclusionAggregateProof, commitment []byte, ) error + GetDataTimeProof( + peerId []byte, + increment uint32, + ) (difficulty, parallelism uint32, input, output []byte, err error) + GetTotalReward( + peerId []byte, + ) (*big.Int, error) + PutDataTimeProof( + txn Transaction, + parallelism uint32, + peerId []byte, + increment uint32, + input []byte, + output []byte, + ) error + GetLatestDataTimeProof(peerId []byte) ( + increment uint32, + parallelism uint32, + output []byte, + err error, + ) } var _ DataProofStore = (*PebbleDataProofStore)(nil) @@ -47,10 +69,13 @@ func NewPebbleDataProofStore( } const ( - DATA_PROOF = 0x04 - DATA_PROOF_METADATA = 0x00 - DATA_PROOF_INCLUSION = 0x01 - DATA_PROOF_SEGMENT = 0x02 + DATA_PROOF = 0x04 + DATA_PROOF_METADATA = 0x00 + DATA_PROOF_INCLUSION = 0x01 + DATA_PROOF_SEGMENT = 0x02 + DATA_TIME_PROOF = 0x05 + DATA_TIME_PROOF_DATA = 0x00 + DATA_TIME_PROOF_LATEST = 0x01 ) func dataProofMetadataKey(filter []byte, commitment []byte) []byte { @@ -82,6 +107,19 @@ func dataProofSegmentKey( return key } +func dataTimeProofKey(peerId []byte, increment uint32) []byte { + key := []byte{DATA_TIME_PROOF, DATA_TIME_PROOF_DATA} + key = append(key, peerId...) + key = binary.BigEndian.AppendUint32(key, increment) + return key +} + +func dataTimeProofLatestKey(peerId []byte) []byte { + key := []byte{DATA_TIME_PROOF, DATA_TIME_PROOF_LATEST} + key = append(key, peerId...) + return key +} + func (p *PebbleDataProofStore) NewTransaction() (Transaction, error) { return p.db.NewBatch(), nil } @@ -362,3 +400,170 @@ func (p *PebbleDataProofStore) PutAggregateProof( commitment, ) } + +func (p *PebbleDataProofStore) GetDataTimeProof( + peerId []byte, + increment uint32, +) (difficulty, parallelism uint32, input, output []byte, err error) { + data, closer, err := p.db.Get(dataTimeProofKey(peerId, increment)) + if err != nil { + if errors.Is(err, pebble.ErrNotFound) { + err = ErrNotFound + return + } + err = errors.Wrap(err, "get data time proof") + return + } + + defer closer.Close() + if len(data) < 24 { + err = ErrInvalidData + return + } + + difficulty = binary.BigEndian.Uint32(data[:4]) + parallelism = binary.BigEndian.Uint32(data[4:8]) + inputLen := binary.BigEndian.Uint64(data[8:16]) + + // Verify length of remaining data is at least equal to the input and next + // length prefix + if uint64(len(data[16:])) < inputLen+8 { + err = ErrInvalidData + return + } + + input = make([]byte, inputLen) + copy(input[:], data[16:16+inputLen]) + + outputLen := binary.BigEndian.Uint64(data[16+inputLen : 16+inputLen+8]) + + // Verify length + if uint64(len(data[16+inputLen+8:])) < outputLen { + err = ErrInvalidData + return + } + + output = make([]byte, outputLen) + copy(output[:], data[16+inputLen+8:]) + return difficulty, parallelism, input, output, nil +} + +func (p *PebbleDataProofStore) GetTotalReward( + peerId []byte, +) (*big.Int, error) { + reward := big.NewInt(0) + prev, closer, err := p.db.Get(dataTimeProofLatestKey(peerId)) + if err != nil { + if errors.Is(err, pebble.ErrNotFound) { + return big.NewInt(0), nil + } + + return nil, errors.Wrap(err, "get total difficulty sum") + } + + if len(prev) != 0 { + reward.SetBytes(prev[4:]) + + if err = closer.Close(); err != nil { + return nil, errors.Wrap(err, "get total difficulty sum") + } + } + + return reward, nil +} + +func (p *PebbleDataProofStore) PutDataTimeProof( + txn Transaction, + parallelism uint32, + peerId []byte, + increment uint32, + input []byte, + output []byte, +) error { + // Now, for the assumptions. + // Rewards are calculated based off of a current average rate of growth such + // that we continue at the rate we have been, for the course of the next month + // and carry it to now it such that the greatest advantage gleaned is from + // upgrading on time, akin to a "difficulty bomb" in reverse, but locally + // calculated. + difficulty := 200000 - (increment / 4) + + // Basis split on the estimated shard level for growth rate (in terms of + // units): 240 (QUIL) * 8000000000 (conversion factor) / 1600000 (shards) + // = 1200000 units per reward interval per core + pomwBasis := big.NewInt(1200000) + reward := new(big.Int) + reward = reward.Mul(pomwBasis, big.NewInt(int64(parallelism))) + + priorSum := big.NewInt(0) + prev, closer, err := p.db.Get(dataTimeProofLatestKey(peerId)) + if err != nil && (!errors.Is(err, pebble.ErrNotFound) || increment != 0) { + return errors.Wrap(err, "put data time proof") + } + + if len(prev) != 0 { + priorSum.SetBytes(prev[4:]) + prevIncrement := binary.BigEndian.Uint32(prev[:4]) + + if err = closer.Close(); err != nil { + return errors.Wrap(err, "put data time proof") + } + + if prevIncrement != increment-1 { + return errors.Wrap(errors.New("invalid increment"), "put data time proof") + } + } + + data := []byte{} + data = binary.BigEndian.AppendUint32(data, difficulty) + data = binary.BigEndian.AppendUint32(data, parallelism) + data = binary.BigEndian.AppendUint64(data, uint64(len(input))) + data = append(data, input...) + data = binary.BigEndian.AppendUint64(data, uint64(len(output))) + data = append(data, output...) + err = txn.Set(dataTimeProofKey(peerId, increment), data) + if err != nil { + return errors.Wrap(err, "put data time proof") + } + + latest := []byte{} + latest = binary.BigEndian.AppendUint32(latest, increment) + + priorSum.Add(priorSum, reward) + latest = append(latest, priorSum.FillBytes(make([]byte, 32))...) + + if err = txn.Set(dataTimeProofLatestKey(peerId), latest); err != nil { + return errors.Wrap(err, "put data time proof") + } + + return nil +} + +func (p *PebbleDataProofStore) GetLatestDataTimeProof(peerId []byte) ( + increment uint32, + parallelism uint32, + output []byte, + err error, +) { + prev, closer, err := p.db.Get(dataTimeProofLatestKey(peerId)) + if err != nil { + if errors.Is(err, pebble.ErrNotFound) { + return 0, 0, nil, ErrNotFound + } + + return 0, 0, nil, errors.Wrap(err, "get latest data time proof") + } + + if len(prev) < 4 { + return 0, 0, nil, ErrInvalidData + } + + increment = binary.BigEndian.Uint32(prev[:4]) + if err = closer.Close(); err != nil { + return 0, 0, nil, errors.Wrap(err, "get latest data time proof") + } + + _, parallelism, _, output, err = p.GetDataTimeProof(peerId, increment) + + return increment, parallelism, output, err +} diff --git a/node/test.sh b/node/test.sh new file mode 100755 index 0000000..0c3845e --- /dev/null +++ b/node/test.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -euxo pipefail + +# Run tests for the node package. Takes care of linking the native VDF. +# Assumes that the VDF library has been built by running the generate.sh script in the `../vdf` directory. + +ROOT_DIR="${ROOT_DIR:-$( cd "$(dirname "$(realpath "$( dirname "${BASH_SOURCE[0]}" )")")" >/dev/null 2>&1 && pwd )}" + +NODE_DIR="$ROOT_DIR/node" +BINARIES_DIR="$ROOT_DIR/target/release" + +# Link the native VDF and execute tests +pushd "$NODE_DIR" > /dev/null + CGO_LDFLAGS="-L$BINARIES_DIR -lvdf -ldl" \ + CGO_ENABLED=1 \ + GOEXPERIMENT=arenas \ + go test "$@" diff --git a/signers/Taskfile.yaml b/signers/Taskfile.yaml index a5d4c3f..4e73bce 100644 --- a/signers/Taskfile.yaml +++ b/signers/Taskfile.yaml @@ -11,7 +11,7 @@ env: vars: VERSION: sh: cat ../node/config/version.go | grep -A 1 "func GetVersion() \[\]byte {" | grep -Eo '0x[0-9a-fA-F]+' | xargs printf "%d.%d.%d" - MAX_KEY_ID: 15 + MAX_KEY_ID: 17 QUILIBRIUM_SIGNERS_IMAGE_NAME: 'quilibrium-signers' USER_NAME: sh: whoami @@ -23,10 +23,11 @@ tasks: status: desc: Display configuration info. cmds: - - echo -n "Version :" && echo " {{.VERSION}}" - - echo -n "Priv Key Path :" && echo " {{.SIGNING_KEY_PATH}}" - - echo -n "Pub Key Path :" && echo " {{.SIGNING_PUB_KEY_PATH}}" - - echo -n "Key ID :" && echo " {{.SIGNING_KEY_ID}}" + - echo -n "Version :" && echo " {{.VERSION}}" + - echo -n "Priv Key Path:" && echo " {{.SIGNING_KEY_PATH}}" + - echo -n "Pub Key Path:" && echo " {{.SIGNING_PUB_KEY_PATH}}" + - echo -n "Key ID :" && echo " {{.SIGNING_KEY_ID}}" + - echo -n "Max Key ID :" && echo " {{.MAX_KEY_ID}}" silent: true hex: diff --git a/vdf/.gitignore b/vdf/.gitignore new file mode 100644 index 0000000..86d4c2d --- /dev/null +++ b/vdf/.gitignore @@ -0,0 +1 @@ +generated diff --git a/vdf/REAMDE.md b/vdf/REAMDE.md new file mode 100644 index 0000000..de9a57c --- /dev/null +++ b/vdf/REAMDE.md @@ -0,0 +1,9 @@ +# VDF + +Wrapper for the Rust implementation of the VDF (Verifiable Delay Function) in [crates/vdf](../crates/vdf). + +## Generate Go bindings + +```sh +go generate +``` diff --git a/vdf/generate.sh b/vdf/generate.sh new file mode 100755 index 0000000..45b706a --- /dev/null +++ b/vdf/generate.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -euxo pipefail + +ROOT_DIR="${ROOT_DIR:-$( cd "$(dirname "$(realpath "$( dirname "${BASH_SOURCE[0]}" )")")" >/dev/null 2>&1 && pwd )}" + +RUST_VDF_PACKAGE="$ROOT_DIR/crates/vdf" +BINDINGS_DIR="$ROOT_DIR/vdf" + +# Build the Rust VDF package in release mode +RUSTFLAGS='-L /opt/homebrew/Cellar/gmp/6.3.0/lib' cargo build -p vdf --release + +# Generate Go bindings +pushd "$RUST_VDF_PACKAGE" > /dev/null +uniffi-bindgen-go src/lib.udl -o "$BINDINGS_DIR"/generated diff --git a/vdf/go.mod b/vdf/go.mod new file mode 100644 index 0000000..db9b44d --- /dev/null +++ b/vdf/go.mod @@ -0,0 +1,12 @@ +module source.quilibrium.com/quilibrium/monorepo/vdf + +go 1.20 + +// A necessary hack until source.quilibrium.com is open to all +replace source.quilibrium.com/quilibrium/monorepo/nekryptology => ../nekryptology + +require ( + golang.org/x/crypto v0.24.0 // indirect + golang.org/x/sys v0.21.0 // indirect + source.quilibrium.com/quilibrium/monorepo/nekryptology v0.0.0-00010101000000-000000000000 // indirect +) diff --git a/vdf/go.sum b/vdf/go.sum new file mode 100644 index 0000000..3983382 --- /dev/null +++ b/vdf/go.sum @@ -0,0 +1,4 @@ +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/vdf/test.sh b/vdf/test.sh new file mode 100755 index 0000000..cb42e34 --- /dev/null +++ b/vdf/test.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -euxo pipefail + +# Run tests for the vdf package. Takes care of linking the native VDF. +# Assumes that the VDF library has been built by running the generate.sh script in the same directory. + +ROOT_DIR="${ROOT_DIR:-$( cd "$(dirname "$(realpath "$( dirname "${BASH_SOURCE[0]}" )")")" >/dev/null 2>&1 && pwd )}" + +NODE_DIR="$ROOT_DIR/vdf" +BINARIES_DIR="$ROOT_DIR/target/release" + +# Link the native VDF and execute tests +pushd "$NODE_DIR" > /dev/null + CGO_LDFLAGS="-L$BINARIES_DIR -lvdf -ldl" \ + CGO_ENABLED=1 \ + GOEXPERIMENT=arenas \ + go test "$@" diff --git a/vdf/vdf.go b/vdf/vdf.go new file mode 100644 index 0000000..78ce931 --- /dev/null +++ b/vdf/vdf.go @@ -0,0 +1,21 @@ +package vdf + +import ( + generated "source.quilibrium.com/quilibrium/monorepo/vdf/generated/vdf" +) + +//go:generate ./generate.sh + +const intSizeBits = uint16(2048) + +// WesolowskiSolve Solve and prove with the Wesolowski VDF using the given parameters. +// Outputs the concatenated solution and proof (in this order). +func WesolowskiSolve(challenge [32]byte, difficulty uint32) [516]byte { + return [516]byte(generated.WesolowskiSolve(intSizeBits, challenge[:], difficulty)) +} + +// WesolowskiVerify Verify with the Wesolowski VDF using the given parameters. +// `allegedSolution` is the output of `WesolowskiSolve`. +func WesolowskiVerify(challenge [32]byte, difficulty uint32, allegedSolution [516]byte) bool { + return generated.WesolowskiVerify(intSizeBits, challenge[:], difficulty, allegedSolution[:]) +} diff --git a/vdf/vdf_test.go b/vdf/vdf_test.go new file mode 100644 index 0000000..dd3e56a --- /dev/null +++ b/vdf/vdf_test.go @@ -0,0 +1,53 @@ +package vdf_test + +import ( + "golang.org/x/crypto/sha3" + nekrovdf "source.quilibrium.com/quilibrium/monorepo/nekryptology/pkg/vdf" + "source.quilibrium.com/quilibrium/monorepo/vdf" + "testing" +) + +func getChallenge(seed string) [32]byte { + return sha3.Sum256([]byte(seed)) +} + +func TestProveVerify(t *testing.T) { + difficulty := uint32(10000) + challenge := getChallenge("TestProveVerify") + solution := vdf.WesolowskiSolve(challenge, difficulty) + isOk := vdf.WesolowskiVerify(challenge, difficulty, solution) + if !isOk { + t.Fatalf("Verification failed") + } +} + +func TestProveRustVerifyNekro(t *testing.T) { + difficulty := uint32(100) + challenge := getChallenge("TestProveRustVerifyNekro") + + for i := 0; i < 100; i++ { + solution := vdf.WesolowskiSolve(challenge, difficulty) + nekroVdf := nekrovdf.New(difficulty, challenge) + isOk := nekroVdf.Verify(solution) + if !isOk { + t.Fatalf("Verification failed") + } + challenge = sha3.Sum256(solution[:]) + } +} + +func TestProveNekroVerifyRust(t *testing.T) { + difficulty := uint32(100) + challenge := getChallenge("TestProveNekroVerifyRust") + + for i := 0; i < 100; i++ { + nekroVdf := nekrovdf.New(difficulty, challenge) + nekroVdf.Execute() + proof := nekroVdf.GetOutput() + isOk := vdf.WesolowskiVerify(challenge, difficulty, proof) + if !isOk { + t.Fatalf("Verification failed") + } + challenge = sha3.Sum256(proof[:]) + } +}