Skip to content

Commit a8d9f27

Browse files
committed
net: Add libnatpmp support
1 parent 58e8364 commit a8d9f27

14 files changed

+195
-13
lines changed

ci/test/00_setup_env_native_qt5.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export LC_ALL=C.UTF-8
99
export CONTAINER_NAME=ci_native_qt5
1010
export DOCKER_NAME_TAG=ubuntu:18.04 # Check that bionic gcc-7 can compile our c++17 and run our functional tests in python3, see doc/dependencies.md
1111
export PACKAGES="python3-zmq qtbase5-dev qttools5-dev-tools libdbus-1-dev libharfbuzz-dev"
12-
export DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1 ALLOW_HOST_PACKAGES=1"
12+
export DEP_OPTS="NO_QT=1 NO_UPNP=1 NO_NATPMP=1 DEBUG=1 ALLOW_HOST_PACKAGES=1"
1313
export TEST_RUNNER_EXTRA="--previous-releases --coverage --extended --exclude feature_dbcrash" # Run extended tests so that coverage does not fail, but exclude the very slow dbcrash
1414
export RUN_SECURITY_TESTS="true"
1515
export RUN_UNIT_TESTS_SEQUENTIAL="true"

configure.ac

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ AC_ARG_ENABLE([upnp-default],
143143
[use_upnp_default=$enableval],
144144
[use_upnp_default=no])
145145

146+
AC_ARG_WITH([natpmp],
147+
[AS_HELP_STRING([--with-natpmp],
148+
[enable NAT-PMP (default is yes if libnatpmp is found)])],
149+
[use_natpmp=$withval],
150+
[use_natpmp=auto])
151+
152+
AC_ARG_ENABLE([natpmp-default],
153+
[AS_HELP_STRING([--enable-natpmp-default],
154+
[if NAT-PMP is enabled, turn it on at startup (default is no)])],
155+
[use_natpmp_default=$enableval],
156+
[use_natpmp_default=no])
157+
146158
AC_ARG_ENABLE(tests,
147159
AS_HELP_STRING([--disable-tests],[do not compile tests (default is to compile)]),
148160
[use_tests=$enableval],
@@ -1203,6 +1215,7 @@ if test "x$enable_fuzz" = "xyes"; then
12031215
enable_wallet=no
12041216
use_bench=no
12051217
use_upnp=no
1218+
use_natpmp=no
12061219
use_zmq=no
12071220

12081221
AX_CHECK_PREPROC_FLAG([-DABORT_ON_FAILED_ASSUME],[[DEBUG_CPPFLAGS="$DEBUG_CPPFLAGS -DABORT_ON_FAILED_ASSUME"]],,[[$CXXFLAG_WERROR]])
@@ -1300,6 +1313,13 @@ if test x$have_miniupnpc != xno; then
13001313
fi
13011314
fi
13021315

1316+
dnl Check for libnatpmp (optional).
1317+
if test "x$use_natpmp" != xno; then
1318+
AC_CHECK_HEADERS([natpmp.h],
1319+
[AC_CHECK_LIB([natpmp], [initnatpmp], [NATPMP_LIBS=-lnatpmp], [have_natpmp=no])],
1320+
[have_natpmp=no])
1321+
fi
1322+
13031323
if test x$build_bitcoin_wallet$build_bitcoin_cli$build_bitcoin_tx$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench = xnonononononono; then
13041324
use_boost=no
13051325
else
@@ -1558,6 +1578,31 @@ else
15581578
fi
15591579
fi
15601580

1581+
dnl Enable NAT-PMP support.
1582+
AC_MSG_CHECKING([whether to build with support for NAT-PMP])
1583+
if test "x$have_natpmp" = xno; then
1584+
if test "x$use_natpmp" = xyes; then
1585+
AC_MSG_ERROR([NAT-PMP requested but cannot be built. Use --without-natpmp])
1586+
fi
1587+
AC_MSG_RESULT([no])
1588+
use_natpmp=no
1589+
else
1590+
if test "x$use_natpmp" != xno; then
1591+
AC_MSG_RESULT([yes])
1592+
AC_MSG_CHECKING([whether to build with NAT-PMP enabled by default])
1593+
use_natpmp=yes
1594+
natpmp_setting=0
1595+
if test "x$use_natpmp_default" != xno; then
1596+
use_natpmp_default=yes
1597+
natpmp_setting=1
1598+
fi
1599+
AC_MSG_RESULT($use_natpmp_default)
1600+
AC_DEFINE_UNQUOTED([USE_NATPMP], [$natpmp_setting], [NAT-PMP support not compiled if undefined, otherwise value (0 or 1) determines default state])
1601+
else
1602+
AC_MSG_RESULT([no])
1603+
fi
1604+
fi
1605+
15611606
dnl these are only used when qt is enabled
15621607
BUILD_TEST_QT=""
15631608
if test x$bitcoin_enable_qt != xno; then
@@ -1704,6 +1749,7 @@ AC_SUBST(SQLITE_LIBS)
17041749
AC_SUBST(TESTDEFS)
17051750
AC_SUBST(MINIUPNPC_CPPFLAGS)
17061751
AC_SUBST(MINIUPNPC_LIBS)
1752+
AC_SUBST(NATPMP_LIBS)
17071753
AC_SUBST(EVENT_LIBS)
17081754
AC_SUBST(EVENT_PTHREADS_LIBS)
17091755
AC_SUBST(ZMQ_LIBS)
@@ -1791,6 +1837,7 @@ else
17911837
fi
17921838
echo " with bench = $use_bench"
17931839
echo " with upnp = $use_upnp"
1840+
echo " with natpmp = $use_natpmp"
17941841
echo " use asm = $use_asm"
17951842
echo " sanitizers = $use_sanitizers"
17961843
echo " debug enabled = $enable_debug"

depends/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ NO_QR ?=
3737
NO_WALLET ?=
3838
NO_ZMQ ?=
3939
NO_UPNP ?=
40+
NO_NATPMP ?=
4041
MULTIPROCESS ?=
4142
FALLBACK_DOWNLOAD_PATH ?= https://bitcoincore.org/depends-sources
4243

@@ -139,10 +140,12 @@ sqlite_packages_$(NO_SQLITE) = $(sqlite_packages)
139140
wallet_packages_$(NO_WALLET) = $(bdb_packages_) $(sqlite_packages_)
140141

141142
upnp_packages_$(NO_UPNP) = $(upnp_packages)
143+
natpmp_packages_$(NO_NATPMP) = $(natpmp_packages)
144+
142145
zmq_packages_$(NO_ZMQ) = $(zmq_packages)
143146
multiprocess_packages_$(MULTIPROCESS) = $(multiprocess_packages)
144147

145-
packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(qt_packages_) $(wallet_packages_) $(upnp_packages_)
148+
packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(qt_packages_) $(wallet_packages_) $(upnp_packages_) $(natpmp_packages_)
146149
native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages)
147150

148151
ifneq ($(zmq_packages_),)
@@ -200,6 +203,7 @@ $(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_
200203
-e 's|@no_zmq@|$(NO_ZMQ)|' \
201204
-e 's|@no_wallet@|$(NO_WALLET)|' \
202205
-e 's|@no_upnp@|$(NO_UPNP)|' \
206+
-e 's|@no_natpmp@|$(NO_NATPMP)|' \
203207
-e 's|@multiprocess@|$(MULTIPROCESS)|' \
204208
-e 's|@debug@|$(DEBUG)|' \
205209
$< > $@

depends/config.site.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ if test -z $with_miniupnpc && test -n "@no_upnp@"; then
4646
with_miniupnpc=no
4747
fi
4848

49+
if test -z $with_natpmp && test -n "@no_natpmp@"; then
50+
with_natpmp=no
51+
fi
52+
4953
if test -z $with_gui && test -n "@no_qt@"; then
5054
with_gui=no
5155
fi

depends/packages/libnatpmp.mk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package=libnatpmp
2+
$(package)_version=20150609
3+
$(package)_download_path=https://miniupnp.tuxfamily.org/files/
4+
$(package)_file_name=$(package)-$($(package)_version).tar.gz
5+
$(package)_sha256_hash=e1aa9c4c4219bc06943d6b2130f664daee213fb262fcb94dd355815b8f4536b0
6+
7+
define $(package)_set_vars
8+
$(package)_build_opts=CC="$($(package)_cc)"
9+
endef
10+
11+
define $(package)_build_cmds
12+
$(MAKE) libnatpmp.a $($(package)_build_opts)
13+
endef
14+
15+
define $(package)_stage_cmds
16+
mkdir -p $($(package)_staging_prefix_dir)/include $($(package)_staging_prefix_dir)/lib &&\
17+
install *.h $($(package)_staging_prefix_dir)/include &&\
18+
install libnatpmp.a $($(package)_staging_prefix_dir)/lib
19+
endef

depends/packages/packages.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ sqlite_packages=sqlite
1616
zmq_packages=zeromq
1717

1818
upnp_packages=miniupnpc
19+
natpmp_packages=libnatpmp
1920

2021
multiprocess_packages = libmultiprocess capnp
2122
multiprocess_native_packages = native_libmultiprocess native_capnp

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ bitcoin_bin_ldadd = \
598598
$(LIBMEMENV) \
599599
$(LIBSECP256K1)
600600

601-
bitcoin_bin_ldadd += $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS) $(SQLITE_LIBS)
601+
bitcoin_bin_ldadd += $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS) $(SQLITE_LIBS)
602602

603603
bitcoind_SOURCES = $(bitcoin_daemon_sources)
604604
bitcoind_CPPFLAGS = $(bitcoin_bin_cppflags)

src/Makefile.bench.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bench_bench_bitcoin_SOURCES += bench/coin_selection.cpp
7474
bench_bench_bitcoin_SOURCES += bench/wallet_balance.cpp
7575
endif
7676

77-
bench_bench_bitcoin_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(MINIUPNPC_LIBS) $(SQLITE_LIBS)
77+
bench_bench_bitcoin_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SQLITE_LIBS)
7878
bench_bench_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
7979

8080
CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES)

src/Makefile.qt.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ if ENABLE_ZMQ
320320
bitcoin_qt_ldadd += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
321321
endif
322322
bitcoin_qt_ldadd += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \
323-
$(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
323+
$(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(LIBSECP256K1) \
324324
$(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(SQLITE_LIBS)
325325
bitcoin_qt_ldflags = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
326326
bitcoin_qt_libtoolflags = $(AM_LIBTOOLFLAGS) --tag CXX

src/Makefile.qttest.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
5555
endif
5656
qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) \
5757
$(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \
58-
$(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
58+
$(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(LIBSECP256K1) \
5959
$(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(SQLITE_LIBS)
6060
qt_test_test_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
6161
qt_test_test_bitcoin_qt_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS)

0 commit comments

Comments
 (0)