go-libp2p-examples icon indicating copy to clipboard operation
go-libp2p-examples copied to clipboard

How to connect to a node that is in other network apart from my local network

Open rahullenkala opened this issue 5 years ago • 6 comments

Hi, I am noob to libp2p. I am trying to figure out how to setup a peer-to-peer network for a blockchain. During my exploration I came across go libp2p examples repository and I tried to execute "Chat with Rendezvous" example but I couldn't connect to a node on a different network apart from my local network. Please guide me in getting over this issue and understand libp2p to the greater extent especially with routing and discovery aspects. NODE 1 (Local Network) scrnshrt1 NODE 2 (Local Network) scrnshrt2 NODE 3 (Different network) Screenshot from 2019-09-16 11-30-21

rahullenkala avatar Sep 16 '19 06:09 rahullenkala

@upperwal

rahullenkala avatar Sep 16 '19 06:09 rahullenkala

@rahullenkala This could be a NAT traversal problem. As you can see QmSs**zk is able to find QnQf**bV and Qmck**Sy but can't dial on their resp. ports because they do not permit incoming traffic.

You can read more about it on Wiki

Work around is to use some NAT traversal method. Libp2p support UPnP which can be enabled by passing libp2p.NATPortMap() to New function like below.

Most of the time this doesn't work with AWS directly. You need to setup a NAT instance and configure it accordingly

host, err := libp2p.New(
  context.Background(),
  libp2p.NATPortMap(),
)

or you can spin up a relay node and enable relay discovery in your code. Refer to relay example

Relay is more reliable but traffic between two nodes will always flow through this relay (high latency)

upperwal avatar Sep 16 '19 07:09 upperwal

@rahullenkala

I has tried this example and it's worked in different networks, but I has to wait about 5 minutes to get resolved

JackBekket avatar Dec 18 '19 21:12 JackBekket

@rahullenkala You can try to add the dht.Mode(dht.ModeServer) option as a parameter when calling dht.New(). Reference issue: https://github.com/libp2p/go-libp2p-examples/issues/171

iamgamelover avatar Dec 17 '20 12:12 iamgamelover

You can run your own bootstrap peer with this code. https://gist.github.com/upperwal/b80bd1516fbad79d0d2c7c4f5b99421b#file-libp2p_with_dht-go

and add the dht.Mode(dht.ModeServer) option as a parameter when calling dht.New().

iamgamelover avatar Dec 17 '20 13:12 iamgamelover

@rahullenkala You can try to add the dht.Mode(dht.ModeServer) option as a parameter when calling dht.New(). Reference issue: #171

thank you

bitcard avatar Dec 28 '20 16:12 bitcard