diff --git a/Cargo.toml b/Cargo.toml index 7b49c5846c2..8fc0e8330fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,7 +108,7 @@ smallvec = "1.6.1" libp2p-deflate = { version = "0.35.0", path = "transports/deflate", optional = true } libp2p-dns = { version = "0.35.0", path = "transports/dns", optional = true, default-features = false } libp2p-mdns = { version = "0.39.0", path = "protocols/mdns", optional = true, default-features = false } -libp2p-tcp = { version = "0.34.0", path = "transports/tcp", default-features = false, optional = true } +libp2p-tcp = { version = "0.35.0", path = "transports/tcp", default-features = false, optional = true } libp2p-websocket = { version = "0.37.0", path = "transports/websocket", optional = true } [target.'cfg(not(target_os = "unknown"))'.dependencies] diff --git a/README.md b/README.md index fb45ac38c10..6e668184a8b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![dependency status](https://deps.rs/repo/github/libp2p/rust-libp2p/status.svg?style=flat-square)](https://deps.rs/repo/github/libp2p/rust-libp2p) +[![Crates.io](https://img.shields.io/crates/v/libp2p.svg)](https://crates.io/crates/libp2p) +[![docs.rs](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/libp2p) This repository is the central place for Rust development of the [libp2p](https://libp2p.io) spec. diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 0102096d780..047a7ac40e2 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -2,8 +2,13 @@ - Remove `StreamMuxer::poll_event` in favor of individual functions: `poll_inbound`, `poll_outbound` and `poll_address_change`. Consequently, `StreamMuxerEvent` is also removed. See [PR 2724]. +- Drop `Unpin` requirement from `SubstreamBox`. See [PR 2762] and [PR 2776]. +- Drop `Sync` requirement on `StreamMuxer` for constructing `StreamMuxerBox`. See [PR 2775]. [PR 2724]: https://github.com/libp2p/rust-libp2p/pull/2724 +[PR 2762]: https://github.com/libp2p/rust-libp2p/pull/2762 +[PR 2775]: https://github.com/libp2p/rust-libp2p/pull/2775 +[PR 2776]: https://github.com/libp2p/rust-libp2p/pull/2776 # 0.34.0 diff --git a/core/src/identity/ecdsa.rs b/core/src/identity/ecdsa.rs index b883243b13b..81dfec4b4e0 100644 --- a/core/src/identity/ecdsa.rs +++ b/core/src/identity/ecdsa.rs @@ -157,7 +157,7 @@ impl PublicKey { let buf = Self::del_asn1_header(k).ok_or_else(|| { DecodingError::new("failed to parse asn.1 encoded ecdsa p256 public key") })?; - Self::from_bytes(&buf) + Self::from_bytes(buf) } // ecPublicKey (ANSI X9.62 public key type) OID: 1.2.840.10045.2.1 @@ -198,8 +198,8 @@ impl PublicKey { if asn1_head[0] != 0x30 || asn1_head[2] != 0x30 || asn1_head[3] as usize != oids_len - || &oids_buf[..Self::EC_PUBLIC_KEY_OID.len()] != &Self::EC_PUBLIC_KEY_OID - || &oids_buf[Self::EC_PUBLIC_KEY_OID.len()..] != &Self::SECP_256_R1_OID + || oids_buf[..Self::EC_PUBLIC_KEY_OID.len()] != Self::EC_PUBLIC_KEY_OID + || oids_buf[Self::EC_PUBLIC_KEY_OID.len()..] != Self::SECP_256_R1_OID || bitstr_head[0] != 0x03 || bitstr_head[2] != 0x00 { diff --git a/core/src/muxing/boxed.rs b/core/src/muxing/boxed.rs index 80753813dcb..8c6467dd7ad 100644 --- a/core/src/muxing/boxed.rs +++ b/core/src/muxing/boxed.rs @@ -10,14 +10,14 @@ use std::task::{Context, Poll}; /// Abstract `StreamMuxer`. pub struct StreamMuxerBox { - inner: Box + Send + Sync>, + inner: Box + Send>, } /// Abstract type for asynchronous reading and writing. /// /// A [`SubstreamBox`] erases the concrete type it is given and only retains its `AsyncRead` /// and `AsyncWrite` capabilities. -pub struct SubstreamBox(Box); +pub struct SubstreamBox(Pin>); struct Wrap where @@ -29,7 +29,7 @@ where impl StreamMuxer for Wrap where T: StreamMuxer, - T::Substream: Send + Unpin + 'static, + T::Substream: Send + 'static, T::Error: Send + Sync + 'static, { type Substream = SubstreamBox; @@ -70,8 +70,8 @@ impl StreamMuxerBox { /// Turns a stream muxer into a `StreamMuxerBox`. pub fn new(muxer: T) -> StreamMuxerBox where - T: StreamMuxer + Send + Sync + 'static, - T::Substream: Send + Unpin + 'static, + T: StreamMuxer + Send + 'static, + T::Substream: Send + 'static, T::Error: Send + Sync + 'static, { let wrap = Wrap { inner: muxer }; @@ -106,8 +106,8 @@ impl StreamMuxer for StreamMuxerBox { impl SubstreamBox { /// Construct a new [`SubstreamBox`] from something that implements [`AsyncRead`] and [`AsyncWrite`]. - pub fn new(stream: S) -> Self { - Self(Box::new(stream)) + pub fn new(stream: S) -> Self { + Self(Box::pin(stream)) } } @@ -118,7 +118,7 @@ impl fmt::Debug for SubstreamBox { } /// Workaround because Rust does not allow `Box`. -trait AsyncReadWrite: AsyncRead + AsyncWrite + Unpin { +trait AsyncReadWrite: AsyncRead + AsyncWrite { /// Helper function to capture the erased inner type. /// /// Used to make the [`Debug`] implementation of [`SubstreamBox`] more useful. @@ -127,7 +127,7 @@ trait AsyncReadWrite: AsyncRead + AsyncWrite + Unpin { impl AsyncReadWrite for S where - S: AsyncRead + AsyncWrite + Unpin, + S: AsyncRead + AsyncWrite, { fn type_name(&self) -> &'static str { std::any::type_name::() @@ -136,44 +136,44 @@ where impl AsyncRead for SubstreamBox { fn poll_read( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll> { - Pin::new(&mut self.get_mut().0).poll_read(cx, buf) + self.0.as_mut().poll_read(cx, buf) } fn poll_read_vectored( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], ) -> Poll> { - Pin::new(&mut self.get_mut().0).poll_read_vectored(cx, bufs) + self.0.as_mut().poll_read_vectored(cx, bufs) } } impl AsyncWrite for SubstreamBox { fn poll_write( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll> { - Pin::new(&mut self.get_mut().0).poll_write(cx, buf) + self.0.as_mut().poll_write(cx, buf) } fn poll_write_vectored( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll> { - Pin::new(&mut self.get_mut().0).poll_write_vectored(cx, bufs) + self.0.as_mut().poll_write_vectored(cx, bufs) } - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - Pin::new(&mut self.get_mut().0).poll_flush(cx) + fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + self.0.as_mut().poll_flush(cx) } - fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - Pin::new(&mut self.get_mut().0).poll_close(cx) + fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + self.0.as_mut().poll_close(cx) } } diff --git a/core/src/transport/upgrade.rs b/core/src/transport/upgrade.rs index da87fb9dd6a..8fc0454794f 100644 --- a/core/src/transport/upgrade.rs +++ b/core/src/transport/upgrade.rs @@ -299,8 +299,8 @@ impl Multiplexed { T::Dial: Send + 'static, T::ListenerUpgrade: Send + 'static, T::Error: Send + Sync, - M: StreamMuxer + Send + Sync + 'static, - M::Substream: Send + Unpin + 'static, + M: StreamMuxer + Send + 'static, + M::Substream: Send + 'static, M::Error: Send + Sync + 'static, { boxed(self.map(|(i, m), _| (i, StreamMuxerBox::new(m)))) diff --git a/core/tests/transport_upgrade.rs b/core/tests/transport_upgrade.rs index ecba64dfb2f..723a04b0780 100644 --- a/core/tests/transport_upgrade.rs +++ b/core/tests/transport_upgrade.rs @@ -18,8 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -mod util; - use futures::prelude::*; use libp2p_core::identity; use libp2p_core::transport::{MemoryTransport, Transport}; @@ -91,11 +89,6 @@ fn upgrade_pipeline() { .apply(HelloUpgrade {}) .apply(HelloUpgrade {}) .multiplex(MplexConfig::default()) - .and_then(|(peer, mplex), _| { - // Gracefully close the connection to allow protocol - // negotiation to complete. - util::CloseMuxer::new(mplex).map_ok(move |mplex| (peer, mplex)) - }) .boxed(); let dialer_keys = identity::Keypair::generate_ed25519(); @@ -110,11 +103,6 @@ fn upgrade_pipeline() { .apply(HelloUpgrade {}) .apply(HelloUpgrade {}) .multiplex(MplexConfig::default()) - .and_then(|(peer, mplex), _| { - // Gracefully close the connection to allow protocol - // negotiation to complete. - util::CloseMuxer::new(mplex).map_ok(move |mplex| (peer, mplex)) - }) .boxed(); let listen_addr1 = Multiaddr::from(Protocol::Memory(random::())); diff --git a/core/tests/util.rs b/core/tests/util.rs deleted file mode 100644 index 7ca52188a52..00000000000 --- a/core/tests/util.rs +++ /dev/null @@ -1,47 +0,0 @@ -#![allow(dead_code)] - -use futures::prelude::*; -use libp2p_core::muxing::StreamMuxer; -use std::{pin::Pin, task::Context, task::Poll}; - -pub struct CloseMuxer { - state: CloseMuxerState, -} - -impl CloseMuxer { - pub fn new(m: M) -> CloseMuxer { - CloseMuxer { - state: CloseMuxerState::Close(m), - } - } -} - -pub enum CloseMuxerState { - Close(M), - Done, -} - -impl Future for CloseMuxer -where - M: StreamMuxer, - M::Error: From, -{ - type Output = Result; - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - loop { - match std::mem::replace(&mut self.state, CloseMuxerState::Done) { - CloseMuxerState::Close(muxer) => { - if !muxer.poll_close(cx)?.is_ready() { - self.state = CloseMuxerState::Close(muxer); - return Poll::Pending; - } - return Poll::Ready(Ok(muxer)); - } - CloseMuxerState::Done => panic!(), - } - } - } -} - -impl Unpin for CloseMuxer {} diff --git a/misc/metrics/CHANGELOG.md b/misc/metrics/CHANGELOG.md index c9cc21a06f1..06e2163597e 100644 --- a/misc/metrics/CHANGELOG.md +++ b/misc/metrics/CHANGELOG.md @@ -16,6 +16,10 @@ - Update to `libp2p-core` `v0.35.0`. +- Update to `prometheus-client` `v0.17.0`. See [PR 2761]. + +[PR 2761]: https://github.com/libp2p/rust-libp2p/pull/2761/ + [PR 2734]: https://github.com/libp2p/rust-libp2p/pull/2734/ # 0.7.0 diff --git a/misc/metrics/Cargo.toml b/misc/metrics/Cargo.toml index 7fdfec733e0..7ccd259e535 100644 --- a/misc/metrics/Cargo.toml +++ b/misc/metrics/Cargo.toml @@ -26,7 +26,7 @@ libp2p-kad = { version = "0.39.0", path = "../../protocols/kad", optional = true libp2p-ping = { version = "0.38.0", path = "../../protocols/ping", optional = true } libp2p-relay = { version = "0.11.0", path = "../../protocols/relay", optional = true } libp2p-swarm = { version = "0.38.0", path = "../../swarm" } -prometheus-client = "0.16.0" +prometheus-client = "0.17.0" [target.'cfg(not(target_os = "unknown"))'.dependencies] libp2p-gossipsub = { version = "0.40.0", path = "../../protocols/gossipsub", optional = true } diff --git a/misc/metrics/src/identify.rs b/misc/metrics/src/identify.rs index b3ae5a75910..730528167a8 100644 --- a/misc/metrics/src/identify.rs +++ b/misc/metrics/src/identify.rs @@ -223,7 +223,7 @@ impl EncodeMetric for Protocols { |mut acc, (_, protocols)| { for protocol in protocols { let count = acc.entry(protocol.to_string()).or_default(); - *count = *count + 1; + *count += 1; } acc }, diff --git a/muxers/mplex/tests/async_write.rs b/muxers/mplex/tests/async_write.rs index 94d69cd7ff1..2c4a2d10f0d 100644 --- a/muxers/mplex/tests/async_write.rs +++ b/muxers/mplex/tests/async_write.rs @@ -22,7 +22,6 @@ use futures::future::poll_fn; use futures::{channel::oneshot, prelude::*}; use libp2p_core::{upgrade, StreamMuxer, Transport}; use libp2p_tcp::TcpTransport; -use std::sync::Arc; #[test] fn async_write() { @@ -72,7 +71,7 @@ fn async_write() { let mut transport = TcpTransport::default() .and_then(move |c, e| upgrade::apply(c, mplex, e, upgrade::Version::V1)); - let client = Arc::new(transport.dial(rx.await.unwrap()).unwrap().await.unwrap()); + let client = transport.dial(rx.await.unwrap()).unwrap().await.unwrap(); let mut inbound = poll_fn(|cx| client.poll_inbound(cx)).await.unwrap(); inbound.write_all(b"hello world").await.unwrap(); diff --git a/muxers/mplex/tests/two_peers.rs b/muxers/mplex/tests/two_peers.rs index 20812fde55c..2b976c12fea 100644 --- a/muxers/mplex/tests/two_peers.rs +++ b/muxers/mplex/tests/two_peers.rs @@ -22,7 +22,6 @@ use futures::future::poll_fn; use futures::{channel::oneshot, prelude::*}; use libp2p_core::{upgrade, StreamMuxer, Transport}; use libp2p_tcp::TcpTransport; -use std::sync::Arc; #[test] fn client_to_server_outbound() { @@ -73,7 +72,7 @@ fn client_to_server_outbound() { .and_then(move |c, e| upgrade::apply(c, mplex, e, upgrade::Version::V1)) .boxed(); - let client = Arc::new(transport.dial(rx.await.unwrap()).unwrap().await.unwrap()); + let client = transport.dial(rx.await.unwrap()).unwrap().await.unwrap(); let mut inbound = poll_fn(|cx| client.poll_inbound(cx)).await.unwrap(); inbound.write_all(b"hello world").await.unwrap(); inbound.close().await.unwrap(); @@ -108,17 +107,15 @@ fn client_to_server_inbound() { tx.send(addr).unwrap(); - let client = Arc::new( - transport - .next() - .await - .expect("some event") - .into_incoming() - .unwrap() - .0 - .await - .unwrap(), - ); + let client = transport + .next() + .await + .expect("some event") + .into_incoming() + .unwrap() + .0 + .await + .unwrap(); let mut inbound = poll_fn(|cx| client.poll_inbound(cx)).await.unwrap(); diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index f6b0902d306..233d3873e98 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -4,6 +4,10 @@ - Update to `libp2p-core` `v0.35.0`. +- Update to `prometheus-client` `v0.17.0`. See [PR 2761]. + +[PR 2761]: https://github.com/libp2p/rust-libp2p/pull/2761/ + # 0.39.0 - Update to `libp2p-core` `v0.34.0`. diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index e992fb3b9ef..da97500808d 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -31,7 +31,7 @@ serde = { version = "1", optional = true, features = ["derive"] } wasm-timer = "0.2.5" instant = "0.1.11" # Metrics dependencies -prometheus-client = "0.16.0" +prometheus-client = "0.17.0" [dev-dependencies] async-std = "1.6.3" diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index 7e765bb1f2b..b643fa95a2e 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -1,6 +1,7 @@ # 0.39.0 [unreleased] - Update to `libp2p-swarm` `v0.38.0`. +- Update to `if-watch` `v1.1.1`. - Allow users to choose between async-io and tokio runtime in the mdns protocol implementation. `async-io` is a default diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index badce945eb9..9ffbb273f72 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"] data-encoding = "2.3.2" dns-parser = "0.8.0" futures = "0.3.13" -if-watch = "1.0.0" +if-watch = "1.1.1" lazy_static = "1.4.0" libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } libp2p-swarm = { version = "0.38.0", path = "../../swarm" } diff --git a/transports/tcp/CHANGELOG.md b/transports/tcp/CHANGELOG.md index 4a9d0245b2b..bf7a5e0daba 100644 --- a/transports/tcp/CHANGELOG.md +++ b/transports/tcp/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.35.0 [unreleased] + +- Update to `libp2p-core` `v0.35.0`. + +- Update to `if-watch` `v1.1.1`. + # 0.34.0 - Update to `libp2p-core` `v0.34.0`. diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 0b86689fa32..7273db58c51 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-tcp" edition = "2021" rust-version = "1.56.1" description = "TCP/IP transport protocol for libp2p" -version = "0.34.0" +version = "0.35.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"] async-io-crate = { package = "async-io", version = "1.2.0", optional = true } futures = "0.3.8" futures-timer = "3.0" -if-watch = { version = "1.0.0", optional = true } +if-watch = { version = "1.1.1", optional = true } if-addrs = { version = "0.7.0", optional = true } ipnet = "2.0.0" libc = "0.2.80" diff --git a/transports/tcp/src/provider/tokio.rs b/transports/tcp/src/provider/tokio.rs index fa9ebe3b3ff..564eebfa48b 100644 --- a/transports/tcp/src/provider/tokio.rs +++ b/transports/tcp/src/provider/tokio.rs @@ -155,9 +155,9 @@ impl Provider for Tcp { #[derive(Debug)] pub struct TcpStream(pub tokio_crate::net::TcpStream); -impl Into for TcpStream { - fn into(self: TcpStream) -> tokio_crate::net::TcpStream { - self.0 +impl From for tokio_crate::net::TcpStream { + fn from(t: TcpStream) -> tokio_crate::net::TcpStream { + t.0 } }