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

Add Kademlia mode override. #1736

Merged
merged 3 commits into from
Aug 2, 2023
Merged

Conversation

shamil-gadelshin
Copy link
Member

This PR adds an optional Kademlia mode override. The feature allows using temporary custom clients without polluting the Kademlia DHT routing table.

Libp2p v0.52.1 is able to determine the Kademlia mode automatically which would be a preferred solution. However, we need to switch to the automatic adding of the addresses by Kademlia and support Autonat to support the automatic mode switch.

Code contributor checklist:

@shamil-gadelshin shamil-gadelshin added the networking Subspace networking (DSN) label Aug 1, 2023
@shamil-gadelshin shamil-gadelshin self-assigned this Aug 1, 2023
@@ -224,6 +225,8 @@ pub struct Config<ProviderStorage> {
pub special_target_connections: u32,
/// Addresses to bootstrap Kademlia network
pub bootstrap_addresses: Vec<Multiaddr>,
/// Optionally overrides the default Kademlia server mode.
pub kademlia_mode_override: Option<Option<Mode>>,
Copy link
Member

Choose a reason for hiding this comment

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

Why not just Option<Mode> and default it to Some(Mode::Client)?

Copy link
Member

Choose a reason for hiding this comment

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

Better yet, just Mode

Copy link
Member Author

Choose a reason for hiding this comment

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

None is a valid Kademlia mode (automatic mode). This way I can set three modes as well as use the default.

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need automatic mode? I thought the whole point was to make it explicit

Copy link
Member Author

Choose a reason for hiding this comment

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

Initially, I set the Server mode to upgrade the libp2p with preserving the current behavior. However, It would be great to use the automatic mode, otherwise, we should add basically the same code as they did. On the other hand, when we know that we must not get to the routing table (as for temporary clients now or for nodes in the future) it's convenient to set Client mode explicitly. I believe that having all options available is good.

Copy link
Member

Choose a reason for hiding this comment

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

It still looks very strange. If we remove outer Option we just don't set anything on None (libp2p default) and if it is Some then we do set it to whatever was specified. I don't think Some(None) is useful.

Copy link
Member Author

Choose a reason for hiding this comment

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

I change the semantics then.

@shamil-gadelshin shamil-gadelshin enabled auto-merge (squash) August 2, 2023 06:18
@@ -340,7 +340,7 @@ where
general_target_connections: SWARM_TARGET_CONNECTION_NUMBER,
special_target_connections: SWARM_TARGET_CONNECTION_NUMBER,
bootstrap_addresses: Vec::new(),
kademlia_mode_override: None,
kademlia_mode: Some(Mode::Server),
Copy link
Member

Choose a reason for hiding this comment

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

Hm... I recall we wanted the default to be client, not server. Why this change? If we want to keep libp2p's default then we need to leave None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
networking Subspace networking (DSN)
Projects
Development

Successfully merging this pull request may close these issues.

2 participants