Skip to content
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/behaviour: Replace inject_* with on_event #3011

Merged
merged 77 commits into from
Nov 17, 2022

Conversation

jxs
Copy link
Member

@jxs jxs commented Oct 11, 2022

Description

Superseeds #2867.

Links to any relevant issues

Fixes #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

Copy link
Member Author

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:

  • In the NetworkBehaviour doc, some inject_* (now on_*) refer Indicates to the behaviour others informs the behaviour should we have them all on the same wording, for consistency?

  • updated the autonat behaviour, if that looks ok to you will follow to the other protocols

swarm/src/behaviour.rs Outdated Show resolved Hide resolved
swarm/src/behaviour.rs Show resolved Hide resolved
swarm/src/handler/either.rs Show resolved Hide resolved
swarm/tests/public_api.rs Outdated Show resolved Hide resolved
@mxinden
Copy link
Member

mxinden commented Oct 11, 2022

  • In the NetworkBehaviour doc, some inject_* (now on_*) refer Indicates to the behaviour others informs the behaviour should we have them all on the same wording, for consistency?

Consistent wording sounds good to me. Thanks for catching that. I suggest only changing the wording on the new APIs.

@jxs
Copy link
Member Author

jxs commented Oct 11, 2022

  • In the NetworkBehaviour doc, some inject_* (now on_*) refer Indicates to the behaviour others informs the behaviour should we have them all on the same wording, for consistency?

Consistent wording sounds good to me. Thanks for catching that. I suggest only changing the wording on the new APIs.

sorry, forgot to ask which one should prevail then

@thomaseizinger
Copy link
Contributor

  • In the NetworkBehaviour doc, some inject_* (now on_*) refer Indicates to the behaviour others informs the behaviour should we have them all on the same wording, for consistency?

Consistent wording sounds good to me. Thanks for catching that. I suggest only changing the wording on the new APIs.

sorry, forgot to ask which one should prevail then

"inform" sounds better to me but I don't have a strong opinion here.

@mxinden
Copy link
Member

mxinden commented Nov 12, 2022

I suggest we merge this together with #3085 to make sure both land in the same release. Objections?

@thomaseizinger
Copy link
Contributor

I suggest we merge this together with #3085 to make sure both land in the same release. Objections?

That would be my preference too!

@mergify
Copy link
Contributor

mergify bot commented Nov 13, 2022

This pull request has merge conflicts. Could you please resolve them @jxs? 🙏

remaining_established,
),
_ => unreachable!(),
Either::Left(b) => b.on_swarm_event(event.map_handler(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomaseizinger comment on #3085 (comment) sparked a thought.

What if b implements the inject_* style methods and not the on_* style methods? In such case, this call would be lost, right?

Unless I am missing something combinators like Either need to call the inject_* style methods until we remove them.

Copy link
Member Author

@jxs jxs Nov 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No no, I noticed it when replacing Inject_* on combinators for #3085 but with the deprecation/removal discussion forgot to address it here, thanks for reminding @mxinden! Updated to call inject methods on those structs. Also merged from master and fixed conflicts ptal.

@mergify
Copy link
Contributor

mergify bot commented Nov 14, 2022

This pull request has merge conflicts. Could you please resolve them @jxs? 🙏

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid there is still one larger work item on swarm-derive. Otherwise this pull request looks good to me.

.iter()
.enumerate()
.map(|(field_n, field)| match field.ident {
Some(ref i) => quote! { self.#i.on_swarm_event(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swarm-derive will need to delegate to the inject_* methods of the corresponding NetworkBehaviour implementations, right? Otherwise our non-breaking deprecation doesn't work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah right, thanks for noticing Max, I think I addressed all the cases but ptal.

@mxinden
Copy link
Member

mxinden commented Nov 15, 2022

Thanks for the follow-ups. Once the last comments in #3085 (review) are addressed, we can merge both.

@mergify
Copy link
Contributor

mergify bot commented Nov 15, 2022

This pull request has merge conflicts. Could you please resolve them @jxs? 🙏

@mxinden
Copy link
Member

mxinden commented Nov 17, 2022

#3085 is all approved. Adding send-it here.

@mergify mergify bot merged commit 3df3c88 into libp2p:master Nov 17, 2022
mxinden added a commit to mxinden/rust-libp2p that referenced this pull request Nov 29, 2022
`libp2p-swarm-derive` released a breaking change (libp2p#3011)
as a patch release `v0.30.2`.

This patch:

1. Prepares a new minor release of `libp2p-swarm-derive`.
2. Prepares a patch release for `libp2p-swarm` to use the minor release of `libp2p-swarm-derive`.

As a follow up we can yank the `libp2p-swarm-derive` `v0.30.2` release. In addition we might want to
release `libp2p-swarm-derive` `v0.30.3` containing all patches but libp2p#3011.
mxinden added a commit that referenced this pull request Nov 29, 2022
`libp2p-swarm-derive` released a breaking change (#3011)
as a patch release `v0.30.2`.

This patch:

1. Prepares a new minor release of `libp2p-swarm-derive`.
2. Prepares a patch release for `libp2p-swarm` to use the minor release of `libp2p-swarm-derive`.

As a follow up we can yank the `libp2p-swarm-derive` `v0.30.2` release. In addition we might want to
release `libp2p-swarm-derive` `v0.30.3` containing all patches but #3011.

/// Enumeration with the list of the possible events
/// to pass to [`on_swarm_event`](NetworkBehaviour::on_swarm_event).
pub enum FromSwarm<'a, Handler: IntoConnectionHandler> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't there Clone derive? I need to forward this to underlying protocols and it seems like I need to match on all variants just to be able to clone and wrap it back into FromSwarm or am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple variants that contain a ConnectionHandler which can't be cloned.

See #3046.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes it feels like we're going through a lot of painful contortions just to avoid saying Arc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes it feels like we're going through a lot of painful contortions just to avoid saying Arc.

In this case, we would also have to say try_unwrap: https://doc.rust-lang.org/std/sync/struct.Arc.html#method.try_unwrap

Possible but doesn't feel very clean. I don't particularly like both solutions but I think we are getting one step closer with the new event into making composition easier.

#3099 will help with this too because we are removing a few more mentions of the handler there.

umgefahren pushed a commit to umgefahren/rust-libp2p that referenced this pull request Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

swarm/behaviour: Inject events via single method
5 participants