Closed agahEbrahimi closed 6 years ago
The chat example actually listens on 0.0.0.0 (the global ip4 address) by default.
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?
@agahEbrahimi yes. You can do that by specifying ./chat -d /ip4/0.0.0.0/tcp/3001
(the all address).
Hmm, it doesn't seem to be working, it gives protocol not found in multiaddr
as an error.
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.
I'm not requesting anything but having a chat example with both discovery and port mapping would be awesome (just as a suggestion).
I'm currently working on a refactor that should make setting up port mapping easier. Once that gets merged, we can improve the examples.
Awesome :)
@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.
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:
NATPortMap
): We try to ask the router to open a port for us.FYI, I'm guessing one probably needs to use the routed host for some of those NAT techniques to work.
@Stebalien Is NATPortMap
not deprecated.
https://github.com/libp2p/go-libp2p/blob/3b8f2275a2b24de5777aaa4fc77f1af57c5c4387/p2p/host/basic/basic_host.go#L50-L51
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.
@Stebalien I think https://github.com/libp2p/go-reuseport is the repo for STUN but its not being used in libp2p.
@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.
@Stebalien Ok. Got it. Thanks.
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