diff --git a/Makefile.am b/Makefile.am index 104a8fb86..37ff1b6bc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -531,8 +531,10 @@ include_bitcoin_network_HEADERS = \ include/bitcoin/network/boost.hpp \ include/bitcoin/network/define.hpp \ include/bitcoin/network/error.hpp \ + include/bitcoin/network/have.hpp \ include/bitcoin/network/memory.hpp \ include/bitcoin/network/net.hpp \ + include/bitcoin/network/preprocessor.hpp \ include/bitcoin/network/settings.hpp \ include/bitcoin/network/version.hpp @@ -762,6 +764,7 @@ include_bitcoin_ssl_openssldir = ${includedir}/bitcoin/ssl/openssl include_bitcoin_ssl_openssl_HEADERS = \ include/bitcoin/ssl/openssl/conf.h \ include/bitcoin/ssl/openssl/dh.h \ + include/bitcoin/ssl/openssl/engine.h \ include/bitcoin/ssl/openssl/err.h \ include/bitcoin/ssl/openssl/openssl.h \ include/bitcoin/ssl/openssl/rsa.h \ diff --git a/builds/cmake/CMakeLists.txt b/builds/cmake/CMakeLists.txt index 6977e3063..98ee77682 100644 --- a/builds/cmake/CMakeLists.txt +++ b/builds/cmake/CMakeLists.txt @@ -118,6 +118,18 @@ set( pkgconfigdir "${libdir}/pkgconfig" CACHE PATH "Path to pkgconfig directory. #------------------------------------------------------------------------------ set( with-tests "yes" CACHE BOOL "Compile with unit tests." ) +# Implement -Dwith-ssl and define WOLFSSL_USER_SETTINGS and output ${ssl}. +#------------------------------------------------------------------------------ +set( with-ssl "yes" CACHE BOOL "Compile with internal ssl." ) + +if (with-ssl) + add_definitions( -DWOLFSSL_USER_SETTINGS ) +endif() + +if (with-ssl) + set( ssl "-DWOLFSSL_USER_SETTINGS" ) +endif() + # Implement -Denable-ndebug and define NDEBUG. #------------------------------------------------------------------------------ set( enable-ndebug "yes" CACHE BOOL "Compile without debug assertions." ) @@ -132,7 +144,6 @@ if (BUILD_SHARED_LIBS) add_definitions( -DBOOST_ALL_DYN_LINK ) endif() -add_definitions( -DWOLFSSL_USER_SETTINGS ) if (BUILD_SHARED_LIBS) set( Boost_USE_STATIC_LIBS "off" ) else() diff --git a/builds/msvc/vs2022/libbitcoin-network-test/libbitcoin-network-test.props b/builds/msvc/vs2022/libbitcoin-network-test/libbitcoin-network-test.props index 25f340480..407207091 100644 --- a/builds/msvc/vs2022/libbitcoin-network-test/libbitcoin-network-test.props +++ b/builds/msvc/vs2022/libbitcoin-network-test/libbitcoin-network-test.props @@ -13,14 +13,16 @@ $(ProjectDir)..\..\..\..\..\libbitcoin-network\test\ssl\wolfssl\;%(AdditionalIncludeDirectories) false - CERT_PREFIX="$(RepoRoot.Replace("\", "/"))test/ssl/vectors/";%(PreprocessorDefinitions) + + + CERT_PREFIX="$(RepoRoot.Replace("\", "/"))test/ssl/vectors/";%(PreprocessorDefinitions) "$(TargetPath)" --log_level=warning --run_test=* --show_progress=no --build_info=yes - + /wd4005 /wd4189 /wd4245 /wd4267 /wd4701 /wd4702 /wd4703 %(AdditionalOptions) diff --git a/builds/msvc/vs2022/libbitcoin-network.import.props b/builds/msvc/vs2022/libbitcoin-network.import.props index 81b0d3dc8..2f5c4fee0 100644 --- a/builds/msvc/vs2022/libbitcoin-network.import.props +++ b/builds/msvc/vs2022/libbitcoin-network.import.props @@ -11,15 +11,29 @@ + + + + true + + + + + + + + $(ProjectDir)..\..\..\..\..\libbitcoin-network\include\;%(AdditionalIncludeDirectories) - $(ProjectDir)..\..\..\..\..\libbitcoin-network\include\bitcoin\ssl\;%(AdditionalIncludeDirectories) + + + $(ProjectDir)..\..\..\..\..\libbitcoin-network\include\bitcoin\ssl\;%(AdditionalIncludeDirectories) /bigobj %(AdditionalOptions) BCT_STATIC;%(PreprocessorDefinitions) - WOLFSSL_USER_SETTINGS;%(PreprocessorDefinitions) + WOLFSSL_USER_SETTINGS;%(PreprocessorDefinitions) libbitcoin-network.lib;%(AdditionalDependencies) @@ -35,4 +49,14 @@ + + + + + + true + + + + \ No newline at end of file diff --git a/builds/msvc/vs2022/libbitcoin-network.import.xml b/builds/msvc/vs2022/libbitcoin-network.import.xml index 7bcfea233..f7ff53dd5 100644 --- a/builds/msvc/vs2022/libbitcoin-network.import.xml +++ b/builds/msvc/vs2022/libbitcoin-network.import.xml @@ -14,4 +14,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.props b/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.props index 03d786e64..8b269d475 100644 --- a/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.props +++ b/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.props @@ -7,24 +7,44 @@ false + + + + + + + + + + true + + $(RepoRoot)include\;%(AdditionalIncludeDirectories) - $(RepoRoot)include\bitcoin\ssl\;%(AdditionalIncludeDirectories) + + + $(RepoRoot)include\bitcoin\ssl\;%(AdditionalIncludeDirectories) /bigobj %(AdditionalOptions) false BCT_DLL;%(PreprocessorDefinitions) BCT_STATIC;%(PreprocessorDefinitions) - WOLFSSL_USER_SETTINGS;%(PreprocessorDefinitions) + WOLFSSL_USER_SETTINGS;%(PreprocessorDefinitions) - + /wd4189 /wd4245 /wd4267 /wd4701 /wd4702 /wd4703 %(AdditionalOptions) + + + true + + + true @@ -51,9 +71,19 @@ static static + + + + true + + + + + + diff --git a/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj b/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj index 256690245..07dba4b11 100644 --- a/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj @@ -373,6 +373,7 @@ + @@ -462,6 +463,7 @@ + @@ -491,6 +493,7 @@ + @@ -702,4 +705,4 @@ - \ No newline at end of file + diff --git a/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj.filters index b6bea5c5e..8a58692b0 100644 --- a/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj.filters @@ -884,6 +884,9 @@ include\bitcoin\network + + include\bitcoin\network + include\bitcoin\network\interfaces @@ -1151,6 +1154,9 @@ include\bitcoin\network\net + + include\bitcoin\network + include\bitcoin\network\protocols @@ -1238,6 +1244,9 @@ include\bitcoin\ssl\openssl + + include\bitcoin\ssl\openssl + include\bitcoin\ssl\openssl @@ -1788,4 +1797,4 @@ - \ No newline at end of file + diff --git a/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.xml b/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.xml new file mode 100644 index 000000000..195b9cca1 --- /dev/null +++ b/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/builds/msvc/vs2022/libbitcoin-system.import.props b/builds/msvc/vs2022/libbitcoin-system.import.props index 59ce698bc..6d9a890f8 100644 --- a/builds/msvc/vs2022/libbitcoin-system.import.props +++ b/builds/msvc/vs2022/libbitcoin-system.import.props @@ -46,12 +46,9 @@ $(ProjectDir)..\..\..\..\..\libbitcoin-system\include\;%(AdditionalIncludeDirectories) - - WITH_ICU;WIN32_LEAN_AND_MEAN;NOMINMAX;_WIN32_WINNT=0x0602;%(PreprocessorDefinitions) - - BOOST_JSON_NO_LIB;BOOST_CONTAINER_NO_LIB;%(PreprocessorDefinitions) + WIN32_LEAN_AND_MEAN;NOMINMAX;_WIN32_WINNT=0x0602;%(PreprocessorDefinitions) BC_STATIC;%(PreprocessorDefinitions) _CRTDBG_MAP_ALLOC;%(PreprocessorDefinitions) diff --git a/configure.ac b/configure.ac index ebe39539c..6b4cf59c4 100644 --- a/configure.ac +++ b/configure.ac @@ -98,6 +98,18 @@ AC_ARG_WITH([tests], AC_MSG_RESULT([$with_tests]) AM_CONDITIONAL([WITH_TESTS], [test x$with_tests != xno]) +# Implement --with-ssl and define WOLFSSL_USER_SETTINGS and output ${ssl}. +#------------------------------------------------------------------------------ +AC_MSG_CHECKING([--with-ssl option]) +AC_ARG_WITH([ssl], + AS_HELP_STRING([--with-ssl], + [Compile with internal ssl. @<:@default=yes@:>@]), + [with_ssl=$withval], + [with_ssl=yes]) +AC_MSG_RESULT([$with_ssl]) +AS_CASE([${with_ssl}], [yes], AC_DEFINE([WOLFSSL_USER_SETTINGS])) +AS_CASE([${with_ssl}], [yes], AC_SUBST([ssl], [-DWOLFSSL_USER_SETTINGS])) + # Implement --enable-ndebug and define NDEBUG. #------------------------------------------------------------------------------ AC_MSG_CHECKING([--enable-ndebug option]) @@ -124,13 +136,6 @@ AC_ARG_ENABLE([isystem], AC_MSG_RESULT([$enable_isystem]) -# Set preprocessor defines. -#============================================================================== -# Unconditionally define the preprocessor symbol WOLFSSL_USER_SETTINGS. -#------------------------------------------------------------------------------ -AC_DEFINE([WOLFSSL_USER_SETTINGS]) - - # Set flags. #============================================================================== # Require c++20 for all c++ products. diff --git a/include/bitcoin/network.hpp b/include/bitcoin/network.hpp index eabb36d6a..107bca133 100644 --- a/include/bitcoin/network.hpp +++ b/include/bitcoin/network.hpp @@ -19,8 +19,10 @@ #include #include #include +#include #include #include +#include #include #include #include diff --git a/include/bitcoin/network/async/asio.hpp b/include/bitcoin/network/async/asio.hpp index 4854be022..b6472cd71 100644 --- a/include/bitcoin/network/async/asio.hpp +++ b/include/bitcoin/network/async/asio.hpp @@ -56,11 +56,8 @@ typedef asio::acceptor::reuse_address reuse_address; /// connect typedef tcp::socket socket; typedef std::shared_ptr socket_ptr; -constexpr auto max_connections = - boost::asio::socket_base::max_listen_connections; /// ssl -#if defined(HAVE_SSL) namespace ssl { typedef boost::asio::ssl::context context; @@ -75,8 +72,6 @@ inline void foobar() THROWS } } // namespace ssl -#endif // HAVE_SSL - } // namespace asio } // namespace network } // namespace libbitcoin diff --git a/include/bitcoin/network/boost.hpp b/include/bitcoin/network/boost.hpp index 6671465e1..a4e851e86 100644 --- a/include/bitcoin/network/boost.hpp +++ b/include/bitcoin/network/boost.hpp @@ -19,7 +19,10 @@ #ifndef LIBBITCOIN_NETWORK_BOOST_HPP #define LIBBITCOIN_NETWORK_BOOST_HPP -#include +#include + +// Pull in any base boost configuration before including boost. +#include #include #include @@ -27,16 +30,13 @@ #include #include -#define BOOST_ASIO_NO_DEPRECATED -#include - -// TODO: Hoist this out to build config. -#define WITH_SSL +// TODO: exclude ssl sources when HAVE_SSL not defined (lib and test). +// TODO: exclude ssl include paths when HAVE_SSL not defined (lib and test). +#if defined(HAVE_SSL) + #define BOOST_ASIO_USE_WOLFSSL +#endif -#if defined(WITH_SSL) -#define HAVE_SSL -#define BOOST_ASIO_USE_WOLFSSL +/// Without HAVE_SSL openssl headers must be externally defined for asio. #include -#endif // WITH_SSL #endif diff --git a/include/bitcoin/network/define.hpp b/include/bitcoin/network/define.hpp index 730f79c31..18381a543 100644 --- a/include/bitcoin/network/define.hpp +++ b/include/bitcoin/network/define.hpp @@ -19,99 +19,6 @@ #ifndef LIBBITCOIN_NETWORK_DEFINE_HPP #define LIBBITCOIN_NETWORK_DEFINE_HPP -#include - -// We use the generic helper definitions in libbitcoin to define BCT_API -// and BCT_INTERNAL. BCT_API is used for the public API symbols. It either DLL -// imports or DLL exports (or does nothing for static build) BCT_INTERNAL is -// used for non-api symbols. - -#if defined BCT_STATIC - #define BCT_API - #define BCT_INTERNAL -#elif defined BCT_DLL - #define BCT_API BC_HELPER_DLL_EXPORT - #define BCT_INTERNAL BC_HELPER_DLL_LOCAL -#else - #define BCT_API BC_HELPER_DLL_IMPORT - #define BCT_INTERNAL BC_HELPER_DLL_LOCAL -#endif - -/// WITH_ indicates build symbol. -/// --------------------------------------------------------------------------- - -/// TODO: Move to build configuration. -////#define WITH_EVENTS -#define WITH_LOGGING -#if !defined(NDEBUG) - #define WITH_LOGO -#endif -#define WITH_LOGA -#define WITH_LOGN -#define WITH_LOGS -#define WITH_LOGP -#define WITH_LOGX -#define WITH_LOGR -#define WITH_LOGF -#define WITH_LOGQ -#define WITH_LOGV - -////#if defined(WITH_EVENTS) -//// #define HAVE_EVENTS -////#endif -#if defined(WITH_LOGGING) - #define HAVE_LOGGING - - /// Objects (shared object construct/destruct). - #if defined(WITH_LOGO) - #define HAVE_LOGO - #endif - - #if defined(WITH_LOGA) - #define HAVE_LOGA - #endif - - /// News (general progression). - #if defined(WITH_LOGN) - #define HAVE_LOGN - #endif - - /// Sessions. - #if defined(WITH_LOGS) - #define HAVE_LOGS - #endif - - /// Protocols. - #if defined(WITH_LOGP) - #define HAVE_LOGP - #endif - - /// ProXy. - #if defined(WITH_LOGX) - #define HAVE_LOGX - #endif - - /// Remote (peer errors). - #if defined(WITH_LOGR) - #define HAVE_LOGR - #endif - - /// Fault (own errors). - #if defined(WITH_LOGF) - #define HAVE_LOGF - #endif - - /// Quitting connections (e.g. read/write/send abort). - #if defined(WITH_LOGQ) - #define HAVE_LOGQ - #endif - - /// Verbose (ad-hoc debugging). - #if defined(WITH_LOGV) - #define HAVE_LOGV - #endif -#endif - #include namespace libbitcoin { @@ -138,7 +45,9 @@ namespace network { // Network inclusions are chained as follows. // version : -// boost : version +// have : version +// preprocessor : have +// boost : preprocessor // beast : boost // error : beast // define : error diff --git a/include/bitcoin/network/have.hpp b/include/bitcoin/network/have.hpp new file mode 100644 index 000000000..9a77517d4 --- /dev/null +++ b/include/bitcoin/network/have.hpp @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) + * + * This file is part of libbitcoin. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#ifndef LIBBITCOIN_NETWORK_HAVE_HPP +#define LIBBITCOIN_NETWORK_HAVE_HPP + +#include + +/// WITH_ indicates build symbol. +/// --------------------------------------------------------------------------- + +/// This enables integral ssl support via embedded wolfssl. +/// If not defined then boost-compatible SSL must be externally linked. +/// The build config must always define either the internal ssl include path or +/// an external one, so that boost will locate the expected openssl headers. +#if defined(WOLFSSL_USER_SETTINGS) + #define HAVE_SSL +#endif + +/// TODO: Move to build configuration. +////#define WITH_EVENTS +#define WITH_LOGGING +#if !defined(NDEBUG) + #define WITH_LOGO +#endif +#define WITH_LOGA +#define WITH_LOGN +#define WITH_LOGS +#define WITH_LOGP +#define WITH_LOGX +#define WITH_LOGR +#define WITH_LOGF +#define WITH_LOGQ +#define WITH_LOGV + +////#if defined(WITH_EVENTS) +//// #define HAVE_EVENTS +////#endif +#if defined(WITH_LOGGING) + #define HAVE_LOGGING + + /// Objects (shared object construct/destruct). + #if defined(WITH_LOGO) + #define HAVE_LOGO + #endif + + #if defined(WITH_LOGA) + #define HAVE_LOGA + #endif + + /// News (general progression). + #if defined(WITH_LOGN) + #define HAVE_LOGN + #endif + + /// Sessions. + #if defined(WITH_LOGS) + #define HAVE_LOGS + #endif + + /// Protocols. + #if defined(WITH_LOGP) + #define HAVE_LOGP + #endif + + /// ProXy. + #if defined(WITH_LOGX) + #define HAVE_LOGX + #endif + + /// Remote (peer errors). + #if defined(WITH_LOGR) + #define HAVE_LOGR + #endif + + /// Fault (own errors). + #if defined(WITH_LOGF) + #define HAVE_LOGF + #endif + + /// Quitting connections (e.g. read/write/send abort). + #if defined(WITH_LOGQ) + #define HAVE_LOGQ + #endif + + /// Verbose (ad-hoc debugging). + #if defined(WITH_LOGV) + #define HAVE_LOGV + #endif +#endif + +#endif diff --git a/include/bitcoin/network/preprocessor.hpp b/include/bitcoin/network/preprocessor.hpp new file mode 100644 index 000000000..0e020888b --- /dev/null +++ b/include/bitcoin/network/preprocessor.hpp @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) + * + * This file is part of libbitcoin. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#ifndef LIBBITCOIN_NETWORK_PREPROCESSOR_HPP +#define LIBBITCOIN_NETWORK_PREPROCESSOR_HPP + +#include + +/// Symbols. +/// --------------------------------------------------------------------------- + +#include + +// We use the generic helper definitions in libbitcoin to define BCT_API +// and BCT_INTERNAL. BCT_API is used for the public API symbols. It either DLL +// imports or DLL exports (or does nothing for static build) BCT_INTERNAL is +// used for non-api symbols. + +#if defined BCT_STATIC + #define BCT_API + #define BCT_INTERNAL +#elif defined BCT_DLL + #define BCT_API BC_HELPER_DLL_EXPORT + #define BCT_INTERNAL BC_HELPER_DLL_LOCAL +#else + #define BCT_API BC_HELPER_DLL_IMPORT + #define BCT_INTERNAL BC_HELPER_DLL_LOCAL +#endif + +#endif diff --git a/include/bitcoin/ssl/openssl/engine.h b/include/bitcoin/ssl/openssl/engine.h new file mode 100644 index 000000000..f8adb5472 --- /dev/null +++ b/include/bitcoin/ssl/openssl/engine.h @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) + * + * This file is part of libbitcoin. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#ifndef LIBBITCOIN_NETWORK_SSL_OPENSSL_ENGINE_H +#define LIBBITCOIN_NETWORK_SSL_OPENSSL_ENGINE_H + +/* Forward load of . */ +#include + +#endif diff --git a/libbitcoin-network.pc.in b/libbitcoin-network.pc.in index ec8b5efda..c5ecddce6 100644 --- a/libbitcoin-network.pc.in +++ b/libbitcoin-network.pc.in @@ -29,7 +29,7 @@ Requires: libbitcoin-system >= 4.0.0 # Include directory and any other required compiler flags. #------------------------------------------------------------------------------ -Cflags: -I${includedir} -DWOLFSSL_USER_SETTINGS +Cflags: -I${includedir} @ssl@ # Lib directory, lib and any required that do not publish pkg-config. #------------------------------------------------------------------------------ diff --git a/src/net/acceptor.cpp b/src/net/acceptor.cpp index 3156bf208..7c909079a 100644 --- a/src/net/acceptor.cpp +++ b/src/net/acceptor.cpp @@ -92,7 +92,7 @@ code acceptor::start(const asio::endpoint& point) NOEXCEPT acceptor_.bind(point, ec); if (!ec) - acceptor_.listen(asio::max_connections, ec); + acceptor_.listen(asio::socket::max_listen_connections, ec); if (!ec) {