Prysm: Enable UPnP for p2p

Created on 5 Jun 2019  路  14Comments  路  Source: prysmaticlabs/prysm

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

Good First Issue Help Wanted

All 14 comments

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:

  1. I added the libp2p.NATPortMap() option in the libp2p new instance creation in /shared/options.go, /tools/bootnode.go, /tools/bootnode-query/main.go and in /boot/relaynode/relaynode.go.
  2. I enabled UPNP on my router.
  3. Ran the beacon-chain service with and without UPNP and saw there are differences in the logs:
    Without UPNP :
    without_upnp

With UPNP:
with_upnp

I can see lots of

  • "ERROR p2p : Failed to write handshare to peer"
  • "WARN p2p : Disconnecting from peer on different contract"

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:

  1. When enabling UPNP and using NATPortMap() as one of the option in libp2p.New() - a new address is added to the multiAddr
    Without NATPortMap() :
    [2019-06-19 22:39:01] INFO p2p: [/ip4/192.168.0.107/tcp/12000]
    With NATPortMap() :
    [2019-06-19 22:42:21] INFO p2p: [/ip4/192.168.0.107/tcp/12000 /ip4/118.173.172.41/tcp/10331]
    The second address' ip address segment is, of course, my public ip address.
  1. I can see that libp2p used UPNP to open a port in the router admin console:
    upnp-stats

  2. 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__:

  1. @katzdan

@ceresstation please take a look at the submitted work:

  • PR by @katzdan

@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.__

Was this page helpful?
0 / 5 - 0 ratings