From d73dc4851509a064420bfe096702d20469087657 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 9 Dec 2024 12:45:57 +0100 Subject: [PATCH 01/11] Add pragma for exception raises --- codexdht/private/eth/p2p/discoveryv5/protocol.nim | 6 +++--- codexdht/private/eth/p2p/discoveryv5/routing_table.nim | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/codexdht/private/eth/p2p/discoveryv5/protocol.nim b/codexdht/private/eth/p2p/discoveryv5/protocol.nim index 77afee3..6de26c6 100644 --- a/codexdht/private/eth/p2p/discoveryv5/protocol.nim +++ b/codexdht/private/eth/p2p/discoveryv5/protocol.nim @@ -236,18 +236,18 @@ proc getNode*(d: Protocol, id: NodeId): Option[Node] = ## Get the node with id from the routing table. d.routingTable.getNode(id) -proc randomNodes*(d: Protocol, maxAmount: int): seq[Node] = +proc randomNodes*(d: Protocol, maxAmount: int): seq[Node] {.raises: Exception.} = ## Get a `maxAmount` of random nodes from the local routing table. d.routingTable.randomNodes(maxAmount) proc randomNodes*(d: Protocol, maxAmount: int, - pred: proc(x: Node): bool {.gcsafe, noSideEffect.}): seq[Node] = + pred: proc(x: Node): bool {.gcsafe, noSideEffect.}): seq[Node] {.raises: Exception.} = ## Get a `maxAmount` of random nodes from the local routing table with the ## `pred` predicate function applied as filter on the nodes selected. d.routingTable.randomNodes(maxAmount, pred) proc randomNodes*(d: Protocol, maxAmount: int, - enrField: (string, seq[byte])): seq[Node] = + enrField: (string, seq[byte])): seq[Node] {.raises: Exception.} = ## Get a `maxAmount` of random nodes from the local routing table. The ## the nodes selected are filtered by provided `enrField`. d.randomNodes(maxAmount, proc(x: Node): bool = x.record.contains(enrField)) diff --git a/codexdht/private/eth/p2p/discoveryv5/routing_table.nim b/codexdht/private/eth/p2p/discoveryv5/routing_table.nim index edc9e65..4917e90 100644 --- a/codexdht/private/eth/p2p/discoveryv5/routing_table.nim +++ b/codexdht/private/eth/p2p/discoveryv5/routing_table.nim @@ -555,7 +555,7 @@ proc nodeToRevalidate*(r: RoutingTable): Node = return b.nodes[^1] proc randomNodes*(r: RoutingTable, maxAmount: int, - pred: proc(x: Node): bool {.gcsafe, noSideEffect.} = nil): seq[Node] = + pred: proc(x: Node): bool {.gcsafe, noSideEffect.} = nil): seq[Node] {.raises: Exception.} = ## Get a `maxAmount` of random nodes from the routing table with the `pred` ## predicate function applied as filter on the nodes selected. var maxAmount = maxAmount From 9fdf0eca8aea20522220b212d04de0b964c2a022 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 9 Dec 2024 12:47:19 +0100 Subject: [PATCH 02/11] Add Nim 2.x specific configuration --- config.nims | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config.nims b/config.nims index eacae8d..d816c1a 100644 --- a/config.nims +++ b/config.nims @@ -1,2 +1,9 @@ switch("define", "libp2p_pki_schemes=secp256k1") +# begin Nimble config (version 2) +when withDir(thisDir(), system.fileExists("nimble.paths")): + include "nimble.paths" +# end Nimble config + +when (NimMajor, NimMinor) >= (2, 0): + --mm:refc From 570fb9a936f13d5c6c763df4e0df643769cc7217 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 9 Dec 2024 12:47:49 +0100 Subject: [PATCH 03/11] Update dependencies --- codexdht.nimble | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/codexdht.nimble b/codexdht.nimble index 0f89769..80ee8ae 100644 --- a/codexdht.nimble +++ b/codexdht.nimble @@ -16,8 +16,9 @@ requires "chronos >= 4.0.3 & < 4.1.0" requires "libp2p == 1.5.0" requires "metrics" requires "stew#head" -requires "stint" -requires "https://github.com/codex-storage/nim-datastore >= 0.1.1 & < 0.2.0" +requires "stint#3236fa68394f1e3a06e2bc34218aacdd2d675923" +requires "results == 0.5.1" +requires "https://github.com/codex-storage/nim-datastore#27ca95a52805cd2bd85906e8d687f998b0db9799" requires "questionable" task testAll, "Run all test suites": From cafb6ffe537d32ffc49a8acd7ea0379bed9148cf Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 9 Dec 2024 12:55:12 +0100 Subject: [PATCH 04/11] Update version --- codexdht.nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codexdht.nimble b/codexdht.nimble index 80ee8ae..e24a135 100644 --- a/codexdht.nimble +++ b/codexdht.nimble @@ -1,6 +1,6 @@ # Package -version = "0.4.0" +version = "0.5.0" author = "Status Research & Development GmbH" description = "DHT based on Eth discv5 implementation" license = "MIT" From de39c2006e5f088212ff3246208bd7a552158d87 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 9 Dec 2024 12:55:53 +0100 Subject: [PATCH 05/11] Add Nim version 2.0.12 to CI matrix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a25711f..56f5314 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - nim: [1.6.18] + nim: [1.6.18, 2.0.12] os: [ubuntu-latest, macOS-latest, windows-latest] steps: - name: Checkout From a3f203bbea84cc8f6c4e4bf9ce4d6b7facbd8925 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 9 Dec 2024 18:56:02 +0100 Subject: [PATCH 06/11] Add nimbledeps to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8bda8b1..a189692 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ NimBinaries .update.timestamp *.dSYM .vscode/* +nimbledeps From e7e45de75fad84a36e81df744b39d40bd49b9445 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 9 Dec 2024 18:56:49 +0100 Subject: [PATCH 07/11] Nim 2 config auto generated --- config.nims | 1 + 1 file changed, 1 insertion(+) diff --git a/config.nims b/config.nims index d816c1a..4b14275 100644 --- a/config.nims +++ b/config.nims @@ -1,6 +1,7 @@ switch("define", "libp2p_pki_schemes=secp256k1") # begin Nimble config (version 2) +--noNimblePath when withDir(thisDir(), system.fileExists("nimble.paths")): include "nimble.paths" # end Nimble config From cc54a4f0ecfa36cc00540fb684abc04a7c7752a2 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 9 Dec 2024 18:57:16 +0100 Subject: [PATCH 08/11] Set dependencies versions and commit hashes and introduce nimble.lock --- codexdht.nimble | 12 +- nimble.lock | 342 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+), 6 deletions(-) create mode 100644 nimble.lock diff --git a/codexdht.nimble b/codexdht.nimble index e24a135..7635ce1 100644 --- a/codexdht.nimble +++ b/codexdht.nimble @@ -8,18 +8,18 @@ skipDirs = @["tests"] # Dependencies requires "secp256k1#2acbbdcc0e63002a013fff49f015708522875832" # >= 0.5.2 & < 0.6.0 -requires "protobuf_serialization" # >= 0.2.0 & < 0.3.0 +requires "protobuf_serialization#5a31137a82c2b6a989c9ed979bb636c7a49f570e" # >= 0.2.0 & < 0.3.0 requires "nimcrypto >= 0.5.4" requires "bearssl == 0.2.5" requires "chronicles >= 0.10.2 & < 0.11.0" requires "chronos >= 4.0.3 & < 4.1.0" requires "libp2p == 1.5.0" -requires "metrics" -requires "stew#head" +requires "metrics#cacfdc12454a0804c65112b9f4f50d1375208dcd" +requires "stew >= 0.2.0" requires "stint#3236fa68394f1e3a06e2bc34218aacdd2d675923" -requires "results == 0.5.1" -requires "https://github.com/codex-storage/nim-datastore#27ca95a52805cd2bd85906e8d687f998b0db9799" -requires "questionable" +requires "results >= 0.5.1" +requires "https://github.com/codex-storage/nim-datastore#e24c8036ee95f2611b384d7b5672025d18c82358" +requires "questionable >= 0.10.15" task testAll, "Run all test suites": exec "nimble install -d -y" diff --git a/nimble.lock b/nimble.lock new file mode 100644 index 0000000..3573802 --- /dev/null +++ b/nimble.lock @@ -0,0 +1,342 @@ +{ + "version": 2, + "packages": { + "asynctest": { + "version": "0.5.2", + "vcsRevision": "32df0f19d6e0e6f84c762cf8de7361ddb419f4ba", + "url": "https://github.com/markspanbroek/asynctest", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "4299d906d93ca5b4fa2f85e808fe868e0be65d43" + } + }, + "unittest2": { + "version": "0.2.3", + "vcsRevision": "845b6af28b9f68f02d320e03ad18eccccea7ddb9", + "url": "https://github.com/status-im/nim-unittest2", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "6936b4e4676c9b37537d93f31cb8fc46f4ebaacb" + } + }, + "bearssl": { + "version": "0.2.5", + "vcsRevision": "667b40440a53a58e9f922e29e20818720c62d9ac", + "url": "https://github.com/status-im/nim-bearssl", + "downloadMethod": "git", + "dependencies": [ + "unittest2" + ], + "checksums": { + "sha1": "550e6f9321b85de53bba9c0ffab9c95ffbe12ab3" + } + }, + "testutils": { + "version": "0.5.3", + "vcsRevision": "4d37244f9f5e1acd8592a4ceb5c3fc47bc160181", + "url": "https://github.com/status-im/nim-testutils", + "downloadMethod": "git", + "dependencies": [ + "unittest2" + ], + "checksums": { + "sha1": "2841517f3891ab396cb78d98d46ffd2551176f4b" + } + }, + "results": { + "version": "0.5.1", + "vcsRevision": "df8113dda4c2d74d460a8fa98252b0b771bf1f27", + "url": "https://github.com/arnetheduck/nim-results", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "a9c011f74bc9ed5c91103917b9f382b12e82a9e7" + } + }, + "stew": { + "version": "0.2.0", + "vcsRevision": "79e4fa5a9d3374db17ed63622714d3e1094c7f34", + "url": "https://github.com/status-im/nim-stew", + "downloadMethod": "git", + "dependencies": [ + "results", + "unittest2" + ], + "checksums": { + "sha1": "26d477c735913b7daa1dab53dd74803c88209634" + } + }, + "faststreams": { + "version": "0.3.0", + "vcsRevision": "cf8d4d22636b8e514caf17e49f9c786ac56b0e85", + "url": "https://github.com/status-im/nim-faststreams", + "downloadMethod": "git", + "dependencies": [ + "stew", + "unittest2" + ], + "checksums": { + "sha1": "68cf8639726abbbe46103fc3457634b297e5589b" + } + }, + "serialization": { + "version": "0.2.6", + "vcsRevision": "2086c99608b4bf472e1ef5fe063710f280243396", + "url": "https://github.com/status-im/nim-serialization", + "downloadMethod": "git", + "dependencies": [ + "faststreams", + "unittest2", + "stew" + ], + "checksums": { + "sha1": "26deca68e1a027be90e2bf2856e25aa819101d1e" + } + }, + "json_serialization": { + "version": "0.2.9", + "vcsRevision": "6eadb6e939ffa7882ff5437033c11a9464d3385c", + "url": "https://github.com/status-im/nim-json-serialization", + "downloadMethod": "git", + "dependencies": [ + "serialization", + "stew", + "results" + ], + "checksums": { + "sha1": "4062dc791d268930701bdef55b5cc35f82303ad3" + } + }, + "chronicles": { + "version": "0.10.3", + "vcsRevision": "32ac8679680ea699f7dbc046e8e0131cac97d41a", + "url": "https://github.com/status-im/nim-chronicles", + "downloadMethod": "git", + "dependencies": [ + "testutils", + "json_serialization" + ], + "checksums": { + "sha1": "79f09526d4d9b9196dd2f6a75310d71a890c4f88" + } + }, + "httputils": { + "version": "0.3.0", + "vcsRevision": "8bb1acbaa4b86eb866145b0d468eff64a57d1897", + "url": "https://github.com/status-im/nim-http-utils", + "downloadMethod": "git", + "dependencies": [ + "stew", + "results", + "unittest2" + ], + "checksums": { + "sha1": "e77263e385390e2e1ace602527c8491a48a85715" + } + }, + "chronos": { + "version": "4.0.3", + "vcsRevision": "c04576d829b8a0a1b12baaa8bc92037501b3a4a0", + "url": "https://github.com/status-im/nim-chronos", + "downloadMethod": "git", + "dependencies": [ + "results", + "stew", + "bearssl", + "httputils", + "unittest2" + ], + "checksums": { + "sha1": "ba179f34b0513ebd1615076f07b61e2e217bd228" + } + }, + "questionable": { + "version": "0.10.15", + "vcsRevision": "82d90b67bcfb7f2e918b61dace2ff1a4ced60935", + "url": "https://github.com/markspanbroek/questionable", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "3238ff637c7b44d2fa8fcb839a8ded968e389de3" + } + }, + "sqlite3_abi": { + "version": "3.47.0.0", + "vcsRevision": "05bbff1af4e8fe2d972ba4b0667b89ca94d3ebba", + "url": "https://github.com/arnetheduck/nim-sqlite3-abi", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "4057724e672b6b6f4d9b96b64914617b46e1bd69" + } + }, + "leveldbstatic": { + "version": "0.2.0", + "vcsRevision": "0bd875d2b76c5b02c771fc1de136826dae6802c6", + "url": "https://github.com/codex-storage/nim-leveldb", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "269646c68f52a9756242731282ffb20cd3fb536d" + } + }, + "datastore": { + "version": "0.2.0", + "vcsRevision": "e24c8036ee95f2611b384d7b5672025d18c82358", + "url": "https://github.com/codex-storage/nim-datastore", + "downloadMethod": "git", + "dependencies": [ + "asynctest", + "chronos", + "questionable", + "sqlite3_abi", + "leveldbstatic", + "stew", + "results", + "unittest2" + ], + "checksums": { + "sha1": "bdc2017b4e1568f09ca47c5202df0500aca77e86" + } + }, + "dnsclient": { + "version": "0.3.4", + "vcsRevision": "23214235d4784d24aceed99bbfe153379ea557c8", + "url": "https://github.com/ba0f3/dnsclient.nim", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "65262c7e533ff49d6aca5539da4bc6c6ce132f40" + } + }, + "nimcrypto": { + "version": "0.6.2", + "vcsRevision": "dc07e3058c6904eef965394493b6ea99aa2adefc", + "url": "https://github.com/cheatfate/nimcrypto", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "8e3e42530f54c8c312942a89640b7e0f687f33a5" + } + }, + "metrics": { + "version": "0.1.0", + "vcsRevision": "cacfdc12454a0804c65112b9f4f50d1375208dcd", + "url": "https://github.com/status-im/nim-metrics", + "downloadMethod": "git", + "dependencies": [ + "chronos", + "results", + "stew" + ], + "checksums": { + "sha1": "c9c52d1f58de7c6589ff40d94f0a61cbd0e3a9d4" + } + }, + "secp256k1": { + "version": "0.6.0.3.1", + "vcsRevision": "2acbbdcc0e63002a013fff49f015708522875832", + "url": "https://github.com/status-im/nim-secp256k1", + "downloadMethod": "git", + "dependencies": [ + "stew", + "nimcrypto" + ], + "checksums": { + "sha1": "146818431dec16ededb951f42fc36832949bcc8f" + } + }, + "zlib": { + "version": "0.1.0", + "vcsRevision": "91cf360b1aeb2e0c753ff8bac6de22a41c5ed8cd", + "url": "https://github.com/status-im/nim-zlib", + "downloadMethod": "git", + "dependencies": [ + "stew" + ], + "checksums": { + "sha1": "faccf2d54a8fe919aa2ac01b5af79a3b49b045fb" + } + }, + "websock": { + "version": "0.2.0", + "vcsRevision": "ebe308a79a7b440a11dfbe74f352be86a3883508", + "url": "https://github.com/status-im/nim-websock", + "downloadMethod": "git", + "dependencies": [ + "chronos", + "httputils", + "chronicles", + "stew", + "nimcrypto", + "bearssl", + "zlib" + ], + "checksums": { + "sha1": "614476e24cad4fe27ee05d29c2b7ea3e4674e3c2" + } + }, + "libp2p": { + "version": "1.5.0", + "vcsRevision": "18a2e79ce209d2f21d8c5db7a41659cc39dbe0b4", + "url": "https://github.com/status-im/nim-libp2p", + "downloadMethod": "git", + "dependencies": [ + "nimcrypto", + "dnsclient", + "bearssl", + "chronicles", + "chronos", + "metrics", + "secp256k1", + "stew", + "websock", + "unittest2" + ], + "checksums": { + "sha1": "e9ff759e55a29d15d885cc8e82155111ef33f78e" + } + }, + "npeg": { + "version": "1.2.0", + "vcsRevision": "22449099d92d8bbd535fcd950287274c8d11daed", + "url": "https://github.com/zevv/npeg", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "bfe84b7b89a4f92e9ca6d9be8256bdda032e556b" + } + }, + "protobuf_serialization": { + "version": "0.3.0", + "vcsRevision": "5a31137a82c2b6a989c9ed979bb636c7a49f570e", + "url": "https://github.com/status-im/nim-protobuf-serialization", + "downloadMethod": "git", + "dependencies": [ + "stew", + "faststreams", + "serialization", + "npeg", + "unittest2" + ], + "checksums": { + "sha1": "ed8270a5f874af35c5e9c04b50020c8a27ba61f5" + } + }, + "stint": { + "version": "2.0.0", + "vcsRevision": "3236fa68394f1e3a06e2bc34218aacdd2d675923", + "url": "https://github.com/status-im/nim-stint", + "downloadMethod": "git", + "dependencies": [ + "stew" + ], + "checksums": { + "sha1": "50744885ee1c320675078b46520268bf3c3c5d81" + } + } + }, + "tasks": {} +} From 5320e8c81e98370f6384c1ebcbd8838e7b324672 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Tue, 10 Dec 2024 10:05:36 +0100 Subject: [PATCH 09/11] Remove .lock and file and direct dependency to nim-results --- codexdht.nimble | 5 +- config.nims | 1 - nimble.lock | 342 ------------------------------------------------ 3 files changed, 2 insertions(+), 346 deletions(-) delete mode 100644 nimble.lock diff --git a/codexdht.nimble b/codexdht.nimble index 7635ce1..52f6d59 100644 --- a/codexdht.nimble +++ b/codexdht.nimble @@ -17,9 +17,8 @@ requires "libp2p == 1.5.0" requires "metrics#cacfdc12454a0804c65112b9f4f50d1375208dcd" requires "stew >= 0.2.0" requires "stint#3236fa68394f1e3a06e2bc34218aacdd2d675923" -requires "results >= 0.5.1" -requires "https://github.com/codex-storage/nim-datastore#e24c8036ee95f2611b384d7b5672025d18c82358" -requires "questionable >= 0.10.15" +requires "https://github.com/codex-storage/nim-datastore#b5635ef82f50255bc5ff2fe411722d870bcb587c" +requires "questionable >= 0.10.15 & < 0.11.0" task testAll, "Run all test suites": exec "nimble install -d -y" diff --git a/config.nims b/config.nims index 4b14275..d816c1a 100644 --- a/config.nims +++ b/config.nims @@ -1,7 +1,6 @@ switch("define", "libp2p_pki_schemes=secp256k1") # begin Nimble config (version 2) ---noNimblePath when withDir(thisDir(), system.fileExists("nimble.paths")): include "nimble.paths" # end Nimble config diff --git a/nimble.lock b/nimble.lock deleted file mode 100644 index 3573802..0000000 --- a/nimble.lock +++ /dev/null @@ -1,342 +0,0 @@ -{ - "version": 2, - "packages": { - "asynctest": { - "version": "0.5.2", - "vcsRevision": "32df0f19d6e0e6f84c762cf8de7361ddb419f4ba", - "url": "https://github.com/markspanbroek/asynctest", - "downloadMethod": "git", - "dependencies": [], - "checksums": { - "sha1": "4299d906d93ca5b4fa2f85e808fe868e0be65d43" - } - }, - "unittest2": { - "version": "0.2.3", - "vcsRevision": "845b6af28b9f68f02d320e03ad18eccccea7ddb9", - "url": "https://github.com/status-im/nim-unittest2", - "downloadMethod": "git", - "dependencies": [], - "checksums": { - "sha1": "6936b4e4676c9b37537d93f31cb8fc46f4ebaacb" - } - }, - "bearssl": { - "version": "0.2.5", - "vcsRevision": "667b40440a53a58e9f922e29e20818720c62d9ac", - "url": "https://github.com/status-im/nim-bearssl", - "downloadMethod": "git", - "dependencies": [ - "unittest2" - ], - "checksums": { - "sha1": "550e6f9321b85de53bba9c0ffab9c95ffbe12ab3" - } - }, - "testutils": { - "version": "0.5.3", - "vcsRevision": "4d37244f9f5e1acd8592a4ceb5c3fc47bc160181", - "url": "https://github.com/status-im/nim-testutils", - "downloadMethod": "git", - "dependencies": [ - "unittest2" - ], - "checksums": { - "sha1": "2841517f3891ab396cb78d98d46ffd2551176f4b" - } - }, - "results": { - "version": "0.5.1", - "vcsRevision": "df8113dda4c2d74d460a8fa98252b0b771bf1f27", - "url": "https://github.com/arnetheduck/nim-results", - "downloadMethod": "git", - "dependencies": [], - "checksums": { - "sha1": "a9c011f74bc9ed5c91103917b9f382b12e82a9e7" - } - }, - "stew": { - "version": "0.2.0", - "vcsRevision": "79e4fa5a9d3374db17ed63622714d3e1094c7f34", - "url": "https://github.com/status-im/nim-stew", - "downloadMethod": "git", - "dependencies": [ - "results", - "unittest2" - ], - "checksums": { - "sha1": "26d477c735913b7daa1dab53dd74803c88209634" - } - }, - "faststreams": { - "version": "0.3.0", - "vcsRevision": "cf8d4d22636b8e514caf17e49f9c786ac56b0e85", - "url": "https://github.com/status-im/nim-faststreams", - "downloadMethod": "git", - "dependencies": [ - "stew", - "unittest2" - ], - "checksums": { - "sha1": "68cf8639726abbbe46103fc3457634b297e5589b" - } - }, - "serialization": { - "version": "0.2.6", - "vcsRevision": "2086c99608b4bf472e1ef5fe063710f280243396", - "url": "https://github.com/status-im/nim-serialization", - "downloadMethod": "git", - "dependencies": [ - "faststreams", - "unittest2", - "stew" - ], - "checksums": { - "sha1": "26deca68e1a027be90e2bf2856e25aa819101d1e" - } - }, - "json_serialization": { - "version": "0.2.9", - "vcsRevision": "6eadb6e939ffa7882ff5437033c11a9464d3385c", - "url": "https://github.com/status-im/nim-json-serialization", - "downloadMethod": "git", - "dependencies": [ - "serialization", - "stew", - "results" - ], - "checksums": { - "sha1": "4062dc791d268930701bdef55b5cc35f82303ad3" - } - }, - "chronicles": { - "version": "0.10.3", - "vcsRevision": "32ac8679680ea699f7dbc046e8e0131cac97d41a", - "url": "https://github.com/status-im/nim-chronicles", - "downloadMethod": "git", - "dependencies": [ - "testutils", - "json_serialization" - ], - "checksums": { - "sha1": "79f09526d4d9b9196dd2f6a75310d71a890c4f88" - } - }, - "httputils": { - "version": "0.3.0", - "vcsRevision": "8bb1acbaa4b86eb866145b0d468eff64a57d1897", - "url": "https://github.com/status-im/nim-http-utils", - "downloadMethod": "git", - "dependencies": [ - "stew", - "results", - "unittest2" - ], - "checksums": { - "sha1": "e77263e385390e2e1ace602527c8491a48a85715" - } - }, - "chronos": { - "version": "4.0.3", - "vcsRevision": "c04576d829b8a0a1b12baaa8bc92037501b3a4a0", - "url": "https://github.com/status-im/nim-chronos", - "downloadMethod": "git", - "dependencies": [ - "results", - "stew", - "bearssl", - "httputils", - "unittest2" - ], - "checksums": { - "sha1": "ba179f34b0513ebd1615076f07b61e2e217bd228" - } - }, - "questionable": { - "version": "0.10.15", - "vcsRevision": "82d90b67bcfb7f2e918b61dace2ff1a4ced60935", - "url": "https://github.com/markspanbroek/questionable", - "downloadMethod": "git", - "dependencies": [], - "checksums": { - "sha1": "3238ff637c7b44d2fa8fcb839a8ded968e389de3" - } - }, - "sqlite3_abi": { - "version": "3.47.0.0", - "vcsRevision": "05bbff1af4e8fe2d972ba4b0667b89ca94d3ebba", - "url": "https://github.com/arnetheduck/nim-sqlite3-abi", - "downloadMethod": "git", - "dependencies": [], - "checksums": { - "sha1": "4057724e672b6b6f4d9b96b64914617b46e1bd69" - } - }, - "leveldbstatic": { - "version": "0.2.0", - "vcsRevision": "0bd875d2b76c5b02c771fc1de136826dae6802c6", - "url": "https://github.com/codex-storage/nim-leveldb", - "downloadMethod": "git", - "dependencies": [], - "checksums": { - "sha1": "269646c68f52a9756242731282ffb20cd3fb536d" - } - }, - "datastore": { - "version": "0.2.0", - "vcsRevision": "e24c8036ee95f2611b384d7b5672025d18c82358", - "url": "https://github.com/codex-storage/nim-datastore", - "downloadMethod": "git", - "dependencies": [ - "asynctest", - "chronos", - "questionable", - "sqlite3_abi", - "leveldbstatic", - "stew", - "results", - "unittest2" - ], - "checksums": { - "sha1": "bdc2017b4e1568f09ca47c5202df0500aca77e86" - } - }, - "dnsclient": { - "version": "0.3.4", - "vcsRevision": "23214235d4784d24aceed99bbfe153379ea557c8", - "url": "https://github.com/ba0f3/dnsclient.nim", - "downloadMethod": "git", - "dependencies": [], - "checksums": { - "sha1": "65262c7e533ff49d6aca5539da4bc6c6ce132f40" - } - }, - "nimcrypto": { - "version": "0.6.2", - "vcsRevision": "dc07e3058c6904eef965394493b6ea99aa2adefc", - "url": "https://github.com/cheatfate/nimcrypto", - "downloadMethod": "git", - "dependencies": [], - "checksums": { - "sha1": "8e3e42530f54c8c312942a89640b7e0f687f33a5" - } - }, - "metrics": { - "version": "0.1.0", - "vcsRevision": "cacfdc12454a0804c65112b9f4f50d1375208dcd", - "url": "https://github.com/status-im/nim-metrics", - "downloadMethod": "git", - "dependencies": [ - "chronos", - "results", - "stew" - ], - "checksums": { - "sha1": "c9c52d1f58de7c6589ff40d94f0a61cbd0e3a9d4" - } - }, - "secp256k1": { - "version": "0.6.0.3.1", - "vcsRevision": "2acbbdcc0e63002a013fff49f015708522875832", - "url": "https://github.com/status-im/nim-secp256k1", - "downloadMethod": "git", - "dependencies": [ - "stew", - "nimcrypto" - ], - "checksums": { - "sha1": "146818431dec16ededb951f42fc36832949bcc8f" - } - }, - "zlib": { - "version": "0.1.0", - "vcsRevision": "91cf360b1aeb2e0c753ff8bac6de22a41c5ed8cd", - "url": "https://github.com/status-im/nim-zlib", - "downloadMethod": "git", - "dependencies": [ - "stew" - ], - "checksums": { - "sha1": "faccf2d54a8fe919aa2ac01b5af79a3b49b045fb" - } - }, - "websock": { - "version": "0.2.0", - "vcsRevision": "ebe308a79a7b440a11dfbe74f352be86a3883508", - "url": "https://github.com/status-im/nim-websock", - "downloadMethod": "git", - "dependencies": [ - "chronos", - "httputils", - "chronicles", - "stew", - "nimcrypto", - "bearssl", - "zlib" - ], - "checksums": { - "sha1": "614476e24cad4fe27ee05d29c2b7ea3e4674e3c2" - } - }, - "libp2p": { - "version": "1.5.0", - "vcsRevision": "18a2e79ce209d2f21d8c5db7a41659cc39dbe0b4", - "url": "https://github.com/status-im/nim-libp2p", - "downloadMethod": "git", - "dependencies": [ - "nimcrypto", - "dnsclient", - "bearssl", - "chronicles", - "chronos", - "metrics", - "secp256k1", - "stew", - "websock", - "unittest2" - ], - "checksums": { - "sha1": "e9ff759e55a29d15d885cc8e82155111ef33f78e" - } - }, - "npeg": { - "version": "1.2.0", - "vcsRevision": "22449099d92d8bbd535fcd950287274c8d11daed", - "url": "https://github.com/zevv/npeg", - "downloadMethod": "git", - "dependencies": [], - "checksums": { - "sha1": "bfe84b7b89a4f92e9ca6d9be8256bdda032e556b" - } - }, - "protobuf_serialization": { - "version": "0.3.0", - "vcsRevision": "5a31137a82c2b6a989c9ed979bb636c7a49f570e", - "url": "https://github.com/status-im/nim-protobuf-serialization", - "downloadMethod": "git", - "dependencies": [ - "stew", - "faststreams", - "serialization", - "npeg", - "unittest2" - ], - "checksums": { - "sha1": "ed8270a5f874af35c5e9c04b50020c8a27ba61f5" - } - }, - "stint": { - "version": "2.0.0", - "vcsRevision": "3236fa68394f1e3a06e2bc34218aacdd2d675923", - "url": "https://github.com/status-im/nim-stint", - "downloadMethod": "git", - "dependencies": [ - "stew" - ], - "checksums": { - "sha1": "50744885ee1c320675078b46520268bf3c3c5d81" - } - } - }, - "tasks": {} -} From 4eb4e9126a0bf8f9f505dd7bc7d30df062d4a8a7 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Wed, 18 Dec 2024 10:48:25 +0100 Subject: [PATCH 10/11] Use IpAddress instead of ValidAddress; remove unused import --- codexdht/private/eth/p2p/discoveryv5/node.nim | 8 +++--- .../private/eth/p2p/discoveryv5/protocol.nim | 4 +-- .../eth/p2p/discoveryv5/routing_table.nim | 6 ++--- codexdht/private/eth/p2p/discoveryv5/spr.nim | 15 +++++------ .../private/eth/p2p/discoveryv5/transport.nim | 4 +-- tests/dht/test_helper.nim | 20 ++++++-------- tests/dht/test_providermngr.nim | 1 - tests/dht/test_providers.nim | 5 +--- tests/discv5/test_discoveryv5.nim | 26 +++++++++---------- tests/discv5/test_discoveryv5_encoding.nim | 9 +++---- 10 files changed, 44 insertions(+), 54 deletions(-) diff --git a/codexdht/private/eth/p2p/discoveryv5/node.nim b/codexdht/private/eth/p2p/discoveryv5/node.nim index 2f3d6c9..442d551 100644 --- a/codexdht/private/eth/p2p/discoveryv5/node.nim +++ b/codexdht/private/eth/p2p/discoveryv5/node.nim @@ -28,7 +28,7 @@ type NodeId* = UInt256 Address* = object - ip*: ValidIpAddress + ip*: IpAddress port*: Port Stats* = object @@ -69,7 +69,7 @@ func newNode*( id: ? pk.toNodeId(), pubkey: pk, record: record, - address: Address(ip: ValidIpAddress.init(ip), port: port).some) + address: Address(ip: ip, port: port).some) ok node @@ -103,7 +103,7 @@ func newNode*(r: SignedPeerRecord): Result[Node, cstring] = record: r, address: none(Address))) -proc update*(n: Node, pk: PrivateKey, ip: Option[ValidIpAddress], +proc update*(n: Node, pk: PrivateKey, ip: Option[IpAddress], tcpPort, udpPort: Option[Port] = none[Port]()): Result[void, cstring] = ? n.record.update(pk, ip, tcpPort, udpPort) @@ -154,7 +154,7 @@ func shortLog*(id: NodeId): string = result.add(sid[i]) chronicles.formatIt(NodeId): shortLog(it) -func hash*(ip: ValidIpAddress): Hash = +func hash*(ip: IpAddress): Hash = case ip.family of IpAddressFamily.IPv6: hash(ip.address_v6) of IpAddressFamily.IPv4: hash(ip.address_v4) diff --git a/codexdht/private/eth/p2p/discoveryv5/protocol.nim b/codexdht/private/eth/p2p/discoveryv5/protocol.nim index 6de26c6..807e9a1 100644 --- a/codexdht/private/eth/p2p/discoveryv5/protocol.nim +++ b/codexdht/private/eth/p2p/discoveryv5/protocol.nim @@ -963,7 +963,7 @@ proc revalidateNode*(d: Protocol, n: Node) {.async.} = # Get IP and port from pong message and add it to the ip votes trace "pong rx", n, myip = res.ip, myport = res.port - let a = Address(ip: ValidIpAddress.init(res.ip), port: Port(res.port)) + let a = Address(ip: res.ip, port: Port(res.port)) d.ipVote.insert(n.id, a) proc revalidateLoop(d: Protocol) {.async.} = @@ -1076,7 +1076,7 @@ func init*( proc newProtocol*( privKey: PrivateKey, - enrIp: Option[ValidIpAddress], + enrIp: Option[IpAddress], enrTcpPort, enrUdpPort: Option[Port], localEnrFields: openArray[(string, seq[byte])] = [], bootstrapRecords: openArray[SignedPeerRecord] = [], diff --git a/codexdht/private/eth/p2p/discoveryv5/routing_table.nim b/codexdht/private/eth/p2p/discoveryv5/routing_table.nim index 4917e90..8239ee4 100644 --- a/codexdht/private/eth/p2p/discoveryv5/routing_table.nim +++ b/codexdht/private/eth/p2p/discoveryv5/routing_table.nim @@ -34,7 +34,7 @@ type IpLimits* = object limit*: uint - ips: Table[ValidIpAddress, uint] + ips: Table[IpAddress, uint] RoutingTable* = object @@ -101,7 +101,7 @@ type ReplacementExisting NoAddress -func inc*(ipLimits: var IpLimits, ip: ValidIpAddress): bool = +func inc*(ipLimits: var IpLimits, ip: IpAddress): bool = let val = ipLimits.ips.getOrDefault(ip, 0) if val < ipLimits.limit: ipLimits.ips[ip] = val + 1 @@ -109,7 +109,7 @@ func inc*(ipLimits: var IpLimits, ip: ValidIpAddress): bool = else: false -func dec*(ipLimits: var IpLimits, ip: ValidIpAddress) = +func dec*(ipLimits: var IpLimits, ip: IpAddress) = let val = ipLimits.ips.getOrDefault(ip, 0) if val == 1: ipLimits.ips.del(ip) diff --git a/codexdht/private/eth/p2p/discoveryv5/spr.nim b/codexdht/private/eth/p2p/discoveryv5/spr.nim index 15c6c2a..1627ae6 100644 --- a/codexdht/private/eth/p2p/discoveryv5/spr.nim +++ b/codexdht/private/eth/p2p/discoveryv5/spr.nim @@ -58,7 +58,7 @@ proc incSeqNo*( proc update*( r: var SignedPeerRecord, pk: crypto.PrivateKey, - ip: Option[ValidIpAddress], + ip: Option[IpAddress], tcpPort, udpPort: Option[Port] = none[Port]()): RecordResult[void] = ## Update a `SignedPeerRecord` with given ip address, tcp port, udp port and optional @@ -97,9 +97,10 @@ proc update*( if udpPort.isNone and tcpPort.isNone: return err "No existing address in SignedPeerRecord with no port provided" - let ipAddr = try: ValidIpAddress.init(ip.get) - except ValueError as e: - return err ("Existing address contains invalid address: " & $e.msg).cstring + let ipAddr = ip.get + # try: ip.get + # except ValueError as e: + # return err ("Existing address contains invalid address: " & $e.msg).cstring if tcpPort.isSome: transProto = IpTransportProtocol.tcpProtocol transProtoPort = tcpPort.get @@ -223,7 +224,7 @@ proc init*( T: type SignedPeerRecord, seqNum: uint64, pk: PrivateKey, - ip: Option[ValidIpAddress], + ip: Option[IpAddress], tcpPort, udpPort: Option[Port]): RecordResult[T] = ## Initialize a `SignedPeerRecord` with given sequence number, private key, optional @@ -238,9 +239,7 @@ proc init*( tcpPort, udpPort var - ipAddr = try: ValidIpAddress.init("127.0.0.1") - except ValueError as e: - return err ("Existing address contains invalid address: " & $e.msg).cstring + ipAddr = static parseIpAddress("127.0.0.1") proto: IpTransportProtocol protoPort: Port diff --git a/codexdht/private/eth/p2p/discoveryv5/transport.nim b/codexdht/private/eth/p2p/discoveryv5/transport.nim index 04fe20c..e1dac60 100644 --- a/codexdht/private/eth/p2p/discoveryv5/transport.nim +++ b/codexdht/private/eth/p2p/discoveryv5/transport.nim @@ -259,7 +259,7 @@ proc processClient[T](transp: DatagramTransport, raddr: TransportAddress): except ValueError as e: error "Not a valid IpAddress", exception = e.name, msg = e.msg return - let a = Address(ip: ValidIpAddress.init(ip), port: raddr.port) + let a = Address(ip: ip, port: raddr.port) t.receive(a, buf) @@ -292,7 +292,7 @@ proc newTransport*[T]( Transport[T]( client: client, - bindAddress: Address(ip: ValidIpAddress.init(bindIp), port: bindPort), + bindAddress: Address(ip: bindIp, port: bindPort), codec: Codec( localNode: localNode, privKey: privKey, diff --git a/tests/dht/test_helper.nim b/tests/dht/test_helper.nim index 3d92b96..f841b7e 100644 --- a/tests/dht/test_helper.nim +++ b/tests/dht/test_helper.nim @@ -4,14 +4,10 @@ import libp2p/crypto/[crypto, secp], libp2p/multiaddress, codexdht/discv5/[node, routing_table, spr], - codexdht/discv5/crypto as dhtcrypto, - codexdht/discv5/protocol as discv5_protocol, - stew/shims/net - -export net + codexdht/discv5/protocol as discv5_protocol proc localAddress*(port: int): Address = - Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(port)) + Address(ip: parseIpAddress("127.0.0.1"), port: Port(port)) proc example*(T: type PrivateKey, rng: ref HmacDrbgContext): PrivateKey = PrivateKey.random(PKScheme.Secp256k1, rng[]).expect("Valid rng for private key") @@ -54,7 +50,7 @@ proc nodeIdInNodes*(id: NodeId, nodes: openArray[Node]): bool = if id == n.id: return true proc generateNode*(privKey: PrivateKey, port: int, - ip: ValidIpAddress = ValidIpAddress.init("127.0.0.1")): Node = + ip: IpAddress = parseIpAddress("127.0.0.1")): Node = let port = Port(port) @@ -72,7 +68,7 @@ proc generateNRandomNodes*(rng: ref HmacDrbgContext, n: int): seq[Node] = res proc nodeAndPrivKeyAtDistance*(n: Node, rng: var HmacDrbgContext, d: uint32, - ip: ValidIpAddress = ValidIpAddress.init("127.0.0.1")): (Node, PrivateKey) = + ip: IpAddress = parseIpAddress("127.0.0.1")): (Node, PrivateKey) = while true: let privKey = PrivateKey.random(rng).expect("Valid rng for private key") @@ -81,23 +77,23 @@ proc nodeAndPrivKeyAtDistance*(n: Node, rng: var HmacDrbgContext, d: uint32, return (node, privKey) proc nodeAtDistance*(n: Node, rng: var HmacDrbgContext, d: uint32, - ip: ValidIpAddress = ValidIpAddress.init("127.0.0.1")): Node = + ip: IpAddress = parseIpAddress("127.0.0.1")): Node = let (node, _) = n.nodeAndPrivKeyAtDistance(rng, d, ip) node proc nodesAtDistance*( n: Node, rng: var HmacDrbgContext, d: uint32, amount: int, - ip: ValidIpAddress = ValidIpAddress.init("127.0.0.1")): seq[Node] = + ip: IpAddress = parseIpAddress("127.0.0.1")): seq[Node] = for i in 0.. Date: Wed, 18 Dec 2024 10:51:56 +0100 Subject: [PATCH 11/11] Remove useless comment --- codexdht/private/eth/p2p/discoveryv5/spr.nim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/codexdht/private/eth/p2p/discoveryv5/spr.nim b/codexdht/private/eth/p2p/discoveryv5/spr.nim index 1627ae6..351b8a7 100644 --- a/codexdht/private/eth/p2p/discoveryv5/spr.nim +++ b/codexdht/private/eth/p2p/discoveryv5/spr.nim @@ -98,9 +98,7 @@ proc update*( return err "No existing address in SignedPeerRecord with no port provided" let ipAddr = ip.get - # try: ip.get - # except ValueError as e: - # return err ("Existing address contains invalid address: " & $e.msg).cstring + if tcpPort.isSome: transProto = IpTransportProtocol.tcpProtocol transProtoPort = tcpPort.get