mirror of
https://github.com/logos-storage/logos-storage-nim-dht.git
synced 2026-01-02 13:33:08 +00:00
Use IpAddress instead of ValidAddress; remove unused import
This commit is contained in:
parent
5320e8c81e
commit
4eb4e9126a
@ -28,7 +28,7 @@ type
|
|||||||
NodeId* = UInt256
|
NodeId* = UInt256
|
||||||
|
|
||||||
Address* = object
|
Address* = object
|
||||||
ip*: ValidIpAddress
|
ip*: IpAddress
|
||||||
port*: Port
|
port*: Port
|
||||||
|
|
||||||
Stats* = object
|
Stats* = object
|
||||||
@ -69,7 +69,7 @@ func newNode*(
|
|||||||
id: ? pk.toNodeId(),
|
id: ? pk.toNodeId(),
|
||||||
pubkey: pk,
|
pubkey: pk,
|
||||||
record: record,
|
record: record,
|
||||||
address: Address(ip: ValidIpAddress.init(ip), port: port).some)
|
address: Address(ip: ip, port: port).some)
|
||||||
|
|
||||||
ok node
|
ok node
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ func newNode*(r: SignedPeerRecord): Result[Node, cstring] =
|
|||||||
record: r,
|
record: r,
|
||||||
address: none(Address)))
|
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] =
|
tcpPort, udpPort: Option[Port] = none[Port]()): Result[void, cstring] =
|
||||||
? n.record.update(pk, ip, tcpPort, udpPort)
|
? n.record.update(pk, ip, tcpPort, udpPort)
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ func shortLog*(id: NodeId): string =
|
|||||||
result.add(sid[i])
|
result.add(sid[i])
|
||||||
chronicles.formatIt(NodeId): shortLog(it)
|
chronicles.formatIt(NodeId): shortLog(it)
|
||||||
|
|
||||||
func hash*(ip: ValidIpAddress): Hash =
|
func hash*(ip: IpAddress): Hash =
|
||||||
case ip.family
|
case ip.family
|
||||||
of IpAddressFamily.IPv6: hash(ip.address_v6)
|
of IpAddressFamily.IPv6: hash(ip.address_v6)
|
||||||
of IpAddressFamily.IPv4: hash(ip.address_v4)
|
of IpAddressFamily.IPv4: hash(ip.address_v4)
|
||||||
|
|||||||
@ -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
|
# Get IP and port from pong message and add it to the ip votes
|
||||||
trace "pong rx", n, myip = res.ip, myport = res.port
|
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)
|
d.ipVote.insert(n.id, a)
|
||||||
|
|
||||||
proc revalidateLoop(d: Protocol) {.async.} =
|
proc revalidateLoop(d: Protocol) {.async.} =
|
||||||
@ -1076,7 +1076,7 @@ func init*(
|
|||||||
|
|
||||||
proc newProtocol*(
|
proc newProtocol*(
|
||||||
privKey: PrivateKey,
|
privKey: PrivateKey,
|
||||||
enrIp: Option[ValidIpAddress],
|
enrIp: Option[IpAddress],
|
||||||
enrTcpPort, enrUdpPort: Option[Port],
|
enrTcpPort, enrUdpPort: Option[Port],
|
||||||
localEnrFields: openArray[(string, seq[byte])] = [],
|
localEnrFields: openArray[(string, seq[byte])] = [],
|
||||||
bootstrapRecords: openArray[SignedPeerRecord] = [],
|
bootstrapRecords: openArray[SignedPeerRecord] = [],
|
||||||
|
|||||||
@ -34,7 +34,7 @@ type
|
|||||||
|
|
||||||
IpLimits* = object
|
IpLimits* = object
|
||||||
limit*: uint
|
limit*: uint
|
||||||
ips: Table[ValidIpAddress, uint]
|
ips: Table[IpAddress, uint]
|
||||||
|
|
||||||
|
|
||||||
RoutingTable* = object
|
RoutingTable* = object
|
||||||
@ -101,7 +101,7 @@ type
|
|||||||
ReplacementExisting
|
ReplacementExisting
|
||||||
NoAddress
|
NoAddress
|
||||||
|
|
||||||
func inc*(ipLimits: var IpLimits, ip: ValidIpAddress): bool =
|
func inc*(ipLimits: var IpLimits, ip: IpAddress): bool =
|
||||||
let val = ipLimits.ips.getOrDefault(ip, 0)
|
let val = ipLimits.ips.getOrDefault(ip, 0)
|
||||||
if val < ipLimits.limit:
|
if val < ipLimits.limit:
|
||||||
ipLimits.ips[ip] = val + 1
|
ipLimits.ips[ip] = val + 1
|
||||||
@ -109,7 +109,7 @@ func inc*(ipLimits: var IpLimits, ip: ValidIpAddress): bool =
|
|||||||
else:
|
else:
|
||||||
false
|
false
|
||||||
|
|
||||||
func dec*(ipLimits: var IpLimits, ip: ValidIpAddress) =
|
func dec*(ipLimits: var IpLimits, ip: IpAddress) =
|
||||||
let val = ipLimits.ips.getOrDefault(ip, 0)
|
let val = ipLimits.ips.getOrDefault(ip, 0)
|
||||||
if val == 1:
|
if val == 1:
|
||||||
ipLimits.ips.del(ip)
|
ipLimits.ips.del(ip)
|
||||||
|
|||||||
@ -58,7 +58,7 @@ proc incSeqNo*(
|
|||||||
proc update*(
|
proc update*(
|
||||||
r: var SignedPeerRecord,
|
r: var SignedPeerRecord,
|
||||||
pk: crypto.PrivateKey,
|
pk: crypto.PrivateKey,
|
||||||
ip: Option[ValidIpAddress],
|
ip: Option[IpAddress],
|
||||||
tcpPort, udpPort: Option[Port] = none[Port]()):
|
tcpPort, udpPort: Option[Port] = none[Port]()):
|
||||||
RecordResult[void] =
|
RecordResult[void] =
|
||||||
## Update a `SignedPeerRecord` with given ip address, tcp port, udp port and optional
|
## 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:
|
if udpPort.isNone and tcpPort.isNone:
|
||||||
return err "No existing address in SignedPeerRecord with no port provided"
|
return err "No existing address in SignedPeerRecord with no port provided"
|
||||||
|
|
||||||
let ipAddr = try: ValidIpAddress.init(ip.get)
|
let ipAddr = ip.get
|
||||||
except ValueError as e:
|
# try: ip.get
|
||||||
return err ("Existing address contains invalid address: " & $e.msg).cstring
|
# except ValueError as e:
|
||||||
|
# return err ("Existing address contains invalid address: " & $e.msg).cstring
|
||||||
if tcpPort.isSome:
|
if tcpPort.isSome:
|
||||||
transProto = IpTransportProtocol.tcpProtocol
|
transProto = IpTransportProtocol.tcpProtocol
|
||||||
transProtoPort = tcpPort.get
|
transProtoPort = tcpPort.get
|
||||||
@ -223,7 +224,7 @@ proc init*(
|
|||||||
T: type SignedPeerRecord,
|
T: type SignedPeerRecord,
|
||||||
seqNum: uint64,
|
seqNum: uint64,
|
||||||
pk: PrivateKey,
|
pk: PrivateKey,
|
||||||
ip: Option[ValidIpAddress],
|
ip: Option[IpAddress],
|
||||||
tcpPort, udpPort: Option[Port]):
|
tcpPort, udpPort: Option[Port]):
|
||||||
RecordResult[T] =
|
RecordResult[T] =
|
||||||
## Initialize a `SignedPeerRecord` with given sequence number, private key, optional
|
## Initialize a `SignedPeerRecord` with given sequence number, private key, optional
|
||||||
@ -238,9 +239,7 @@ proc init*(
|
|||||||
tcpPort, udpPort
|
tcpPort, udpPort
|
||||||
|
|
||||||
var
|
var
|
||||||
ipAddr = try: ValidIpAddress.init("127.0.0.1")
|
ipAddr = static parseIpAddress("127.0.0.1")
|
||||||
except ValueError as e:
|
|
||||||
return err ("Existing address contains invalid address: " & $e.msg).cstring
|
|
||||||
proto: IpTransportProtocol
|
proto: IpTransportProtocol
|
||||||
protoPort: Port
|
protoPort: Port
|
||||||
|
|
||||||
|
|||||||
@ -259,7 +259,7 @@ proc processClient[T](transp: DatagramTransport, raddr: TransportAddress):
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
error "Not a valid IpAddress", exception = e.name, msg = e.msg
|
error "Not a valid IpAddress", exception = e.name, msg = e.msg
|
||||||
return
|
return
|
||||||
let a = Address(ip: ValidIpAddress.init(ip), port: raddr.port)
|
let a = Address(ip: ip, port: raddr.port)
|
||||||
|
|
||||||
t.receive(a, buf)
|
t.receive(a, buf)
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ proc newTransport*[T](
|
|||||||
|
|
||||||
Transport[T](
|
Transport[T](
|
||||||
client: client,
|
client: client,
|
||||||
bindAddress: Address(ip: ValidIpAddress.init(bindIp), port: bindPort),
|
bindAddress: Address(ip: bindIp, port: bindPort),
|
||||||
codec: Codec(
|
codec: Codec(
|
||||||
localNode: localNode,
|
localNode: localNode,
|
||||||
privKey: privKey,
|
privKey: privKey,
|
||||||
|
|||||||
@ -4,14 +4,10 @@ import
|
|||||||
libp2p/crypto/[crypto, secp],
|
libp2p/crypto/[crypto, secp],
|
||||||
libp2p/multiaddress,
|
libp2p/multiaddress,
|
||||||
codexdht/discv5/[node, routing_table, spr],
|
codexdht/discv5/[node, routing_table, spr],
|
||||||
codexdht/discv5/crypto as dhtcrypto,
|
codexdht/discv5/protocol as discv5_protocol
|
||||||
codexdht/discv5/protocol as discv5_protocol,
|
|
||||||
stew/shims/net
|
|
||||||
|
|
||||||
export net
|
|
||||||
|
|
||||||
proc localAddress*(port: int): Address =
|
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 =
|
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")
|
||||||
@ -54,7 +50,7 @@ proc nodeIdInNodes*(id: NodeId, nodes: openArray[Node]): bool =
|
|||||||
if id == n.id: return true
|
if id == n.id: return true
|
||||||
|
|
||||||
proc generateNode*(privKey: PrivateKey, port: int,
|
proc generateNode*(privKey: PrivateKey, port: int,
|
||||||
ip: ValidIpAddress = ValidIpAddress.init("127.0.0.1")): Node =
|
ip: IpAddress = parseIpAddress("127.0.0.1")): Node =
|
||||||
|
|
||||||
let
|
let
|
||||||
port = Port(port)
|
port = Port(port)
|
||||||
@ -72,7 +68,7 @@ proc generateNRandomNodes*(rng: ref HmacDrbgContext, n: int): seq[Node] =
|
|||||||
res
|
res
|
||||||
|
|
||||||
proc nodeAndPrivKeyAtDistance*(n: Node, rng: var HmacDrbgContext, d: uint32,
|
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:
|
while true:
|
||||||
let
|
let
|
||||||
privKey = PrivateKey.random(rng).expect("Valid rng for private key")
|
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)
|
return (node, privKey)
|
||||||
|
|
||||||
proc nodeAtDistance*(n: Node, rng: var HmacDrbgContext, d: uint32,
|
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)
|
let (node, _) = n.nodeAndPrivKeyAtDistance(rng, d, ip)
|
||||||
node
|
node
|
||||||
|
|
||||||
proc nodesAtDistance*(
|
proc nodesAtDistance*(
|
||||||
n: Node, rng: var HmacDrbgContext, d: uint32, amount: int,
|
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..<amount:
|
for i in 0..<amount:
|
||||||
result.add(nodeAtDistance(n, rng, d, ip))
|
result.add(nodeAtDistance(n, rng, d, ip))
|
||||||
|
|
||||||
proc nodesAtDistanceUniqueIp*(
|
proc nodesAtDistanceUniqueIp*(
|
||||||
n: Node, rng: var HmacDrbgContext, d: uint32, amount: int,
|
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] =
|
||||||
var ta = initTAddress(ip, Port(0))
|
var ta = initTAddress(ip, Port(0))
|
||||||
for i in 0..<amount:
|
for i in 0..<amount:
|
||||||
ta.inc()
|
ta.inc()
|
||||||
result.add(nodeAtDistance(n, rng, d, ValidIpAddress.init(ta.address())))
|
result.add(nodeAtDistance(n, rng, d, ta.address()))
|
||||||
|
|
||||||
proc addSeenNode*(d: discv5_protocol.Protocol, n: Node): bool =
|
proc addSeenNode*(d: discv5_protocol.Protocol, n: Node): bool =
|
||||||
# Add it as a seen node, warning: for testing convenience only!
|
# Add it as a seen node, warning: for testing convenience only!
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import pkg/asynctest/chronos/unittest
|
|||||||
import pkg/datastore
|
import pkg/datastore
|
||||||
from pkg/libp2p import PeerId
|
from pkg/libp2p import PeerId
|
||||||
|
|
||||||
import codexdht/dht
|
|
||||||
import codexdht/private/eth/p2p/discoveryv5/spr
|
import codexdht/private/eth/p2p/discoveryv5/spr
|
||||||
import codexdht/private/eth/p2p/discoveryv5/providers
|
import codexdht/private/eth/p2p/discoveryv5/providers
|
||||||
import codexdht/discv5/node
|
import codexdht/discv5/node
|
||||||
|
|||||||
@ -10,18 +10,15 @@
|
|||||||
{.used.}
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[options, sequtils],
|
std/[options],
|
||||||
asynctest/chronos/unittest2,
|
asynctest/chronos/unittest2,
|
||||||
bearssl/rand,
|
bearssl/rand,
|
||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
nimcrypto,
|
|
||||||
libp2p/crypto/[crypto, secp],
|
libp2p/crypto/[crypto, secp],
|
||||||
libp2p/[multiaddress, multicodec, multihash, routing_record, signed_envelope],
|
libp2p/[multiaddress, multicodec, multihash, routing_record, signed_envelope],
|
||||||
codexdht/dht,
|
|
||||||
codexdht/discv5/crypto as dhtcrypto,
|
codexdht/discv5/crypto as dhtcrypto,
|
||||||
codexdht/discv5/protocol as discv5_protocol,
|
codexdht/discv5/protocol as discv5_protocol,
|
||||||
stew/byteutils,
|
|
||||||
test_helper
|
test_helper
|
||||||
|
|
||||||
proc bootstrapNodes(
|
proc bootstrapNodes(
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import
|
import
|
||||||
std/tables,
|
std/tables,
|
||||||
chronos, chronicles, stint, asynctest/chronos/unittest, stew/shims/net,
|
chronos, chronicles, stint, asynctest/chronos/unittest,
|
||||||
stew/byteutils, bearssl/rand,
|
stew/byteutils, bearssl/rand,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
codexdht/discv5/[transport, spr, node, routing_table, encoding, sessions, nodes_verification],
|
codexdht/discv5/[transport, spr, node, routing_table, encoding, sessions, nodes_verification],
|
||||||
@ -442,7 +442,7 @@ suite "Discovery v5 Tests":
|
|||||||
test "New protocol with spr":
|
test "New protocol with spr":
|
||||||
let
|
let
|
||||||
privKey = PrivateKey.example(rng)
|
privKey = PrivateKey.example(rng)
|
||||||
ip = some(ValidIpAddress.init("127.0.0.1"))
|
ip = some(parseIpAddress("127.0.0.1"))
|
||||||
port = Port(20301)
|
port = Port(20301)
|
||||||
node = newProtocol(privKey, ip, some(port), some(port), bindPort = port,
|
node = newProtocol(privKey, ip, some(port), some(port), bindPort = port,
|
||||||
rng = rng)
|
rng = rng)
|
||||||
@ -537,7 +537,7 @@ suite "Discovery v5 Tests":
|
|||||||
let
|
let
|
||||||
port = Port(9000)
|
port = Port(9000)
|
||||||
fromNoderecord = SignedPeerRecord.init(1, PrivateKey.example(rng),
|
fromNoderecord = SignedPeerRecord.init(1, PrivateKey.example(rng),
|
||||||
some(ValidIpAddress.init("11.12.13.14")),
|
some(parseIpAddress("11.12.13.14")),
|
||||||
some(port), some(port))[]
|
some(port), some(port))[]
|
||||||
fromNode = newNode(fromNoderecord)[]
|
fromNode = newNode(fromNoderecord)[]
|
||||||
privKey = PrivateKey.example(rng)
|
privKey = PrivateKey.example(rng)
|
||||||
@ -549,7 +549,7 @@ suite "Discovery v5 Tests":
|
|||||||
block: # Duplicates
|
block: # Duplicates
|
||||||
let
|
let
|
||||||
record = SignedPeerRecord.init(
|
record = SignedPeerRecord.init(
|
||||||
1, privKey, some(ValidIpAddress.init("12.13.14.15")),
|
1, privKey, some(parseIpAddress("12.13.14.15")),
|
||||||
some(port), some(port))[]
|
some(port), some(port))[]
|
||||||
|
|
||||||
# Exact duplicates
|
# Exact duplicates
|
||||||
@ -559,7 +559,7 @@ suite "Discovery v5 Tests":
|
|||||||
|
|
||||||
# Node id duplicates
|
# Node id duplicates
|
||||||
let recordSameId = SignedPeerRecord.init(
|
let recordSameId = SignedPeerRecord.init(
|
||||||
1, privKey, some(ValidIpAddress.init("212.13.14.15")),
|
1, privKey, some(parseIpAddress("212.13.14.15")),
|
||||||
some(port), some(port))[]
|
some(port), some(port))[]
|
||||||
records.add(recordSameId)
|
records.add(recordSameId)
|
||||||
nodes = verifyNodesRecords(records, fromNode, limit, targetDistance)
|
nodes = verifyNodesRecords(records, fromNode, limit, targetDistance)
|
||||||
@ -568,7 +568,7 @@ suite "Discovery v5 Tests":
|
|||||||
block: # No address
|
block: # No address
|
||||||
let
|
let
|
||||||
recordNoAddress = SignedPeerRecord.init(
|
recordNoAddress = SignedPeerRecord.init(
|
||||||
1, privKey, none(ValidIpAddress), some(port), some(port))[]
|
1, privKey, none(IpAddress), some(port), some(port))[]
|
||||||
records = [recordNoAddress]
|
records = [recordNoAddress]
|
||||||
test = verifyNodesRecords(records, fromNode, limit, targetDistance)
|
test = verifyNodesRecords(records, fromNode, limit, targetDistance)
|
||||||
check test.len == 0
|
check test.len == 0
|
||||||
@ -576,7 +576,7 @@ suite "Discovery v5 Tests":
|
|||||||
block: # Invalid address - site local
|
block: # Invalid address - site local
|
||||||
let
|
let
|
||||||
recordInvalidAddress = SignedPeerRecord.init(
|
recordInvalidAddress = SignedPeerRecord.init(
|
||||||
1, privKey, some(ValidIpAddress.init("10.1.2.3")),
|
1, privKey, some(parseIpAddress("10.1.2.3")),
|
||||||
some(port), some(port))[]
|
some(port), some(port))[]
|
||||||
records = [recordInvalidAddress]
|
records = [recordInvalidAddress]
|
||||||
test = verifyNodesRecords(records, fromNode, limit, targetDistance)
|
test = verifyNodesRecords(records, fromNode, limit, targetDistance)
|
||||||
@ -585,7 +585,7 @@ suite "Discovery v5 Tests":
|
|||||||
block: # Invalid address - loopback
|
block: # Invalid address - loopback
|
||||||
let
|
let
|
||||||
recordInvalidAddress = SignedPeerRecord.init(
|
recordInvalidAddress = SignedPeerRecord.init(
|
||||||
1, privKey, some(ValidIpAddress.init("127.0.0.1")),
|
1, privKey, some(parseIpAddress("127.0.0.1")),
|
||||||
some(port), some(port))[]
|
some(port), some(port))[]
|
||||||
records = [recordInvalidAddress]
|
records = [recordInvalidAddress]
|
||||||
test = verifyNodesRecords(records, fromNode, limit, targetDistance)
|
test = verifyNodesRecords(records, fromNode, limit, targetDistance)
|
||||||
@ -594,7 +594,7 @@ suite "Discovery v5 Tests":
|
|||||||
block: # Invalid distance
|
block: # Invalid distance
|
||||||
let
|
let
|
||||||
recordInvalidDistance = SignedPeerRecord.init(
|
recordInvalidDistance = SignedPeerRecord.init(
|
||||||
1, privKey, some(ValidIpAddress.init("12.13.14.15")),
|
1, privKey, some(parseIpAddress("12.13.14.15")),
|
||||||
some(port), some(port))[]
|
some(port), some(port))[]
|
||||||
records = [recordInvalidDistance]
|
records = [recordInvalidDistance]
|
||||||
test = verifyNodesRecords(records, fromNode, limit, @[0'u16])
|
test = verifyNodesRecords(records, fromNode, limit, @[0'u16])
|
||||||
@ -603,7 +603,7 @@ suite "Discovery v5 Tests":
|
|||||||
block: # Invalid distance but distance validation is disabled
|
block: # Invalid distance but distance validation is disabled
|
||||||
let
|
let
|
||||||
recordInvalidDistance = SignedPeerRecord.init(
|
recordInvalidDistance = SignedPeerRecord.init(
|
||||||
1, privKey, some(ValidIpAddress.init("12.13.14.15")),
|
1, privKey, some(parseIpAddress("12.13.14.15")),
|
||||||
some(port), some(port))[]
|
some(port), some(port))[]
|
||||||
records = [recordInvalidDistance]
|
records = [recordInvalidDistance]
|
||||||
test = verifyNodesRecords(records, fromNode, limit)
|
test = verifyNodesRecords(records, fromNode, limit)
|
||||||
@ -630,7 +630,7 @@ suite "Discovery v5 Tests":
|
|||||||
let
|
let
|
||||||
privKey = PrivateKey.example(rng)
|
privKey = PrivateKey.example(rng)
|
||||||
enrRec = SignedPeerRecord.init(1, privKey,
|
enrRec = SignedPeerRecord.init(1, privKey,
|
||||||
some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)),
|
some(parseIpAddress("127.0.0.1")), some(Port(9000)),
|
||||||
some(Port(9000))).expect("Properly intialized private key")
|
some(Port(9000))).expect("Properly intialized private key")
|
||||||
sendNode = newNode(enrRec).expect("Properly initialized record")
|
sendNode = newNode(enrRec).expect("Properly initialized record")
|
||||||
var codec = Codec(localNode: sendNode, privKey: privKey, sessions: Sessions.init(5))
|
var codec = Codec(localNode: sendNode, privKey: privKey, sessions: Sessions.init(5))
|
||||||
@ -659,7 +659,7 @@ suite "Discovery v5 Tests":
|
|||||||
let
|
let
|
||||||
privKey = PrivateKey.example(rng)
|
privKey = PrivateKey.example(rng)
|
||||||
enrRec = SignedPeerRecord.init(1, privKey,
|
enrRec = SignedPeerRecord.init(1, privKey,
|
||||||
some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)),
|
some(parseIpAddress("127.0.0.1")), some(Port(9000)),
|
||||||
some(Port(9000))).expect("Properly intialized private key")
|
some(Port(9000))).expect("Properly intialized private key")
|
||||||
sendNode = newNode(enrRec).expect("Properly initialized record")
|
sendNode = newNode(enrRec).expect("Properly initialized record")
|
||||||
var codec = Codec(localNode: sendNode, privKey: privKey, sessions: Sessions.init(5))
|
var codec = Codec(localNode: sendNode, privKey: privKey, sessions: Sessions.init(5))
|
||||||
@ -690,7 +690,7 @@ suite "Discovery v5 Tests":
|
|||||||
a = localAddress(20303)
|
a = localAddress(20303)
|
||||||
privKey = PrivateKey.example(rng)
|
privKey = PrivateKey.example(rng)
|
||||||
enrRec = SignedPeerRecord.init(1, privKey,
|
enrRec = SignedPeerRecord.init(1, privKey,
|
||||||
some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)),
|
some(parseIpAddress("127.0.0.1")), some(Port(9000)),
|
||||||
some(Port(9000))).expect("Properly intialized private key")
|
some(Port(9000))).expect("Properly intialized private key")
|
||||||
sendNode = newNode(enrRec).expect("Properly initialized record")
|
sendNode = newNode(enrRec).expect("Properly initialized record")
|
||||||
var codec = Codec(localNode: sendNode, privKey: privKey, sessions: Sessions.init(5))
|
var codec = Codec(localNode: sendNode, privKey: privKey, sessions: Sessions.init(5))
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import
|
|||||||
codexdht/discv5/[messages, messages_encoding, encoding, spr, node, sessions],
|
codexdht/discv5/[messages, messages_encoding, encoding, spr, node, sessions],
|
||||||
codexdht/discv5/crypto,
|
codexdht/discv5/crypto,
|
||||||
stew/byteutils,
|
stew/byteutils,
|
||||||
stew/shims/net,
|
|
||||||
stint,
|
stint,
|
||||||
../dht/test_helper
|
../dht/test_helper
|
||||||
|
|
||||||
@ -275,11 +274,11 @@ suite "Discovery v5.1 Packet Encodings Test Vectors":
|
|||||||
|
|
||||||
let
|
let
|
||||||
enrRecA = SignedPeerRecord.init(1, privKeyA,
|
enrRecA = SignedPeerRecord.init(1, privKeyA,
|
||||||
some(ValidIpAddress.init("127.0.0.1")), some(Port(9001)),
|
some(parseIpAddress("127.0.0.1")), some(Port(9001)),
|
||||||
some(Port(9001))).expect("Properly intialized private key")
|
some(Port(9001))).expect("Properly intialized private key")
|
||||||
|
|
||||||
enrRecB = SignedPeerRecord.init(1, privKeyB,
|
enrRecB = SignedPeerRecord.init(1, privKeyB,
|
||||||
some(ValidIpAddress.init("127.0.0.1")), some(Port(9001)),
|
some(parseIpAddress("127.0.0.1")), some(Port(9001)),
|
||||||
some(Port(9001))).expect("Properly intialized private key")
|
some(Port(9001))).expect("Properly intialized private key")
|
||||||
|
|
||||||
nodeA = newNode(enrRecA).expect("Properly initialized record")
|
nodeA = newNode(enrRecA).expect("Properly initialized record")
|
||||||
@ -508,11 +507,11 @@ suite "Discovery v5.1 Additional Encode/Decode":
|
|||||||
|
|
||||||
let
|
let
|
||||||
enrRecA = SignedPeerRecord.init(1, privKeyA,
|
enrRecA = SignedPeerRecord.init(1, privKeyA,
|
||||||
some(ValidIpAddress.init("127.0.0.1")), some(Port(9001)),
|
some(parseIpAddress("127.0.0.1")), some(Port(9001)),
|
||||||
some(Port(9001))).expect("Properly intialized private key")
|
some(Port(9001))).expect("Properly intialized private key")
|
||||||
|
|
||||||
enrRecB = SignedPeerRecord.init(1, privKeyB,
|
enrRecB = SignedPeerRecord.init(1, privKeyB,
|
||||||
some(ValidIpAddress.init("127.0.0.1")), some(Port(9001)),
|
some(parseIpAddress("127.0.0.1")), some(Port(9001)),
|
||||||
some(Port(9001))).expect("Properly intialized private key")
|
some(Port(9001))).expect("Properly intialized private key")
|
||||||
|
|
||||||
nodeA = newNode(enrRecA).expect("Properly initialized record")
|
nodeA = newNode(enrRecA).expect("Properly initialized record")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user