-
Notifications
You must be signed in to change notification settings - Fork 26
kad: Allow connecting to more than one DHT network #473
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,7 +240,9 @@ impl Kademlia { | |
| self.routing_table.on_connection_established(Key::from(peer), endpoint); | ||
|
|
||
| let Some(actions) = self.pending_dials.remove(&peer) else { | ||
| entry.insert(PeerContext::new()); | ||
| // Note that we do not add peer entry if we don't have any pending actions. | ||
| // This is done to not populate `self.peers` with peers that don't support | ||
| // our Kademlia protocol. | ||
| return Ok(()); | ||
| }; | ||
|
|
||
|
|
@@ -343,6 +345,7 @@ impl Kademlia { | |
| let pending_action = &mut self | ||
| .peers | ||
| .get_mut(&peer) | ||
| // If we opened an outbound substream, we must have pending actions for the peer. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't we get in a race case here between the following timelines?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might happen when there was an error reading inbound request at the same time as we sent an outbound request. The worst that can happen is we won't process pending actions for a peer, but this is not much different to an error during outbound request. As a side note, the PR doesn't change the way this race can happen. |
||
| .ok_or(Error::PeerDoesntExist(peer))? | ||
| .pending_actions | ||
| .remove(&substream_id); | ||
|
|
@@ -412,6 +415,10 @@ impl Kademlia { | |
| async fn on_inbound_substream(&mut self, peer: PeerId, substream: Substream) { | ||
| tracing::trace!(target: LOG_TARGET, ?peer, "inbound substream opened"); | ||
|
|
||
| // Ensure peer entry exists to treat peer as [`ConnectionType::Connected`]. | ||
| // when inserting into the routing table. | ||
| self.peers.entry(peer).or_default(); | ||
|
|
||
| self.executor.read_message(peer, None, substream); | ||
| } | ||
|
|
||
|
|
||
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.
dq: This won't affect networks with a single DHT started? Maybe we could add a trace here in case some issues popup in the future?
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.
Thinking outloud: If that's the case we could maybe add a new builder method on the KadConfig to signal we run in multi-dht-worlds? And return none only on multi-dht?
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.
This won't affect a single DHT network, as the entry is always inserted anyway when substream is opened. Strictly speaking, it doesn't make sense to consider transport-level connected peers as connected, because they might not speak the Kademlia protocol (even in a single DHT case). We are interested in substreams over a specific protocol.
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.
The logic shouldn't be different for a single DHT versus multi-DHT cases.