From 3e3ea3a7b44820006c0b706428606447ac74f77d Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Sun, 19 Nov 2023 14:28:59 +1100 Subject: [PATCH 01/11] chore(futures-bounded): prepare release `0.2.3` Pull-Request: #4892. --- misc/futures-bounded/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/futures-bounded/CHANGELOG.md b/misc/futures-bounded/CHANGELOG.md index 7a6e4deac2f..aa2b3e8a65e 100644 --- a/misc/futures-bounded/CHANGELOG.md +++ b/misc/futures-bounded/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.2.3 - unreleased +## 0.2.3 - Introduce `FuturesTupleSet`, holding tuples of a `Future` together with an arbitrary piece of data. See [PR 4841](https://github.com/libp2p/rust-lib2pp/pulls/4841). From edca09b58e19dd1e6ca5183898ad24b0cfb32d92 Mon Sep 17 00:00:00 2001 From: Darius Clark Date: Sat, 18 Nov 2023 22:48:03 -0500 Subject: [PATCH 02/11] docs: fix URLs in changelogs Pull-Request: #4893. --- misc/futures-bounded/CHANGELOG.md | 8 ++++---- protocols/relay/CHANGELOG.md | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/misc/futures-bounded/CHANGELOG.md b/misc/futures-bounded/CHANGELOG.md index aa2b3e8a65e..72b0b4f457d 100644 --- a/misc/futures-bounded/CHANGELOG.md +++ b/misc/futures-bounded/CHANGELOG.md @@ -1,22 +1,22 @@ ## 0.2.3 - Introduce `FuturesTupleSet`, holding tuples of a `Future` together with an arbitrary piece of data. - See [PR 4841](https://github.com/libp2p/rust-lib2pp/pulls/4841). + See [PR 4841](https://github.com/libp2p/rust-libp2p/pull/4841). ## 0.2.2 - Fix an issue where `{Futures,Stream}Map` returns `Poll::Pending` despite being ready after an item has been replaced as part of `try_push`. - See [PR 4865](https://github.com/libp2p/rust-lib2pp/pulls/4865). + See [PR 4865](https://github.com/libp2p/rust-libp2p/pull/4865). ## 0.2.1 - Add `.len()` getter to `FuturesMap`, `FuturesSet`, `StreamMap` and `StreamSet`. - See [PR 4745](https://github.com/libp2p/rust-lib2pp/pulls/4745). + See [PR 4745](https://github.com/libp2p/rust-libp2p/pull/4745). ## 0.2.0 - Add `StreamMap` type and remove `Future`-suffix from `PushError::ReplacedFuture` to reuse it for `StreamMap`. - See [PR 4616](https://github.com/libp2p/rust-lib2pp/pulls/4616). + See [PR 4616](https://github.com/libp2p/rust-libp2p/pull/4616). ## 0.1.0 diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 565748aef7e..aaade5e48f9 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.17.1 - Automatically register relayed addresses as external addresses. - See [PR 4809](https://github.com/libp2p/rust-lib2pp/pulls/4809). + See [PR 4809](https://github.com/libp2p/rust-libp2p/pull/4809). - Fix an error where performing too many reservations at once could lead to inconsistent internal state. See [PR 4841](https://github.com/libp2p/rust-libp2p/pull/4841). @@ -14,7 +14,7 @@ See [PR 4718](https://github.com/libp2p/rust-libp2p/pull/4718). - Fix a rare race condition when making a reservation on a relay that could lead to a failed reservation. - See [PR 4747](https://github.com/libp2p/rust-lib2pp/pulls/4747). + See [PR 4747](https://github.com/libp2p/rust-libp2p/pull/4747). - Propagate errors of relay client to the listener / dialer. A failed reservation will now appear as `SwarmEvent::ListenerClosed` with the `ListenerId` of the corresponding `Swarm::listen_on` call. A failed circuit request will now appear as `SwarmEvent::OutgoingConnectionError` with the `ConnectionId` of the corresponding `Swarm::dial` call. @@ -25,7 +25,7 @@ - `relay::client::Event::InboundCircuitReqDenied` - `relay::client::Event::InboundCircuitReqDenyFailed` - See [PR 4745](https://github.com/libp2p/rust-lib2pp/pulls/4745). + See [PR 4745](https://github.com/libp2p/rust-libp2p/pull/4745). ## 0.16.2 From 0ceb6580941c010edff2a5689ada2e9e33c773cb Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Sun, 19 Nov 2023 15:19:17 +1100 Subject: [PATCH 03/11] chore: bump version of `quick-protobuf-codec` The `asynchronous-codec` dependency is exposed in `quick-protobuf-codec`, hence we need to bump the minor version. Pull-Request: #4895. --- Cargo.lock | 2 +- Cargo.toml | 2 +- misc/quick-protobuf-codec/CHANGELOG.md | 5 +++++ misc/quick-protobuf-codec/Cargo.toml | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 332764c36f3..a8fe1eeee7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4367,7 +4367,7 @@ dependencies = [ [[package]] name = "quick-protobuf-codec" -version = "0.2.0" +version = "0.3.0" dependencies = [ "asynchronous-codec", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 35439a1a696..9417876ae01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -117,7 +117,7 @@ multiaddr = "0.18.1" multihash = "0.19.1" multistream-select = { version = "0.13.0", path = "misc/multistream-select" } prometheus-client = "0.22.0" -quick-protobuf-codec = { version = "0.2.0", path = "misc/quick-protobuf-codec" } +quick-protobuf-codec = { version = "0.3.0", path = "misc/quick-protobuf-codec" } quickcheck = { package = "quickcheck-ext", path = "misc/quickcheck-ext" } rw-stream-sink = { version = "0.4.0", path = "misc/rw-stream-sink" } unsigned-varint = { version = "0.8.0" } diff --git a/misc/quick-protobuf-codec/CHANGELOG.md b/misc/quick-protobuf-codec/CHANGELOG.md index 740201f80d7..779dd750abd 100644 --- a/misc/quick-protobuf-codec/CHANGELOG.md +++ b/misc/quick-protobuf-codec/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.3.0 + +- Update to `asynchronous-codec` `v0.7.0`. + See [PR 4636](https://github.com/libp2p/rust-libp2p/pull/4636). + ## 0.2.0 - Raise MSRV to 1.65. diff --git a/misc/quick-protobuf-codec/Cargo.toml b/misc/quick-protobuf-codec/Cargo.toml index 2e309a02889..fdc65cfa93c 100644 --- a/misc/quick-protobuf-codec/Cargo.toml +++ b/misc/quick-protobuf-codec/Cargo.toml @@ -3,7 +3,7 @@ name = "quick-protobuf-codec" edition = "2021" rust-version = { workspace = true } description = "Asynchronous de-/encoding of Protobuf structs using asynchronous-codec, unsigned-varint and quick-protobuf." -version = "0.2.0" +version = "0.3.0" authors = ["Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" From 2e3dae713dbd4da1ff3e5f94e2c0e17f236d5e4d Mon Sep 17 00:00:00 2001 From: omahs <73983677+omahs@users.noreply.github.com> Date: Mon, 20 Nov 2023 00:41:43 +0100 Subject: [PATCH 04/11] docs: fix typos Pull-Request: #4897. --- README.md | 2 +- docs/coding-guidelines.md | 10 +++++----- docs/release.md | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 62573353845..62375b3dab0 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ The main components of this repository are structured as follows: * `transports/`: Implementations of transport protocols (e.g. TCP) and protocol upgrades (e.g. for authenticated encryption, compression, ...) based on the `libp2p-core` `Transport` - API . + API. * `muxers/`: Implementations of the `StreamMuxer` interface of `libp2p-core`, e.g. (sub)stream multiplexing protocols on top of (typically TCP) connections. diff --git a/docs/coding-guidelines.md b/docs/coding-guidelines.md index aef8dd6986a..bacbfe9509e 100644 --- a/docs/coding-guidelines.md +++ b/docs/coding-guidelines.md @@ -28,7 +28,7 @@ Below is a set of coding guidelines followed across the rust-libp2p code base. ## Hierarchical State Machines -If you sqint, rust-libp2p is just a big hierarchy of [state +If you squint, rust-libp2p is just a big hierarchy of [state machines](https://en.wikipedia.org/wiki/Finite-state_machine) where parents pass events down to their children and children pass events up to their parents. @@ -167,7 +167,7 @@ impl Stream for SomeStateMachine { } ``` -This priotization provides: +This prioritization provides: - Low memory footprint as local queues (here `events_to_return_to_parent`) stay small. - Low latency as accepted local work is not stuck in queues. - DOS defense as a remote does not control the size of the local queue, nor starves local work with its remote work. @@ -195,7 +195,7 @@ through a side-channel. ### Local queues As for channels shared across potentially concurrent actors (e.g. future tasks -or OS threads), the same applies for queues owned by a single actor only. E.g. +or OS threads), the same applies to queues owned by a single actor only. E.g. reading events from a socket into a `Vec` without some mechanism bounding the size of that `Vec` again can lead to unbounded memory growth and high latencies. @@ -241,7 +241,7 @@ shows a speed up when running it concurrently. ## Use `async/await` for sequential execution only Using `async/await` for sequential execution makes things significantly simpler. -Though unfortunately using `async/await` does not allow accesing methods on the +Though unfortunately using `async/await` does not allow accessing methods on the object being `await`ed unless paired with some synchronization mechanism like an `Arc>`. @@ -308,7 +308,7 @@ response and a previous request. For example, if a user requests two new connect peer, they should be able to match each new connection to the corresponding previous connection request without having to guess. -When accepting a **command** that eventually results in a response through an event require that +When accepting a **command** that eventually results in a response through an event requires that command to contain a unique ID, which is later on contained in the asynchronous response event. One such example is the `Swarm` accepting a `ToSwarm::Dial` from the `NetworkBehaviour`. diff --git a/docs/release.md b/docs/release.md index 5b4d32aedaf..8edc621c127 100644 --- a/docs/release.md +++ b/docs/release.md @@ -65,13 +65,13 @@ Hence, we are going to bump those versions once we work through the milestone th ## Dealing with alphas -Unfortunately, `cargo` has a rather uninutitive behaviour when it comes to dealing with pre-releases like `0.1.0-alpha`. +Unfortunately, `cargo` has a rather unintuitive behaviour when it comes to dealing with pre-releases like `0.1.0-alpha`. See this internals thread for some context: https://internals.rust-lang.org/t/changing-cargo-semver-compatibility-for-pre-releases In short, cargo will automatically update from `0.1.0-alpha.1` to `0.1.0-alpha.2` UNLESS you pin the version directly with `=0.1.0-alpha.1`. However, from a semver perspective, changes between pre-releases can be breaking. -To avoid accidential breaking changes for our users, we employ the following convention for alpha releases: +To avoid accidental breaking changes for our users, we employ the following convention for alpha releases: - For a breaking change in a crate with an alpha release, bump the "minor" version but retain the "alpha" tag. Example: `0.1.0-alpha` to `0.2.0-alpha`. From 35b8fa5812065bb4b3278b90583a10fa2a7d3435 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 20 Nov 2023 11:55:35 +1100 Subject: [PATCH 05/11] deps: upgrade `cargo semver-checks` to `v0.25.0` Pull-Request: #4899. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ccaa53f381..f0c852367a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -293,7 +293,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: wget -q -O- https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.24.2/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C ~/.cargo/bin + - 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 shell: bash - uses: obi1kenobi/cargo-semver-checks-action@e275dda72e250d4df5b564e969e1348d67fefa52 # v2 From 8d3bde46a8482bd58e1e0581cdf110cd0943c1d7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Nov 2023 08:13:24 +0000 Subject: [PATCH 06/11] deps: bump rustls from 0.21.8 to 0.21.9 Pull-Request: #4902. --- Cargo.lock | 18 +++++++++--------- transports/quic/Cargo.toml | 2 +- transports/tls/Cargo.toml | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a8fe1eeee7a..49fd90990ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1657,7 +1657,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35bd3cf68c183738046838e300353e4716c674dc5e56890de4826801a6622a28" dependencies = [ "futures-io", - "rustls 0.21.8", + "rustls 0.21.9", ] [[package]] @@ -2977,7 +2977,7 @@ dependencies = [ "quinn", "rand 0.8.5", "ring 0.16.20", - "rustls 0.21.8", + "rustls 0.21.9", "socket2 0.5.5", "thiserror", "tokio", @@ -3185,7 +3185,7 @@ dependencies = [ "libp2p-yamux", "rcgen", "ring 0.16.20", - "rustls 0.21.8", + "rustls 0.21.9", "rustls-webpki", "thiserror", "tokio", @@ -4409,7 +4409,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash", - "rustls 0.21.8", + "rustls 0.21.9", "thiserror", "tokio", "tracing", @@ -4425,7 +4425,7 @@ dependencies = [ "rand 0.8.5", "ring 0.16.20", "rustc-hash", - "rustls 0.21.8", + "rustls 0.21.9", "slab", "thiserror", "tinyvec", @@ -4952,9 +4952,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.8" +version = "0.21.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "446e14c5cda4f3f30fe71863c34ec70f5ac79d6087097ad0bb433e1be5edf04c" +checksum = "629648aced5775d558af50b2b4c7b02983a04b312126d45eeead26e7caa498b9" dependencies = [ "log", "ring 0.17.5", @@ -6377,7 +6377,7 @@ dependencies = [ "ring 0.16.20", "rtcp", "rtp", - "rustls 0.21.8", + "rustls 0.21.9", "sdp", "serde", "serde_json", @@ -6438,7 +6438,7 @@ dependencies = [ "rand_core 0.6.4", "rcgen", "ring 0.16.20", - "rustls 0.21.8", + "rustls 0.21.9", "sec1", "serde", "sha1", diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index 22b241c8d8e..c59c9b64f1c 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -20,7 +20,7 @@ libp2p-identity = { workspace = true } parking_lot = "0.12.0" quinn = { version = "0.10.2", default-features = false, features = ["tls-rustls", "futures-io"] } rand = "0.8.5" -rustls = { version = "0.21.8", default-features = false } +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 } tracing = "0.1.37" diff --git a/transports/tls/Cargo.toml b/transports/tls/Cargo.toml index 196251dcb76..5a1e4788245 100644 --- a/transports/tls/Cargo.toml +++ b/transports/tls/Cargo.toml @@ -22,7 +22,7 @@ yasna = "0.5.2" # Exposed dependencies. Breaking changes to these are breaking changes to us. [dependencies.rustls] -version = "0.21.8" +version = "0.21.9" default-features = false features = ["dangerous_configuration"] # Must enable this to allow for custom verification code. From 7387500b878efb73fb3083d2aefca5bc3f08202e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Nov 2023 11:04:41 +0000 Subject: [PATCH 07/11] deps: bump zeroize from 1.6.0 to 1.7.0 Pull-Request: #4904. --- Cargo.lock | 4 ++-- identity/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49fd90990ef..b342fbb133b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6783,9 +6783,9 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" dependencies = [ "zeroize_derive", ] diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 1d5a8f4ac54..49f90a1c680 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -27,7 +27,7 @@ serde = { version = "1", optional = true, features = ["derive"] } sha2 = { version = "0.10.8", optional = true } thiserror = { version = "1.0", optional = true } void = { version = "1.0", optional = true } -zeroize = { version = "1.6", optional = true } +zeroize = { version = "1.7", optional = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] ring = { version = "0.17.5", features = [ "alloc", "std"], default-features = false, optional = true } From 338e467927f8a0cba34eb24288f0be9b0972d05d Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 21 Nov 2023 00:46:06 +1100 Subject: [PATCH 08/11] docs: document new CHANGELOG-management strategy At the moment, we have to send a separate PR that removes the `- unreleased` suffix in `CHANGELOG.md` before we can make a release. This is annoying and unnecessarily delays being able to make releases for features that have been merged into master. As of #4620, we have CI checks that ensure we add a changelog entry when a particular crate is modified. Additionally, the CI check also ensures we bump the version in case the top-most one of the changelog is already released. The combination of these checks should ensure that we add a section for the new version in case the top-most one is already released. Previously, the presence of `- unreleased` would notify us of that. In the future, we can add a CI job that allows us to release at the press of a button (think `workflow_dispatch`). Until then, this setup should already make it much easier to release crates. Pull-Request: #4894. --- docs/release.md | 37 +++++++++++++------------------- protocols/gossipsub/CHANGELOG.md | 2 +- protocols/identify/CHANGELOG.md | 2 +- protocols/kad/CHANGELOG.md | 2 +- protocols/mdns/CHANGELOG.md | 2 +- scripts/add-changelog-header.sh | 2 +- 6 files changed, 20 insertions(+), 27 deletions(-) diff --git a/docs/release.md b/docs/release.md index 8edc621c127..50b7b0605c7 100644 --- a/docs/release.md +++ b/docs/release.md @@ -17,43 +17,34 @@ Non-breaking changes are typically merged very quickly and often released as pat Every crate that we publish on `crates.io` has a `CHANGELOG.md` file. Substantial PRs should add an entry to each crate they modify. -The next unreleased version is tagged with ` - unreleased`, for example: `0.17.0 - unreleased`. +We have a CI check[^1] that enforces adding a changelog entry if you modify code in a particular crate. +In case the current version is already released (we also check that in CI), you'll have to add a new header at the top. +For example, the top-listed version might be `0.17.3` but it is already released. +In that case, add a new heading `## 0.17.4` with your changelog entry in case it is a non-breaking change. -In case there isn't a version with an ` - unreleased` postfix yet, add one for the next version. -The next version number depends on the impact of your change (breaking vs non-breaking, see above). - -If you are making a non-breaking change, please also bump the version number: - -- in the `Cargo.toml` manifest of the respective crate -- in the `[workspace.dependencies]` section of the workspace `Cargo.toml` manifest - -For breaking changes, a changelog entry itself is sufficient. -Bumping the version in the `Cargo.toml` file would lead to many merge conflicts once we decide to merge them. -Hence, we are going to bump those versions once we work through the milestone that collects the breaking changes. +The version in the crate's `Cargo.toml` and the top-most version in the `CHANGELOG.md` file always have to be in sync. +Additionally, we also enforce that all crates always depend on the latest version of other workspace-crates through workspace inheritance. +As a consequence, you'll also have to bump the version in `[workspace.dependencies]` in the workspace `Cargo.toml` manifest. ## Releasing one or more crates +The above changelog-management strategy means `master` is always in a state where we can make a release. + ### Prerequisites - [cargo release](https://github.com/crate-ci/cargo-release/) ### Steps -1. Remove the ` - unreleased` tag for each crate to be released in the respective `CHANGELOG.md`. - Create a pull request with the changes against the rust-libp2p `master` branch. - -2. Once merged, run the two commands below on the (squash-) merged commit on the `master` branch. +1. Run the two commands below on the (squash-) merged commit on the `master` branch. 1. `cargo release publish --execute` 2. `cargo release tag --sign-tag --execute` -3. Confirm that `cargo release` tagged the commit correctly via `git push - $YOUR_ORIGIN --tag --dry-run` and then push the new tags via `git push - $YOUR_ORIGIN --tag`. Make sure not to push unrelated git tags. - - Note that dropping the `--no-push` flag on `cargo release` might as well do - the trick. +2. Confirm that `cargo release` tagged the commit correctly via `git push $YOUR_ORIGIN --tag --dry-run` + Push the new tags via `git push $YOUR_ORIGIN --tag`. + Make sure not to push unrelated git tags. ## Patch release @@ -77,3 +68,5 @@ To avoid accidental breaking changes for our users, we employ the following conv Example: `0.1.0-alpha` to `0.2.0-alpha`. - For a non-breaking change in a crate with an alpha release, bump or append number to the "alpha" tag. Example: `0.1.0-alpha` to `0.1.0-alpha.1`. + +[^1]: See [ci.yml](../.github/workflows/ci.yml) and look for "Ensure manifest and CHANGELOG are properly updated". diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 68041f2dcd3..5ff4cfa27d6 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.46.1 - unreleased +## 0.46.1 - Deprecate `Rpc` in preparation for removing it from the public API because it is an internal type. See [PR 4833](https://github.com/libp2p/rust-libp2p/pull/4833). diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index d2f67bd908c..22c74b28cae 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.44.1 - unreleased +## 0.44.1 - Ensure `Multiaddr` handled and returned by `Behaviour` are `/p2p` terminated. See [PR 4596](https://github.com/libp2p/rust-libp2p/pull/4596). diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index d59ea8acb17..4740e4b1f95 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.45.2 - unreleased +## 0.45.2 - Ensure `Multiaddr` handled and returned by `Behaviour` are `/p2p` terminated. See [PR 4596](https://github.com/libp2p/rust-libp2p/pull/4596). diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index c6a9359c23b..6f5aa6945fd 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.45.1 - unreleased +## 0.45.1 - Ensure `Multiaddr` handled and returned by `Behaviour` are `/p2p` terminated. See [PR 4596](https://github.com/libp2p/rust-libp2p/pull/4596). diff --git a/scripts/add-changelog-header.sh b/scripts/add-changelog-header.sh index 8050857c52e..4717940c8d7 100755 --- a/scripts/add-changelog-header.sh +++ b/scripts/add-changelog-header.sh @@ -7,4 +7,4 @@ if [[ $header == $prefix* ]]; then exit fi -sed -i "1i ## ${NEW_VERSION} - unreleased\n\n" "$CRATE_ROOT/CHANGELOG.md" +sed -i "1i ## ${NEW_VERSION}\n\n" "$CRATE_ROOT/CHANGELOG.md" From 594ecaaeec159f435cb8251aaa5986ddfbb4e552 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Nov 2023 22:15:37 +0000 Subject: [PATCH 09/11] deps: bump ed25519-dalek from 2.0.0 to 2.1.0 Pull-Request: #4903. --- Cargo.lock | 5 +++-- identity/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b342fbb133b..25319bcf968 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1320,15 +1320,16 @@ dependencies = [ [[package]] name = "ed25519-dalek" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" +checksum = "1f628eaec48bfd21b865dc2950cfa014450c01d2fa2b69a86c2fd5844ec523c0" dependencies = [ "curve25519-dalek", "ed25519", "rand_core 0.6.4", "serde", "sha2 0.10.8", + "subtle", "zeroize", ] diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 49f90a1c680..f70db830d3f 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -14,7 +14,7 @@ categories = ["cryptography"] [dependencies] asn1_der = { version = "0.7.6", optional = true } bs58 = { version = "0.5.0", optional = true } -ed25519-dalek = { version = "2.0", optional = true } +ed25519-dalek = { version = "2.1", optional = true } hkdf = { version = "0.12.3", optional = true } libsecp256k1 = { version = "0.7.0", optional = true } tracing = "0.1.37" From 5a4a462899ac937cb1a0dc84ef29333a7ad1b047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Daniel=20Hern=C3=A1ndez?= Date: Mon, 20 Nov 2023 18:05:58 -0600 Subject: [PATCH 10/11] feat(websocket-websys): add support for different WASM environments We introduce a `WebContext` `enum` that abstracts and detects the `Window` vs the `WorkerGlobalScope` API. Related: https://github.com/rustwasm/wasm-bindgen/issues/1046. Pull-Request: #4889. --- Cargo.lock | 2 +- Cargo.toml | 2 +- transports/websocket-websys/CHANGELOG.md | 6 ++ transports/websocket-websys/Cargo.toml | 4 +- transports/websocket-websys/src/lib.rs | 16 ++++-- .../websocket-websys/src/web_context.rs | 57 +++++++++++++++++++ 6 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 transports/websocket-websys/src/web_context.rs diff --git a/Cargo.lock b/Cargo.lock index 25319bcf968..4a7655a3004 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3321,7 +3321,7 @@ dependencies = [ [[package]] name = "libp2p-websocket-websys" -version = "0.3.0" +version = "0.3.1" dependencies = [ "bytes", "futures", diff --git a/Cargo.toml b/Cargo.toml index 9417876ae01..0603a22629b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -110,7 +110,7 @@ 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-websocket = { version = "0.43.0", path = "transports/websocket" } -libp2p-websocket-websys = { version = "0.3.0", path = "transports/websocket-websys" } +libp2p-websocket-websys = { version = "0.3.1", path = "transports/websocket-websys" } libp2p-webtransport-websys = { version = "0.2.0", path = "transports/webtransport-websys" } libp2p-yamux = { version = "0.45.0", path = "muxers/yamux" } multiaddr = "0.18.1" diff --git a/transports/websocket-websys/CHANGELOG.md b/transports/websocket-websys/CHANGELOG.md index 17c253cb80a..3cfb1b2fbf9 100644 --- a/transports/websocket-websys/CHANGELOG.md +++ b/transports/websocket-websys/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.3.1 + +- Add support for different WASM environments by introducing a `WebContext` that + detects and abstracts the `Window` vs the `WorkerGlobalScope` API. + See [PR 4889](https://github.com/libp2p/rust-libp2p/pull/4889). + ## 0.3.0 diff --git a/transports/websocket-websys/Cargo.toml b/transports/websocket-websys/Cargo.toml index 6a6cef5f8bc..ffa2892e838 100644 --- a/transports/websocket-websys/Cargo.toml +++ b/transports/websocket-websys/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-websocket-websys" edition = "2021" rust-version = "1.60.0" description = "WebSocket for libp2p under WASM environment" -version = "0.3.0" +version = "0.3.1" authors = ["Vince Vasta "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -20,7 +20,7 @@ parking_lot = "0.12.1" send_wrapper = "0.6.0" thiserror = "1.0.50" wasm-bindgen = "0.2.88" -web-sys = { version = "0.3.65", features = ["BinaryType", "CloseEvent", "MessageEvent", "WebSocket", "Window"] } +web-sys = { version = "0.3.65", 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/websocket-websys/src/lib.rs b/transports/websocket-websys/src/lib.rs index b4f7566f95e..5c1a6ebf1c4 100644 --- a/transports/websocket-websys/src/lib.rs +++ b/transports/websocket-websys/src/lib.rs @@ -20,6 +20,8 @@ //! Libp2p websocket transports built on [web-sys](https://rustwasm.github.io/wasm-bindgen/web-sys/index.html). +mod web_context; + use bytes::BytesMut; use futures::task::AtomicWaker; use futures::{future::Ready, io, prelude::*}; @@ -35,7 +37,9 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Mutex; use std::{pin::Pin, task::Context, task::Poll}; use wasm_bindgen::{prelude::*, JsCast}; -use web_sys::{window, CloseEvent, Event, MessageEvent, WebSocket}; +use web_sys::{CloseEvent, Event, MessageEvent, WebSocket}; + +use crate::web_context::WebContext; /// A Websocket transport that can be used in a wasm environment. /// @@ -300,8 +304,8 @@ impl Connection { } } }); - let buffered_amount_low_interval = window() - .expect("to have a window") + let buffered_amount_low_interval = WebContext::new() + .expect("to have a window or worker context") .set_interval_with_callback_and_timeout_and_arguments( on_buffered_amount_low_closure.as_ref().unchecked_ref(), 100, // Chosen arbitrarily and likely worth tuning. Due to low impact of the /ws transport, no further effort was invested at the time. @@ -439,8 +443,8 @@ impl Drop for Connection { .close_with_code_and_reason(GO_AWAY_STATUS_CODE, "connection dropped"); } - window() - .expect("to have a window") - .clear_interval_with_handle(self.inner.buffered_amount_low_interval) + WebContext::new() + .expect("to have a window or worker context") + .clear_interval_with_handle(self.inner.buffered_amount_low_interval); } } diff --git a/transports/websocket-websys/src/web_context.rs b/transports/websocket-websys/src/web_context.rs new file mode 100644 index 00000000000..c514435d2bb --- /dev/null +++ b/transports/websocket-websys/src/web_context.rs @@ -0,0 +1,57 @@ +use wasm_bindgen::{prelude::*, JsCast}; +use web_sys::window; + +/// Web context that abstract the window vs web worker API +#[derive(Debug)] +pub(crate) enum WebContext { + Window(web_sys::Window), + Worker(web_sys::WorkerGlobalScope), +} + +impl WebContext { + pub(crate) fn new() -> Option { + match window() { + Some(window) => Some(Self::Window(window)), + None => { + #[wasm_bindgen] + extern "C" { + type Global; + + #[wasm_bindgen(method, getter, js_name = WorkerGlobalScope)] + fn worker(this: &Global) -> JsValue; + } + let global: Global = js_sys::global().unchecked_into(); + if !global.worker().is_undefined() { + Some(Self::Worker(global.unchecked_into())) + } else { + None + } + } + } + } + + /// The `setInterval()` method. + pub(crate) fn set_interval_with_callback_and_timeout_and_arguments( + &self, + handler: &::js_sys::Function, + timeout: i32, + arguments: &::js_sys::Array, + ) -> Result { + match self { + WebContext::Window(w) => { + w.set_interval_with_callback_and_timeout_and_arguments(handler, timeout, arguments) + } + WebContext::Worker(w) => { + w.set_interval_with_callback_and_timeout_and_arguments(handler, timeout, arguments) + } + } + } + + /// The `clearInterval()` method. + pub(crate) fn clear_interval_with_handle(&self, handle: i32) { + match self { + WebContext::Window(w) => w.clear_interval_with_handle(handle), + WebContext::Worker(w) => w.clear_interval_with_handle(handle), + } + } +} From 3e30c2051c4b09642914929bbf471aceb37230eb Mon Sep 17 00:00:00 2001 From: Michael Assaf <94772640+snowmead@users.noreply.github.com> Date: Mon, 20 Nov 2023 19:16:15 -0500 Subject: [PATCH 11/11] fix: set `idle_connection_timeout` in examples Within examples, we often set up a very specific network configuration which may leave connections idle whilst we wait for user input. To ensure that the examples can still showcase something, we need to set an `idle_connection_timeout` on the `Swarm`. Related: #4877. Pull-Request: #4887. --- examples/autonat/src/bin/autonat_client.rs | 1 + examples/autonat/src/bin/autonat_server.rs | 2 ++ examples/dcutr/src/main.rs | 3 ++- examples/distributed-key-value-store/src/main.rs | 2 ++ examples/file-sharing/src/network.rs | 2 ++ examples/identify/src/main.rs | 3 ++- examples/ipfs-private/src/main.rs | 3 ++- 7 files changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/autonat/src/bin/autonat_client.rs b/examples/autonat/src/bin/autonat_client.rs index b071e717731..3fb25aa6222 100644 --- a/examples/autonat/src/bin/autonat_client.rs +++ b/examples/autonat/src/bin/autonat_client.rs @@ -60,6 +60,7 @@ async fn main() -> Result<(), Box> { yamux::Config::default, )? .with_behaviour(|key| Behaviour::new(key.public()))? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); swarm.listen_on( diff --git a/examples/autonat/src/bin/autonat_server.rs b/examples/autonat/src/bin/autonat_server.rs index d1c0c005861..44a53f0d17f 100644 --- a/examples/autonat/src/bin/autonat_server.rs +++ b/examples/autonat/src/bin/autonat_server.rs @@ -27,6 +27,7 @@ use libp2p::swarm::{NetworkBehaviour, SwarmEvent}; use libp2p::{autonat, identify, identity, noise, tcp, yamux}; use std::error::Error; use std::net::Ipv4Addr; +use std::time::Duration; use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] @@ -52,6 +53,7 @@ async fn main() -> Result<(), Box> { yamux::Config::default, )? .with_behaviour(|key| Behaviour::new(key.public()))? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); swarm.listen_on( diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index 91beaa02c67..51df670f8a7 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -28,8 +28,8 @@ use libp2p::{ swarm::{NetworkBehaviour, SwarmEvent}, tcp, yamux, PeerId, }; -use std::error::Error; use std::str::FromStr; +use std::{error::Error, time::Duration}; use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] @@ -105,6 +105,7 @@ async fn main() -> Result<(), Box> { )), dcutr: dcutr::Behaviour::new(keypair.public().to_peer_id()), })? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); swarm diff --git a/examples/distributed-key-value-store/src/main.rs b/examples/distributed-key-value-store/src/main.rs index 1843520838b..404333f3d20 100644 --- a/examples/distributed-key-value-store/src/main.rs +++ b/examples/distributed-key-value-store/src/main.rs @@ -31,6 +31,7 @@ use libp2p::{ tcp, yamux, }; use std::error::Error; +use std::time::Duration; use tracing_subscriber::EnvFilter; #[async_std::main] @@ -65,6 +66,7 @@ async fn main() -> Result<(), Box> { )?, }) })? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); swarm.behaviour_mut().kademlia.set_mode(Some(Mode::Server)); diff --git a/examples/file-sharing/src/network.rs b/examples/file-sharing/src/network.rs index ad5418193a4..59625fc39ea 100644 --- a/examples/file-sharing/src/network.rs +++ b/examples/file-sharing/src/network.rs @@ -15,6 +15,7 @@ use libp2p::StreamProtocol; use serde::{Deserialize, Serialize}; use std::collections::{hash_map, HashMap, HashSet}; use std::error::Error; +use std::time::Duration; /// Creates the network components, namely: /// @@ -58,6 +59,7 @@ pub(crate) async fn new( request_response::Config::default(), ), })? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); swarm diff --git a/examples/identify/src/main.rs b/examples/identify/src/main.rs index 3c40addbcf8..916317a5a43 100644 --- a/examples/identify/src/main.rs +++ b/examples/identify/src/main.rs @@ -22,7 +22,7 @@ use futures::StreamExt; use libp2p::{core::multiaddr::Multiaddr, identify, noise, swarm::SwarmEvent, tcp, yamux}; -use std::error::Error; +use std::{error::Error, time::Duration}; use tracing_subscriber::EnvFilter; #[async_std::main] @@ -44,6 +44,7 @@ async fn main() -> Result<(), Box> { key.public(), )) })? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); // Tell the swarm to listen on all interfaces and a random, OS-assigned diff --git a/examples/ipfs-private/src/main.rs b/examples/ipfs-private/src/main.rs index 12bd985cdf0..a57bfd465e0 100644 --- a/examples/ipfs-private/src/main.rs +++ b/examples/ipfs-private/src/main.rs @@ -31,7 +31,7 @@ use libp2p::{ swarm::{NetworkBehaviour, SwarmEvent}, tcp, yamux, Multiaddr, Transport, }; -use std::{env, error::Error, fs, path::Path, str::FromStr}; +use std::{env, error::Error, fs, path::Path, str::FromStr, time::Duration}; use tokio::{io, io::AsyncBufReadExt, select}; use tracing_subscriber::EnvFilter; @@ -151,6 +151,7 @@ async fn main() -> Result<(), Box> { ping: ping::Behaviour::new(ping::Config::new()), }) })? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); println!("Subscribing to {gossipsub_topic:?}");