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): report changes to our mode as an event #4499

Closed
wants to merge 10 commits into from

Conversation

dhuseby
Copy link
Contributor

@dhuseby dhuseby commented Sep 13, 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
  • I have force pushed to break the squash commit system we use around here.

@dhuseby
Copy link
Contributor Author

dhuseby commented Sep 13, 2023

This PR replaces the messed up previous PR #4341

@dhuseby dhuseby mentioned this pull request Sep 13, 2023
4 tasks
@thomaseizinger thomaseizinger changed the title Add kad modechanged event feat(kad): report changes to our mode as an event Sep 13, 2023
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 for the creating a new PR!

The kademlia tests are still failing (correctly) because we are now emitting an additional event. For example, you'd have to add your new event to the following list:

[MyBehaviourEvent::Identify(_), MyBehaviourEvent::Identify(_), MyBehaviourEvent::Kad(KademliaEvent::RoutingUpdated { peer, .. })],
[MyBehaviourEvent::Identify(_), MyBehaviourEvent::Identify(_)],

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

I am adding this to the next milestone because it is a breaking change. Conventionally, we also set these PRs to draft to not accidentally merge them! :)

@thomaseizinger thomaseizinger marked this pull request as draft September 13, 2023 22:42
dhuseby and others added 10 commits September 14, 2023 09:28
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>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Signed-off-by: Dave Huseby <dwh@linuxprogrammer.org>
@dhuseby dhuseby self-assigned this Sep 14, 2023
@dhuseby
Copy link
Contributor Author

dhuseby commented Sep 14, 2023

So I was looking at the behavior of this change and I was wondering about what we want as the correct behavior. In the case where the set_mode function is called with a new mode (instead of None), there will be no event emitted because it never results in a call to the determine_mode_from_external addresses function which is the only place we emit the event.

Is it correct to say we only emit the event whenever we are in auto_mode and we determine our mode from the external addresses?

Also, the current behavior means that there's often—but not always—an initial event emitted from the first time a we try to determine our mode from the external addresses. There is a corner case where set_mode is called, auto_mode is set to false, before the swarm starts. In that case no mode changed events will ever be emitted.

I suppose this all is as it should be. If you set the mode manually and turn of auto_mode in doing so, you probably don't want any mode changed events emitted. If you never set the mode manually or you disable the manual mode setting, you're putting the behavior into auto_mode and it will report any changes via a mode changed event.

@dhuseby
Copy link
Contributor Author

dhuseby commented Sep 14, 2023

no force pushes... closed in lieu of PR #4503

@dhuseby dhuseby closed this Sep 14, 2023
@thomaseizinger
Copy link
Contributor

So I was looking at the behavior of this change and I was wondering about what we want as the correct behavior. In the case where the set_mode function is called with a new mode (instead of None), there will be no event emitted because it never results in a call to the determine_mode_from_external addresses function which is the only place we emit the event.

Is it correct to say we only emit the event whenever we are in auto_mode and we determine our mode from the external addresses?

Also, the current behavior means that there's often—but not always—an initial event emitted from the first time a we try to determine our mode from the external addresses. There is a corner case where set_mode is called, auto_mode is set to false, before the swarm starts. In that case no mode changed events will ever be emitted.

I suppose this all is as it should be. If you set the mode manually and turn of auto_mode in doing so, you probably don't want any mode changed events emitted. If you never set the mode manually or you disable the manual mode setting, you're putting the behavior into auto_mode and it will report any changes via a mode changed event.

Yep, that is my thinking too! If you set the mode manually, you don't need an event to tell you because you already have a code path where you can add whatever logic you want to do as a result of the new mode.

@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
2 participants