Remove nim-eth dependency (#37)
This commit is contained in:
parent
faf5cad9d4
commit
f824c0a3cd
|
@ -13,7 +13,6 @@ requires "nim >= 1.2.0",
|
||||||
"bearssl >= 0.1.5 & < 0.2.0",
|
"bearssl >= 0.1.5 & < 0.2.0",
|
||||||
"chronicles >= 0.10.2 & < 0.11.0",
|
"chronicles >= 0.10.2 & < 0.11.0",
|
||||||
"chronos >= 3.0.11 & < 3.1.0",
|
"chronos >= 3.0.11 & < 3.1.0",
|
||||||
"eth >= 1.0.0 & < 1.1.0", # to be removed in https://github.com/status-im/nim-libp2p-dht/issues/2
|
|
||||||
"libp2p#c7504d2446717a48a79c8b15e0f21bbfc84957ba",
|
"libp2p#c7504d2446717a48a79c8b15e0f21bbfc84957ba",
|
||||||
"metrics",
|
"metrics",
|
||||||
"protobufserialization >= 0.2.0 & < 0.3.0",
|
"protobufserialization >= 0.2.0 & < 0.3.0",
|
||||||
|
|
|
@ -15,7 +15,6 @@ import
|
||||||
nimcrypto,
|
nimcrypto,
|
||||||
stew/shims/net,
|
stew/shims/net,
|
||||||
stint,
|
stint,
|
||||||
eth/net/utils,
|
|
||||||
./crypto,
|
./crypto,
|
||||||
./spr
|
./spr
|
||||||
|
|
||||||
|
@ -123,6 +122,11 @@ 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 =
|
||||||
|
case ip.family
|
||||||
|
of IpAddressFamily.IPv6: hash(ip.address_v6)
|
||||||
|
of IpAddressFamily.IPv4: hash(ip.address_v4)
|
||||||
|
|
||||||
func hash*(a: Address): hashes.Hash =
|
func hash*(a: Address): hashes.Hash =
|
||||||
let res = a.ip.hash !& a.port.hash
|
let res = a.ip.hash !& a.port.hash
|
||||||
!$res
|
!$res
|
||||||
|
|
|
@ -76,8 +76,8 @@
|
||||||
import
|
import
|
||||||
std/[tables, sets, options, math, sequtils, algorithm],
|
std/[tables, sets, options, math, sequtils, algorithm],
|
||||||
stew/shims/net as stewNet, json_serialization/std/net,
|
stew/shims/net as stewNet, json_serialization/std/net,
|
||||||
stew/[base64, endians2, results], chronicles, chronos, chronos/timer, stint, bearssl,
|
stew/[base64, endians2, results], chronicles, chronicles/chronos_tools, chronos, chronos/timer, stint, bearssl,
|
||||||
metrics, eth/async_utils,
|
metrics,
|
||||||
libp2p/[crypto/crypto, routing_record],
|
libp2p/[crypto/crypto, routing_record],
|
||||||
"."/[transport, messages, messages_encoding, node, routing_table, spr, random2, ip_vote, nodes_verification]
|
"."/[transport, messages, messages_encoding, node, routing_table, spr, random2, ip_vote, nodes_verification]
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,8 @@
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[algorithm, times, sequtils, bitops, sets, options],
|
std/[algorithm, times, sequtils, bitops, sets, options, tables],
|
||||||
stint, chronicles, metrics, bearssl, chronos, stew/shims/net as stewNet,
|
stint, chronicles, metrics, bearssl, chronos, stew/shims/net as stewNet,
|
||||||
eth/net/utils,
|
|
||||||
"."/[node, random2, spr]
|
"."/[node, random2, spr]
|
||||||
|
|
||||||
export options
|
export options
|
||||||
|
@ -28,6 +27,11 @@ type
|
||||||
calculateLogDistance*: LogDistanceProc
|
calculateLogDistance*: LogDistanceProc
|
||||||
calculateIdAtDistance*: IdAtDistanceProc
|
calculateIdAtDistance*: IdAtDistanceProc
|
||||||
|
|
||||||
|
IpLimits* = object
|
||||||
|
limit*: uint
|
||||||
|
ips: Table[ValidIpAddress, uint]
|
||||||
|
|
||||||
|
|
||||||
RoutingTable* = object
|
RoutingTable* = object
|
||||||
localNode*: Node
|
localNode*: Node
|
||||||
buckets*: seq[KBucket]
|
buckets*: seq[KBucket]
|
||||||
|
@ -92,7 +96,21 @@ type
|
||||||
ReplacementExisting
|
ReplacementExisting
|
||||||
NoAddress
|
NoAddress
|
||||||
|
|
||||||
# xor distance functions
|
func inc*(ipLimits: var IpLimits, ip: ValidIpAddress): bool =
|
||||||
|
let val = ipLimits.ips.getOrDefault(ip, 0)
|
||||||
|
if val < ipLimits.limit:
|
||||||
|
ipLimits.ips[ip] = val + 1
|
||||||
|
true
|
||||||
|
else:
|
||||||
|
false
|
||||||
|
|
||||||
|
func dec*(ipLimits: var IpLimits, ip: ValidIpAddress) =
|
||||||
|
let val = ipLimits.ips.getOrDefault(ip, 0)
|
||||||
|
if val == 1:
|
||||||
|
ipLimits.ips.del(ip)
|
||||||
|
elif val > 1:
|
||||||
|
ipLimits.ips[ip] = val - 1
|
||||||
|
|
||||||
func distance*(a, b: NodeId): UInt256 =
|
func distance*(a, b: NodeId): UInt256 =
|
||||||
## Calculate the distance to a NodeId.
|
## Calculate the distance to a NodeId.
|
||||||
a xor b
|
a xor b
|
||||||
|
|
Loading…
Reference in New Issue