mirror of
https://github.com/logos-storage/logos-storage-nim-dht.git
synced 2026-01-02 13:33:08 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
754765ba31 | ||
|
|
99884b5971 | ||
|
|
6c7de03622 |
10
.github/workflows/ci.yml
vendored
10
.github/workflows/ci.yml
vendored
@ -7,15 +7,15 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
nim: [2.0.14]
|
nim: [2.2.4]
|
||||||
os: [ubuntu-latest, macOS-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Install Nim
|
- uses: jiro4989/setup-nim-action@v2
|
||||||
uses: iffy/install-nim@v5
|
|
||||||
with:
|
with:
|
||||||
version: ${{ matrix.nim }}
|
nim-version: ${{matrix.nim}}
|
||||||
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Build
|
- name: Build
|
||||||
run: nimble install -y
|
run: nimble install -y
|
||||||
- name: Test
|
- name: Test
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
# A DHT implementation for Codex
|
# A DHT implementation for Logos Storage
|
||||||
|
|
||||||
[](https://opensource.org/licenses/Apache-2.0)
|
[](https://opensource.org/licenses/Apache-2.0)
|
||||||
[](https://opensource.org/licenses/MIT)
|
[](https://opensource.org/licenses/MIT)
|
||||||
[](#stability)
|
[](#stability)
|
||||||
[](https://github.com/codex-storage/nim-codex-dht/actions/workflows/ci.yml?query=workflow%3ACI+branch%3Amaster)
|
[](https://github.com/logos-storage/logos-storage-nim-dht/actions/workflows/ci.yml?query=workflow%3ACI+branch%3Amaster)
|
||||||
[](https://codecov.io/gh/codex-storage/nim-codex-dht)
|
[](https://codecov.io/gh/logos-storage/logos-storage-nim-dht)
|
||||||
|
|
||||||
This DHT implementation is aiming to provide a DHT for Codex with the following properties
|
This DHT implementation is aiming to provide a DHT for Logos Storage with the following properties
|
||||||
* flexible secure transport usage with
|
* flexible secure transport usage with
|
||||||
* fast UDP based operation
|
* fast UDP based operation
|
||||||
* eventual fallback to TCP-based operation (maybe though libp2p)
|
* eventual fallback to TCP-based operation (maybe though libp2p)
|
||||||
|
|||||||
@ -1,25 +1,25 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.5.0"
|
version = "0.6.0"
|
||||||
author = "Status Research & Development GmbH"
|
author = "Status Research & Development GmbH"
|
||||||
description = "DHT based on Eth discv5 implementation"
|
description = "DHT based on Eth discv5 implementation"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
skipDirs = @["tests"]
|
skipDirs = @["tests"]
|
||||||
|
|
||||||
# Dependencies
|
# 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 "secp256k1 >= 0.6.0 & < 0.7.0"
|
||||||
requires "protobuf_serialization >= 0.3.0 & < 0.4.0"
|
requires "nimcrypto >= 0.6.2 & < 0.8.0"
|
||||||
requires "nimcrypto >= 0.6.2 & < 0.7.0"
|
|
||||||
requires "bearssl >= 0.2.5 & < 0.3.0"
|
requires "bearssl >= 0.2.5 & < 0.3.0"
|
||||||
requires "chronicles >= 0.10.2 & < 0.11.0"
|
requires "chronicles >= 0.11.2 & < 0.13.0"
|
||||||
requires "chronos >= 4.0.3 & < 4.1.0"
|
requires "chronos >= 4.0.4 & < 4.1.0"
|
||||||
requires "libp2p >= 1.5.0 & < 2.0.0"
|
requires "libp2p >= 1.14.1 & < 2.0.0"
|
||||||
requires "metrics >= 0.1.0 & < 0.2.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 "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/logos-storage/nim-datastore >= 0.2.1 & < 0.3.0"
|
||||||
requires "questionable >= 0.10.15 & < 0.11.0"
|
requires "questionable >= 0.10.15 & < 0.11.0"
|
||||||
|
requires "leveldbstatic >= 0.2.1 & < 0.3.0"
|
||||||
|
|
||||||
task testAll, "Run all test suites":
|
task testAll, "Run all test suites":
|
||||||
exec "nimble install -d -y"
|
exec "nimble install -d -y"
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import
|
import
|
||||||
std/sugar,
|
std/sugar,
|
||||||
libp2p/crypto/[crypto, secp],
|
libp2p/crypto/[crypto, secp],
|
||||||
stew/[byteutils, objects, results, ptrops]
|
stew/[byteutils, objects, ptrops],
|
||||||
|
results
|
||||||
|
|
||||||
# from secp256k1 import ecdh, SkEcdhSecretSize, toRaw, SkSecretKey, SkPublicKey
|
|
||||||
import secp256k1
|
import secp256k1
|
||||||
|
|
||||||
const
|
const
|
||||||
KeyLength* = SkEcdhSecretSize
|
KeyLength* = secp256k1.SkEcdhSecretSize
|
||||||
## Ecdh shared secret key length without leading byte
|
## Ecdh shared secret key length without leading byte
|
||||||
## (publicKey * privateKey).x, where length of x is 32 bytes
|
## (publicKey * privateKey).x, where length of x is 32 bytes
|
||||||
|
|
||||||
@ -25,12 +25,12 @@ type
|
|||||||
data*: array[FullKeyLength, byte]
|
data*: array[FullKeyLength, byte]
|
||||||
|
|
||||||
proc fromHex*(T: type PrivateKey, data: string): Result[PrivateKey, cstring] =
|
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)
|
("Failed to init private key from hex string: " & $e).cstring)
|
||||||
ok PrivateKey.init(skKey)
|
ok PrivateKey.init(skKey)
|
||||||
|
|
||||||
proc fromHex*(T: type PublicKey, data: string): Result[PublicKey, cstring] =
|
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)
|
("Failed to init public key from hex string: " & $e).cstring)
|
||||||
ok PublicKey.init(skKey)
|
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.
|
## Take the `x32` part as ecdh shared secret.
|
||||||
## output length is derived from x32 length and taken from ecdh
|
## output length is derived from x32 length and taken from ecdh
|
||||||
## generic parameter `KeyLength`
|
## generic parameter `KeyLength`
|
||||||
copyMem(output, x32, SkEcdhSecretSize)
|
copyMem(output, x32, KeyLength)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
func ecdhSharedSecret(seckey: SkPrivateKey, pubkey: secp.SkPublicKey): SharedSecret =
|
func ecdhSharedSecret(seckey: SkPrivateKey, pubkey: secp.SkPublicKey): SharedSecret =
|
||||||
## Compute ecdh agreed shared secret.
|
## Compute ecdh agreed shared secret.
|
||||||
let res = ecdh[SkEcdhSecretSize](secp256k1.SkSecretKey(seckey),
|
let res = secp256k1.ecdh[KeyLength](
|
||||||
secp256k1.SkPublicKey(pubkey),
|
secp256k1.SkSecretKey(seckey),
|
||||||
ecdhSharedSecretHash, nil)
|
secp256k1.SkPublicKey(pubkey),
|
||||||
|
ecdhSharedSecretHash,
|
||||||
|
nil,
|
||||||
|
)
|
||||||
# This function only fail if the hash function return zero.
|
# This function only fail if the hash function return zero.
|
||||||
# Because our hash function always success, we can turn the error into defect
|
# Because our hash function always success, we can turn the error into defect
|
||||||
doAssert res.isOk, $res.error
|
doAssert res.isOk, $res.error
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# codex-dht - Codex DHT
|
# logos-storage-dht - Logos Storage DHT
|
||||||
# Copyright (c) 2022 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
@ -18,13 +18,14 @@ import
|
|||||||
stew/endians2,
|
stew/endians2,
|
||||||
bearssl/rand,
|
bearssl/rand,
|
||||||
chronicles,
|
chronicles,
|
||||||
stew/[results, byteutils],
|
stew/[byteutils],
|
||||||
stint,
|
stint,
|
||||||
libp2p/crypto/crypto as libp2p_crypto,
|
libp2p/crypto/crypto as libp2p_crypto,
|
||||||
libp2p/crypto/secp,
|
libp2p/crypto/secp,
|
||||||
libp2p/signed_envelope,
|
libp2p/signed_envelope,
|
||||||
metrics,
|
metrics,
|
||||||
nimcrypto,
|
nimcrypto,
|
||||||
|
results,
|
||||||
"."/[messages, messages_encoding, node, spr, hkdf, sessions],
|
"."/[messages, messages_encoding, node, spr, hkdf, sessions],
|
||||||
"."/crypto
|
"."/crypto
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# codex-dht - Codex DHT
|
# logos-storage-dht - Logos Storage DHT
|
||||||
# Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2021 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# codex-dht - Codex DHT
|
# logos-storage-dht - Logos Storage DHT
|
||||||
# Copyright (c) 2022 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# codex-dht - Codex DHT
|
# logos-storage-dht - Logos Storage DHT
|
||||||
# Copyright (c) 2020-2022 Status Research & Development GmbH
|
# Copyright (c) 2020-2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# codex-dht - Codex DHT
|
# logos-storage-dht - Logos Storage DHT
|
||||||
# Copyright (c) 2022 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
@ -8,12 +8,11 @@
|
|||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/hashes,
|
std/[hashes, net],
|
||||||
bearssl/rand,
|
bearssl/rand,
|
||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
nimcrypto,
|
nimcrypto,
|
||||||
stew/shims/net,
|
|
||||||
stint,
|
stint,
|
||||||
./crypto,
|
./crypto,
|
||||||
./spr
|
./spr
|
||||||
@ -89,7 +88,9 @@ func newNode*(r: SignedPeerRecord): Result[Node, cstring] =
|
|||||||
nodeId = ? pk.get().toNodeId()
|
nodeId = ? pk.get().toNodeId()
|
||||||
|
|
||||||
if r.ip.isSome() and r.udp.isSome():
|
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(
|
ok(Node(
|
||||||
id: nodeId,
|
id: nodeId,
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[sets, options],
|
std/[net, sets, options],
|
||||||
stew/results, stew/shims/net, chronicles, chronos,
|
results, chronicles, chronos,
|
||||||
"."/[node, spr, routing_table]
|
"."/[node, spr, routing_table]
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# codex-dht - Codex DHT
|
# logos-storage-dht - Logos Storage DHT
|
||||||
# Copyright (c) 2022 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
@ -74,15 +74,15 @@
|
|||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[tables, sets, options, math, sequtils, algorithm, strutils],
|
std/[net, tables, sets, options, math, sequtils, algorithm, strutils],
|
||||||
stew/shims/net as stewNet,
|
|
||||||
json_serialization/std/net,
|
json_serialization/std/net,
|
||||||
stew/[base64, endians2, results],
|
stew/[base64, endians2],
|
||||||
pkg/[chronicles, chronicles/chronos_tools],
|
pkg/[chronicles, chronicles/chronos_tools],
|
||||||
pkg/chronos,
|
pkg/chronos,
|
||||||
pkg/stint,
|
pkg/stint,
|
||||||
pkg/bearssl/rand,
|
pkg/bearssl/rand,
|
||||||
pkg/metrics
|
pkg/metrics,
|
||||||
|
pkg/results
|
||||||
|
|
||||||
import "."/[
|
import "."/[
|
||||||
messages,
|
messages,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# codex-dht - Codex DHT
|
# logos-storage-dht - Logos Storage DHT
|
||||||
# Copyright (c) 2022 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# codex-dht - Codex DHT
|
# logos-storage-dht - Logos Storage DHT
|
||||||
# Copyright (c) 2022 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# codex-dht - Codex DHT
|
# logos-storage-dht - Logos Storage DHT
|
||||||
# Copyright (c) 2022 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# codex-dht - Codex DHT
|
# logos-storage-dht - Logos Storage DHT
|
||||||
# Copyright (c) 2022 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
@ -14,7 +14,6 @@ import pkg/datastore
|
|||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/libp2p
|
import pkg/libp2p
|
||||||
import pkg/chronicles
|
import pkg/chronicles
|
||||||
import pkg/stew/results as rs
|
|
||||||
import pkg/stew/byteutils
|
import pkg/stew/byteutils
|
||||||
import pkg/questionable
|
import pkg/questionable
|
||||||
import pkg/questionable/results
|
import pkg/questionable/results
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# codex-dht - Codex DHT
|
# logos-storage-dht - Logos Storage DHT
|
||||||
# Copyright (c) 2022 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
@ -8,8 +8,8 @@
|
|||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[algorithm, times, sequtils, bitops, sets, options, tables],
|
std/[algorithm, net, times, sequtils, bitops, sets, options, tables],
|
||||||
stint, chronicles, metrics, bearssl/rand, chronos, stew/shims/net as stewNet,
|
stint, chronicles, metrics, bearssl/rand, chronos,
|
||||||
"."/[node, random2, spr]
|
"."/[node, random2, spr]
|
||||||
|
|
||||||
export options
|
export options
|
||||||
@ -524,10 +524,16 @@ proc len*(r: RoutingTable): int =
|
|||||||
proc moveRight[T](arr: var openArray[T], a, b: int) =
|
proc moveRight[T](arr: var openArray[T], a, b: int) =
|
||||||
## In `arr` move elements in range [a, b] right by 1.
|
## In `arr` move elements in range [a, b] right by 1.
|
||||||
var t: T
|
var t: T
|
||||||
shallowCopy(t, arr[b + 1])
|
when declared(shallowCopy):
|
||||||
for i in countdown(b, a):
|
shallowCopy(t, arr[b + 1])
|
||||||
shallowCopy(arr[i + 1], arr[i])
|
for i in countdown(b, a):
|
||||||
shallowCopy(arr[a], t)
|
shallowCopy(arr[i + 1], arr[i])
|
||||||
|
shallowCopy(arr[a], t)
|
||||||
|
else:
|
||||||
|
t = move arr[b + 1]
|
||||||
|
for i in countdown(b, a):
|
||||||
|
arr[i + 1] = move arr[i]
|
||||||
|
arr[a] = move t
|
||||||
|
|
||||||
proc setJustSeen*(r: RoutingTable, n: Node, seen = true) =
|
proc setJustSeen*(r: RoutingTable, n: Node, seen = true) =
|
||||||
## If seen, move `n` to the head (most recently seen) of its bucket.
|
## If seen, move `n` to the head (most recently seen) of its bucket.
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# codex-dht - Codex DHT
|
# logos-storage-dht - Logos Storage DHT
|
||||||
# Copyright (c) 2022 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
@ -19,8 +19,8 @@
|
|||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/options,
|
std/[net, options],
|
||||||
stint, stew/endians2, stew/shims/net,
|
stint, stew/endians2,
|
||||||
node, lru
|
node, lru
|
||||||
|
|
||||||
export lru
|
export lru
|
||||||
|
|||||||
@ -6,10 +6,10 @@
|
|||||||
#
|
#
|
||||||
import
|
import
|
||||||
chronicles,
|
chronicles,
|
||||||
std/[options, strutils, sugar],
|
results,
|
||||||
pkg/stew/[results, byteutils, arrayops],
|
std/[net, options, strutils, sugar],
|
||||||
|
pkg/stew/[byteutils, arrayops],
|
||||||
stew/endians2,
|
stew/endians2,
|
||||||
stew/shims/net,
|
|
||||||
stew/base64,
|
stew/base64,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/crypto/secp,
|
libp2p/crypto/secp,
|
||||||
@ -122,9 +122,13 @@ proc update*(
|
|||||||
.mapErr((e: string) => e.cstring)
|
.mapErr((e: string) => e.cstring)
|
||||||
existingIp =
|
existingIp =
|
||||||
if existingNetProtoFam == MultiCodec.codec("ip6"):
|
if existingNetProtoFam == MultiCodec.codec("ip6"):
|
||||||
ipv6 array[16, byte].initCopyFrom(existingNetProtoAddr)
|
IpAddress(
|
||||||
|
family: IPv6, address_v6: array[16, byte].initCopyFrom(existingNetProtoAddr)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
ipv4 array[4, byte].initCopyFrom(existingNetProtoAddr)
|
IpAddress(
|
||||||
|
family: IPv4, address_v4: array[4, byte].initCopyFrom(existingNetProtoAddr)
|
||||||
|
)
|
||||||
|
|
||||||
ipAddr = ip.get(existingIp)
|
ipAddr = ip.get(existingIp)
|
||||||
|
|
||||||
|
|||||||
@ -6,13 +6,12 @@
|
|||||||
|
|
||||||
# Everything below the handling of ordinary messages
|
# Everything below the handling of ordinary messages
|
||||||
import
|
import
|
||||||
std/[tables, options, sets],
|
std/[net, tables, options, sets],
|
||||||
bearssl/rand,
|
bearssl/rand,
|
||||||
chronos,
|
chronos,
|
||||||
chronicles,
|
chronicles,
|
||||||
metrics,
|
metrics,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
stew/shims/net,
|
|
||||||
"."/[node, encoding, sessions]
|
"."/[node, encoding, sessions]
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|||||||
@ -4,6 +4,3 @@ switch("define", "libp2p_pki_schemes=secp256k1")
|
|||||||
when withDir(thisDir(), system.fileExists("nimble.paths")):
|
when withDir(thisDir(), system.fileExists("nimble.paths")):
|
||||||
include "nimble.paths"
|
include "nimble.paths"
|
||||||
# end Nimble config
|
# end Nimble config
|
||||||
|
|
||||||
when (NimMajor, NimMinor) >= (2, 0):
|
|
||||||
--mm:refc
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import
|
import
|
||||||
|
std/net,
|
||||||
bearssl/rand,
|
bearssl/rand,
|
||||||
chronos,
|
chronos,
|
||||||
libp2p/crypto/[crypto, secp],
|
libp2p/crypto/[crypto, secp],
|
||||||
@ -7,7 +8,7 @@ import
|
|||||||
codexdht/discv5/protocol as discv5_protocol
|
codexdht/discv5/protocol as discv5_protocol
|
||||||
|
|
||||||
proc localAddress*(port: int): Address =
|
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 =
|
proc example*(T: type PrivateKey, rng: ref HmacDrbgContext): PrivateKey =
|
||||||
PrivateKey.random(PKScheme.Secp256k1, rng[]).expect("Valid rng for private key")
|
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)
|
d.addNode(n)
|
||||||
|
|
||||||
func udpExample*(_: type MultiAddress): MultiAddress =
|
func udpExample*(_: type MultiAddress): MultiAddress =
|
||||||
## creates a new udp multiaddress on a random port
|
## creates a new udp MultiAddress on a random port
|
||||||
Multiaddress.init("/ip4/0.0.0.0/udp/0")
|
MultiAddress.init("/ip4/0.0.0.0/udp/0")
|
||||||
|
|
||||||
func udpExamples*(_: type MultiAddress, count: int): seq[MultiAddress] =
|
func udpExamples*(_: type MultiAddress, count: int): seq[MultiAddress] =
|
||||||
var res: seq[MultiAddress] = @[]
|
var res: seq[MultiAddress] = @[]
|
||||||
for i in 1..count:
|
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
|
return res
|
||||||
|
|
||||||
proc toSignedPeerRecord*(privKey: PrivateKey) : SignedPeerRecord =
|
proc toSignedPeerRecord*(privKey: PrivateKey) : SignedPeerRecord =
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
author = "Status Research & Development GmbH"
|
author = "Status Research & Development GmbH"
|
||||||
description = "Tests for Codex DHT"
|
description = "Tests for Logos Storage DHT"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
installFiles = @["build.nims"]
|
installFiles = @["build.nims"]
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user