Compare commits

...
77 Commits
Author SHA1 Message Date
Adrien Beraud 8255596171 cmake: various fixes on Linux 2025-07-21 15:49:34 -04:00
Adrien Beraud baae3ba701 cmake/presets: build ninja with proxy 2025-07-21 13:28:36 -04:00
Maxim Cournoyer 6c43be2a03 configure.ac: Improve the error message when readline is missing.
* configure.ac[tools]: Mention that the requirement is due to the
tools.
2025-07-21 08:24:03 -04:00
Maxim Cournoyer ee4c8a19d6 configure.ac: Error out when doc is requested but Doxygen is missing.
Previously, documentation would be automatically disabled when Doxygen
was found missing.

* configure.ac: Change AC_MSG_WARN into AC_MSG_ERROR and adjust error
message.
2025-07-21 08:24:03 -04:00
Maxim Cournoyer e8cf9dd25f configure.ac: Make the Python option depend on the indexation option.
Mimic what is done already in the CMakeLists.txt file, with one
distinction: do not automagically turn on indexation when Python is
selected; rather, stop and tell the user that it is required for
Python support.  Remove the automatic downgrade to --disable-python
when Cython is not found.

* configure.ac: Enforce dependencies on indexation and Cython when
Python support is requested.
2025-07-21 08:24:03 -04:00
Maxim Cournoyer df21c4524c configure.ac: Fix the description of the '--without-openssl' option. 2025-07-21 08:24:03 -04:00
Maxim Cournoyer ccec6c2f67 replace usleep with nanosleep
* src/compat/msvc/unistd.h (usleep): Delete.
* tools/dhtcnode.c (main) <usleep>: Replace with nanosleep on non
Windows platform, or Sleep on Windows.

Fixes: #607
2025-07-20 22:25:28 -04:00
Adrien Béraud 5ab450491c Merge remote-tracking branch 'origin/master' into pulls/1772757862/750 2025-07-20 11:59:30 -04:00
Adrien Béraud 3b0cce8c25 Added and tested build scenarios for Windows (MSYS2, MSVC) 2025-07-20 11:55:40 -04:00
copilot-swe-agent[bot]andaberaud d6b6f30275 Replace hardcoded documentation path with CMAKE_INSTALL_DOCDIR
Co-authored-by: aberaud <101827+aberaud@users.noreply.github.com>
2025-07-19 23:08:08 -04:00
Adrien Béraud c9f18c8349 Pull Request #750: Added and tested build scenarios for Windows (MSYS2, MSVC) 2025-07-19 14:36:26 -04:00
Adrien Beraud df3186ad95 proxy server: export ServerStats 2025-07-16 11:29:18 -04:00
Andrey Vukolov 58956549b8 Merge branch 'savoirfairelinux:master' into winbuild 2025-07-15 16:47:24 +02:00
Adrien Beraud 74ed041791 tests/dhtrunner: create value as shared_ptr 2025-07-10 13:50:42 -04:00
Adrien Beraud 312f883387 proxy server: move ServerStats impl to cpp 2025-07-10 13:46:17 -04:00
Andrey Vukolov fad4093183 CI fix (squashed 17 commits) 2025-06-27 14:27:48 +02:00
Andrey Vukolov 5c005e097e Harmonizing CMakeLists 2025-06-26 16:20:27 +02:00
Andrey Vukolov 69f23e49c4 Preparing for rebase and merge #750
Addresses:
        - https://github.com/savoirfairelinux/opendht/pull/750#discussion_r2157723135
        - https://github.com/savoirfairelinux/opendht/pull/750#discussion_r2157794234
        - https://github.com/savoirfairelinux/opendht/pull/750#discussion_r2157795386
        - https://github.com/savoirfairelinux/opendht/pull/750#discussion_r2161542551
        - https://github.com/savoirfairelinux/opendht/pull/750#discussion_r2161546768
