From 31185039266198a4dd73071d178e02d64e0ace90 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 27 Oct 2023 16:04:26 +1100 Subject: [PATCH] chore(swarm): remove deprecated symbols Pull-Request: #4737. --- Cargo.lock | 12 - libp2p/src/tutorials/ping.rs | 7 +- protocols/gossipsub/src/lib.rs | 48 +--- protocols/request-response/src/cbor.rs | 2 +- swarm-derive/CHANGELOG.md | 3 + swarm-derive/Cargo.toml | 1 - swarm-derive/src/lib.rs | 16 -- swarm/CHANGELOG.md | 2 + swarm/src/handler.rs | 3 - swarm/src/lib.rs | 217 +----------------- swarm/tests/ui/fail/out_event_deprecation.rs | 21 -- .../ui/fail/out_event_deprecation.stderr | 12 - 12 files changed, 16 insertions(+), 328 deletions(-) delete mode 100644 swarm/tests/ui/fail/out_event_deprecation.rs delete mode 100644 swarm/tests/ui/fail/out_event_deprecation.stderr diff --git a/Cargo.lock b/Cargo.lock index cd78185085b..f4fd13cfccd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3070,7 +3070,6 @@ name = "libp2p-swarm-derive" version = "0.34.0" dependencies = [ "heck", - "proc-macro-warning", "proc-macro2", "quote", "syn 2.0.38", @@ -4150,17 +4149,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-warning" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b698b0b09d40e9b7c1a47b132d66a8b54bcd20583d9b6d06e4535e383b4405c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - [[package]] name = "proc-macro2" version = "1.0.69" diff --git a/libp2p/src/tutorials/ping.rs b/libp2p/src/tutorials/ping.rs index 11a5a40907b..b92d7b51c8a 100644 --- a/libp2p/src/tutorials/ping.rs +++ b/libp2p/src/tutorials/ping.rs @@ -165,7 +165,7 @@ //! to the [`Transport`] as well as events from the [`Transport`] to the [`NetworkBehaviour`]. //! //! ```rust -//! use libp2p::swarm::{NetworkBehaviour, SwarmBuilder}; +//! use libp2p::swarm::NetworkBehaviour; //! use libp2p::{identity, ping, PeerId}; //! use std::error::Error; //! @@ -198,7 +198,7 @@ //! Thus, without any other behaviour in place, we would not be able to observe the pings. //! //! ```rust -//! use libp2p::swarm::{NetworkBehaviour, SwarmBuilder}; +//! use libp2p::swarm::NetworkBehaviour; //! use libp2p::{identity, ping, PeerId}; //! use std::error::Error; //! use std::time::Duration; @@ -249,7 +249,6 @@ //! remote peer. //! //! ```rust -//! use libp2p::swarm::{NetworkBehaviour, SwarmBuilder}; //! use libp2p::{identity, ping, Multiaddr, PeerId}; //! use std::error::Error; //! use std::time::Duration; @@ -291,7 +290,7 @@ //! //! ```no_run //! use futures::prelude::*; -//! use libp2p::swarm::{NetworkBehaviour, SwarmEvent, SwarmBuilder}; +//! use libp2p::swarm::{NetworkBehaviour, SwarmEvent}; //! use libp2p::{identity, ping, Multiaddr, PeerId}; //! use std::error::Error; //! use std::time::Duration; diff --git a/protocols/gossipsub/src/lib.rs b/protocols/gossipsub/src/lib.rs index 1d70febf296..dcc67558be1 100644 --- a/protocols/gossipsub/src/lib.rs +++ b/protocols/gossipsub/src/lib.rs @@ -89,53 +89,7 @@ //! ## Example //! -//! An example of initialising a gossipsub compatible swarm: -//! -//! ``` -//! # use libp2p_gossipsub::Event; -//! # use libp2p_core::{transport::{Transport, MemoryTransport}, Multiaddr}; -//! # use libp2p_gossipsub::MessageAuthenticity; -//! # use libp2p_identity as identity; -//! let local_key = identity::Keypair::generate_ed25519(); -//! let local_peer_id = local_key.public().to_peer_id(); -//! -//! // Set up an encrypted TCP Transport over yamux -//! // This is test transport (memory). -//! let transport = MemoryTransport::default() -//! .upgrade(libp2p_core::upgrade::Version::V1) -//! .authenticate(libp2p_noise::Config::new(&local_key).unwrap()) -//! .multiplex(libp2p_yamux::Config::default()) -//! .boxed(); -//! -//! // Create a Gossipsub topic -//! let topic = libp2p_gossipsub::IdentTopic::new("example"); -//! -//! // Set the message authenticity - How we expect to publish messages -//! // Here we expect the publisher to sign the message with their key. -//! let message_authenticity = MessageAuthenticity::Signed(local_key); -//! -//! // Create a Swarm to manage peers and events -//! let mut swarm = { -//! // set default parameters for gossipsub -//! let gossipsub_config = libp2p_gossipsub::Config::default(); -//! // build a gossipsub network behaviour -//! let mut gossipsub: libp2p_gossipsub::Behaviour = -//! libp2p_gossipsub::Behaviour::new(message_authenticity, gossipsub_config).unwrap(); -//! // subscribe to the topic -//! gossipsub.subscribe(&topic); -//! // create the swarm (use an executor in a real example) -//! libp2p_swarm::SwarmBuilder::without_executor( -//! transport, -//! gossipsub, -//! local_peer_id, -//! ).build() -//! }; -//! -//! // Listen on a memory transport. -//! let memory: Multiaddr = libp2p_core::multiaddr::Protocol::Memory(10).into(); -//! let addr = swarm.listen_on(memory).unwrap(); -//! println!("Listening on {:?}", addr); -//! ``` +//! For an example on how to use gossipsub, see the [chat-example](https://github.com/libp2p/rust-libp2p/tree/master/examples/chat). #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] diff --git a/protocols/request-response/src/cbor.rs b/protocols/request-response/src/cbor.rs index ff56aa52ddf..f371f6149dc 100644 --- a/protocols/request-response/src/cbor.rs +++ b/protocols/request-response/src/cbor.rs @@ -25,7 +25,7 @@ /// /// ``` /// # use libp2p_request_response::{cbor, ProtocolSupport, self as request_response}; -/// # use libp2p_swarm::{StreamProtocol, SwarmBuilder}; +/// # use libp2p_swarm::StreamProtocol; /// #[derive(Debug, serde::Serialize, serde::Deserialize)] /// struct GreetRequest { /// name: String, diff --git a/swarm-derive/CHANGELOG.md b/swarm-derive/CHANGELOG.md index fc228b80a62..269c2f1af7f 100644 --- a/swarm-derive/CHANGELOG.md +++ b/swarm-derive/CHANGELOG.md @@ -2,6 +2,9 @@ - Adapt to interface changes in `libp2p-swarm`. See [PR 4706](https://github.com/libp2p/rust-libp2p/pull/4076). +- Remove supported for deprecated `#[behaviour(out_event = "...")]`. + To same functionality is available using `#[behaviour(to_swarm = "...")]` + See [PR 4737](https://github.com/libp2p/rust-libp2p/pull/4737). ## 0.33.0 diff --git a/swarm-derive/Cargo.toml b/swarm-derive/Cargo.toml index 322ffda0c1d..61aac588a80 100644 --- a/swarm-derive/Cargo.toml +++ b/swarm-derive/Cargo.toml @@ -17,7 +17,6 @@ proc-macro = true heck = "0.4" quote = "1.0" syn = { version = "2.0.38", default-features = false, features = ["clone-impls", "derive", "parsing", "printing", "proc-macro"] } -proc-macro-warning = "1.0.0" proc-macro2 = "1.0" # Passing arguments to the docsrs builder in order to properly document cfg's. diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index cbc81876c55..e8aa79d8470 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -28,7 +28,6 @@ use heck::ToUpperCamelCase; use proc_macro::TokenStream; use quote::quote; use syn::punctuated::Punctuated; -use syn::spanned::Spanned; use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Meta, Token}; /// Generates a delegating `NetworkBehaviour` implementation for the struct this is used for. See @@ -61,7 +60,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result syn::Result syn::Result, - deprecation_tokenstream: proc_macro2::TokenStream, } /// Parses the `value` of a key=value pair in the `#[behaviour]` attribute into the requested type. @@ -889,7 +884,6 @@ fn parse_attributes(ast: &DeriveInput) -> syn::Result { let mut attributes = BehaviourAttributes { prelude_path: syn::parse_quote! { ::libp2p::swarm::derive_prelude }, user_specified_out_event: None, - deprecation_tokenstream: proc_macro2::TokenStream::new(), }; for attr in ast @@ -909,16 +903,6 @@ fn parse_attributes(ast: &DeriveInput) -> syn::Result { } if meta.path().is_ident("to_swarm") || meta.path().is_ident("out_event") { - if meta.path().is_ident("out_event") { - let warning = proc_macro_warning::FormattedWarning::new_deprecated( - "out_event_renamed_to_to_swarm", - "The `out_event` attribute has been renamed to `to_swarm`.", - meta.span(), - ); - - attributes.deprecation_tokenstream = quote::quote! { #warning }; - } - let value = meta.require_name_value()?.value.require_str_lit()?; attributes.user_specified_out_event = Some(syn::parse_str(&value)?); diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 814d37cda8f..df85fbdcd49 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -16,6 +16,8 @@ See [PR 4715](https://github.com/libp2p/rust-libp2p/pull/4715). - Log `PeerId` of `Swarm` even when constructed with new `SwarmBuilder`. See [PR 4671](https://github.com/libp2p/rust-libp2p/pull/4671). +- Remove deprecated symbols. + See [PR 4737](https://github.com/libp2p/rust-libp2p/pull/4737). ## 0.43.6 diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index f1f0547f6d2..ea42f64cca9 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -668,9 +668,6 @@ impl } } -#[deprecated(note = "Renamed to `StreamUpgradeError`")] -pub type ConnectionHandlerUpgrErr = StreamUpgradeError; - /// Error that can happen on an outbound substream opening attempt. #[derive(Debug)] pub enum StreamUpgradeError { diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 65384a54c35..908936069e0 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -152,12 +152,6 @@ use std::{ task::{Context, Poll}, }; -/// Substream for which a protocol has been chosen. -/// -/// Implements the [`AsyncRead`] and [`AsyncWrite`] traits. -#[deprecated(note = "The 'substream' terminology is deprecated. Use 'Stream' instead")] -pub type NegotiatedSubstream = Stream; - /// Event generated by the [`NetworkBehaviour`] that the swarm will report back. type TBehaviourOutEvent = ::ToSwarm; @@ -411,7 +405,7 @@ where /// See also [`DialOpts`]. /// /// ``` - /// # use libp2p_swarm::SwarmBuilder; + /// # use libp2p_swarm::Swarm; /// # use libp2p_swarm::dial_opts::{DialOpts, PeerCondition}; /// # use libp2p_core::{Multiaddr, Transport}; /// # use libp2p_core::transport::dummy::DummyTransport; @@ -420,11 +414,7 @@ where /// # /// # #[tokio::main] /// # async fn main() { - /// let mut swarm = SwarmBuilder::with_tokio_executor( - /// DummyTransport::new().boxed(), - /// dummy::Behaviour, - /// PeerId::random(), - /// ).build(); + /// let mut swarm = build_swarm(); /// /// // Dial a known peer. /// swarm.dial(PeerId::random()); @@ -432,6 +422,10 @@ where /// // Dial an unknown peer. /// swarm.dial("/ip6/::1/tcp/12345".parse::().unwrap()); /// # } + /// + /// # fn build_swarm() -> Swarm { + /// # Swarm::new(DummyTransport::new().boxed(), dummy::Behaviour, PeerId::random(), libp2p_swarm::Config::with_tokio_executor()) + /// # } /// ``` pub fn dial(&mut self, opts: impl Into) -> Result<(), DialError> { let dial_opts = opts.into(); @@ -1464,205 +1458,6 @@ impl Config { } } -/// A [`SwarmBuilder`] provides an API for configuring and constructing a [`Swarm`]. -#[deprecated( - note = "Use the new `libp2p::SwarmBuilder` instead of `libp2p::swarm::SwarmBuilder` or create a `Swarm` directly via `Swarm::new`." -)] -pub struct SwarmBuilder { - local_peer_id: PeerId, - transport: transport::Boxed<(PeerId, StreamMuxerBox)>, - behaviour: TBehaviour, - pool_config: PoolConfig, -} - -#[allow(deprecated)] -impl SwarmBuilder -where - TBehaviour: NetworkBehaviour, -{ - /// Creates a new [`SwarmBuilder`] from the given transport, behaviour, local peer ID and - /// executor. The `Swarm` with its underlying `Network` is obtained via - /// [`SwarmBuilder::build`]. - pub fn with_executor( - transport: transport::Boxed<(PeerId, StreamMuxerBox)>, - behaviour: TBehaviour, - local_peer_id: PeerId, - executor: impl Executor + Send + 'static, - ) -> Self { - Self { - local_peer_id, - transport, - behaviour, - pool_config: PoolConfig::new(Some(Box::new(executor))), - } - } - - /// Sets executor to the `wasm` executor. - /// Background tasks will be executed by the browser on the next micro-tick. - /// - /// Spawning a task is similar too: - /// ```typescript - /// function spawn(task: () => Promise) { - /// task() - /// } - /// ``` - #[cfg(feature = "wasm-bindgen")] - pub fn with_wasm_executor( - transport: transport::Boxed<(PeerId, StreamMuxerBox)>, - behaviour: TBehaviour, - local_peer_id: PeerId, - ) -> Self { - Self::with_executor( - transport, - behaviour, - local_peer_id, - crate::executor::WasmBindgenExecutor, - ) - } - - /// Builds a new [`SwarmBuilder`] from the given transport, behaviour, local peer ID and a - /// `tokio` executor. - #[cfg(all( - feature = "tokio", - not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")) - ))] - pub fn with_tokio_executor( - transport: transport::Boxed<(PeerId, StreamMuxerBox)>, - behaviour: TBehaviour, - local_peer_id: PeerId, - ) -> Self { - Self::with_executor( - transport, - behaviour, - local_peer_id, - crate::executor::TokioExecutor, - ) - } - - /// Builds a new [`SwarmBuilder`] from the given transport, behaviour, local peer ID and a - /// `async-std` executor. - #[cfg(all( - feature = "async-std", - not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")) - ))] - pub fn with_async_std_executor( - transport: transport::Boxed<(PeerId, StreamMuxerBox)>, - behaviour: TBehaviour, - local_peer_id: PeerId, - ) -> Self { - Self::with_executor( - transport, - behaviour, - local_peer_id, - crate::executor::AsyncStdExecutor, - ) - } - - /// Creates a new [`SwarmBuilder`] from the given transport, behaviour and local peer ID. The - /// `Swarm` with its underlying `Network` is obtained via [`SwarmBuilder::build`]. - /// - /// ## ⚠️ Performance warning - /// All connections will be polled on the current task, thus quite bad performance - /// characteristics should be expected. Whenever possible use an executor and - /// [`SwarmBuilder::with_executor`]. - pub fn without_executor( - transport: transport::Boxed<(PeerId, StreamMuxerBox)>, - behaviour: TBehaviour, - local_peer_id: PeerId, - ) -> Self { - Self { - local_peer_id, - transport, - behaviour, - pool_config: PoolConfig::new(None), - } - } - - /// Configures the number of events from the [`NetworkBehaviour`] in - /// destination to the [`ConnectionHandler`] that can be buffered before - /// the [`Swarm`] has to wait. An individual buffer with this number of - /// events exists for each individual connection. - /// - /// The ideal value depends on the executor used, the CPU speed, and the - /// volume of events. If this value is too low, then the [`Swarm`] will - /// be sleeping more often than necessary. Increasing this value increases - /// the overall memory usage. - pub fn notify_handler_buffer_size(mut self, n: NonZeroUsize) -> Self { - self.pool_config = self.pool_config.with_notify_handler_buffer_size(n); - self - } - - /// Configures the size of the buffer for events sent by a [`ConnectionHandler`] to the - /// [`NetworkBehaviour`]. - /// - /// Each connection has its own buffer. - /// - /// The ideal value depends on the executor used, the CPU speed and the volume of events. - /// If this value is too low, then the [`ConnectionHandler`]s will be sleeping more often - /// than necessary. Increasing this value increases the overall memory - /// usage, and more importantly the latency between the moment when an - /// event is emitted and the moment when it is received by the - /// [`NetworkBehaviour`]. - pub fn per_connection_event_buffer_size(mut self, n: usize) -> Self { - self.pool_config = self.pool_config.with_per_connection_event_buffer_size(n); - self - } - - /// Number of addresses concurrently dialed for a single outbound connection attempt. - pub fn dial_concurrency_factor(mut self, factor: NonZeroU8) -> Self { - self.pool_config = self.pool_config.with_dial_concurrency_factor(factor); - self - } - - /// Configures an override for the substream upgrade protocol to use. - /// - /// The subtream upgrade protocol is the multistream-select protocol - /// used for protocol negotiation on substreams. Since a listener - /// supports all existing versions, the choice of upgrade protocol - /// only effects the "dialer", i.e. the peer opening a substream. - /// - /// > **Note**: If configured, specific upgrade protocols for - /// > individual [`SubstreamProtocol`]s emitted by the `NetworkBehaviour` - /// > are ignored. - pub fn substream_upgrade_protocol_override(mut self, v: libp2p_core::upgrade::Version) -> Self { - self.pool_config = self.pool_config.with_substream_upgrade_protocol_override(v); - self - } - - /// The maximum number of inbound streams concurrently negotiating on a - /// connection. New inbound streams exceeding the limit are dropped and thus - /// reset. - /// - /// Note: This only enforces a limit on the number of concurrently - /// negotiating inbound streams. The total number of inbound streams on a - /// connection is the sum of negotiating and negotiated streams. A limit on - /// the total number of streams can be enforced at the [`StreamMuxerBox`] level. - pub fn max_negotiating_inbound_streams(mut self, v: usize) -> Self { - self.pool_config = self.pool_config.with_max_negotiating_inbound_streams(v); - self - } - - /// How long to keep a connection alive once it is idling. - /// - /// Defaults to 0. - pub fn idle_connection_timeout(mut self, timeout: Duration) -> Self { - self.pool_config.idle_connection_timeout = timeout; - self - } - - /// Builds a `Swarm` with the current configuration. - pub fn build(self) -> Swarm { - Swarm::new( - self.transport, - self.behaviour, - self.local_peer_id, - Config { - pool_config: self.pool_config, - }, - ) - } -} - /// Possible errors when trying to establish or upgrade an outbound connection. #[derive(Debug)] pub enum DialError { diff --git a/swarm/tests/ui/fail/out_event_deprecation.rs b/swarm/tests/ui/fail/out_event_deprecation.rs deleted file mode 100644 index f552ca32d10..00000000000 --- a/swarm/tests/ui/fail/out_event_deprecation.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![deny(warnings)] // Ensure the warnings we produce surface as errors. - -use libp2p_ping as ping; - -#[derive(libp2p_swarm::NetworkBehaviour)] -#[behaviour(out_event = "FooEvent", prelude = "libp2p_swarm::derive_prelude")] -struct Foo { - ping: ping::Behaviour, -} - -struct FooEvent; - -impl From for FooEvent { - fn from(_: ping::Event) -> Self { - unimplemented!() - } -} - -fn main() { - -} diff --git a/swarm/tests/ui/fail/out_event_deprecation.stderr b/swarm/tests/ui/fail/out_event_deprecation.stderr deleted file mode 100644 index e8c9c20a995..00000000000 --- a/swarm/tests/ui/fail/out_event_deprecation.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error: use of deprecated constant `out_event_renamed_to_to_swarm::_w`: The `out_event` attribute has been renamed to `to_swarm`. - --> tests/ui/fail/out_event_deprecation.rs:6:13 - | -6 | #[behaviour(out_event = "FooEvent", prelude = "libp2p_swarm::derive_prelude")] - | ^^^^^^^^^ - | -note: the lint level is defined here - --> tests/ui/fail/out_event_deprecation.rs:1:9 - | -1 | #![deny(warnings)] // Ensure the warnings we produce surface as errors. - | ^^^^^^^^ - = note: `#[deny(deprecated)]` implied by `#[deny(warnings)]`