Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webrtc-websys): hide libp2p_noise from the public API #4969

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions misc/webrtc-utils/src/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand All @@ -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,
{
Expand Down
1 change: 1 addition & 0 deletions transports/webrtc-websys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved

## 0.2.0-alpha

Expand Down
1 change: 0 additions & 1 deletion transports/webrtc-websys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
9 changes: 7 additions & 2 deletions transports/webrtc-websys/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>() {
Expand All @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion transports/webrtc-websys/src/upgrade.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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");

Expand Down
Loading