2025-06-24 18:06:52 +02:00
Andrey Vukolov f53976dc2f Merge branch 'savoirfairelinux:master' into winbuild 2025-06-23 10:34:11 +02:00
Adrien Béraud 1d80a77e55 build/cmake: avoid overriding "" for CMAKE_MSVC_RUNTIME_LIBRARY 2025-06-20 19:06:08 -04:00
Adrien Béraud fb8734c448 c: use c++ linkage for some non-exported functions 2025-06-20 19:04:59 -04:00
Andrey Vukolov 090fe75b7f OpenSSL link MSVC workflow workaround 2025-06-19 12:56:44 +02:00
Andrey Vukolov 173ca3d923 OpenSSL link Clang workflow workaround 2025-06-19 12:52:30 +02:00
Andrey Vukolov f5c875a19d OpenSSL link CMake workflow check 2025-06-19 12:46:20 +02:00
Andrey Vukolov 6780013f50 Unit tests workaround for possible issue with OpenSSL link 2025-06-19 12:17:10 +02:00
Andrey Vukolov 2f21a6e35a Unit tests workaround for possible issue with OpenSSL link 2025-06-19 12:07:36 +02:00
Andrey Vukolov 9e9e364048 C tools CFLAGS workaround for STATIC builds 2025-06-19 11:59:50 +02:00
Andrey Vukolov 2c3296542b Crypt32.dll fix 2025-06-18 17:14:05 +02:00
Andrey Vukolov 72988cca28 Regression fix 2025-06-18 16:53:54 +02:00
Andrey Vukolov a105513750 Attempt to fix OpenSSL for MSYS2 builds on CI 2025-06-18 16:48:05 +02:00
Andrey Vukolov bece03eab8 Attempt to fix llhttp for MSYS2 builds on CI 2025-06-18 16:32:28 +02:00
Andrey Vukolov 0fdb6979dd Attempt to fix OpenSSL for MSYS2 builds on CI 2025-06-18 16:21:57 +02:00
Andrey Vukolov a77c1d9538 Attempt to fix llhttp for MSYS2 builds on CI 2025-06-18 16:13:10 +02:00
Andrey Vukolov 4a7e1aba15 Attempt to fix llhttp for MSYS2 builds on CI 2025-06-18 16:08:38 +02:00
Andrey Vukolov a4263b9b54 Attempt to fix llhttp for MSYS2 builds on CI 2025-06-18 15:59:41 +02:00
Andrey Vukolov e26ed26e05 Attempt to fix restinio for MSYS2 builds on CI 2025-06-18 15:47:31 +02:00
Andrey Vukolov 526b11f973 C binding fixes, libreadline support for MSVC 2025-06-18 15:30:51 +02:00
Andrey Vukolov 627af36085 MSYS2 Crypto library fix 2025-06-18 12:07:51 +02:00
Andrey Vukolov a22c84d013 MSVC static runtime fix 2025-06-18 11:41:52 +02:00
Andrey Vukolov 3707f6294e libreadline fix for C tools 2025-06-18 11:29:26 +02:00
Andrey Vukolov 94cb17ef63 libreadline fix, WINVER typo fix 2025-06-18 11:22:55 +02:00
Andrey Vukolov 9bb08fa194 Merge branch 'master' into winbuild 2025-06-18 10:40:02 +02:00
Adrien Béraud 425cd58ea6 ci: build a static windows release 2025-06-17 20:49:05 -04:00
Adrien Béraud 43eb062ac5 build/cmake: use appropriate definitions for shared c lib 2025-06-17 20:25:56 -04:00
Adrien Béraud 29d878fad7 build/cmake: inherit build dir for msvc 2025-06-17 20:22:22 -04:00
Adrien Béraud a3a95a8f59 build/cmake: use appropriate definitions for shared c lib 2025-06-17 20:22:22 -04:00
Adrien Béraud 550721e233 build/cmake: use global MSVC_RUNTIME_LIBRARY 2025-06-17 20:22:22 -04:00
Adrien Béraud fa11d60672 c: use OPENDHT_C_PUBLIC for all symbols 2025-06-17 20:22:22 -04:00
Andrey Vukolov 6f8c681b26 Boost fix 2025-06-17 20:23:45 +02:00
Andrey Vukolov 718e445370 typo fix 2025-06-17 19:37:05 +02:00
Andrey Vukolov 5e469cba0f Boost fetcher (MSYS2/MinGW dependency) 2025-06-17 19:26:40 +02:00
Andrey Vukolov a05479e2dc Merge branch 'master' into winbuild
- Built and tested on MSVC for static and dynamic builds, tested.
2025-06-17 18:59:51 +02:00
Andrey Vukolov fb630e29b9 Merge branch 'savoirfairelinux:master' into winbuild 2025-06-12 09:28:10 +02:00
Andrey Vukolov 3a0b09816b Merge remote-tracking branch 'refs/remotes/twdragon/winbuild' into winbuild 2025-06-12 09:23:14 +02:00
Andrey Vukolov 8ab6b5b06e Fixes for current MSVC build, presets deleted 2025-06-12 09:22:30 +02:00
Andrey Vukolov 9ca1c45ae7 CMakeLists.txt - remove occasional regression to cjson 2025-06-10 14:01:14 +02:00
Andrey Vukolov b9a6b1001c Merge branch 'master' into winbuild 2025-06-10 09:31:47 +02:00
Andrey Vukolov 798adefcde Fixes for MSYS2
- Set populated only for msgpack-cxx that does not exist for
      MinGW GCC x86_64
      https://packages.msys2.org/base/mingw-w64-msgpack-cxx
    - .gitignore fix for vcpkg (incorporated #760)
    - GnuTLS version handler fix (#755, #758)
2025-06-09 15:31:38 +02:00
Andrey Vukolov 72afb61079 Merge branch 'savoirfairelinux:master' into winbuild 2025-06-09 09:40:26 +02:00
Andrey Vukolov c27f0f8fdc Merge branch 'master' into winbuild 2025-06-07 22:32:26 +02:00
Andrey Vukolov 8d8b082ae2 Temporary fix https://github.com/savoirfairelinux/opendht/pull/750#discussion_r2129833074 2025-06-06 11:09:43 +02:00
Andrey Vukolov 5377a48074 Rebase regression fix in tools_common.h 2025-06-06 11:00:35 +02:00
Andrey Vukolov ca8998e62b Merge branch 'winbuild' of github.com:twdragon/opendht into winbuild 2025-06-05 18:38:49 +02:00
Andrey Vukolov 62359d9011 Edited CMakeLists.txt file for building over vcpkg only 2025-06-05 18:38:21 +02:00
Andrey Vukolov 3022c4b378 Merge branch 'savoirfairelinux:master' into winbuild 2025-06-05 17:52:47 +02:00
Andrey Vukolov de8b441dae Merge branch 'master' into winbuild 2025-06-02 16:37:57 +02:00
Andrey Vukolov 5c4997d07e Merge master branch changes
- Applies master branch changes from #753 #754 #755 #756
      and commits for version 3.4.0 by @aberaud to winbuild branch
      for #750
	- CMake version handler for MINIMUM requirement setup to 3.5
2025-06-02 16:26:45 +02:00
Andrey Vukolov 49b1daec38 Indentation fix 2025-05-23 15:43:08 +02:00
Andrey Vukolov 1eba919dbd Trailing newline fix 2025-05-23 14:42:43 +02:00
Andrey Vukolov 3cd5338890 opendht_EXPORTS fix for shared builds 2025-04-27 22:53:17 +02:00
Andrey Vukolov 2fc81ad2dd GnuTLS build fix for MSVC
- Removed GNUTLS_INTERNAL_BUILD definition to avoid
	  usage of POSIX free() function
	- Autotools build fix
2025-04-26 16:55:58 +02:00
Andrey Vukolov 63a49896bf Fix Meson build 2025-04-24 16:00:04 +02:00
Andrey Vukolov 80755e5f15 Fix Meson build 2025-04-24 15:55:06 +02:00
Andrey Vukolov ba25b8aeba Incorporated commits for version 3.3.1 + MSVC build fixes
- Incorporated code for version 3.3.1
	- Reverted constexpr commits for hex_map:
	  - 352e36500c
	  - 6a264d6f73
	  as they created a lot of problems during builds on
	  Windows/MSVC.
	- Tested binaried linked dynamically with:
	  - MSYS2 (production-ready)
	  - MSVC (only for testing) !!!danger of memory leaks!!!
	- Tested binaries linked statically on win32 x64 platform
	- Populated libasio for both MSYS2 and MSVC builds on Windows
	- Pipeline fixes to build on Windows using only:
	  - vcpkg for MSVC
	  - MSYS2 pacman for MinGW
	  and remove the external dependency directory

The reference Windows builds are accessible in the following IPFS directory:

https://bafybeihsrak7orgubrnl5lvpcyzb4xf6kc7cd4tfvctucftg6vfqdhphlq.ipfs.dweb.link/
2025-04-24 14:50:23 +02:00
Andrey Vukolov 279589fa78 Pre-master 2025-04-23 18:18:58 +02:00
Andrey Vukolov 1c1c99974a Added and tested build scenarios for Windows (MSYS2, MSVC static)
- Based on Windows build adjustment code from @novemus
	  (see his magnificient code merge request #716)
	- Determined full-static and dynamic link libraries for
	  Windows if built using MSYS2 or MSVC
	- Built without restinio and llhttp [TODO]
	- Set for automatic fetching and population from the network
	  the following libraries for MSYS2:
		- GnuTLS 3.8.4 for 64-bit Windows (tested for dynamic
		  and static builds)
			- Auto name adjustments for GnuTLS
		- GnuTLS 3.8.9 for 32-bit Windows (untested)
		- cJSON as a dependency for msgpack
		- msgpack 6.1.1
		- jsoncpp 1.9.5
		- libfmt 11.1.2
		- libasio 1.30.2
	  for MSVC:
		- cJSON (used by msgpack in dynamic builds)
		- jsoncpp 1.9.5
		- libfmt 11.1.2
	- Various build scenario fixes for MSVC dynamic builds
	- Added modular codebase for infohash.cpp to avoid header
	  treatment mismatches in MSVC when compiling DLL
	- Added convenience prints in the build scenario
	- Fixed inconvenient usage of pkgconfig in Windows, the
	  link scenarios adjusted accordingly
	- Fixed hardcoded find_library calls
	- Added standard CMake handler for Boost library using
	  BOOST_ROOT variable, including environmental definition
	- Fixed libreadline linkage on POSIX when the default link
	  point is turned off for OPENDHT_TOOLS (Mint Linux)
	- Added versioned handler for CMP0167 policy (from CMake 3.30)
	- Code fixes for compatibility headers in Windows (crypto.cpp,
	  network_utils.h, utils.h)
	- Urgent fix for improper redefinition of _WINNT_VERSION for
	  Windows 10/11
	  (https://github.com/savoirfairelinux/opendht/pull/716#issuecomment-2793129052)
	- Compile definitions fixed for opendht_EXPORTS and OPENDHT_BUILD
	  in build scenario for OPENDHT_TOOLS
	- Urgent fix for GnuTLS version handler in the code (type
	  redefinition in version 3.8.7 and later)
	  https://github.com/savoirfairelinux/opendht/pull/716#issuecomment-2792592951
	- Various fixes for proper dynamic linking in Windows
	- Built and tested in dynamic and static build scenarios under
	  MSYS2 in Windows 10 and Windows 11, proven working. The
	  static build does not seem fully static, the redevelopment
	  of the MSVC build scenario is proposed by @novemus
	- Built and tested in static mode under MSVC/Visual Studio 2022.
	  Proven working
	- Improper usage of the C's free() function is detected in GnuTLS
	  dynamically linked in Windows (shiftmedia-gnutls 3.7.2 to 3.8.7)
	- Added a MSVC-specific source hack to avoid using gnutls_free()
	  function when built in Windows using dynamic link.
	  !!! CAUTION !!!
	  This implementation should be considered as a dirty hack likely
	  leading to memory leaks! The code should be thoroughly tested
	  and refactored to avoid memory leaks, but the true origin of
	  errors is still not revealed [TODO]
	- My respect to @novemus and his works over #716
2025-04-22 14:46:41 +02:00
novemus 3be70cd90d msvc build adjustment 2024-07-13 09:42:34 +03:00
16 changed files with 626 additions and 363 deletions

No files matched your search

+1 -1
View File
@@ -333,7 +333,7 @@ jobs:
mkdir build_python && cd build_python && \
cmake .. -DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release \
-DOPENDHT_STATIC=Off \
-DBUILD_SHARED_LIBS=On \
-DOPENDHT_PYTHON=On \
-DOPENDHT_C=Off \
-DOPENDHT_PEER_DISCOVERY=On \
+114
View File
@@ -47,6 +47,7 @@ jobs:
${{ runner.os }}-vcpkg-${{ env.VCPKG_VERSION }}-${{ matrix.arch }}-
- name: Setup vcpkg and install dependencies
if: steps.cache-vcpkg.outputs.cache-hit != 'true'
run: |
New-Item -Path "${{ env.VCPKG_INSTALLED_DIR }}" -ItemType Directory -Force
vcpkg install `
@@ -57,6 +58,51 @@ jobs:
--x-feature=test
shell: pwsh
prepare-static-dependencies:
name: Prepare Windows Static Dependencies
runs-on: windows-latest
outputs:
vcpkg_static_cache_key: ${{ steps.generate_static_cache_key.outputs.key }}
strategy:
matrix:
arch: [x64]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up MSVC
uses: microsoft/setup-msbuild@v2
- name: Generate Cache Key for Static Libs
id: generate_static_cache_key
shell: pwsh
run: |
$key_value = "${{ runner.os }}-vcpkg-${{ env.VCPKG_VERSION }}-${{ matrix.arch }}-static-${{ hashFiles('**/vcpkg.json', '**/vcpkg-configuration.json') }}-${{ hashFiles('.github/workflows/windows-build.yml') }}"
echo "key=$key_value" >> $env:GITHUB_OUTPUT
- name: Cache vcpkg static installed packages
id: cache-vcpkg-static
uses: actions/cache@v4
with:
path: ${{ env.VCPKG_INSTALLED_DIR }}
key: ${{ steps.generate_static_cache_key.outputs.key }}
restore-keys: |
${{ runner.os }}-vcpkg-${{ env.VCPKG_VERSION }}-${{ matrix.arch }}-static-${{ hashFiles('**/vcpkg.json', '**/vcpkg-configuration.json') }}
${{ runner.os }}-vcpkg-${{ env.VCPKG_VERSION }}-${{ matrix.arch }}-static-
- name: Setup vcpkg and install static dependencies
if: steps.cache-vcpkg-static.outputs.cache-hit != 'true'
shell: pwsh
run: |
New-Item -Path "${{ env.VCPKG_INSTALLED_DIR }}" -ItemType Directory -Force
vcpkg install `
--recurse `
--clean-after-build `
--triplet=${{ matrix.arch }}-windows-static-release `
--x-install-root=${{ env.VCPKG_INSTALLED_DIR }} `
--x-feature=test
build-windows:
name: Windows MSVC Build
runs-on: windows-latest
@@ -129,6 +175,74 @@ jobs:
build/**/*.lib
retention-days: 7
build-windows-static:
name: Windows Static MSVC Build
runs-on: windows-latest
needs: prepare-static-dependencies
strategy:
matrix:
build_type: [Release]
arch: [x64]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up MSVC
uses: microsoft/setup-msbuild@v2
- name: Restore vcpkg static installed packages
id: cache-vcpkg-static-restore
uses: actions/cache/restore@v4
with:
path: ${{ env.VCPKG_INSTALLED_DIR }}
key: ${{ needs.prepare-static-dependencies.outputs.vcpkg_static_cache_key }}
restore-keys: |
${{ runner.os }}-vcpkg-${{ env.VCPKG_VERSION }}-${{ matrix.arch }}-static-${{ hashFiles('**/vcpkg.json', '**/vcpkg-configuration.json') }}
${{ runner.os }}-vcpkg-${{ env.VCPKG_VERSION }}-${{ matrix.arch }}-static-
- name: Configure CMake for Static Build
shell: pwsh
run: |
mkdir build -ErrorAction SilentlyContinue
cmake -B build `
-S . `
-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_INSTALLATION_ROOT }}/scripts/buildsystems/vcpkg.cmake `
-DVCPKG_TARGET_TRIPLET=${{ matrix.arch }}-windows-static-release `
-DVCPKG_INSTALLED_DIR=${{ env.VCPKG_INSTALLED_DIR }} `
-DVCPKG_MANIFEST_FEATURES=test `
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} `
-DBUILD_SHARED_LIBS=OFF `
-DBUILD_TESTING=ON `
-DOPENDHT_PROXY_CLIENT=ON `
-DOPENDHT_PROXY_SERVER=ON `
-DOPENDHT_C=ON `
-DOPENDHT_TOOLS=ON `
-DOPENDHT_PYTHON=OFF `
-DOPENDHT_PEER_DISCOVERY=ON `
-DOPENDHT_HTTP=ON `
-A ${{ matrix.arch }}
- name: Build Static
shell: pwsh
run: |
cmake --build build --config ${{ matrix.build_type }} --parallel 4
- name: Test Static Build
shell: pwsh
run: |
cd build
ctest --build-config ${{ matrix.build_type }} --output-on-failure --parallel 4
- name: Upload static build artifacts
uses: actions/upload-artifact@v4
with:
name: opendht-windows-static-${{ matrix.arch }}-${{ matrix.build_type }}
path: |
build/**/*.exe
build/**/*.lib
retention-days: 7
build-windows-mingw:
name: Windows MinGW Build
runs-on: windows-latest
+410 -293
View File
@@ -1,10 +1,13 @@
cmake_minimum_required (VERSION 3.21..3.31)
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif() # MSVC build workaround for STATIC mode
endif()
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
if(NOT CMAKE_VERSION VERSION_LESS 3.30 AND NOT POLICY CMP0167)
cmake_policy(SET CMP0167 OLD)
endif()
set (opendht_VERSION_MAJOR 3)
set (opendht_VERSION_MINOR 4.0)
@@ -17,18 +20,20 @@ project (opendht
HOMEPAGE_URL "https://opendht.net/"
)
include(CMakePackageConfigHelpers)
include(CMakeDependentOption)
include(CheckIncludeFileCXX)
include(FindPkgConfig)
set(POSSIBLE_PKGCONFIG OFF)
if(NOT MSVC)
include(FindPkgConfig)
set(POSSIBLE_PKGCONFIG ON)
endif()
include(cmake/CheckAtomic.cmake)
include(FetchContent)
include(CTest)
# Options
option (BUILD_SHARED_LIBS "Build shared library" ON)
CMAKE_DEPENDENT_OPTION (OPENDHT_STATIC "Build static library" OFF BUILD_SHARED_LIBS ON)
option (OPENDHT_USE_PKGCONFIG "Use pkg-config to find installed libraries where possible" ${POSSIBLE_PKGCONFIG})
option (OPENDHT_PYTHON "Build Python bindings" OFF)
option (OPENDHT_TOOLS "Build DHT tools" ON)
option (OPENDHT_SYSTEMD "Install systemd module" OFF)
@@ -42,17 +47,22 @@ option (OPENDHT_PROXY_OPENSSL "Build DHT proxy with OpenSSL" ON)
CMAKE_DEPENDENT_OPTION(OPENDHT_HTTP "Build embedded http(s) client" OFF "NOT OPENDHT_PROXY_SERVER;NOT OPENDHT_PROXY_CLIENT" ON)
option (OPENDHT_PEER_DISCOVERY "Enable multicast peer discovery" ON)
option (OPENDHT_IO_URING "Use io_uring if available on the system (Linux only)" OFF)
option (OPENDHT_INDEX "Build DHT indexation feature" OFF)
option (OPENDHT_INDEX "Build DHT indexing feature" OFF)
option (OPENDHT_TESTS_NETWORK "Enable unit tests that require network access" ON)
option (OPENDHT_C "Build C bindings" OFF)
option (OPENDHT_CPACK "Add CPack support" OFF)
option (OPENDHT_DOWNLOAD_DEPS "Fetch automatically the dependency libraries from the network" OFF)
find_package(Doxygen)
option (OPENDHT_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
find_package(Doxygen QUIET)
if (DOXYGEN_FOUND)
option (OPENDHT_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
endif ()
# Build flags
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED on)
if(MSVC AND NOT BUILD_SHARED_LIBS AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
if (OPENDHT_C)
set (CMAKE_C_STANDARD 11)
@@ -63,106 +73,110 @@ if (OPENDHT_C)
endif()
endif()
# Dependencies
if (NOT HAVE_CXX_ATOMICS_WITHOUT_LIB
# For ARM EABI (armel), little-endian MIPS (mipsel), etc.
OR NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
link_libraries (atomic)
endif ()
if (WIN32)
if(CMAKE_SYSTEM_VERSION AND CMAKE_SYSTEM_VERSION VERSION_LESS_EQUAL "6.3")
set(WINVER 0x0603) # Minimum supported is Windows 8.1
else()
set(WINVER 0x0A00) # Windows 10/11 by default
if(WIN32) # https://stackoverflow.com/a/40217291/9560245
macro(get_WIN32_WINNT version)
if(CMAKE_SYSTEM_VERSION)
set(ver ${CMAKE_SYSTEM_VERSION})
string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
# Check for Windows 10, b/c we'll need to convert to hex 'A'.
if("${verMajor}" MATCHES "10")
set(verMajor "A")
string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
endif()
# Remove all remaining '.' characters.
string(REPLACE "." "" ver ${ver})
# Prepend each digit with a zero.
string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
set(${version} "0x${ver}")
endif()
endmacro()
get_WIN32_WINNT(WINNT_VERSION)
# Prevents MinGW from problems linking Windows networking and IPC functions on Windows 10/11
# if _WIN32_WINNT is not defined correctly
message(STATUS "Windows NT version detection: ${WINNT_VERSION}")
if(NOT MSVC)
add_definitions(-D_WIN32_WINNT=${WINNT_VERSION} -DWINVER=${WINNT_VERSION})
endif()
add_definitions(-DWINVER=${WINVER} -D_WIN32_WINNT=${WINVER})
set(CMAKE_DEBUG_POSTFIX "")
endif()
# Dependencies
if(OPENDHT_DOWNLOAD_DEPS)
message(STATUS "Dependency downloader fallback activated")
include(FetchContent)
set(FETCHCONTENT_QUIET FALSE)
endif()
if (WIN32)
set(MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE) # MSVC CMake cache workaround
endif ()
list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
if (NOT MSVC)
# Generalized UNIX/MSYS2 build pipeline
set (THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package (Threads)
find_package (PkgConfig REQUIRED)
pkg_search_module (GnuTLS REQUIRED IMPORTED_TARGET gnutls)
pkg_search_module (Nettle REQUIRED IMPORTED_TARGET nettle)
check_include_file_cxx(msgpack.hpp HAVE_MSGPACKCXX)
if (NOT HAVE_MSGPACKCXX)
find_package(msgpack QUIET CONFIG NAMES msgpack msgpackc-cxx)
if (NOT msgpack_FOUND)
find_package(msgpack REQUIRED CONFIG NAMES msgpack-cxx)
set(MSGPACK_TARGET "msgpack-cxx")
else()
set(MSGPACK_TARGET "msgpackc-cxx")
endif()
endif()
if (OPENDHT_TOOLS)
find_package (Readline 6 REQUIRED)
set(readline_LIBRARIES ${READLINE_LIBRARIES})
endif ()
pkg_search_module(argon2 REQUIRED IMPORTED_TARGET libargon2)
set(argon2_lib ", libargon2")
pkg_search_module(Jsoncpp IMPORTED_TARGET jsoncpp)
if (Jsoncpp_FOUND)
add_definitions(-DOPENDHT_JSONCPP)
set(jsoncpp_lib ", jsoncpp")
list (APPEND opendht_SOURCES
src/base64.h
src/base64.cpp
)
endif()
if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
find_path(ASIO_INCLUDE_DIR asio.hpp REQUIRED)
message(STATUS "Found ASIO ${ASIO_INCLUDE_DIR}")
else()
message(STATUS "ASIO not required")
endif ()
find_package(fmt)
if (OPENDHT_HTTP)
find_package(Restinio REQUIRED)
# llhttp
pkg_search_module(LLHTTP IMPORTED_TARGET llhttp libllhttp)
if (LLHTTP_FOUND)
message(STATUS "Found llhttp ${LLHTTP_INCLUDE_DIRS}")
set(llhttp_target PkgConfig::LLHTTP)
else()
find_path(LLHTTP_INCLUDE_DIR llhttp.h)
find_library(LLHTTP_LIBRARY NAMES llhttp libllhttp)
if (LLHTTP_INCLUDE_DIR AND LLHTTP_LIBRARY)
message(STATUS "Found llhttp ${LLHTTP_INCLUDE_DIR} ${LLHTTP_LIBRARY}")
add_library(llhttp_static STATIC IMPORTED)
set_target_properties(llhttp_static PROPERTIES
IMPORTED_LOCATION ${LLHTTP_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${LLHTTP_INCLUDE_DIR}
)
set(llhttp_target llhttp_static)
if (OPENDHT_USE_PKGCONFIG)
find_package (PkgConfig REQUIRED)
# GNUTLS
pkg_search_module (GnuTLS REQUIRED IMPORTED_TARGET gnutls)
# libnettle
pkg_search_module (Nettle REQUIRED IMPORTED_TARGET nettle)
# libargon2
pkg_search_module (argon2 REQUIRED IMPORTED_TARGET libargon2)
set(argon2_lib ", libargon2")
# jsoncpp
pkg_search_module (Jsoncpp IMPORTED_TARGET jsoncpp)
if(Jsoncpp_FOUND)
if(APPLE)
set(JSONCPP_LIBRARIES PkgConfig::Jsoncpp)
else()
FetchContent_Declare(llhttp-local URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v9.2.1.tar.gz")
if (BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON CACHE INTERNAL "")
else()
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
set(BUILD_STATIC_LIBS ON CACHE INTERNAL "")
endif()
FetchContent_MakeAvailable(llhttp-local)
if (BUILD_SHARED_LIBS)
set(llhttp_target llhttp_shared)
else()
set(llhttp_target llhttp_static)
endif()
set(JSONCPP_LIBRARIES ${Jsoncpp_LIBRARIES})
endif()
set(JSONCPP_INCLUDE_DIRS ${Jsoncpp_INCLUDE_DIRS})
set(JSONCPP_FOUND ${Jsoncpp_FOUND})
include_directories(${JSONCPP_INCLUDE_DIRS})
endif()
set(http_lib "-lllhttp")
if (NOT Jsoncpp_FOUND)
message(SEND_ERROR "Jsoncpp is required for DHT proxy support")
endif()
# libfmt
pkg_search_module (fmt REQUIRED IMPORTED_TARGET fmt)
# libreadline
if (OPENDHT_TOOLS AND NOT APPLE)
pkg_search_module(readline REQUIRED IMPORTED_TARGET readline)
message(STATUS "libreadline: version ${readline_VERSION}")
set(READLINE_VERSION ${readline_VERSION})
if(READLINE_VERSION VERSION_LESS 6)
message(SEND_ERROR "libreadline: required version 6.0 or later")
endif()
set(READLINE_LIBRARIES ${readline_LIBRARIES})
endif ()
# ASIO
if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
pkg_search_module(asio REQUIRED IMPORTED_TARGET asio)
set(ASIO_INCLUDE_DIR ${asio_INCLUDE_DIRS})
message(STATUS "Found ASIO: ${ASIO_INCLUDE_DIR}")
endif ()
# llhttp
if (OPENDHT_HTTP)
pkg_search_module(LLHTTP IMPORTED_TARGET llhttp libllhttp)
if (LLHTTP_FOUND)
message(STATUS "Found llhttp: ${LLHTTP_FOUND} ${LLHTTP_INCLUDE_DIR}")
set(llhttp_target PkgConfig::LLHTTP)
else()
message(STATUS "llhttp not found with pkgconfig")
endif()
else ()
set(OPENDHT_PROXY_OPENSSL OFF)
endif ()
if (OPENDHT_PROXY_OPENSSL)
# https://cmake.org/cmake/help/latest/module/FindOpenSSL.html
pkg_search_module(OPENSSL REQUIRED IMPORTED_TARGET openssl)
if (OPENSSL_FOUND)
message(STATUS "Found OpenSSL ${OPENSSL_VERSION} ${OPENSSL_INCLUDE_DIRS}")
@@ -172,103 +186,197 @@ if (NOT MSVC)
endif()
endif()
else ()
set(OPENDHT_PROXY_OPENSSL OFF)
endif ()
else ()
# MSVC build - check if using vcpkg first
if (DEFINED CMAKE_TOOLCHAIN_FILE AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
# Using vcpkg - use find_package for dependencies
find_package(msgpack-cxx CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(GnuTLS REQUIRED)
include_directories(${GNUTLS_INCLUDE_DIR})
# jsoncpp
find_package(jsoncpp CONFIG REQUIRED)
# Find GnuTLS and Nettle libraries (vcpkg doesn't provide CMake targets for these)
find_library(GNUTLS_LIBRARY NAMES gnutls REQUIRED)
find_library(NETTLE_LIBRARY NAMES nettle REQUIRED)
find_library(HOGWEED_LIBRARY NAMES hogweed REQUIRED)
find_library(TASN_LIBRARY NAMES tasn1 REQUIRED)
find_library(ARGON2_LIBRARY NAMES argon2 REQUIRED)
find_path(GNUTLS_INCLUDE_DIR gnutls/gnutls.h REQUIRED)
find_path(NETTLE_INCLUDE_DIR nettle/aes.h REQUIRED)
set(JSONCPP_FOUND TRUE)
# libfmt
find_package(fmt CONFIG REQUIRED)
# libargon2
find_path(ARGON2_INCLUDE_DIR argon2.h REQUIRED)
# Create imported targets for these libraries
add_library(gnutls_lib STATIC IMPORTED)
set_target_properties(gnutls_lib PROPERTIES
IMPORTED_LOCATION ${GNUTLS_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${GNUTLS_INCLUDE_DIR}
)
add_library(nettle_lib STATIC IMPORTED)
set_target_properties(nettle_lib PROPERTIES
IMPORTED_LOCATION ${NETTLE_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${NETTLE_INCLUDE_DIR}
)
add_library(hogweed_lib STATIC IMPORTED)
set_target_properties(hogweed_lib PROPERTIES
IMPORTED_LOCATION ${HOGWEED_LIBRARY}
)
add_library(tasn1_lib STATIC IMPORTED)
set_target_properties(tasn1_lib PROPERTIES
IMPORTED_LOCATION ${TASN_LIBRARY}
)
add_library(argon2_lib STATIC IMPORTED)
set_target_properties(argon2_lib PROPERTIES
IMPORTED_LOCATION ${ARGON2_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${ARGON2_INCLUDE_DIR}
)
add_definitions(-DOPENDHT_JSONCPP)
list (APPEND opendht_SOURCES
src/base64.h
src/base64.cpp
)
if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
find_package(asio CONFIG REQUIRED)
find_package(llhttp CONFIG REQUIRED)
find_package(restinio CONFIG REQUIRED)
if (OPENDHT_PROXY_OPENSSL)
find_package(OpenSSL REQUIRED)
endif ()
endif ()
set(argon2_lib ", libargon2")
# libreadline
if (OPENDHT_TOOLS)
find_package(unofficial-readline-win32 CONFIG)
if (unofficial-readline-win32_FOUND)
set(readline_LIBRARIES unofficial::readline-win32::readline)
else()
set (readline_LIBRARIES "readline")
message(WARNING "unofficial-readline-win32 not found, trying to use system readline")
endif()
find_package (Readline 6 REQUIRED)
endif ()
else()
# Traditional MSVC dependency path
set (WIN32_DEP_DIR ${PROJECT_SOURCE_DIR}/../)
include_directories(${WIN32_DEP_DIR}/../msvc/include) # SMP gnutls
include_directories(${WIN32_DEP_DIR}/argon2/include)
include_directories(${WIN32_DEP_DIR}/jsoncpp/include)
list (APPEND opendht_SOURCES
src/base64.h
src/base64.cpp
)
add_definitions(-DOPENDHT_JSONCPP)
include_directories(${WIN32_DEP_DIR}/msgpack-c/include)
# ASIO
if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
include_directories(
${WIN32_DEP_DIR}/asio/asio/include
${WIN32_DEP_DIR}/openssl/include
${WIN32_DEP_DIR}/restinio/dev
${WIN32_DEP_DIR}/fmt/include
${WIN32_DEP_DIR}/llhttp/include
find_path(ASIO_INCLUDE_DIR asio.hpp REQUIRED)
message(STATUS "Found ASIO ${ASIO_INCLUDE_DIR}")
else()
message(STATUS "ASIO not required")
endif ()
# llhttp
if (OPENDHT_HTTP)
find_package(llhttp CONFIG REQUIRED)
set(llhttp_target llhttp::llhttp_static)
if (OPENDHT_PROXY_OPENSSL)
find_package(openssl REQUIRED)
endif()
else ()
set(OPENDHT_PROXY_OPENSSL OFF)
endif ()
endif ()
# File-based searches
# msgpack
check_include_file_cxx(msgpack.hpp HAVE_MSGPACKCXX)
if (NOT HAVE_MSGPACKCXX)
find_package(msgpack QUIET CONFIG NAMES msgpack msgpackc-cxx)
if (NOT msgpack_FOUND)
find_package(msgpack QUIET CONFIG NAMES msgpack-cxx)
if (msgpack_FOUND)
set(MSGPACK_TARGET "msgpack-cxx")
else()
if(OPENDHT_DOWNLOAD_DEPS)
# Workaround for msgpack-cxx
FetchContent_Declare(msgpack-c
GIT_REPOSITORY "https://github.com/msgpack/msgpack-c.git"
GIT_TAG "cpp-7.0.0"
FIND_PACKAGE_ARGS NAMES msgpack-c
)
set(MSGPACK_USE_BOOST OFF CACHE INTERNAL "Workaround for Boost")
FetchContent_MakeAvailable(msgpack-c)
find_package(msgpack-c CONFIG REQUIRED)
include_directories(${MSGPACK_INCLUDEDIR} ${msgpack-c_SOURCE_DIR}/include)
else()
message(SEND_ERROR "msgpack not found and the fallback downloader is not set! Please install msgpack or use OPENDHT_DOWNLOAD_DEPS option")
endif()
endif ()
else()
set(MSGPACK_TARGET "msgpackc-cxx")
endif()
endif()
# llhttp
if (OPENDHT_HTTP AND NOT LLHTTP_FOUND)
find_path(LLHTTP_INCLUDE_DIR llhttp.h)
find_library(LLHTTP_LIBRARY NAMES llhttp libllhttp)
if (LLHTTP_INCLUDE_DIR AND LLHTTP_LIBRARY)
message(STATUS "Found llhttp ${LLHTTP_INCLUDE_DIR} ${LLHTTP_LIBRARY}")
add_library(llhttp_static STATIC IMPORTED)
set_target_properties(llhttp_static PROPERTIES
IMPORTED_LOCATION ${LLHTTP_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${LLHTTP_INCLUDE_DIR}
)
set(llhttp_target llhttp_static)
elseif (OPENDHT_DOWNLOAD_DEPS)
message(STATUS "Fallback mode specified, downloading llhttp")
FetchContent_Declare(llhttp-local REQUIRED
URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v9.2.1.tar.gz"
)
if (BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON CACHE INTERNAL "")
else()
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
set(BUILD_STATIC_LIBS ON CACHE INTERNAL "")
endif()
FetchContent_MakeAvailable(llhttp-local)
include_directories(${llhttp-local_SOURCE_DIR}/include)
link_directories(${llhttp-local_BINARY_DIR}) # MacOS library search workaround
if (BUILD_SHARED_LIBS)
set(llhttp_target llhttp_shared)
else()
set(llhttp_target llhttp_static)
endif()
else()
message(SEND_ERROR "llhttp not found and fallback downloader disabled. Install llhttp or use OPENDHT_DOWNLOAD_DEPS option")
endif ()
endif ()
# restinio: does not provide pkg-config PC file
if(OPENDHT_HTTP)
find_package(Restinio REQUIRED)
set(restinio_target "")
endif()
# System-specific pipeline setup
if(APPLE)
if (OPENDHT_TOOLS)
find_package (Readline 6 REQUIRED)
endif ()
endif()
else () # MSVC
include_directories(src/compat/msvc)
include_directories(src/compat/win32)
find_package(unofficial-argon2 CONFIG REQUIRED)
include_directories(${ARGON2_INCLUDEDIR})
set(argon2_lib ", libargon2")
find_package(GnuTLS REQUIRED)
include_directories(${GNUTLS_INCLUDE_DIR})
find_package(msgpack-cxx CONFIG REQUIRED)
get_target_property(MSGPACK_INCLUDEDIR msgpack-cxx INTERFACE_INCLUDE_DIRECTORIES)
include_directories(${MSGPACK_INCLUDEDIR})
find_package(jsoncpp REQUIRED)
set(JSONCPP_FOUND TRUE)
include_directories(${JSONCPP_INCLUDE_DIRS})
find_package(fmt CONFIG REQUIRED)
include_directories(${FMT_INCLUDEDIR})
if(OPENDHT_TOOLS)
find_package(unofficial-readline-win32 CONFIG REQUIRED)
include_directories(${READLINE_INCLUDEDIR})
endif()
if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
find_package(asio CONFIG REQUIRED)
find_path(ASIO_INCLUDE_DIR asio.hpp REQUIRED HINTS ${ASIO_INCLUDE_DIRS}/asio/include)
message(STATUS "Found ASIO ${ASIO_INCLUDE_DIR}")
include_directories(${ASIO_INCLUDE_DIR})
add_definitions(-DASIO_STANDALONE)
else()
message(STATUS "ASIO not required")
endif ()
if (OPENDHT_HTTP)
find_package(restinio CONFIG REQUIRED)
set(restinio_target restinio::restinio)
find_package(llhttp CONFIG REQUIRED)
set(http_lib "-lllhttp")
if (OPENDHT_PROXY_OPENSSL)
find_package(OpenSSL REQUIRED)
set(openssl_lib ", openssl")
endif()
else()
set(OPENDHT_PROXY_OPENSSL OFF)
endif()
message(STATUS "Discovering external non-CMake libraries")
find_library(NETTLE_LIBRARY NAMES nettle libnettle REQUIRED)
find_library(HOGWEED_LIBRARY NAMES hogweed REQUIRED)
find_library(TASN_LIBRARY NAMES tasn1 REQUIRED)
find_path(NETTLE_INCLUDE_DIR nettle/aes.h REQUIRED)
add_library(nettle_lib STATIC IMPORTED)
set_target_properties(nettle_lib PROPERTIES
IMPORTED_LOCATION ${NETTLE_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${NETTLE_INCLUDE_DIR}
)
add_library(hogweed_lib STATIC IMPORTED)
set_target_properties(hogweed_lib PROPERTIES
IMPORTED_LOCATION ${HOGWEED_LIBRARY}
)
add_library(tasn1_lib STATIC IMPORTED)
set_target_properties(tasn1_lib PROPERTIES
IMPORTED_LOCATION ${TASN_LIBRARY}
)
endif ()
# Definitions
if(JSONCPP_FOUND)
add_definitions(-DOPENDHT_JSONCPP)
set(jsoncpp_lib ", jsoncpp")
list (APPEND opendht_SOURCES
src/base64.h
src/base64.cpp
)
endif()
if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
add_definitions(-DASIO_STANDALONE)
if (OPENDHT_IO_URING AND UNIX AND NOT APPLE)
@@ -277,7 +385,7 @@ if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
endif()
if (NOT MSVC)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wall -Wextra -Wnon-virtual-dtor -pedantic-errors -fvisibility=hidden")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes -Wno-return-type -Wno-deprecated -Wno-deprecated-declarations -Wno-unknown-pragmas -Wall -Wextra -Wnon-virtual-dtor -pedantic-errors -fvisibility=hidden")
if (OPENDHT_SANITIZE)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fstack-protector-strong")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fstack-protector-strong")
@@ -349,11 +457,11 @@ list (APPEND opendht_SOURCES
list (APPEND opendht_HEADERS
include/opendht.h
include/opendht/def.h
include/opendht/rng.h
include/opendht/infohash.h
include/opendht/utils.h
include/opendht/sockaddr.h
include/opendht/rng.h
include/opendht/crypto.h
include/opendht/infohash.h
include/opendht/default_types.h
include/opendht/node.h
include/opendht/value.h
@@ -414,7 +522,7 @@ endif ()
if (OPENDHT_HTTP)
if (OPENDHT_PUSH_NOTIFICATIONS)
message("Using push notification")
message(STATUS "Using push notification capability")
add_definitions(-DOPENDHT_PUSH_NOTIFICATIONS)
endif ()
list (APPEND opendht_HEADERS
@@ -433,130 +541,124 @@ if (MSVC)
endif ()
# Targets
# if (MSVC)
# if (OPENDHT_STATIC)
# if (OPENDHT_TOOLS)
# function (add_obj_lib name libfile)
# add_library(${name} OBJECT IMPORTED)
# set_property(TARGET ${name} PROPERTY IMPORTED_OBJECTS ${libfile})
# endfunction ()
# add_obj_lib (win32_json ${WIN32_DEP_DIR}/../msvc/lib/x64/lib_json.lib)
# add_obj_lib (win32_gnutls ${WIN32_DEP_DIR}/../msvc/lib/x64/libgnutls.lib)
# add_obj_lib (win32_argon2 ${WIN32_DEP_DIR}/argon2/vs2015/Argon2Ref/vs2015/build/Argon2Ref.lib)
# list (APPEND obj_libs
# $<TARGET_OBJECTS:win32_json>
# $<TARGET_OBJECTS:win32_gnutls>
# $<TARGET_OBJECTS:win32_argon2>
# )
# if (OPENDHT_HTTP)
# add_obj_lib (win32_fmt ${WIN32_DEP_DIR}/fmt/msvc/Release/fmt.lib)
# add_obj_lib (win32_llhttp ${WIN32_DEP_DIR}/llhttp/build/Release/llhttp.lib)
# add_obj_lib (win32_ssl ${WIN32_DEP_DIR}/openssl/libssl_static.lib)
# add_obj_lib (win32_crypto ${WIN32_DEP_DIR}/openssl/libcrypto_static.lib)
# list (APPEND obj_libs
# $<TARGET_OBJECTS:win32_fmt>
# $<TARGET_OBJECTS:win32_llhttp>
# $<TARGET_OBJECTS:win32_ssl>
# $<TARGET_OBJECTS:win32_crypto>
# )
# endif ()
# else ()
# list (APPEND win32_Libs
# ${PROJECT_SOURCE_DIR}/../../msvc/lib/x64/libgnutls.lib
# ${PROJECT_SOURCE_DIR}/../../msvc/lib/x64/lib_json.lib
# ${PROJECT_SOURCE_DIR}/../argon2/vs2015/Argon2Ref/vs2015/build/Argon2Ref.lib
# )
# list (APPEND win32_Libs
# ${PROJECT_SOURCE_DIR}/../fmt/msvc/Release/fmt.lib
# ${PROJECT_SOURCE_DIR}/../llhttp/build/Release/llhttp.lib
# ${PROJECT_SOURCE_DIR}/../openssl/libssl.lib
# ${PROJECT_SOURCE_DIR}/../openssl/libcrypto.lib
# )
# endif ()
# set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4006")
# endif()
# endif ()
add_library (opendht
${opendht_SOURCES}
${opendht_HEADERS}
${obj_libs}
add_library(opendht ${opendht_SOURCES} ${opendht_HEADERS})
target_include_directories(opendht
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
set_target_properties (opendht PROPERTIES OUTPUT_NAME "opendht")
if (NOT HAVE_MSGPACKCXX)
target_link_libraries(opendht PUBLIC ${MSGPACK_TARGET})
endif()
if (APPLE)
target_link_libraries(opendht PRIVATE "-framework CoreFoundation" "-framework Security")
endif()
if (WIN32)
target_link_libraries(opendht PUBLIC ws2_32 wsock32)
if (OPENDHT_HTTP)
target_link_libraries(opendht PRIVATE crypt32)
endif()
endif()
set_target_properties(opendht PROPERTIES OUTPUT_NAME "opendht")
# Linker pipelines
if (MSVC)
if (DEFINED CMAKE_TOOLCHAIN_FILE AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
# Using vcpkg - link with vcpkg targets
target_link_libraries(opendht
PUBLIC
msgpack-cxx
fmt::fmt
JsonCpp::JsonCpp
gnutls_lib
PRIVATE
argon2_lib
nettle_lib
hogweed_lib
tasn1_lib
)
if (OPENDHT_HTTP)
target_link_libraries(opendht
PUBLIC restinio::restinio
PRIVATE llhttp::llhttp_static)
if (OPENDHT_PROXY_OPENSSL)
target_link_libraries(opendht PUBLIC OpenSSL::SSL OpenSSL::Crypto)
endif()
endif()
message(STATUS "Build pipeline: Windows/MSVC + vcpkg")
message(STATUS "Used GnuTLS library: ${GNUTLS_LIBRARIES}")
message(STATUS "Used NETTLE library: ${NETTLE_LIBRARY}")
target_link_libraries(opendht
PRIVATE
unofficial::argon2::libargon2
nettle_lib
hogweed_lib
tasn1_lib
PUBLIC
${GNUTLS_LIBRARIES}
wsock32
ws2_32
)
if (OPENDHT_TOOLS)
target_link_libraries(opendht PUBLIC unofficial::readline-win32::readline)
endif()
if (OPENDHT_STATIC)
target_link_libraries(opendht PUBLIC ${Win32_STATIC_LIBRARIES} ${Win32_IMPORT_LIBRARIES})
set_target_properties(opendht PROPERTIES
OUTPUT_NAME "libopendht"
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
target_link_libraries(opendht PUBLIC msgpack-cxx jsoncpp_lib fmt::fmt)
if (OPENDHT_HTTP)
target_link_libraries(opendht
PUBLIC restinio::restinio
PRIVATE llhttp::llhttp_static)
if (OPENDHT_PROXY_OPENSSL)
target_link_libraries(opendht PUBLIC OpenSSL::SSL OpenSSL::Crypto)
endif()
target_link_libraries(opendht PUBLIC llhttp::llhttp_static)
endif()
else()
target_link_libraries(opendht
PRIVATE
PkgConfig::argon2
PkgConfig::Nettle
PUBLIC
${CMAKE_THREAD_LIBS_INIT}
PkgConfig::GnuTLS
fmt::fmt
if (APPLE)
message(STATUS "Build pipeline: Apple/Darwin")
target_link_libraries(opendht PRIVATE "-framework CoreFoundation" "-framework Security")
endif ()
# Generalized UNIX/MSYS2 build pipeline
if (OPENDHT_USE_PKGCONFIG)
target_link_libraries(opendht
PRIVATE
PkgConfig::argon2
PkgConfig::Nettle
PUBLIC
${CMAKE_THREAD_LIBS_INIT}
PkgConfig::GnuTLS
PkgConfig::fmt
${JSONCPP_LIBRARIES}
)
if(OPENDHT_TOOLS)
message(STATUS ${READLINE_LIBRARIES})
target_link_libraries(opendht PUBLIC ${READLINE_LIBRARIES})
endif()
if(OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
target_link_libraries(opendht PUBLIC PkgConfig::asio)
endif()
if (OPENDHT_PROXY_OPENSSL)
target_link_libraries(opendht PUBLIC PkgConfig::OPENSSL)
endif()
else(OPENDHT_USE_PKGCONFIG)
target_link_libraries(opendht
PRIVATE
argon2
nettle
PUBLIC
${CMAKE_THREAD_LIBS_INIT}
${GNUTLS_LIBRARIES}
jsoncpp
)
if(BUILD_SHARED_LIBS)
target_link_libraries(opendht PUBLIC fmt::fmt)
else()
target_link_libraries(opendht PUBLIC fmt::fmt-header-only)
endif()
if(OPENDHT_TOOLS)
target_link_libraries(opendht PUBLIC ${READLINE_LIBRARIES})
endif()
if (OPENDHT_PROXY_OPENSSL)
target_link_libraries(opendht PUBLIC OpenSSL::SSL OpenSSL::Crypto)
endif()
endif(OPENDHT_USE_PKGCONFIG)
if (NOT HAVE_MSGPACKCXX)
target_link_libraries(opendht PUBLIC ${MSGPACK_TARGET})
endif()
if(OPENDHT_HTTP)
target_link_libraries(opendht
PUBLIC # Required for linking tests
${llhttp_target}
${restinio_target}
)
if (OPENDHT_HTTP)
target_link_libraries(opendht PUBLIC ${llhttp_target})
endif()
if (Jsoncpp_FOUND)
target_link_libraries(opendht PUBLIC PkgConfig::Jsoncpp)
endif()
if (OPENDHT_PROXY_OPENSSL)
target_link_libraries(opendht PUBLIC PkgConfig::OPENSSL)
endif()
if (OPENDHT_IO_URING AND liburing_FOUND)
set(iouring_lib ", liburing")
target_link_libraries(opendht PUBLIC PkgConfig::liburing)
target_compile_definitions(opendht PUBLIC ASIO_HAS_IO_URING ASIO_DISABLE_EPOLL)
endif()
# System-specific linker pipelines
if (WIN32 AND MINGW) # MSYS2
message(STATUS "Build pipeline: Windows/MSYS2-MinGW")
target_link_libraries(opendht PUBLIC wsock32 ws2_32)
if(OPENDHT_PROXY_OPENSSL)
target_link_libraries(opendht PUBLIC Crypt32)
endif()
else() # UNIX / LLVM
message(STATUS "Build pipeline: UNIX generalized")
endif()
endif()
if (BUILD_SHARED_LIBS)
set_target_properties (opendht PROPERTIES IMPORT_SUFFIX "_import.lib")
set_target_properties (opendht PROPERTIES SOVERSION ${opendht_VERSION_MAJOR} VERSION ${opendht_VERSION})
target_compile_definitions(opendht PRIVATE OPENDHT_BUILD)
target_compile_definitions(opendht PRIVATE OPENDHT_BUILD)
target_compile_definitions(opendht PUBLIC opendht_EXPORTS)
endif ()
@@ -566,7 +668,7 @@ install (TARGETS opendht
RUNTIME_DEPENDENCY_SET opendht_rdeps
EXPORT opendht
)
if (WIN32 AND DEFINED CMAKE_TOOLCHAIN_FILE AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
if (WIN32)
install(RUNTIME_DEPENDENCY_SET opendht_rdeps
PRE_EXCLUDE_REGEXES
"api-ms-win-.*\\.dll"
@@ -606,9 +708,13 @@ if (OPENDHT_C)
)
target_compile_definitions(opendht-c PRIVATE OPENDHT_C_BUILD)
target_link_libraries(opendht-c PRIVATE opendht)
set_target_properties (opendht-c PROPERTIES SOVERSION ${opendht_VERSION_MAJOR} VERSION ${opendht_VERSION})
if(NOT BUILD_SHARED_LIBS)
set_target_properties(opendht-c PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
if(OPENDHT_TOOLS)
target_link_libraries(opendht-c PUBLIC ${READLINE_LIBRARIES})
endif()
if (BUILD_SHARED_LIBS)
target_compile_definitions(opendht-c PRIVATE OPENDHT_C_BUILD)
target_compile_definitions(opendht-c PUBLIC opendht_c_EXPORTS)
set_target_properties (opendht-c PROPERTIES SOVERSION ${opendht_VERSION_MAJOR} VERSION ${opendht_VERSION})
endif()
install (TARGETS opendht-c DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT opendht-c)
@@ -636,6 +742,7 @@ write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/opendhtConfigVersi
VERSION ${opendht_VERSION}
COMPATIBILITY AnyNewerVersion
)
# PkgConfig module
configure_file (
opendht.pc.in
@@ -648,6 +755,9 @@ install (DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/opendht.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install (EXPORT opendht DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/opendht FILE opendhtConfig.cmake)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/opendhtConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/opendht)
if(MSVC AND BUILD_SHARED_LIBS)
install(FILES $<TARGET_PDB_FILE:opendht> CONFIGURATIONS "RelWithDebInfo" "Debug" DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
# Unit tests
if (BUILD_TESTING)
@@ -696,6 +806,13 @@ if (BUILD_TESTING)
${CMAKE_THREAD_LIBS_INIT}
${cppunit_LIBRARIES}
)
if (OPENDHT_PROXY_OPENSSL)
if (WIN32 AND MINGW) # MSYS2
target_link_libraries(opendht_unit_tests PRIVATE ${OPENSSL_LIBRARIES})
elseif(NOT MSVC) # Clang on UNIX-pkgconfig
target_link_libraries(opendht_unit_tests PRIVATE PkgConfig::OPENSSL)
endif()
endif()
add_test(TEST opendht_unit_tests)
endif()
+5 -2
View File
@@ -20,14 +20,17 @@
"generator": "Ninja",
"inherits": "default",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_BUILD_TYPE": "Debug",
"OPENDHT_PROXY_CLIENT": true,
"OPENDHT_PROXY_SERVER": true,
"OPENDHT_C": true
}
},
{
"name": "msvc",
"generator": "Visual Studio 17 2022",
"inherits": "default",
"binaryDir": "${sourceDir}/build-vs",
"cacheVariables": {
"BUILD_TESTING": true,
"VCPKG_MANIFEST_FEATURES": "test",
+9
View File
@@ -268,6 +268,11 @@ dht_publickey* dht_certificate_get_publickey(const dht_certificate* c) {
return reinterpret_cast<dht_publickey*>(new PubkeySp(cert->getSharedPublicKey()));
}
#ifdef __cplusplus
} // extern "C"
// Function with internal C++ linkage
#endif
// dht::crypto::Identity
inline dht::crypto::Identity dht_identity_from_c(const dht_identity* cid) {
dht::crypto::Identity id {};
@@ -285,6 +290,10 @@ inline dht_identity dht_identity_to_c(const dht::crypto::Identity& id) {
return cid;
}
#ifdef __cplusplus
extern "C" {
#endif
OPENDHT_C_PUBLIC dht_identity dht_identity_generate(const char* common_name, const dht_identity* ca) {
return dht_identity_to_c(dht::crypto::generateIdentity(common_name, dht_identity_from_c(ca)));
}
+3 -3
View File
@@ -135,7 +135,7 @@ typedef struct dht_op_token dht_op_token;
OPENDHT_C_PUBLIC void dht_op_token_delete(dht_op_token* token);
// config
struct OPENDHT_PUBLIC dht_node_config {
struct OPENDHT_C_PUBLIC dht_node_config {
dht_infohash node_id;
uint32_t network;
bool is_bootstrap;
@@ -144,13 +144,13 @@ struct OPENDHT_PUBLIC dht_node_config {
};
typedef struct dht_node_config dht_node_config;
struct OPENDHT_PUBLIC dht_secure_config {
struct OPENDHT_C_PUBLIC dht_secure_config {
dht_node_config node_config;
dht_identity id;
};
typedef struct dht_secure_config dht_secure_config;
struct OPENDHT_PUBLIC dht_runner_config {
struct OPENDHT_C_PUBLIC dht_runner_config {
dht_secure_config dht_config;
bool threaded;
const char* proxy_server;
+19 -14
View File
@@ -56,21 +56,25 @@ dnl Check for Doxygen
AC_ARG_ENABLE([doc], AS_HELP_STRING([--enable-doc], [Enable documentation generation (doxygen)]))
AS_IF([test "x$enable_doc" = "xyes"], [
AC_CHECK_PROGS([DOXYGEN], [doxygen])
AS_IF([test -z "$DOXYGEN"], [AC_MSG_WARN([Doxygen not found - continuing without Doxygen support])])
AS_IF([test -z "$DOXYGEN"],
[AC_MSG_ERROR([Doxygen is required to generate the documentation.])])
])
AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])
dnl Check for Python
AC_ARG_ENABLE([python], [AS_HELP_STRING([--disable-python], [Disble python binding])])
AS_IF([test "x$enable_python" != "xno"], [
AM_PATH_PYTHON([3.3],, [:])
AS_IF([test -n "$PYTHON"],[
echo 'import Cython' | $PYTHON
AS_IF([test $? == 0],[CYTHON=yes],[AC_MSG_WARN([Cython not found - continuing without python support])])
AC_CHECK_PROGS([PIP], [pip3])
AS_IF([test -z "$PIP"],[AC_MSG_WARN([pip not found - continuing without python uninstall support])])
])
])
AC_ARG_ENABLE([python], [AS_HELP_STRING([--disable-python], [Disable python binding])])
AS_IF([test "x$enable_python" = "xyes"], [
AM_COND_IF([ENABLE_INDEXATION], [
AM_PATH_PYTHON([3.3],, [:])
AS_IF([test -n "$PYTHON"],[
echo 'import Cython' | $PYTHON
AS_IF([test $? == 0],
[CYTHON=yes],
[AC_MSG_ERROR([Cython not found, but required for Python support.])])
AC_CHECK_PROGS([PIP], [pip3])
AS_IF([test -z "$PIP"],
[AC_MSG_WARN([pip not found - continuing without python uninstall support])])])
], [AC_MSG_ERROR([Python support requires DHT indexation to be turned on.])])])
AM_CONDITIONAL([USE_CYTHON], [test -n "$CYTHON"])
AM_CONDITIONAL([HAVE_PIP], [test -n "$PIP"])
@@ -83,6 +87,7 @@ case "${host_os}" in
;;
linux*)
SYS=linux
CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200809L"
;;
darwin*)
SYS=darwin
@@ -154,7 +159,7 @@ AS_IF([test "x$have_jsoncpp" = "xyes"], [
AM_COND_IF(PROXY_CLIENT_OR_SERVER, AC_MSG_ERROR(["JsonCpp is required for proxy/push notification support"]))
])
AC_ARG_WITH([openssl], AS_HELP_STRING([--without-openssl], [Build with OpenSSL support]))
AC_ARG_WITH([openssl], AS_HELP_STRING([--without-openssl], [Build without OpenSSL support]))
AS_IF([test "x$with_openssl" != "xno"],
[PKG_CHECK_MODULES([OpenSSL], [openssl >= 1.1], [have_openssl=yes], [have_openssl=no])],
[have_openssl=no])
@@ -187,8 +192,8 @@ CXXFLAGS="${CXXFLAGS} -DMSGPACK_NO_BOOST -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_
AC_ARG_ENABLE([tools], AS_HELP_STRING([--disable-tools],[Disable tools (CLI DHT node)]),,build_tools=yes)
AM_CONDITIONAL(ENABLE_TOOLS, test x$build_tools == xyes)
AM_COND_IF([ENABLE_TOOLS], [
AC_CHECK_HEADERS([readline/readline.h readline/history.h], [], [
AC_MSG_ERROR([unable to find readline.h])
AC_CHECK_HEADERS([readline/readline.h readline/history.h], [],
[AC_MSG_ERROR([Unable to find readline.h. Readline is required for the tools.])
])
])
+1 -1
View File
@@ -12,5 +12,5 @@ if (OPENDHT_DOCUMENTATION)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc/opendht)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION ${CMAKE_INSTALL_DOCDIR}/opendht)
endif()
+3 -35
View File
@@ -124,7 +124,7 @@ public:
}
};
struct ServerStats {
struct OPENDHT_PUBLIC ServerStats {
/** Current number of listen operations */
size_t listenCount {0};
/** Current number of permanent put operations (hash used) */
@@ -149,44 +149,12 @@ public:
/** Node Info **/
std::shared_ptr<NodeInfo> nodeInfo {};
std::string toString() const {
auto ret = fmt::format("Listens: {}, Puts: {}, PushListeners: {}\n"
"Push requests in the last {}: [Android: {}], [iOS: {}], [Unified: {}]\n"
"Requests: {} per second.",
listenCount, putCount, pushListenersCount,
print_duration(lastUpdated - serverStartTime),
androidPush.toString(), iosPush.toString(), unifiedPush.toString(),
requestRate);
if (nodeInfo) {
auto& ipv4 = nodeInfo->ipv4;
if (ipv4.table_depth > 1)
ret += fmt::format("IPv4 Network estimation: {}\n", ipv4.getNetworkSizeEstimation());
auto& ipv6 = nodeInfo->ipv6;
if (ipv6.table_depth > 1)
ret += fmt::format("IPv6 Network estimation: {}\n", ipv6.getNetworkSizeEstimation());
}
return ret;
}
std::string toString() const;
/**
* Build a json object from a NodeStats
*/
Json::Value toJson() const {
Json::Value result;
result["listenCount"] = static_cast<Json::UInt64>(listenCount);
result["putCount"] = static_cast<Json::UInt64>(putCount);
result["totalPermanentPuts"] = static_cast<Json::UInt64>(totalPermanentPuts);
result["pushListenersCount"] = static_cast<Json::UInt64>(pushListenersCount);
result["serverStartTime"] = static_cast<Json::LargestInt>(to_time_t(serverStartTime));
result["lastUpdated"] = static_cast<Json::LargestInt>(to_time_t(lastUpdated));
result["androidPush"] = androidPush.toJson();
result["iosPush"] = iosPush.toJson();
result["unifiedPush"] = unifiedPush.toJson();
result["requestRate"] = requestRate;
if (nodeInfo)
result["nodeInfo"] = nodeInfo->toJson();
return result;
}
Json::Value toJson() const;
};
std::shared_ptr<ServerStats> stats() const { return stats_; }
-2
View File
@@ -51,6 +51,4 @@
typedef int mode_t;
#include <BaseTsd.h>
#define usleep(x) Sleep((x) / 1000)
#endif
+41
View File
@@ -100,6 +100,47 @@ private:
std::shared_ptr<Logger> m_logger;
};
std::string
DhtProxyServer::ServerStats::toString() const
{
auto ret = fmt::format("Listens: {}, Puts: {}, PushListeners: {}\n"
"Push requests in the last {}: [Android: {}], [iOS: {}], [Unified: {}]\n"
"Requests: {} per second.",
listenCount, putCount, pushListenersCount,
print_duration(lastUpdated - serverStartTime),
androidPush.toString(), iosPush.toString(), unifiedPush.toString(),
requestRate);
if (nodeInfo) {
auto& ipv4 = nodeInfo->ipv4;
if (ipv4.table_depth > 1)
ret += fmt::format("IPv4 Network estimation: {}\n", ipv4.getNetworkSizeEstimation());
auto& ipv6 = nodeInfo->ipv6;
if (ipv6.table_depth > 1)
ret += fmt::format("IPv6 Network estimation: {}\n", ipv6.getNetworkSizeEstimation());
}
return ret;
}
Json::Value
DhtProxyServer::ServerStats::toJson() const
{
Json::Value result;
result["listenCount"] = static_cast<Json::UInt64>(listenCount);
result["putCount"] = static_cast<Json::UInt64>(putCount);
result["totalPermanentPuts"] = static_cast<Json::UInt64>(totalPermanentPuts);
result["pushListenersCount"] = static_cast<Json::UInt64>(pushListenersCount);
result["serverStartTime"] = static_cast<Json::LargestInt>(to_time_t(serverStartTime));
result["lastUpdated"] = static_cast<Json::LargestInt>(to_time_t(lastUpdated));
result["androidPush"] = androidPush.toJson();
result["iosPush"] = iosPush.toJson();
result["unifiedPush"] = unifiedPush.toJson();
result["requestRate"] = requestRate;
if (nodeInfo)
result["nodeInfo"] = nodeInfo->toJson();
return result;
}
restinio::request_handling_status_t
DhtProxyServer::serverError(restinio::request_t& request) {
auto response = initHttpResponse(request.create_response(restinio::status_internal_server_error()));
+7
View File
@@ -20,6 +20,13 @@
#include "config.h"
#endif
#if defined(_WIN32) && (_WIN32_WINNT < 0x0502) && (NTDDI_VERSION >= NTDDI_VISTA)
#define _WIN32_WINNT _WIN32_WINNT_WIN10
#include <winsock2.h>
#include <ws2tcpip.h>
#include <io.h>
#endif // inet_pton() workaround for MSVC in Windows 10/11
#include "utils.h"
#include "sockaddr.h"
#include "default_types.h"
+1 -1
View File
@@ -73,7 +73,7 @@ std::ostream& operator<< (std::ostream& s, const Value& v)
s << "data(" << v.user_type << "):";
if (v.user_type == "text/plain") {
s << '"';
s.write((const char*)v.data.data(), v.data.size());
s.write(reinterpret_cast<const char*>(v.data.data()), v.data.size());
s << '"';
} else if (v.data.size() < 1024) {
s << toHex(v.data.data(), v.data.size());
+1 -1
View File
@@ -328,7 +328,7 @@ DhtRunnerTester::testIdOps() {
cv.notify_all();
});
node1.putEncrypted(key, node2.getPublicKey(), dht::Value("yo"), [&](bool ok){
node1.putEncrypted(key, node2.getPublicKey(), std::make_shared<dht::Value>("yo"), [&](bool ok){
CPPUNIT_ASSERT(ok);
std::lock_guard<std::mutex> lk(mutex);
valueCount++;
+3 -9
View File
@@ -9,14 +9,10 @@ function (configure_tool name extra_files)
add_dependencies(${name} opendht)
if (MSVC)
target_sources(${name} PRIVATE ${MSC_COMPAT_SOURCES})
target_link_libraries (${name} PUBLIC opendht wsock32 ws2_32)
if(NOT BUILD_SHARED_LIBS)
set_target_properties(${name} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
target_link_libraries (${name} PUBLIC opendht)
target_include_directories (${name} PRIVATE SYSTEM ${MSC_COMPAT_DIR} ${MSVC_COMPAT_DIR})
else()
target_link_libraries (${name} LINK_PUBLIC opendht ${readline_LIBRARIES})
target_link_libraries (${name} LINK_PUBLIC opendht ${READLINE_LIBRARIES})
target_include_directories (${name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
endif ()
endfunction ()
@@ -34,17 +30,15 @@ endif ()
if (OPENDHT_C)
add_executable (dhtcnode dhtcnode.c)
add_dependencies(dhtcnode opendht-c)
target_link_libraries (dhtcnode PUBLIC opendht-c ${readline_LIBRARIES})
target_link_libraries (dhtcnode PUBLIC opendht-c)
target_include_directories (dhtcnode SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/c)
if (WIN32)
target_link_libraries (dhtcnode PUBLIC ws2_32)
endif()
if (MSVC)
target_sources(dhtcnode PRIVATE ${MSC_COMPAT_SOURCES})
target_link_libraries(dhtcnode PRIVATE unofficial::readline-win32::readline)
target_include_directories (dhtcnode SYSTEM PRIVATE ${MSC_COMPAT_DIR} ${MSVC_COMPAT_DIR})
if(NOT BUILD_SHARED_LIBS)
set_target_properties(dhtcnode PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()
endif ()
+8 -1
View File
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <stdatomic.h>
#include <inttypes.h>
#include <time.h>
#ifdef _MSC_VER
#include "wingetopt.h"
@@ -33,6 +34,7 @@
#include <readline/readline.h>
#include <readline/history.h>
#ifdef _WIN32
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#else
@@ -296,7 +298,12 @@ int main(int argc, char **argv)
// Wait until shutdown callback is called
while (!atomic_load(&ctx.stop)) {
usleep(10000);
#ifdef _WIN32
Sleep(10); // 10ms
#else
struct timespec ts = {0, 10000000}; // 10ms
nanosleep(&ts, NULL);
#endif
}
dht_runner_delete(runner);
return EXIT_SUCCESS;