From ee17df9c5324a27dab9edbbe9f6deed1e36b9f45 Mon Sep 17 00:00:00 2001
From: Thomas Eizinger <thomas@eizinger.io>
Date: Tue, 28 Nov 2023 23:04:26 +1100
Subject: [PATCH 01/12] chore(identity): don't inherit rust-version from
 workspace

Another data point in favor of #4742 just popped up. With `libp2p-identity` being part of the workspace, we accidentally published a patch release that bumps the MSRV which is something we normally consider a breaking change.

This PR freezes the MSRV of `libp2p-identity` to avoid this problem in the future. Long-term, we should do #4742 to avoid these kind of mistakes instead of special-casing crates within the repository.

Pull-Request: #4866.
---
 identity/Cargo.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/identity/Cargo.toml b/identity/Cargo.toml
index f70db830d3f..e7aa15fef07 100644
--- a/identity/Cargo.toml
+++ b/identity/Cargo.toml
@@ -3,7 +3,7 @@ name = "libp2p-identity"
 version = "0.2.8"
 edition = "2021"
 description = "Data structures and algorithms for identifying peers in libp2p."
-rust-version = { workspace = true }
+rust-version = "1.73.0" # MUST NOT inherit from workspace because we don't want to publish breaking changes to `libp2p-identity`.
 license = "MIT"
 repository = "https://github.com/libp2p/rust-libp2p"
 keywords = ["peer-to-peer", "libp2p", "networking", "cryptography"]

From 4d7a535c7fa750ba88622e7d7cbbbbbb6884985c Mon Sep 17 00:00:00 2001
From: Thomas Eizinger <thomas@eizinger.io>
Date: Wed, 29 Nov 2023 00:42:17 +1100
Subject: [PATCH 02/12] refactor(relay): use oneshot's to track requested
 streams

This is much cleaner as it allows us to construct a single `Future` that expresses the entire outbound protocol from stream opening to finish.

Pull-Request: #4900.
---
 protocols/relay/src/priv_client/handler.rs   | 220 ++++++++-----------
 protocols/relay/src/protocol/outbound_hop.rs |   4 +-
 2 files changed, 99 insertions(+), 125 deletions(-)

diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs
index 1925d6f6ab4..662d63cc742 100644
--- a/protocols/relay/src/priv_client/handler.rs
+++ b/protocols/relay/src/priv_client/handler.rs
@@ -18,9 +18,12 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
+use crate::client::Connection;
 use crate::priv_client::transport;
+use crate::priv_client::transport::ToListenerMsg;
 use crate::protocol::{self, inbound_stop, outbound_hop};
 use crate::{priv_client, proto, HOP_PROTOCOL_NAME, STOP_PROTOCOL_NAME};
+use futures::channel::mpsc::Sender;
 use futures::channel::{mpsc, oneshot};
 use futures::future::FutureExt;
 use futures_timer::Delay;
@@ -28,17 +31,16 @@ use libp2p_core::multiaddr::Protocol;
 use libp2p_core::upgrade::ReadyUpgrade;
 use libp2p_core::Multiaddr;
 use libp2p_identity::PeerId;
-use libp2p_swarm::handler::{
-    ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound,
-};
+use libp2p_swarm::handler::{ConnectionEvent, FullyNegotiatedInbound};
 use libp2p_swarm::{
-    ConnectionHandler, ConnectionHandlerEvent, StreamProtocol, StreamUpgradeError,
+    ConnectionHandler, ConnectionHandlerEvent, Stream, StreamProtocol, StreamUpgradeError,
     SubstreamProtocol,
 };
 use std::collections::VecDeque;
 use std::task::{Context, Poll};
 use std::time::Duration;
 use std::{fmt, io};
+use void::Void;
 
 /// The maximum number of circuits being denied concurrently.
 ///
@@ -104,8 +106,7 @@ pub struct Handler {
         >,
     >,
 
-    /// We issue a stream upgrade for each pending request.
-    pending_requests: VecDeque<PendingRequest>,
+    pending_streams: VecDeque<oneshot::Sender<Result<Stream, StreamUpgradeError<Void>>>>,
 
     inflight_reserve_requests: futures_bounded::FuturesTupleSet<
         Result<outbound_hop::Reservation, outbound_hop::ReserveError>,
@@ -133,7 +134,7 @@ impl Handler {
             remote_peer_id,
             remote_addr,
             queued_events: Default::default(),
-            pending_requests: Default::default(),
+            pending_streams: Default::default(),
             inflight_reserve_requests: futures_bounded::FuturesTupleSet::new(
                 STREAM_TIMEOUT,
                 MAX_CONCURRENT_STREAMS_PER_CONNECTION,
@@ -154,57 +155,6 @@ impl Handler {
         }
     }
 
-    fn on_dial_upgrade_error(
-        &mut self,
-        DialUpgradeError { error, .. }: DialUpgradeError<
-            <Self as ConnectionHandler>::OutboundOpenInfo,
-            <Self as ConnectionHandler>::OutboundProtocol,
-        >,
-    ) {
-        let pending_request = self
-            .pending_requests
-            .pop_front()
-            .expect("got a stream error without a pending request");
-
-        match pending_request {
-            PendingRequest::Reserve { mut to_listener } => {
-                let error = match error {
-                    StreamUpgradeError::Timeout => {
-                        outbound_hop::ReserveError::Io(io::ErrorKind::TimedOut.into())
-                    }
-                    StreamUpgradeError::Apply(never) => void::unreachable(never),
-                    StreamUpgradeError::NegotiationFailed => {
-                        outbound_hop::ReserveError::Unsupported
-                    }
-                    StreamUpgradeError::Io(e) => outbound_hop::ReserveError::Io(e),
-                };
-
-                if let Err(e) =
-                    to_listener.try_send(transport::ToListenerMsg::Reservation(Err(error)))
-                {
-                    tracing::debug!("Unable to send error to listener: {}", e.into_send_error())
-                }
-                self.reservation.failed();
-            }
-            PendingRequest::Connect {
-                to_dial: send_back, ..
-            } => {
-                let error = match error {
-                    StreamUpgradeError::Timeout => {
-                        outbound_hop::ConnectError::Io(io::ErrorKind::TimedOut.into())
-                    }
-                    StreamUpgradeError::NegotiationFailed => {
-                        outbound_hop::ConnectError::Unsupported
-                    }
-                    StreamUpgradeError::Io(e) => outbound_hop::ConnectError::Io(e),
-                    StreamUpgradeError::Apply(v) => void::unreachable(v),
-                };
-
-                let _ = send_back.send(Err(error));
-            }
-        }
-    }
-
     fn insert_to_deny_futs(&mut self, circuit: inbound_stop::Circuit) {
         let src_peer_id = circuit.src_peer_id();
 
@@ -219,6 +169,62 @@ impl Handler {
             )
         }
     }
+
+    fn make_new_reservation(&mut self, to_listener: Sender<ToListenerMsg>) {
+        let (sender, receiver) = oneshot::channel();
+
+        self.pending_streams.push_back(sender);
+        self.queued_events
+            .push_back(ConnectionHandlerEvent::OutboundSubstreamRequest {
+                protocol: SubstreamProtocol::new(ReadyUpgrade::new(HOP_PROTOCOL_NAME), ()),
+            });
+        let result = self.inflight_reserve_requests.try_push(
+            async move {
+                let stream = receiver
+                    .await
+                    .map_err(|_| io::Error::from(io::ErrorKind::BrokenPipe))?
+                    .map_err(into_reserve_error)?;
+
+                let reservation = outbound_hop::make_reservation(stream).await?;
+
+                Ok(reservation)
+            },
+            to_listener,
+        );
+
+        if result.is_err() {
+            tracing::warn!("Dropping in-flight reservation request because we are at capacity");
+        }
+    }
+
+    fn establish_new_circuit(
+        &mut self,
+        to_dial: oneshot::Sender<Result<Connection, outbound_hop::ConnectError>>,
+        dst_peer_id: PeerId,
+    ) {
+        let (sender, receiver) = oneshot::channel();
+
+        self.pending_streams.push_back(sender);
+        self.queued_events
+            .push_back(ConnectionHandlerEvent::OutboundSubstreamRequest {
+                protocol: SubstreamProtocol::new(ReadyUpgrade::new(HOP_PROTOCOL_NAME), ()),
+            });
+        let result = self.inflight_outbound_connect_requests.try_push(
+            async move {
+                let stream = receiver
+                    .await
+                    .map_err(|_| io::Error::from(io::ErrorKind::BrokenPipe))?
+                    .map_err(into_connect_error)?;
+
+                outbound_hop::open_circuit(stream, dst_peer_id).await
+            },
+            to_dial,
+        );
+
+        if result.is_err() {
+            tracing::warn!("Dropping in-flight connect request because we are at capacity")
+        }
+    }
 }
 
 impl ConnectionHandler for Handler {
@@ -236,25 +242,13 @@ impl ConnectionHandler for Handler {
     fn on_behaviour_event(&mut self, event: Self::FromBehaviour) {
         match event {
             In::Reserve { to_listener } => {
-                self.pending_requests
-                    .push_back(PendingRequest::Reserve { to_listener });
-                self.queued_events
-                    .push_back(ConnectionHandlerEvent::OutboundSubstreamRequest {
-                        protocol: SubstreamProtocol::new(ReadyUpgrade::new(HOP_PROTOCOL_NAME), ()),
-                    });
+                self.make_new_reservation(to_listener);
             }
             In::EstablishCircuit {
-                to_dial: send_back,
+                to_dial,
                 dst_peer_id,
             } => {
-                self.pending_requests.push_back(PendingRequest::Connect {
-                    dst_peer_id,
-                    to_dial: send_back,
-                });
-                self.queued_events
-                    .push_back(ConnectionHandlerEvent::OutboundSubstreamRequest {
-                        protocol: SubstreamProtocol::new(ReadyUpgrade::new(HOP_PROTOCOL_NAME), ()),
-                    });
+                self.establish_new_circuit(to_dial, dst_peer_id);
             }
         }
     }
@@ -402,12 +396,8 @@ impl ConnectionHandler for Handler {
             }
 
             if let Poll::Ready(Some(to_listener)) = self.reservation.poll(cx) {
-                self.pending_requests
-                    .push_back(PendingRequest::Reserve { to_listener });
-
-                return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest {
-                    protocol: SubstreamProtocol::new(ReadyUpgrade::new(HOP_PROTOCOL_NAME), ()),
-                });
+                self.make_new_reservation(to_listener);
+                continue;
             }
 
             // Deny incoming circuit requests.
@@ -450,42 +440,16 @@ impl ConnectionHandler for Handler {
                     tracing::warn!("Dropping inbound stream because we are at capacity")
                 }
             }
