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

Chat Example #311

Closed
agahEbrahimi opened this issue Apr 14, 2018 · 15 comments
Closed

Chat Example #311

agahEbrahimi opened this issue Apr 14, 2018 · 15 comments

Comments

@agahEbrahimi
Copy link

Hello,

I was wondering how I would be able to give a non local IP to the chat example. When running the executable, a port is given to it, but how would I be able to set it so that it works with the public IP and not the local IP (127.0.0.1).

Thank you in advance,
Agah Ebrahimi

@Stebalien
Copy link
Member

The chat example actually listens on 0.0.0.0 (the global ip4 address) by default.

@agahEbrahimi
Copy link
Author

but that's not the case for the sender, is it? wouldn't I have to set the public address for the sender address if I want to communicate over the internet?

@Stebalien
Copy link
Member

@agahEbrahimi yes. You can do that by specifying ./chat -d /ip4/0.0.0.0/tcp/3001 (the all address).

@agahEbrahimi
Copy link
Author

agahEbrahimi commented Apr 15, 2018

Hmm, it doesn't seem to be working, it gives protocol not found in multiaddr as an error.

@upperwal
Copy link
Contributor

0.0.0.0 in the code means listen to all IPv4 addresses (ie. accept connects from all)

Try this if you want to run it on a public network.

Simple Case: Atleast one public IP

Run this on a system with public IP address:

./chat -sp 3000

It should output something like this
Run './chat -d /ip4/127.0.0.1/tcp/3000/ipfs/<node_id>' on another console.

Now replace 127.0.0.1 with the public IP of the previous system and execute

./chat -d /ip4/<public_ip>/tcp/3000/ipfs/<node_id>

on any system (public or private ip)

Not so simple case: Different private networks
This example does not support this. You need to enable discovery and port mapping for this.

@agahEbrahimi
Copy link
Author

I'm not requesting anything but having a chat example with both discovery and port mapping would be awesome (just as a suggestion).

@Stebalien
Copy link
Member

I'm currently working on a refactor that should make setting up port mapping easier. Once that gets merged, we can improve the examples.

@agahEbrahimi
Copy link
Author

Awesome :)

@upperwal
Copy link
Contributor

@Stebalien Would it be possible to share these changes? It would also be great if more NAT traversal techniques (NAT hole punching and STUN) are added to libp2p-nat. Let me know what do you think about it.

@Stebalien
Copy link
Member

Actually, I forgot. @jvsteiner already added a nice option for configuring NAT port mapping. Pass the NATPortMap() option to libp2p.New(...).


We actually have three nat-traversal solutions at the moment:

  1. UPnP (NATPortMap): We try to ask the router to open a port for us.
  2. Custom hole-punching/STUN through a combination of peer-routing, external-address/port discovery, and reuseport (we try to use one local port for all inbound and outbound connections).
  3. Custom TURN (in-progress) through go-libp2p-circuit. Unfortunately, we don't currently advertise relayed addresses by default but we're working on that.

@jvsteiner
Copy link
Contributor

jvsteiner commented Apr 16, 2018

FYI, I'm guessing one probably needs to use the routed host for some of those NAT techniques to work.

@upperwal
Copy link
Contributor

@Stebalien Is NATPortMap not deprecated.

// This option is deprecated in favor of HostOpts and NewHost.
const NATPortMap Option = iota

libp2p uses https://github.com/fd/go-nat repo for NAT and I could only find NAT UPnP and NAT-PMP, could you please point me to STUN implementation used in libp2p.

@upperwal
Copy link
Contributor

@Stebalien I think https://github.com/libp2p/go-reuseport is the repo for STUN but its not being used in libp2p.

@Stebalien
Copy link
Member

@upperwal

Is NATPortMap not deprecated.

That option is (technically) deprecated but NATPortMap isn't. That comment is just telling you to configure the nat manager using the HostOpts instead of passing that option to NewHost.

@Stebalien I think https://github.com/libp2p/go-reuseport is the repo for STUN but its not being used in libp2p.

It's used by go-tcp-transport which is used by go-libp2p-swarm for TCP connections.

@upperwal
Copy link
Contributor

@Stebalien Ok. Got it. Thanks.

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

4 participants