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

feat(kad)!: add ModeChanged event #4341

Closed
wants to merge 20 commits into from

Conversation

dhuseby
Copy link
Contributor

@dhuseby dhuseby commented Aug 18, 2023

Description

Previously, the kademlia protocol would only log changes to the internal mode. With this patch, we now also emit an event which allows users to code against the internal state of the kademlia protocol.

Fixes #4310.

Notes & open questions

I added the code to emit the event in the reconfigure_mode function on the assumption that all mode changes result in that function being called.

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

Signed-off-by: Dave Huseby <dwh@linuxprogrammer.org>
@dhuseby
Copy link
Contributor Author

dhuseby commented Aug 18, 2023

Maybe the correct behavior is to change the Handler so that after it has made changes in response to the KademliaHandlerIn::ReconfigureMode event, then it confirms that change by telling the behavior to emit the event. Thoughts?

@dhuseby dhuseby force-pushed the add-kademlia-modechanged-event branch from 0d7b317 to f81207f Compare August 18, 2023 01:31
dhuseby and others added 2 commits August 17, 2023 19:31
Signed-off-by: Dave Huseby <dwh@linuxprogrammer.org>
@mergify
Copy link

mergify bot commented Aug 18, 2023

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

@thomaseizinger thomaseizinger changed the title feat!: added kademlia ModeChanged event feat(kad)!: add ModeChanged event Aug 18, 2023
@thomaseizinger
Copy link
Contributor

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Thanks!

The test now fails which is good. We should update the test to also assert the new event being emitted.

protocols/kad/CHANGELOG.md Outdated Show resolved Hide resolved
protocols/kad/CHANGELOG.md Outdated Show resolved Hide resolved
protocols/kad/CHANGELOG.md Outdated Show resolved Hide resolved
protocols/kad/src/behaviour.rs Outdated Show resolved Hide resolved
@thomaseizinger thomaseizinger added this to the v0.53.0 milestone Aug 18, 2023
@thomaseizinger
Copy link
Contributor

I've queued this for the v0.53 release because it is a breaking change. We set those PRs to draft to prevent them from being merged accidentally before that :)

@thomaseizinger thomaseizinger marked this pull request as draft August 18, 2023 08:51
@thomaseizinger
Copy link
Contributor

Maybe the correct behavior is to change the Handler so that after it has made changes in response to the KademliaHandlerIn::ReconfigureMode event, then it confirms that change by telling the behavior to emit the event. Thoughts?

The handler doesn't know about the "automatic" reconfiguration based on the external address. In other words, it also reconfigures itself if the user sets the mode manually. I think we should not emit an event in that case because the user already knows that they just changed the mode. We should probably also mention that in the docs of the new event.

mxinden and others added 5 commits August 18, 2023 09:02
Following libp2p#4289 (comment), hereby is the PR to also improve the `create_socket`  using [`for_addr`](https://docs.rs/socket2/latest/socket2/struct.Domain.html#method.for_address). We also add a test for listening on IPv4 and IPv6 separately.

Pull-Request: libp2p#4328.
Request to add [TAPLE](https://www.taple.es) Project to rust-libp2p notable users. TAPLE is a permissioned DLT solution for traceability of assets and processes. We use libp2p for the network layer.

Pull-Request: libp2p#4309.
@dhuseby
Copy link
Contributor Author

dhuseby commented Aug 18, 2023

Please no force-pushing :)

I can kill this PR, create a new clean branch on my end and resubmit with your suggested changes.

dhuseby and others added 10 commits August 18, 2023 17:11
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Signed-off-by: Dave Huseby <dwh@linuxprogrammer.org>
Signed-off-by: Dave Huseby <dwh@linuxprogrammer.org>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Signed-off-by: Dave Huseby <dwh@linuxprogrammer.org>
Signed-off-by: Dave Huseby <dwh@linuxprogrammer.org>
Signed-off-by: Dave Huseby <dwh@linuxprogrammer.org>
Signed-off-by: Dave Huseby <dwh@linuxprogrammer.org>
@thomaseizinger
Copy link
Contributor

Please no force-pushing :)

I can kill this PR, create a new clean branch on my end and resubmit with your suggested changes.

No need for the extra effort! Continuing here is fine :)

- [Ursa](https://github.com/fleek-network/ursa) - Decentralized Content Delivery & Edge Compute.
- [Taple](https://github.com/opencanarias/taple-core) - Sustainable DLT for asset and process traceability by [OpenCanarias](https://www.opencanarias.com/en/).
Copy link
Contributor

Choose a reason for hiding this comment

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

Something seems to have gone wrong during the rebase / merge because this diff is showing up here as if it were in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah...I think I pulled the upstream master into my branch at some point. let me see if I can clean this up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to do an interactive rebase and drop the unwanted commits and they don't show up in the list of available commits to drop. So instead I created a new branch and used cherry-pick to recreate this PR's branch with just my commits and your review commits. The new branch is here: https://github.com/dhuseby/rust-libp2p/tree/add-kad-modechanged-event

I was think the best course of action at this point is to close this PR and file a new PR with the new clean branch. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was think the best course of action at this point is to close this PR and file a new PR with the new clean branch. What do you think?

Yes, sounds good!

@dhuseby
Copy link
Contributor Author

dhuseby commented Sep 13, 2023

This branch is messed up. Replaced by PR #4499

@dhuseby dhuseby closed this Sep 13, 2023
@thomaseizinger thomaseizinger removed this from the v0.53.0 milestone Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kademlia: be louder about the kind of mode we are operating in
6 participants