From 5d75a8444017f7d03963e32589129aa7a06c1c0a Mon Sep 17 00:00:00 2001 From: Amin Bandali Date: Sun, 24 Sep 2023 20:01:05 -0400 Subject: [PATCH] Import opendht_3.0.0.orig.tar.gz [dgit import orig opendht_3.0.0.orig.tar.gz] --- .clang-tidy | 1 + .devcontainer/devcontainer.json | 12 + .github/workflows/ccpp.yml | 92 + .github/workflows/clang-analyzer.yml | 35 + .github/workflows/codeql-analysis.yml | 53 + .github/workflows/release-package.yml | 293 ++ .gitignore | 80 + .vscode/launch.json | 54 + .vscode/tasks.json | 46 + CMakeLists.txt | 473 ++++ COPYING | 674 +++++ Makefile.am | 35 + README.md | 120 + autogen.sh | 1 + c/Makefile.am | 15 + c/opendht.cpp | 517 ++++ c/opendht_c.h | 188 ++ cmake/CheckAtomic.cmake | 103 + cmake/DetermineGCCCompatible.cmake | 13 + cmake/FindReadline.cmake | 48 + cmake/FindRestinio.cmake | 14 + configure.ac | 216 ++ doc/CMakeLists.txt | 16 + doc/Doxyfile.in | 983 +++++++ doc/Makefile.am | 16 + doc/connectivity-loss-by-search-criteria.pdf | Bin 0 -> 126785 bytes doc/connectivity-loss-by-search-criteria.tex | 142 + doc/dhtnode.1 | 110 + docker/Dockerfile | 18 + docker/DockerfileAlpine | 37 + docker/DockerfileBionic | 17 + docker/DockerfileDeps | 28 + docker/DockerfileDepsAlpine | 23 + docker/DockerfileDepsBionic | 32 + docker/DockerfileDepsFocal | 28 + docker/DockerfileDepsLlvm | 32 + docker/DockerfileDhtnode | 4 + docker/DockerfileFocal | 17 + docker/DockerfileLlvm | 18 + include/opendht.h | 22 + include/opendht/callbacks.h | 196 ++ include/opendht/crypto.h | 815 ++++++ include/opendht/def.h | 44 + include/opendht/default_types.h | 273 ++ include/opendht/dht.h | 632 +++++ include/opendht/dht_interface.h | 272 ++ include/opendht/dht_proxy_client.h | 458 +++ include/opendht/dht_proxy_server.h | 470 +++ include/opendht/dhtrunner.h | 533 ++++ include/opendht/http.h | 394 +++ include/opendht/indexation/pht.h | 533 ++++ include/opendht/infohash.h | 404 +++ include/opendht/log.h | 59 + include/opendht/logger.h | 118 + include/opendht/network_engine.h | 602 ++++ include/opendht/network_utils.h | 161 ++ include/opendht/node.h | 174 ++ include/opendht/node_cache.h | 71 + include/opendht/node_export.h | 48 + include/opendht/peer_discovery.h | 95 + include/opendht/proxy.h | 31 + include/opendht/rate_limiter.h | 56 + include/opendht/rng.h | 130 + include/opendht/routing_table.h | 102 + include/opendht/scheduler.h | 132 + include/opendht/securedht.h | 396 +++ include/opendht/sockaddr.h | 325 +++ include/opendht/thread_pool.h | 169 ++ include/opendht/utils.h | 185 ++ include/opendht/value.h | 1065 +++++++ m4/ax_cxx_compile_stdcxx.m4 | 1005 +++++++ meson.build | 99 + meson_options.txt | 4 + opendht-c.pc.in | 10 + opendht.pc.in | 12 + python/CMakeLists.txt | 19 + python/Makefile.am | 30 + python/opendht.pyx | 693 +++++ python/opendht_cpp.pxd | 286 ++ python/pyproject.toml | 3 + python/setup.py.in | 55 + python/tests/opendht_tests.py | 53 + python/tools/README.md | 45 + python/tools/benchmark.py | 240 ++ python/tools/dht/__init__.py | 0 python/tools/dht/network.py | 594 ++++ python/tools/dht/tests.py | 995 +++++++ python/tools/dht/virtual_network_builder.py | 267 ++ python/tools/dhtcluster.py | 270 ++ python/tools/http_server.py | 78 + python/tools/network_monitor.py | 83 + python/tools/pingpong.py | 78 + python/tools/scanner.py | 301 ++ resources/opendht_logo.svg | 105 + resources/opendht_logo_512.png | Bin 0 -> 23071 bytes rust/.gitignore | 2 + rust/Cargo.toml | 11 + rust/README.md | 21 + rust/examples/dhtnode.rs | 73 + rust/src/blob.rs | 37 + rust/src/crypto.rs | 194 ++ rust/src/dhtrunner.rs | 325 +++ rust/src/ffi.rs | 224 ++ rust/src/infohash.rs | 83 + rust/src/lib.rs | 34 + rust/src/pkid.rs | 34 + rust/src/value.rs | 107 + src/Makefile.am | 86 + src/base64.cpp | 143 + src/base64.h | 36 + src/callbacks.cpp | 164 ++ src/compat/msvc/unistd.h | 53 + src/compat/msvc/wingetopt.c | 971 +++++++ src/compat/msvc/wingetopt.h | 97 + src/compat/os_cert.cpp | 204 ++ src/compat/os_cert.h | 81 + src/crypto.cpp | 1774 ++++++++++++ src/default_types.cpp | 106 + src/dht.cpp | 2676 ++++++++++++++++++ src/dht_proxy_client.cpp | 1369 +++++++++ src/dht_proxy_server.cpp | 1476 ++++++++++ src/dhtrunner.cpp | 1192 ++++++++ src/http.cpp | 1516 ++++++++++ src/indexation/pht.cpp | 538 ++++ src/listener.h | 52 + src/log.cpp | 178 ++ src/net.h | 39 + src/network_engine.cpp | 1402 +++++++++ src/network_utils.cpp | 363 +++ src/node.cpp | 200 ++ src/node_cache.cpp | 160 ++ src/op_cache.cpp | 276 ++ src/op_cache.h | 204 ++ src/parsed_message.h | 387 +++ src/peer_discovery.cpp | 415 +++ src/request.h | 153 + src/rng.cpp | 117 + src/routing_table.cpp | 265 ++ src/search.h | 987 +++++++ src/securedht.cpp | 456 +++ src/storage.h | 320 +++ src/thread_pool.cpp | 209 ++ src/utils.cpp | 299 ++ src/value.cpp | 642 +++++ src/value_cache.h | 213 ++ tests/Makefile.am | 9 + tests/cryptotester.cpp | 180 ++ tests/cryptotester.h | 69 + tests/dhtproxytester.cpp | 335 +++ tests/dhtproxytester.h | 82 + tests/dhtrunnertester.cpp | 406 +++ tests/dhtrunnertester.h | 77 + tests/httptester.cpp | 292 ++ tests/httptester.h | 95 + tests/infohashtester.cpp | 151 + tests/infohashtester.h | 74 + tests/peerdiscoverytester.cpp | 114 + tests/peerdiscoverytester.h | 50 + tests/tests_runner.cpp | 35 + tests/threadpooltester.cpp | 108 + tests/threadpooltester.h | 50 + tests/valuetester.cpp | 83 + tests/valuetester.h | 53 + tools/CMakeLists.txt | 75 + tools/Makefile.am | 20 + tools/dhtchat.cpp | 151 + tools/dhtcnode.c | 285 ++ tools/dhtnode.cpp | 607 ++++ tools/dhtproxy_stats.py | 54 + tools/dhtscanner.cpp | 130 + tools/durl.cpp | 124 + tools/perftest.cpp | 180 ++ tools/proxy_loadtester.py | 82 + tools/proxy_node.html | 196 ++ tools/systemd/dhtcluster.conf | 1 + tools/systemd/dhtcluster.service.in | 20 + tools/systemd/dhtnode.conf | 1 + tools/systemd/dhtnode.service.in | 44 + tools/tools_common.h | 472 +++ 179 files changed, 44563 insertions(+) create mode 100644 .clang-tidy create mode 100644 .devcontainer/devcontainer.json create mode 100644 .github/workflows/ccpp.yml create mode 100644 .github/workflows/clang-analyzer.yml create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/release-package.yml create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 CMakeLists.txt create mode 100644 COPYING create mode 100644 Makefile.am create mode 100644 README.md create mode 100755 autogen.sh create mode 100644 c/Makefile.am create mode 100644 c/opendht.cpp create mode 100644 c/opendht_c.h create mode 100644 cmake/CheckAtomic.cmake create mode 100644 cmake/DetermineGCCCompatible.cmake create mode 100644 cmake/FindReadline.cmake create mode 100644 cmake/FindRestinio.cmake create mode 100644 configure.ac create mode 100644 doc/CMakeLists.txt create mode 100644 doc/Doxyfile.in create mode 100644 doc/Makefile.am create mode 100644 doc/connectivity-loss-by-search-criteria.pdf create mode 100644 doc/connectivity-loss-by-search-criteria.tex create mode 100644 doc/dhtnode.1 create mode 100644 docker/Dockerfile create mode 100644 docker/DockerfileAlpine create mode 100644 docker/DockerfileBionic create mode 100644 docker/DockerfileDeps create mode 100644 docker/DockerfileDepsAlpine create mode 100644 docker/DockerfileDepsBionic create mode 100644 docker/DockerfileDepsFocal create mode 100644 docker/DockerfileDepsLlvm create mode 100644 docker/DockerfileDhtnode create mode 100644 docker/DockerfileFocal create mode 100644 docker/DockerfileLlvm create mode 100644 include/opendht.h create mode 100644 include/opendht/callbacks.h create mode 100644 include/opendht/crypto.h create mode 100644 include/opendht/def.h create mode 100644 include/opendht/default_types.h create mode 100644 include/opendht/dht.h create mode 100644 include/opendht/dht_interface.h create mode 100644 include/opendht/dht_proxy_client.h create mode 100644 include/opendht/dht_proxy_server.h create mode 100644 include/opendht/dhtrunner.h create mode 100644 include/opendht/http.h create mode 100644 include/opendht/indexation/pht.h create mode 100644 include/opendht/infohash.h create mode 100644 include/opendht/log.h create mode 100644 include/opendht/logger.h create mode 100644 include/opendht/network_engine.h create mode 100644 include/opendht/network_utils.h create mode 100644 include/opendht/node.h create mode 100644 include/opendht/node_cache.h create mode 100644 include/opendht/node_export.h create mode 100644 include/opendht/peer_discovery.h create mode 100644 include/opendht/proxy.h create mode 100644 include/opendht/rate_limiter.h create mode 100644 include/opendht/rng.h create mode 100644 include/opendht/routing_table.h create mode 100644 include/opendht/scheduler.h create mode 100644 include/opendht/securedht.h create mode 100644 include/opendht/sockaddr.h create mode 100644 include/opendht/thread_pool.h create mode 100644 include/opendht/utils.h create mode 100644 include/opendht/value.h create mode 100644 m4/ax_cxx_compile_stdcxx.m4 create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 opendht-c.pc.in create mode 100644 opendht.pc.in create mode 100644 python/CMakeLists.txt create mode 100644 python/Makefile.am create mode 100644 python/opendht.pyx create mode 100644 python/opendht_cpp.pxd create mode 100644 python/pyproject.toml create mode 100644 python/setup.py.in create mode 100644 python/tests/opendht_tests.py create mode 100644 python/tools/README.md create mode 100755 python/tools/benchmark.py create mode 100644 python/tools/dht/__init__.py create mode 100755 python/tools/dht/network.py create mode 100644 python/tools/dht/tests.py create mode 100755 python/tools/dht/virtual_network_builder.py create mode 100755 python/tools/dhtcluster.py create mode 100755 python/tools/http_server.py create mode 100755 python/tools/network_monitor.py create mode 100755 python/tools/pingpong.py create mode 100755 python/tools/scanner.py create mode 100644 resources/opendht_logo.svg create mode 100644 resources/opendht_logo_512.png create mode 100644 rust/.gitignore create mode 100644 rust/Cargo.toml create mode 100644 rust/README.md create mode 100644 rust/examples/dhtnode.rs create mode 100644 rust/src/blob.rs create mode 100644 rust/src/crypto.rs create mode 100644 rust/src/dhtrunner.rs create mode 100644 rust/src/ffi.rs create mode 100644 rust/src/infohash.rs create mode 100644 rust/src/lib.rs create mode 100644 rust/src/pkid.rs create mode 100644 rust/src/value.rs create mode 100644 src/Makefile.am create mode 100644 src/base64.cpp create mode 100644 src/base64.h create mode 100644 src/callbacks.cpp create mode 100644 src/compat/msvc/unistd.h create mode 100644 src/compat/msvc/wingetopt.c create mode 100644 src/compat/msvc/wingetopt.h create mode 100644 src/compat/os_cert.cpp create mode 100644 src/compat/os_cert.h create mode 100644 src/crypto.cpp create mode 100644 src/default_types.cpp create mode 100644 src/dht.cpp create mode 100644 src/dht_proxy_client.cpp create mode 100644 src/dht_proxy_server.cpp create mode 100644 src/dhtrunner.cpp create mode 100644 src/http.cpp create mode 100644 src/indexation/pht.cpp create mode 100644 src/listener.h create mode 100644 src/log.cpp create mode 100644 src/net.h create mode 100644 src/network_engine.cpp create mode 100644 src/network_utils.cpp create mode 100644 src/node.cpp create mode 100644 src/node_cache.cpp create mode 100644 src/op_cache.cpp create mode 100644 src/op_cache.h create mode 100644 src/parsed_message.h create mode 100644 src/peer_discovery.cpp create mode 100644 src/request.h create mode 100644 src/rng.cpp create mode 100644 src/routing_table.cpp create mode 100644 src/search.h create mode 100644 src/securedht.cpp create mode 100644 src/storage.h create mode 100644 src/thread_pool.cpp create mode 100644 src/utils.cpp create mode 100644 src/value.cpp create mode 100644 src/value_cache.h create mode 100644 tests/Makefile.am create mode 100644 tests/cryptotester.cpp create mode 100644 tests/cryptotester.h create mode 100644 tests/dhtproxytester.cpp create mode 100644 tests/dhtproxytester.h create mode 100644 tests/dhtrunnertester.cpp create mode 100644 tests/dhtrunnertester.h create mode 100644 tests/httptester.cpp create mode 100644 tests/httptester.h create mode 100644 tests/infohashtester.cpp create mode 100644 tests/infohashtester.h create mode 100644 tests/peerdiscoverytester.cpp create mode 100644 tests/peerdiscoverytester.h create mode 100644 tests/tests_runner.cpp create mode 100644 tests/threadpooltester.cpp create mode 100644 tests/threadpooltester.h create mode 100644 tests/valuetester.cpp create mode 100644 tests/valuetester.h create mode 100644 tools/CMakeLists.txt create mode 100644 tools/Makefile.am create mode 100644 tools/dhtchat.cpp create mode 100644 tools/dhtcnode.c create mode 100644 tools/dhtnode.cpp create mode 100644 tools/dhtproxy_stats.py create mode 100644 tools/dhtscanner.cpp create mode 100644 tools/durl.cpp create mode 100644 tools/perftest.cpp create mode 100644 tools/proxy_loadtester.py create mode 100644 tools/proxy_node.html create mode 100644 tools/systemd/dhtcluster.conf create mode 100644 tools/systemd/dhtcluster.service.in create mode 100644 tools/systemd/dhtnode.conf create mode 100644 tools/systemd/dhtnode.service.in create mode 100644 tools/tools_common.h diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..26374af --- /dev/null +++ b/.clang-tidy @@ -0,0 +1 @@ +Checks: '-*,clang-diagnostic-*,performance-*,bugprone-*,llvm-*,clang-analyzer-*,misc-*,-llvm-namespace-comment,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-llvm-header-guard,-llvm-include-order,-bugprone-suspicious-string-compare' diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..9157472 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,12 @@ +{ + "name": "C++", + "build": { + "dockerfile": "../docker/DockerfileDepsLlvm", + }, + "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"], + "settings": {}, + "extensions": [ + "ms-vscode.cpptools" + ], + "forwardPorts": [4222], +} diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml new file mode 100644 index 0000000..00a4ed0 --- /dev/null +++ b/.github/workflows/ccpp.yml @@ -0,0 +1,92 @@ +name: C/C++ CI + +on: [push, pull_request] + +jobs: + build-ubuntu: + name: Ubuntu/GCC Autotools build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Dependencies + run: | + sudo apt install libncurses5-dev libreadline-dev nettle-dev libasio-dev \ + libgnutls28-dev libuv1-dev cython3 python3-dev python3-setuptools libcppunit-dev libjsoncpp-dev \ + autotools-dev autoconf libfmt-dev libhttp-parser-dev libmsgpack-dev libargon2-0-dev + - name: Configure + run: | + ./autogen.sh + ./configure + - name: Build + run: make + + build-ubuntu-meson: + name: Ubuntu/GCC Meson build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Dependencies + run: | + sudo apt install meson ninja-build libncurses5-dev libreadline-dev nettle-dev libasio-dev \ + libgnutls28-dev libuv1-dev cython3 python3-dev python3-setuptools libcppunit-dev libjsoncpp-dev \ + libfmt-dev libhttp-parser-dev libmsgpack-dev libargon2-0-dev + - name: Configure + run: meson setup build . + - name: Build + run: cd build && ninja + + build-ubuntu-minimal: + name: Ubuntu/GCC minimal build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Dependencies + run: | + sudo apt install libncurses5-dev libreadline-dev nettle-dev libfmt-dev \ + libgnutls28-dev libcppunit-dev libmsgpack-dev libargon2-0-dev + - name: Configure + run: | + mkdir build && cd build + cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Debug \ + -DOPENDHT_C=Off -DOPENDHT_TESTS=On -DOPENDHT_PEER_DISCOVERY=Off -DOPENDHT_PYTHON=Off \ + -DOPENDHT_TOOLS=On -DOPENDHT_PROXY_SERVER=Off -DOPENDHT_PROXY_CLIENT=Off + - name: Build + run: cd build && make + - name: Unit tests + run: cd build && ./opendht_unit_tests + + build-macos: + name: macOS/Clang build + runs-on: macos-11 + steps: + - uses: actions/checkout@v3 + - name: Dependencies + run: | + brew install msgpack-cxx asio gnutls nettle readline fmt jsoncpp argon2 openssl http-parser cppunit + + - name: restinio + run: | + mkdir restinio && cd restinio + wget https://github.com/aberaud/restinio/archive/6fd08b65f6f15899dd0de3c801f6a5462b811c64.tar.gz + ls -l && tar -xzf 6fd08b65f6f15899dd0de3c801f6a5462b811c64.tar.gz + cd restinio-6fd08b65f6f15899dd0de3c801f6a5462b811c64/dev + cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DRESTINIO_TEST=OFF -DRESTINIO_SAMPLE=OFF \ + -DRESTINIO_INSTALL_SAMPLES=OFF -DRESTINIO_BENCH=OFF -DRESTINIO_INSTALL_BENCHES=OFF \ + -DRESTINIO_FIND_DEPS=ON -DRESTINIO_ALLOW_SOBJECTIZER=Off -DRESTINIO_USE_BOOST_ASIO=none . + make -j8 && sudo make install + cd ../../.. && rm -rf restinio + + - name: Configure + run: | + mkdir build && cd build + export PATH="/opt/homebrew/opt/openssl@3/bin:$PATH" + export LDFLAGS="-L/usr/local/opt/openssl@3/lib" + export CPPFLAGS="-I/usr/local/opt/openssl@3/include" + export PKG_CONFIG_PATH="/usr/local/opt/openssl@3/lib/pkgconfig" + cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Debug \ + -DOPENDHT_C=On -DOPENDHT_TESTS=On -DOPENDHT_PEER_DISCOVERY=On -DOPENDHT_PYTHON=Off \ + -DOPENDHT_TOOLS=On -DOPENDHT_PROXY_SERVER=On -DOPENDHT_PROXY_CLIENT=On -DOPENDHT_PUSH_NOTIFICATIONS=On + + - name: Build + run: cd build && make + diff --git a/.github/workflows/clang-analyzer.yml b/.github/workflows/clang-analyzer.yml new file mode 100644 index 0000000..9b3c6be --- /dev/null +++ b/.github/workflows/clang-analyzer.yml @@ -0,0 +1,35 @@ +name: Clang Static Analysis +on: [push, pull_request] + +jobs: + clang-analyzer: + name: Clang Static Analysis + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: deps + run: | + sudo apt install libncurses5-dev libreadline-dev nettle-dev \ + libgnutls28-dev libuv1-dev cython3 python3-dev python3-setuptools libcppunit-dev libjsoncpp-dev \ + autotools-dev autoconf libfmt-dev libhttp-parser-dev libmsgpack-dev libargon2-0-dev libasio-dev \ + llvm llvm-dev clang clang-tools && \ + sudo apt remove gcc g++ + + - name: restinio + run: | + mkdir restinio && cd restinio \ + && wget https://github.com/aberaud/restinio/archive/6fd08b65f6f15899dd0de3c801f6a5462b811c64.tar.gz \ + && ls -l && tar -xzf 6fd08b65f6f15899dd0de3c801f6a5462b811c64.tar.gz \ + && cd restinio-6fd08b65f6f15899dd0de3c801f6a5462b811c64/dev \ + && cmake -DCMAKE_INSTALL_PREFIX=/usr -DRESTINIO_TEST=OFF -DRESTINIO_SAMPLE=OFF \ + -DRESTINIO_INSTALL_SAMPLES=OFF -DRESTINIO_BENCH=OFF -DRESTINIO_INSTALL_BENCHES=OFF \ + -DRESTINIO_FIND_DEPS=ON -DRESTINIO_ALLOW_SOBJECTIZER=Off -DRESTINIO_USE_BOOST_ASIO=none . \ + && make -j8 && sudo make install \ + && cd ../../.. && rm -rf restinio + + - name: cmake + run: | + mkdir build && cd build && \ + cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DOPENDHT_C=On -DOPENDHT_PEER_DISCOVERY=On -DOPENDHT_PYTHON=Off -DOPENDHT_TOOLS=On -DOPENDHT_PROXY_SERVER=On -DOPENDHT_PROXY_CLIENT=On -DOPENDHT_PUSH_NOTIFICATIONS=On + - name: scan-build + run: cd build && scan-build --status-bugs make diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..1f99710 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,53 @@ +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "master" ] + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + container: + image: ghcr.io/savoirfairelinux/opendht/opendht-deps:latest + + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'cpp' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/release-package.yml b/.github/workflows/release-package.yml new file mode 100644 index 0000000..5a59478 --- /dev/null +++ b/.github/workflows/release-package.yml @@ -0,0 +1,293 @@ +name: Release actions + +on: + push: + tags: + - 'v*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME_DEPS: ${{ github.repository }}/opendht-deps + IMAGE_NAME: ${{ github.repository }}/opendht + IMAGE_NAME_DEPS_LLVM: ${{ github.repository }}/opendht-deps-llvm + IMAGE_NAME_LLVM: ${{ github.repository }}/opendht-llvm + IMAGE_NAME_DHTNODE: ${{ github.repository }}/dhtnode + IMAGE_NAME_ALPINE: ${{ github.repository }}/opendht-alpine + IMAGE_NAME_ALPINE_DEPS: ${{ github.repository }}/opendht-deps-alpine + +jobs: + build-and-push-deps-image: + name: Dependency Docker image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_DEPS }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + file: docker/DockerfileDeps + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + build-and-push-image: + name: OpenDHT Docker image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + file: docker/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + build-and-push-deps-image-llvm: + name: Dependency Docker image (LLVM) + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_DEPS_LLVM }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + file: docker/DockerfileDepsLlvm + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + build-and-push-image-llvm: + name: OpenDHT Docker image (LLVM) + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LLVM }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + file: docker/DockerfileLlvm + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + build-and-push-image-dhtnode: + name: dhtnode Docker image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_DHTNODE }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + file: docker/DockerfileDhtnode + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + build-and-push-image-alpine-deps: + name: Alpine Deps Docker image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_ALPINE_DEPS }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + file: docker/DockerfileDepsAlpine + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + build-and-push-image-alpine: + name: Alpine Docker image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_ALPINE }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + file: docker/DockerfileAlpine + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + build-python-wheel: + name: Release and build Python Wheel package + runs-on: ubuntu-latest + container: ghcr.io/savoirfairelinux/opendht/opendht-deps:latest + + permissions: + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: cmake + run: | + mkdir build && cd build && \ + cmake .. -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_BUILD_TYPE=Release \ + -DOPENDHT_STATIC=Off \ + -DOPENDHT_PYTHON=On \ + -DOPENDHT_C=Off \ + -DOPENDHT_PEER_DISCOVERY=On \ + -DOPENDHT_TOOLS=Off \ + -DOPENDHT_PROXY_SERVER=On \ + -DOPENDHT_PROXY_CLIENT=On + + - name: build + run: cd build && make dist + + - uses: actions/upload-artifact@v3 + with: + name: opendht-wheels-linux + path: build/python/dist/*.whl + + - name: Create Release + id: create_release + uses: softprops/action-gh-release@v1 + with: + draft: true + files: build/python/dist/*.whl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd367ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,80 @@ +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app +**/dhtnode +**/dhtchat +**/dhtscanner + +# Autotools +/ac +Makefile +Makefile.in +/aclocal.m4 +/autom4te.cache/ +/config.* +/configure +/depcomp +/install-sh +/libtool +/ltmain.sh +/m4/ +/missing +/stamp-h? +.deps/ +.dirstamp +.libs/ +*.l[ao] +*~ +*.pc + +# KDevelop +.kdev4/ +*.kdev4 + +# VSCode +.vscode/* + +# Eclipse CDT +.cproject +.project +.autotools +language.settings.xml + +# Python +*.pyc +*.stamp +python/opendht.cpp +python/setup.py + +# Doxygen +doc/Doxyfile + +# git backup files +*.orig + +# vim swap files +*.swp +*.swo + +# build dir +build +build_dev +.DS_Store diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..24364e7 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,54 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "dhtnode", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build_dev/tools/dhtnode", + "args": ["-v", "-p", "4222"], + "cwd": "${workspaceFolder}/build_dev", + "environment": [], + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "build", + "linux": { + "MIMode": "gdb", + "externalConsole": false, + }, + "osx": { + "MIMode": "lldb", + "externalConsole": true, + }, + }, + { + "name": "tests", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build_dev/opendht_unit_tests", + "cwd": "${workspaceFolder}/build_dev", + "environment": [], + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "build", + "linux": { + "MIMode": "gdb", + "externalConsole": false, + }, + "osx": { + "MIMode": "lldb", + "externalConsole": true, + }, + } + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..d9c292f --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,46 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "options": { + "cwd": "${workspaceRoot}/build_dev" + }, + "command": "make", + "args": ["-j4"], + "dependsOn": "cmake" + }, + { + "label": "cmake", + "type": "shell", + "options": { + "cwd": "${workspaceRoot}/build_dev" + }, + "command": "cmake", + "args": [ + "${workspaceRoot}", + "-DCMAKE_EXPORT_COMPILE_COMMANDS=On", + "-DCMAKE_BUILD_TYPE=Debug", + "-DOPENDHT_SANITIZE=On", + "-DOPENDHT_PROXY_CLIENT=On", + "-DOPENDHT_PROXY_SERVER=On", + "-DOPENDHT_TESTS=On", + "-DOPENDHT_C=On" + ], + "dependsOn": "builddir" + }, + { + "label": "builddir", + "type": "shell", + "options": { + "cwd": "${workspaceRoot}" + }, + "command": "mkdir", + "args": [ + "-p", + "${workspaceRoot}/build_dev" + ] + }, + ] +} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..13bb1b3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,473 @@ +cmake_minimum_required (VERSION 3.10..3.20) +if(POLICY CMP0073) + cmake_policy(SET CMP0073 NEW) +endif() +if(POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) +endif() +project (opendht) + +include(CMakePackageConfigHelpers) +include(CMakeDependentOption) +include(CheckIncludeFileCXX) +include(FindPkgConfig) +include(cmake/CheckAtomic.cmake) +include(CTest) + +set (opendht_VERSION_MAJOR 3) +set (opendht_VERSION_MINOR 0.0) +set (opendht_VERSION ${opendht_VERSION_MAJOR}.${opendht_VERSION_MINOR}) +set (PACKAGE_VERSION ${opendht_VERSION}) +set (VERSION "${opendht_VERSION}") + +# Options +option (BUILD_SHARED_LIBS "Build shared library" ON) +CMAKE_DEPENDENT_OPTION (OPENDHT_STATIC "Build static library" OFF BUILD_SHARED_LIBS ON) +option (OPENDHT_PYTHON "Build Python bindings" OFF) +option (OPENDHT_TOOLS "Build DHT tools" ON) +option (OPENDHT_SYSTEMD "Install systemd module" OFF) +option (OPENDHT_SYSTEMD_UNIT_FILE_LOCATION "Where to install systemd unit file") +option (OPENDHT_SANITIZE "Build with address sanitizer and stack protector" OFF) +option (OPENDHT_PROXY_SERVER "Enable DHT proxy server, use Restinio and jsoncpp" OFF) +option (OPENDHT_PUSH_NOTIFICATIONS "Enable push notifications support" OFF) +option (OPENDHT_PROXY_SERVER_IDENTITY "Allow clients to use the node identity" OFF) +option (OPENDHT_PROXY_CLIENT "Enable DHT proxy client, use Restinio and jsoncpp" OFF) +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_INDEX "Build DHT indexation feature" OFF) +option (OPENDHT_TESTS_NETWORK "Enable unit tests that require network access" ON) +option (OPENDHT_C "Build C bindings" OFF) + +find_package(Doxygen) +option (OPENDHT_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND}) + +# Build flags +set (CMAKE_CXX_STANDARD 17) +set (CMAKE_CXX_STANDARD_REQUIRED on) + +# Dependencies +if (NOT HAVE_CXX_ATOMICS_WITHOUT_LIB) + link_libraries (atomic) +endif () + +list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") +if (NOT MSVC) + 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) + 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) + endif () + + find_package(fmt) + + if (OPENDHT_HTTP) + find_package(Restinio REQUIRED) + find_library(HTTP_PARSER_LIBRARY http_parser) + add_library(http_parser SHARED IMPORTED) + set(http_parser_lib "-lhttp_parser") + if (NOT Jsoncpp_FOUND) + message(SEND_ERROR "Jsoncpp is required for DHT proxy support") + 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}") + set(openssl_lib ", openssl") + else () + message(SEND_ERROR "OpenSSL is required for DHT proxy as specified") + endif() + endif() + else () + set(OPENDHT_PROXY_OPENSSL OFF) + endif () +else () + 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) + 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}/http_parser + ) + endif () +endif () + +if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY) + add_definitions(-DASIO_STANDALONE) +endif() + +if (NOT MSVC) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type -Wno-deprecated -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") + endif () +else () + add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS + -D_CRT_SECURE_NO_WARNINGS + -DWIN32_LEAN_AND_MEAN + -DSTATIC_GETOPT + -DGNUTLS_INTERNAL_BUILD) + set(DISABLE_MSC_WARNINGS "/wd4101 /wd4244 /wd4267 /wd4273 /wd4804 /wd4834 /wd4996") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DISABLE_MSC_WARNINGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") +endif () +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMSGPACK_NO_BOOST -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT") + +add_definitions(-DPACKAGE_VERSION="${opendht_VERSION}") + +if (ASIO_INCLUDE_DIR) + include_directories (SYSTEM "${ASIO_INCLUDE_DIR}") +endif () +if (Restinio_INCLUDE_DIR) + include_directories (SYSTEM "${Restinio_INCLUDE_DIR}") +endif () +include_directories ( + ./ + include/ + include/opendht/ + ${CMAKE_CURRENT_BINARY_DIR}/include/ +) + +# Install dirs +include (GNUInstallDirs) +set (prefix ${CMAKE_INSTALL_PREFIX}) +set (exec_prefix "\${prefix}") +set (libdir "${CMAKE_INSTALL_FULL_LIBDIR}") +set (includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") +set (bindir "${CMAKE_INSTALL_FULL_BINDIR}") +set (sysconfdir "${CMAKE_INSTALL_FULL_SYSCONFDIR}") +set (top_srcdir "${CMAKE_CURRENT_SOURCE_DIR}") + +# Sources +list (APPEND opendht_SOURCES + src/utils.cpp + src/crypto.cpp + src/default_types.cpp + src/node.cpp + src/value.cpp + src/dht.cpp + src/op_cache.cpp + src/storage.h + src/listener.h + src/search.h + src/value_cache.h + src/op_cache.h + src/net.h + src/parsed_message.h + src/request.h + src/callbacks.cpp + src/routing_table.cpp + src/node_cache.cpp + src/network_engine.cpp + src/securedht.cpp + src/dhtrunner.cpp + src/log.cpp + src/network_utils.cpp + src/thread_pool.cpp +) + +list (APPEND opendht_HEADERS + include/opendht/def.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 + include/opendht/dht.h + include/opendht/dht_interface.h + include/opendht/callbacks.h + include/opendht/routing_table.h + include/opendht/node_cache.h + include/opendht/network_engine.h + include/opendht/scheduler.h + include/opendht/rate_limiter.h + include/opendht/securedht.h + include/opendht/log.h + include/opendht/logger.h + include/opendht/thread_pool.h + include/opendht/network_utils.h + include/opendht.h +) + +if (OPENDHT_PEER_DISCOVERY) + list (APPEND opendht_SOURCES src/peer_discovery.cpp) + list (APPEND opendht_HEADERS include/opendht/peer_discovery.h) + add_definitions(-DOPENDHT_PEER_DISCOVERY) +endif() + +if (OPENDHT_PYTHON) + message("Indexation enabled since it is required for Python support") + set(OPENDHT_INDEX ON) +endif() +if (OPENDHT_INDEX) + list (APPEND opendht_SOURCES src/indexation/pht.cpp) + list (APPEND opendht_HEADERS include/opendht/indexation/pht.h) + add_definitions(-DOPENDHT_INDEXATION) +endif() + +if (OPENDHT_PROXY_SERVER) + add_definitions(-DOPENDHT_PROXY_SERVER) + if (OPENDHT_PROXY_SERVER_IDENTITY) + add_definitions(-DOPENDHT_PROXY_SERVER_IDENTITY) + endif() + list (APPEND opendht_HEADERS + include/opendht/dht_proxy_server.h + ) + list (APPEND opendht_SOURCES + src/dht_proxy_server.cpp + ) +endif () + +if (OPENDHT_PROXY_CLIENT) + add_definitions(-DOPENDHT_PROXY_CLIENT) + list (APPEND opendht_HEADERS + include/opendht/dht_proxy_client.h + ) + list (APPEND opendht_SOURCES + src/dht_proxy_client.cpp + ) +endif () + +if (OPENDHT_HTTP) + if (OPENDHT_PUSH_NOTIFICATIONS) + message("Using push notification") + add_definitions(-DOPENDHT_PUSH_NOTIFICATIONS) + endif () + list (APPEND opendht_HEADERS + include/opendht/proxy.h + include/opendht/http.h + src/compat/os_cert.h + ) + list (APPEND opendht_SOURCES + src/http.cpp + src/compat/os_cert.cpp + ) +endif () + +if (MSVC) + list (APPEND opendht_HEADERS src/compat/msvc/unistd.h) +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 + $ + $ + $ + ) + if (OPENDHT_HTTP) + add_obj_lib (win32_fmt ${WIN32_DEP_DIR}/fmt/msvc/Release/fmt.lib) + add_obj_lib (win32_http_parser ${WIN32_DEP_DIR}/http_parser/x64/Release/http-parser.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 + $ + $ + $ + $ + ) + 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}/../http_parser/x64/Release/http-parser.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} +) +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 (MSVC) + if (OPENDHT_STATIC) + target_link_libraries(opendht PUBLIC ${Win32_STATIC_LIBRARIES} ${Win32_IMPORT_LIBRARIES}) + set_target_properties (opendht PROPERTIES OUTPUT_NAME "libopendht") + endif() +else() + target_link_libraries(opendht + PRIVATE + PkgConfig::argon2 + PkgConfig::Nettle + ${HTTP_PARSER_LIBRARY} + PUBLIC + ${CMAKE_THREAD_LIBS_INIT} + PkgConfig::GnuTLS + fmt::fmt + ) + if (Jsoncpp_FOUND) + target_link_libraries(opendht PUBLIC PkgConfig::Jsoncpp) + endif() + if (OPENDHT_PROXY_OPENSSL) + target_link_libraries(opendht PUBLIC PkgConfig::OPENSSL) + 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) +endif () +install (TARGETS opendht DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT opendht) + +if (OPENDHT_C) + add_library (opendht-c + c/opendht.cpp + c/opendht_c.h + ) + 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}) + install (TARGETS opendht-c DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT opendht-c) + + # PkgConfig module + configure_file ( + opendht-c.pc.in + opendht-c.pc + @ONLY + ) + install (FILES ${CMAKE_CURRENT_BINARY_DIR}/opendht-c.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + install (FILES c/opendht_c.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/opendht) +endif () + +if (OPENDHT_TOOLS) + add_subdirectory(tools) +endif () +add_subdirectory(doc) + +if (OPENDHT_PYTHON) + add_subdirectory(python) +endif () + +# CMake module +write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/opendhtConfigVersion.cmake" + VERSION ${opendht_VERSION} + COMPATIBILITY AnyNewerVersion +) +# PkgConfig module +configure_file ( + opendht.pc.in + opendht.pc + @ONLY +) + +# Install targets +install (DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX}) +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) + +# Unit tests +if (BUILD_TESTING AND NOT MSVC) + pkg_search_module(Cppunit REQUIRED IMPORTED_TARGET cppunit) + # unit testing + list (APPEND test_FILES + tests/infohashtester.h + tests/infohashtester.cpp + tests/valuetester.h + tests/valuetester.cpp + tests/cryptotester.h + tests/cryptotester.cpp + tests/dhtrunnertester.h + tests/dhtrunnertester.cpp + tests/threadpooltester.h + tests/threadpooltester.cpp + ) + if (OPENDHT_TESTS_NETWORK) + if (OPENDHT_PROXY_SERVER AND OPENDHT_PROXY_CLIENT) + list (APPEND test_FILES + tests/httptester.h + tests/httptester.cpp + tests/dhtproxytester.h + tests/dhtproxytester.cpp + ) + endif() + if (OPENDHT_PEER_DISCOVERY) + list (APPEND test_FILES + tests/peerdiscoverytester.h + tests/peerdiscoverytester.cpp + ) + endif() + endif() + add_executable(opendht_unit_tests + tests/tests_runner.cpp + ${test_FILES} + ) + target_link_libraries(opendht_unit_tests PRIVATE + opendht + ${CMAKE_THREAD_LIBS_INIT} + PkgConfig::Cppunit + ) + add_test(TEST opendht_unit_tests) +endif() diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..498329b --- /dev/null +++ b/Makefile.am @@ -0,0 +1,35 @@ +AM_CXXFLAGS = -pthread + +SUBDIRS = + +SUBDIRS += src + +if ENABLE_C +SUBDIRS += c +endif + +if ENABLE_TOOLS +SUBDIRS += tools +endif + +if USE_CYTHON +SUBDIRS += python +endif + +if ENABLE_TESTS +SUBDIRS += tests +endif + +SUBDIRS += doc + +ACLOCAL_AMFLAGS = -I m4 + +DOC_FILES = \ + README.md \ + COPYING + +EXTRA_DIST = \ + $(DOC_FILES) + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = opendht.pc diff --git a/README.md b/README.md new file mode 100644 index 0000000..0cc81d3 --- /dev/null +++ b/README.md @@ -0,0 +1,120 @@ + +
+

+ OpenDHT +

+ +A lightweight C++17 Distributed Hash Table implementation. + +OpenDHT provides an easy to use distributed in-memory data store. +Every node in the network can read and write values to the store. +Values are distributed over the network, with redundancy. + + * Lightweight and scalable, designed for large networks and small devices + * High resilience to network disruption + * Public key cryptography layer providing optional data signature and encryption (using GnuTLS) + * IPv4 and IPv6 support + * Clean and powerful **C++17** map API + * Bindings for **C, Rust & Python 3** + * REST API with optional HTTP client+server with push notification support + +## Documentation +See the wiki: + +#### How to run a node + +You can help contributing to the public network by running a stable node with a public IP address. +https://github.com/savoirfairelinux/opendht/wiki/Running-a-node-with-dhtnode + +#### How-to build and install + +Build instructions: + +## Examples +### C++ example +The `tools` directory includes simple example programs : +* `dhtnode`, a command line tool, allowing to run a DHT node and perform operations supported by the library (get, put etc.) with text values. +* `dhtchat`, a very simple IM client working over the dht. + +Example program launching a DHT node, connecting to the network and performing some basic operations: +```c++ +#include +#include + +int main() +{ + dht::DhtRunner node; + + // Launch a dht node on a new thread, using a + // generated RSA key pair, and listen on port 4222. + node.run(4222, dht::crypto::generateIdentity(), true); + + // Join the network through any running node, + // here using a known bootstrap node. + node.bootstrap("bootstrap.jami.net", "4222"); + + // put some data on the dht + std::vector some_data(5, 10); + node.put("unique_key", some_data); + + // put some data on the dht, signed with our generated private key + node.putSigned("unique_key_42", some_data); + + // get data from the dht + node.get("other_unique_key", [](const std::vector>& values) { + // Callback called when values are found + for (const auto& value : values) + std::cout << "Found value: " << *value << std::endl; + return true; // return false to stop the search + }); + + // wait for dht threads to end + node.join(); + return 0; +} +``` +### Python 3 example +```python +import opendht as dht + +node = dht.DhtRunner() +node.run() + +# Join the network through any running node, +# here using a known bootstrap node. +node.bootstrap("bootstrap.jami.net", "4222") + +# blocking call (provide callback arguments to make the call non-blocking) +node.put(dht.InfoHash.get("unique_key"), dht.Value(b'some binary data')) + +results = node.get(dht.InfoHash.get("unique_key")) +for r in results: + print(r) +``` + +## Dependencies +- msgpack-c 1.2+, used for data serialization. +- GnuTLS 3.3+, used for cryptographic operations. +- Nettle 2.4+, a GnuTLS dependency for crypto. +- {fmt} 9.0+, for log formatting. +- (optional) restinio used for the REST API. +- (optional) jsoncpp 1.7.4-3+, used for the REST API. +- Build tested with GCC 7+ (GNU/Linux, Windows with MinGW), Clang/LLVM (GNU/Linux, Android, macOS, iOS). +- Build tested with Microsoft Visual Studio 2019, 2022 + +## Contact + +IRC: join us on Libera.chat at [`#opendht`](https://web.libera.chat/#opendht). + +## License +Copyright (C) 2014-2023 Savoir-faire Linux Inc. + +OpenDHT is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. + +See COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html for the full GPLv3 license. + +## Acknowledgements +This project was originally based on https://github.com/jech/dht by Juliusz Chroboczek. +It is independent from another project called OpenDHT (Sean Rhea. Ph.D. Thesis, 2005), now extinct. diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..52bbe56 --- /dev/null +++ b/autogen.sh @@ -0,0 +1 @@ +autoreconf --install --verbose -Wall diff --git a/c/Makefile.am b/c/Makefile.am new file mode 100644 index 0000000..9832679 --- /dev/null +++ b/c/Makefile.am @@ -0,0 +1,15 @@ +lib_LTLIBRARIES = libopendht-c.la +noinst_HEADERS = opendht_c.h + +AM_CPPFLAGS = -DOPENDHT_C_BUILD -isystem @top_srcdir@/include @JsonCpp_CFLAGS@ @MsgPack_CFLAGS@ +if OPENDHT_SHARED +AM_CPPFLAGS += -Dopendht_c_EXPORTS +endif + +libopendht_c_la_LIBADD = $(LIBOBJS) ../src/.libs/libopendht.la + +libopendht_c_la_SOURCES = \ + opendht.cpp + +nobase_include_HEADERS = \ + opendht_c.h diff --git a/c/opendht.cpp b/c/opendht.cpp new file mode 100644 index 0000000..10d0ff4 --- /dev/null +++ b/c/opendht.cpp @@ -0,0 +1,517 @@ +/* + * Copyright (C) 2014-2023 Savoir-faire Linux Inc. + * Author : Adrien Béraud + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "opendht_c.h" + +#include +#include + +using ValueSp = std::shared_ptr; +using PrivkeySp = std::shared_ptr; +using PubkeySp = std::shared_ptr; +using CertSp = std::shared_ptr; + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +const char* dht_version() +{ + return dht::version(); +} + +// dht::InfoHash + +inline dht_infohash dht_infohash_to_c(const dht::InfoHash& h) { + dht_infohash ret; + *reinterpret_cast(&ret) = h; + return ret; +} + +inline dht_pkid dht_pkid_to_c(const dht::PkId& h) { + dht_pkid ret; + *reinterpret_cast(&ret) = h; + return ret; +} + +const char* dht_infohash_print(const dht_infohash* h) { + return reinterpret_cast(h)->to_c_str(); +} + +void dht_infohash_zero(dht_infohash* h) { + *reinterpret_cast(h) = dht::InfoHash{}; +} + +void dht_infohash_random(dht_infohash* h) { + *reinterpret_cast(h) = dht::InfoHash::getRandom(); +} + +void dht_infohash_get(dht_infohash* h, const uint8_t* dat, size_t dat_size) { + *reinterpret_cast(h) = dht::InfoHash::get(dat, dat_size); +} + +void dht_infohash_get_from_string(dht_infohash* h, const char* dat) { + *reinterpret_cast(h) = dht::InfoHash::get((const uint8_t*)dat, (size_t)strlen(dat)); +} + +bool dht_infohash_is_zero(const dht_infohash* h) { + return !static_cast(*reinterpret_cast(h)); +} + +void dht_infohash_from_hex(dht_infohash* h, const char* dat) { + *h = dht_infohash_to_c(dht::InfoHash(std::string_view(dat, HASH_LEN*2))); +} + +void dht_infohash_from_hex_null(dht_infohash* h, const char* dat) { + *h = dht_infohash_to_c(dht::InfoHash(std::string_view(dat))); +} + +const char* dht_pkid_print(const dht_pkid* h) { + return reinterpret_cast(h)->to_c_str(); +} + +// dht::Blob +void dht_blob_delete(dht_blob* data) { + delete reinterpret_cast(data); +} + +dht_data_view dht_blob_get_data(const dht_blob* data) { + dht_data_view view; + view.data = reinterpret_cast(data)->data(); + view.size = reinterpret_cast(data)->size(); + return view; +} + +// dht::Value +dht_data_view dht_value_get_data(const dht_value* data) { + const ValueSp& vsp(*reinterpret_cast(data)); + dht_data_view view; + view.data = vsp->data.data(); + view.size = vsp->data.size(); + return view; +} + +dht_value_id dht_value_get_id(const dht_value* data) { + const ValueSp& vsp(*reinterpret_cast(data)); + return vsp->id; +} + +dht_publickey* dht_value_get_owner(const dht_value* data) { + const ValueSp& vsp(*reinterpret_cast(data)); + return vsp->owner ? reinterpret_cast(new PubkeySp(vsp->owner)) : nullptr; +} + +dht_infohash dht_value_get_recipient(const dht_value* data) { + const ValueSp& vsp(*reinterpret_cast(data)); + return dht_infohash_to_c(vsp->recipient); +} + +const char* dht_value_get_user_type(const dht_value* data) { + const ValueSp& vsp(*reinterpret_cast(data)); + return vsp->user_type.c_str(); +} + +void dht_value_set_user_type(dht_value* data, const char* user_type) { + (*reinterpret_cast(data))->user_type = user_type; +} + +dht_value* dht_value_new(const uint8_t* data, size_t size) { + return reinterpret_cast(new ValueSp(std::make_shared(data, size))); +} + +dht_value* dht_value_new_from_string(const char* str) { + ValueSp value = std::make_shared((const uint8_t*)str, strlen(str)); + value->user_type = "text/plain"; + return reinterpret_cast(new ValueSp(std::move(value))); +} + +dht_value* dht_value_ref(const dht_value* v) { + return reinterpret_cast(new ValueSp(*reinterpret_cast(v))); +} + +void dht_value_unref(dht_value* v) { + delete reinterpret_cast(v); +} + +// dht::crypto::PublicKey +dht_publickey* dht_publickey_import(const uint8_t* dat, size_t dat_size) { + try { + return reinterpret_cast(new PubkeySp(std::make_shared(dat, dat_size))); + } catch (const dht::crypto::CryptoException& e) { + return nullptr; + } +} + +void dht_publickey_delete(dht_publickey* pk) { + delete reinterpret_cast(pk); +} + +int dht_publickey_export(const dht_publickey* pk, char* out, size_t* outlen) { + const auto& pkey = *reinterpret_cast(pk); + return pkey->pack((uint8_t*)out, outlen); +} + +dht_infohash dht_publickey_get_id(const dht_publickey* pk) { + const auto& pkey = *reinterpret_cast(pk); + return dht_infohash_to_c(pkey->getId()); +} + +dht_pkid dht_publickey_get_long_id(const dht_publickey* pk) { + const auto& pkey = *reinterpret_cast(pk); + return dht_pkid_to_c(pkey->getLongId()); +} + +bool dht_publickey_check_signature(const dht_publickey* pk, const char* data, size_t data_size, const char* signature, size_t signature_size) { + const auto& pkey = *reinterpret_cast(pk); + return pkey->checkSignature((const uint8_t*)data, data_size, (const uint8_t*)signature, signature_size); +} + +dht_blob* dht_publickey_encrypt(const dht_publickey* pk, const char* data, size_t data_size) { + const auto& pkey = *reinterpret_cast(pk); + try { + auto rdata = std::make_unique(); + *rdata = pkey->encrypt((const uint8_t*)data, data_size); + return (dht_blob*)rdata.release(); + } catch (...) { + return nullptr; + } +} + +// dht::crypto::PrivateKey +dht_privatekey* dht_privatekey_generate(unsigned key_length_bits) { + if (key_length_bits == 0) + key_length_bits = 4096; + return reinterpret_cast(new PrivkeySp(std::make_shared(dht::crypto::PrivateKey::generate(key_length_bits)))); +} + +dht_privatekey* dht_privatekey_import(const uint8_t* dat, size_t dat_size, const char* password) { + try { + return reinterpret_cast(new PrivkeySp(std::make_shared(dat, dat_size, password))); + } catch (const dht::crypto::CryptoException& e) { + return nullptr; + } +} + +int dht_privatekey_export(const dht_privatekey* k, char* out, size_t* out_size, const char* password) { + if (!out or !out_size or !*out_size) + return -1; + const auto& key = *reinterpret_cast(k); + return key->serialize((uint8_t*)out, out_size, password); +} + +dht_publickey* dht_privatekey_get_publickey(const dht_privatekey* k) { + const auto& key = *reinterpret_cast(k); + return reinterpret_cast(new PubkeySp(key->getSharedPublicKey())); +} + +dht_blob* dht_privatekey_decrypt(const dht_privatekey* k, const char* data, size_t data_size) { + const auto& key = *reinterpret_cast(k); + try { + auto rdata = std::make_unique(); + *rdata = key->decrypt((const uint8_t*)data, data_size); + return (dht_blob*)rdata.release(); + } catch (...) { + return nullptr; + } +} + +void dht_privatekey_delete(dht_privatekey* pk) { + delete reinterpret_cast(pk); +} + +// dht::crypto::Certificate +dht_certificate* dht_certificate_import(const uint8_t* dat, size_t dat_size) { + try { + return reinterpret_cast(new CertSp(std::make_shared(dat, dat_size))); + } catch (const dht::crypto::CryptoException& e) { + return nullptr; + } +} + +void dht_certificate_delete(dht_certificate* c) { + delete reinterpret_cast(c); +} + +dht_infohash dht_certificate_get_id(const dht_certificate* c) { + const auto& cert = *reinterpret_cast(c); + return dht_infohash_to_c(cert->getId()); +} + +dht_pkid dht_certificate_get_long_id(const dht_certificate* c) { + const auto& cert = *reinterpret_cast(c); + return dht_pkid_to_c(cert->getLongId()); +} + +dht_publickey* dht_certificate_get_publickey(const dht_certificate* c) { + const auto& cert = *reinterpret_cast(c); + return reinterpret_cast(new PubkeySp(cert->getSharedPublicKey())); +} + +// dht::crypto::Identity +inline dht::crypto::Identity dht_identity_from_c(const dht_identity* cid) { + dht::crypto::Identity id {}; + if (cid and cid->privatekey) + id.first = *reinterpret_cast(cid->privatekey); + if (cid and cid->certificate) + id.second = *reinterpret_cast(cid->certificate); + return id; +} + +inline dht_identity dht_identity_to_c(const dht::crypto::Identity& id) { + dht_identity cid {}; + cid.privatekey = id.first ? reinterpret_cast(new PrivkeySp(id.first)) : NULL; + cid.certificate = id.second ? reinterpret_cast(new CertSp(id.second)) : NULL; + return cid; +} + +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))); +} + +OPENDHT_C_PUBLIC void dht_identity_delete(dht_identity* id) { + if (id->certificate) { + dht_certificate_delete(id->certificate); + id->certificate = NULL; + } + if (id->privatekey) { + dht_privatekey_delete(id->privatekey); + id->privatekey = NULL; + } +} + +// config +void dht_runner_config_default(dht_runner_config* config) { + bzero(config, sizeof(dht_runner_config)); + config->threaded = true; +} + +// dht::DhtRunner +dht_runner* dht_runner_new(void) { + return reinterpret_cast(new dht::DhtRunner); +} + +void dht_runner_delete(dht_runner* runner) { + delete reinterpret_cast(runner); +} + +int dht_runner_run(dht_runner* r, in_port_t port) { + auto runner = reinterpret_cast(r); + try { + runner->run(port, {}, true); + } catch(...) { + return ENOTCONN; + } + return 0; +} + +int dht_runner_run_config(dht_runner* r, in_port_t port, const dht_runner_config* conf) { + auto runner = reinterpret_cast(r); + try { + dht::DhtRunner::Config config; + config.dht_config.node_config.is_bootstrap = conf->dht_config.node_config.is_bootstrap; + config.dht_config.node_config.maintain_storage = conf->dht_config.node_config.maintain_storage; + config.dht_config.node_config.node_id = *reinterpret_cast(&conf->dht_config.node_config.node_id); + config.dht_config.node_config.network = conf->dht_config.node_config.network; + config.dht_config.node_config.persist_path = conf->dht_config.node_config.persist_path + ? std::string(conf->dht_config.node_config.persist_path) : std::string{}; + + if (conf->dht_config.id.privatekey) + config.dht_config.id.first = *reinterpret_cast(conf->dht_config.id.privatekey); + + if (conf->dht_config.id.certificate) + config.dht_config.id.second = *reinterpret_cast(conf->dht_config.id.certificate); + + config.threaded = conf->threaded; + config.proxy_server = conf->proxy_server ? std::string(conf->proxy_server) : std::string{}; + config.push_node_id = conf->push_node_id ? std::string(conf->push_node_id) : std::string{}; + config.push_token = conf->push_token ? std::string(conf->push_token) : std::string{}; + config.push_topic = conf->push_topic ? std::string(conf->push_topic) : std::string{}; + config.push_platform = conf->push_platform ? std::string(conf->push_platform) : std::string{}; + config.peer_discovery = conf->peer_discovery; + config.peer_publish = conf->peer_publish; + + dht::DhtRunner::Context context; + if (conf->log) { + context.logger = dht::log::getStdLogger(); + } + runner->run(port, config, std::move(context)); + } catch(...) { + return ENOTCONN; + } + return 0; +} + +void dht_runner_ping(dht_runner* r, struct sockaddr* addr, socklen_t addr_len, dht_done_cb done_cb, void* cb_user_data) { + auto runner = reinterpret_cast(r); + if (done_cb) { + runner->bootstrap(dht::SockAddr(addr, addr_len), [done_cb, cb_user_data](bool ok){ + done_cb(ok, cb_user_data); + }); + } else { + runner->bootstrap(dht::SockAddr(addr, addr_len)); + } +} + +void dht_runner_bootstrap(dht_runner* r, const char* host, const char* service) { + auto runner = reinterpret_cast(r); + if (service) + runner->bootstrap(host, service); + else + runner->bootstrap(host); +} + +void dht_runner_get(dht_runner* r, const dht_infohash* h, dht_get_cb cb, dht_done_cb done_cb, void* cb_user_data) { + auto runner = reinterpret_cast(r); + auto hash = reinterpret_cast(h); + runner->get(*hash, [cb,cb_user_data](std::shared_ptr value){ + return cb(reinterpret_cast(&value), cb_user_data); + }, [done_cb, cb_user_data](bool ok){ + if (done_cb) + done_cb(ok, cb_user_data); + }); +} + +struct ScopeGuardCb { + ScopeGuardCb(dht_shutdown_cb cb, void* data) + : onDestroy(cb), userData(data) {} + + ~ScopeGuardCb() { + if (onDestroy) + onDestroy((void*)userData); + } +private: + const dht_shutdown_cb onDestroy; + void const* userData; +}; + +dht_op_token* dht_runner_listen(dht_runner* r, const dht_infohash* h, dht_value_cb cb, dht_shutdown_cb done_cb, void* cb_user_data) { + auto runner = reinterpret_cast(r); + auto hash = reinterpret_cast(h); + auto fret = new std::future; + *fret = runner->listen(*hash, [ + cb, + cb_user_data, + guard = done_cb ? std::make_shared(done_cb, cb_user_data) : std::shared_ptr{} + ](const std::vector>& values, bool expired) { + for (const auto& value : values) { + if (not cb(reinterpret_cast(&value), expired, cb_user_data)) + return false; + } + return true; + }); + return (dht_op_token*)fret; +} + +void dht_runner_cancel_listen(dht_runner* r, const dht_infohash* h, dht_op_token* t) { + auto runner = reinterpret_cast(r); + auto hash = reinterpret_cast(h); + auto token = reinterpret_cast*>(t); + runner->cancelListen(*hash, std::move(*token)); +} + +void dht_op_token_delete(dht_op_token* token) { + delete reinterpret_cast*>(token); +} + +void dht_runner_put(dht_runner* r, const dht_infohash* h, const dht_value* v, dht_done_cb done_cb, void* cb_user_data, bool permanent) { + auto runner = reinterpret_cast(r); + auto hash = reinterpret_cast(h); + auto value = reinterpret_cast(v); + runner->put(*hash, *value, [done_cb, cb_user_data](bool ok){ + if (done_cb) + done_cb(ok, cb_user_data); + }, dht::time_point::max(), permanent); +} + +void dht_runner_put_signed(dht_runner* r, const dht_infohash* h, const dht_value* v, dht_done_cb done_cb, void* cb_user_data, bool permanent) { + auto runner = reinterpret_cast(r); + auto hash = reinterpret_cast(h); + auto value = reinterpret_cast(v); + runner->putSigned(*hash, *value, [done_cb, cb_user_data](bool ok){ + if (done_cb) + done_cb(ok, cb_user_data); + }, permanent); +} + +void dht_runner_put_encrypted(dht_runner* r, const dht_infohash* h, const dht_infohash* to, const dht_value* v, dht_done_cb done_cb, void* cb_user_data, bool permanent) { + auto runner = reinterpret_cast(r); + auto hash = reinterpret_cast(h); + auto toHash = reinterpret_cast(to); + auto value = reinterpret_cast(v); + runner->putEncrypted(*hash, *toHash, *value, [done_cb, cb_user_data](bool ok){ + if (done_cb) + done_cb(ok, cb_user_data); + }, permanent); +} + +void dht_runner_cancel_put(dht_runner* r, const dht_infohash* h, dht_value_id value_id) { + auto runner = reinterpret_cast(r); + auto hash = reinterpret_cast(h); + runner->cancelPut(*hash, value_id); +} + +void dht_runner_shutdown(dht_runner* r, dht_shutdown_cb done_cb, void* cb_user_data) { + auto runner = reinterpret_cast(r); + runner->shutdown([done_cb, cb_user_data](){ + if (done_cb) + done_cb(cb_user_data); + }); +} + +bool dht_runner_is_running(const dht_runner* r) { + if (not r) return false; + auto runner = reinterpret_cast(r); + return runner->isRunning(); +} + +in_port_t dht_runner_get_bound_port(const dht_runner* r, sa_family_t af) { + auto runner = reinterpret_cast(r); + return runner->getBoundPort(af); +} + +dht_infohash dht_runner_get_node_id(const dht_runner* r) { + auto runner = reinterpret_cast(r); + dht_infohash ret; + *reinterpret_cast(&ret) = runner->getNodeId(); + return ret; +} + +dht_infohash dht_runner_get_id(const dht_runner* r) { + auto runner = reinterpret_cast(r); + dht_infohash ret; + *reinterpret_cast(&ret) = runner->getId(); + return ret; +} + +struct sockaddr** dht_runner_get_public_address(const dht_runner* r) { + auto runner = reinterpret_cast(r); + auto addrs = const_cast(runner)->getPublicAddress(); + if (addrs.empty()) + return nullptr; + auto ret = (struct sockaddr**)malloc(sizeof(struct sockaddr*) * (addrs.size() + 1)); + for (size_t i=0; i + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include + +// Non-owning data view +struct OPENDHT_C_PUBLIC dht_data_view { + const uint8_t* data; + size_t size; +}; +typedef struct dht_data_view dht_data_view; + +OPENDHT_C_PUBLIC const char* dht_version(void); + +// dht::Blob +struct OPENDHT_C_PUBLIC dht_blob; +typedef struct dht_blob dht_blob; +OPENDHT_C_PUBLIC dht_data_view dht_blob_get_data(const dht_blob* data); +OPENDHT_C_PUBLIC void dht_blob_delete(dht_blob* data); + +// dht::InfoHash +struct OPENDHT_C_PUBLIC dht_infohash { uint8_t d[HASH_LEN]; }; +typedef struct dht_infohash dht_infohash; +OPENDHT_C_PUBLIC void dht_infohash_zero(dht_infohash* h); +OPENDHT_C_PUBLIC void dht_infohash_random(dht_infohash* h); +OPENDHT_C_PUBLIC void dht_infohash_from_hex(dht_infohash* h, const char* dat); +OPENDHT_C_PUBLIC void dht_infohash_from_hex_null(dht_infohash* h, const char* dat); +OPENDHT_C_PUBLIC void dht_infohash_get(dht_infohash* h, const uint8_t* dat, size_t dat_size); +OPENDHT_C_PUBLIC void dht_infohash_get_from_string(dht_infohash* h, const char* str); +OPENDHT_C_PUBLIC const char* dht_infohash_print(const dht_infohash* h); +OPENDHT_C_PUBLIC bool dht_infohash_is_zero(const dht_infohash* h); + +// dht::PkId +struct OPENDHT_C_PUBLIC dht_pkid { uint8_t d[32]; }; +typedef struct dht_pkid dht_pkid; +OPENDHT_C_PUBLIC const char* dht_pkid_print(const dht_pkid* h); + +// dht::crypto::PublicKey +struct OPENDHT_C_PUBLIC dht_publickey; +typedef struct dht_publickey dht_publickey; +OPENDHT_C_PUBLIC dht_publickey* dht_publickey_import(const uint8_t* dat, size_t dat_size); +OPENDHT_C_PUBLIC void dht_publickey_delete(dht_publickey* pk); +OPENDHT_C_PUBLIC int dht_publickey_export(const dht_publickey* pk, char* out, size_t* out_size); +OPENDHT_C_PUBLIC dht_infohash dht_publickey_get_id(const dht_publickey* pk); +OPENDHT_C_PUBLIC dht_pkid dht_publickey_get_long_id(const dht_publickey* pk); +OPENDHT_C_PUBLIC bool dht_publickey_check_signature(const dht_publickey* pk, const char* data, size_t data_size, const char* signature, size_t signature_size); +OPENDHT_C_PUBLIC dht_blob* dht_publickey_encrypt(const dht_publickey* pk, const char* data, size_t data_size); + +// dht::crypto::PrivateKey +struct OPENDHT_C_PUBLIC dht_privatekey; +typedef struct dht_privatekey dht_privatekey; +OPENDHT_C_PUBLIC dht_privatekey* dht_privatekey_generate(unsigned key_length_bits); +OPENDHT_C_PUBLIC dht_privatekey* dht_privatekey_import(const uint8_t* dat, size_t dat_size, const char* password); +OPENDHT_C_PUBLIC int dht_privatekey_export(const dht_privatekey*, char* out, size_t* out_size, const char* password); +OPENDHT_C_PUBLIC dht_publickey* dht_privatekey_get_publickey(const dht_privatekey*); +OPENDHT_C_PUBLIC dht_blob* dht_privatekey_decrypt(const dht_privatekey*, const char* data, size_t data_size); +OPENDHT_C_PUBLIC void dht_privatekey_delete(dht_privatekey*); + +// dht::crypto::Certificate +struct OPENDHT_C_PUBLIC dht_certificate; +typedef struct dht_certificate dht_certificate; +OPENDHT_C_PUBLIC dht_certificate* dht_certificate_import(const uint8_t* dat, size_t dat_size); +OPENDHT_C_PUBLIC dht_infohash dht_certificate_get_id(const dht_certificate*); +OPENDHT_C_PUBLIC dht_pkid dht_certificate_get_long_id(const dht_certificate*); +OPENDHT_C_PUBLIC dht_publickey* dht_certificate_get_publickey(const dht_certificate*); +OPENDHT_C_PUBLIC void dht_certificate_delete(dht_certificate*); + +struct OPENDHT_PUBLIC dht_identity { + dht_privatekey* privatekey; + dht_certificate* certificate; +}; +typedef struct dht_identity dht_identity; +OPENDHT_C_PUBLIC dht_identity dht_identity_generate(const char* common_name, const dht_identity* ca); +OPENDHT_C_PUBLIC void dht_identity_delete(dht_identity*); + +// dht::Value +struct OPENDHT_C_PUBLIC dht_value; +typedef struct dht_value dht_value; +typedef uint64_t dht_value_id; +OPENDHT_C_PUBLIC dht_value* dht_value_new(const uint8_t* data, size_t size); +OPENDHT_C_PUBLIC dht_value* dht_value_new_from_string(const char* str); +OPENDHT_C_PUBLIC dht_value* dht_value_ref(const dht_value*); +OPENDHT_C_PUBLIC void dht_value_unref(dht_value*); +OPENDHT_C_PUBLIC dht_data_view dht_value_get_data(const dht_value* data); +OPENDHT_C_PUBLIC dht_value_id dht_value_get_id(const dht_value* data); +OPENDHT_C_PUBLIC dht_publickey* dht_value_get_owner(const dht_value* data); +OPENDHT_C_PUBLIC dht_infohash dht_value_get_recipient(const dht_value* data); +OPENDHT_C_PUBLIC const char* dht_value_get_user_type(const dht_value* data); +OPENDHT_C_PUBLIC void dht_value_set_user_type(dht_value* data, const char* user_type); + +// callbacks +typedef bool (*dht_get_cb)(const dht_value* value, void* user_data); +typedef bool (*dht_value_cb)(const dht_value* value, bool expired, void* user_data); +typedef void (*dht_done_cb)(bool ok, void* user_data); +typedef void (*dht_shutdown_cb)(void* user_data); + +struct OPENDHT_C_PUBLIC dht_op_token; +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 { + dht_infohash node_id; + uint32_t network; + bool is_bootstrap; + bool maintain_storage; + const char* persist_path; +}; +typedef struct dht_node_config dht_node_config; + +struct OPENDHT_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 { + dht_secure_config dht_config; + bool threaded; + const char* proxy_server; + const char* push_node_id; + const char* push_token; + const char* push_topic; + const char* push_platform; + bool peer_discovery; + bool peer_publish; + dht_certificate* server_ca; + dht_identity client_identity; + bool log; +}; +typedef struct dht_runner_config dht_runner_config; +OPENDHT_C_PUBLIC void dht_runner_config_default(dht_runner_config* config); + +// dht::DhtRunner +struct OPENDHT_C_PUBLIC dht_runner; +typedef struct dht_runner dht_runner; +OPENDHT_C_PUBLIC dht_runner* dht_runner_new(void); +OPENDHT_C_PUBLIC void dht_runner_delete(dht_runner* runner); +/* Returns 0 on success, standard error code on failure */ +OPENDHT_C_PUBLIC int dht_runner_run(dht_runner* runner, in_port_t port); +/* Returns 0 on success, standard error code on failure */ +OPENDHT_C_PUBLIC int dht_runner_run_config(dht_runner* runner, in_port_t port, const dht_runner_config* config); +OPENDHT_C_PUBLIC void dht_runner_ping(dht_runner* runner, struct sockaddr* addr, socklen_t addr_len, dht_done_cb done_cb, void* cb_user_data); +OPENDHT_C_PUBLIC void dht_runner_bootstrap(dht_runner* runner, const char* host, const char* service); +OPENDHT_C_PUBLIC void dht_runner_get(dht_runner* runner, const dht_infohash* hash, dht_get_cb cb, dht_done_cb done_cb, void* cb_user_data); +OPENDHT_C_PUBLIC dht_op_token* dht_runner_listen(dht_runner* runner, const dht_infohash* hash, dht_value_cb cb, dht_shutdown_cb done_cb, void* cb_user_data); +OPENDHT_C_PUBLIC void dht_runner_cancel_listen(dht_runner* runner, const dht_infohash* hash, dht_op_token* token); +OPENDHT_C_PUBLIC void dht_runner_put(dht_runner* runner, const dht_infohash* hash, const dht_value* value, dht_done_cb done_cb, void* cb_user_data, bool permanent); +OPENDHT_C_PUBLIC void dht_runner_put_signed(dht_runner* runner, const dht_infohash* hash, const dht_value* value, dht_done_cb done_cb, void* cb_user_data, bool permanent); +OPENDHT_C_PUBLIC void dht_runner_put_encrypted(dht_runner* runner, const dht_infohash* hash, const dht_infohash* to, const dht_value* value, dht_done_cb done_cb, void* cb_user_data, bool permanent); +OPENDHT_C_PUBLIC void dht_runner_cancel_put(dht_runner* runner, const dht_infohash* hash, dht_value_id value_id); +OPENDHT_C_PUBLIC void dht_runner_shutdown(dht_runner* runner, dht_shutdown_cb done_cb, void* cb_user_data); +OPENDHT_C_PUBLIC dht_infohash dht_runner_get_node_id(const dht_runner* runner); +OPENDHT_C_PUBLIC dht_infohash dht_runner_get_id(const dht_runner* runner); +OPENDHT_C_PUBLIC bool dht_runner_is_running(const dht_runner* runner); +OPENDHT_C_PUBLIC in_port_t dht_runner_get_bound_port(const dht_runner* runner, sa_family_t af); +/** Returns null-terminated array that must be freed after use as well as each element */ +OPENDHT_C_PUBLIC struct sockaddr** dht_runner_get_public_address(const dht_runner* runner); + +#ifdef __cplusplus +} +#endif diff --git a/cmake/CheckAtomic.cmake b/cmake/CheckAtomic.cmake new file mode 100644 index 0000000..b6be817 --- /dev/null +++ b/cmake/CheckAtomic.cmake @@ -0,0 +1,103 @@ +# atomic builtins are required for threading support. + +INCLUDE(CheckCXXSourceCompiles) +INCLUDE(CheckLibraryExists) +INCLUDE("${CMAKE_CURRENT_LIST_DIR}/DetermineGCCCompatible.cmake") + +# Sometimes linking against libatomic is required for atomic ops, if +# the platform doesn't support lock-free atomics. + +function(check_working_cxx_atomics varname) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") + CHECK_CXX_SOURCE_COMPILES(" +#include +std::atomic x; +std::atomic y; +std::atomic z; +int main() { + ++z; + ++y; + return ++x; +} +" ${varname}) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) +endfunction(check_working_cxx_atomics) + +function(check_working_cxx_atomics64 varname) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}") + CHECK_CXX_SOURCE_COMPILES(" +#include +#include +std::atomic x (0); +int main() { + uint64_t i = x.load(std::memory_order_relaxed); + (void)i; + return 0; +} +" ${varname}) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) +endfunction(check_working_cxx_atomics64) + + +# Check for (non-64-bit) atomic operations. +if(MSVC) + set(HAVE_CXX_ATOMICS_WITHOUT_LIB True) +elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL") + # First check if atomics work without the library. + check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB) + # If not, check if the library exists, and atomics work with it. + if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") + check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB) + if (NOT HAVE_CXX_ATOMICS_WITH_LIB) + message(FATAL_ERROR "Host compiler must support std::atomic!") + endif() + endif() +endif() + +# Check for 64 bit atomic operations. +if(MSVC) + set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True) +elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL") + # First check if atomics work without the library. + check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB) + # If not, check if the library exists, and atomics work with it. + if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") + check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB) + if (NOT HAVE_CXX_ATOMICS64_WITH_LIB) + message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!") + endif() + endif() +endif() + +## TODO: This define is only used for the legacy atomic operations in +## llvm's Atomic.h, which should be replaced. Other code simply +## assumes C++11 works. +CHECK_CXX_SOURCE_COMPILES(" +#ifdef _MSC_VER +#include +#endif +int main() { +#ifdef _MSC_VER + volatile LONG val = 1; + MemoryBarrier(); + InterlockedCompareExchange(&val, 0, 1); + InterlockedIncrement(&val); + InterlockedDecrement(&val); +#else + volatile unsigned long val = 1; + __sync_synchronize(); + __sync_val_compare_and_swap(&val, 1, 0); + __sync_add_and_fetch(&val, 1); + __sync_sub_and_fetch(&val, 1); +#endif + return 0; + } +" LLVM_HAS_ATOMICS) + +if( NOT LLVM_HAS_ATOMICS ) + message(STATUS "Warning: LLVM will be built thread-unsafe because atomic builtins are missing") +endif() \ No newline at end of file diff --git a/cmake/DetermineGCCCompatible.cmake b/cmake/DetermineGCCCompatible.cmake new file mode 100644 index 0000000..1369ebe --- /dev/null +++ b/cmake/DetermineGCCCompatible.cmake @@ -0,0 +1,13 @@ +# Determine if the compiler has GCC-compatible command-line syntax. + +if(NOT DEFINED LLVM_COMPILER_IS_GCC_COMPATIBLE) + if(CMAKE_COMPILER_IS_GNUCXX) + set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON) + elseif( MSVC ) + set(LLVM_COMPILER_IS_GCC_COMPATIBLE OFF) + elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) + set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON) + elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel" ) + set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON) + endif() +endif() diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake new file mode 100644 index 0000000..6807812 --- /dev/null +++ b/cmake/FindReadline.cmake @@ -0,0 +1,48 @@ +# - Try to find readline, a library for easy editing of command lines. +# Variables used by this module: +# READLINE_ROOT_DIR - Readline root directory +# Variables defined by this module: +# READLINE_FOUND - system has Readline +# READLINE_INCLUDE_DIR - the Readline include directory (cached) +# READLINE_INCLUDE_DIRS - the Readline include directories +# (identical to READLINE_INCLUDE_DIR) +# READLINE_LIBRARY - the Readline library (cached) +# READLINE_LIBRARIES - the Readline library plus the libraries it +# depends on + +# Copyright (C) 2009 +# ASTRON (Netherlands Institute for Radio Astronomy) +# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands +# +# This program is free software; you can redistribute it and/or modify +# modify it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# $Id: FindReadline.cmake 15228 2010-03-16 09:27:26Z loose $ + +if(NOT READLINE_FOUND) + + find_path(READLINE_INCLUDE_DIR readline/readline.h + HINTS ${READLINE_ROOT_DIR} PATH_SUFFIXES include) + find_library(READLINE_LIBRARY readline + HINTS ${READLINE_ROOT_DIR} PATH_SUFFIXES lib) + find_library(NCURSES_LIBRARY ncurses) # readline depends on libncurses + mark_as_advanced(READLINE_INCLUDE_DIR READLINE_LIBRARY NCURSES_LIBRARY) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Readline DEFAULT_MSG + READLINE_LIBRARY NCURSES_LIBRARY READLINE_INCLUDE_DIR) + + set(READLINE_INCLUDE_DIRS ${READLINE_INCLUDE_DIR}) + set(READLINE_LIBRARIES ${READLINE_LIBRARY} ${NCURSES_LIBRARY}) + +endif(NOT READLINE_FOUND) diff --git a/cmake/FindRestinio.cmake b/cmake/FindRestinio.cmake new file mode 100644 index 0000000..a0887b3 --- /dev/null +++ b/cmake/FindRestinio.cmake @@ -0,0 +1,14 @@ +# header-only does not produce a library +if(NOT Restinio_FOUND) + find_path (Restinio_INCLUDE_DIR restinio + HINTS + "/usr/include" + "/usr/local/include" + "/opt/local/include") + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Restinio DEFAULT_MSG Restinio_INCLUDE_DIR) + if (Restinio_INCLUDE_DIR) + set(Restinio_FOUND TRUE) + set(Restinio_INCLUDE_DIRS ${Restinio_INCLUDE_DIR}) + endif() +endif() diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..2e54c1d --- /dev/null +++ b/configure.ac @@ -0,0 +1,216 @@ +dnl define macros +m4_define([opendht_major_version], 3) +m4_define([opendht_minor_version], 0) +m4_define([opendht_patch_version], 0) +m4_define([opendht_version], + [opendht_major_version.opendht_minor_version.opendht_patch_version]) + +AC_INIT(opendht, [opendht_version]) +AC_CONFIG_AUX_DIR(ac) +AM_INIT_AUTOMAKE([foreign subdir-objects]) +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_MACRO_DIR([m4]) +AC_CANONICAL_HOST + +AC_SUBST(OPENDHT_MAJOR_VERSION, opendht_major_version) +AC_SUBST(OPENDHT_MINOR_VERSION, opendht_minor_version) +AC_SUBST(OPENDHT_PATCH_VERSION, opendht_patch_version) + +AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [Build in debug mode, adds stricter warnings, disables optimization])) +AS_IF([test "x$enable_debug" = "xyes"], + [CXXFLAGS="${CXXFLAGS} -g -Og -Wno-return-type -Wall -Wextra -Wnon-virtual-dtor -Wno-deprecated -pedantic-errors"], + [CXXFLAGS="${CXXFLAGS} -O3 -Wno-deprecated -pedantic-errors -fvisibility=hidden"]) + +CPPFLAGS+=" -DOPENDHT_BUILD" +AM_CONDITIONAL([OPENDHT_SHARED], [test "x$enable_shared" != xno]) +AM_COND_IF(OPENDHT_SHARED, [ + CPPFLAGS+=" -Dopendht_EXPORTS" +]) + +AM_PROG_AR +LT_INIT() +LT_LANG(C++) +AC_LANG(C++) +AC_PROG_CXX +AX_CXX_COMPILE_STDCXX(17,[noext],[mandatory]) + +dnl Check for C binding +AC_ARG_ENABLE([c], [AS_HELP_STRING([--disable-c], [Disable DHT C binding])]) +AM_CONDITIONAL(ENABLE_C, test x$enable_c != "xno") +AM_COND_IF(ENABLE_C, [ + AC_DEFINE([OPENDHT_C], [], [Define if DHT C biding is enabled]) +]) + +dnl Check for indexation +AC_ARG_ENABLE([indexation], [AS_HELP_STRING([--disable-indexation], [Disable DHT indexation])]) +AM_CONDITIONAL(ENABLE_INDEXATION, test x$enable_indexation != "xno") +AM_COND_IF(ENABLE_INDEXATION, [ + AC_DEFINE([OPENDHT_INDEXATION], [], [Define if DHT indexation is enabled]) +]) + +AC_ARG_ENABLE([peer-discovery], [AS_HELP_STRING([--disable-peer-discovery], [Disable peer-discovery])]) +AM_CONDITIONAL(ENABLE_PEER_DISCOVERY, test x$enable_peer_discovery != "xno") +AM_COND_IF(ENABLE_PEER_DISCOVERY, [AC_DEFINE([OPENDHT_PEER_DISCOVERY], [], [Define if peer discovery is enabled])]) + +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])]) +]) +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])]) + ]) + ]) +AM_CONDITIONAL([USE_CYTHON], [test -n "$CYTHON"]) +AM_CONDITIONAL([HAVE_PIP], [test -n "$PIP"]) + +case "${host_os}" in + "") + SYS=unknown + ;; + *android*) + SYS=android + ;; + linux*) + SYS=linux + ;; + darwin*) + SYS=darwin + ;; + mingw32*) + SYS=mingw32 + WIN32=1 + AC_DEFINE([_POSIX_SOURCE], [1], [IEEE Std 1003.1.]) + AC_DEFINE([_POSIX_C_SOURCE], [200809L], [IEEE Std 1003.1.]) + AC_DEFINE([_XOPEN_SOURCE], [700], [POSIX and XPG 7th edition]) + AC_DEFINE([_XOPEN_SOURCE_EXTENDED], [1], [XPG things and X/Open Unix extensions.]) + AC_DEFINE([_BSD_SOURCE], [1], [ISO C, POSIX, and 4.3BSD things.]) + LDFLAGS="${LDFLAGS} -lws2_32" + AC_SUBST(WINDOWS_ARCH) + AC_SUBST(PROGRAMFILES) + ;; + *) + SYS="${host_os}" + ;; +esac + +AM_CONDITIONAL(WIN32, [test "x$SYS" = "xmingw32"]) +AS_IF([test "x$SYS" = "xandroid"], + [], [LDFLAGS="${LDFLAGS} -lpthread"]) + +PKG_PROG_PKG_CONFIG() + +AC_ARG_ENABLE([proxy_server], AS_HELP_STRING([--enable-proxy-server], [Enable proxy server ability]), proxy_server=yes, proxy_server=no) +AM_CONDITIONAL(ENABLE_PROXY_SERVER, test x$proxy_server == xyes) + +AC_ARG_ENABLE([push_notifications], AS_HELP_STRING([--enable-push-notifications], [Enable push notifications support]), push_notifications=yes, push_notifications=no) +AM_CONDITIONAL(ENABLE_PUSH_NOTIFICATIONS, test x$push_notifications == xyes) + +AC_ARG_ENABLE([proxy_server_identity], AS_HELP_STRING([--enable-proxy-server-identity], + [Enable proxy server ability]), proxy_server_identity=yes, proxy_server_identity=no) +AM_CONDITIONAL(ENABLE_PROXY_SERVER_IDENTITY, test x$proxy_server_identity == xyes -a x$proxy_server == xyes) +AC_ARG_ENABLE([proxy_server_identity], AS_HELP_STRING([--enable-proxy-server-identity], + [Enable proxy server ability]), proxy_server_identity=yes, proxy_server_identity=no) + +AC_ARG_ENABLE([proxy_client], AS_HELP_STRING([--enable-proxy-client], [Enable proxy client ability]), proxy_client=yes, proxy_client=no) +AM_CONDITIONAL(ENABLE_PROXY_CLIENT, test x$proxy_client == xyes) + +AC_ARG_ENABLE([tests], AS_HELP_STRING([--enable-tests], [Enable tests]), build_tests=yes, build_tests=no) +AM_CONDITIONAL(ENABLE_TESTS, test "x$build_tests" == xyes) +AS_IF([test "x$build_tests" == xyes], [ + PKG_CHECK_MODULES([CppUnit], [cppunit >= 1.12]) +]) + +AM_CONDITIONAL(PROXY_CLIENT_OR_SERVER, test x$proxy_client == xyes || test x$proxy_server == xyes) + +PKG_CHECK_MODULES([Nettle], [nettle >= 2.4]) +PKG_CHECK_MODULES([GnuTLS], [gnutls >= 3.3]) +AC_CHECK_HEADERS([msgpack.hpp], [], [ + PKG_CHECK_MODULES([MsgPack], [msgpack >= 1.2]) +]) +PKG_CHECK_MODULES([Argon2], [libargon2]) +AC_SUBST(argon2_lib, [", libargon2"]) + +AC_ARG_WITH([jsoncpp], AS_HELP_STRING([--without-jsoncpp], [Build without JsonCpp support])) +AS_IF([test "x$with_jsoncpp" != "xno"], + [PKG_CHECK_MODULES([JsonCpp], [jsoncpp >= 1.7.2], [have_jsoncpp=yes], [have_jsoncpp=no])], + [have_jsoncpp=no]) +AS_IF([test "x$have_jsoncpp" = "xyes"], [ + AC_MSG_NOTICE([Using JsonCpp]) + CPPFLAGS+=" -DOPENDHT_JSONCPP" + AC_SUBST(jsoncpp_lib, [", jsoncpp"]) +], [ + AC_MSG_NOTICE([Not using JsonCpp]) + 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])) +AS_IF([test "x$with_openssl" != "xno"], + [PKG_CHECK_MODULES([OpenSSL], [openssl >= 1.1], [have_openssl=yes], [have_openssl=no])], + [have_openssl=no]) +AS_IF([test "x$have_openssl" = "xyes"], [ + AC_MSG_NOTICE([Using OpenSSL]) + AC_SUBST(openssl_lib, [", openssl"]) +], [ + AC_MSG_NOTICE([Not using OpenSSL]) +]) + +PKG_CHECK_MODULES([Fmt], [fmt >= 5.3.0], [have_fmt=yes], [have_fmt=no]) +AS_IF([test "x$have_fmt" = "xyes"], [ + AC_MSG_NOTICE([Using libfmt]) +], [ + AC_MSG_NOTICE([Missing libfmt files]) +]) + +AM_COND_IF([PROXY_CLIENT_OR_SERVER], [ + AC_CHECK_HEADERS([asio.hpp],, AC_MSG_ERROR([Missing Asio headers files])) + CXXFLAGS="${CXXFLAGS} -DASIO_STANDALONE" + # http_parser has no pkgconfig, instead we check with: + AC_CHECK_LIB(http_parser, exit,, AC_MSG_ERROR([Missing HttpParser library files])) + AC_CHECK_HEADERS([http_parser.h], [http_parser_headers=yes; break;]) + AC_SUBST(http_parser_lib, ["-lhttp_parser"]) + AS_IF([test "x$http_parser_headers" != "xyes"], AC_MSG_ERROR([Missing HttpParser headers files])) +]) + +CXXFLAGS="${CXXFLAGS} -DMSGPACK_NO_BOOST -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT" + +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]) + ]) +]) + +AM_COND_IF(ENABLE_PROXY_SERVER, AC_DEFINE([OPENDHT_PROXY_SERVER], [], [Building with proxy server])) +AM_COND_IF(ENABLE_PROXY_CLIENT, AC_DEFINE([OPENDHT_PROXY_CLIENT], [], [Building with proxy client])) +AM_COND_IF(ENABLE_PUSH_NOTIFICATIONS, [CPPFLAGS+=" -DOPENDHT_PUSH_NOTIFICATIONS"], []) +AM_COND_IF(ENABLE_PROXY_SERVER_IDENTITY, [CPPFLAGS+=" -DOPENDHT_PROXY_SERVER_IDENTITY"], []) + +dnl Configure setup.py if we build the python module +AC_SUBST(CURRENT_SOURCE_DIR, ".") +AC_SUBST(CURRENT_BINARY_DIR, ".") +AC_SUBST(PROJECT_SOURCE_DIR, "..") +AC_SUBST(PROJECT_BINARY_DIR, "../src/.libs") + +AC_CONFIG_FILES([Makefile + src/Makefile + c/Makefile + tools/Makefile + python/Makefile + python/setup.py + tests/Makefile + doc/Makefile + doc/Doxyfile + opendht.pc]) +AC_OUTPUT diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt new file mode 100644 index 0000000..681cb28 --- /dev/null +++ b/doc/CMakeLists.txt @@ -0,0 +1,16 @@ +if (OPENDHT_TOOLS) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dhtnode.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1) +endif () + +if (OPENDHT_DOCUMENTATION) + if (NOT DOXYGEN_FOUND) + message(FATAL_ERROR "Doxygen is needed to build the documentation.") + endif() + configure_file (Doxyfile.in Doxyfile @ONLY) + add_custom_target(doc ALL + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating API documentation with Doxygen" + VERBATIM) + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc/opendht) +endif() diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in new file mode 100644 index 0000000..19dfa98 --- /dev/null +++ b/doc/Doxyfile.in @@ -0,0 +1,983 @@ +# Doxyfile 1.8.9.1 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for this project. + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +DOXYFILE_ENCODING = UTF-8 + +PROJECT_NAME = @PACKAGE_NAME@ +PROJECT_NUMBER = @PACKAGE_VERSION@ +PROJECT_BRIEF = "C++ Distributed Hash Table" +PROJECT_LOGO = + +OUTPUT_DIRECTORY = +CREATE_SUBDIRS = NO +ALLOW_UNICODE_NAMES = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +QT_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 4 +ALIASES = +TCL_SUBST = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +OPTIMIZE_FOR_FORTRAN = NO +OPTIMIZE_OUTPUT_VHDL = NO +EXTENSION_MAPPING = +MARKDOWN_SUPPORT = YES +AUTOLINK_SUPPORT = YES +BUILTIN_STL_SUPPORT = YES +CPP_CLI_SUPPORT = NO +SIP_SUPPORT = NO +IDL_PROPERTY_SUPPORT = YES +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +INLINE_GROUPED_CLASSES = NO +INLINE_SIMPLE_STRUCTS = NO +TYPEDEF_HIDES_STRUCT = NO +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_PACKAGE = NO +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +EXTRACT_ANON_NSPACES = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +HIDE_COMPOUND_REFERENCE= NO +SHOW_INCLUDE_FILES = YES +SHOW_GROUPED_MEMB_INC = NO +FORCE_LOCAL_INCLUDES = NO +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_MEMBERS_CTORS_1ST = NO +SORT_GROUP_NAMES = NO +SORT_BY_SCOPE_NAME = NO +STRICT_PROTO_MATCHING = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_FILES = YES +SHOW_NAMESPACES = YES +FILE_VERSION_FILTER = +LAYOUT_FILE = +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +QUIET = YES +WARNINGS = YES +WARN_IF_UNDOCUMENTED = NO +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +INPUT = @top_srcdir@/include +INPUT_ENCODING = UTF-8 +FILE_PATTERNS = *.cpp *.h +RECURSIVE = YES + +EXCLUDE = @top_srcdir@/include/opendht/serialize.h +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXCLUDE_SYMBOLS = + +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO + +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +FILTER_SOURCE_PATTERNS = +USE_MDFILE_AS_MAINPAGE = + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = YES +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +REFERENCES_LINK_SOURCE = YES +SOURCE_TOOLTIPS = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +CLANG_ASSISTED_PARSING = NO +CLANG_OPTIONS = + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output +# The default value is: YES. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a colorwheel, see +# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use grayscales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to NO can help when comparing the output of multiple runs. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_TIMESTAMP = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: http://developer.apple.com/tools/xcode/), introduced with +# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a +# Makefile in the HTML output directory. Running make will produce the docset in +# that directory and running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = com.savoirfairelinux + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Savoir-faire Linux + +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# Windows. +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = NO + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = + +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the master .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = NO + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- +# folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = doc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location of Qt's +# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the +# generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine-tune the look of the index. As an example, the default style +# sheet generated by doxygen has an example that shows how to put an image at +# the root of the tree instead of the PROJECT_NAME. Since the tree basically has +# the same information as the tab index, you could consider setting +# DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 250 + +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# http://www.mathjax.org) which uses client side Javascript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. See the MathJax site (see: +# http://docs.mathjax.org/en/latest/output.html) for more details. +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility), NativeMML (i.e. MathML) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from http://www.mathjax.org before deployment. +# The default value is: http://cdn.mathjax.org/mathjax/latest. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /