What is the best way to establish a connection to a node if I only know the PeerId? #2025
-
I have a node that is listening on a publicly reachable port. As such, doing any form of NAT traversal is not required. I've also successfully tested that - using the What I am trying to achieve is have a 2nd node connect to the first one solely based on the Idea 1 - Use the DHTMy first attempt was to use Kademlia and the official libp2p bootstrap nodes discoverable through It works using the DHT but we get a lot of unwanted connections. I presume this is because it is actually the IPFS DHT ( If this is the way to go about solving this problem, my question would be: Can I somehow avoid all these nodes connecting to me? I know that I can configure Kademlia to use a custom protocol string but I assume once I do that, I can no longer use the official libp2p bootstrap nodes because those will not support the custom protocol and hence my other nodes cannot discover the first one. Idea 2 - Use the relay protocolA second idea I had but I didn't yet get around to try it out is the circuit relay protocol.
Given that my first node is actually listening on a publicly reachable port, it feels a bit of a waste to use the relay protocol here. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Correct.
No, you can't, unless you spoof your address.
Correct.
Using libp2p-lookup it seems like they do:
Yes, you could, though (1) you need to ensure all your nodes are connected to the same set of bootstrap nodes and (2) all your traffic is relayed which is both not very performant and also incurring additional costs on the bootstrap nodes. You might as well want to take a look at the eth2 discovery mechanism https://docs.rs/discv5/0.1.0-beta.3/discv5/ or the rendezvous protocol, though I am not aware of a Rust implementation for the latter. |
Beta Was this translation helpful? Give feedback.
-
Does the rust DHT implementation have a client-only option? Part of being a DHT server node is expecting that nodes will regularly connect to you, ask questions, and then disconnect. If you are a client (including making sure that you aren't advertising your support for Note: When switching from server to client mode there will be some lag time on the inbound connections stopping as peers retry you and learn that you aren't a member of the DHT anymore.
Using information from Identify to figure out what protocols a node supports is something to be careful with. Sometimes protocols have different properties/subcomponents and may not support what you are looking for. For example, there are nodes that have the circuit-relay protocol enabled/advertised that are announcing "I speak the relay protocol and will happily talk to peers behind relays" as opposed to "I am willing to serve you as a public relay", I'm pretty sure the bootstrap.libp2p.io nodes are not public relays. |
Beta Was this translation helpful? Give feedback.
-
Yes. It's just that if you are in server mode then you'll start getting added to other people's routing tables and then you'll start getting used for queries. This means that @thomaseizinger's issue of seeing inbound connections come and go is likely just normal DHT behavior not an instance of IPFS nodes connecting for arbitrary reasons and then going away. However, it doesn't seem like running rust-libp2p as an IPFS public DHT server implementation seems like a good idea as if it doesn't support the same behavior (e.g. the ability to store IPNS records) then it might just end up hurting the network.
I can write up the issue + description of how to implement it, although I'm a Rust novice ATM. Update: issue #2032
It helps, although it's not everything. Different relays might decide to only serve certain people, or offer different SLAs (e.g. limited relays used for coordinating NAT holepunching vs full VPN style relays). |
Beta Was this translation helpful? Give feedback.
Correct.
No, you can't, unless you spoof your address.
Correct.
Using libp2p-lookup it seems like they do: