Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Use a Kademlia instance per ProtocolId. #5045

Merged
merged 12 commits into from
Apr 16, 2020
Merged

Conversation

twittner
Copy link
Contributor

This PR changes discovery to use one kademlia instance per protocol ID. The change is motivated by the fact that the single DHT we use now includes incompatible nodes with different protocols.

To retain backwards compatibility we currently use a fake ProtocolId matching the existing /ipfs/kad/1.0.0 protocol string. If and when this change is rolled out we can remove it and work solely with ProtocolIds taken from the chain specification.

Currently the implementation relies on changes in libp2p master which have yet to be published so a patch section is added to Cargo.toml which should be removed before merging this PR.

This PR changes discovery to use one kademlia instance per protocol
ID. The change is motivated by the fact that the single DHT we use
now includes incompatible nodes with different protocols.

To retain backwards compatibility we currently use a fake `ProtocolId`
matching the existing `/ipfs/kad/1.0.0` protocol string. If and when
this change is rolled out we can remove it and work solely with
`ProtocolId`s taken from the chain specification.
@twittner twittner added the A0-please_review Pull request needs code review. label Feb 25, 2020
@tomaka tomaka self-requested a review February 25, 2020 13:05
@tomaka
Copy link
Contributor

tomaka commented Mar 9, 2020

I think libp2p 0.16.2 contains the methods that you're using, so we can remove the [patch] section.

client/network/src/behaviour.rs Outdated Show resolved Hide resolved
client/network/src/discovery.rs Outdated Show resolved Hide resolved
client/network/src/discovery.rs Outdated Show resolved Hide resolved
self.kademlia.get_record(key, Quorum::One)
for k in self.kademlias.values_mut() {
k.get_record(key, Quorum::One)
}
}

/// Start putting a record into the DHT. Other nodes can later fetch that value with
/// `get_value`.
///
/// A corresponding `ValuePut` or `ValuePutFailed` event will later be generated.
pub fn put_value(&mut self, key: record::Key, value: Vec<u8>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

get_value and put_value ultimately should be changed to pass a ProtocolId to designate which DHT to target.
I'm unsure if we should do this now though.

client/network/src/discovery.rs Show resolved Hide resolved
client/network/src/discovery.rs Outdated Show resolved Hide resolved
client/network/src/discovery.rs Outdated Show resolved Hide resolved
client/network/src/discovery.rs Outdated Show resolved Hide resolved
# Conflicts:
#	client/network/src/behaviour.rs
#	client/network/src/discovery.rs
#	client/network/src/service.rs
client/network/src/service.rs Outdated Show resolved Hide resolved
client/network/src/discovery.rs Outdated Show resolved Hide resolved
As requested this is now set implicitly in `DiscoveryConfig::new`.
@tomaka
Copy link
Contributor

tomaka commented Apr 15, 2020

Please merge master in order for the Polkadot check to pass.

@tomaka tomaka added A8-mergeoncegreen and removed A0-please_review Pull request needs code review. labels Apr 15, 2020
@gnunicorn gnunicorn merged commit 710722f into paritytech:master Apr 16, 2020
@twittner twittner deleted the multikad branch April 16, 2020 09:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants