rust-libp2p icon indicating copy to clipboard operation
rust-libp2p copied to clipboard

swarm/behaviour: Replace inject_* with on_event

Open mxinden opened this issue 3 years ago • 6 comments

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

mxinden avatar Sep 04 '22 03:09 mxinden

Exciting!

MarcoPolo avatar Sep 04 '22 04:09 MarcoPolo

Thanks @thomaseizinger for the helpful review. Mind taking another look?

mxinden avatar Sep 07 '22 06:09 mxinden

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).

mxinden avatar Sep 07 '22 06:09 mxinden

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).

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.

thomaseizinger avatar Sep 08 '22 08:09 thomaseizinger

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.

mxinden avatar Sep 17 '22 16:09 mxinden

63b70fe 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.

Agreed!

thomaseizinger avatar Sep 19 '22 05:09 thomaseizinger

Closing here in favor of https://github.com/libp2p/rust-libp2p/pull/3011.

mxinden avatar Oct 12 '22 12:10 mxinden