libp2p/go-libp2p-examples

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

Opened this issue · 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 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)

@rahullenkala

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

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

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().

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

thank you