From 0be58329a9a913b1a7724ebda6473ced6e9ec4fe Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 1 Dec 2023 17:34:36 +1100 Subject: [PATCH 1/3] Hide `libp2p_noise` from the public API --- Cargo.lock | 1 - misc/webrtc-utils/src/noise.rs | 6 ++++-- transports/webrtc-websys/Cargo.toml | 1 - transports/webrtc-websys/src/error.rs | 9 +++++++-- transports/webrtc-websys/src/upgrade.rs | 5 ++++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 349d0e9a82a..d80a69d8415 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( 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/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::() { @@ -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"); From 404978ec52a5b78678e006f569224b0de7856ad4 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 1 Dec 2023 17:38:34 +1100 Subject: [PATCH 2/3] Add changelog entry --- transports/webrtc-websys/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/transports/webrtc-websys/CHANGELOG.md b/transports/webrtc-websys/CHANGELOG.md index 727faa2561b..4ebb212d78e 100644 --- a/transports/webrtc-websys/CHANGELOG.md +++ b/transports/webrtc-websys/CHANGELOG.md @@ -2,6 +2,7 @@ - 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. ## 0.2.0-alpha From ef81d7d01ac2a40d7ed0af4ce9f07e6be025c01e Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 1 Dec 2023 17:41:08 +1100 Subject: [PATCH 3/3] Update transports/webrtc-websys/CHANGELOG.md --- transports/webrtc-websys/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/transports/webrtc-websys/CHANGELOG.md b/transports/webrtc-websys/CHANGELOG.md index 4ebb212d78e..634120c53c3 100644 --- a/transports/webrtc-websys/CHANGELOG.md +++ b/transports/webrtc-websys/CHANGELOG.md @@ -3,6 +3,7 @@ - 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