mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-17 10:59:27 +00:00
5c7cacf649a6b474b876a7d219c7dc683a25e33d ci: Remove natpmp build option and libnatpmp dependency (laanwj) 7e7ec984da50f45491b994aaab180e7735ad1d8f doc: Remove mention of natpmp build options (laanwj) 061c3e32a26c6c04bf734d62627403758d7e51d9 depends: Drop natpmp and associated option from depends (laanwj) 20a18bf6aa38e87f72e2645482d00d0c77a344f5 build: Drop libnatpmp from build system (laanwj) 7b04709862f48e9020c7bef79cb31dd794cf91d0 qt: Changes for built-in PCP+NAT-PMP (laanwj) 52f8ef66c61b82457a161f3b90cc87f57d1dda80 net: Replace libnatpmp with built-in NATPMP+PCP implementation in mapport (laanwj) 97c97177cdb2f596aa7d4a65c4bde87de50a96f2 net: Add PCP and NATPMP implementation (laanwj) d72df63d16941576b3523cfeaa49985cf3cd4d42 net: Use GetLocalAddresses in Discover (laanwj) e02030432b77abbf27bb4f67d879d3ad6d6366e6 net: Add netif utility (laanwj) 754e4254388ec8ac1be6cf807bf300cd43fd3da5 crypto: Add missing WriteBE16 function (laanwj) Pull request description: Continues #30005. Closes #17012.. This PR adds PCP (Port Control Protocol) from [RFC6887](https://datatracker.ietf.org/doc/html/rfc6887). This adds, in addition to the existing IPv4 port mapping (which now uses PCP, with fallback to NAT-PMP), support for IPv6 pinholing-that is, opening a port on the firewall to make it reachable. PCP, like NAT-PMP is a simple UDP-based protocol, and the implementation is self-contained, so this gets rid of lthe libnatpnp dependency without adding a new one. It should otherwise be a drop-in replacement. NAT-PMP fallback is implemented so this will not make router support worse. For now it is disabled by default, though in the future (not in this PR) we could consider enable it by default to increase the number of connectable nodes without adding significant attack surface. To test: ```bash bitcoind -regtest -natpmp=1 -debug=net ``` (most of the changes in this PR are, ironically, removing the libnatpmp dependency and associated build system and build docs) ## TODO - [x] Default gateway discovery on Linux / FreeBSD - [x] Default gateway discovery on Windows - [x] Default gateway discovery on MacOS - [x] Either solve FreeBSD compile issue (probably upstream issue) or remove FreeBSD support ## Things to consider for follow-up PRs - https://github.com/bitcoin/bitcoin/pull/30043#discussion_r1658764974 avoid unreachable nets (not given to -onlynet=) - https://github.com/bitcoin/bitcoin/pull/30043#discussion_r1658949236 could announce an addr:port where we do not listen (no -bind) - https://github.com/bitcoin/bitcoin/pull/30043#discussion_r1684368824 could announce the wrong port because it uses GetListenPort() - https://github.com/bitcoin/bitcoin/pull/30043#discussion_r1679709347 if we requested one port but another was assigned, then which one to use in the renewal? - https://github.com/bitcoin/bitcoin/pull/30043#discussion_r1772017020 Use `GetAdapterAddresses` to discover local addresses for Windows ACKs for top commit: Sjors: ACK 5c7cacf649a6b474b876a7d219c7dc683a25e33d achow101: ACK 5c7cacf649a6b474b876a7d219c7dc683a25e33d vasild: ACK 5c7cacf649a6b474b876a7d219c7dc683a25e33d Tree-SHA512: e35b69e56d5f5449a3d48a799f9b7b65107c65eeb3e245c2c1e9d42221e469ca5ead90afae423160601cd664dd553a51c859e04f4492f335b064aae3bf23e3bc
453 lines
11 KiB
CMake
453 lines
11 KiB
CMake
# Copyright (c) 2023-present The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or https://opensource.org/license/mit/.
|
|
|
|
include(GNUInstallDirs)
|
|
include(AddWindowsResources)
|
|
|
|
configure_file(${PROJECT_SOURCE_DIR}/cmake/bitcoin-config.h.in config/bitcoin-config.h USE_SOURCE_PERMISSIONS @ONLY)
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
add_custom_target(generate_build_info
|
|
BYPRODUCTS ${PROJECT_BINARY_DIR}/src/bitcoin-build-info.h
|
|
COMMAND ${CMAKE_COMMAND} -DBUILD_INFO_HEADER_PATH=${PROJECT_BINARY_DIR}/src/bitcoin-build-info.h -DSOURCE_DIR=${PROJECT_SOURCE_DIR} -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateBuildInfo.cmake
|
|
COMMENT "Generating bitcoin-build-info.h"
|
|
VERBATIM
|
|
)
|
|
add_library(bitcoin_clientversion OBJECT EXCLUDE_FROM_ALL
|
|
clientversion.cpp
|
|
)
|
|
target_link_libraries(bitcoin_clientversion
|
|
PRIVATE
|
|
core_interface
|
|
)
|
|
add_dependencies(bitcoin_clientversion generate_build_info)
|
|
|
|
add_subdirectory(crypto)
|
|
add_subdirectory(univalue)
|
|
add_subdirectory(util)
|
|
if(WITH_MULTIPROCESS)
|
|
add_subdirectory(ipc)
|
|
endif()
|
|
|
|
#=============================
|
|
# secp256k1 subtree
|
|
#=============================
|
|
message("")
|
|
message("Configuring secp256k1 subtree...")
|
|
set(SECP256K1_DISABLE_SHARED ON CACHE BOOL "" FORCE)
|
|
set(SECP256K1_ENABLE_MODULE_ECDH OFF CACHE BOOL "" FORCE)
|
|
set(SECP256K1_ENABLE_MODULE_RECOVERY ON CACHE BOOL "" FORCE)
|
|
set(SECP256K1_BUILD_BENCHMARK OFF CACHE BOOL "" FORCE)
|
|
set(SECP256K1_BUILD_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
|
|
set(SECP256K1_BUILD_EXHAUSTIVE_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
|
|
if(NOT BUILD_TESTS)
|
|
# Always skip the ctime tests, if we are building no other tests.
|
|
# Otherwise, they are built if Valgrind is available. See SECP256K1_VALGRIND.
|
|
set(SECP256K1_BUILD_CTIME_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
|
|
endif()
|
|
set(SECP256K1_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
|
include(GetTargetInterface)
|
|
# -fsanitize and related flags apply to both C++ and C,
|
|
# so we can pass them down to libsecp256k1 as CFLAGS and LDFLAGS.
|
|
get_target_interface(core_sanitizer_cxx_flags "" sanitize_interface COMPILE_OPTIONS)
|
|
set(SECP256K1_APPEND_CFLAGS ${core_sanitizer_cxx_flags} CACHE STRING "" FORCE)
|
|
unset(core_sanitizer_cxx_flags)
|
|
get_target_interface(core_sanitizer_linker_flags "" sanitize_interface LINK_OPTIONS)
|
|
set(SECP256K1_APPEND_LDFLAGS ${core_sanitizer_linker_flags} CACHE STRING "" FORCE)
|
|
unset(core_sanitizer_linker_flags)
|
|
# We want to build libsecp256k1 with the most tested RelWithDebInfo configuration.
|
|
enable_language(C)
|
|
foreach(config IN LISTS CMAKE_BUILD_TYPE CMAKE_CONFIGURATION_TYPES)
|
|
if(config STREQUAL "")
|
|
continue()
|
|
endif()
|
|
string(TOUPPER "${config}" config)
|
|
set(CMAKE_C_FLAGS_${config} "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
|
|
endforeach()
|
|
# If the CFLAGS environment variable is defined during building depends
|
|
# and configuring this build system, its content might be duplicated.
|
|
if(DEFINED ENV{CFLAGS})
|
|
deduplicate_flags(CMAKE_C_FLAGS)
|
|
endif()
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS OFF)
|
|
add_subdirectory(secp256k1)
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
string(APPEND CMAKE_C_COMPILE_OBJECT " ${APPEND_CPPFLAGS} ${APPEND_CFLAGS}")
|
|
|
|
add_library(bitcoin_consensus STATIC EXCLUDE_FROM_ALL
|
|
arith_uint256.cpp
|
|
consensus/merkle.cpp
|
|
consensus/tx_check.cpp
|
|
hash.cpp
|
|
primitives/block.cpp
|
|
primitives/transaction.cpp
|
|
pubkey.cpp
|
|
script/interpreter.cpp
|
|
script/script.cpp
|
|
script/script_error.cpp
|
|
uint256.cpp
|
|
)
|
|
target_link_libraries(bitcoin_consensus
|
|
PRIVATE
|
|
core_interface
|
|
bitcoin_crypto
|
|
secp256k1
|
|
)
|
|
|
|
if(WITH_ZMQ)
|
|
add_subdirectory(zmq)
|
|
endif()
|
|
|
|
# Home for common functionality shared by different executables and libraries.
|
|
# Similar to `bitcoin_util` library, but higher-level.
|
|
add_library(bitcoin_common STATIC EXCLUDE_FROM_ALL
|
|
addresstype.cpp
|
|
base58.cpp
|
|
bech32.cpp
|
|
chainparams.cpp
|
|
chainparamsbase.cpp
|
|
coins.cpp
|
|
common/args.cpp
|
|
common/bloom.cpp
|
|
common/config.cpp
|
|
common/init.cpp
|
|
common/interfaces.cpp
|
|
common/messages.cpp
|
|
common/run_command.cpp
|
|
common/settings.cpp
|
|
common/signmessage.cpp
|
|
common/system.cpp
|
|
common/url.cpp
|
|
compressor.cpp
|
|
core_read.cpp
|
|
core_write.cpp
|
|
deploymentinfo.cpp
|
|
external_signer.cpp
|
|
init/common.cpp
|
|
kernel/chainparams.cpp
|
|
key.cpp
|
|
key_io.cpp
|
|
merkleblock.cpp
|
|
net_permissions.cpp
|
|
net_types.cpp
|
|
netaddress.cpp
|
|
netbase.cpp
|
|
outputtype.cpp
|
|
policy/feerate.cpp
|
|
policy/policy.cpp
|
|
protocol.cpp
|
|
psbt.cpp
|
|
rpc/external_signer.cpp
|
|
rpc/rawtransaction_util.cpp
|
|
rpc/request.cpp
|
|
rpc/util.cpp
|
|
scheduler.cpp
|
|
script/descriptor.cpp
|
|
script/miniscript.cpp
|
|
script/parsing.cpp
|
|
script/sign.cpp
|
|
script/signingprovider.cpp
|
|
script/solver.cpp
|
|
)
|
|
target_link_libraries(bitcoin_common
|
|
PRIVATE
|
|
core_interface
|
|
bitcoin_consensus
|
|
bitcoin_util
|
|
univalue
|
|
secp256k1
|
|
Boost::headers
|
|
$<TARGET_NAME_IF_EXISTS:USDT::headers>
|
|
$<$<PLATFORM_ID:Windows>:ws2_32>
|
|
)
|
|
|
|
|
|
set(installable_targets)
|
|
if(ENABLE_WALLET)
|
|
add_subdirectory(wallet)
|
|
|
|
if(BUILD_WALLET_TOOL)
|
|
add_executable(bitcoin-wallet
|
|
bitcoin-wallet.cpp
|
|
init/bitcoin-wallet.cpp
|
|
wallet/wallettool.cpp
|
|
)
|
|
add_windows_resources(bitcoin-wallet bitcoin-wallet-res.rc)
|
|
target_link_libraries(bitcoin-wallet
|
|
core_interface
|
|
bitcoin_wallet
|
|
bitcoin_common
|
|
bitcoin_util
|
|
Boost::headers
|
|
)
|
|
list(APPEND installable_targets bitcoin-wallet)
|
|
endif()
|
|
endif()
|
|
|
|
|
|
# P2P and RPC server functionality used by `bitcoind` and `bitcoin-qt` executables.
|
|
add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
|
|
addrdb.cpp
|
|
addrman.cpp
|
|
banman.cpp
|
|
bip324.cpp
|
|
blockencodings.cpp
|
|
blockfilter.cpp
|
|
chain.cpp
|
|
consensus/tx_verify.cpp
|
|
dbwrapper.cpp
|
|
deploymentstatus.cpp
|
|
flatfile.cpp
|
|
headerssync.cpp
|
|
httprpc.cpp
|
|
httpserver.cpp
|
|
i2p.cpp
|
|
index/base.cpp
|
|
index/blockfilterindex.cpp
|
|
index/coinstatsindex.cpp
|
|
index/txindex.cpp
|
|
init.cpp
|
|
kernel/chain.cpp
|
|
kernel/checks.cpp
|
|
kernel/coinstats.cpp
|
|
kernel/context.cpp
|
|
kernel/cs_main.cpp
|
|
kernel/disconnected_transactions.cpp
|
|
kernel/mempool_removal_reason.cpp
|
|
mapport.cpp
|
|
net.cpp
|
|
net_processing.cpp
|
|
netgroup.cpp
|
|
node/abort.cpp
|
|
node/blockmanager_args.cpp
|
|
node/blockstorage.cpp
|
|
node/caches.cpp
|
|
node/chainstate.cpp
|
|
node/chainstatemanager_args.cpp
|
|
node/coin.cpp
|
|
node/coins_view_args.cpp
|
|
node/connection_types.cpp
|
|
node/context.cpp
|
|
node/database_args.cpp
|
|
node/eviction.cpp
|
|
node/interface_ui.cpp
|
|
node/interfaces.cpp
|
|
node/kernel_notifications.cpp
|
|
node/mempool_args.cpp
|
|
node/mempool_persist.cpp
|
|
node/mempool_persist_args.cpp
|
|
node/miner.cpp
|
|
node/mini_miner.cpp
|
|
node/minisketchwrapper.cpp
|
|
node/peerman_args.cpp
|
|
node/psbt.cpp
|
|
node/timeoffsets.cpp
|
|
node/transaction.cpp
|
|
node/txreconciliation.cpp
|
|
node/utxo_snapshot.cpp
|
|
node/warnings.cpp
|
|
noui.cpp
|
|
policy/fees.cpp
|
|
policy/fees_args.cpp
|
|
policy/packages.cpp
|
|
policy/rbf.cpp
|
|
policy/settings.cpp
|
|
policy/truc_policy.cpp
|
|
pow.cpp
|
|
rest.cpp
|
|
rpc/blockchain.cpp
|
|
rpc/fees.cpp
|
|
rpc/mempool.cpp
|
|
rpc/mining.cpp
|
|
rpc/net.cpp
|
|
rpc/node.cpp
|
|
rpc/output_script.cpp
|
|
rpc/rawtransaction.cpp
|
|
rpc/server.cpp
|
|
rpc/server_util.cpp
|
|
rpc/signmessage.cpp
|
|
rpc/txoutproof.cpp
|
|
script/sigcache.cpp
|
|
signet.cpp
|
|
torcontrol.cpp
|
|
txdb.cpp
|
|
txmempool.cpp
|
|
txorphanage.cpp
|
|
txrequest.cpp
|
|
validation.cpp
|
|
validationinterface.cpp
|
|
versionbits.cpp
|
|
$<$<TARGET_EXISTS:bitcoin_wallet>:wallet/init.cpp>
|
|
$<$<NOT:$<TARGET_EXISTS:bitcoin_wallet>>:dummywallet.cpp>
|
|
)
|
|
target_link_libraries(bitcoin_node
|
|
PRIVATE
|
|
core_interface
|
|
bitcoin_common
|
|
bitcoin_util
|
|
leveldb
|
|
minisketch
|
|
univalue
|
|
Boost::headers
|
|
$<TARGET_NAME_IF_EXISTS:libevent::libevent>
|
|
$<TARGET_NAME_IF_EXISTS:libevent::pthreads>
|
|
$<TARGET_NAME_IF_EXISTS:MiniUPnPc::MiniUPnPc>
|
|
$<TARGET_NAME_IF_EXISTS:bitcoin_zmq>
|
|
$<TARGET_NAME_IF_EXISTS:USDT::headers>
|
|
)
|
|
|
|
|
|
# Bitcoin Core bitcoind.
|
|
if(BUILD_DAEMON)
|
|
add_executable(bitcoind
|
|
bitcoind.cpp
|
|
init/bitcoind.cpp
|
|
)
|
|
add_windows_resources(bitcoind bitcoind-res.rc)
|
|
target_link_libraries(bitcoind
|
|
core_interface
|
|
bitcoin_node
|
|
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
|
|
)
|
|
list(APPEND installable_targets bitcoind)
|
|
endif()
|
|
if(WITH_MULTIPROCESS)
|
|
add_executable(bitcoin-node
|
|
bitcoind.cpp
|
|
init/bitcoin-node.cpp
|
|
)
|
|
target_link_libraries(bitcoin-node
|
|
core_interface
|
|
bitcoin_node
|
|
bitcoin_ipc
|
|
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
|
|
)
|
|
list(APPEND installable_targets bitcoin-node)
|
|
|
|
if(BUILD_TESTS)
|
|
# bitcoin_ipc_test library target is defined here in src/CMakeLists.txt
|
|
# instead of src/test/CMakeLists.txt so capnp files in src/test/ are able to
|
|
# reference capnp files in src/ipc/capnp/ by relative path. The Cap'n Proto
|
|
# compiler only allows importing by relative path when the importing and
|
|
# imported files are underneath the same compilation source prefix, so the
|
|
# source prefix must be src/, not src/test/
|
|
add_library(bitcoin_ipc_test STATIC EXCLUDE_FROM_ALL
|
|
test/ipc_test.cpp
|
|
)
|
|
target_capnp_sources(bitcoin_ipc_test ${PROJECT_SOURCE_DIR}
|
|
test/ipc_test.capnp
|
|
)
|
|
add_dependencies(bitcoin_ipc_test bitcoin_ipc_headers)
|
|
endif()
|
|
endif()
|
|
|
|
|
|
add_library(bitcoin_cli STATIC EXCLUDE_FROM_ALL
|
|
compat/stdin.cpp
|
|
rpc/client.cpp
|
|
)
|
|
target_link_libraries(bitcoin_cli
|
|
PUBLIC
|
|
core_interface
|
|
univalue
|
|
)
|
|
|
|
|
|
# Bitcoin Core RPC client
|
|
if(BUILD_CLI)
|
|
add_executable(bitcoin-cli bitcoin-cli.cpp)
|
|
add_windows_resources(bitcoin-cli bitcoin-cli-res.rc)
|
|
target_link_libraries(bitcoin-cli
|
|
core_interface
|
|
bitcoin_cli
|
|
bitcoin_common
|
|
bitcoin_util
|
|
$<TARGET_NAME_IF_EXISTS:libevent::libevent>
|
|
)
|
|
list(APPEND installable_targets bitcoin-cli)
|
|
endif()
|
|
|
|
|
|
if(BUILD_TX)
|
|
add_executable(bitcoin-tx bitcoin-tx.cpp)
|
|
add_windows_resources(bitcoin-tx bitcoin-tx-res.rc)
|
|
target_link_libraries(bitcoin-tx
|
|
core_interface
|
|
bitcoin_common
|
|
bitcoin_util
|
|
univalue
|
|
)
|
|
list(APPEND installable_targets bitcoin-tx)
|
|
endif()
|
|
|
|
|
|
if(BUILD_UTIL)
|
|
add_executable(bitcoin-util bitcoin-util.cpp)
|
|
add_windows_resources(bitcoin-util bitcoin-util-res.rc)
|
|
target_link_libraries(bitcoin-util
|
|
core_interface
|
|
bitcoin_common
|
|
bitcoin_util
|
|
)
|
|
list(APPEND installable_targets bitcoin-util)
|
|
endif()
|
|
|
|
|
|
if(BUILD_GUI)
|
|
add_subdirectory(qt)
|
|
endif()
|
|
|
|
|
|
if(BUILD_KERNEL_LIB)
|
|
add_subdirectory(kernel)
|
|
endif()
|
|
|
|
if(BUILD_UTIL_CHAINSTATE)
|
|
add_executable(bitcoin-chainstate
|
|
bitcoin-chainstate.cpp
|
|
)
|
|
# TODO: The `SKIP_BUILD_RPATH` property setting can be deleted
|
|
# in the future after reordering Guix script commands to
|
|
# perform binary checks after the installation step.
|
|
# Relevant discussions:
|
|
# - https://github.com/hebasto/bitcoin/pull/236#issuecomment-2183120953
|
|
# - https://github.com/bitcoin/bitcoin/pull/30312#issuecomment-2191235833
|
|
set_target_properties(bitcoin-chainstate PROPERTIES
|
|
SKIP_BUILD_RPATH OFF
|
|
)
|
|
target_link_libraries(bitcoin-chainstate
|
|
PRIVATE
|
|
core_interface
|
|
bitcoinkernel
|
|
)
|
|
endif()
|
|
|
|
|
|
add_subdirectory(test/util)
|
|
if(BUILD_BENCH)
|
|
add_subdirectory(bench)
|
|
endif()
|
|
|
|
if(BUILD_TESTS)
|
|
add_subdirectory(test)
|
|
endif()
|
|
|
|
if(BUILD_FUZZ_BINARY)
|
|
add_subdirectory(test/fuzz)
|
|
endif()
|
|
|
|
|
|
install(TARGETS ${installable_targets}
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
)
|
|
unset(installable_targets)
|
|
|
|
if(INSTALL_MAN)
|
|
# TODO: these stubs are no longer needed. man pages should be generated at install time.
|
|
install(DIRECTORY ../doc/man/
|
|
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
|
|
FILES_MATCHING PATTERN *.1
|
|
)
|
|
endif()
|