-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 achieve punching behind nat or firewall, Is there an example? #312
Comments
What you need is a mechanism for Peer Discovery and Port mapping for NAT. You can look at this example for bootstrapping. NAT Port mapping is taken care by go-libp2p-nat which can be used as follows. // create a network.
// Docs: https://godoc.org/github.com/libp2p/go-libp2p-swarm#NewNetwork
network, err := swarm.NewNetwork(ctx, sourceMultiAddr, ...)
// now create a host and pass NATManager as hostOpt
natMgr := basichost.NewNATManager(network)
hostOpt := basichost.HostOpts{
NATManager: natMgr,
}
host := basichost.New(network, hostOpt)
|
Does the bootstrap example work correctly outside of the local network? |
@agahEbrahimi If I can understand your question correctly you are talking about port mapping incase of NAT. If so, first of all I haven't tested it, so not sure. But the example is using Just compile and run it. |
@upperwal No, I'm referring to the peer discovery and not the port mapping. Sorry I phrased my question incorrectly. |
I believe it should work. Just try it. More info on compiling here |
Is it just on a local network or does it work across routers (over internet) too? |
Yes, you can run it across networks (the internet) easily if your system has a public IP address and not so easily if they are behind NAT (have a private IP address). Incase of public IP's you just have to replace Incase of a NAT (private IP's), process to establish connection will be complicated (don't worry everything is taken care within libp2p). Libp2p will use NAT port mapping (the thing I was talking about earlier) to convert You need to know what |
Ah, so I just change the IPs in the Go code to their respective public IPs and they would be able to find each (after the Nat Port mapping process which you were talking about)? but wouldn't they still have to have the session hash? |
When you ran On executing |
I get that part but if the person running the ./routed-echo -l 10001 -d QmfRY4vuKpU2tApACrbmYFn9xoeNzMQhLXg7nKnyvnzHeL has never initiated contact with the other node how does it get access to this address "QmfRY4vuKpU2tApACrbmYFn9xoeNzMQhLXg7nKnyvnzHeL"? |
@upperwal how to construct a private bootstrapper node? If i don't want run the whole ipfs node. Is there any examples to do that? |
@jiangsuwwj1 there's a bootstrapping example here: #278 |
@Stebalien Thank you very much, I will try later. |
release the stream scope if the conn fails to open a new stream
I want to achieve p2p communication through libp2p, and these two are in the private network, how should I do?
The text was updated successfully, but these errors were encountered: