-
Notifications
You must be signed in to change notification settings - Fork 961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
swarm/src/behaviour: Deprecate NetworkBehaviourEventProcess #2784
Conversation
In preparation for libp2p#2751.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK, just one suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand it correctly, the plan is to publish a release that includes this changes here (deprecating NetworkBehaviourEventProcess
), but do a separate release for the main changes of #2751 (changing the proc macro, removing NetworkBehaviourEventProcess
completely).
I am not sure if it make sense to deprecate NetworkBehaviourEventProcess
without publishing the changes in the proc macro. User that want to upgrade can not use the automatically generated OutEvent
yet. Imo ideally the first release should already include all changes of #2751, but not yet remove support for NetworkBehaviourEventProcess
/ event_process=false
event_process=true
.
The problem that I see here is what the default should be (= What should be generated if a struct is only annotated with #[derive(NetworkBehavour)]
and nothing else?).
In the old version the default was to expect NetworkBehaviourEventProcess
, in the new version the default will be to generate the OutEvent
enum.
What do you think about the following:
- Include all changes of swarm*/: Remove NetworkBehaviourEventProcess and generate OutEvent #2751, but only deprecate
NetworkBehaviourEventProcess
instead of removing it and keep support forevent_process=false
event_process=true
(which means that for this interim period the macro would have to support both,event_process
and the new generatedOutEvent
) Change default forevent_process
totrue
instead offalse
. User that would like to keep using it would have to explicitly add#[event_process=false]
rather than it being the default- Per default generate the
OutEvent
enum - In the following release then just remove
NetworkBehaviourEventProcess
andevent_process
.
We'd have to explicitly point that out in our Changelog, but I think it would be more convenient for the majority of our users.
I think there is a confusion here. Today, by default, rust-libp2p/swarm-derive/src/lib.rs Lines 73 to 75 in eaf3f3a
Am I missing something @elenaf9? |
You are right, I mixed it up what |
I think that is a really good idea actually! |
@elenaf9 @thomaseizinger with #2792 merged, would you mind taking another look? |
#[allow(deprecated)] | ||
impl<TEvent, TBehaviourLeft, TBehaviourRight> NetworkBehaviourEventProcess<TEvent> | ||
for Either<TBehaviourLeft, TBehaviourRight> | ||
where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the usage case for NetworkBehaviourEventProcess
on Either
(or Toggle
below)?
As far as I understood it, the purpose of NetworkBehaviourEventProcess
is only to be used in combination with the NetworkBehaviour
derive macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess when you use Either
or Toggle
when building a nested NetworkBehaviour
. See for example:
rust-libp2p/swarm-derive/tests/test.rs
Lines 354 to 369 in a4110a2
#[test] | |
fn with_toggle() { | |
use libp2p::swarm::behaviour::toggle::Toggle; | |
#[allow(dead_code)] | |
#[derive(NetworkBehaviour)] | |
struct Foo { | |
identify: libp2p::identify::Identify, | |
ping: Toggle<libp2p::ping::Ping>, | |
} | |
#[allow(dead_code)] | |
fn foo() { | |
require_net_behaviour::<Foo>(); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here with NetworkBehaviourEventProcess
:
rust-libp2p/swarm-derive/tests/test.rs
Lines 328 to 352 in 2f2b7cb
#[test] | |
fn with_toggle() { | |
use libp2p::swarm::behaviour::toggle::Toggle; | |
#[allow(dead_code)] | |
#[derive(NetworkBehaviour)] | |
#[behaviour(event_process = true)] | |
struct Foo { | |
identify: libp2p::identify::Identify, | |
ping: Toggle<libp2p::ping::Ping>, | |
} | |
impl libp2p::swarm::NetworkBehaviourEventProcess<libp2p::identify::IdentifyEvent> for Foo { | |
fn inject_event(&mut self, _: libp2p::identify::IdentifyEvent) {} | |
} | |
impl libp2p::swarm::NetworkBehaviourEventProcess<libp2p::ping::PingEvent> for Foo { | |
fn inject_event(&mut self, _: libp2p::ping::PingEvent) {} | |
} | |
#[allow(dead_code)] | |
fn foo() { | |
require_net_behaviour::<Foo>(); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you wouldn't call the NetworkBehaviourEventProcess
implementation of an inner behaviour, no? Instead you implement NetworkBehaviourEventProcess
on the parent (in the above case in Foo
) and handle the event there. Why would anyone want to inject the event back into an inner behaviour?
None of our behaviours currently implement NetworkBehaviourProcess
, so the below trait bound for it would not apply anyway:
rust-libp2p/swarm/src/behaviour/toggle.rs
Lines 237 to 239 in a4110a2
where | |
TBehaviour: NetworkBehaviourEventProcess<TEvent>, | |
{ |
So
libp2p::ping::Ping
does not implement NetworkBehaviourEventProcess
, therefore Toggle<libp2p::ping::Ping>
will also not implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I am missing something, there was never really a use-case for NetworkBehaviourEventProcess
on those two behaviours in the first place. However, that's not really a concern of this PR.
So I guess I am fine with for now with keeping it the way it is, since this trait will be remove anyway in the next release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK modulo mine and @elenaf9 's comments :)
swarm/CHANGELOG.md
Outdated
- Update dial address concurrency factor to `8`, thus dialing up to 8 addresses concurrently for a single connection attempt. See `Swarm::dial_concurrency_factor` and [PR 2741]. | ||
|
||
- Update to `libp2p-core` `v0.35.0`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the changelog entry above so this doesn't come up in the diff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ordered the entries by significance. I don't think users care much about the libp2p-core
update. I do think users care about how to upgrade from NetworkBehaviourEventProcess
. Does that reasoning make sense @thomaseizinger?
One more thing: I think if we are deprecating |
Co-authored-by: Elena Frank <elena.frank@protonmail.com>
Co-authored-by: Elena Frank <elena.frank@protonmail.com>
Co-authored-by: Elena Frank <elena.frank@protonmail.com>
Co-authored-by: Elena Frank <elena.frank@protonmail.com>
…eprecate-event-process
That is a good point. 0f3ef69 does the change. |
As far as I can tell all comments are addressed and everyone approved. Thus I am merging here. Happy to do any follow-ups in case I missed something. As always, thanks for all the input @elenaf9 and @thomaseizinger! |
Removes the `NetworkBehaviourEventProcess` and all its associated logic. See deprecation pull request libp2p#2784. Find rational in libp2p#2751.
…2p#2840) Removes the `NetworkBehaviourEventProcess` and all its associated logic. See deprecation pull request libp2p#2784. Find rational in libp2p#2751.
Description
In preparation for #2751.
Change checklist