Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

# `libp2p` facade crate

# 0.48.0 [unreleased]

- Update to `libp2p-swarm-derive` [`v0.30.0`](swarm-derive/CHANGELOG.md#0300).

# 0.47.0

- Update to [`libp2p-dcutr` `v0.5.0`](protocols/dcutr/CHANGELOG.md#050).
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p"
edition = "2021"
rust-version = "1.60.0"
description = "Peer-to-peer networking library"
version = "0.47.0"
version = "0.48.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down Expand Up @@ -93,7 +93,7 @@ libp2p-relay = { version = "0.11.0", path = "protocols/relay", optional = true }
libp2p-rendezvous = { version = "0.8.0", path = "protocols/rendezvous", optional = true }
libp2p-request-response = { version = "0.20.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.38.0", path = "swarm" }
libp2p-swarm-derive = { version = "0.29.0", path = "swarm-derive" }
libp2p-swarm-derive = { version = "0.30.0", path = "swarm-derive" }
libp2p-uds = { version = "0.34.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.35.0", path = "transports/wasm-ext", default-features = false, optional = true }
libp2p-yamux = { version = "0.39.0", path = "muxers/yamux", optional = true }
Expand Down
4 changes: 4 additions & 0 deletions swarm-derive/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.30.0 - [unreleased]

- Remove support for custom `poll` method on `NetworkBehaviour` via `#[behaviour(poll_method = "poll")]`.

# 0.29.0

- Generate `NetworkBehaviour::OutEvent` if not provided through `#[behaviour(out_event =
Expand Down
2 changes: 1 addition & 1 deletion swarm-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-swarm-derive"
edition = "2021"
rust-version = "1.56.1"
description = "Procedural macros of libp2p-core"
version = "0.29.0"
version = "0.30.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
28 changes: 2 additions & 26 deletions swarm-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use heck::ToUpperCamelCase;
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Ident};
use syn::{parse_macro_input, Data, DataStruct, DeriveInput};

/// Generates a delegating `NetworkBehaviour` implementation for the struct this is used for. See
/// the trait documentation for better description.
Expand Down Expand Up @@ -472,29 +472,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
out_handler.unwrap_or(quote! {()}) // TODO: See test `empty`.
};

// The method to use to poll.
// If we find a `#[behaviour(poll_method = "poll")]` attribute on the struct, we call
// `self.poll()` at the end of the polling.
let poll_method = {
let mut poll_method = quote! {std::task::Poll::Pending};
for meta_items in ast.attrs.iter().filter_map(get_meta_items) {
for meta_item in meta_items {
match meta_item {
syn::NestedMeta::Meta(syn::Meta::NameValue(ref m))
if m.path.is_ident("poll_method") =>
{
if let syn::Lit::Str(ref s) = m.lit {
let ident: Ident = syn::parse_str(&s.value()).unwrap();
poll_method = quote! {#name::#ident(self, cx, poll_params)};
}
}
_ => (),
}
}
}
poll_method
};

// List of statements to put in `poll()`.
//
// We poll each child one by one and wrap around the output.
Expand Down Expand Up @@ -683,8 +660,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
fn poll(&mut self, cx: &mut std::task::Context, poll_params: &mut impl #poll_parameters) -> std::task::Poll<#network_behaviour_action<Self::OutEvent, Self::ConnectionHandler>> {
use libp2p::futures::prelude::*;
#(#poll_stmts)*
let f: std::task::Poll<#network_behaviour_action<Self::OutEvent, Self::ConnectionHandler>> = #poll_method;
f
std::task::Poll::Pending
}
}
};
Expand Down
81 changes: 1 addition & 80 deletions swarm-derive/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,38 +128,7 @@ fn three_fields_non_last_ignored() {
}

#[test]
fn custom_polling() {
#[allow(dead_code)]
#[derive(NetworkBehaviour)]
#[behaviour(poll_method = "foo")]
struct Foo {
ping: libp2p::ping::Ping,
identify: libp2p::identify::Identify,
}

impl Foo {
fn foo(
&mut self,
_: &mut std::task::Context,
_: &mut impl libp2p::swarm::PollParameters,
) -> std::task::Poll<
libp2p::swarm::NetworkBehaviourAction<
<Self as NetworkBehaviour>::OutEvent,
<Self as NetworkBehaviour>::ConnectionHandler,
>,
> {
std::task::Poll::Pending
}
}

#[allow(dead_code)]
fn foo() {
require_net_behaviour::<Foo>();
}
}

#[test]
fn custom_event_no_polling() {
fn custom_event() {
#[allow(dead_code)]
#[derive(NetworkBehaviour)]
#[behaviour(out_event = "MyEvent")]
Expand Down Expand Up @@ -191,54 +160,6 @@ fn custom_event_no_polling() {
}
}

#[test]
fn custom_event_and_polling() {
#[allow(dead_code)]
#[derive(NetworkBehaviour)]
#[behaviour(poll_method = "foo", out_event = "MyEvent")]
struct Foo {
ping: libp2p::ping::Ping,
identify: libp2p::identify::Identify,
}

enum MyEvent {
Ping(libp2p::ping::PingEvent),
Identify(libp2p::identify::IdentifyEvent),
}

impl From<libp2p::ping::PingEvent> for MyEvent {
fn from(event: libp2p::ping::PingEvent) -> Self {
MyEvent::Ping(event)
}
}

impl From<libp2p::identify::IdentifyEvent> for MyEvent {
fn from(event: libp2p::identify::IdentifyEvent) -> Self {
MyEvent::Identify(event)
}
}

impl Foo {
fn foo(
&mut self,
_: &mut std::task::Context,
_: &mut impl libp2p::swarm::PollParameters,
) -> std::task::Poll<
libp2p::swarm::NetworkBehaviourAction<
<Self as NetworkBehaviour>::OutEvent,
<Self as NetworkBehaviour>::ConnectionHandler,
>,
> {
std::task::Poll::Pending
}
}

#[allow(dead_code)]
fn foo() {
require_net_behaviour::<Foo>();
}
}

#[test]
fn custom_event_mismatching_field_names() {
#[allow(dead_code)]
Expand Down
4 changes: 0 additions & 4 deletions swarm/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ pub(crate) type THandlerOutEvent<THandler> =
/// }
/// ```
///
/// Optionally one can provide a custom `poll` function through the `#[behaviour(poll_method =
/// "poll")]` attribute. This function must have the same signature as the [`NetworkBehaviour#poll`]
/// function and will be called last within the generated [`NetworkBehaviour`] implementation.
///
/// Struct members that don't implement [`NetworkBehaviour`] must be annotated with
/// `#[behaviour(ignore)]`.
///
Expand Down