Finding and connecting to peers with a known PeerId with rust-libp2p

I need to set up a swarm to connect to peers with known peer IDs but that may be behind firewalls. Right now it seems like the “easiest way” to do this is

  1. Create a gossipsub topic for publishing publicly accessible multiaddr
  2. Use autonat to discover own multiaddr
  3. Publish multiaddr on the gossipsub topic
  4. Receive message from topic and then add peerid/multiaddr to list of kademlia peers
  5. Dial peers with known publicly accessible multiaddr

This isn’t too complex, but it does feel kind of hacky and makes me think I’m misunderstanding something fundamental. Is there a better method for establishing a connection to a peer with known peerid or does this sound about right?

I think the Identify protocol is what I’m looking for.

Just some thoughts. You could:

  1. have a publicly addressable bootstrap node. Connect new nodes to this bootstrap node and setup kademlia.
  2. Each node advertises its multiaddr in kademlia.
  3. Nodes can find the multiaddr of a given peer by querying kademlia.

Not sure if there’s a public rust-libp2p bootstrap node, but you could probably use the ipfs bootstrap nodes for this.