1

I want to connect two hosts (libp2p nodes), each of them behind a home router (thus, NAT).

The relay example in the official Go implementation repo simulates two undialable hosts and spawns a relay node, which is used to establish the connection across the NAT. It's a good example, it works and makes sense. I'd like to start from there.

What I can't find is how to automatically discover and use a public relay instead of a dummy one running on the same system.

I asked ChatGPT and she pointed me out to:

func main() {
    ctx := context.Background()

    // Create the first node
    node1, err := libp2p.New(ctx)
    if err != nil {
        panic(err)
    }

    // Create the second node
    node2, err := libp2p.New(ctx)
    if err != nil {
        panic(err)
    }

    // Set up a relay for each node
    err = relay.NewAutoRelay(ctx, node1)
    if err != nil {
        panic(err)
    }

    err = relay.NewAutoRelay(ctx, node2)
    if err != nil {
        panic(err)
    }

But it doesn't sound sound at all.

What's the standard setup to make two nodes behind NAT talk to each other?

Fabio B.
  • 9,138
  • 25
  • 105
  • 177
  • I'm not aware of any public relays. Just deploy your own. There's examples of trivial node.js (websocket) servers used for bootstrapping WebRTC connections that would likely work for you as well. – selbie Feb 21 '23 at 01:42

0 Answers0