From 7e6df490468da974a56e90621679f11d00bd6a0d Mon Sep 17 00:00:00 2001 From: Pawan Dhananjay Date: Wed, 13 Dec 2023 00:10:16 -0800 Subject: [PATCH] Merge 0.53.2 changes to gossipsub testing fork (#560) * ci: unset `RUSTFLAGS` value in semver job Don't fail semver-checking if a dependency version has warnings, such as deprecation notices. Related: https://github.com/libp2p/rust-libp2p/pull/4932#issuecomment-1829014527. Related: https://github.com/obi1kenobi/cargo-semver-checks/issues/589. Pull-Request: #4942. * deps(webrtc): bump alpha versions Bumps versions of `libp2p-webrtc` and `libp2p-webrtc-websys` up one minor version. Fixes: #4953. Pull-Request: #4959. * feat(request-response): derive `PartialOrd`,`Ord` for `{Out,In}RequestId` Pull-Request: #4956. * refactor(connection-limits): make `check_limit` a free-function Pull-Request: #4958. * chore(webrtc-utils): bump version to allow for new release We didn't bump this crate's version despite it depending on `libp2p_noise`. As such, we can't release `libp2p-webrtc-websys` at the moment because it needs a new release of this crate. Pull-Request: #4968. * feat(webrtc-websys): hide `libp2p_noise` from the public API Currently, `libp2p-webrtc-websys` exposes the `libp2p_noise` dependency in its public API. It should really be a private dependency of the crate. By wrapping it in a new-type, we can achieve this. Pull-Request: #4969. * fix(kad): iterator progress to be decided by any of new peers Pull-Request: #4932. * chore(quic): set `max_idle_timeout` to quinn default timeout Resolves #4917. Pull-Request: #4965. * feat(core): impl Display on ListenerId Fixes: #4935. Pull-Request: #4936. * feat(server): support websocket Pull-Request: #4937. * feat(swarm): implement `Copy` and `Clone` for `FromSwarm` We can make `FromSwarm` implement `Copy` and `Close` which makes it much easier to a) generate code in `libp2p-swarm-derive` b) manually wrap a `NetworkBehaviour` Previously, we couldn't do this because `ConnectionClosed` would have a `handler` field that cannot be cloned / copied. Related: #4076. Related: #4581. Pull-Request: #4825. * deps: bump wasm-bindgen-futures from 0.4.38 to 0.4.39 Pull-Request: #4946. * feat(connection-limit): add function to mutate `ConnectionLimits` Resolves: #4826. Pull-Request: #4964. * deps: bump web-sys from 0.3.65 to 0.3.66 Pull-Request: #4976. * deps: bump wasm-bindgen-test from 0.3.38 to 0.3.39 Pull-Request: #4975. * fix(kad): don't assume `QuerId`s are unique We mistakenly assumed that `QueryId`s are unique in that, only a single request will be emitted per `QueryId`. This is wrong. A bootstrap for example will issue multiple requests as part of the same `QueryId`. Thus, we cannot use the `QueryId` as a key for the `FuturesMap`. Instead, we use a `FuturesTupleSet` to associate the `QueryId` with the in-flight request. Related: #4901. Resolves: #4948. Pull-Request: #4971. * fix(webrtc example): clarify idle connection timeout When I ran the `example/browser-webrtc` example I discovered it would break after a ping or two. The `Ping` idle timeout needed to be extended, on both the server and the wasm client, which is what this PR fixes. I also added a small note to the README about ensuring `wasm-pack` is install for the users who are new to the ecosystem. Fixes: #4950. Pull-Request: #4966. * docs(examples/readme): fix broken link Related: #3536. Pull-Request: #4984. * feat(yamux): auto-tune (dynamic) stream receive window https://github.com/libp2p/rust-yamux/pull/176 enables auto-tuning for the Yamux stream receive window. While preserving small buffers on low-latency and/or low-bandwidth connections, this change allows for high-latency and/or high-bandwidth connections to exhaust the available bandwidth on a single stream. Using the [libp2p perf](https://github.com/libp2p/test-plans/blob/master/perf/README.md) benchmark tools (60ms, 10Gbit/s) shows an **improvement from 33 Mbit/s to 1.3 Gbit/s** in single stream throughput. See https://github.com/libp2p/rust-yamux/pull/176 for details. To ship the above Rust Yamux change in a libp2p patch release (non-breaking), this pull request uses `yamux` `v0.13` (new version) by default and falls back to `yamux` `v0.12` (old version) when setting any configuration options. Thus default users benefit from the increased performance, while power users with custom configurations maintain the old behavior. Pull-Request: #4970. * deps: bump actions/deploy-pages from 2 to 3 Pull-Request: #4978. * deps: bump the axum group with 2 updates Pull-Request: #4943. * chore(webrtc-websys): remove unused dependencies Pull-Request: #4973. * chore(quic): fix link to PR in changelog Pull-Request: #4993. * deps: bump tokio from 1.34.0 to 1.35.0 Pull-Request: #4995. * deps: bump syn from 2.0.39 to 2.0.40 Pull-Request: #4996. * deps: bump once_cell from 1.18.0 to 1.19.0 Pull-Request: #4998. --------- Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> Co-authored-by: Doug A Co-authored-by: Darius Clark Co-authored-by: zhiqiangxu <652732310@qq.com> Co-authored-by: Thomas Eizinger Co-authored-by: maqi Co-authored-by: stormshield-frb <144998884+stormshield-frb@users.noreply.github.com> Co-authored-by: Max Inden Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com> --- .github/workflows/ci.yml | 9 + .github/workflows/docs.yml | 2 +- Cargo.lock | 345 +++++++++++++++------ Cargo.toml | 24 +- core/CHANGELOG.md | 5 + core/Cargo.toml | 4 +- core/src/transport.rs | 6 + examples/README.md | 2 +- examples/autonat/Cargo.toml | 2 +- examples/browser-webrtc/Cargo.toml | 8 +- examples/browser-webrtc/README.md | 2 + examples/browser-webrtc/src/lib.rs | 21 +- examples/browser-webrtc/src/main.rs | 13 +- examples/chat/Cargo.toml | 2 +- examples/dcutr/Cargo.toml | 2 +- examples/ipfs-kad/Cargo.toml | 2 +- examples/ipfs-private/Cargo.toml | 2 +- examples/ping/Cargo.toml | 2 +- examples/rendezvous/Cargo.toml | 2 +- hole-punching-tests/Cargo.toml | 2 +- interop-tests/Cargo.toml | 6 +- interop-tests/src/bin/wasm_ping.rs | 8 +- libp2p/CHANGELOG.md | 5 + libp2p/Cargo.toml | 2 +- libp2p/src/builder/phase/relay.rs | 19 +- misc/connection-limits/CHANGELOG.md | 5 + misc/connection-limits/Cargo.toml | 2 +- misc/connection-limits/src/lib.rs | 41 +-- misc/futures-bounded/Cargo.toml | 2 +- misc/server/CHANGELOG.md | 7 + misc/server/Cargo.toml | 4 +- misc/server/src/main.rs | 2 + misc/webrtc-utils/CHANGELOG.md | 5 + misc/webrtc-utils/Cargo.toml | 2 +- misc/webrtc-utils/src/noise.rs | 6 +- muxers/yamux/CHANGELOG.md | 6 + muxers/yamux/Cargo.toml | 4 +- muxers/yamux/src/lib.rs | 214 +++++++++---- protocols/autonat/src/behaviour.rs | 90 +----- protocols/kad/CHANGELOG.md | 5 + protocols/kad/Cargo.toml | 2 +- protocols/kad/src/handler.rs | 67 ++-- protocols/kad/src/query/peers/closest.rs | 17 +- protocols/mdns/Cargo.toml | 4 +- protocols/perf/Cargo.toml | 2 +- protocols/rendezvous/Cargo.toml | 2 +- protocols/rendezvous/src/server.rs | 12 +- protocols/request-response/CHANGELOG.md | 5 + protocols/request-response/Cargo.toml | 2 +- protocols/request-response/src/lib.rs | 4 +- protocols/upnp/Cargo.toml | 2 +- swarm-derive/CHANGELOG.md | 5 + swarm-derive/Cargo.toml | 4 +- swarm-derive/src/lib.rs | 362 +--------------------- swarm/CHANGELOG.md | 6 + swarm/Cargo.toml | 12 +- swarm/src/behaviour.rs | 4 +- swarm/src/test.rs | 41 +-- transports/noise/Cargo.toml | 2 +- transports/pnet/Cargo.toml | 2 +- transports/quic/CHANGELOG.md | 5 + transports/quic/Cargo.toml | 6 +- transports/quic/src/config.rs | 4 +- transports/tcp/Cargo.toml | 4 +- transports/tls/Cargo.toml | 2 +- transports/uds/Cargo.toml | 2 +- transports/webrtc-websys/CHANGELOG.md | 7 + transports/webrtc-websys/Cargo.toml | 14 +- transports/webrtc-websys/src/error.rs | 9 +- transports/webrtc-websys/src/upgrade.rs | 5 +- transports/webrtc/CHANGELOG.md | 5 + transports/webrtc/Cargo.toml | 6 +- transports/websocket-websys/Cargo.toml | 2 +- transports/webtransport-websys/Cargo.toml | 4 +- wasm-tests/webtransport-tests/Cargo.toml | 6 +- 75 files changed, 736 insertions(+), 794 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04dab309902..f8770a29bc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -307,6 +307,15 @@ jobs: semver: runs-on: ubuntu-latest + env: + # Unset the global `RUSTFLAGS` env to allow warnings. + # cargo-semver-checks intentionally re-locks dependency versions + # before checking, and we shouldn't fail here if a dep has a warning. + # + # More context: + # https://github.com/libp2p/rust-libp2p/pull/4932#issuecomment-1829014527 + # https://github.com/obi1kenobi/cargo-semver-checks/issues/589 + RUSTFLAGS: '' steps: - uses: actions/checkout@v4 - run: wget -q -O- https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.25.0/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C ~/.cargo/bin diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index bffcc60d2ea..87fb4732b6e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -42,5 +42,5 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v2 + uses: actions/deploy-pages@v3 diff --git a/Cargo.lock b/Cargo.lock index 2f252eecba0..fbbf1d84f1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -424,7 +424,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -452,7 +452,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d9a9bf8b79a749ee0b911b91b671cc2b6c670bdbc7e3dfd537576ddc94bb2a2" dependencies = [ - "http", + "http 0.2.9", "log", "url", ] @@ -482,13 +482,42 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.3.4", "bitflags 1.3.2", "bytes", "futures-util", - "http", - "http-body", - "hyper", + "http 0.2.9", + "http-body 0.4.5", + "hyper 0.14.27", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "810a80b128d70e6ed2bdf3fe8ed72c0ae56f5f5948d01c2753282dd92a84fce8" +dependencies = [ + "async-trait", + "axum-core 0.4.0", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.0.1", + "hyper-util", "itoa", "matchit", "memchr", @@ -516,14 +545,34 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 0.2.9", + "http-body 0.4.5", "mime", "rustversion", "tower-layer", "tower-service", ] +[[package]] +name = "axum-core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de0ddc355eab88f4955090a823715df47acf0b7660aab7a69ad5ce6301ee3b73" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.68" @@ -661,7 +710,7 @@ name = "browser-webrtc-example" version = "0.1.0" dependencies = [ "anyhow", - "axum", + "axum 0.7.1", "futures", "js-sys", "libp2p", @@ -878,7 +927,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -1155,7 +1204,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -1272,7 +1321,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -1377,7 +1426,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -1467,8 +1516,8 @@ dependencies = [ "cookie", "futures-core", "futures-util", - "http", - "hyper", + "http 0.2.9", + "hyper 0.14.27", "hyper-rustls", "mime", "serde", @@ -1647,7 +1696,7 @@ checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -1827,7 +1876,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.9", "indexmap 1.9.3", "slab", "tokio", @@ -1835,6 +1884,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "h2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d308f63daf4181410c242d34c11f928dcb3aa105852019e043c9d1f4e4368a" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 1.0.0", + "indexmap 2.0.0", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "half" version = "1.8.2" @@ -2010,6 +2078,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.5" @@ -2017,15 +2096,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", - "http", + "http 0.2.9", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.0.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" +dependencies = [ + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", "pin-project-lite", ] [[package]] name = "http-range-header" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f" +checksum = "3ce4ef31cda248bbdb6e6820603b82dfcd9e833db65a43e997a0ccec777d11fe" [[package]] name = "httparse" @@ -2055,9 +2157,9 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.3.20", + "http 0.2.9", + "http-body 0.4.5", "httparse", "httpdate", "itoa", @@ -2069,14 +2171,33 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "403f9214f3e703236b221f1a9cd88ec8b4adfa5296de01ab96216361f4692f56" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.0", + "http 1.0.0", + "http-body 1.0.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "tokio", +] + [[package]] name = "hyper-rustls" version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" dependencies = [ - "http", - "hyper", + "http 0.2.9", + "hyper 0.14.27", "log", "rustls 0.20.8", "rustls-native-certs", @@ -2090,7 +2211,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ - "hyper", + "hyper 0.14.27", "pin-project-lite", "tokio", "tokio-io-timeout", @@ -2103,12 +2224,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper", + "hyper 0.14.27", "native-tls", "tokio", "tokio-native-tls", ] +[[package]] +name = "hyper-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca339002caeb0d159cc6e023dff48e199f081e42fa039895c7c6f38b37f2e9d" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "hyper 1.0.1", + "pin-project-lite", + "socket2 0.5.5", + "tokio", + "tower", + "tower-service", + "tracing", +] + [[package]] name = "identify-example" version = "0.1.0" @@ -2181,8 +2322,8 @@ dependencies = [ "attohttpc", "bytes", "futures", - "http", - "hyper", + "http 0.2.9", + "hyper 0.14.27", "log", "rand 0.8.5", "tokio", @@ -2256,7 +2397,7 @@ name = "interop-tests" version = "0.1.0" dependencies = [ "anyhow", - "axum", + "axum 0.7.1", "console_error_panic_hook", "either", "futures", @@ -2422,7 +2563,7 @@ checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "libp2p" -version = "0.53.1" +version = "0.53.2" dependencies = [ "async-std", "async-trait", @@ -2510,7 +2651,7 @@ dependencies = [ [[package]] name = "libp2p-connection-limits" -version = "0.3.0" +version = "0.3.1" dependencies = [ "async-std", "libp2p-core", @@ -2527,7 +2668,7 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.41.1" +version = "0.41.2" dependencies = [ "async-std", "either", @@ -2722,7 +2863,7 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.45.2" +version = "0.45.3" dependencies = [ "arrayvec", "async-std", @@ -2971,7 +3112,7 @@ dependencies = [ [[package]] name = "libp2p-quic" -version = "0.10.1" +version = "0.10.2" dependencies = [ "async-std", "bytes", @@ -3059,7 +3200,7 @@ dependencies = [ [[package]] name = "libp2p-request-response" -version = "0.26.0" +version = "0.26.1" dependencies = [ "anyhow", "async-std", @@ -3088,13 +3229,13 @@ dependencies = [ [[package]] name = "libp2p-server" -version = "0.12.4" +version = "0.12.5" dependencies = [ "base64 0.21.5", "clap", "futures", "futures-timer", - "hyper", + "hyper 0.14.27", "libp2p", "prometheus-client", "serde", @@ -3108,7 +3249,7 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.44.0" +version = "0.44.1" dependencies = [ "async-std", "either", @@ -3141,12 +3282,12 @@ dependencies = [ [[package]] name = "libp2p-swarm-derive" -version = "0.34.0" +version = "0.34.1" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -3234,7 +3375,7 @@ dependencies = [ [[package]] name = "libp2p-webrtc" -version = "0.6.1-alpha" +version = "0.7.0-alpha" dependencies = [ "async-trait", "bytes", @@ -3263,7 +3404,7 @@ dependencies = [ [[package]] name = "libp2p-webrtc-utils" -version = "0.1.0" +version = "0.2.0" dependencies = [ "asynchronous-codec", "bytes", @@ -3285,23 +3426,17 @@ dependencies = [ [[package]] name = "libp2p-webrtc-websys" -version = "0.2.0-alpha" +version = "0.3.0-alpha" dependencies = [ "bytes", "futures", - "futures-timer", "getrandom 0.2.11", "hex", - "hex-literal", "js-sys", "libp2p-core", "libp2p-identity", - "libp2p-noise", - "libp2p-ping", - "libp2p-swarm", "libp2p-webrtc-utils", "send_wrapper 0.6.0", - "serde", "thiserror", "tracing", "wasm-bindgen", @@ -3375,12 +3510,14 @@ name = "libp2p-yamux" version = "0.45.1" dependencies = [ "async-std", + "either", "futures", "libp2p-core", "libp2p-muxer-test-harness", "thiserror", "tracing", - "yamux", + "yamux 0.12.1", + "yamux 0.13.1", ] [[package]] @@ -3555,7 +3692,7 @@ name = "metrics-example" version = "0.1.0" dependencies = [ "futures", - "hyper", + "hyper 0.14.27", "libp2p", "opentelemetry", "opentelemetry-otlp", @@ -3875,9 +4012,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oorandom" @@ -3914,7 +4051,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -3953,7 +4090,7 @@ checksum = "7e5e5a5c4135864099f3faafbe939eb4d7f9b80ebf68a8448da961b32a7c1275" dependencies = [ "async-trait", "futures-core", - "http", + "http 0.2.9", "opentelemetry-proto", "opentelemetry-semantic-conventions", "opentelemetry_api", @@ -4140,7 +4277,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -4337,7 +4474,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -4714,10 +4851,10 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", - "http", - "http-body", - "hyper", + "h2 0.3.20", + "http 0.2.9", + "http-body 0.4.5", + "hyper 0.14.27", "hyper-tls", "ipnet", "js-sys", @@ -4882,7 +5019,7 @@ dependencies = [ "quote", "rust-embed-utils", "shellexpand", - "syn 2.0.39", + "syn 2.0.40", "walkdir", ] @@ -5167,7 +5304,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -5200,7 +5337,7 @@ checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -5503,9 +5640,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "13fa70a4ee923979ffb522cacce59d34421ebdea5625e1073c4326ef9d2dd42e" dependencies = [ "proc-macro2", "quote", @@ -5599,7 +5736,7 @@ dependencies = [ "cookie", "fantoccini", "futures", - "http", + "http 0.2.9", "indexmap 1.9.3", "log", "parking_lot", @@ -5643,7 +5780,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -5710,9 +5847,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.34.0" +version = "1.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" +checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c" dependencies = [ "backtrace", "bytes", @@ -5745,7 +5882,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -5802,15 +5939,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3082666a3a6433f7f511c7192923fa1fe07c69332d3c6a2e6bb040b569199d5a" dependencies = [ "async-trait", - "axum", + "axum 0.6.20", "base64 0.21.5", "bytes", "futures-core", "futures-util", - "h2", - "http", - "http-body", - "hyper", + "h2 0.3.20", + "http 0.2.9", + "http-body 0.4.5", + "hyper 0.14.27", "hyper-timeout", "percent-encoding", "pin-project", @@ -5845,16 +5982,16 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.4.4" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140" +checksum = "09e12e6351354851911bdf8c2b8f2ab15050c567d70a8b9a37ae7b8301a4080d" dependencies = [ "bitflags 2.4.1", "bytes", - "futures-core", "futures-util", - "http", - "http-body", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", "http-range-header", "httpdate", "mime", @@ -5900,7 +6037,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -6257,15 +6394,15 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" +checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" dependencies = [ "cfg-if", "js-sys", @@ -6291,7 +6428,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6304,9 +6441,9 @@ checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "wasm-bindgen-test" -version = "0.3.38" +version = "0.3.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6433b7c56db97397842c46b67e11873eda263170afeb3a2dc74a7cb370fee0d" +checksum = "2cf9242c0d27999b831eae4767b2a146feb0b27d332d553e605864acd2afd403" dependencies = [ "console_error_panic_hook", "js-sys", @@ -6318,13 +6455,13 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.38" +version = "0.3.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "493fcbab756bb764fa37e6bee8cec2dd709eb4273d06d0c282a5e74275ded735" +checksum = "794645f5408c9a039fd09f4d113cdfb2e7eba5ff1956b07bcf701cf4b394fe89" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -6340,9 +6477,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" +checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" dependencies = [ "js-sys", "wasm-bindgen", @@ -6357,7 +6494,7 @@ dependencies = [ "base64 0.13.1", "bytes", "cookie", - "http", + "http 0.2.9", "log", "serde", "serde_derive", @@ -6865,6 +7002,22 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "yamux" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1d0148b89300047e72994bee99ecdabd15a9166a7b70c8b8c37c314dcc9002" +dependencies = [ + "futures", + "instant", + "log", + "nohash-hasher", + "parking_lot", + "pin-project", + "rand 0.8.5", + "static_assertions", +] + [[package]] name = "yasna" version = "0.5.2" @@ -6891,5 +7044,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] diff --git a/Cargo.toml b/Cargo.toml index 346b316d4dc..11ac47b0be4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,18 +72,18 @@ rust-version = "1.73.0" [workspace.dependencies] asynchronous-codec = { version = "0.7.0" } futures-bounded = { version = "0.2.3", path = "misc/futures-bounded" } -libp2p = { version = "0.53.0", path = "libp2p" } +libp2p = { version = "0.53.2", path = "libp2p" } libp2p-allow-block-list = { version = "0.3.0", path = "misc/allow-block-list" } libp2p-autonat = { version = "0.12.0", path = "protocols/autonat" } -libp2p-connection-limits = { version = "0.3.0", path = "misc/connection-limits" } -libp2p-core = { version = "0.41.1", path = "core" } +libp2p-connection-limits = { version = "0.3.1", path = "misc/connection-limits" } +libp2p-core = { version = "0.41.2", path = "core" } libp2p-dcutr = { version = "0.11.0", path = "protocols/dcutr" } libp2p-dns = { version = "0.41.1", path = "transports/dns" } libp2p-floodsub = { version = "0.44.0", path = "protocols/floodsub" } libp2p-gossipsub = { version = "0.46.1", path = "protocols/gossipsub" } libp2p-identify = { version = "0.44.1", path = "protocols/identify" } libp2p-identity = { version = "0.2.8" } -libp2p-kad = { version = "0.45.2", path = "protocols/kad" } +libp2p-kad = { version = "0.45.3", path = "protocols/kad" } libp2p-mdns = { version = "0.45.1", path = "protocols/mdns" } libp2p-memory-connection-limits = { version = "0.2.0", path = "misc/memory-connection-limits" } libp2p-metrics = { version = "0.14.1", path = "misc/metrics" } @@ -94,21 +94,21 @@ libp2p-perf = { version = "0.3.0", path = "protocols/perf" } libp2p-ping = { version = "0.44.0", path = "protocols/ping" } libp2p-plaintext = { version = "0.41.0", path = "transports/plaintext" } libp2p-pnet = { version = "0.24.0", path = "transports/pnet" } -libp2p-quic = { version = "0.10.1", path = "transports/quic" } +libp2p-quic = { version = "0.10.2", path = "transports/quic" } libp2p-relay = { version = "0.17.1", path = "protocols/relay" } libp2p-rendezvous = { version = "0.14.0", path = "protocols/rendezvous" } -libp2p-request-response = { version = "0.26.0", path = "protocols/request-response" } -libp2p-server = { version = "0.12.4", path = "misc/server" } -libp2p-swarm = { version = "0.44.0", path = "swarm" } -libp2p-swarm-derive = { version = "=0.34.0", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required. +libp2p-request-response = { version = "0.26.1", path = "protocols/request-response" } +libp2p-server = { version = "0.12.5", path = "misc/server" } +libp2p-swarm = { version = "0.44.1", path = "swarm" } +libp2p-swarm-derive = { version = "=0.34.1", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required. libp2p-swarm-test = { version = "0.3.0", path = "swarm-test" } libp2p-tcp = { version = "0.41.0", path = "transports/tcp" } libp2p-tls = { version = "0.3.0", path = "transports/tls" } libp2p-uds = { version = "0.40.0", path = "transports/uds" } libp2p-upnp = { version = "0.2.0", path = "protocols/upnp" } -libp2p-webrtc = { version = "0.6.1-alpha", path = "transports/webrtc" } -libp2p-webrtc-utils = { version = "0.1.0", path = "misc/webrtc-utils" } -libp2p-webrtc-websys = { version = "0.2.0-alpha", path = "transports/webrtc-websys" } +libp2p-webrtc = { version = "0.7.0-alpha", path = "transports/webrtc" } +libp2p-webrtc-utils = { version = "0.2.0", path = "misc/webrtc-utils" } +libp2p-webrtc-websys = { version = "0.3.0-alpha", path = "transports/webrtc-websys" } libp2p-websocket = { version = "0.43.0", path = "transports/websocket" } libp2p-websocket-websys = { version = "0.3.1", path = "transports/websocket-websys" } libp2p-webtransport-websys = { version = "0.2.0", path = "transports/webtransport-websys" } diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 833af07982c..a7cd7fd46b4 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.41.2 + +- Implement `std::fmt::Display` on `ListenerId`. + See [PR 4936](https://github.com/libp2p/rust-libp2p/pull/4936). + ## 0.41.1 - Implement `{In,Out}boundConnectionUpgrade` for `SelectUpgrade`. diff --git a/core/Cargo.toml b/core/Cargo.toml index 7380695023b..5c941db6e33 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-core" edition = "2021" rust-version = { workspace = true } description = "Core traits and structs of libp2p" -version = "0.41.1" +version = "0.41.2" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -20,7 +20,7 @@ libp2p-identity = { workspace = true, features = ["peerid", "ed25519"] } multiaddr = { workspace = true } multihash = { workspace = true } multistream-select = { workspace = true } -once_cell = "1.18.0" +once_cell = "1.19.0" parking_lot = "0.12.0" pin-project = "1.1.3" quick-protobuf = "0.8" diff --git a/core/src/transport.rs b/core/src/transport.rs index 8656b89228c..22e7a0532fa 100644 --- a/core/src/transport.rs +++ b/core/src/transport.rs @@ -256,6 +256,12 @@ impl ListenerId { } } +impl std::fmt::Display for ListenerId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + /// Event produced by [`Transport`]s. pub enum TransportEvent { /// A new address is being listened on. diff --git a/examples/README.md b/examples/README.md index 28e085587b7..0a3e55aed39 100644 --- a/examples/README.md +++ b/examples/README.md @@ -20,6 +20,6 @@ A set of examples showcasing how to use rust-libp2p. - [IPFS Private](./ipfs-private) Implementation using the gossipsub, ping and identify protocols to implement the ipfs private swarms feature. -- [Ping](./ping) Small `ping` clone, sending a ping to a peer, expecting a pong as a response. See [tutorial](../src/tutorials/ping.rs) for a step-by-step guide building the example. +- [Ping](./ping) Small `ping` clone, sending a ping to a peer, expecting a pong as a response. See [tutorial](../libp2p/src/tutorials/ping.rs) for a step-by-step guide building the example. - [Rendezvous](./rendezvous) Rendezvous Protocol. See [specs](https://github.com/libp2p/specs/blob/master/rendezvous/README.md). diff --git a/examples/autonat/Cargo.toml b/examples/autonat/Cargo.toml index cca3b5e326e..e530cbe9561 100644 --- a/examples/autonat/Cargo.toml +++ b/examples/autonat/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" release = false [dependencies] -tokio = { version = "1.34", features = ["full"] } +tokio = { version = "1.35", features = ["full"] } clap = { version = "4.4.10", features = ["derive"] } futures = "0.3.29" libp2p = { path = "../../libp2p", features = ["tokio", "tcp", "noise", "yamux", "autonat", "identify", "macros"] } diff --git a/examples/browser-webrtc/Cargo.toml b/examples/browser-webrtc/Cargo.toml index 57232abeb5e..c94baf5f7ba 100644 --- a/examples/browser-webrtc/Cargo.toml +++ b/examples/browser-webrtc/Cargo.toml @@ -23,14 +23,14 @@ tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -axum = "0.6.19" +axum = "0.7.1" libp2p = { path = "../../libp2p", features = [ "ed25519", "macros", "ping", "tokio"] } libp2p-webrtc = { workspace = true, features = ["tokio"] } rust-embed = { version = "8.0.0", features = ["include-exclude", "interpolate-folder-path"] } -tokio = { version = "1.34", features = ["macros", "net", "rt", "signal"] } +tokio = { version = "1.35", features = ["macros", "net", "rt", "signal"] } tokio-util = { version = "0.7", features = ["compat"] } tower = "0.4" -tower-http = { version = "0.4.0", features = ["cors"] } +tower-http = { version = "0.5.0", features = ["cors"] } mime_guess = "2.0.4" [target.'cfg(target_arch = "wasm32")'.dependencies] @@ -39,7 +39,7 @@ libp2p = { path = "../../libp2p", features = [ "ed25519", "macros", "ping", "was libp2p-webrtc-websys = { workspace = true } tracing-wasm = "0.2.1" wasm-bindgen = "0.2.89" -wasm-bindgen-futures = "0.4.38" +wasm-bindgen-futures = "0.4.39" web-sys = { version = "0.3", features = ['Document', 'Element', 'HtmlElement', 'Node', 'Response', 'Window'] } [lints] diff --git a/examples/browser-webrtc/README.md b/examples/browser-webrtc/README.md index d44cf879905..eec2c9c0494 100644 --- a/examples/browser-webrtc/README.md +++ b/examples/browser-webrtc/README.md @@ -5,6 +5,8 @@ It uses [wasm-pack](https://rustwasm.github.io/docs/wasm-pack/) to build the pro ## Running the example +Ensure you have `wasm-pack` [installed](https://rustwasm.github.io/wasm-pack/). + 1. Build the client library: ```shell wasm-pack build --target web --out-dir static diff --git a/examples/browser-webrtc/src/lib.rs b/examples/browser-webrtc/src/lib.rs index 2112919c6de..9499ccbd158 100644 --- a/examples/browser-webrtc/src/lib.rs +++ b/examples/browser-webrtc/src/lib.rs @@ -15,8 +15,13 @@ use web_sys::{Document, HtmlElement}; pub async fn run(libp2p_endpoint: String) -> Result<(), JsError> { tracing_wasm::set_as_global_default(); + let ping_duration = Duration::from_secs(30); + let body = Body::from_current_window()?; - body.append_p("Let's ping the WebRTC Server!")?; + body.append_p(&format!( + "Let's ping the rust-libp2p server over WebRTC for {:?}:", + ping_duration + ))?; let mut swarm = libp2p::SwarmBuilder::with_new_identity() .with_wasm_bindgen() @@ -24,7 +29,7 @@ pub async fn run(libp2p_endpoint: String) -> Result<(), JsError> { webrtc_websys::Transport::new(webrtc_websys::Config::new(&key)) })? .with_behaviour(|_| ping::Behaviour::new(ping::Config::new()))? - .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(5))) + .with_swarm_config(|c| c.with_idle_connection_timeout(ping_duration)) .build(); let addr = libp2p_endpoint.parse::()?; @@ -46,6 +51,18 @@ pub async fn run(libp2p_endpoint: String) -> Result<(), JsError> { tracing::info!("Ping successful: RTT: {rtt:?}, from {peer}"); body.append_p(&format!("RTT: {rtt:?} at {}", Date::new_0().to_string()))?; } + SwarmEvent::ConnectionClosed { + cause: Some(cause), .. + } => { + tracing::info!("Swarm event: {:?}", cause); + + if let libp2p::swarm::ConnectionError::KeepAliveTimeout = cause { + body.append_p("All done with pinging! ")?; + + break; + } + body.append_p(&format!("Connection closed due to: {:?}", cause))?; + } evt => tracing::info!("Swarm event: {:?}", evt), } } diff --git a/examples/browser-webrtc/src/main.rs b/examples/browser-webrtc/src/main.rs index 098b70f3054..7f06b0d0d99 100644 --- a/examples/browser-webrtc/src/main.rs +++ b/examples/browser-webrtc/src/main.rs @@ -18,6 +18,7 @@ use libp2p_webrtc as webrtc; use rand::thread_rng; use std::net::{Ipv4Addr, SocketAddr}; use std::time::Duration; +use tokio::net::TcpListener; use tower_http::cors::{Any, CorsLayer}; #[tokio::main] @@ -38,7 +39,7 @@ async fn main() -> anyhow::Result<()> { .with_behaviour(|_| ping::Behaviour::default())? .with_swarm_config(|cfg| { cfg.with_idle_connection_timeout( - Duration::from_secs(30), // Allows us to observe the pings. + Duration::from_secs(u64::MAX), // Allows us to observe the pings. ) }) .build(); @@ -112,10 +113,12 @@ pub(crate) async fn serve(libp2p_transport: Multiaddr) { tracing::info!(url=%format!("http://{addr}"), "Serving client files at url"); - axum::Server::bind(&addr) - .serve(server.into_make_service()) - .await - .unwrap(); + axum::serve( + TcpListener::bind((listen_addr, 8080)).await.unwrap(), + server.into_make_service(), + ) + .await + .unwrap(); } #[derive(Clone)] diff --git a/examples/chat/Cargo.toml b/examples/chat/Cargo.toml index 9b3561dab48..9e6f58852f8 100644 --- a/examples/chat/Cargo.toml +++ b/examples/chat/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" release = false [dependencies] -tokio = { version = "1.34", features = ["full"] } +tokio = { version = "1.35", features = ["full"] } async-trait = "0.1" futures = "0.3.29" libp2p = { path = "../../libp2p", features = [ "tokio", "gossipsub", "mdns", "noise", "macros", "tcp", "yamux", "quic"] } diff --git a/examples/dcutr/Cargo.toml b/examples/dcutr/Cargo.toml index 8dcb403218e..6eeb1969745 100644 --- a/examples/dcutr/Cargo.toml +++ b/examples/dcutr/Cargo.toml @@ -14,7 +14,7 @@ futures = "0.3.29" futures-timer = "3.0" libp2p = { path = "../../libp2p", features = [ "dns", "dcutr", "identify", "macros", "noise", "ping", "quic", "relay", "rendezvous", "tcp", "tokio", "yamux"] } log = "0.4" -tokio = { version = "1.34", features = ["macros", "net", "rt", "signal"] } +tokio = { version = "1.35", features = ["macros", "net", "rt", "signal"] } tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/ipfs-kad/Cargo.toml b/examples/ipfs-kad/Cargo.toml index 7870d3adb79..4e4a1eafdd5 100644 --- a/examples/ipfs-kad/Cargo.toml +++ b/examples/ipfs-kad/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" release = false [dependencies] -tokio = { version = "1.34", features = ["rt-multi-thread", "macros"] } +tokio = { version = "1.35", features = ["rt-multi-thread", "macros"] } async-trait = "0.1" clap = { version = "4.4.10", features = ["derive"] } env_logger = "0.10" diff --git a/examples/ipfs-private/Cargo.toml b/examples/ipfs-private/Cargo.toml index 97c1ca59368..076c863543b 100644 --- a/examples/ipfs-private/Cargo.toml +++ b/examples/ipfs-private/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" release = false [dependencies] -tokio = { version = "1.34", features = ["rt-multi-thread", "macros", "io-std"] } +tokio = { version = "1.35", features = ["rt-multi-thread", "macros", "io-std"] } async-trait = "0.1" either = "1.9" futures = "0.3.29" diff --git a/examples/ping/Cargo.toml b/examples/ping/Cargo.toml index 66d2847cb8f..128d33d26f4 100644 --- a/examples/ping/Cargo.toml +++ b/examples/ping/Cargo.toml @@ -11,7 +11,7 @@ release = false [dependencies] futures = "0.3.29" libp2p = { path = "../../libp2p", features = ["noise", "ping", "tcp", "tokio", "yamux"] } -tokio = { version = "1.34.0", features = ["full"] } +tokio = { version = "1.35.0", features = ["full"] } tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/rendezvous/Cargo.toml b/examples/rendezvous/Cargo.toml index fbb2ed44a03..bc48b70d30d 100644 --- a/examples/rendezvous/Cargo.toml +++ b/examples/rendezvous/Cargo.toml @@ -13,7 +13,7 @@ async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" futures = "0.3.29" libp2p = { path = "../../libp2p", features = [ "async-std", "identify", "macros", "noise", "ping", "rendezvous", "tcp", "tokio", "yamux"] } -tokio = { version = "1.34", features = ["rt-multi-thread", "macros", "time"] } +tokio = { version = "1.35", features = ["rt-multi-thread", "macros", "time"] } tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/hole-punching-tests/Cargo.toml b/hole-punching-tests/Cargo.toml index a6f1bd6571c..e080b76a0d7 100644 --- a/hole-punching-tests/Cargo.toml +++ b/hole-punching-tests/Cargo.toml @@ -12,7 +12,7 @@ futures = "0.3.29" libp2p = { path = "../libp2p", features = ["tokio", "dcutr", "identify", "macros", "noise", "ping", "relay", "tcp", "yamux", "quic"] } tracing = "0.1.37" redis = { version = "0.23.0", default-features = false, features = ["tokio-comp"] } -tokio = { version = "1.34.0", features = ["full"] } +tokio = { version = "1.35.0", features = ["full"] } serde = { version = "1.0.193", features = ["derive"] } serde_json = "1.0.108" either = "1.9.0" diff --git a/interop-tests/Cargo.toml b/interop-tests/Cargo.toml index eba65b782e7..b09371fc8b1 100644 --- a/interop-tests/Cargo.toml +++ b/interop-tests/Cargo.toml @@ -21,7 +21,7 @@ tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -axum = "0.6" +axum = "0.7" libp2p = { path = "../libp2p", features = [ "ping", "noise", "tls", "rsa", "macros", "websocket", "tokio", "yamux", "tcp", "dns", "identify", "quic"] } libp2p-mplex = { path = "../muxers/mplex" } libp2p-noise = { workspace = true } @@ -34,8 +34,8 @@ redis = { version = "0.23.3", default-features = false, features = [ rust-embed = "8.0" serde_json = "1" thirtyfour = "=0.32.0-rc.8" # https://github.com/stevepryde/thirtyfour/issues/169 -tokio = { version = "1.34.0", features = ["full"] } -tower-http = { version = "0.4", features = ["cors", "fs", "trace"] } +tokio = { version = "1.35.0", features = ["full"] } +tower-http = { version = "0.5", features = ["cors", "fs", "trace"] } tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/interop-tests/src/bin/wasm_ping.rs b/interop-tests/src/bin/wasm_ping.rs index 8269ff064ad..e1bb2ea49fb 100644 --- a/interop-tests/src/bin/wasm_ping.rs +++ b/interop-tests/src/bin/wasm_ping.rs @@ -1,9 +1,10 @@ #![allow(non_upper_case_globals)] + +use std::future::IntoFuture; use std::process::Stdio; use std::time::Duration; use anyhow::{bail, Context, Result}; -use axum::body; use axum::http::{header, Uri}; use axum::response::{Html, IntoResponse, Response}; use axum::routing::get; @@ -11,6 +12,7 @@ use axum::{extract::State, http::StatusCode, routing::post, Json, Router}; use redis::{AsyncCommands, Client}; use thirtyfour::prelude::*; use tokio::io::{AsyncBufReadExt, BufReader}; +use tokio::net::TcpListener; use tokio::process::Child; use tokio::sync::mpsc; use tower_http::cors::CorsLayer; @@ -76,7 +78,7 @@ async fn main() -> Result<()> { .with_state(state); // Run the service in background - tokio::spawn(axum::Server::bind(&BIND_ADDR.parse()?).serve(app.into_make_service())); + tokio::spawn(axum::serve(TcpListener::bind(BIND_ADDR).await?, app).into_future()); // Start executing the test in a browser let (mut chrome, driver) = open_in_browser().await?; @@ -229,7 +231,7 @@ async fn serve_wasm_pkg(uri: Uri) -> Result { let mime = mime_guess::from_path(&path).first_or_octet_stream(); Ok(Response::builder() .header(header::CONTENT_TYPE, mime.as_ref()) - .body(body::boxed(body::Full::from(content.data))) + .body(content.data.into()) .unwrap()) } else { Err(StatusCode::NOT_FOUND) diff --git a/libp2p/CHANGELOG.md b/libp2p/CHANGELOG.md index bb6d8211bd5..80b32c35643 100644 --- a/libp2p/CHANGELOG.md +++ b/libp2p/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.53.2 + +- Allow `SwarmBuilder::with_bandwidth_metrics` after `SwarmBuilder::with_websocket`. + See [PR 4937](https://github.com/libp2p/rust-libp2p/pull/4937). + ## 0.53.1 - Allow `SwarmBuilder::with_quic_config` to be called without `with_tcp` first. diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index 6ced40e1dfe..9dc9667be10 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p" edition = "2021" rust-version = { workspace = true } description = "Peer-to-peer networking library" -version = "0.53.1" +version = "0.53.2" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/libp2p/src/builder/phase/relay.rs b/libp2p/src/builder/phase/relay.rs index 2d47810ca9e..f8305f9d246 100644 --- a/libp2p/src/builder/phase/relay.rs +++ b/libp2p/src/builder/phase/relay.rs @@ -116,11 +116,28 @@ impl SwarmBuilder> { } // Shortcuts +#[cfg(feature = "metrics")] +impl SwarmBuilder> { + pub fn with_bandwidth_metrics( + self, + registry: &mut libp2p_metrics::Registry, + ) -> SwarmBuilder< + Provider, + BehaviourPhase, + > { + self.without_relay() + .without_bandwidth_logging() + .with_bandwidth_metrics(registry) + } +} impl SwarmBuilder> { pub fn with_behaviour>( self, constructor: impl FnOnce(&libp2p_identity::Keypair) -> R, ) -> Result>, R::Error> { - self.without_relay().with_behaviour(constructor) + self.without_relay() + .without_bandwidth_logging() + .without_bandwidth_metrics() + .with_behaviour(constructor) } } diff --git a/misc/connection-limits/CHANGELOG.md b/misc/connection-limits/CHANGELOG.md index a5b68a6f51b..4654281a83e 100644 --- a/misc/connection-limits/CHANGELOG.md +++ b/misc/connection-limits/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.3.1 + +- Add function to mutate `ConnectionLimits`. + See [PR 4964](https://github.com/libp2p/rust-libp2p/pull/4964). + ## 0.3.0 diff --git a/misc/connection-limits/Cargo.toml b/misc/connection-limits/Cargo.toml index 2aa26ad44f1..8ecb0005cb1 100644 --- a/misc/connection-limits/Cargo.toml +++ b/misc/connection-limits/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-connection-limits" edition = "2021" rust-version = { workspace = true } description = "Connection limits for libp2p." -version = "0.3.0" +version = "0.3.1" license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" keywords = ["peer-to-peer", "libp2p", "networking"] diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index af76e9a57d9..dbe68a8ad11 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -80,21 +80,22 @@ impl Behaviour { } } - fn check_limit( - &mut self, - limit: Option, - current: usize, - kind: Kind, - ) -> Result<(), ConnectionDenied> { - let limit = limit.unwrap_or(u32::MAX); - let current = current as u32; + /// Returns a mutable reference to [`ConnectionLimits`]. + /// > **Note**: A new limit will not be enforced against existing connections. + pub fn limits_mut(&mut self) -> &mut ConnectionLimits { + &mut self.limits + } +} - if current >= limit { - return Err(ConnectionDenied::new(Exceeded { limit, kind })); - } +fn check_limit(limit: Option, current: usize, kind: Kind) -> Result<(), ConnectionDenied> { + let limit = limit.unwrap_or(u32::MAX); + let current = current as u32; - Ok(()) + if current >= limit { + return Err(ConnectionDenied::new(Exceeded { limit, kind })); } + + Ok(()) } /// A connection limit has been exceeded. @@ -210,7 +211,7 @@ impl NetworkBehaviour for Behaviour { _: &Multiaddr, _: &Multiaddr, ) -> Result<(), ConnectionDenied> { - self.check_limit( + check_limit( self.limits.max_pending_incoming, self.pending_inbound_connections.len(), Kind::PendingIncoming, @@ -230,12 +231,12 @@ impl NetworkBehaviour for Behaviour { ) -> Result, ConnectionDenied> { self.pending_inbound_connections.remove(&connection_id); - self.check_limit( + check_limit( self.limits.max_established_incoming, self.established_inbound_connections.len(), Kind::EstablishedIncoming, )?; - self.check_limit( + check_limit( self.limits.max_established_per_peer, self.established_per_peer .get(&peer) @@ -243,7 +244,7 @@ impl NetworkBehaviour for Behaviour { .unwrap_or(0), Kind::EstablishedPerPeer, )?; - self.check_limit( + check_limit( self.limits.max_established_total, self.established_inbound_connections.len() + self.established_outbound_connections.len(), @@ -260,7 +261,7 @@ impl NetworkBehaviour for Behaviour { _: &[Multiaddr], _: Endpoint, ) -> Result, ConnectionDenied> { - self.check_limit( + check_limit( self.limits.max_pending_outgoing, self.pending_outbound_connections.len(), Kind::PendingOutgoing, @@ -280,12 +281,12 @@ impl NetworkBehaviour for Behaviour { ) -> Result, ConnectionDenied> { self.pending_outbound_connections.remove(&connection_id); - self.check_limit( + check_limit( self.limits.max_established_outgoing, self.established_outbound_connections.len(), Kind::EstablishedOutgoing, )?; - self.check_limit( + check_limit( self.limits.max_established_per_peer, self.established_per_peer .get(&peer) @@ -293,7 +294,7 @@ impl NetworkBehaviour for Behaviour { .unwrap_or(0), Kind::EstablishedPerPeer, )?; - self.check_limit( + check_limit( self.limits.max_established_total, self.established_inbound_connections.len() + self.established_outbound_connections.len(), diff --git a/misc/futures-bounded/Cargo.toml b/misc/futures-bounded/Cargo.toml index b375242bb3c..fe4328b41d9 100644 --- a/misc/futures-bounded/Cargo.toml +++ b/misc/futures-bounded/Cargo.toml @@ -17,7 +17,7 @@ futures-util = { version = "0.3.29" } futures-timer = "3.0.2" [dev-dependencies] -tokio = { version = "1.34.0", features = ["macros", "rt", "sync"] } +tokio = { version = "1.35.0", features = ["macros", "rt", "sync"] } futures = "0.3.28" [lints] diff --git a/misc/server/CHANGELOG.md b/misc/server/CHANGELOG.md index d476a8722eb..e4c5dd4a103 100644 --- a/misc/server/CHANGELOG.md +++ b/misc/server/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.12.5 + +### Added + +- Add `/wss` support. + See [PR 4937](https://github.com/libp2p/rust-libp2p/pull/4937). + ## 0.12.4 ### Added diff --git a/misc/server/Cargo.toml b/misc/server/Cargo.toml index ba848eaeadb..87bdc20b169 100644 --- a/misc/server/Cargo.toml +++ b/misc/server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-server" -version = "0.12.4" +version = "0.12.5" authors = ["Max Inden "] edition = "2021" repository = "https://github.com/libp2p/rust-libp2p" @@ -16,7 +16,7 @@ clap = { version = "4.4.10", features = ["derive"] } futures = "0.3" futures-timer = "3" hyper = { version = "0.14", features = ["server", "tcp", "http1"] } -libp2p = { workspace = true, features = ["autonat", "dns", "tokio", "noise", "tcp", "yamux", "identify", "kad", "ping", "relay", "metrics", "rsa", "macros", "quic"] } +libp2p = { workspace = true, features = ["autonat", "dns", "tokio", "noise", "tcp", "yamux", "identify", "kad", "ping", "relay", "metrics", "rsa", "macros", "quic", "websocket"] } prometheus-client = { workspace = true } serde = "1.0.193" serde_derive = "1.0.125" diff --git a/misc/server/src/main.rs b/misc/server/src/main.rs index 2349ebf6485..16e6530e946 100644 --- a/misc/server/src/main.rs +++ b/misc/server/src/main.rs @@ -82,6 +82,8 @@ async fn main() -> Result<(), Box> { )? .with_quic() .with_dns()? + .with_websocket(noise::Config::new, yamux::Config::default) + .await? .with_bandwidth_metrics(&mut metric_registry) .with_behaviour(|key| { behaviour::Behaviour::new(key.public(), opt.enable_kademlia, opt.enable_autonat) diff --git a/misc/webrtc-utils/CHANGELOG.md b/misc/webrtc-utils/CHANGELOG.md index c3485aa1dbf..6949113a377 100644 --- a/misc/webrtc-utils/CHANGELOG.md +++ b/misc/webrtc-utils/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.2.0 + +- Update to latest version of `libp2p-noise`. + See [PR 4968](https://github.com/libp2p/rust-libp2p/pull/4968). + ## 0.1.0 - Initial release. diff --git a/misc/webrtc-utils/Cargo.toml b/misc/webrtc-utils/Cargo.toml index 8ae36754d0f..7173dedae7b 100644 --- a/misc/webrtc-utils/Cargo.toml +++ b/misc/webrtc-utils/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT" name = "libp2p-webrtc-utils" repository = "https://github.com/libp2p/rust-libp2p" rust-version = { workspace = true } -version = "0.1.0" +version = "0.2.0" publish = true [dependencies] diff --git a/misc/webrtc-utils/src/noise.rs b/misc/webrtc-utils/src/noise.rs index ac2e58c9163..9180acfc1ca 100644 --- a/misc/webrtc-utils/src/noise.rs +++ b/misc/webrtc-utils/src/noise.rs @@ -27,12 +27,14 @@ use libp2p_noise as noise; use crate::fingerprint::Fingerprint; +pub use noise::Error; + pub async fn inbound( id_keys: identity::Keypair, stream: T, client_fingerprint: Fingerprint, server_fingerprint: Fingerprint, -) -> Result +) -> Result where T: AsyncRead + AsyncWrite + Unpin + Send + 'static, { @@ -54,7 +56,7 @@ pub async fn outbound( stream: T, server_fingerprint: Fingerprint, client_fingerprint: Fingerprint, -) -> Result +) -> Result where T: AsyncRead + AsyncWrite + Unpin + Send + 'static, { diff --git a/muxers/yamux/CHANGELOG.md b/muxers/yamux/CHANGELOG.md index c8534166ea6..de608b195f8 100644 --- a/muxers/yamux/CHANGELOG.md +++ b/muxers/yamux/CHANGELOG.md @@ -4,6 +4,12 @@ It does not enforce flow-control, i.e. breaks backpressure. Use `WindowUpdateMode::on_read` instead. See `yamux` crate version `v0.12.1` and [Yamux PR #177](https://github.com/libp2p/rust-yamux/pull/177). +- `yamux` `v0.13` enables auto-tuning for the Yamux stream receive window. + While preserving small buffers on low-latency and/or low-bandwidth connections, this change allows for high-latency and/or high-bandwidth connections to exhaust the available bandwidth on a single stream. + Have `libp2p-yamux` use `yamux` `v0.13` (new version) by default and fall back to `yamux` `v0.12` (old version) when setting any configuration options. + Thus default users benefit from the increased performance, while power users with custom configurations maintain the old behavior. + `libp2p-yamux` will switch over to `yamux` `v0.13` entirely with the next breaking release. + See [PR 4970](https://github.com/libp2p/rust-libp2p/pull/4970). ## 0.45.0 diff --git a/muxers/yamux/Cargo.toml b/muxers/yamux/Cargo.toml index 1456238121b..36601ae56af 100644 --- a/muxers/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -11,10 +11,12 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] +either = "1" futures = "0.3.29" libp2p-core = { workspace = true } thiserror = "1.0" -yamux = "0.12" +yamux012 = { version = "0.12.1", package = "yamux" } +yamux013 = { version = "0.13.1", package = "yamux" } tracing = "0.1.37" [dev-dependencies] diff --git a/muxers/yamux/src/lib.rs b/muxers/yamux/src/lib.rs index fc7ff430396..2b5eb52a11e 100644 --- a/muxers/yamux/src/lib.rs +++ b/muxers/yamux/src/lib.rs @@ -22,6 +22,7 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +use either::Either; use futures::{future, prelude::*, ready}; use libp2p_core::muxing::{StreamMuxer, StreamMuxerEvent}; use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade, UpgradeInfo}; @@ -34,15 +35,14 @@ use std::{ task::{Context, Poll}, }; use thiserror::Error; -use yamux::ConnectionError; /// A Yamux connection. #[derive(Debug)] pub struct Muxer { - connection: yamux::Connection, + connection: Either, yamux013::Connection>, /// Temporarily buffers inbound streams in case our node is performing backpressure on the remote. /// - /// The only way how yamux can make progress is by calling [`yamux::Connection::poll_next_inbound`]. However, the + /// The only way how yamux can make progress is by calling [`yamux013::Connection::poll_next_inbound`]. However, the /// [`StreamMuxer`] interface is designed to allow a caller to selectively make progress via /// [`StreamMuxer::poll_inbound`] and [`StreamMuxer::poll_outbound`] whilst the more general /// [`StreamMuxer::poll`] is designed to make progress on existing streams etc. @@ -65,9 +65,9 @@ where C: AsyncRead + AsyncWrite + Send + Unpin + 'static, { /// Create a new Yamux connection. - fn new(io: C, cfg: yamux::Config, mode: yamux::Mode) -> Self { + fn new(connection: Either, yamux013::Connection>) -> Self { Muxer { - connection: yamux::Connection::new(io, cfg, mode), + connection, inbound_stream_buffer: VecDeque::default(), inbound_stream_waker: None, } @@ -103,16 +103,23 @@ where mut self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll> { - let stream = ready!(self.connection.poll_new_outbound(cx).map_err(Error)?); - - Poll::Ready(Ok(Stream(stream))) + let stream = match self.connection.as_mut() { + Either::Left(c) => ready!(c.poll_new_outbound(cx)) + .map_err(|e| Error(Either::Left(e))) + .map(|s| Stream(Either::Left(s))), + Either::Right(c) => ready!(c.poll_new_outbound(cx)) + .map_err(|e| Error(Either::Right(e))) + .map(|s| Stream(Either::Right(s))), + }?; + Poll::Ready(Ok(stream)) } #[tracing::instrument(level = "trace", name = "StreamMuxer::poll_close", skip(self, cx))] fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - ready!(self.connection.poll_close(cx).map_err(Error)?); - - Poll::Ready(Ok(())) + match self.connection.as_mut() { + Either::Left(c) => c.poll_close(cx).map_err(|e| Error(Either::Left(e))), + Either::Right(c) => c.poll_close(cx).map_err(|e| Error(Either::Right(e))), + } } #[tracing::instrument(level = "trace", name = "StreamMuxer::poll", skip(self, cx))] @@ -146,7 +153,7 @@ where /// A stream produced by the yamux multiplexer. #[derive(Debug)] -pub struct Stream(yamux::Stream); +pub struct Stream(Either); impl AsyncRead for Stream { fn poll_read( @@ -154,7 +161,7 @@ impl AsyncRead for Stream { cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll> { - Pin::new(&mut self.0).poll_read(cx, buf) + either::for_both!(self.0.as_mut(), s => Pin::new(s).poll_read(cx, buf)) } fn poll_read_vectored( @@ -162,7 +169,7 @@ impl AsyncRead for Stream { cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], ) -> Poll> { - Pin::new(&mut self.0).poll_read_vectored(cx, bufs) + either::for_both!(self.0.as_mut(), s => Pin::new(s).poll_read_vectored(cx, bufs)) } } @@ -172,7 +179,7 @@ impl AsyncWrite for Stream { cx: &mut Context<'_>, buf: &[u8], ) -> Poll> { - Pin::new(&mut self.0).poll_write(cx, buf) + either::for_both!(self.0.as_mut(), s => Pin::new(s).poll_write(cx, buf)) } fn poll_write_vectored( @@ -180,15 +187,15 @@ impl AsyncWrite for Stream { cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll> { - Pin::new(&mut self.0).poll_write_vectored(cx, bufs) + either::for_both!(self.0.as_mut(), s => Pin::new(s).poll_write_vectored(cx, bufs)) } fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - Pin::new(&mut self.0).poll_flush(cx) + either::for_both!(self.0.as_mut(), s => Pin::new(s).poll_flush(cx)) } fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - Pin::new(&mut self.0).poll_close(cx) + either::for_both!(self.0.as_mut(), s => Pin::new(s).poll_close(cx)) } } @@ -197,11 +204,16 @@ where C: AsyncRead + AsyncWrite + Unpin + 'static, { fn poll_inner(&mut self, cx: &mut Context<'_>) -> Poll> { - let stream = ready!(self.connection.poll_next_inbound(cx)) - .transpose() - .map_err(Error)? - .map(Stream) - .ok_or(Error(ConnectionError::Closed))?; + let stream = match self.connection.as_mut() { + Either::Left(c) => ready!(c.poll_next_inbound(cx)) + .ok_or(Error(Either::Left(yamux012::ConnectionError::Closed)))? + .map_err(|e| Error(Either::Left(e))) + .map(|s| Stream(Either::Left(s)))?, + Either::Right(c) => ready!(c.poll_next_inbound(cx)) + .ok_or(Error(Either::Right(yamux013::ConnectionError::Closed)))? + .map_err(|e| Error(Either::Right(e))) + .map(|s| Stream(Either::Right(s)))?, + }; Poll::Ready(Ok(stream)) } @@ -209,14 +221,33 @@ where /// The yamux configuration. #[derive(Debug, Clone)] -pub struct Config { - inner: yamux::Config, - mode: Option, +pub struct Config(Either); + +impl Default for Config { + fn default() -> Self { + Self(Either::Right(Config013::default())) + } +} + +#[derive(Debug, Clone)] +struct Config012 { + inner: yamux012::Config, + mode: Option, +} + +impl Default for Config012 { + fn default() -> Self { + let mut inner = yamux012::Config::default(); + // For conformity with mplex, read-after-close on a multiplexed + // connection is never permitted and not configurable. + inner.set_read_after_close(false); + Self { inner, mode: None } + } } /// The window update mode determines when window updates are /// sent to the remote, giving it new credit to send more data. -pub struct WindowUpdateMode(yamux::WindowUpdateMode); +pub struct WindowUpdateMode(yamux012::WindowUpdateMode); impl WindowUpdateMode { /// The window update mode whereby the remote is given @@ -234,7 +265,7 @@ impl WindowUpdateMode { #[deprecated(note = "Use `WindowUpdateMode::on_read` instead.")] pub fn on_receive() -> Self { #[allow(deprecated)] - WindowUpdateMode(yamux::WindowUpdateMode::OnReceive) + WindowUpdateMode(yamux012::WindowUpdateMode::OnReceive) } /// The window update mode whereby the remote is given new @@ -252,62 +283,71 @@ impl WindowUpdateMode { /// > **Note**: With this strategy, there is usually no point in the /// > receive buffer being larger than the window size. pub fn on_read() -> Self { - WindowUpdateMode(yamux::WindowUpdateMode::OnRead) + WindowUpdateMode(yamux012::WindowUpdateMode::OnRead) } } impl Config { /// Creates a new `YamuxConfig` in client mode, regardless of whether /// it will be used for an inbound or outbound upgrade. + #[deprecated(note = "Will be removed with the next breaking release.")] pub fn client() -> Self { - Self { - mode: Some(yamux::Mode::Client), + Self(Either::Left(Config012 { + mode: Some(yamux012::Mode::Client), ..Default::default() - } + })) } /// Creates a new `YamuxConfig` in server mode, regardless of whether /// it will be used for an inbound or outbound upgrade. + #[deprecated(note = "Will be removed with the next breaking release.")] pub fn server() -> Self { - Self { - mode: Some(yamux::Mode::Server), + Self(Either::Left(Config012 { + mode: Some(yamux012::Mode::Server), ..Default::default() - } + })) } /// Sets the size (in bytes) of the receive window per substream. + #[deprecated( + note = "Will be replaced in the next breaking release with a connection receive window size limit." + )] pub fn set_receive_window_size(&mut self, num_bytes: u32) -> &mut Self { - self.inner.set_receive_window(num_bytes); - self + self.set(|cfg| cfg.set_receive_window(num_bytes)) } /// Sets the maximum size (in bytes) of the receive buffer per substream. + #[deprecated(note = "Will be removed with the next breaking release.")] pub fn set_max_buffer_size(&mut self, num_bytes: usize) -> &mut Self { - self.inner.set_max_buffer_size(num_bytes); - self + self.set(|cfg| cfg.set_max_buffer_size(num_bytes)) } /// Sets the maximum number of concurrent substreams. pub fn set_max_num_streams(&mut self, num_streams: usize) -> &mut Self { - self.inner.set_max_num_streams(num_streams); - self + self.set(|cfg| cfg.set_max_num_streams(num_streams)) } /// Sets the window update mode that determines when the remote /// is given new credit for sending more data. + #[deprecated( + note = "`WindowUpdate::OnRead` is the default. `WindowUpdate::OnReceive` breaks backpressure, is thus not recommended, and will be removed in the next breaking release. Thus this method becomes obsolete and will be removed with the next breaking release." + )] pub fn set_window_update_mode(&mut self, mode: WindowUpdateMode) -> &mut Self { - self.inner.set_window_update_mode(mode.0); - self + self.set(|cfg| cfg.set_window_update_mode(mode.0)) } -} -impl Default for Config { - fn default() -> Self { - let mut inner = yamux::Config::default(); - // For conformity with mplex, read-after-close on a multiplexed - // connection is never permitted and not configurable. - inner.set_read_after_close(false); - Config { inner, mode: None } + fn set(&mut self, f: impl FnOnce(&mut yamux012::Config) -> &mut yamux012::Config) -> &mut Self { + let cfg012 = match self.0.as_mut() { + Either::Left(c) => &mut c.inner, + Either::Right(_) => { + self.0 = Either::Left(Config012::default()); + &mut self.0.as_mut().unwrap_left().inner + } + }; + + f(cfg012); + + self } } @@ -329,8 +369,18 @@ where type Future = future::Ready>; fn upgrade_inbound(self, io: C, _: Self::Info) -> Self::Future { - let mode = self.mode.unwrap_or(yamux::Mode::Server); - future::ready(Ok(Muxer::new(io, self.inner, mode))) + let connection = match self.0 { + Either::Left(Config012 { inner, mode }) => Either::Left(yamux012::Connection::new( + io, + inner, + mode.unwrap_or(yamux012::Mode::Server), + )), + Either::Right(Config013(cfg)) => { + Either::Right(yamux013::Connection::new(io, cfg, yamux013::Mode::Server)) + } + }; + + future::ready(Ok(Muxer::new(connection))) } } @@ -343,21 +393,69 @@ where type Future = future::Ready>; fn upgrade_outbound(self, io: C, _: Self::Info) -> Self::Future { - let mode = self.mode.unwrap_or(yamux::Mode::Client); - future::ready(Ok(Muxer::new(io, self.inner, mode))) + let connection = match self.0 { + Either::Left(Config012 { inner, mode }) => Either::Left(yamux012::Connection::new( + io, + inner, + mode.unwrap_or(yamux012::Mode::Client), + )), + Either::Right(Config013(cfg)) => { + Either::Right(yamux013::Connection::new(io, cfg, yamux013::Mode::Client)) + } + }; + + future::ready(Ok(Muxer::new(connection))) + } +} + +#[derive(Debug, Clone)] +struct Config013(yamux013::Config); + +impl Default for Config013 { + fn default() -> Self { + let mut cfg = yamux013::Config::default(); + // For conformity with mplex, read-after-close on a multiplexed + // connection is never permitted and not configurable. + cfg.set_read_after_close(false); + Self(cfg) } } /// The Yamux [`StreamMuxer`] error type. #[derive(Debug, Error)] #[error(transparent)] -pub struct Error(yamux::ConnectionError); +pub struct Error(Either); impl From for io::Error { fn from(err: Error) -> Self { match err.0 { - yamux::ConnectionError::Io(e) => e, - e => io::Error::new(io::ErrorKind::Other, e), + Either::Left(err) => match err { + yamux012::ConnectionError::Io(e) => e, + e => io::Error::new(io::ErrorKind::Other, e), + }, + Either::Right(err) => match err { + yamux013::ConnectionError::Io(e) => e, + e => io::Error::new(io::ErrorKind::Other, e), + }, } } } + +#[cfg(test)] +mod test { + use super::*; + #[test] + fn config_set_switches_to_v012() { + // By default we use yamux v0.13. Thus we provide the benefits of yamux v0.13 to all users + // that do not depend on any of the behaviors (i.e. configuration options) of v0.12. + let mut cfg = Config::default(); + assert!(matches!( + cfg, + Config(Either::Right(Config013(yamux013::Config { .. }))) + )); + + // In case a user makes any configurations, use yamux v0.12 instead. + cfg.set_max_num_streams(42); + assert!(matches!(cfg, Config(Either::Left(Config012 { .. })))); + } +} diff --git a/protocols/autonat/src/behaviour.rs b/protocols/autonat/src/behaviour.rs index 0b80a079c0f..e95163ab23f 100644 --- a/protocols/autonat/src/behaviour.rs +++ b/protocols/autonat/src/behaviour.rs @@ -35,12 +35,9 @@ use libp2p_request_response::{ self as request_response, InboundRequestId, OutboundRequestId, ProtocolSupport, ResponseChannel, }; use libp2p_swarm::{ - behaviour::{ - AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, ExpiredListenAddr, - ExternalAddrExpired, FromSwarm, - }, - ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, NewExternalAddrCandidate, - THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}, + ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, THandler, THandlerInEvent, + THandlerOutEvent, ToSwarm, }; use std::{ collections::{HashMap, HashSet, VecDeque}, @@ -363,18 +360,10 @@ impl Behaviour { ConnectionClosed { peer_id, connection_id, - endpoint, remaining_established, + .. }: ConnectionClosed, ) { - self.inner - .on_swarm_event(FromSwarm::ConnectionClosed(ConnectionClosed { - peer_id, - connection_id, - endpoint, - remaining_established, - })); - if remaining_established == 0 { self.connected.remove(&peer_id); } else { @@ -386,20 +375,7 @@ impl Behaviour { } } - fn on_dial_failure( - &mut self, - DialFailure { - peer_id, - connection_id, - error, - }: DialFailure, - ) { - self.inner - .on_swarm_event(FromSwarm::DialFailure(DialFailure { - peer_id, - connection_id, - error, - })); + fn on_dial_failure(&mut self, DialFailure { peer_id, error, .. }: DialFailure) { if let Some(event) = self.as_server().on_outbound_dial_error(peer_id, error) { self.pending_actions .push_back(ToSwarm::GenerateEvent(Event::InboundProbe(event))); @@ -542,57 +518,25 @@ impl NetworkBehaviour for Behaviour { fn on_swarm_event(&mut self, event: FromSwarm) { self.listen_addresses.on_swarm_event(&event); + self.inner.on_swarm_event(event); match event { - FromSwarm::ConnectionEstablished(connection_established) => { - self.inner - .on_swarm_event(FromSwarm::ConnectionEstablished(connection_established)); - self.on_connection_established(connection_established) - } - FromSwarm::ConnectionClosed(connection_closed) => { - self.on_connection_closed(connection_closed) - } - FromSwarm::DialFailure(dial_failure) => self.on_dial_failure(dial_failure), - FromSwarm::AddressChange(address_change) => { - self.inner - .on_swarm_event(FromSwarm::AddressChange(address_change)); - self.on_address_change(address_change) - } - listen_addr @ FromSwarm::NewListenAddr(_) => { - self.inner.on_swarm_event(listen_addr); + FromSwarm::ConnectionEstablished(e) => self.on_connection_established(e), + FromSwarm::ConnectionClosed(e) => self.on_connection_closed(e), + FromSwarm::DialFailure(e) => self.on_dial_failure(e), + FromSwarm::AddressChange(e) => self.on_address_change(e), + FromSwarm::NewListenAddr(_) => { self.as_client().on_new_address(); } - FromSwarm::ExpiredListenAddr(ExpiredListenAddr { listener_id, addr }) => { - self.inner - .on_swarm_event(FromSwarm::ExpiredListenAddr(ExpiredListenAddr { - listener_id, - addr, - })); - self.as_client().on_expired_address(addr); - } - FromSwarm::ExternalAddrExpired(ExternalAddrExpired { addr }) => { - self.inner - .on_swarm_event(FromSwarm::ExternalAddrExpired(ExternalAddrExpired { addr })); - self.as_client().on_expired_address(addr); - } - FromSwarm::NewExternalAddrCandidate(NewExternalAddrCandidate { addr }) => { - self.inner - .on_swarm_event(FromSwarm::NewExternalAddrCandidate( - NewExternalAddrCandidate { addr }, - )); - self.probe_address(addr.to_owned()); - } - listen_failure @ FromSwarm::ListenFailure(_) => { - self.inner.on_swarm_event(listen_failure) + FromSwarm::ExpiredListenAddr(e) => { + self.as_client().on_expired_address(e.addr); } - new_listener @ FromSwarm::NewListener(_) => self.inner.on_swarm_event(new_listener), - listener_error @ FromSwarm::ListenerError(_) => { - self.inner.on_swarm_event(listener_error) + FromSwarm::ExternalAddrExpired(e) => { + self.as_client().on_expired_address(e.addr); } - listener_closed @ FromSwarm::ListenerClosed(_) => { - self.inner.on_swarm_event(listener_closed) + FromSwarm::NewExternalAddrCandidate(e) => { + self.probe_address(e.addr.to_owned()); } - confirmed @ FromSwarm::ExternalAddrConfirmed(_) => self.inner.on_swarm_event(confirmed), _ => {} } } diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 4740e4b1f95..b27a6943659 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.45.3 + +- The progress of the close query iterator shall be decided by ANY of the new peers. + See [PR 4932](https://github.com/libp2p/rust-libp2p/pull/4932). + ## 0.45.2 - Ensure `Multiaddr` handled and returned by `Behaviour` are `/p2p` terminated. diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 1e4c788cf00..f4ad83972b4 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-kad" edition = "2021" rust-version = { workspace = true } description = "Kademlia protocol for libp2p" -version = "0.45.2" +version = "0.45.3" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 318261d8d21..5e7c2e21b8b 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -60,7 +60,8 @@ pub struct Handler { next_connec_unique_id: UniqueConnecId, /// List of active outbound streams. - outbound_substreams: futures_bounded::FuturesMap>>, + outbound_substreams: + futures_bounded::FuturesTupleSet>, QueryId>, /// Contains one [`oneshot::Sender`] per outbound stream that we have requested. pending_streams: @@ -453,7 +454,7 @@ impl Handler { remote_peer_id, next_connec_unique_id: UniqueConnecId(0), inbound_substreams: Default::default(), - outbound_substreams: futures_bounded::FuturesMap::new( + outbound_substreams: futures_bounded::FuturesTupleSet::new( Duration::from_secs(10), MAX_NUM_STREAMS, ), @@ -552,32 +553,36 @@ impl Handler { let (sender, receiver) = oneshot::channel(); self.pending_streams.push_back(sender); - let result = self.outbound_substreams.try_push(id, async move { - let mut stream = receiver - .await - .map_err(|_| io::Error::from(io::ErrorKind::BrokenPipe))? - .map_err(|e| match e { - StreamUpgradeError::Timeout => io::ErrorKind::TimedOut.into(), - StreamUpgradeError::Apply(e) => e, - StreamUpgradeError::NegotiationFailed => { - io::Error::new(io::ErrorKind::ConnectionRefused, "protocol not supported") - } - StreamUpgradeError::Io(e) => e, - })?; - - let has_answer = !matches!(msg, KadRequestMsg::AddProvider { .. }); - - stream.send(msg).await?; - stream.close().await?; - - if !has_answer { - return Ok(None); - } + let result = self.outbound_substreams.try_push( + async move { + let mut stream = receiver + .await + .map_err(|_| io::Error::from(io::ErrorKind::BrokenPipe))? + .map_err(|e| match e { + StreamUpgradeError::Timeout => io::ErrorKind::TimedOut.into(), + StreamUpgradeError::Apply(e) => e, + StreamUpgradeError::NegotiationFailed => io::Error::new( + io::ErrorKind::ConnectionRefused, + "protocol not supported", + ), + StreamUpgradeError::Io(e) => e, + })?; + + let has_answer = !matches!(msg, KadRequestMsg::AddProvider { .. }); + + stream.send(msg).await?; + stream.close().await?; + + if !has_answer { + return Ok(None); + } - let msg = stream.next().await.ok_or(io::ErrorKind::UnexpectedEof)??; + let msg = stream.next().await.ok_or(io::ErrorKind::UnexpectedEof)??; - Ok(Some(msg)) - }); + Ok(Some(msg)) + }, + id, + ); debug_assert!( result.is_ok(), @@ -728,15 +733,15 @@ impl ConnectionHandler for Handler { } match self.outbound_substreams.poll_unpin(cx) { - Poll::Ready((query, Ok(Ok(Some(response))))) => { + Poll::Ready((Ok(Ok(Some(response))), query_id)) => { return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour( - process_kad_response(response, query), + process_kad_response(response, query_id), )) } - Poll::Ready((_, Ok(Ok(None)))) => { + Poll::Ready((Ok(Ok(None)), _)) => { continue; } - Poll::Ready((query_id, Ok(Err(e)))) => { + Poll::Ready((Ok(Err(e)), query_id)) => { return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour( HandlerEvent::QueryError { error: HandlerQueryErr::Io(e), @@ -744,7 +749,7 @@ impl ConnectionHandler for Handler { }, )) } - Poll::Ready((query_id, Err(_timeout))) => { + Poll::Ready((Err(_timeout), query_id)) => { return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour( HandlerEvent::QueryError { error: HandlerQueryErr::Io(io::ErrorKind::TimedOut.into()), diff --git a/protocols/kad/src/query/peers/closest.rs b/protocols/kad/src/query/peers/closest.rs index 01155b7f010..dc913f1bbca 100644 --- a/protocols/kad/src/query/peers/closest.rs +++ b/protocols/kad/src/query/peers/closest.rs @@ -175,10 +175,14 @@ impl ClosestPeersIter { }, } - let num_closest = self.closest_peers.len(); - let mut progress = false; - // Incorporate the reported closer peers into the iterator. + // + // The iterator makes progress if: + // 1, the iterator did not yet accumulate enough closest peers. + // OR + // 2, any of the new peers is closer to the target than any peer seen so far + // (i.e. is the first entry after being incorporated) + let mut progress = self.closest_peers.len() < self.config.num_results.get(); for peer in closer_peers { let key = peer.into(); let distance = self.target.distance(&key); @@ -187,11 +191,8 @@ impl ClosestPeersIter { state: PeerState::NotContacted, }; self.closest_peers.entry(distance).or_insert(peer); - // The iterator makes progress if the new peer is either closer to the target - // than any peer seen so far (i.e. is the first entry), or the iterator did - // not yet accumulate enough closest peers. - progress = self.closest_peers.keys().next() == Some(&distance) - || num_closest < self.config.num_results.get(); + + progress = self.closest_peers.keys().next() == Some(&distance) || progress; } // Update the iterator state. diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index 97e7204cd63..5561575bf2a 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -22,7 +22,7 @@ libp2p-identity = { workspace = true } rand = "0.8.3" smallvec = "1.11.2" socket2 = { version = "0.5.5", features = ["all"] } -tokio = { version = "1.34", default-features = false, features = ["net", "time"], optional = true} +tokio = { version = "1.35", default-features = false, features = ["net", "time"], optional = true} tracing = "0.1.37" hickory-proto = { version = "0.24.0", default-features = false, features = ["mdns"] } void = "1.0.2" @@ -37,7 +37,7 @@ libp2p-noise = { workspace = true } libp2p-swarm = { workspace = true, features = ["tokio", "async-std"] } libp2p-tcp = { workspace = true, features = ["tokio", "async-io"] } libp2p-yamux = { workspace = true } -tokio = { version = "1.34", default-features = false, features = ["macros", "rt", "rt-multi-thread", "time"] } +tokio = { version = "1.35", default-features = false, features = ["macros", "rt", "rt-multi-thread", "time"] } libp2p-swarm-test = { path = "../../swarm-test" } tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index c2fc146f231..cca7631d67d 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -31,7 +31,7 @@ serde_json = "1.0" thiserror = "1.0" tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } -tokio = { version = "1.34", default-features = false, features = ["macros", "rt", "rt-multi-thread"] } +tokio = { version = "1.35", default-features = false, features = ["macros", "rt", "rt-multi-thread"] } void = "1" [dev-dependencies] diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index 4dfd77e1eba..edc0ec8a38a 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -37,7 +37,7 @@ libp2p-swarm-test = { path = "../../swarm-test" } libp2p-tcp = { workspace = true, features = ["tokio"] } libp2p-yamux = { workspace = true } rand = "0.8" -tokio = { version = "1.34", features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs", "net" ] } +tokio = { version = "1.35", features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs", "net" ] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 78aa42043cd..667c71e20e3 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -215,20 +215,12 @@ impl NetworkBehaviour for Behaviour { }) => { continue; } - ToSwarm::Dial { .. } - | ToSwarm::ListenOn { .. } - | ToSwarm::RemoveListener { .. } - | ToSwarm::NotifyHandler { .. } - | ToSwarm::NewExternalAddrCandidate(_) - | ToSwarm::ExternalAddrConfirmed(_) - | ToSwarm::ExternalAddrExpired(_) - | ToSwarm::CloseConnection { .. } => { - let new_to_swarm = to_swarm + other => { + let new_to_swarm = other .map_out(|_| unreachable!("we manually map `GenerateEvent` variants")); return Poll::Ready(new_to_swarm); } - _ => {} }; } diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index 30fc700da3c..d53ff479ee2 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.26.1 + +- Derive `PartialOrd` and `Ord` for `{Out,In}boundRequestId`. + See [PR 4956](https://github.com/libp2p/rust-libp2p/pull/4956). + ## 0.26.0 - Remove `request_response::Config::set_connection_keep_alive` in favor of `SwarmBuilder::idle_connection_timeout`. diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 2c7692fb9b4..6da25e24862 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-request-response" edition = "2021" rust-version = { workspace = true } description = "Generic Request/Response Protocols" -version = "0.26.0" +version = "0.26.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 824839ebac8..fc68bd6cf1f 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -274,7 +274,7 @@ impl ResponseChannel { /// /// Note: [`InboundRequestId`]'s uniqueness is only guaranteed between /// inbound requests of the same originating [`Behaviour`]. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct InboundRequestId(u64); impl fmt::Display for InboundRequestId { @@ -287,7 +287,7 @@ impl fmt::Display for InboundRequestId { /// /// Note: [`OutboundRequestId`]'s uniqueness is only guaranteed between /// outbound requests of the same originating [`Behaviour`]. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct OutboundRequestId(u64); impl fmt::Display for OutboundRequestId { diff --git a/protocols/upnp/Cargo.toml b/protocols/upnp/Cargo.toml index f00c80aabb3..2353463bfaa 100644 --- a/protocols/upnp/Cargo.toml +++ b/protocols/upnp/Cargo.toml @@ -16,7 +16,7 @@ futures-timer = "3.0.2" igd-next = "0.14.2" libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } -tokio = { version = "1.34", default-features = false, features = ["rt"], optional = true } +tokio = { version = "1.35", default-features = false, features = ["rt"], optional = true } tracing = "0.1.37" void = "1.0.2" diff --git a/swarm-derive/CHANGELOG.md b/swarm-derive/CHANGELOG.md index 08adba00cdb..85ea1a46048 100644 --- a/swarm-derive/CHANGELOG.md +++ b/swarm-derive/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.34.1 + +- Always forward all variants of `FromSwarm`. + See [PR 4825](https://github.com/libp2p/rust-libp2p/pull/4825). + ## 0.34.0 - Adapt to interface changes in `libp2p-swarm`. diff --git a/swarm-derive/Cargo.toml b/swarm-derive/Cargo.toml index 11cc4b6a12a..9259d63c4ed 100644 --- a/swarm-derive/Cargo.toml +++ b/swarm-derive/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-swarm-derive" edition = "2021" rust-version = { workspace = true } description = "Procedural macros of libp2p-swarm" -version = "0.34.0" +version = "0.34.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -16,7 +16,7 @@ proc-macro = true [dependencies] heck = "0.4" quote = "1.0" -syn = { version = "2.0.39", default-features = false, features = ["clone-impls", "derive", "parsing", "printing", "proc-macro"] } +syn = { version = "2.0.40", default-features = false, features = ["clone-impls", "derive", "parsing", "printing", "proc-macro"] } proc-macro2 = "1.0" # Passing arguments to the docsrs builder in order to properly document cfg's. diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index 514975390b0..5c8ce93966d 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -71,19 +71,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result syn::Result quote! { - self.#i.on_swarm_event(#from_swarm::ConnectionEstablished(#connection_established { - peer_id, - connection_id, - endpoint, - failed_addresses, - other_established, - })); + self.#i.on_swarm_event(event); }, None => quote! { - self.#field_n.on_swarm_event(#from_swarm::ConnectionEstablished(#connection_established { - peer_id, - connection_id, - endpoint, - failed_addresses, - other_established, - })); - }, - }) - }; - - // Build the list of statements to put in the body of `on_swarm_event()` - // for the `FromSwarm::AddressChange variant`. - let on_address_change_stmts = { - data_struct - .fields - .iter() - .enumerate() - .map(|(field_n, field)| match field.ident { - Some(ref i) => quote! { - self.#i.on_swarm_event(#from_swarm::AddressChange(#address_change { - peer_id, - connection_id, - old, - new, - })); - }, - None => quote! { - self.#field_n.on_swarm_event(#from_swarm::AddressChange(#address_change { - peer_id, - connection_id, - old, - new, - })); - }, - }) - }; - - // Build the list of statements to put in the body of `on_swarm_event()` - // for the `FromSwarm::ConnectionClosed` variant. - let on_connection_closed_stmts = { - data_struct - .fields - .iter() - .rev() - .enumerate() - .map(|(enum_n, field)| { - let inject = match field.ident { - Some(ref i) => quote! { - self.#i.on_swarm_event(#from_swarm::ConnectionClosed(#connection_closed { - peer_id, - connection_id, - endpoint, - remaining_established, - })); - }, - None => quote! { - self.#enum_n.on_swarm_event(#from_swarm::ConnectionClosed(#connection_closed { - peer_id, - connection_id, - endpoint, - remaining_established, - })); - }, - }; - - quote! { - #inject; - } - }) - }; - - // Build the list of statements to put in the body of `on_swarm_event()` - // for the `FromSwarm::DialFailure` variant. - let on_dial_failure_stmts = data_struct - .fields - .iter() - .enumerate() - .map(|(enum_n, field)| match field.ident { - Some(ref i) => quote! { - self.#i.on_swarm_event(#from_swarm::DialFailure(#dial_failure { - peer_id, - connection_id, - error, - })); - }, - None => quote! { - self.#enum_n.on_swarm_event(#from_swarm::DialFailure(#dial_failure { - peer_id, - connection_id, - error, - })); - }, - }); - - // Build the list of statements to put in the body of `on_swarm_event()` - // for the `FromSwarm::ListenFailure` variant. - let on_listen_failure_stmts = data_struct - .fields - .iter() - .enumerate() - .map(|(enum_n, field)| match field.ident { - Some(ref i) => quote! { - self.#i.on_swarm_event(#from_swarm::ListenFailure(#listen_failure { - local_addr, - send_back_addr, - connection_id, - error - })); - }, - None => quote! { - self.#enum_n.on_swarm_event(#from_swarm::ListenFailure(#listen_failure { - local_addr, - send_back_addr, - connection_id, - error - })); - }, - }); - - // Build the list of statements to put in the body of `on_swarm_event()` - // for the `FromSwarm::NewListener` variant. - let on_new_listener_stmts = { - data_struct - .fields - .iter() - .enumerate() - .map(|(field_n, field)| match field.ident { - Some(ref i) => quote! { - self.#i.on_swarm_event(#from_swarm::NewListener(#new_listener { - listener_id, - })); - }, - None => quote! { - self.#field_n.on_swarm_event(#from_swarm::NewListener(#new_listener { - listener_id, - })); - }, - }) - }; - - // Build the list of statements to put in the body of `on_swarm_event()` - // for the `FromSwarm::NewListenAddr` variant. - let on_new_listen_addr_stmts = { - data_struct - .fields - .iter() - .enumerate() - .map(|(field_n, field)| match field.ident { - Some(ref i) => quote! { - self.#i.on_swarm_event(#from_swarm::NewListenAddr(#new_listen_addr { - listener_id, - addr, - })); - }, - None => quote! { - self.#field_n.on_swarm_event(#from_swarm::NewListenAddr(#new_listen_addr { - listener_id, - addr, - })); - }, - }) - }; - - // Build the list of statements to put in the body of `on_swarm_event()` - // for the `FromSwarm::ExpiredListenAddr` variant. - let on_expired_listen_addr_stmts = { - data_struct - .fields - .iter() - .enumerate() - .map(|(field_n, field)| match field.ident { - Some(ref i) => quote! { - self.#i.on_swarm_event(#from_swarm::ExpiredListenAddr(#expired_listen_addr { - listener_id, - addr, - })); - }, - None => quote! { - self.#field_n.on_swarm_event(#from_swarm::ExpiredListenAddr(#expired_listen_addr { - listener_id, - addr, - })); - }, - }) - }; - - // Build the list of statements to put in the body of `on_swarm_event()` - // for the `FromSwarm::NewExternalAddr` variant. - let on_new_external_addr_candidate_stmts = { - data_struct - .fields - .iter() - .enumerate() - .map(|(field_n, field)| match field.ident { - Some(ref i) => quote! { - self.#i.on_swarm_event(#from_swarm::NewExternalAddrCandidate(#new_external_addr_candidate { - addr, - })); - }, - None => quote! { - self.#field_n.on_swarm_event(#from_swarm::NewExternalAddrCandidate(#new_external_addr_candidate { - addr, - })); - }, - }) - }; - - // Build the list of statements to put in the body of `on_swarm_event()` - // for the `FromSwarm::ExternalAddrExpired` variant. - let on_external_addr_expired_stmts = { - data_struct - .fields - .iter() - .enumerate() - .map(|(field_n, field)| match field.ident { - Some(ref i) => quote! { - self.#i.on_swarm_event(#from_swarm::ExternalAddrExpired(#external_addr_expired { - addr, - })); - }, - None => quote! { - self.#field_n.on_swarm_event(#from_swarm::ExternalAddrExpired(#external_addr_expired { - addr, - })); - }, - }) - }; - - // Build the list of statements to put in the body of `on_swarm_event()` - // for the `FromSwarm::ExternalAddrConfirmed` variant. - let on_external_addr_confirmed_stmts = { - data_struct - .fields - .iter() - .enumerate() - .map(|(field_n, field)| match field.ident { - Some(ref i) => quote! { - self.#i.on_swarm_event(#from_swarm::ExternalAddrConfirmed(#external_addr_confirmed { - addr, - })); - }, - None => quote! { - self.#field_n.on_swarm_event(#from_swarm::ExternalAddrConfirmed(#external_addr_confirmed { - addr, - })); - }, - }) - }; - - // Build the list of statements to put in the body of `on_swarm_event()` - // for the `FromSwarm::ListenerError` variant. - let on_listener_error_stmts = { - data_struct - .fields - .iter() - .enumerate() - .map(|(field_n, field)| match field.ident { - Some(ref i) => quote! { - self.#i.on_swarm_event(#from_swarm::ListenerError(#listener_error { - listener_id, - err, - })); - }, - None => quote! { - self.#field_n.on_swarm_event(#from_swarm::ListenerError(#listener_error { - listener_id, - err, - })); - }, - }) - }; - - // Build the list of statements to put in the body of `on_swarm_event()` - // for the `FromSwarm::ListenerClosed` variant. - let on_listener_closed_stmts = { - data_struct - .fields - .iter() - .enumerate() - .map(|(field_n, field)| match field.ident { - Some(ref i) => quote! { - self.#i.on_swarm_event(#from_swarm::ListenerClosed(#listener_closed { - listener_id, - reason, - })); - }, - None => quote! { - self.#field_n.on_swarm_event(#from_swarm::ListenerClosed(#listener_closed { - listener_id, - reason, - })); + self.#field_n.on_swarm_event(event); }, }) }; @@ -792,48 +481,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result { #(#on_connection_established_stmts)* } - #from_swarm::AddressChange( - #address_change { peer_id, connection_id, old, new }) - => { #(#on_address_change_stmts)* } - #from_swarm::ConnectionClosed( - #connection_closed { peer_id, connection_id, endpoint, remaining_established }) - => { #(#on_connection_closed_stmts)* } - #from_swarm::DialFailure( - #dial_failure { peer_id, connection_id, error }) - => { #(#on_dial_failure_stmts)* } - #from_swarm::ListenFailure( - #listen_failure { local_addr, send_back_addr, connection_id, error }) - => { #(#on_listen_failure_stmts)* } - #from_swarm::NewListener( - #new_listener { listener_id }) - => { #(#on_new_listener_stmts)* } - #from_swarm::NewListenAddr( - #new_listen_addr { listener_id, addr }) - => { #(#on_new_listen_addr_stmts)* } - #from_swarm::ExpiredListenAddr( - #expired_listen_addr { listener_id, addr }) - => { #(#on_expired_listen_addr_stmts)* } - #from_swarm::NewExternalAddrCandidate( - #new_external_addr_candidate { addr }) - => { #(#on_new_external_addr_candidate_stmts)* } - #from_swarm::ExternalAddrExpired( - #external_addr_expired { addr }) - => { #(#on_external_addr_expired_stmts)* } - #from_swarm::ExternalAddrConfirmed( - #external_addr_confirmed { addr }) - => { #(#on_external_addr_confirmed_stmts)* } - #from_swarm::ListenerError( - #listener_error { listener_id, err }) - => { #(#on_listener_error_stmts)* } - #from_swarm::ListenerClosed( - #listener_closed { listener_id, reason }) - => { #(#on_listener_closed_stmts)* } - _ => {} - } + #(#on_swarm_event_stmts)* } } }; diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 48cafee6ced..65dce4b002a 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.44.1 + +- Implement `Clone` & `Copy` for `FromSwarm. + This makes it easier to forward these events when wrapping other behaviours. + See [PR 4825](https://github.com/libp2p/rust-libp2p/pull/4825). + ## 0.44.0 - Add `#[non_exhaustive]` to `FromSwarm`, `ToSwarm`, `SwarmEvent`, `ConnectionHandlerEvent`, `ConnectionEvent`. diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 3b706df6d2b..0e87f30979d 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-swarm" edition = "2021" rust-version = { workspace = true } description = "The libp2p swarm" -version = "0.44.0" +version = "0.44.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -21,16 +21,16 @@ libp2p-core = { workspace = true } libp2p-identity = { workspace = true } libp2p-swarm-derive = { workspace = true, optional = true } multistream-select = { workspace = true } -once_cell = "1.18.0" +once_cell = "1.19.0" rand = "0.8" smallvec = "1.11.2" tracing = "0.1.37" void = "1" -wasm-bindgen-futures = { version = "0.4.38", optional = true } +wasm-bindgen-futures = { version = "0.4.39", optional = true } [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] async-std = { version = "1.6.2", optional = true } -tokio = { version = "1.34", features = ["rt"], optional = true } +tokio = { version = "1.35", features = ["rt"], optional = true } [features] macros = ["dep:libp2p-swarm-derive"] @@ -52,9 +52,9 @@ libp2p-swarm-test = { path = "../swarm-test" } # Using `pat libp2p-yamux = { path = "../muxers/yamux" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. quickcheck = { workspace = true } void = "1" -once_cell = "1.18.0" +once_cell = "1.19.0" trybuild = "1.0.85" -tokio = { version = "1.34.0", features = ["time", "rt", "macros", "rt-multi-thread"] } +tokio = { version = "1.35.0", features = ["time", "rt", "macros", "rt-multi-thread"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } [[test]] diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index c25b14e75e3..4be129a4eea 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -391,7 +391,7 @@ pub enum CloseConnection { /// Enumeration with the list of the possible events /// to pass to [`on_swarm_event`](NetworkBehaviour::on_swarm_event). -#[derive(Debug)] +#[derive(Debug, Clone, Copy)] #[non_exhaustive] pub enum FromSwarm<'a> { /// Informs the behaviour about a newly established connection to a peer. @@ -449,7 +449,7 @@ pub struct ConnectionEstablished<'a> { /// This event is always paired with an earlier /// [`FromSwarm::ConnectionEstablished`] with the same peer ID, connection ID /// and endpoint. -#[derive(Debug)] +#[derive(Debug, Clone, Copy)] pub struct ConnectionClosed<'a> { pub peer_id: PeerId, pub connection_id: ConnectionId, diff --git a/swarm/src/test.rs b/swarm/src/test.rs index 4f6adfc37b0..547277550bb 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -437,6 +437,8 @@ where } fn on_swarm_event(&mut self, event: FromSwarm) { + self.inner.on_swarm_event(event); + match event { FromSwarm::ConnectionEstablished(connection_established) => { self.on_connection_established(connection_established) @@ -444,68 +446,33 @@ where FromSwarm::ConnectionClosed(connection_closed) => { self.on_connection_closed(connection_closed) } - FromSwarm::DialFailure(DialFailure { - peer_id, - connection_id, - error, - }) => { + FromSwarm::DialFailure(DialFailure { peer_id, .. }) => { self.on_dial_failure.push(peer_id); - self.inner - .on_swarm_event(FromSwarm::DialFailure(DialFailure { - peer_id, - connection_id, - error, - })); } FromSwarm::NewListener(NewListener { listener_id }) => { self.on_new_listener.push(listener_id); - self.inner - .on_swarm_event(FromSwarm::NewListener(NewListener { listener_id })); } FromSwarm::NewListenAddr(NewListenAddr { listener_id, addr }) => { self.on_new_listen_addr.push((listener_id, addr.clone())); - self.inner - .on_swarm_event(FromSwarm::NewListenAddr(NewListenAddr { - listener_id, - addr, - })); } FromSwarm::ExpiredListenAddr(ExpiredListenAddr { listener_id, addr }) => { self.on_expired_listen_addr .push((listener_id, addr.clone())); - self.inner - .on_swarm_event(FromSwarm::ExpiredListenAddr(ExpiredListenAddr { - listener_id, - addr, - })); } FromSwarm::NewExternalAddrCandidate(NewExternalAddrCandidate { addr }) => { self.on_new_external_addr.push(addr.clone()); - self.inner - .on_swarm_event(FromSwarm::NewExternalAddrCandidate( - NewExternalAddrCandidate { addr }, - )); } FromSwarm::ExternalAddrExpired(ExternalAddrExpired { addr }) => { self.on_expired_external_addr.push(addr.clone()); - self.inner - .on_swarm_event(FromSwarm::ExternalAddrExpired(ExternalAddrExpired { addr })); } - FromSwarm::ListenerError(ListenerError { listener_id, err }) => { + FromSwarm::ListenerError(ListenerError { listener_id, .. }) => { self.on_listener_error.push(listener_id); - self.inner - .on_swarm_event(FromSwarm::ListenerError(ListenerError { listener_id, err })); } FromSwarm::ListenerClosed(ListenerClosed { listener_id, reason, }) => { self.on_listener_closed.push((listener_id, reason.is_ok())); - self.inner - .on_swarm_event(FromSwarm::ListenerClosed(ListenerClosed { - listener_id, - reason, - })); } _ => {} } diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index 772b74c7acb..d4168246b66 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -17,7 +17,7 @@ libp2p-core = { workspace = true } libp2p-identity = { workspace = true, features = ["ed25519"] } multiaddr = { workspace = true } multihash = { workspace = true } -once_cell = "1.18.0" +once_cell = "1.19.0" quick-protobuf = "0.8" rand = "0.8.3" sha2 = "0.10.8" diff --git a/transports/pnet/Cargo.toml b/transports/pnet/Cargo.toml index ab23de720e7..f598e876c09 100644 --- a/transports/pnet/Cargo.toml +++ b/transports/pnet/Cargo.toml @@ -27,7 +27,7 @@ libp2p-tcp = { workspace = true, features = ["tokio"] } libp2p-websocket = { workspace = true } libp2p-yamux = { workspace = true } quickcheck = { workspace = true } -tokio = { version = "1.34.0", features = ["full"] } +tokio = { version = "1.35.0", features = ["full"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/transports/quic/CHANGELOG.md b/transports/quic/CHANGELOG.md index 2283c41262b..3c34a1989f9 100644 --- a/transports/quic/CHANGELOG.md +++ b/transports/quic/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.10.2 + +- Change `max_idle_timeout`to 10s. + See [PR 4965](https://github.com/libp2p/rust-libp2p/pull/4965). + ## 0.10.1 - Allow disabling path MTU discovery. diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index 5f3fd5cfb43..8a1ca4287ff 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-quic" -version = "0.10.1" +version = "0.10.2" authors = ["Parity Technologies "] edition = "2021" rust-version = { workspace = true } @@ -22,7 +22,7 @@ quinn = { version = "0.10.2", default-features = false, features = ["tls-rustls" rand = "0.8.5" rustls = { version = "0.21.9", default-features = false } thiserror = "1.0.50" -tokio = { version = "1.34.0", default-features = false, features = ["net", "rt", "time"], optional = true } +tokio = { version = "1.35.0", default-features = false, features = ["net", "rt", "time"], optional = true } tracing = "0.1.37" socket2 = "0.5.5" ring = "0.16.20" @@ -46,7 +46,7 @@ libp2p-noise = { workspace = true } libp2p-tcp = { workspace = true, features = ["async-io"] } libp2p-yamux = { workspace = true } quickcheck = "1" -tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread", "time"] } +tokio = { version = "1.35.0", features = ["macros", "rt-multi-thread", "time"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } [[test]] diff --git a/transports/quic/src/config.rs b/transports/quic/src/config.rs index 4e4bb94cd7a..540f13e726b 100644 --- a/transports/quic/src/config.rs +++ b/transports/quic/src/config.rs @@ -78,9 +78,9 @@ impl Config { server_tls_config, support_draft_29: false, handshake_timeout: Duration::from_secs(5), - max_idle_timeout: 30 * 1000, + max_idle_timeout: 10 * 1000, max_concurrent_stream_limit: 256, - keep_alive_interval: Duration::from_secs(15), + keep_alive_interval: Duration::from_secs(5), max_connection_data: 15_000_000, // Ensure that one stream is not consuming the whole connection. diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 13eeb01786d..b4517cf269b 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -19,7 +19,7 @@ libc = "0.2.150" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } socket2 = { version = "0.5.5", features = ["all"] } -tokio = { version = "1.34.0", default-features = false, features = ["net"], optional = true } +tokio = { version = "1.35.0", default-features = false, features = ["net"], optional = true } tracing = "0.1.37" [features] @@ -29,7 +29,7 @@ async-io = ["dep:async-io", "if-watch/smol"] [dev-dependencies] async-std = { version = "1.6.5", features = ["attributes"] } libp2p-identity = { workspace = true, features = ["rand"] } -tokio = { version = "1.34.0", default-features = false, features = ["full"] } +tokio = { version = "1.35.0", default-features = false, features = ["full"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Passing arguments to the docsrs builder in order to properly document cfg's. diff --git a/transports/tls/Cargo.toml b/transports/tls/Cargo.toml index 5a1e4788245..2a683decec0 100644 --- a/transports/tls/Cargo.toml +++ b/transports/tls/Cargo.toml @@ -33,7 +33,7 @@ libp2p-core = { workspace = true } libp2p-identity = { workspace = true, features = ["ed25519", "rsa", "secp256k1", "ecdsa", "rand"] } libp2p-swarm = { workspace = true, features = ["tokio"] } libp2p-yamux = { workspace = true } -tokio = { version = "1.34.0", features = ["full"] } +tokio = { version = "1.35.0", features = ["full"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/transports/uds/Cargo.toml b/transports/uds/Cargo.toml index bcf7570c44f..e730bf87895 100644 --- a/transports/uds/Cargo.toml +++ b/transports/uds/Cargo.toml @@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"] async-std = { version = "1.6.2", optional = true } libp2p-core = { workspace = true } futures = "0.3.29" -tokio = { version = "1.34", default-features = false, features = ["net"], optional = true } +tokio = { version = "1.35", default-features = false, features = ["net"], optional = true } tracing = "0.1.37" [dev-dependencies] diff --git a/transports/webrtc-websys/CHANGELOG.md b/transports/webrtc-websys/CHANGELOG.md index 3cc263e2ce5..634120c53c3 100644 --- a/transports/webrtc-websys/CHANGELOG.md +++ b/transports/webrtc-websys/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.3.0-alpha + +- Bump version in order to publish a new version dependent on latest `libp2p-core`. + See [PR 4959](https://github.com/libp2p/rust-libp2p/pull/4959). +- Remove `libp2p_noise` from the public API. + See [PR 4969](https://github.com/libp2p/rust-libp2p/pull/4969). + ## 0.2.0-alpha - Rename `Error::JsError` to `Error::Js`. diff --git a/transports/webrtc-websys/Cargo.toml b/transports/webrtc-websys/Cargo.toml index 44607de30c0..34da24a3f5f 100644 --- a/transports/webrtc-websys/Cargo.toml +++ b/transports/webrtc-websys/Cargo.toml @@ -8,32 +8,24 @@ license = "MIT" name = "libp2p-webrtc-websys" repository = "https://github.com/libp2p/rust-libp2p" rust-version = { workspace = true } -version = "0.2.0-alpha" +version = "0.3.0-alpha" publish = true [dependencies] bytes = "1" futures = "0.3" -futures-timer = "3" getrandom = { version = "0.2.11", features = ["js"] } hex = "0.4.3" js-sys = { version = "0.3" } libp2p-core = { workspace = true } libp2p-identity = { workspace = true } -libp2p-noise = { workspace = true } libp2p-webrtc-utils = { workspace = true } send_wrapper = { version = "0.6.0", features = ["futures"] } -serde = { version = "1.0", features = ["derive"] } thiserror = "1" tracing = "0.1.37" wasm-bindgen = { version = "0.2.89" } -wasm-bindgen-futures = { version = "0.4.38" } -web-sys = { version = "0.3.65", features = ["Document", "Location", "MessageEvent", "Navigator", "RtcCertificate", "RtcConfiguration", "RtcDataChannel", "RtcDataChannelEvent", "RtcDataChannelInit", "RtcDataChannelState", "RtcDataChannelType", "RtcPeerConnection", "RtcSdpType", "RtcSessionDescription", "RtcSessionDescriptionInit", "Window"] } - -[dev-dependencies] -hex-literal = "0.4" -libp2p-ping = { workspace = true } -libp2p-swarm = { workspace = true, features = ["wasm-bindgen"] } +wasm-bindgen-futures = { version = "0.4.39" } +web-sys = { version = "0.3.66", features = ["Document", "Location", "MessageEvent", "Navigator", "RtcCertificate", "RtcConfiguration", "RtcDataChannel", "RtcDataChannelEvent", "RtcDataChannelInit", "RtcDataChannelState", "RtcDataChannelType", "RtcPeerConnection", "RtcSdpType", "RtcSessionDescription", "RtcSessionDescriptionInit", "Window"] } [lints] workspace = true diff --git a/transports/webrtc-websys/src/error.rs b/transports/webrtc-websys/src/error.rs index c95b1caf49b..a2df1a182ea 100644 --- a/transports/webrtc-websys/src/error.rs +++ b/transports/webrtc-websys/src/error.rs @@ -20,9 +20,14 @@ pub enum Error { Connection(String), #[error("Authentication error")] - Authentication(#[from] libp2p_noise::Error), + Authentication(#[from] AuthenticationError), } +/// New-type wrapper to hide `libp2p_noise` from the public API. +#[derive(thiserror::Error, Debug)] +#[error(transparent)] +pub struct AuthenticationError(pub(crate) libp2p_webrtc_utils::noise::Error); + impl Error { pub(crate) fn from_js_value(value: JsValue) -> Self { let s = if value.is_instance_of::() { @@ -38,7 +43,7 @@ impl Error { } } -impl std::convert::From for Error { +impl From for Error { fn from(value: JsValue) -> Self { Error::from_js_value(value) } diff --git a/transports/webrtc-websys/src/upgrade.rs b/transports/webrtc-websys/src/upgrade.rs index cc053835041..d42f2e3ae18 100644 --- a/transports/webrtc-websys/src/upgrade.rs +++ b/transports/webrtc-websys/src/upgrade.rs @@ -1,5 +1,6 @@ use super::Error; use crate::connection::RtcPeerConnection; +use crate::error::AuthenticationError; use crate::sdp; use crate::Connection; use libp2p_identity::{Keypair, PeerId}; @@ -48,7 +49,9 @@ async fn outbound_inner( tracing::trace!(?local_fingerprint); tracing::trace!(?remote_fingerprint); - let peer_id = noise::outbound(id_keys, channel, remote_fingerprint, local_fingerprint).await?; + let peer_id = noise::outbound(id_keys, channel, remote_fingerprint, local_fingerprint) + .await + .map_err(AuthenticationError)?; tracing::debug!(peer=%peer_id, "Remote peer identified"); diff --git a/transports/webrtc/CHANGELOG.md b/transports/webrtc/CHANGELOG.md index 710c2e315d9..7cc2b2b63bc 100644 --- a/transports/webrtc/CHANGELOG.md +++ b/transports/webrtc/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.7.0-alpha + +- Bump version in order to publish a new version dependent on latest `libp2p-core`. + See [PR 4959](https://github.com/libp2p/rust-libp2p/pull/4959). + ## 0.6.1-alpha - Move common dependencies to `libp2p-webrtc-utils` crate. diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index 8aa43652392..de805840683 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-webrtc" -version = "0.6.1-alpha" +version = "0.7.0-alpha" authors = ["Parity Technologies "] description = "WebRTC transport for libp2p" repository = "https://github.com/libp2p/rust-libp2p" @@ -28,7 +28,7 @@ serde = { version = "1.0", features = ["derive"] } stun = "0.5" thiserror = "1" tinytemplate = "1.2" -tokio = { version = "1.34", features = ["net"], optional = true } +tokio = { version = "1.35", features = ["net"], optional = true } tokio-util = { version = "0.7", features = ["compat"], optional = true } tracing = "0.1.37" webrtc = { version = "0.9.0", optional = true } @@ -39,7 +39,7 @@ pem = ["webrtc?/pem"] [dev-dependencies] libp2p-identity = { workspace = true, features = ["rand"] } -tokio = { version = "1.34", features = ["full"] } +tokio = { version = "1.35", features = ["full"] } quickcheck = "1.0.3" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/transports/websocket-websys/Cargo.toml b/transports/websocket-websys/Cargo.toml index b0493533e26..568bd22e20e 100644 --- a/transports/websocket-websys/Cargo.toml +++ b/transports/websocket-websys/Cargo.toml @@ -20,7 +20,7 @@ parking_lot = "0.12.1" send_wrapper = "0.6.0" thiserror = "1.0.50" wasm-bindgen = "0.2.89" -web-sys = { version = "0.3.65", features = ["BinaryType", "CloseEvent", "MessageEvent", "WebSocket", "Window", "WorkerGlobalScope"] } +web-sys = { version = "0.3.66", features = ["BinaryType", "CloseEvent", "MessageEvent", "WebSocket", "Window", "WorkerGlobalScope"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/transports/webtransport-websys/Cargo.toml b/transports/webtransport-websys/Cargo.toml index d21730e42c4..96afd159ff8 100644 --- a/transports/webtransport-websys/Cargo.toml +++ b/transports/webtransport-websys/Cargo.toml @@ -25,8 +25,8 @@ send_wrapper = { version = "0.6.0", features = ["futures"] } thiserror = "1.0.50" tracing = "0.1.37" wasm-bindgen = "0.2.89" -wasm-bindgen-futures = "0.4.38" -web-sys = { version = "0.3.65", features = [ +wasm-bindgen-futures = "0.4.39" +web-sys = { version = "0.3.66", features = [ "ReadableStreamDefaultReader", "WebTransport", "WebTransportBidirectionalStream", diff --git a/wasm-tests/webtransport-tests/Cargo.toml b/wasm-tests/webtransport-tests/Cargo.toml index 8d775b6c2fb..d8c11b646f1 100644 --- a/wasm-tests/webtransport-tests/Cargo.toml +++ b/wasm-tests/webtransport-tests/Cargo.toml @@ -18,9 +18,9 @@ libp2p-webtransport-websys = { workspace = true } multiaddr = { workspace = true } multihash = { workspace = true } wasm-bindgen = "0.2.89" -wasm-bindgen-futures = "0.4.38" -wasm-bindgen-test = "0.3.38" -web-sys = { version = "0.3.65", features = ["Response", "Window"] } +wasm-bindgen-futures = "0.4.39" +wasm-bindgen-test = "0.3.39" +web-sys = { version = "0.3.66", features = ["Response", "Window"] } [lints] workspace = true