diff --git a/eth/net/nat.nim b/eth/net/nat.nim index 5ec4675..84faeea 100644 --- a/eth/net/nat.nim +++ b/eth/net/nat.nim @@ -113,8 +113,7 @@ proc getExternalIP*(natStrategy: NatStrategy, quiet = false): Option[IpAddress] # Further more, we check if the bind address (user provided, or a "0.0.0.0" # default) is a public IP. That's a long shot, because code paths involving a # user-provided bind address are not supposed to get here. -proc getRoutePrefSrc( - bindIp: ValidIpAddress): (Option[ValidIpAddress], PrefSrcStatus) = +proc getRoutePrefSrc(bindIp: IpAddress): (Option[IpAddress], PrefSrcStatus) = let bindAddress = initTAddress(bindIp, Port(0)) if bindAddress.isAnyLocal(): @@ -123,18 +122,20 @@ proc getRoutePrefSrc( # No route was found, log error and continue without IP. error "No routable IP address found, check your network connection", error = ip.error - return (none(ValidIpAddress), NoRoutingInfo) + return (none(IpAddress), NoRoutingInfo) elif ip.get().isGlobalUnicast(): return (some(ip.get()), PrefSrcIsPublic) else: - return (none(ValidIpAddress), PrefSrcIsPrivate) + return (none(IpAddress), PrefSrcIsPrivate) elif bindAddress.isGlobalUnicast(): - return (some(ValidIpAddress.init(bindIp)), BindAddressIsPublic) + return (some(bindIp), BindAddressIsPublic) else: - return (none(ValidIpAddress), BindAddressIsPrivate) + return (none(IpAddress), BindAddressIsPrivate) # Try to detect a public IP assigned to this host, before trying NAT traversal. -proc getPublicRoutePrefSrcOrExternalIP*(natStrategy: NatStrategy, bindIp: ValidIpAddress, quiet = true): Option[ValidIpAddress] = +proc getPublicRoutePrefSrcOrExternalIP*( + natStrategy: NatStrategy, bindIp: IpAddress, quiet = true): + Option[IpAddress] = let (prefSrcIp, prefSrcStatus) = getRoutePrefSrc(bindIp) case prefSrcStatus: @@ -143,7 +144,7 @@ proc getPublicRoutePrefSrcOrExternalIP*(natStrategy: NatStrategy, bindIp: ValidI of PrefSrcIsPrivate, BindAddressIsPrivate: let extIp = getExternalIP(natStrategy, quiet) if extIp.isSome: - return some(ValidIpAddress.init(extIp.get)) + return some(extIp.get) proc doPortMapping(tcpPort, udpPort: Port, description: string): Option[(Port, Port)] {.gcsafe.} = var @@ -293,14 +294,14 @@ proc redirectPorts*(tcpPort, udpPort: Port, description: string): Option[(Port, proc setupNat*(natStrategy: NatStrategy, tcpPort, udpPort: Port, clientId: string): - tuple[ip: Option[ValidIpAddress], tcpPort, udpPort: Option[Port]] = + tuple[ip: Option[IpAddress], tcpPort, udpPort: Option[Port]] = ## Setup NAT port mapping and get external IP address. ## If any of this fails, we don't return any IP address but do return the ## original ports as best effort. ## TODO: Allow for tcp or udp port mapping to be optional. let extIp = getExternalIP(natStrategy) if extIp.isSome: - let ip = ValidIpAddress.init(extIp.get) + let ip = extIp.get let extPorts = ({.gcsafe.}: redirectPorts(tcpPort = tcpPort, udpPort = udpPort, @@ -310,15 +311,15 @@ proc setupNat*(natStrategy: NatStrategy, tcpPort, udpPort: Port, (ip: some(ip), tcpPort: some(extTcpPort), udpPort: some(extUdpPort)) else: warn "UPnP/NAT-PMP available but port forwarding failed" - (ip: none(ValidIpAddress), tcpPort: some(tcpPort), udpPort: some(udpPort)) + (ip: none(IpAddress), tcpPort: some(tcpPort), udpPort: some(udpPort)) else: warn "UPnP/NAT-PMP not available" - (ip: none(ValidIpAddress), tcpPort: some(tcpPort), udpPort: some(udpPort)) + (ip: none(IpAddress), tcpPort: some(tcpPort), udpPort: some(udpPort)) type NatConfig* = object case hasExtIp*: bool - of true: extIp*: ValidIpAddress + of true: extIp*: IpAddress of false: nat*: NatStrategy func parseCmdArg*(T: type NatConfig, p: string): T {.raises: [ValueError].} = @@ -334,7 +335,7 @@ func parseCmdArg*(T: type NatConfig, p: string): T {.raises: [ValueError].} = else: if p.startsWith("extip:"): try: - let ip = ValidIpAddress.init(p[6..^1]) + let ip = parseIpAddress(p[6..^1]) NatConfig(hasExtIp: true, extIp: ip) except ValueError: let error = "Not a valid IP address: " & p[6..^1] @@ -346,9 +347,9 @@ func parseCmdArg*(T: type NatConfig, p: string): T {.raises: [ValueError].} = func completeCmdArg*(T: type NatConfig, val: string): seq[string] = return @[] -proc setupAddress*(natConfig: NatConfig, bindIp: ValidIpAddress, +proc setupAddress*(natConfig: NatConfig, bindIp: IpAddress, tcpPort, udpPort: Port, clientId: string): - tuple[ip: Option[ValidIpAddress], tcpPort, udpPort: Option[Port]] + tuple[ip: Option[IpAddress], tcpPort, udpPort: Option[Port]] {.gcsafe.} = ## Set-up of the external address via any of the ways as configured in ## `NatConfig`. In case all fails an error is logged and the bind ports are @@ -377,9 +378,9 @@ proc setupAddress*(natConfig: NatConfig, bindIp: ValidIpAddress, return (prefSrcIp, some(tcpPort), some(udpPort)) of PrefSrcIsPrivate: error "No public IP address found. Should not use --nat:none option" - return (none(ValidIpAddress), some(tcpPort), some(udpPort)) + return (none(IpAddress), some(tcpPort), some(udpPort)) of BindAddressIsPrivate: error "Bind IP is not a public IP address. Should not use --nat:none option" - return (none(ValidIpAddress), some(tcpPort), some(udpPort)) + return (none(IpAddress), some(tcpPort), some(udpPort)) of NatUpnp, NatPmp: return setupNat(natConfig.nat, tcpPort, udpPort, clientId) diff --git a/eth/net/utils.nim b/eth/net/utils.nim index 88000ca..8990426 100644 --- a/eth/net/utils.nim +++ b/eth/net/utils.nim @@ -14,14 +14,14 @@ import type IpLimits* = object limit*: uint - ips: Table[ValidIpAddress, uint] + ips: Table[IpAddress, uint] func hash*(ip: ValidIpAddress): Hash = case ip.family of IpAddressFamily.IPv6: hash(ip.address_v6) of IpAddressFamily.IPv4: hash(ip.address_v4) -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 @@ -29,7 +29,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) @@ -46,7 +46,7 @@ func isGlobalUnicast*(address: IpAddress): bool = let a = initTAddress(address, Port(0)) a.isGlobalUnicast() -proc getRouteIpv4*(): Result[ValidIpAddress, cstring] = +proc getRouteIpv4*(): Result[IpAddress, cstring] = # Avoiding Exception with initTAddress and can't make it work with static. # Note: `publicAddress` is only used an "example" IP to find the best route, # no data is send over the network to this IP! @@ -63,4 +63,4 @@ proc getRouteIpv4*(): Result[ValidIpAddress, cstring] = # This should not occur really. error "Address conversion error", exception = e.name, msg = e.msg return err("Invalid IP address") - ok(ValidIpAddress.init(ip)) + ok(ip) diff --git a/eth/p2p/discoveryv5/enr.nim b/eth/p2p/discoveryv5/enr.nim index de90f8f..b8b8d7d 100644 --- a/eth/p2p/discoveryv5/enr.nim +++ b/eth/p2p/discoveryv5/enr.nim @@ -165,7 +165,7 @@ template toFieldPair*(key: string, value: auto): FieldPair = func addAddress( fields: var seq[FieldPair], - ip: Option[ValidIpAddress], + ip: Option[IpAddress], tcpPort, udpPort: Option[Port]) = ## Add address information in new fields. Incomplete address ## information is allowed (example: Port but not IP) as that information @@ -190,7 +190,7 @@ func addAddress( func init*( T: type Record, seqNum: uint64, pk: PrivateKey, - ip: Option[ValidIpAddress], + ip: Option[IpAddress], tcpPort, udpPort: Option[Port], extraFields: openArray[FieldPair] = []): EnrResult[T] = @@ -321,7 +321,7 @@ func update*( func update*( r: var Record, pk: PrivateKey, - ip: Option[ValidIpAddress], + ip: Option[IpAddress], tcpPort, udpPort: Option[Port] = none[Port](), extraFields: openArray[FieldPair] = []): EnrResult[void] = diff --git a/eth/p2p/discoveryv5/node.nim b/eth/p2p/discoveryv5/node.nim index 2160053..edf7fd0 100644 --- a/eth/p2p/discoveryv5/node.nim +++ b/eth/p2p/discoveryv5/node.nim @@ -19,7 +19,7 @@ type NodeId* = UInt256 Address* = object - ip*: ValidIpAddress + ip*: IpAddress port*: Port Node* = ref object @@ -58,7 +58,7 @@ func newNode*(r: Record): Result[Node, cstring] = ok(Node(id: pk.get().toNodeId(), pubkey: pk.get(), record: r, address: none(Address))) -func update*(n: Node, pk: PrivateKey, ip: Option[ValidIpAddress], +func update*(n: Node, pk: PrivateKey, ip: Option[IpAddress], tcpPort, udpPort: Option[Port] = none[Port](), extraFields: openArray[FieldPair] = []): Result[void, cstring] = ? n.record.update(pk, ip, tcpPort, udpPort, extraFields) diff --git a/eth/p2p/discoveryv5/protocol.nim b/eth/p2p/discoveryv5/protocol.nim index 3aa74b8..4e29bbd 100644 --- a/eth/p2p/discoveryv5/protocol.nim +++ b/eth/p2p/discoveryv5/protocol.nim @@ -175,7 +175,7 @@ const ) chronicles.formatIt(Option[Port]): $it -chronicles.formatIt(Option[ValidIpAddress]): $it +chronicles.formatIt(Option[IpAddress]): $it proc addNode*(d: Protocol, node: Node): bool = ## Add `Node` to discovery routing table. @@ -479,7 +479,7 @@ proc processClient(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) proto.receive(a, buf) @@ -832,7 +832,7 @@ proc revalidateNode*(d: Protocol, n: Node) {.async.} = discard d.addNode(nodes[][0]) # Get IP and port from pong message and add it to the ip votes - 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.} = @@ -865,7 +865,7 @@ proc refreshLoop(d: Protocol) {.async.} = except CancelledError: trace "refreshLoop canceled" -proc updateExternalIp*(d: Protocol, extIp: ValidIpAddress, udpPort: Port): bool = +proc updateExternalIp*(d: Protocol, extIp: IpAddress, udpPort: Port): bool = var success = false let previous = d.localNode.address @@ -956,7 +956,7 @@ func init*( proc newProtocol*( privKey: PrivateKey, - enrIp: Option[ValidIpAddress], + enrIp: Option[IpAddress], enrTcpPort, enrUdpPort: Option[Port], localEnrFields: openArray[(string, seq[byte])] = [], bootstrapRecords: openArray[Record] = [], @@ -1003,7 +1003,7 @@ proc newProtocol*( Protocol( privateKey: privKey, localNode: node, - bindAddress: Address(ip: ValidIpAddress.init(bindIp), port: bindPort), + bindAddress: Address(ip: bindIp, port: bindPort), codec: Codec(localNode: node, privKey: privKey, sessions: Sessions.init(256)), bootstrapRecords: @bootstrapRecords, diff --git a/tests/fuzzing/discoveryv5/fuzz_decode_packet.nim b/tests/fuzzing/discoveryv5/fuzz_decode_packet.nim index 4d23e71..80ba808 100644 --- a/tests/fuzzing/discoveryv5/fuzz_decode_packet.nim +++ b/tests/fuzzing/discoveryv5/fuzz_decode_packet.nim @@ -12,12 +12,12 @@ init: privKeyB = PrivateKey.fromHex(nodeBKey)[] # receive -> decode enrRecA = enr.Record.init(1, privKeyA, - some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)), + some(parseIpAddress("127.0.0.1")), some(Port(9000)), some(Port(9000))).expect("Properly initialized private key") nodeA = newNode(enrRecA).expect("Properly initialized record") enrRecB = enr.Record.init(1, privKeyB, - some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)), + some(parseIpAddress("127.0.0.1")), some(Port(9000)), some(Port(9000))).expect("Properly initialized private key") nodeB = newNode(enrRecB).expect("Properly initialized record") diff --git a/tests/fuzzing/enr/generate.nim b/tests/fuzzing/enr/generate.nim index c2c3131..7f1378f 100644 --- a/tests/fuzzing/enr/generate.nim +++ b/tests/fuzzing/enr/generate.nim @@ -11,7 +11,7 @@ proc generate() = let rng = newRng() privKey = PrivateKey.random(rng[]) - ip = some(ValidIpAddress.init("127.0.0.1")) + ip = some(parseIpAddress("127.0.0.1")) port = some(Port(20301)) block: diff --git a/tests/p2p/discv5_test_helper.nim b/tests/p2p/discv5_test_helper.nim index fb770d6..9745617 100644 --- a/tests/p2p/discv5_test_helper.nim +++ b/tests/p2p/discv5_test_helper.nim @@ -6,8 +6,8 @@ import export net -proc localAddress*(port: int): Address = - Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(port)) +func localAddress*(port: int): Address = + Address(ip: parseIpAddress("127.0.0.1"), port: Port(port)) proc initDiscoveryNode*( rng: ref HmacDrbgContext, @@ -35,12 +35,12 @@ proc initDiscoveryNode*( protocol -proc nodeIdInNodes*(id: NodeId, nodes: openArray[Node]): bool = +func nodeIdInNodes*(id: NodeId, nodes: openArray[Node]): bool = for n in nodes: if id == n.id: return true -proc generateNode*(privKey: PrivateKey, port: int = 20302, - ip: ValidIpAddress = ValidIpAddress.init("127.0.0.1"), +func generateNode*(privKey: PrivateKey, port: int = 20302, + ip: IpAddress = parseIpAddress("127.0.0.1"), localEnrFields: openArray[FieldPair] = []): Node = let port = Port(port) let enr = enr.Record.init(1, privKey, some(ip), @@ -55,7 +55,7 @@ proc generateNRandomNodes*(rng: var 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 pk = PrivateKey.random(rng) let node = generateNode(pk, ip = ip) @@ -63,23 +63,23 @@ proc nodeAndPrivKeyAtDistance*(n: Node, rng: var HmacDrbgContext, d: uint32, return (node, pk) 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.. decode enrRecA = enr.Record.init(1, privKeyA, - some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)), + some(parseIpAddress("127.0.0.1")), some(Port(9000)), some(Port(9000))).expect("Properly initialized private key") nodeA = newNode(enrRecA).expect("Properly initialized record") enrRecB = enr.Record.init(1, privKeyB, - some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)), + some(parseIpAddress("127.0.0.1")), some(Port(9000)), some(Port(9000))).expect("Properly initialized private key") nodeB = newNode(enrRecB).expect("Properly initialized record") @@ -479,12 +479,12 @@ suite "Discovery v5.1 Additional Encode/Decode": privKeyB = PrivateKey.random(rng[]) # receiver -> decode enrRecA = enr.Record.init(1, privKeyA, - some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)), + some(parseIpAddress("127.0.0.1")), some(Port(9000)), some(Port(9000))).expect("Properly initialized private key") nodeA = newNode(enrRecA).expect("Properly initialized record") enrRecB = enr.Record.init(1, privKeyB, - some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)), + some(parseIpAddress("127.0.0.1")), some(Port(9000)), some(Port(9000))).expect("Properly initialized private key") nodeB = newNode(enrRecB).expect("Properly initialized record") diff --git a/tests/p2p/test_enr.nim b/tests/p2p/test_enr.nim index e4beeb4..2a9efb4 100644 --- a/tests/p2p/test_enr.nim +++ b/tests/p2p/test_enr.nim @@ -68,7 +68,7 @@ suite "ENR": test "Create from ENode address": let keypair = KeyPair.random(rng[]) - ip = ValidIpAddress.init("10.20.30.40") + ip = parseIpAddress("10.20.30.40") port = some(Port(9000)) enr = Record.init( 100, keypair.seckey, some(ip), port, port,@[])[] @@ -92,7 +92,7 @@ suite "ENR": keypair = KeyPair.random(rng[]) port = none(Port) enr = Record.init( - 100, keypair.seckey, none(ValidIpAddress), port, port)[] + 100, keypair.seckey, none(IpAddress), port, port)[] typedEnr = get enr.toTypedRecord() check: @@ -123,7 +123,7 @@ suite "ENR": pk = PrivateKey.fromHex( "5d2908f3f09ea1ff2e327c3f623159639b00af406e9009de5fd4b910fc34049d")[] newField = toFieldPair("test", 123'u) - var r = Record.init(1, pk, none(ValidIpAddress), none(Port), none(Port))[] + var r = Record.init(1, pk, none(IpAddress), none(Port), none(Port))[] block: # Insert new k:v pair, update of seqNum should occur. let updated = r.update(pk, [newField]) @@ -190,11 +190,11 @@ suite "ENR": let pk = PrivateKey.fromHex( "5d2908f3f09ea1ff2e327c3f623159639b00af406e9009de5fd4b910fc34049d")[] - var r = Record.init(1, pk, none(ValidIpAddress), + var r = Record.init(1, pk, none(IpAddress), some(Port(9000)), some(Port(9000)))[] block: - let updated = r.update(pk, none(ValidIpAddress), + let updated = r.update(pk, none(IpAddress), some(Port(9000)), some(Port(9000))) check updated.isOk() check: @@ -204,7 +204,7 @@ suite "ENR": r.seqNum == 1 block: - let updated = r.update(pk, none(ValidIpAddress), + let updated = r.update(pk, none(IpAddress), some(Port(9001)), some(Port(9002))) check updated.isOk() check: @@ -214,7 +214,7 @@ suite "ENR": r.seqNum == 2 block: - let updated = r.update(pk, some(ValidIpAddress.init("10.20.30.40")), + let updated = r.update(pk, some(parseIpAddress("10.20.30.40")), some(Port(9000)), some(Port(9000))) check updated.isOk() @@ -233,7 +233,7 @@ suite "ENR": r.seqNum == 3 block: - let updated = r.update(pk, some(ValidIpAddress.init("10.20.30.40")), + let updated = r.update(pk, some(parseIpAddress("10.20.30.40")), some(Port(9001)), some(Port(9001))) check updated.isOk() diff --git a/tests/p2p/test_ip_vote.nim b/tests/p2p/test_ip_vote.nim index 34dfe79..9e6f855 100644 --- a/tests/p2p/test_ip_vote.nim +++ b/tests/p2p/test_ip_vote.nim @@ -12,9 +12,9 @@ suite "IP vote": var votes = IpVote.init(2) let - addr1 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(1)) - addr2 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(2)) - addr3 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(3)) + addr1 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(1)) + addr2 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(2)) + addr3 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(3)) votes.insert(NodeId.random(rng[]), addr1); votes.insert(NodeId.random(rng[]), addr1); @@ -32,9 +32,9 @@ suite "IP vote": var votes = IpVote.init(threshold) let - addr1 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(1)) - addr2 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(2)) - addr3 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(3)) + addr1 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(1)) + addr2 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(2)) + addr3 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(3)) votes.insert(NodeId.random(rng[]), addr1); votes.insert(NodeId.random(rng[]), addr2); @@ -50,9 +50,9 @@ suite "IP vote": var votes = IpVote.init(threshold) let - addr1 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(1)) - addr2 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(2)) - addr3 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(3)) + addr1 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(1)) + addr2 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(2)) + addr3 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(3)) votes.insert(NodeId.random(rng[]), addr1); votes.insert(NodeId.random(rng[]), addr2); @@ -68,8 +68,8 @@ suite "IP vote": var votes = IpVote.init(threshold) let - addr1 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(1)) - addr2 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(2)) + addr1 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(1)) + addr2 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(2)) let nodeIdA = NodeId.random(rng[]) votes.insert(nodeIdA, addr1); @@ -86,9 +86,9 @@ suite "IP vote": var votes = IpVote.init(threshold) let - addr1 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(1)) - addr2 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(2)) - addr3 = Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(3)) + addr1 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(1)) + addr2 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(2)) + addr3 = Address(ip: parseIpAddress("127.0.0.1"), port: Port(3)) let nodeIdA = NodeId.random(rng[]) votes.insert(nodeIdA, addr1); diff --git a/tests/p2p/test_routing_table.nim b/tests/p2p/test_routing_table.nim index 4d32bca..ae08ac8 100644 --- a/tests/p2p/test_routing_table.nim +++ b/tests/p2p/test_routing_table.nim @@ -291,7 +291,7 @@ suite "Routing Table Tests": # Further fill the bucket with nodes with different ip. let diffIpNodes = node.nodesAtDistanceUniqueIp(rng[], 256, int(BUCKET_SIZE - DefaultTableIpLimits.bucketIpLimit), - ValidIpAddress.init("192.168.0.1")) + parseIpAddress("192.168.0.1")) for n in diffIpNodes: check table.addNode(n) == Added @@ -304,7 +304,7 @@ suite "Routing Table Tests": # Add more nodes with different ip and distance 255 to get in the new bucket let diffIpNodes = node.nodesAtDistanceUniqueIp(rng[], 255, int(BUCKET_SIZE - DefaultTableIpLimits.bucketIpLimit - 1), - ValidIpAddress.init("192.168.1.1")) + parseIpAddress("192.168.1.1")) for n in diffIpNodes: check table.addNode(n) == Added @@ -329,7 +329,7 @@ suite "Routing Table Tests": for j in 0..