Skip to content

Commit

Permalink
WIP on (no branch): 83c6795 *: Prepare v0.48.0 (libp2p#2869)
Browse files Browse the repository at this point in the history
  • Loading branch information
binier committed May 30, 2023
1 parent 3c5940a commit ff91a87
Show file tree
Hide file tree
Showing 14 changed files with 569 additions and 17 deletions.
22 changes: 20 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions core/CHANGELOG.md
Expand Up @@ -352,9 +352,9 @@

## 0.24.0 [2020-11-09]

- Remove `ConnectionInfo` trait and replace it with `PeerId`
- Remove `Connection` trait and replace it with `PeerId`
everywhere. This was already effectively the case because
`ConnectionInfo` was implemented on `PeerId`.
`Connection` was implemented on `PeerId`.

## 0.23.1 [2020-10-20]

Expand Down
14 changes: 14 additions & 0 deletions core/src/connection.rs
Expand Up @@ -20,6 +20,20 @@

use crate::multiaddr::{Multiaddr, Protocol};

pub trait Connection {
/// Should be `Some(_)` if transport itself handles authentication.
fn remote_peer_id(&self) -> Option<crate::PeerId> {
None
}
}

impl<C> Connection for multistream_select::Negotiated<C>
where C: Connection {
fn remote_peer_id(&self) -> Option<crate::PeerId> {
self.inner_completed_io().and_then(|io| io.remote_peer_id())
}
}

/// The endpoint roles associated with a peer-to-peer communication channel.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Endpoint {
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Expand Up @@ -118,7 +118,7 @@ pub type PeerId = libp2p_identity::PeerId;
#[deprecated(since = "0.39.0", note = "Depend on `libp2p-identity` instead.")]
pub type ParseError = libp2p_identity::ParseError;

pub use connection::{ConnectedPoint, Endpoint};
pub use connection::{ConnectedPoint, Connection, Endpoint};
pub use multiaddr::Multiaddr;
pub use multihash;
pub use muxing::StreamMuxer;
Expand Down
3 changes: 2 additions & 1 deletion libp2p/src/lib.rs
Expand Up @@ -65,7 +65,8 @@ pub use libp2p_dns as dns;
#[doc(inline)]
pub use libp2p_floodsub as floodsub;
#[cfg(feature = "gossipsub")]
#[cfg(not(target_os = "unknown"))]
#[cfg_attr(docsrs, doc(cfg(feature = "gossipsub")))]
// #[cfg(not(target_os = "unknown"))]
#[doc(inline)]
pub use libp2p_gossipsub as gossipsub;
#[cfg(feature = "identify")]
Expand Down
9 changes: 9 additions & 0 deletions misc/multistream-select/src/negotiated.rs
Expand Up @@ -51,6 +51,15 @@ pub struct Negotiated<TInner> {
state: State<TInner>,
}

impl<TInner> Negotiated<TInner> {
pub fn inner_completed_io(&self) -> Option<&TInner> {
match &self.state {
State::Completed { io } => Some(io),
_ => None
}
}
}

/// A `Future` that waits on the completion of protocol negotiation.
#[derive(Debug)]
pub struct NegotiatedComplete<TInner> {
Expand Down
3 changes: 2 additions & 1 deletion protocols/gossipsub/Cargo.toml
Expand Up @@ -31,7 +31,8 @@ hex_fmt = "0.3.0"
regex = "1.7.3"
serde = { version = "1", optional = true, features = ["derive"] }
thiserror = "1.0"
wasm-timer = "0.2.5"
# wasm-timer = "0.2.5"
wasm-timer = { git = "https://github.com/fusetim/wasm-timer", branch = "tim-add-missing-methods" }
instant = "0.1.11"
# Metrics dependencies
prometheus-client = "0.19.0"
Expand Down
3 changes: 2 additions & 1 deletion transports/pnet/Cargo.toml
Expand Up @@ -17,6 +17,7 @@ salsa20 = "0.10"
sha3 = "0.10"
rand = "0.8"
pin-project = "1.0.2"
libp2p-core = { version = "0.39.0", path = "../../core", default-features = false }

[dev-dependencies]
libp2p-core = { path = "../../core", features = ["rsa", "ecdsa", "secp256k1"] }
Expand All @@ -29,7 +30,7 @@ libp2p-yamux = { path = "../../muxers/yamux" }
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
tokio = { version = "1.27.0", features = ["full"] }

# Passing arguments to the docsrs builder in order to properly document cfg's.
# Passing arguments to the docsrs builder in order to properly document cfg's.
# More information: https://docs.rs/about/builds#cross-compiling
[package.metadata.docs.rs]
all-features = true
Expand Down
9 changes: 9 additions & 0 deletions transports/pnet/src/crypt_writer.rs
Expand Up @@ -28,6 +28,8 @@ use pin_project::pin_project;
use salsa20::{cipher::StreamCipher, XSalsa20};
use std::{fmt, pin::Pin};

use libp2p_core::Connection;

/// A writer that encrypts and forwards to an inner writer
#[pin_project]
pub struct CryptWriter<W> {
Expand All @@ -37,6 +39,13 @@ pub struct CryptWriter<W> {
cipher: XSalsa20,
}

impl<C> Connection for CryptWriter<C>
where C: Connection {
fn remote_peer_id(&self) -> Option<libp2p_core::PeerId> {
self.inner.remote_peer_id()
}
}

impl<W: AsyncWrite> CryptWriter<W> {
/// Creates a new `CryptWriter` with the specified buffer capacity.
pub fn with_capacity(capacity: usize, inner: W, cipher: XSalsa20) -> CryptWriter<W> {
Expand Down
9 changes: 9 additions & 0 deletions transports/pnet/src/lib.rs
Expand Up @@ -48,6 +48,8 @@ use std::{
task::{Context, Poll},
};

use libp2p_core::Connection;

const KEY_SIZE: usize = 32;
const NONCE_SIZE: usize = 24;
const WRITE_BUFFER_SIZE: usize = 1024;
Expand Down Expand Up @@ -238,6 +240,13 @@ pub struct PnetOutput<S> {
read_cipher: XSalsa20,
}

impl<C> Connection for PnetOutput<C>
where C: Connection {
fn remote_peer_id(&self) -> Option<libp2p_core::PeerId> {
self.inner.remote_peer_id()
}
}

impl<S: AsyncRead + AsyncWrite> PnetOutput<S> {
fn new(inner: S, write_cipher: XSalsa20, read_cipher: XSalsa20) -> Self {
Self {
Expand Down
11 changes: 3 additions & 8 deletions transports/wasm-ext/Cargo.toml
Expand Up @@ -13,17 +13,12 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.28"
js-sys = "0.3.61"
libp2p-core = { version = "0.39.0", path = "../../core" }
libp2p-core = { version = "0.39.0", path = "../../core", default-features = false, features = ["ecdsa"] }
parity-send-wrapper = "0.1.0"
wasm-bindgen = "0.2.42"
wasm-bindgen-futures = "0.4.34"
x509-parser = "0.14.0"

[features]
websocket = []

# Passing arguments to the docsrs builder in order to properly document cfg's.
# More information: https://docs.rs/about/builds#cross-compiling
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
rustc-args = ["--cfg", "docsrs"]
webrtc = []
68 changes: 68 additions & 0 deletions transports/wasm-ext/src/dtls.rs
@@ -0,0 +1,68 @@
use libp2p_core::{Connection, InboundUpgrade, OutboundUpgrade, PeerId, UpgradeInfo};

#[derive(Debug, Clone)]
pub struct NonDTLSConnectionError;

impl std::fmt::Display for NonDTLSConnectionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Tried to authenticate using `DTLSAuthenticated` for non DTLS transport connection!")
}
}

impl std::error::Error for NonDTLSConnectionError {
}

#[derive(Clone)]
pub struct DTLSAuthenticated;


impl DTLSAuthenticated {
pub fn new() -> Self {
Self {}
}
}

impl UpgradeInfo for DTLSAuthenticated {
type Info = &'static str;
// type InfoIter = std::iter::Once<Self::Info>;
type InfoIter = std::iter::Empty<Self::Info>;

fn protocol_info(&self) -> Self::InfoIter {
std::iter::empty()
// std::iter::once("/dtls")
}
}

impl<C> InboundUpgrade<C> for DTLSAuthenticated
where
C: Connection,
{
type Output = (PeerId, C);
type Error = NonDTLSConnectionError;
type Future = std::future::Ready<Result<Self::Output, Self::Error>>;

fn upgrade_inbound(self, socket: C, _: Self::Info) -> Self::Future {
let peer_id_result = socket
.remote_peer_id()
.map(|id| (id, socket))
.ok_or(NonDTLSConnectionError);
std::future::ready(peer_id_result)
}
}

impl<C> OutboundUpgrade<C> for DTLSAuthenticated
where
C: Connection,
{
type Output = (PeerId, C);
type Error = NonDTLSConnectionError;
type Future = std::future::Ready<Result<Self::Output, Self::Error>>;

fn upgrade_outbound(self, socket: C, _: Self::Info) -> Self::Future {
let peer_id_result = socket
.remote_peer_id()
.map(|id| (id, socket))
.ok_or(NonDTLSConnectionError);
std::future::ready(peer_id_result)
}
}

0 comments on commit ff91a87

Please sign in to comment.