diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c46d466..5995d77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,15 +7,15 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - nim: [2.0.14] - os: [ubuntu-latest, macOS-latest, windows-latest] + nim: [2.2.4] + os: [ubuntu-latest, macos-latest, windows-latest] steps: - name: Checkout uses: actions/checkout@v4 - - name: Install Nim - uses: iffy/install-nim@v5 + - uses: jiro4989/setup-nim-action@v2 with: - version: ${{ matrix.nim }} + nim-version: ${{matrix.nim}} + repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Build run: nimble install -y - name: Test diff --git a/codexdht.nimble b/codexdht.nimble index 03de482..e76ce25 100644 --- a/codexdht.nimble +++ b/codexdht.nimble @@ -7,19 +7,19 @@ license = "MIT" skipDirs = @["tests"] # Dependencies -requires "nim >= 2.0.14 & < 3.0.0" +requires "nim >= 2.2.4 & < 3.0.0" requires "secp256k1 >= 0.6.0 & < 0.7.0" -requires "protobuf_serialization >= 0.3.0 & < 0.4.0" -requires "nimcrypto >= 0.6.2 & < 0.7.0" +requires "nimcrypto >= 0.6.2 & < 0.8.0" requires "bearssl >= 0.2.5 & < 0.3.0" -requires "chronicles >= 0.10.2 & < 0.11.0" -requires "chronos >= 4.0.3 & < 4.1.0" -requires "libp2p >= 1.5.0 & < 2.0.0" +requires "chronicles >= 0.11.2 & < 0.13.0" +requires "chronos >= 4.0.4 & < 4.1.0" +requires "libp2p >= 1.14.1 & < 2.0.0" requires "metrics >= 0.1.0 & < 0.2.0" -requires "stew >= 0.2.0 & < 0.3.0" +requires "stew >= 0.4.2" requires "stint >= 0.8.1 & < 0.9.0" -requires "https://github.com/codex-storage/nim-datastore >= 0.2.0 & < 0.3.0" +requires "https://github.com/codex-storage/nim-datastore >= 0.2.1 & < 0.3.0" requires "questionable >= 0.10.15 & < 0.11.0" +requires "leveldbstatic >= 0.2.1 & < 0.3.0" task testAll, "Run all test suites": exec "nimble install -d -y" diff --git a/codexdht/private/eth/p2p/discoveryv5/crypto.nim b/codexdht/private/eth/p2p/discoveryv5/crypto.nim index 2ba3939..5bb4f46 100644 --- a/codexdht/private/eth/p2p/discoveryv5/crypto.nim +++ b/codexdht/private/eth/p2p/discoveryv5/crypto.nim @@ -1,13 +1,13 @@ import std/sugar, libp2p/crypto/[crypto, secp], - stew/[byteutils, objects, results, ptrops] + stew/[byteutils, objects, ptrops], + results -# from secp256k1 import ecdh, SkEcdhSecretSize, toRaw, SkSecretKey, SkPublicKey import secp256k1 const - KeyLength* = SkEcdhSecretSize + KeyLength* = secp256k1.SkEcdhSecretSize ## Ecdh shared secret key length without leading byte ## (publicKey * privateKey).x, where length of x is 32 bytes @@ -25,12 +25,12 @@ type data*: array[FullKeyLength, byte] proc fromHex*(T: type PrivateKey, data: string): Result[PrivateKey, cstring] = - let skKey = ? SkPrivateKey.init(data).mapErr(e => + let skKey = ? secp.SkPrivateKey.init(data).mapErr(e => ("Failed to init private key from hex string: " & $e).cstring) ok PrivateKey.init(skKey) proc fromHex*(T: type PublicKey, data: string): Result[PublicKey, cstring] = - let skKey = ? SkPublicKey.init(data).mapErr(e => + let skKey = ? secp.SkPublicKey.init(data).mapErr(e => ("Failed to init public key from hex string: " & $e).cstring) ok PublicKey.init(skKey) @@ -45,14 +45,17 @@ proc ecdhSharedSecretHash(output: ptr byte, x32, y32: ptr byte, data: pointer): ## Take the `x32` part as ecdh shared secret. ## output length is derived from x32 length and taken from ecdh ## generic parameter `KeyLength` - copyMem(output, x32, SkEcdhSecretSize) + copyMem(output, x32, KeyLength) return 1 func ecdhSharedSecret(seckey: SkPrivateKey, pubkey: secp.SkPublicKey): SharedSecret = ## Compute ecdh agreed shared secret. - let res = ecdh[SkEcdhSecretSize](secp256k1.SkSecretKey(seckey), - secp256k1.SkPublicKey(pubkey), - ecdhSharedSecretHash, nil) + let res = secp256k1.ecdh[KeyLength]( + secp256k1.SkSecretKey(seckey), + secp256k1.SkPublicKey(pubkey), + ecdhSharedSecretHash, + nil, + ) # This function only fail if the hash function return zero. # Because our hash function always success, we can turn the error into defect doAssert res.isOk, $res.error diff --git a/codexdht/private/eth/p2p/discoveryv5/encoding.nim b/codexdht/private/eth/p2p/discoveryv5/encoding.nim index 2cb7962..f99e727 100644 --- a/codexdht/private/eth/p2p/discoveryv5/encoding.nim +++ b/codexdht/private/eth/p2p/discoveryv5/encoding.nim @@ -18,13 +18,14 @@ import stew/endians2, bearssl/rand, chronicles, - stew/[results, byteutils], + stew/[byteutils], stint, libp2p/crypto/crypto as libp2p_crypto, libp2p/crypto/secp, libp2p/signed_envelope, metrics, nimcrypto, + results, "."/[messages, messages_encoding, node, spr, hkdf, sessions], "."/crypto diff --git a/codexdht/private/eth/p2p/discoveryv5/node.nim b/codexdht/private/eth/p2p/discoveryv5/node.nim index cad809f..5310d0e 100644 --- a/codexdht/private/eth/p2p/discoveryv5/node.nim +++ b/codexdht/private/eth/p2p/discoveryv5/node.nim @@ -8,12 +8,11 @@ {.push raises: [].} import - std/hashes, + std/[hashes, net], bearssl/rand, chronicles, chronos, nimcrypto, - stew/shims/net, stint, ./crypto, ./spr @@ -89,7 +88,9 @@ func newNode*(r: SignedPeerRecord): Result[Node, cstring] = nodeId = ? pk.get().toNodeId() if r.ip.isSome() and r.udp.isSome(): - let a = Address(ip: ipv4(r.ip.get()), port: Port(r.udp.get())) + let a = Address( + ip: IpAddress(family: IPv4, address_v4: r.ip.get()), port: Port(r.udp.get()) + ) ok(Node( id: nodeId, diff --git a/codexdht/private/eth/p2p/discoveryv5/nodes_verification.nim b/codexdht/private/eth/p2p/discoveryv5/nodes_verification.nim index bd2dbd0..ccabb77 100644 --- a/codexdht/private/eth/p2p/discoveryv5/nodes_verification.nim +++ b/codexdht/private/eth/p2p/discoveryv5/nodes_verification.nim @@ -1,8 +1,8 @@ {.push raises: [].} import - std/[sets, options], - stew/results, stew/shims/net, chronicles, chronos, + std/[net, sets, options], + results, chronicles, chronos, "."/[node, spr, routing_table] logScope: diff --git a/codexdht/private/eth/p2p/discoveryv5/protocol.nim b/codexdht/private/eth/p2p/discoveryv5/protocol.nim index 0089d12..27c7b14 100644 --- a/codexdht/private/eth/p2p/discoveryv5/protocol.nim +++ b/codexdht/private/eth/p2p/discoveryv5/protocol.nim @@ -74,15 +74,15 @@ {.push raises: [].} import - std/[tables, sets, options, math, sequtils, algorithm, strutils], - stew/shims/net as stewNet, + std/[net, tables, sets, options, math, sequtils, algorithm, strutils], json_serialization/std/net, - stew/[base64, endians2, results], + stew/[base64, endians2], pkg/[chronicles, chronicles/chronos_tools], pkg/chronos, pkg/stint, pkg/bearssl/rand, - pkg/metrics + pkg/metrics, + pkg/results import "."/[ messages, diff --git a/codexdht/private/eth/p2p/discoveryv5/providers/manager.nim b/codexdht/private/eth/p2p/discoveryv5/providers/manager.nim index 7eb33b1..f317cd8 100644 --- a/codexdht/private/eth/p2p/discoveryv5/providers/manager.nim +++ b/codexdht/private/eth/p2p/discoveryv5/providers/manager.nim @@ -14,7 +14,6 @@ import pkg/datastore import pkg/chronos import pkg/libp2p import pkg/chronicles -import pkg/stew/results as rs import pkg/stew/byteutils import pkg/questionable import pkg/questionable/results diff --git a/codexdht/private/eth/p2p/discoveryv5/routing_table.nim b/codexdht/private/eth/p2p/discoveryv5/routing_table.nim index e270315..2d4e855 100644 --- a/codexdht/private/eth/p2p/discoveryv5/routing_table.nim +++ b/codexdht/private/eth/p2p/discoveryv5/routing_table.nim @@ -8,8 +8,8 @@ {.push raises: [].} import - std/[algorithm, times, sequtils, bitops, sets, options, tables], - stint, chronicles, metrics, bearssl/rand, chronos, stew/shims/net as stewNet, + std/[algorithm, net, times, sequtils, bitops, sets, options, tables], + stint, chronicles, metrics, bearssl/rand, chronos, "."/[node, random2, spr] export options diff --git a/codexdht/private/eth/p2p/discoveryv5/sessions.nim b/codexdht/private/eth/p2p/discoveryv5/sessions.nim index ee770bb..0b23f29 100644 --- a/codexdht/private/eth/p2p/discoveryv5/sessions.nim +++ b/codexdht/private/eth/p2p/discoveryv5/sessions.nim @@ -19,8 +19,8 @@ {.push raises: [].} import - std/options, - stint, stew/endians2, stew/shims/net, + std/[net, options], + stint, stew/endians2, node, lru export lru diff --git a/codexdht/private/eth/p2p/discoveryv5/spr.nim b/codexdht/private/eth/p2p/discoveryv5/spr.nim index 351b8a7..0d95138 100644 --- a/codexdht/private/eth/p2p/discoveryv5/spr.nim +++ b/codexdht/private/eth/p2p/discoveryv5/spr.nim @@ -6,10 +6,10 @@ # import chronicles, - std/[options, strutils, sugar], - pkg/stew/[results, byteutils, arrayops], + results, + std/[net, options, strutils, sugar], + pkg/stew/[byteutils, arrayops], stew/endians2, - stew/shims/net, stew/base64, libp2p/crypto/crypto, libp2p/crypto/secp, @@ -122,9 +122,13 @@ proc update*( .mapErr((e: string) => e.cstring) existingIp = if existingNetProtoFam == MultiCodec.codec("ip6"): - ipv6 array[16, byte].initCopyFrom(existingNetProtoAddr) + IpAddress( + family: IPv6, address_v6: array[16, byte].initCopyFrom(existingNetProtoAddr) + ) else: - ipv4 array[4, byte].initCopyFrom(existingNetProtoAddr) + IpAddress( + family: IPv4, address_v4: array[4, byte].initCopyFrom(existingNetProtoAddr) + ) ipAddr = ip.get(existingIp) diff --git a/codexdht/private/eth/p2p/discoveryv5/transport.nim b/codexdht/private/eth/p2p/discoveryv5/transport.nim index e1dac60..d7cac5d 100644 --- a/codexdht/private/eth/p2p/discoveryv5/transport.nim +++ b/codexdht/private/eth/p2p/discoveryv5/transport.nim @@ -6,13 +6,12 @@ # Everything below the handling of ordinary messages import - std/[tables, options, sets], + std/[net, tables, options, sets], bearssl/rand, chronos, chronicles, metrics, libp2p/crypto/crypto, - stew/shims/net, "."/[node, encoding, sessions] const diff --git a/tests/dht/test_helper.nim b/tests/dht/test_helper.nim index f841b7e..341f9cc 100644 --- a/tests/dht/test_helper.nim +++ b/tests/dht/test_helper.nim @@ -1,4 +1,5 @@ import + std/net, bearssl/rand, chronos, libp2p/crypto/[crypto, secp], @@ -7,7 +8,7 @@ import codexdht/discv5/protocol as discv5_protocol proc localAddress*(port: int): Address = - Address(ip: parseIpAddress("127.0.0.1"), port: Port(port)) + Address(ip: IPv4_loopback(), port: Port(port)) proc example*(T: type PrivateKey, rng: ref HmacDrbgContext): PrivateKey = PrivateKey.random(PKScheme.Secp256k1, rng[]).expect("Valid rng for private key") @@ -101,13 +102,13 @@ proc addSeenNode*(d: discv5_protocol.Protocol, n: Node): bool = d.addNode(n) func udpExample*(_: type MultiAddress): MultiAddress = - ## creates a new udp multiaddress on a random port - Multiaddress.init("/ip4/0.0.0.0/udp/0") + ## creates a new udp MultiAddress on a random port + MultiAddress.init("/ip4/0.0.0.0/udp/0") func udpExamples*(_: type MultiAddress, count: int): seq[MultiAddress] = var res: seq[MultiAddress] = @[] for i in 1..count: - res.add Multiaddress.init("/ip4/0.0.0.0/udp/" & $i).get + res.add MultiAddress.init("/ip4/0.0.0.0/udp/" & $i).get return res proc toSignedPeerRecord*(privKey: PrivateKey) : SignedPeerRecord =