diff --git a/CHANGELOG.md b/CHANGELOG.md index b9d574ea35f..20766d4dc19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,8 @@ # 0.48.0 [unreleased] +- Update to [`libp2p-swarm-derive` `v0.30.0`](swarm-derive/CHANGELOG.md#0300). + - Update to [`libp2p-dcutr` `v0.6.0`](protocols/dcutr/CHANGELOG.md#060). - Update to [`libp2p-rendezvous` `v0.9.0`](protocols/rendezvous/CHANGELOG.md#090). diff --git a/swarm-derive/CHANGELOG.md b/swarm-derive/CHANGELOG.md index 5cf840c331c..4dc5a9769cb 100644 --- a/swarm-derive/CHANGELOG.md +++ b/swarm-derive/CHANGELOG.md @@ -1,6 +1,12 @@ # 0.30.0 - [unreleased] -- Remove support for removed `NetworkBehaviourEventProcess`. +- Remove support for removed `NetworkBehaviourEventProcess`. See [PR 2840]. + +- Remove support for custom `poll` method on `NetworkBehaviour` via `#[behaviour(poll_method = + "poll")]`. See [PR 2841]. + +[PR 2840]: https://github.com/libp2p/rust-libp2p/pull/2840 +[PR 2841]: https://github.com/libp2p/rust-libp2p/pull/2841 # 0.29.0 diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index 0369a67c5ea..d1e49ef361a 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -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. @@ -433,29 +433,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. @@ -638,8 +615,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> { use libp2p::futures::prelude::*; #(#poll_stmts)* - let f: std::task::Poll<#network_behaviour_action> = #poll_method; - f + std::task::Poll::Pending } } }; diff --git a/swarm-derive/tests/test.rs b/swarm-derive/tests/test.rs index 61c95cd8aaa..d7b058d2169 100644 --- a/swarm-derive/tests/test.rs +++ b/swarm-derive/tests/test.rs @@ -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< - ::OutEvent, - ::ConnectionHandler, - >, - > { - std::task::Poll::Pending - } - } - - #[allow(dead_code)] - fn foo() { - require_net_behaviour::(); - } -} - -#[test] -fn custom_event_no_polling() { +fn custom_event() { #[allow(dead_code)] #[derive(NetworkBehaviour)] #[behaviour(out_event = "MyEvent")] @@ -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 for MyEvent { - fn from(event: libp2p::ping::PingEvent) -> Self { - MyEvent::Ping(event) - } - } - - impl From 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< - ::OutEvent, - ::ConnectionHandler, - >, - > { - std::task::Poll::Pending - } - } - - #[allow(dead_code)] - fn foo() { - require_net_behaviour::(); - } -} - #[test] fn custom_event_mismatching_field_names() { #[allow(dead_code)] diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index 9c4a10b56cd..acda2cedc27 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -118,10 +118,6 @@ pub(crate) type THandlerOutEvent = /// } /// ``` /// -/// 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)]`. ///