Apparently libp2p already supports UPnP and PMP https://github.com/libp2p/go-libp2p/issues/319#issuecomment-383505818
Enabling this would mean users with UPnP enabled routers would not need to configure port forwarding if they want to expose the p2p port.
Not sure how this would behave with the docker images
I _think_ this functionality is already enabled within libp2p core library. Also see: https://github.com/libp2p/go-libp2p/issues/375#issuecomment-407122416
It seems that providing NatPortMap option might be enough to enable this functionality. I'm not sure how to test this actually works as this method has no explicit tests and documentation is lacking details. Does this automatically broadcast the allocated port / public IP from the router?
Other references:
With regards to docker, I believe you can give it access to the host network with --network host. That should allow upnp functionality within a docker image.
Labelling with help wanted, if anyone wants to investigate this issue and report their findings here.
I'll look into it.
Initial test results:

With UPNP:

I can see lots of
I didn't see these msgs when UPNP was disabled on the router.
Team, any ideas?
Those warnings are normal. It means that someone else is connect to the network and asking for the wrong contract. These context failures seem like a bigger issue.
The real test is if you can dial your node from the outside world. Have you been able to verify that?
Thanks @prestonvanloon , I'll check that and report.
Hi,
findings:
I can see that libp2p used UPNP to open a port in the router admin console:

Finally - I created a node.js script that tries to connect to the peerId of the beacon service directly.
2019-06-19T17:46:01.778638+00:00 app[web.1]: node has started (true/false): true
2019-06-19T17:46:01.779088+00:00 app[web.1]: listening on:
2019-06-19T17:46:01.779300+00:00 app[web.1]: /ip4/127.0.0.1/tcp/46115/ipfs/QmS82vo2wdQrn8nBeJta54zodfNJW7BaeFJAbaCZAWfg9r
2019-06-19T17:46:01.779456+00:00 app[web.1]: /ip4/172.19.46.50/tcp/46115/ipfs/QmS82vo2wdQrn8nBeJta54zodfNJW7BaeFJAbaCZAWfg9r
2019-06-19T17:46:02.603465+00:00 app[web.1]: /app/prysm-libp2p-upnp-test.js:62
2019-06-19T17:46:02.603496+00:00 app[web.1]: throw err
2019-06-19T17:46:02.603504+00:00 app[web.1]: Error: "/plaintext/1.0.0" not supported
The last line shows that there is a connection (it's rejected because the sample sends a protocol that's not supported but at that point the peers are already connected).
To conclude - the NATPortMap() looks like it's working.
@terencechain - thanks for the guidelines you gave me.
@prestonvanloon - are there any additional tests/research that needs to be done? or shall I move forward with code changes and add NATPortMap() in the libp2p.New calls?
Awesome! This is excellent work.
Let鈥檚 add this as a feature flag where the default value is OFF. We can test it out in a few scenarios and then graduate the flag with default value ON.
Issue Status: 1. Open 2. Started 3. Submitted 4. Done
__This issue now has a funding of 300.0 DAI (300.0 USD @ $1.0/DAI) attached to it.__
Issue Status: 1. Open 2. Started 3. Submitted 4. Done
__Work has been started__.
These users each claimed they can complete the work by 11聽months, 2聽weeks from now.
Please review their action plans below:
1) katzdan has been approved to start work.
Add the option for NAT enabled comm during libp2p init.
Learn more on the Gitcoin Issue Details page.
Resolved in #2860. Thanks for all of the research and a quick turn around on the feature!
Issue Status: 1. Open 2. Started 3. Submitted 4. Done
__Work for 300.0 DAI (300.0 USD @ $1.0/DAI) has been submitted by__:
@ceresstation please take a look at the submitted work:
@ceresstation can you help to release the bounty please?
Issue Status: 1. Open 2. Started 3. Submitted 4. Done
__The funding of 300.0 DAI (300.0 USD @ $1.0/DAI) attached to this issue has been approved & issued to @katzdan.__