Skip to content

Commit

Permalink
chore(swarm): remove deprecated symbols
Browse files Browse the repository at this point in the history
Pull-Request: #4737.
  • Loading branch information
thomaseizinger authored Oct 27, 2023
1 parent 20e4b36 commit 3118503
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 328 deletions.
12 changes: 0 additions & 12 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions libp2p/src/tutorials/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
//!
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
48 changes: 1 addition & 47 deletions protocols/gossipsub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]

Expand Down
2 changes: 1 addition & 1 deletion protocols/request-response/src/cbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions swarm-derive/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion swarm-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 0 additions & 16 deletions swarm-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,7 +60,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result<Toke
let BehaviourAttributes {
prelude_path,
user_specified_out_event,
deprecation_tokenstream,
} = parse_attributes(ast)?;

let multiaddr = quote! { #prelude_path::Multiaddr };
Expand Down Expand Up @@ -756,8 +754,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result<Toke

// Now the magic happens.
let final_quote = quote! {
#deprecation_tokenstream

#out_event_definition

impl #impl_generics #trait_to_impl for #name #ty_generics
Expand Down Expand Up @@ -881,15 +877,13 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result<Toke
struct BehaviourAttributes {
prelude_path: syn::Path,
user_specified_out_event: Option<syn::Type>,
deprecation_tokenstream: proc_macro2::TokenStream,
}

/// Parses the `value` of a key=value pair in the `#[behaviour]` attribute into the requested type.
fn parse_attributes(ast: &DeriveInput) -> syn::Result<BehaviourAttributes> {
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
Expand All @@ -909,16 +903,6 @@ fn parse_attributes(ast: &DeriveInput) -> syn::Result<BehaviourAttributes> {
}

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)?);
Expand Down
2 changes: 2 additions & 0 deletions swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions swarm/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,6 @@ impl<TConnectionUpgrade, TOutboundOpenInfo, TCustom, TErr>
}
}

#[deprecated(note = "Renamed to `StreamUpgradeError`")]
pub type ConnectionHandlerUpgrErr<TUpgrErr> = StreamUpgradeError<TUpgrErr>;

/// Error that can happen on an outbound substream opening attempt.
#[derive(Debug)]
pub enum StreamUpgradeError<TUpgrErr> {
Expand Down
Loading

0 comments on commit 3118503

Please sign in to comment.