-
Notifications
You must be signed in to change notification settings - Fork 1k
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
kad: consume FromSwarm::NewExternalAddrOfPeer
#5313
Comments
FromSwarm::NewExternalAddrOfPeer
FromSwarm::NewExternalAddrOfPeer
I manually hooked it up to the swarm :) Glad to see this implemented in the protocol. However there's the question whether the peer wants to participate in the network when local peer participates in two or more separate DHT networks. |
If a peer does not wish to participate in the DHT network, they can change the mode to |
The problem is, both behaviours that use different protocols will receive |
As I think about it, we could still add the peer to the routing table since in client mode, they wont be able to participate in the DHT until it is switched to server mode (either manually or if auto is set, by confirmation of an external address). This way, two or more dht implementations wont be fragmented. EDIT: We could probably just do the following diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs
index fb77f3c0e..64c3a6c14 100644
--- a/protocols/kad/src/behaviour.rs
+++ b/protocols/kad/src/behaviour.rs
@@ -42,6 +42,7 @@ use libp2p_identity::PeerId;
use libp2p_swarm::behaviour::{
AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm,
};
+use libp2p_swarm::NewExternalAddrOfPeer;
use libp2p_swarm::{
dial_opts::{self, DialOpts},
ConnectionDenied, ConnectionHandler, ConnectionId, DialError, ExternalAddresses,
@@ -2050,6 +2051,13 @@ where
}
}
+ fn on_new_external_peer(
+ &mut self,
+ NewExternalAddrOfPeer { peer_id, addr }: NewExternalAddrOfPeer,
+ ) {
+ self.add_address(&peer_id, addr.clone());
+ }
+
fn on_dial_failure(&mut self, DialFailure { peer_id, error, .. }: DialFailure) {
let Some(peer_id) = peer_id else { return };
@@ -2628,6 +2636,9 @@ where
}
FromSwarm::DialFailure(dial_failure) => self.on_dial_failure(dial_failure),
FromSwarm::AddressChange(address_change) => self.on_address_change(address_change),
+ FromSwarm::NewExternalAddrOfPeer(new_external_peer) => {
+ self.on_new_external_peer(new_external_peer)
+ }
_ => {}
}
} |
IIUC the goal here is to update the address of a peer that is already a |
Possible, though based on the OP, it sounds like it could be both, in which case i recall @thomaseizinger thoughts? |
Yes, I am pretty sure If a protocol is essential for a node to operate, you should disconnect it on the |
This is my understanding of the problem: Suppose there is a node sit in-between two different DHTs. Then a peer from one of the DHTs triggers |
Is there much harm in that? Would you want to validate first that a node speaks the corresponding kad protocol before returning it in queries from other nodes? |
There is essentially no harm to that single peer, but it can do harm to the network. We marked deprecated for default configuration with IPFS protocol name for the behaviour earlier with the intention of preventing other DHT networks from accidentially merging with IPFS' DHT. If both networks are large enough and different enough, records from the other network will only be unnecessary overhead since those peers contributes little. |
Currently, we only add nodes to the DHT that we dialed successfully. That guarantees that at least the IP is valid and reachable. In addition, we also check that we actually speak the same kademlia protocol, see rust-libp2p/protocols/kad/src/behaviour.rs Line 2239 in a91c48f
So currently, only nodes that speak the correct protocol are added to the DHT, unless you use Perhaps the better solution would be to dial the peer upon receiving this address to test if the peer speaks kademlia? If it does, each kademlia behaviour will add it to the corresponding routing table. Or maybe dialing should not happen in the protocols but is something that the user should do? |
Ideally when a peer is dialed or changes its addresses, the swarm should emit an event, mentioning the peer and its supported protocols. Different protocols could then decide what to do with this information. E.g if a peer supports 2 DHTs, and a remote peer only supporting 1 DHT changes its external address, the routing table of the DHT in which this remote peer participates must be updated, while the other DHT will simply ignore the event. But if this remote peer starts supporting the other DHT, then it should be added to the routing table of the second DHT. |
In rust-libp2p, identify is decoupled from the swarm so this is currently not possible and unless major changes are done, will unlikely be possible in the future. |
We should probably leave this to the user because it's a very rare case. I'm just bringing it to attention. |
Counter-part to #5103. We should consume this event and extend our routing table.
rust-libp2p/swarm/src/behaviour.rs
Lines 454 to 455 in bee8199
Probably here:
rust-libp2p/protocols/kad/src/behaviour.rs
Lines 2614 to 2634 in bee8199
The text was updated successfully, but these errors were encountered: