diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d8a743..b9f644c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,12 +15,16 @@ jobs: target: - os: linux cpu: amd64 + tests: all - os: macos cpu: amd64 + tests: all - os: windows cpu: amd64 - #- os: windows - #cpu: i386 + tests: part1 + - os: windows + cpu: amd64 + tests: part2 branch: [version-1-6] include: - target: @@ -33,7 +37,7 @@ jobs: shell: bash - target: os: windows - builder: windows-2019 + builder: windows-latest shell: msys2 {0} defaults: @@ -49,37 +53,6 @@ jobs: with: submodules: true - - name: Install build dependencies (Linux i386) - if: runner.os == 'Linux' && matrix.target.cpu == 'i386' - run: | - sudo dpkg --add-architecture i386 - sudo apt-get update -qq - sudo DEBIAN_FRONTEND='noninteractive' apt-get install \ - --no-install-recommends -yq gcc-multilib g++-multilib \ - libssl-dev:i386 - mkdir -p external/bin - cat << EOF > external/bin/gcc - #!/bin/bash - exec $(which gcc) -m32 "\$@" - EOF - cat << EOF > external/bin/g++ - #!/bin/bash - exec $(which g++) -m32 "\$@" - EOF - chmod 755 external/bin/gcc external/bin/g++ - echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH - - - name: MSYS2 (Windows i386) - if: runner.os == 'Windows' && matrix.target.cpu == 'i386' - uses: msys2/setup-msys2@v2 - with: - path-type: inherit - msystem: MINGW32 - install: >- - base-devel - git - mingw-w64-i686-toolchain - - name: MSYS2 (Windows amd64) if: runner.os == 'Windows' && matrix.target.cpu == 'amd64' uses: msys2/setup-msys2@v2 @@ -89,7 +62,6 @@ jobs: base-devel git mingw-w64-x86_64-toolchain - - name: Restore Nim DLLs dependencies (Windows) from cache if: runner.os == 'Windows' id: windows-dlls-cache @@ -106,48 +78,21 @@ jobs: mkdir external curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip 7z x external/windeps.zip -oexternal/dlls - - name: Path to cached dependencies (Windows) if: > runner.os == 'Windows' run: | echo '${{ github.workspace }}'"/external/dlls" >> $GITHUB_PATH - - name: Derive environment variables - run: | - if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then - PLATFORM=x64 - else - PLATFORM=x86 - fi - echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV - - ncpu= - MAKE_CMD="make" - case '${{ runner.os }}' in - 'Linux') - ncpu=$(nproc) - ;; - 'macOS') - ncpu=$(sysctl -n hw.ncpu) - ;; - 'Windows') - ncpu=$NUMBER_OF_PROCESSORS - MAKE_CMD="mingw32-make" - ;; - esac - [[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1 - echo "ncpu=$ncpu" >> $GITHUB_ENV - echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV - + ## Restore nimble deps - name: Restore nimble dependencies from cache id: nimble_deps uses: actions/cache@v3 with: path: | - ~/.nimble/pkgs2 - ~/.nimble/packages_official.json - key: ${{ inputs.os }}-${{ inputs.cpu }}-${{ env.cache_nonce }} + ~/.nimble + ${{ github.workspace }}/.nimble + key: ${{ matrix.target.os }}-${{ matrix.target.cpu }}-dotnimble-${{ hashFiles('nimble.lock') }} - name: Setup Nimble uses: "./.github/actions/install_nimble" @@ -155,16 +100,35 @@ jobs: os: ${{ matrix.target.os }} cpu: ${{ matrix.target.cpu }} - - name: Run tests + - name: Setup Env + run: | + nimble -v + + - name: Setup Deps + run: | + nimble install -d + nimble setup + + - name: Run tests + if: runner.os != 'Windows' + run: | + nimble test -y + + - name: Run windows tests part1 + if: runner.os == 'Windows' && matrix.target.tests == 'part1' run: | - rm -rf ~/.nimble/ if [[ "${{ matrix.target.os }}" == "windows" ]]; then # https://github.com/status-im/nimbus-eth2/issues/3121 export NIMFLAGS="-d:nimRawSetjmp" fi - nimble test -y - if [[ "${{ matrix.branch }}" == "version-1-6" || "${{ matrix.branch }}" == "devel" ]]; then - echo -e "\nTesting with '--gc:orc':\n" - export NIMFLAGS="${NIMFLAGS} --gc:orc" - nimble test -y - fi; + + nimble testPart1 -y + + - name: Run windows tests part2 + if: runner.os == 'Windows' && matrix.target.tests == 'part2' + run: | + if [[ "${{ matrix.target.os }}" == "windows" ]]; then + export NIMFLAGS="-d:nimRawSetjmp" + fi + + nimble testPart2 -y diff --git a/.gitignore b/.gitignore index e36a278..9eaaf60 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,14 @@ +* +!*.* +!*/ coverage nimcache tests/testAll nimble.develop nimble.paths +nim.cfg +nimbus-build-system.paths +vendor/* +NimBinaries +.update.timestamp +*.dSYM diff --git a/README.md b/README.md index 780f686..805008a 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,26 @@ This DHT implementation is aiming to provide a DHT for Codex with the following Current implementation is based on nim-eth's Discovery v5 implementation. Base files were copied from [`status-im/nim-eth@779d767b024175a51cf74c79ec7513301ebe2f46`](https://github.com/status-im/nim-eth/commit/779d767b024175a51cf74c79ec7513301ebe2f46) + +## Building + +This repo is setup to use Nimble lockfiles. This requires Nimble 0.14+ which isn't installed by default when this was written. If `nimble -v` reports `0.13.x` then you will need to install Nimble 0.14. Note that using Nimble 0.14 changes how Nimble behaves! + +Nimble 0.14 can be install by: + +```sh +nimble install nimble@0.14.2 +``` + +After this you can setup your Nimble environment. Note that this will build the pinned version of Nim! The first run can take ~15 minutes. + +```sh +nimble setup # creates a nimble.paths used for rest of Nimble commands +nimble testAll +``` + +You can also run tasks directly: + +```sh +nim testAll +``` diff --git a/atlas.lock b/atlas.lock new file mode 100644 index 0000000..f672e7f --- /dev/null +++ b/atlas.lock @@ -0,0 +1,143 @@ +{ + "items": { + "nimbus-build-system": { + "dir": "vendor/nimbus-build-system", + "url": "https://github.com/status-im/nimbus-build-system", + "commit": "239c3a7fbb88fd241da0ade3246fd2e5fcff4f25" + }, + "nim-nat-traversal": { + "dir": "vendor/nim-nat-traversal", + "url": "https://github.com/status-im/nim-nat-traversal", + "commit": "802d75edcc656e616120fb27f950ff1285ddcbba" + }, + "nim-zlib": { + "dir": "vendor/nim-zlib", + "url": "https://github.com/status-im/nim-zlib", + "commit": "f34ca261efd90f118dc1647beefd2f7a69b05d93" + }, + "nim-stew": { + "dir": "vendor/nim-stew", + "url": "https://github.com/status-im/nim-stew.git", + "commit": "e18f5a62af2ade7a1fd1d39635d4e04d944def08" + }, + "nim-http-utils": { + "dir": "vendor/nim-http-utils", + "url": "https://github.com/status-im/nim-http-utils.git", + "commit": "3b491a40c60aad9e8d3407443f46f62511e63b18" + }, + "nim-chronos": { + "dir": "vendor/nim-chronos", + "url": "https://github.com/status-im/nim-chronos.git", + "commit": "6525f4ce1d1a7eba146e5f1a53f6f105077ae686" + }, + "upraises": { + "dir": "vendor/upraises", + "url": "https://github.com/markspanbroek/upraises.git", + "commit": "bc2628989b63854d980e92dadbd58f83e34b6f25" + }, + "nim-sqlite3-abi": { + "dir": "vendor/nim-sqlite3-abi", + "url": "https://github.com/arnetheduck/nim-sqlite3-abi.git", + "commit": "362e1bd9f689ad9f5380d9d27f0705b3d4dfc7d3" + }, + "questionable": { + "dir": "vendor/questionable", + "url": "https://github.com/status-im/questionable.git", + "commit": "0d7ce8efdedaf184680cb7268721fca0af947a74" + }, + "nim-websock": { + "dir": "vendor/nim-websock", + "url": "https://github.com/status-im/nim-websock.git", + "commit": "2c3ae3137f3c9cb48134285bd4a47186fa51f0e8" + }, + "nim-secp256k1": { + "dir": "vendor/nim-secp256k1", + "url": "https://github.com/status-im/nim-secp256k1.git", + "commit": "5340cf188168d6afcafc8023770d880f067c0b2f" + }, + "nim-bearssl": { + "dir": "vendor/nim-bearssl", + "url": "https://github.com/status-im/nim-bearssl.git", + "commit": "f4c4233de453cb7eac0ce3f3ffad6496295f83ab" + }, + "dnsclient.nim": { + "dir": "vendor/dnsclient.nim", + "url": "https://github.com/ba0f3/dnsclient.nim", + "commit": "23214235d4784d24aceed99bbfe153379ea557c8" + }, + "nimcrypto": { + "dir": "vendor/nimcrypto", + "url": "https://github.com/status-im/nimcrypto.git", + "commit": "a5742a9a214ac33f91615f3862c7b099aec43b00" + }, + "nim-json-serialization": { + "dir": "vendor/nim-json-serialization", + "url": "https://github.com/status-im/nim-json-serialization.git", + "commit": "e5b18fb710c3d0167ec79f3b892f5a7a1bc6d1a4" + }, + "nim-testutils": { + "dir": "vendor/nim-testutils", + "url": "https://github.com/status-im/nim-testutils", + "commit": "b56a5953e37fc5117bd6ea6dfa18418c5e112815" + }, + "nim-unittest2": { + "dir": "vendor/nim-unittest2", + "url": "https://github.com/status-im/nim-unittest2.git", + "commit": "b178f47527074964f76c395ad0dfc81cf118f379" + }, + "npeg": { + "dir": "vendor/npeg", + "url": "https://github.com/zevv/npeg", + "commit": "b15a10e388b91b898c581dbbcb6a718d46b27d2f" + }, + "nim-serialization": { + "dir": "vendor/nim-serialization", + "url": "https://github.com/status-im/nim-serialization.git", + "commit": "493d18b8292fc03aa4f835fd825dea1183f97466" + }, + "nim-faststreams": { + "dir": "vendor/nim-faststreams", + "url": "https://github.com/status-im/nim-faststreams.git", + "commit": "1b561a9e71b6bdad1c1cdff753418906037e9d09" + }, + "nim-datastore": { + "dir": "vendor/nim-datastore", + "url": "https://github.com/codex-storage/nim-datastore.git", + "commit": "0cde8aeb67c59fd0ac95496dc6b5e1168d6632aa" + }, + "asynctest": { + "dir": "vendor/asynctest", + "url": "https://github.com/markspanbroek/asynctest", + "commit": "a236a5f0f3031573ac2cb082b63dbf6e170e06e7" + }, + "nim-stint": { + "dir": "vendor/nim-stint", + "url": "https://github.com/status-im/nim-stint.git", + "commit": "036c71d06a6b22f8f967ba9d54afd2189c3872ca" + }, + "nim-metrics": { + "dir": "vendor/nim-metrics", + "url": "https://github.com/status-im/nim-metrics.git", + "commit": "743f81d4f6c6ebf0ac02389f2392ff8b4235bee5" + }, + "nim-libp2p": { + "dir": "vendor/nim-libp2p", + "url": "https://github.com/status-im/nim-libp2p.git", + "commit": "a3e9d1ed80c048cd5abc839cbe0863cefcedc702" + }, + "nim-chronicles": { + "dir": "vendor/nim-chronicles", + "url": "https://github.com/status-im/nim-chronicles.git", + "commit": "7631f7b2ee03398cb1512a79923264e8f9410af6" + }, + "nim-protobuf-serialization": { + "dir": "vendor/nim-protobuf-serialization", + "url": "https://github.com/status-im/nim-protobuf-serialization", + "commit": "28214b3e40c755a9886d2ec8f261ec48fbb6bec6" + } + }, + "nimcfg": "############# begin Atlas config section ##########\n--noNimblePath\n--path:\"vendor/nim-secp256k1\"\n--path:\"vendor/nim-protobuf-serialization\"\n--path:\"vendor/nimcrypto\"\n--path:\"vendor/nim-bearssl\"\n--path:\"vendor/nim-chronicles\"\n--path:\"vendor/nim-chronos\"\n--path:\"vendor/nim-libp2p\"\n--path:\"vendor/nim-metrics\"\n--path:\"vendor/nim-stew\"\n--path:\"vendor/nim-stint\"\n--path:\"vendor/asynctest\"\n--path:\"vendor/nim-datastore\"\n--path:\"vendor/questionable\"\n--path:\"vendor/nim-faststreams\"\n--path:\"vendor/nim-serialization\"\n--path:\"vendor/npeg/src\"\n--path:\"vendor/nim-unittest2\"\n--path:\"vendor/nim-testutils\"\n--path:\"vendor/nim-json-serialization\"\n--path:\"vendor/nim-http-utils\"\n--path:\"vendor/dnsclient.nim/src\"\n--path:\"vendor/nim-websock\"\n--path:\"vendor/nim-sqlite3-abi\"\n--path:\"vendor/upraises\"\n--path:\"vendor/nim-zlib\"\n############# end Atlas config section ##########\n", + "nimVersion": "1.6.14", + "gccVersion": "", + "clangVersion": "" +} diff --git a/libp2pdht.nimble b/build.nims similarity index 51% rename from libp2pdht.nimble rename to build.nims index 29712ca..164c795 100644 --- a/libp2pdht.nimble +++ b/build.nims @@ -1,28 +1,18 @@ -# Package +import std / [os, strutils, sequtils] -version = "0.1.0" -author = "Status Research & Development GmbH" -description = "DHT based on the libp2p Kademlia spec" -license = "MIT" -skipDirs = @["tests"] +switch("define", "libp2p_pki_schemes=secp256k1") +task testAll, "Run DHT tests": + exec "nim c -r tests/testAll.nim" -# TODO: fix versions after tagging the version in the corresponding package -# Dependencies -requires "nim >= 1.2.0" -requires "secp256k1#b3f38e2795e805743b299dc5d96d332db375b520" # >= 0.5.2 & < 0.6.0 -requires "protobuf_serialization#27b400fdf3bd8ce7120ca66fc1de39d3f1a5804a" # >= 0.2.0 & < 0.3.0 -requires "nimcrypto == 0.5.4" -requires "bearssl#head" -requires "chronicles >= 0.10.2 & < 0.11.0" -requires "chronos#1394c9e04957928afc1db33d2e0965cfb677a1e0" # >= 3.0.11 & < 3.1.0 -requires "libp2p#unstable" -requires "metrics" -requires "stew#head" -requires "stint" -requires "asynctest >= 0.3.1 & < 0.4.0" -requires "https://github.com/status-im/nim-datastore#head" -requires "questionable" +task test, "Run DHT tests": + exec "nim c -r -d:testsAll --verbosity:0 tests/testAllParallel.nim" + +task testPart1, "Run DHT tests A": + exec "nim c -r -d:testsPart1 tests/testAllParallel.nim" + +task testPart2, "Run DHT tests B": + exec "nim c -r -d:testsPart2 tests/testAllParallel.nim" task coverage, "generates code coverage report": var (output, exitCode) = gorgeEx("which lcov") @@ -50,14 +40,19 @@ task coverage, "generates code coverage report": echo " *****************************************************************" echo "" - exec("nimble --verbose test --opt:speed -d:debug --verbosity:0 --hints:off --lineDir:on -d:chronicles_log_level=INFO --nimcache:nimcache --passC:-fprofile-arcs --passC:-ftest-coverage --passL:-fprofile-arcs --passL:-ftest-coverage") - exec("cd nimcache; rm *.c; cd ..") - mkDir("coverage") + var nimSrcs = "" + for f in walkDirRec(".", {pcFile}): + if f.endswith(".nim"): nimSrcs.add " " & f.quoteShell() + + echo "======== Running Tests ======== " + exec("nim c -r tests/coverage.nim") + # exec("rm nimcache/*.c") + rmDir("coverage"); mkDir("coverage") + echo " ======== Running LCOV ======== " exec("lcov --capture --directory nimcache --output-file coverage/coverage.info") - exec("$(which bash) -c 'shopt -s globstar; ls $(pwd)/libp2pdht/{*,**/*}.nim'") - exec("$(which bash) -c 'shopt -s globstar; lcov --extract coverage/coverage.info $(pwd)/libp2pdht/{*,**/*}.nim --output-file coverage/coverage.f.info'") - echo "Generating HTML coverage report" - exec("genhtml coverage/coverage.f.info --output-directory coverage/report") - echo "Opening HTML coverage report in browser..." + exec("lcov --extract coverage/coverage.info --output-file coverage/coverage.f.info " & nimSrcs) + echo " ======== Generating HTML coverage report ======== " + exec("genhtml coverage/coverage.f.info --output-directory coverage/report ") + echo " ======== Opening HTML coverage report in browser... ======== " exec("open coverage/report/index.html") diff --git a/codexdht.nim b/codexdht.nim new file mode 100644 index 0000000..a4a4a9d --- /dev/null +++ b/codexdht.nim @@ -0,0 +1,5 @@ +import + ./codexdht/dht, + ./codexdht/discv5 + +export dht, discv5 diff --git a/codexdht.nimble b/codexdht.nimble new file mode 100644 index 0000000..25df1ef --- /dev/null +++ b/codexdht.nimble @@ -0,0 +1,28 @@ +# Package + +version = "0.3.1" +author = "Status Research & Development GmbH" +description = "DHT based on the libp2p Kademlia spec" +license = "MIT" +skipDirs = @["tests"] + + +# Dependencies +requires "nim >= 1.2.0" +requires "secp256k1#b3f38e2795e805743b299dc5d96d332db375b520" # >= 0.5.2 & < 0.6.0 +requires "protobuf_serialization#27b400fdf3bd8ce7120ca66fc1de39d3f1a5804a" # >= 0.2.0 & < 0.3.0 +requires "nimcrypto == 0.5.4" +requires "bearssl#head" +requires "chronicles >= 0.10.2 & < 0.11.0" +requires "chronos#1394c9e04957928afc1db33d2e0965cfb677a1e0" # >= 3.0.11 & < 3.1.0 +requires "libp2p#unstable" +requires "metrics" +requires "stew#head" +requires "stint" +requires "asynctest >= 0.3.1 & < 0.4.0" +requires "https://github.com/status-im/nim-datastore#head" +requires "questionable" + +include "build.nims" + + diff --git a/libp2pdht/dht.nim b/codexdht/dht.nim similarity index 100% rename from libp2pdht/dht.nim rename to codexdht/dht.nim diff --git a/libp2pdht/dht/providers_encoding.nim b/codexdht/dht/providers_encoding.nim similarity index 100% rename from libp2pdht/dht/providers_encoding.nim rename to codexdht/dht/providers_encoding.nim diff --git a/libp2pdht/dht/providers_messages.nim b/codexdht/dht/providers_messages.nim similarity index 100% rename from libp2pdht/dht/providers_messages.nim rename to codexdht/dht/providers_messages.nim diff --git a/libp2pdht/discv5.nim b/codexdht/discv5.nim similarity index 100% rename from libp2pdht/discv5.nim rename to codexdht/discv5.nim diff --git a/libp2pdht/discv5/crypto.nim b/codexdht/discv5/crypto.nim similarity index 100% rename from libp2pdht/discv5/crypto.nim rename to codexdht/discv5/crypto.nim diff --git a/libp2pdht/discv5/encoding.nim b/codexdht/discv5/encoding.nim similarity index 100% rename from libp2pdht/discv5/encoding.nim rename to codexdht/discv5/encoding.nim diff --git a/libp2pdht/discv5/messages.nim b/codexdht/discv5/messages.nim similarity index 100% rename from libp2pdht/discv5/messages.nim rename to codexdht/discv5/messages.nim diff --git a/libp2pdht/discv5/messages_encoding.nim b/codexdht/discv5/messages_encoding.nim similarity index 100% rename from libp2pdht/discv5/messages_encoding.nim rename to codexdht/discv5/messages_encoding.nim diff --git a/libp2pdht/discv5/node.nim b/codexdht/discv5/node.nim similarity index 100% rename from libp2pdht/discv5/node.nim rename to codexdht/discv5/node.nim diff --git a/libp2pdht/discv5/nodes_verification.nim b/codexdht/discv5/nodes_verification.nim similarity index 100% rename from libp2pdht/discv5/nodes_verification.nim rename to codexdht/discv5/nodes_verification.nim diff --git a/libp2pdht/discv5/protocol.nim b/codexdht/discv5/protocol.nim similarity index 100% rename from libp2pdht/discv5/protocol.nim rename to codexdht/discv5/protocol.nim diff --git a/libp2pdht/discv5/routing_table.nim b/codexdht/discv5/routing_table.nim similarity index 100% rename from libp2pdht/discv5/routing_table.nim rename to codexdht/discv5/routing_table.nim diff --git a/libp2pdht/discv5/sessions.nim b/codexdht/discv5/sessions.nim similarity index 100% rename from libp2pdht/discv5/sessions.nim rename to codexdht/discv5/sessions.nim diff --git a/libp2pdht/discv5/spr.nim b/codexdht/discv5/spr.nim similarity index 100% rename from libp2pdht/discv5/spr.nim rename to codexdht/discv5/spr.nim diff --git a/libp2pdht/discv5/transport.nim b/codexdht/discv5/transport.nim similarity index 100% rename from libp2pdht/discv5/transport.nim rename to codexdht/discv5/transport.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/crypto.nim b/codexdht/private/eth/p2p/discoveryv5/crypto.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/crypto.nim rename to codexdht/private/eth/p2p/discoveryv5/crypto.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/encoding.nim b/codexdht/private/eth/p2p/discoveryv5/encoding.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/encoding.nim rename to codexdht/private/eth/p2p/discoveryv5/encoding.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/hkdf.nim b/codexdht/private/eth/p2p/discoveryv5/hkdf.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/hkdf.nim rename to codexdht/private/eth/p2p/discoveryv5/hkdf.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/ip_vote.nim b/codexdht/private/eth/p2p/discoveryv5/ip_vote.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/ip_vote.nim rename to codexdht/private/eth/p2p/discoveryv5/ip_vote.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/lru.nim b/codexdht/private/eth/p2p/discoveryv5/lru.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/lru.nim rename to codexdht/private/eth/p2p/discoveryv5/lru.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/messages.nim b/codexdht/private/eth/p2p/discoveryv5/messages.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/messages.nim rename to codexdht/private/eth/p2p/discoveryv5/messages.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/messages_encoding.nim b/codexdht/private/eth/p2p/discoveryv5/messages_encoding.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/messages_encoding.nim rename to codexdht/private/eth/p2p/discoveryv5/messages_encoding.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/node.nim b/codexdht/private/eth/p2p/discoveryv5/node.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/node.nim rename to codexdht/private/eth/p2p/discoveryv5/node.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/nodes_verification.nim b/codexdht/private/eth/p2p/discoveryv5/nodes_verification.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/nodes_verification.nim rename to codexdht/private/eth/p2p/discoveryv5/nodes_verification.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/protocol.nim b/codexdht/private/eth/p2p/discoveryv5/protocol.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/protocol.nim rename to codexdht/private/eth/p2p/discoveryv5/protocol.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/providers.nim b/codexdht/private/eth/p2p/discoveryv5/providers.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/providers.nim rename to codexdht/private/eth/p2p/discoveryv5/providers.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/providers/cache.nim b/codexdht/private/eth/p2p/discoveryv5/providers/cache.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/providers/cache.nim rename to codexdht/private/eth/p2p/discoveryv5/providers/cache.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/providers/common.nim b/codexdht/private/eth/p2p/discoveryv5/providers/common.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/providers/common.nim rename to codexdht/private/eth/p2p/discoveryv5/providers/common.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/providers/maintenance.nim b/codexdht/private/eth/p2p/discoveryv5/providers/maintenance.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/providers/maintenance.nim rename to codexdht/private/eth/p2p/discoveryv5/providers/maintenance.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/providers/manager.nim b/codexdht/private/eth/p2p/discoveryv5/providers/manager.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/providers/manager.nim rename to codexdht/private/eth/p2p/discoveryv5/providers/manager.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/random2.nim b/codexdht/private/eth/p2p/discoveryv5/random2.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/random2.nim rename to codexdht/private/eth/p2p/discoveryv5/random2.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/routing_table.nim b/codexdht/private/eth/p2p/discoveryv5/routing_table.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/routing_table.nim rename to codexdht/private/eth/p2p/discoveryv5/routing_table.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/sessions.nim b/codexdht/private/eth/p2p/discoveryv5/sessions.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/sessions.nim rename to codexdht/private/eth/p2p/discoveryv5/sessions.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/spr.nim b/codexdht/private/eth/p2p/discoveryv5/spr.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/spr.nim rename to codexdht/private/eth/p2p/discoveryv5/spr.nim diff --git a/libp2pdht/private/eth/p2p/discoveryv5/transport.nim b/codexdht/private/eth/p2p/discoveryv5/transport.nim similarity index 100% rename from libp2pdht/private/eth/p2p/discoveryv5/transport.nim rename to codexdht/private/eth/p2p/discoveryv5/transport.nim diff --git a/config.nims b/config.nims index 068054d..831d5cd 100644 --- a/config.nims +++ b/config.nims @@ -1,4 +1,5 @@ -switch("define", "libp2p_pki_schemes=secp256k1") + +include "build.nims" # begin Nimble config (version 2) --noNimblePath diff --git a/libp2pdht.nim b/libp2pdht.nim deleted file mode 100644 index a907dd1..0000000 --- a/libp2pdht.nim +++ /dev/null @@ -1,5 +0,0 @@ -import - ./libp2pdht/dht, - ./libp2pdht/discv5 - -export dht, discv5 diff --git a/tests/coverage.nim b/tests/coverage.nim new file mode 100644 index 0000000..e9146c9 --- /dev/null +++ b/tests/coverage.nim @@ -0,0 +1,2 @@ + +include ./testAll diff --git a/tests/coverage.nims b/tests/coverage.nims new file mode 100644 index 0000000..f14fce4 --- /dev/null +++ b/tests/coverage.nims @@ -0,0 +1,15 @@ +switch("define", "testsAll") + +switch("debugger", "native") +switch("lineDir", "on") +switch("define", "debug") +# switch("opt", "none") +switch("verbosity", "0") +switch("hints", "off") +switch("warnings", "off") +switch("define", "chronicles_log_level=INFO") +switch("nimcache", "nimcache") +switch("passC", "-fprofile-arcs") +switch("passC", "-ftest-coverage") +switch("passL", "-fprofile-arcs") +switch("passL", "-ftest-coverage") diff --git a/tests/dht/test_helper.nim b/tests/dht/test_helper.nim index 89f5797..38772ca 100644 --- a/tests/dht/test_helper.nim +++ b/tests/dht/test_helper.nim @@ -3,9 +3,9 @@ import chronos, libp2p/crypto/[crypto, secp], libp2p/multiaddress, - libp2pdht/discv5/[node, routing_table, spr], - libp2pdht/discv5/crypto as dhtcrypto, - libp2pdht/discv5/protocol as discv5_protocol, + codexdht/discv5/[node, routing_table, spr], + codexdht/discv5/crypto as dhtcrypto, + codexdht/discv5/protocol as discv5_protocol, stew/shims/net export net @@ -53,7 +53,7 @@ proc nodeIdInNodes*(id: NodeId, nodes: openArray[Node]): bool = for n in nodes: if id == n.id: return true -proc generateNode*(privKey: PrivateKey, port: int = 20302, +proc generateNode*(privKey: PrivateKey, port: int, ip: ValidIpAddress = ValidIpAddress.init("127.0.0.1")): Node = let @@ -67,7 +67,7 @@ proc generateNRandomNodes*(rng: ref HmacDrbgContext, n: int): seq[Node] = for i in 1..n: let privKey = PrivateKey.example(rng) - node = privKey.generateNode() + node = privKey.generateNode(port = 20402 + 10*n) res.add(node) res @@ -76,7 +76,7 @@ proc nodeAndPrivKeyAtDistance*(n: Node, rng: var HmacDrbgContext, d: uint32, while true: let privKey = PrivateKey.random(rng).expect("Valid rng for private key") - node = privKey.generateNode(ip = ip) + node = privKey.generateNode(port = 21302 + 10*d.int, ip = ip) if logDistance(n.id, node.id) == d: return (node, privKey) diff --git a/tests/dht/test_providermngr.nim b/tests/dht/test_providermngr.nim index 7ec742c..ea2456d 100644 --- a/tests/dht/test_providermngr.nim +++ b/tests/dht/test_providermngr.nim @@ -6,11 +6,11 @@ import pkg/asynctest import pkg/datastore import pkg/libp2p -import libp2pdht/dht -import libp2pdht/private/eth/p2p/discoveryv5/spr -import libp2pdht/private/eth/p2p/discoveryv5/providers -import libp2pdht/discv5/node -import libp2pdht/private/eth/p2p/discoveryv5/lru +import codexdht/dht +import codexdht/private/eth/p2p/discoveryv5/spr +import codexdht/private/eth/p2p/discoveryv5/providers +import codexdht/discv5/node +import codexdht/private/eth/p2p/discoveryv5/lru import ./test_helper suite "Test Providers Manager simple": diff --git a/tests/dht/test_providers.nim b/tests/dht/test_providers.nim index fecb9b9..3f01e52 100644 --- a/tests/dht/test_providers.nim +++ b/tests/dht/test_providers.nim @@ -18,9 +18,9 @@ import nimcrypto, libp2p/crypto/[crypto, secp], libp2p/[multiaddress, multicodec, multihash, routing_record, signed_envelope], - libp2pdht/dht, - libp2pdht/discv5/crypto as dhtcrypto, - libp2pdht/discv5/protocol as discv5_protocol, + codexdht/dht, + codexdht/discv5/crypto as dhtcrypto, + codexdht/discv5/protocol as discv5_protocol, stew/byteutils, test_helper @@ -34,7 +34,7 @@ proc bootstrapNodes( debug "---- STARTING BOOSTRAPS ---" for i in 0.. 0: @@ -53,7 +53,7 @@ proc bootstrapNetwork( bootNodeKey = PrivateKey.fromHex( "a2b50376a79b1a8c8a3296485572bdfbf54708bb46d3c25d73d2723aaaf6a617") .expect("Valid private key hex") - bootNodeAddr = localAddress(20301) + bootNodeAddr = localAddress(25311) bootNode = initDiscoveryNode(rng, bootNodeKey, bootNodeAddr, @[]) # just a shortcut for new and open #waitFor bootNode.bootstrap() # immediate, since no bootnodes are defined above diff --git a/tests/discv5/test_discoveryv5.nim b/tests/discv5/test_discoveryv5.nim index ad0066d..1255569 100644 --- a/tests/discv5/test_discoveryv5.nim +++ b/tests/discv5/test_discoveryv5.nim @@ -5,9 +5,9 @@ import chronos, chronicles, stint, asynctest, stew/shims/net, stew/byteutils, bearssl/rand, libp2p/crypto/crypto, - libp2pdht/discv5/[transport, spr, node, routing_table, encoding, sessions, nodes_verification], - libp2pdht/discv5/crypto as dhtcrypto, - libp2pdht/discv5/protocol as discv5_protocol, + codexdht/discv5/[transport, spr, node, routing_table, encoding, sessions, nodes_verification], + codexdht/discv5/crypto as dhtcrypto, + codexdht/discv5/protocol as discv5_protocol, ../dht/test_helper suite "Discovery v5 Tests": @@ -22,13 +22,13 @@ suite "Discovery v5 Tests": pk = PrivateKey.example(rng) targetPk = PrivateKey.example(rng) node = initDiscoveryNode(rng, pk, localAddress(20302)) - targetNode = targetPk.generateNode() + targetNode = targetPk.generateNode(port=26302) check node.addNode(targetNode) for i in 0..<1000: let pk = PrivateKey.example(rng) - discard node.addNode(pk.generateNode()) + discard node.addNode(pk.generateNode(port=27302+i)) let n = node.getNode(targetNode.id) check n.isSome() @@ -265,7 +265,7 @@ suite "Discovery v5 Tests": # Generate 1000 random nodes and add to our main node's routing table for i in 0..<1000: - discard mainNode.addSeenNode(generateNode(PrivateKey.example(rng))) # for testing only! + discard mainNode.addSeenNode(generateNode(PrivateKey.example(rng), port=28302+i)) # for testing only! let neighbours = mainNode.neighbours(mainNode.localNode.id) diff --git a/tests/discv5/test_discoveryv5_encoding.nim b/tests/discv5/test_discoveryv5_encoding.nim index 3eb2380..e2c87bc 100644 --- a/tests/discv5/test_discoveryv5_encoding.nim +++ b/tests/discv5/test_discoveryv5_encoding.nim @@ -6,8 +6,8 @@ import bearssl/rand, chronos, libp2p/crypto/secp, - libp2pdht/discv5/[messages, messages_encoding, encoding, spr, node, sessions], - libp2pdht/discv5/crypto, + codexdht/discv5/[messages, messages_encoding, encoding, spr, node, sessions], + codexdht/discv5/crypto, stew/byteutils, stew/shims/net, stint, @@ -275,12 +275,12 @@ suite "Discovery v5.1 Packet Encodings Test Vectors": let enrRecA = SignedPeerRecord.init(1, privKeyA, - some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)), - some(Port(9000))).expect("Properly intialized private key") + some(ValidIpAddress.init("127.0.0.1")), some(Port(9001)), + some(Port(9001))).expect("Properly intialized private key") enrRecB = SignedPeerRecord.init(1, privKeyB, - some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)), - some(Port(9000))).expect("Properly intialized private key") + some(ValidIpAddress.init("127.0.0.1")), some(Port(9001)), + some(Port(9001))).expect("Properly intialized private key") nodeA = newNode(enrRecA).expect("Properly initialized record") nodeB = newNode(enrRecB).expect("Properly initialized record") @@ -508,12 +508,12 @@ suite "Discovery v5.1 Additional Encode/Decode": let enrRecA = SignedPeerRecord.init(1, privKeyA, - some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)), - some(Port(9000))).expect("Properly intialized private key") + some(ValidIpAddress.init("127.0.0.1")), some(Port(9001)), + some(Port(9001))).expect("Properly intialized private key") enrRecB = SignedPeerRecord.init(1, privKeyB, - some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)), - some(Port(9000))).expect("Properly intialized private key") + some(ValidIpAddress.init("127.0.0.1")), some(Port(9001)), + some(Port(9001))).expect("Properly intialized private key") nodeA = newNode(enrRecA).expect("Properly initialized record") nodeB = newNode(enrRecB).expect("Properly initialized record") diff --git a/tests/testAll.nim b/tests/testAll.nim index f9fc17c..af432e0 100644 --- a/tests/testAll.nim +++ b/tests/testAll.nim @@ -1,5 +1,6 @@ -import - ./dht/[test_providers, test_providermngr], - ./discv5/[test_discoveryv5, test_discoveryv5_encoding] +import ./dht/test_providers +import ./dht/test_providermngr +import ./discv5/test_discoveryv5 +import ./discv5/test_discoveryv5_encoding {.warning[UnusedImport]: off.} diff --git a/tests/testAllParallel.nim b/tests/testAllParallel.nim new file mode 100644 index 0000000..7bff2e1 --- /dev/null +++ b/tests/testAllParallel.nim @@ -0,0 +1,22 @@ +# import +# ./dht/[test_providers, test_providermngr], +# ./discv5/[test_discoveryv5, test_discoveryv5_encoding] + +import osproc + +var cmds: seq[string] + +when defined(testsPart1) or defined(testsAll): + cmds.add [ + "nim c -r tests/dht/test_providers.nim", + "nim c -r tests/dht/test_providermngr.nim", + ] +when defined(testsPart2) or defined(testsAll): + cmds.add [ + "nim c -r tests/discv5/test_discoveryv5.nim", + "nim c -r tests/discv5/test_discoveryv5_encoding.nim", + ] + +echo "Running Test Commands: ", cmds + +quit execProcesses(cmds) diff --git a/vendor/atlas.workspace b/vendor/atlas.workspace new file mode 100644 index 0000000..79173a1 --- /dev/null +++ b/vendor/atlas.workspace @@ -0,0 +1,2 @@ +deps="" +resolver="MaxVer"