-
Notifications
You must be signed in to change notification settings - Fork 959
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): allow to explicitly set Mode::{Client,Server}
#4132
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this PR @dariusc93 !
I realised that the issue with Option<Mode>
is that we can't tell whether we should reconfigure the mode automatically. Thus my suggestion would be:
- Delete
ExplicitMode
- Introduce a new boolean field:
auto_mode
, defaulting totrue
- Make the signature of
set_explicit_mode
Option<None>
- If an explicit mode is set, set
auto_mode
to false
Also, to be technically correct in regards to the poll
contract, I think we will need a Waker
that is set in poll
that we can call once we change any state around the mode, be it the auto_mode
boolean or the mode
field itself. Otherwise we rely on another event in the network to call poll
on Behaviour
which might not happen immediately.
Let me know what you think!
That is just for logging though right? We don't need to pass an address to the
The suggested waker should address this. |
Mode::{Client,Server}
Looks good to me. Originally I had a boolean field to determine if it should be done automatically or not but I think I also had mode be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Just missing some tests now :)
…into kad-explicit-mode
…into kad-explicit-mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for tackling this @dariusc93.
protocols/kad/src/behaviour.rs
Outdated
@@ -990,6 +994,40 @@ where | |||
id | |||
} | |||
|
|||
pub fn set_explicit_mode(&mut self, mode: Option<Mode>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn set_explicit_mode(&mut self, mode: Option<Mode>) { | |
/// Either set Kademlia [`Mode`] explicitly via `Some(_)` or enable automatic configuration of the Kademlia [`Mode`] based on the external addresses available via `None`. | |
pub fn set_mode(&mut self, mode: Option<Mode>) { |
- Nit pick, passing
None
enables auto-mode, thus the function name (xxx_explicit_xxx
) is not accurate. Would you agree? - Adding some documentation. Feel free to rephrase. Just a suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit pick, passing None enables auto-mode, thus the function name (xxx_explicit_xxx) is not accurate. Would you agree?
I disagree. If you call set_explicit_mode
with None
, you are not setting an explicit mode. Seems quite logical to me?
Co-authored-by: Max Inden <[email protected]>
Co-authored-by: Max Inden <[email protected]>
…into kad-explicit-mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Some final input but looks good already :)
Co-authored-by: Thomas Eizinger <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Some final nits.
Co-authored-by: Thomas Eizinger <[email protected]>
…into kad-explicit-mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your patience! This turned out quite clean :)
…into kad-explicit-mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 thank you for the follow-ups!
Description
The current implementation in Kademlia relies on an external address to determine if it should be in client or server mode. However there are instances where a node, which may know an external address, wishes to remain in client mode and switch to server mode at a later point.
This PR introduces
Kademlia::set_mode
, which accepts anOption<Mode>
that would allow one to setMode::Client
for client mode,Mode::Server
for server mode, orNone
to determine if we should operate as a client or server based on our external addresses.Resolves #4074.
Notes & open questions
This is just my thoughts on how it should be based on what was discussed in #4074. IntroducingExplicitMode
would remove the possibility of complexity if we were to haveMode::Auto
due to it being passed into the handler, but open to suggestions on changing this to something different instead.From what it looks like, settingExplicitMode::Server
(which internally would set it toMode::Server
) still require an external address. Do we wish to keep this behaviour so the node is reachable or should we rely on another form of address (eg address(es) being listened on)?WhenExplicitMode::Auto
is set, do we want to automatically determine the mode at that point base on the external address and notify the handler(s) or should we leaveKademlia::mode
as is untilNetworkBehaviour::on_swarm_event
is executed to determine that for us as long as the mode is set to auto?Change checklist