-            ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
-                protocol: stream,
-                ..
-            }) => {
-                let pending_request = self.pending_requests.pop_front().expect(
-                    "opened a stream without a pending connection command or a reserve listener",
-                );
-                match pending_request {
-                    PendingRequest::Reserve { to_listener } => {
-                        if self
-                            .inflight_reserve_requests
-                            .try_push(outbound_hop::make_reservation(stream), to_listener)
-                            .is_err()
-                        {
-                            tracing::warn!("Dropping outbound stream because we are at capacity");
-                        }
-                    }
-                    PendingRequest::Connect {
-                        dst_peer_id,
-                        to_dial: send_back,
-                    } => {
-                        if self
-                            .inflight_outbound_connect_requests
-                            .try_push(outbound_hop::open_circuit(stream, dst_peer_id), send_back)
-                            .is_err()
-                        {
-                            tracing::warn!("Dropping outbound stream because we are at capacity");
-                        }
-                    }
+            ConnectionEvent::FullyNegotiatedOutbound(ev) => {
+                if let Some(next) = self.pending_streams.pop_front() {
+                    let _ = next.send(Ok(ev.protocol));
                 }
             }
-            ConnectionEvent::ListenUpgradeError(listen_upgrade_error) => {
-                void::unreachable(listen_upgrade_error.error)
-            }
-            ConnectionEvent::DialUpgradeError(dial_upgrade_error) => {
-                self.on_dial_upgrade_error(dial_upgrade_error)
+            ConnectionEvent::ListenUpgradeError(ev) => void::unreachable(ev.error),
+            ConnectionEvent::DialUpgradeError(ev) => {
+                if let Some(next) = self.pending_streams.pop_front() {
+                    let _ = next.send(Err(ev.error));
+                }
             }
             _ => {}
         }
@@ -614,14 +578,24 @@ impl Reservation {
     }
 }
 
-pub(crate) enum PendingRequest {
-    Reserve {
-        /// A channel into the [`Transport`](priv_client::Transport).
-        to_listener: mpsc::Sender<transport::ToListenerMsg>,
-    },
-    Connect {
-        dst_peer_id: PeerId,
-        /// A channel into the future returned by [`Transport::dial`](libp2p_core::Transport::dial).
-        to_dial: oneshot::Sender<Result<priv_client::Connection, outbound_hop::ConnectError>>,
-    },
+fn into_reserve_error(e: StreamUpgradeError<Void>) -> outbound_hop::ReserveError {
+    match e {
+        StreamUpgradeError::Timeout => {
+            outbound_hop::ReserveError::Io(io::ErrorKind::TimedOut.into())
+        }
+        StreamUpgradeError::Apply(never) => void::unreachable(never),
+        StreamUpgradeError::NegotiationFailed => outbound_hop::ReserveError::Unsupported,
+        StreamUpgradeError::Io(e) => outbound_hop::ReserveError::Io(e),
+    }
+}
+
+fn into_connect_error(e: StreamUpgradeError<Void>) -> outbound_hop::ConnectError {
+    match e {
+        StreamUpgradeError::Timeout => {
+            outbound_hop::ConnectError::Io(io::ErrorKind::TimedOut.into())
+        }
+        StreamUpgradeError::Apply(never) => void::unreachable(never),
+        StreamUpgradeError::NegotiationFailed => outbound_hop::ConnectError::Unsupported,
+        StreamUpgradeError::Io(e) => outbound_hop::ConnectError::Io(e),
+    }
 }
diff --git a/protocols/relay/src/protocol/outbound_hop.rs b/protocols/relay/src/protocol/outbound_hop.rs
index e5f9a6a0a52..3ae824be167 100644
--- a/protocols/relay/src/protocol/outbound_hop.rs
+++ b/protocols/relay/src/protocol/outbound_hop.rs
@@ -47,7 +47,7 @@ pub enum ConnectError {
     #[error("Remote does not support the `{HOP_PROTOCOL_NAME}` protocol")]
     Unsupported,
     #[error("IO error")]
-    Io(#[source] io::Error),
+    Io(#[from] io::Error),
     #[error("Protocol error")]
     Protocol(#[from] ProtocolViolation),
 }
@@ -61,7 +61,7 @@ pub enum ReserveError {
     #[error("Remote does not support the `{HOP_PROTOCOL_NAME}` protocol")]
     Unsupported,
     #[error("IO error")]
-    Io(#[source] io::Error),
+    Io(#[from] io::Error),
     #[error("Protocol error")]
     Protocol(#[from] ProtocolViolation),
 }

From ab9e7a0283207c9084aaf32012e3189bef03db4e Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 28 Nov 2023 21:48:33 +0000
Subject: [PATCH 03/12] deps: bump openssl from 0.10.55 to 0.10.60

Pull-Request: #4951.
---
 Cargo.lock | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index e91391a515a..0aea788d220 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3891,11 +3891,11 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
 
 [[package]]
 name = "openssl"
-version = "0.10.55"
+version = "0.10.60"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d"
+checksum = "79a4c6c3a2b158f7f8f2a2fc5a969fa3a068df6fc9dbb4a43845436e3af7c800"
 dependencies = [
- "bitflags 1.3.2",
+ "bitflags 2.4.1",
  "cfg-if",
  "foreign-types",
  "libc",
@@ -3923,9 +3923,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
 
 [[package]]
 name = "openssl-sys"
-version = "0.9.90"
+version = "0.9.96"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6"
+checksum = "3812c071ba60da8b5677cc12bcb1d42989a65553772897a7e0355545a819838f"
 dependencies = [
  "cc",
  "libc",

From bca3a264ff684d21c0bc92c7e793942c94e2e093 Mon Sep 17 00:00:00 2001
From: Doug A <douganderson444@gmail.com>
Date: Tue, 28 Nov 2023 22:52:51 -0500
Subject: [PATCH 04/12] fix(browser-webrtc-example): use `tracing-wasm` logger

Upgrade `wasm-logger` to `tracing-wasm`.

Related: #4950.

Pull-Request: #4952.
---
 Cargo.lock                         | 13 ++++++++++++-
 examples/browser-webrtc/Cargo.toml |  4 ++--
 examples/browser-webrtc/src/lib.rs |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 0aea788d220..e11c6ba5460 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -676,9 +676,9 @@ dependencies = [
  "tower-http",
  "tracing",
  "tracing-subscriber",
+ "tracing-wasm",
  "wasm-bindgen",
  "wasm-bindgen-futures",
- "wasm-logger",
  "web-sys",
 ]
 
@@ -5967,6 +5967,17 @@ dependencies = [
  "tracing-log 0.2.0",
 ]
 
+[[package]]
+name = "tracing-wasm"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4575c663a174420fa2d78f4108ff68f65bf2fbb7dd89f33749b6e826b3626e07"
+dependencies = [
+ "tracing",
+ "tracing-subscriber",
+ "wasm-bindgen",
+]
+
 [[package]]
 name = "try-lock"
 version = "0.2.4"
diff --git a/examples/browser-webrtc/Cargo.toml b/examples/browser-webrtc/Cargo.toml
index 2607d0c1056..57232abeb5e 100644
--- a/examples/browser-webrtc/Cargo.toml
+++ b/examples/browser-webrtc/Cargo.toml
@@ -24,7 +24,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
 
 [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
 axum = "0.6.19"
-libp2p = { path = "../../libp2p", features = [ "ed25519", "macros", "ping", "wasm-bindgen", "tokio"] }
+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"] }
@@ -37,9 +37,9 @@ mime_guess = "2.0.4"
 js-sys = "0.3.66"
 libp2p = { path = "../../libp2p", features = [ "ed25519", "macros", "ping", "wasm-bindgen"] }
 libp2p-webrtc-websys = { workspace = true }
+tracing-wasm = "0.2.1"
 wasm-bindgen = "0.2.89"
 wasm-bindgen-futures = "0.4.38"
-wasm-logger = { version = "0.2.0" }
 web-sys = { version = "0.3", features = ['Document', 'Element', 'HtmlElement', 'Node', 'Response', 'Window'] }
 
 [lints]
diff --git a/examples/browser-webrtc/src/lib.rs b/examples/browser-webrtc/src/lib.rs
index 609d72479c4..2112919c6de 100644
--- a/examples/browser-webrtc/src/lib.rs
+++ b/examples/browser-webrtc/src/lib.rs
@@ -13,7 +13,7 @@ use web_sys::{Document, HtmlElement};
 
 #[wasm_bindgen]
 pub async fn run(libp2p_endpoint: String) -> Result<(), JsError> {
-    wasm_logger::init(wasm_logger::Config::default());
+    tracing_wasm::set_as_global_default();
 
     let body = Body::from_current_window()?;
     body.append_p("Let's ping the WebRTC Server!")?;

From 0810672d0fb98d0109f4dcf9be00d6a10e2d2e6c Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Wed, 29 Nov 2023 04:04:45 +0000
Subject: [PATCH 05/12] deps: bump aes-gcm from 0.10.2 to 0.10.3

Pull-Request: #4955.
---
 Cargo.lock | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index e11c6ba5460..617d54e9b2b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -40,9 +40,9 @@ dependencies = [
 
 [[package]]
 name = "aes-gcm"
-version = "0.10.2"
+version = "0.10.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "209b47e8954a928e1d72e86eca7000ebb6655fe1436d33eefc2201cad027e237"
+checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1"
 dependencies = [
  "aead",
  "aes",

From dfd66f918d6298af535e14367d7a901a0717284f Mon Sep 17 00:00:00 2001
From: Jiyuan Zheng <jiyuanz95@gmail.com>
Date: Tue, 28 Nov 2023 22:17:50 -0600
Subject: [PATCH 06/12] fix(tutorial): import dependencies via meta crate

Pull-Request: #4949.
---
 libp2p/src/tutorials/ping.rs | 54 +++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 29 deletions(-)

diff --git a/libp2p/src/tutorials/ping.rs b/libp2p/src/tutorials/ping.rs
index db515595bfc..1413531cd72 100644
--- a/libp2p/src/tutorials/ping.rs
+++ b/libp2p/src/tutorials/ping.rs
@@ -55,7 +55,7 @@
 //!        edition = "2021"
 //!
 //!    [dependencies]
-//!        libp2p = { version = "0.52", features = ["tcp", "dns", "async-std", "noise", "yamux", "websocket", "ping", "macros"] }
+//!        libp2p = { version = "0.52", features = ["tcp", "tls", "dns", "async-std", "noise", "yamux", "websocket", "ping", "macros"] }
 //!        futures = "0.3.21"
 //!        async-std = { version = "1.12.0", features = ["attributes"] }
 //!        tracing-subscriber = { version = "0.3", features = ["env-filter"] }
@@ -95,7 +95,6 @@
 //! trait.
 //!
 //! ```rust
-//! use libp2p::{identity, PeerId};
 //! use std::error::Error;
 //! use tracing_subscriber::EnvFilter;
 //!
@@ -106,9 +105,9 @@
 //!     let mut swarm = libp2p::SwarmBuilder::with_new_identity()
 //!         .with_async_std()
 //!         .with_tcp(
-//!             libp2p_tcp::Config::default(),
-//!             libp2p_tls::Config::new,
-//!             libp2p_yamux::Config::default,
+//!             libp2p::tcp::Config::default(),
+//!             libp2p::tls::Config::new,
+//!             libp2p::yamux::Config::default,
 //!         )?;
 //!
 //!     Ok(())
@@ -138,8 +137,7 @@
 //! With the above in mind, let's extend our example, creating a [`ping::Behaviour`](crate::ping::Behaviour) at the end:
 //!
 //! ```rust
-//! use libp2p::swarm::NetworkBehaviour;
-//! use libp2p::{identity, ping, PeerId};
+//! use libp2p::ping;
 //! use tracing_subscriber::EnvFilter;
 //! use std::error::Error;
 //!
@@ -150,9 +148,9 @@
 //!     let mut swarm = libp2p::SwarmBuilder::with_new_identity()
 //!         .with_async_std()
 //!         .with_tcp(
-//!             libp2p_tcp::Config::default(),
-//!             libp2p_tls::Config::new,
-//!             libp2p_yamux::Config::default,
+//!             libp2p::tcp::Config::default(),
+//!             libp2p::tls::Config::new,
+//!             libp2p::yamux::Config::default,
 //!         )?
 //!         .with_behaviour(|_| ping::Behaviour::default())?;
 //!
@@ -168,8 +166,7 @@
 //! to the [`Transport`] as well as events from the [`Transport`] to the [`NetworkBehaviour`].
 //!
 //! ```rust
-//! use libp2p::swarm::NetworkBehaviour;
-//! use libp2p::{identity, ping, PeerId};
+//! use libp2p::ping;
 //! use std::error::Error;
 //! use tracing_subscriber::EnvFilter;
 //!
@@ -180,9 +177,9 @@
 //!     let mut swarm = libp2p::SwarmBuilder::with_new_identity()
 //!         .with_async_std()
 //!         .with_tcp(
-//!             libp2p_tcp::Config::default(),
-//!             libp2p_tls::Config::new,
-//!             libp2p_yamux::Config::default,
+//!             libp2p::tcp::Config::default(),
+//!             libp2p::tls::Config::new,
+//!             libp2p::yamux::Config::default,
 //!         )?
 //!         .with_behaviour(|_| ping::Behaviour::default())?
 //!         .build();
@@ -202,8 +199,7 @@
 //! Thus, without any other behaviour in place, we would not be able to observe the pings.
 //!
 //! ```rust
-//! use libp2p::swarm::NetworkBehaviour;
-//! use libp2p::{identity, ping, PeerId};
+//! use libp2p::ping;
 //! use std::error::Error;
 //! use std::time::Duration;
 //! use tracing_subscriber::EnvFilter;
@@ -215,9 +211,9 @@
 //!     let mut swarm = libp2p::SwarmBuilder::with_new_identity()
 //!         .with_async_std()
 //!         .with_tcp(
-//!             libp2p_tcp::Config::default(),
-//!             libp2p_tls::Config::new,
-//!             libp2p_yamux::Config::default,
+//!             libp2p::tcp::Config::default(),
+//!             libp2p::tls::Config::new,
+//!             libp2p::yamux::Config::default,
 //!         )?
 //!         .with_behaviour(|_| ping::Behaviour::default())?
 //!         .with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(30))) // Allows us to observe pings for 30 seconds.
@@ -254,7 +250,7 @@
 //! remote peer.
 //!
 //! ```rust
-//! use libp2p::{identity, ping, Multiaddr, PeerId};
+//! use libp2p::{ping, Multiaddr};
 //! use std::error::Error;
 //! use std::time::Duration;
 //! use tracing_subscriber::EnvFilter;
@@ -266,9 +262,9 @@
 //!     let mut swarm = libp2p::SwarmBuilder::with_new_identity()
 //!         .with_async_std()
 //!         .with_tcp(
-//!             libp2p_tcp::Config::default(),
-//!             libp2p_tls::Config::new,
-//!             libp2p_yamux::Config::default,
+//!             libp2p::tcp::Config::default(),
+//!             libp2p::tls::Config::new,
+//!             libp2p::yamux::Config::default,
 //!         )?
 //!         .with_behaviour(|_| ping::Behaviour::default())?
 //!         .with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(30))) // Allows us to observe pings for 30 seconds.
@@ -298,8 +294,8 @@
 //!
 //! ```no_run
 //! use futures::prelude::*;
-//! use libp2p::swarm::{NetworkBehaviour, SwarmEvent};
-//! use libp2p::{identity, ping, Multiaddr, PeerId};
+//! use libp2p::swarm::SwarmEvent;
+//! use libp2p::{ping, Multiaddr};
 //! use std::error::Error;
 //! use std::time::Duration;
 //! use tracing_subscriber::EnvFilter;
@@ -311,9 +307,9 @@
 //!     let mut swarm = libp2p::SwarmBuilder::with_new_identity()
 //!         .with_async_std()
 //!         .with_tcp(
-//!             libp2p_tcp::Config::default(),
-//!             libp2p_tls::Config::new,
-//!             libp2p_yamux::Config::default,
+//!             libp2p::tcp::Config::default(),
+//!             libp2p::tls::Config::new,
+//!             libp2p::yamux::Config::default,
 //!         )?
 //!         .with_behaviour(|_| ping::Behaviour::default())?
 //!         .with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(30))) // Allows us to observe pings for 30 seconds.

From 543408bec68c6d8fdef352a1a2a41994af9a4ca3 Mon Sep 17 00:00:00 2001
From: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Date: Wed, 29 Nov 2023 00:37:30 -0500
Subject: [PATCH 07/12] 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.
---
 .github/workflows/ci.yml | 9 +++++++++
 1 file changed, 9 insertions(+)

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

From e889e2e446e32e29a6c979d4b37775181bb55455 Mon Sep 17 00:00:00 2001
From: Doug A <douganderson444@gmail.com>
Date: Wed, 29 Nov 2023 20:59:15 -0500
Subject: [PATCH 08/12] deps(webrtc): bump alpha versions

Bumps versions of `libp2p-webrtc` and `libp2p-webrtc-websys` up one minor version.

Fixes: #4953.

Pull-Request: #4959.
---
 Cargo.lock                            | 4 ++--
 Cargo.toml                            | 4 ++--
 transports/webrtc-websys/CHANGELOG.md | 5 +++++
 transports/webrtc-websys/Cargo.toml   | 2 +-
 transports/webrtc/CHANGELOG.md        | 5 +++++
 transports/webrtc/Cargo.toml          | 2 +-
 6 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 617d54e9b2b..3d4acf65eef 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3232,7 +3232,7 @@ dependencies = [
 
 [[package]]
 name = "libp2p-webrtc"
-version = "0.6.1-alpha"
+version = "0.7.0-alpha"
 dependencies = [
  "async-trait",
  "bytes",
@@ -3283,7 +3283,7 @@ dependencies = [
 
 [[package]]
 name = "libp2p-webrtc-websys"
-version = "0.2.0-alpha"
+version = "0.3.0-alpha"
 dependencies = [
  "bytes",
  "futures",
diff --git a/Cargo.toml b/Cargo.toml
index 346b316d4dc..c773d56a2a9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -106,9 +106,9 @@ 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 = { version = "0.7.0-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-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/transports/webrtc-websys/CHANGELOG.md b/transports/webrtc-websys/CHANGELOG.md
index 3cc263e2ce5..727faa2561b 100644
--- a/transports/webrtc-websys/CHANGELOG.md
+++ b/transports/webrtc-websys/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 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).
+
 ## 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..5aa0a90200e 100644
--- a/transports/webrtc-websys/Cargo.toml
+++ b/transports/webrtc-websys/Cargo.toml
@@ -8,7 +8,7 @@ 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]
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..214d6778bf0 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 <admin@parity.io>"]
 description = "WebRTC transport for libp2p"
 repository = "https://github.com/libp2p/rust-libp2p"

From 7b7cf5f5c1e49cbb7ae7f09b7f2203890f4aa664 Mon Sep 17 00:00:00 2001
From: Darius Clark <dariusc93@users.noreply.github.com>
Date: Thu, 30 Nov 2023 02:20:25 -0500
Subject: [PATCH 09/12] feat(request-response): derive `PartialOrd`,`Ord` for
 `{Out,In}RequestId`

Pull-Request: #4956.
---
 Cargo.lock                              | 2 +-
 Cargo.toml                              | 2 +-
 protocols/request-response/CHANGELOG.md | 5 +++++
 protocols/request-response/Cargo.toml   | 2 +-
 protocols/request-response/src/lib.rs   | 4 ++--
 5 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 3d4acf65eef..349d0e9a82a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3057,7 +3057,7 @@ dependencies = [
 
 [[package]]
 name = "libp2p-request-response"
-version = "0.26.0"
+version = "0.26.1"
 dependencies = [
  "anyhow",
  "async-std",
diff --git a/Cargo.toml b/Cargo.toml
index c773d56a2a9..b48088f6218 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -97,7 +97,7 @@ libp2p-pnet = { version = "0.24.0", path = "transports/pnet" }
 libp2p-quic = { version = "0.10.1", 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-request-response = { version = "0.26.1", 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.
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 <admin@parity.io>"]
 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<TResponse> ResponseChannel<TResponse> {
 ///
 /// 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 {

From ec2258e36e20dc8e933ddc68a0f83ef3f3b48545 Mon Sep 17 00:00:00 2001
From: zhiqiangxu <652732310@qq.com>
Date: Thu, 30 Nov 2023 15:38:58 +0800
Subject: [PATCH 10/12] refactor(connection-limits): make `check_limit` a
 free-function

Pull-Request: #4958.
---
 misc/connection-limits/src/lib.rs | 37 +++++++++++++------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs
index af76e9a57d9..cb12599ad79 100644
--- a/misc/connection-limits/src/lib.rs
+++ b/misc/connection-limits/src/lib.rs
@@ -79,22 +79,17 @@ impl Behaviour {
             established_per_peer: Default::default(),
         }
     }
+}
 
-    fn check_limit(
-        &mut self,
-        limit: Option<u32>,
-        current: usize,
-        kind: Kind,
-    ) -> Result<(), ConnectionDenied> {
-        let limit = limit.unwrap_or(u32::MAX);
-        let current = current as u32;
+fn check_limit(limit: Option<u32>, current: usize, kind: Kind) -> Result<(), ConnectionDenied> {
+    let limit = limit.unwrap_or(u32::MAX);
+    let current = current as u32;
 
-        if current >= limit {
-            return Err(ConnectionDenied::new(Exceeded { limit, kind }));
-        }
-
-        Ok(())
+    if current >= limit {
+        return Err(ConnectionDenied::new(Exceeded { limit, kind }));
     }
+
+    Ok(())
 }
 
 /// A connection limit has been exceeded.
@@ -210,7 +205,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 +225,12 @@ impl NetworkBehaviour for Behaviour {
     ) -> Result<THandler<Self>, 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 +238,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 +255,7 @@ impl NetworkBehaviour for Behaviour {
         _: &[Multiaddr],
         _: Endpoint,
     ) -> Result<Vec<Multiaddr>, ConnectionDenied> {
-        self.check_limit(
+        check_limit(
             self.limits.max_pending_outgoing,
             self.pending_outbound_connections.len(),
             Kind::PendingOutgoing,
@@ -280,12 +275,12 @@ impl NetworkBehaviour for Behaviour {
     ) -> Result<THandler<Self>, 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 +288,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(),

From 6d21e6ed7f208c1ed2ba840a739f2445faaa5e5a Mon Sep 17 00:00:00 2001
From: Thomas Eizinger <thomas@eizinger.io>
Date: Fri, 1 Dec 2023 17:51:26 +1100
Subject: [PATCH 11/12] 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.
---
 Cargo.lock                     | 2 +-
 Cargo.toml                     | 2 +-
 misc/webrtc-utils/CHANGELOG.md | 5 +++++
 misc/webrtc-utils/Cargo.toml   | 2 +-
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 349d0e9a82a..825217393f2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3261,7 +3261,7 @@ dependencies = [
 
 [[package]]
 name = "libp2p-webrtc-utils"
-version = "0.1.0"
+version = "0.2.0"
 dependencies = [
  "asynchronous-codec",
  "bytes",
diff --git a/Cargo.toml b/Cargo.toml
index b48088f6218..1e243c418eb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -107,7 +107,7 @@ 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.7.0-alpha", path = "transports/webrtc" }
-libp2p-webrtc-utils = { version = "0.1.0", path = "misc/webrtc-utils" }
+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" }
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]

From c1925e5e612bd609e57d6ac50a7b28cf16a1aa2c Mon Sep 17 00:00:00 2001
From: Thomas Eizinger <thomas@eizinger.io>
Date: Fri, 1 Dec 2023 18:01:27 +1100
Subject: [PATCH 12/12] 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.
---
 Cargo.lock                              | 1 -
 misc/webrtc-utils/src/noise.rs          | 6 ++++--
 transports/webrtc-websys/CHANGELOG.md   | 2 ++
 transports/webrtc-websys/Cargo.toml     | 1 -
 transports/webrtc-websys/src/error.rs   | 9 +++++++--
 transports/webrtc-websys/src/upgrade.rs | 5 ++++-
 6 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 825217393f2..3d6031af9cf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3294,7 +3294,6 @@ dependencies = [
  "js-sys",
  "libp2p-core",
  "libp2p-identity",
- "libp2p-noise",
  "libp2p-ping",
  "libp2p-swarm",
  "libp2p-webrtc-utils",
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<T>(
     id_keys: identity::Keypair,
     stream: T,
     client_fingerprint: Fingerprint,
     server_fingerprint: Fingerprint,
-) -> Result<PeerId, libp2p_noise::Error>
+) -> Result<PeerId, Error>
 where
     T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
 {
@@ -54,7 +56,7 @@ pub async fn outbound<T>(
     stream: T,
     server_fingerprint: Fingerprint,
     client_fingerprint: Fingerprint,
-) -> Result<PeerId, libp2p_noise::Error>
+) -> Result<PeerId, Error>
 where
     T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
 {
diff --git a/transports/webrtc-websys/CHANGELOG.md b/transports/webrtc-websys/CHANGELOG.md
index 727faa2561b..634120c53c3 100644
--- a/transports/webrtc-websys/CHANGELOG.md
+++ b/transports/webrtc-websys/CHANGELOG.md
@@ -2,6 +2,8 @@
 
 - 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
 
diff --git a/transports/webrtc-websys/Cargo.toml b/transports/webrtc-websys/Cargo.toml
index 5aa0a90200e..a5eb8f0b14d 100644
--- a/transports/webrtc-websys/Cargo.toml
+++ b/transports/webrtc-websys/Cargo.toml
@@ -20,7 +20,6 @@ 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"] }
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::<js_sys::Error>() {
@@ -38,7 +43,7 @@ impl Error {
     }
 }
 
-impl std::convert::From<wasm_bindgen::JsValue> for Error {
+impl From<JsValue> 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");