Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the public IP of the node that's connecting to the bootstrap server #1

Closed
jeshocarmel opened this issue Jun 19, 2019 · 9 comments

Comments

@jeshocarmel
Copy link

First of all @BenDerPan thanks for this awesome bootstrap server code. I'm using chat-with-rendezvous example as the basis for the application that I'm developing.

I'm using Amazon default VPC on my nodes to connect to the bootstrap server. They all connect to the bootstrap server (I'm using the Public IP of the bootstrap server) but their Private IP is being listed in the multiaddr and they fail to connect to each other.

I know that using a VPC would solve this problem, But I'm trying to make this work on the public internet. Any leads?

@BenDerPan
Copy link
Owner

BenDerPan commented Jun 19, 2019

Hi @jeshocarmel , if your VPC nodes are in the same local network, they will connect to each other, and if your nodes have public address, it should work too, you can look more info at #657

@jeshocarmel
Copy link
Author

Yes if the VPC nodes are in the same local network it's working. When I use instances of AWS where they are not connected through the local network but are only connected through internet, the discovery fails

@BenDerPan
Copy link
Owner

All your VPC nodes have their own public ip address ? I didn't tested with AWS VPC, but I guess it's problem of the public ips, can you listen with your public ip address? if not , there maybe the problem of NAT. :)

@jeshocarmel
Copy link
Author

Exactly. AWS doesn't allow to listen on the public IPs. This is the NAT problem. Any workaround that you know of?

@BenDerPan
Copy link
Owner

I think you can add a NAT relay node, then routing with DHT(bootstrap) to make your VPC nodes connect to each other, try this go-libp2p/#527 may help you

@jeshocarmel
Copy link
Author

jeshocarmel commented Jun 20, 2019

I tried this out. Not working. I'm writing down the code I used

Bootstrap Server (BS):

sourceMultiAddr, _ := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d", *listenHost, *port))

host, err := libp2p.New( ctx, 
libp2p.ListenAddrs(sourceMultiAddr),
libp2p.Identity(prvKey), 
libp2p.EnableRelay(circuit.OptDiscovery),
libp2p.NATPortMap(), )

Instance (EC2) A:

sourceMultiAddr, _ := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d", *listenHost, *port))

host, err := libp2p.New(
ctx,
libp2p.ListenAddrs(sourceMultiAddr),
libp2p.Identity(prvKey),
libp2p.DefaultMuxers,
libp2p.EnableRelay(),
)

kademliaDHT, err := dht.New(ctx, host)
checkAndPanic(err)

boostrap(ctx, kademliaDHT)
routingDiscovery := discovery.NewRoutingDiscovery(kademliaDHT)

go func() {
	for {
		time.Sleep(time.Second * 1)
		peerChan, err = routingDiscovery.FindPeers(ctx, dconfig.RendezvousString)

		for p := range peerChan {
			fmt.Println(p)
		}

		checkAndPanic(err)
	}
}()

Instance (EC2) B (same as above):

sourceMultiAddr, _ := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d", *listenHost, *port))

host, err := libp2p.New(
ctx,
libp2p.ListenAddrs(sourceMultiAddr),
libp2p.Identity(prvKey),
libp2p.DefaultMuxers,
libp2p.EnableRelay(),
)

kademliaDHT, err := dht.New(ctx, host)
checkAndPanic(err)

boostrap(ctx, kademliaDHT)
routingDiscovery := discovery.NewRoutingDiscovery(kademliaDHT)

go func() {
	for {
		time.Sleep(time.Second * 1)
		peerChan, err = routingDiscovery.FindPeers(ctx, dconfig.RendezvousString)

		for p := range peerChan {
			fmt.Println(p)
		}

		checkAndPanic(err)
	}
}()

Both A and B are not establishing connection with each other. They are both connected to the bootstrap server and their private addresses are being received by the each other. I can see that in my fmt.Println(p) statement .

Any help is appreciated. Thanks

@jeshocarmel
Copy link
Author

jeshocarmel commented Jun 20, 2019

This works. Now successfully able to communicate

@BenDerPan
Copy link
Owner

@jeshocarmel good job 👍

@jeshocarmel
Copy link
Author

Thanks @BenDerPan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants