-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Changes to support NAT-PMP #15717
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
Changes to support NAT-PMP #15717
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
@MishraShivendra I would love to review this, would you be able to do the following:
|
@dongcarl |
No need to close the PR; you can overwrite it by force pushing. |
@practicalswift This is code copied from another project; unless we're going to submit improvements upstream, nits here are pointless. |
@MishraShivendra Can you clarify which files/directories that are meant to be left as-is (with flaws reported upstream) and which files/directories that are not? :-) |
@practicalswift It's literally in the PR description, and also obvious from the code (it's copyright someone else...) |
@sipa The reason that I'm asking explicitly is that I noticed that some files added to this repo were not identical to the corresponding files in the repo that appears to be the upstream. @MishraShivendra What is the correct upstream repo the files were copied from? |
@practicalswift Thanks for reviewing the changes. Those files were taken from here. I've taken just the files needed. A few headers were merged together and useless code was removed. A few other error codes were also added. Please see diff between corresponding .c and .h files. Would push suggested changes in a while.
@sipa I think we can fix/modify based on our need. Those files are already way too customized for upstream. @dongcarl Removing license headers will lead to writing implementation of our own. Not sure if that would be a good idea. Any input? |
travis linter complains; either this needs the expected include guards, or to be excluded from the lints
I don't think this is allowed, at least the 3-clause BSD license has more restrictions than the MIT one. |
Ok, we discussed the license issue on IRC. The conclusion was that it's probably best to mention the differing license for the files in |
I was wrong, see comment here: #15717 (comment) |
I'm sorry about the confusion, https://github.com/miniupnp/libnatpmp is indeed the repo that's being updated. |
@MishraShivendra It seems that Travis is failing. Could you take a look at the errors there? Aside from that, please rearrange your commits so they look something like this:
Obviously there might be some mixing of 2 and 3, but at the very least 1 should be a separate commit. |
There's no excuse to subtree this. It should be a normal shared library dependency. |
Concept ACK in any case, thanks for picking this up. |
@dongcarl @laanwj Thanks for those input and clarification.
Changes already in progress on a private branch. I'll push them shortly.
@luke-jr |
There is already a separate shared library. |
* Pulls core NAT-PMP files from https://github.com/miniupnp/libnatpmp.git * Above codes are ported/filtered for easier integration.
@dongcarl @practicalswift The current commit includes most of the changes you suggested. Can you please take a look? @luke-jr Can you please point me to it. I couldn't find any place where we already build one. Did you mean upnp shared lib? |
@MishraShivendra Sure! In light of previous comments -- do you want me to review all the files or just a subset? In the latter case, what subset? :-) |
@practicalswift |
@MishaShivendra It's installed with the user's OS. |
Pushed suggested changes. |
#else | ||
gArgs.AddArg("-upnp", strprintf("Use UPnP to map the listening port (default: %u)", 0), false, OptionsCategory::CONNECTION); | ||
gArgs.AddArg("-portmap", strprintf("Use NAT-PMP to map the listening port (default: %u)", 0), false, OptionsCategory::CONNECTION); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both should be supported...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luke-jr
I meant to use same switch "-portmap" for upnp as well as NAT-PMP. And the particular implementation is picked based on "USE_UPNP" flag (In this file as well as net.cpp). So I believe both are supported but picked based on USE_UPNP flag. Do you see any problem here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
USE_UPNP is a compile-time option, not run-time.
UPnP and NAT-PMP are two completely different protocols. They don't do the same thing. Some routers may support only one or the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can someone please give input in the above? |
You should leave UPnP stuff alone for this. Just add NAT-PMP support as a separate feature. |
There was some discussion about this in IRC yesterday: http://www.erisian.com.au/bitcoin-core-dev/log-2019-04-24.html#l-255 I did want to throw out as a suggestion that instead of running this code inside bitcoind or even adding it to the project we could consider calling out to a command line client with boost::process like: https://superuser.com/questions/192132/how-to-automatically-forward-a-port-from-the-router-to-a-mac-upnp/192487#192487. This could potentially be a very small code change after #15382 which adds boost::process. But this is just a thought which doesn't need to affect the current effort. |
Yes that discussion resulted in a few conclusions:
|
Please, no scope creep here. This can always be done later but there's no need to complicate this effort even further with a requirement that it should run outside the process. |
NACK. There is no excuse for this. It is universally held to be a bad practice in the open source community, and for very good reasons. We have an excuse to bundle consensus-critical stuff because upstream doesn't generally consider the ramifications of some bugfixes, but that does not apply to NAT-PMP at all. |
Just in case there is a misunderstanding, the change I was referring to is potentially a very small change after #15382. Something like: gArgs.AddArg("-upnpc_bin", "Path to port forwarding client binary.");
...
if (gArgs.IsArgSet("-upnp_bin")) {
bp::system(strprintf("%s %i %i", gArgs.GetArg("-upnp_bin"), internal_port, external_port));
} But I mostly just wanted to suggest it an alternative to the approaches discussed above (which all seem perfectly fine to me). |
Concept ACK. I'm OK with compiling this by default I don't think we should turn this on by default until the GUI is updated: that's better done in a followup. I'm reluctant to strip UPnP compilation by default. The GUI currently has a "map port using UPnP" (off by default). Although it's tempting to just change the text and meaning of that textbox, that's a can of worms by itself. It seems better to just add a checkbox for this new setting, and mention in the tooltip which one is recommended. I tend to agree with @luke-jr on avoiding pulling in code. The Depends system seems more appropriate. From IRC in favor of subtree'ing:
The last Homebrew release is from 2015. Ditto for Ubuntu Bionic. I haven't tested those releases. If they have problems then we could encourage the author to issue a new release. Also, a slight lazy argument of why fresh releases aren't super important, is that anyone who can compile from source can learn how to forward a port; this library primarily benefits users of the binary distribution. There is still is some modest commit activity, so we shouldn't declare it dead upstream. Even if it was, I would prefer forking the repo in the bitcoin-core org. The act us of using it could also bring new life to the project. In fact I think we should encourage that, since a lot projects stand to benefit from this library. For a followup I like the idea of using |
I don't seem to agree. It could be difficult to find these errors through running the binary with the help of boost::process. I happen to agree with @luke-jr idea to sub-tree libnatpmp related changes. Just to sum it up:
Let me know if you all agree with the aforementioned. |
That's not what I meant. Just use standard |
|
No, I would not sub-tree libnatpmp. Just rely on |
Needs rebase |
There hasn't been much activity lately and the patch still needs rebase, so I am closing this for now. Please let me know when you want to continue working on this, so the pull request can be re-opened. |
Hi, First, I'm not sure if this task is still "up for grabs", because it's closed now. However, the icon is still there, so it should be. Anyway, I'm working on it out of curiosity, because I only know about UPnPC, so I thought it would be nice to learn how NAT-PMP works. :) The commit in my forked repo contains following changes:
Well, that's it. I don't know the current state of this task, but in any case, it was fun writing configure scripts, trying out various Makefile settings,...and reading through ugly C code. Regards, |
Don't do this.
.la files are generally considered obsolete... |
@luke-jr Anyway, I consider this task as obsolete then. Thanks. |
Adding. NAT-PMP support is not obsolete, see #11902. The question is just how. I think @luke-jr's point about integrating the source directory is that this practice should be avoided, especially for projects that are still being (somewhat) maintained. It's better to make a PR upstream to add pkg-config support. Meanwhile you could add it to https://github.com/bitcoin/bitcoin/tree/master/depends, which works by fetching the code from its original source, and has room for patches. The only problem there is that afaik you can't build 1 depends package and get the rest via pkg-config (but I could be wrong). |
a191e23 doc: Add release notes (Hennadii Stepanov) ae749d1 doc: Add libnatpmp stuff (Hennadii Stepanov) e28f9be ci: Add libnatpmp-dev package to some builds (Hennadii Stepanov) 5a0185b gui: Add NAT-PMP network option (Hennadii Stepanov) a39f733 net: Add -natpmp command line option (Hennadii Stepanov) 28acffd net: Add NAT-PMP to port mapping loop (Hennadii Stepanov) a8d9f27 net: Add libnatpmp support (Hennadii Stepanov) 58e8364 gui: Apply port mapping changes on dialog exit (Hennadii Stepanov) cf151cc scripted-diff: Rename UPnP stuff (Hennadii Stepanov) 4e91b1e net: Add flags for port mapping protocols (Hennadii Stepanov) 8b50d1b net: Keep trying to use UPnP when -upnp=1 (Hennadii Stepanov) 28e2961 refactor: Replace magic number with named constant (Hennadii Stepanov) 02ccf69 refactor: Move port mapping code to its own module (Hennadii Stepanov) Pull request description: Close #11902 This PR is an alternative to: - #12288 - #15717 To compile with NAT-PMP support on Ubuntu [`libnatpmp-dev`](https://packages.ubuntu.com/source/bionic/libnatpmp) should be available. 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. ``` See: [`libnatpmp`](https://miniupnp.tuxfamily.org/libnatpmp.html) --- 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](#18077 (comment))) ACKs for top commit: laanwj: Tested and code review ACK a191e23 Tree-SHA512: 10e19267c21bf30f20ff1abfc882d526049f0e790b95e12f109dc2bed7c0aef45de03eaf967f4e667e7509be04f1873a5c508087393d947205f3aab2ad6d7cf1
Changes to support NAT-PMP port forwarding based on libnatpmp to address #11902.
Changes include the following:
Test
Note to reviewers are here, need insights.