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

net: Add NAT-PMP port forwarding support #18077

Open
wants to merge 13 commits into
base: master
from

Conversation

@hebasto
Copy link
Member

hebasto commented Feb 5, 2020

Close #11902
This PR is an alternative to:

To compile with NAT-PMP support on Ubuntu libnatpmp-dev should be available.

TODO:

  • break into reviewable commits
  • add / change relevant command line options
  • release notes
  • docs changes

Log excerpt:

2020-02-05T20:12:28Z [mapport] NAT-PMP: public address = 95.164.65.194
2020-02-05T20:12:28Z [mapport] AddLocal(95.164.65.194:18333,3)
2020-02-05T20:12:28Z [mapport] NAT-PMP: port mapping successful.

Ref: libnatpmp


Some follow-ups are out of this PR's scope:

  • mention NAT-PMP library in the version message
  • integrate NAT-PMP into the GUI (already added)
@DrahtBot

This comment has been minimized.

Copy link
Contributor

DrahtBot commented Feb 5, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #18514 (test: remove rapidcheck integration and tests by fanquake)
  • #18450 (util: Use locale independent ToString(…) instead of locale dependent strprintf(…) for low-level string formatting by practicalswift)
  • #18421 (Periodically update DNS caches for better privacy of non-reachable nodes by naumenkogs)
  • #17428 (p2p: Try to preserve outbound block-relay-only connections during restart by hebasto)
  • #16883 (WIP: Qt: add QML based mobile GUI by icota)
  • #16549 ([WIP] UI external signer support (e.g. hardware wallet) by Sjors)
  • #16546 ([WIP] External signer support - Wallet Box edition by Sjors)
  • #16367 (Multiprocess build support by ryanofsky)
  • #14066 (gitian-linux: Build binaries for 64-bit POWER by luke-jr)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@laanwj

This comment has been minimized.

Copy link
Member

laanwj commented Feb 6, 2020

Thanks for picking this up again. I hope we manage to do this this time.

@hebasto hebasto force-pushed the hebasto:20200130-natpmp branch from 2a65212 to 60e2524 Feb 6, 2020
src/mapport.cpp Outdated Show resolved Hide resolved
@luke-jr

This comment has been minimized.

Copy link
Member

luke-jr commented Feb 6, 2020

Concept ACK

@hebasto hebasto force-pushed the hebasto:20200130-natpmp branch from 60e2524 to 4ff5349 Feb 7, 2020
@hebasto hebasto marked this pull request as ready for review Feb 7, 2020
@hebasto hebasto changed the title [WIP] net: Add NAT-PMP port forwarding support net: Add NAT-PMP port forwarding support Feb 7, 2020
@hebasto

This comment has been minimized.

Copy link
Member Author

hebasto commented Feb 7, 2020

It is ready for reviewing now.

@hebasto hebasto force-pushed the hebasto:20200130-natpmp branch from 4ff5349 to cf94431 Feb 7, 2020
@hebasto

This comment has been minimized.

Copy link
Member Author

hebasto commented Feb 7, 2020

Updated 4ff5349 -> cf94431 (pr18077.03 -> pr18077.04, compare):

added libnatpmp package to macOS 10.14 native Travis build.

@hebasto

This comment has been minimized.

Copy link
Member Author

hebasto commented Feb 8, 2020

Updated cf94431 -> 88248a4 (pr18077.04 -> pr18077.05, compare):

added:

  • changes to docs
  • release notes
@hebasto hebasto force-pushed the hebasto:20200130-natpmp branch from 88248a4 to c7e90ca Feb 10, 2020
@hebasto

This comment has been minimized.

Copy link
Member Author

hebasto commented Feb 10, 2020

Rebased after #17398 and #18081 have been merged.

@DrahtBot DrahtBot removed the Needs rebase label Feb 10, 2020
@dongcarl dongcarl self-assigned this Feb 10, 2020
@dongcarl

This comment has been minimized.

Copy link
Contributor

dongcarl commented Feb 10, 2020

Concept ACK, will test on my home router.

@Sjors

This comment has been minimized.

Copy link
Member

Sjors commented Feb 11, 2020

Concept ACK. Lightly tested configure / build on macOS.

Unfortunately I'm behind a IPv6 DS-Lite router, I can't test the IPv4 port forward. Perhaps -7 could be replaced by something more readable.

2020-02-11T17:48:27Z natpmp thread start
2020-02-11T17:48:27Z Bound to [::]:8333
2020-02-11T17:48:27Z Bound to 0.0.0.0:8333
2020-02-11T17:48:27Z init message: Loading P2P addresses...
2020-02-11T17:48:27Z NAT-PMP: readnatpmpresponseorretry() for public address failed with -7 error.
2020-02-11T17:48:27Z NAT-PMP: readnatpmpresponseorretry() for port mapping failed with -7 error. 

I looked up the error code, and it's what I would expect given my setup:

/* NATPMP_ERR_NOGATEWAYSUPPORT : the gateway does not support NAT-PMP */
#define NATPMP_ERR_NOGATEWAYSUPPORT (-7)

Two suggesitons for followups, or this PR:

  • add checkbox in QT Settings (above UPNP)
  • add support for IPv6 pinhole if the library supports it, see #17012 (looks like it doesn't)
@hebasto

This comment has been minimized.

Copy link
Member Author

hebasto commented Feb 11, 2020

@Sjors

Thank you for your review and testing.

I looked up the error code, and it's what I would expect given my setup:

/* NATPMP_ERR_NOGATEWAYSUPPORT : the gateway does not support NAT-PMP */
#define NATPMP_ERR_NOGATEWAYSUPPORT (-7)

Agree.
But in this initial PR I intentionally do not provide user-friendly error messages in order to keep ThreadNatpmp() dense and tight for easier reviewing ;)

In followups every library call (initnatpmp(), sendpublicaddressrequest() and sendnewportmappingrequest()) with the following readnatpmpresponseorretry() loops could be refactored out to separate functions with user-friendly error messages.

Two suggesitons for followups, or this PR:

* add checkbox in QT Settings (above UPNP)

Agree. From the OP:

Some follow-ups are out of this PR's scope:

* mention NAT-PMP library in the version message

* integrate NAT-PMP into the GUI
@hebasto

This comment has been minimized.

Copy link
Member Author

hebasto commented Mar 11, 2020

Rebased due to the conflict with merged #18264.

hebasto added 13 commits Feb 6, 2020
This commit does not change behavior.
This commit does not change behavior. It is a prerequisite for NAT-PMP
support adding.
@hebasto hebasto force-pushed the hebasto:20200130-natpmp branch from 4be5c3c to 1bf61f0 Mar 28, 2020
@hebasto

This comment has been minimized.

Copy link
Member Author

hebasto commented Mar 28, 2020

Rebased 4be5c3c -> 1bf61f0 due to the conflicts with #18134 and #18438.

@DrahtBot

This comment has been minimized.

Copy link
Contributor

DrahtBot commented Apr 6, 2020

🐙 This pull request conflicts with the target branch and needs rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

8 participants
You can’t perform that action at this time.