swarm/behaviour: Replace inject_* with on_event
Description
Replace the various NetworkBehaviour::inject_* methods with a single
NetworkBehaviour::on_event method and a InEvent enum.
I want to open this for early feedback before I update the many NetworkBehaviour implementations in /protocols.
Links to any relevant issues
Fixes https://github.com/libp2p/rust-libp2p/issues/2832.
Open Questions
Change checklist
- [ ] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] A changelog entry has been made in the appropriate crates
Exciting!
Thanks @thomaseizinger for the helpful review. Mind taking another look?
Once everyone is happy with the changes in libp2p-swarm I will start porting the many users of libp2p-swarm in /protocols to the new NetworkBehaviour::on_event methods. I plan to do so in this pull request, unless folks prefer separate pull request(s).
Once everyone is happy with the changes in
libp2p-swarmI will start porting the many users oflibp2p-swarmin/protocolsto the newNetworkBehaviour::on_eventmethods. I plan to do so in this pull request, unless folks prefer separate pull request(s).
We would have to litter the rest of the codebase with allow(deprecated) attributes to make CI pass. I think porting the protocols in this PR is better.
https://github.com/libp2p/rust-libp2p/pull/2867/commits/63b70fe60d723ce75510dc0cfea81302b92a7f58 provides default implementations for NetworkBehaviour::on_swarm_event and NetworkBehaviour::on_connection_handler_event, thus this patch set can be released as a non-breaking change.
Once we remove the deprecated NetworkBehaviour::inject_* methods, I think we should remove the default implementations on NetworkBehaviour::on_swarm_event and NetworkBehaviour::on_connection_handler_event as well.
63b70fe provides default implementations for
NetworkBehaviour::on_swarm_eventandNetworkBehaviour::on_connection_handler_event, thus this patch set can be released as a non-breaking change.Once we remove the deprecated
NetworkBehaviour::inject_*methods, I think we should remove the default implementations onNetworkBehaviour::on_swarm_eventandNetworkBehaviour::on_connection_handler_eventas well.
Agreed!
Closing here in favor of https://github.com/libp2p/rust-libp2p/pull/3011.