mirror of https://github.com/status-im/nim-eth.git
Remove hashData usage on objects (#441)
* Remove hashData usage on objects * Add hash func for NodeId to avoid using the one of stint
This commit is contained in:
parent
307b4e51b4
commit
ae0920d40d
|
@ -16,7 +16,7 @@ type
|
|||
limit*: uint
|
||||
ips: Table[ValidIpAddress, uint]
|
||||
|
||||
func hash(ip: ValidIpAddress): Hash =
|
||||
func hash*(ip: ValidIpAddress): Hash =
|
||||
case ip.family
|
||||
of IpAddressFamily.IPv6: hash(ip.address_v6)
|
||||
of IpAddressFamily.IPv4: hash(ip.address_v4)
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
import
|
||||
std/hashes,
|
||||
nimcrypto, stint, chronos, stew/shims/net, chronicles,
|
||||
../../keys, ./enr
|
||||
../../keys, ../../net/utils,
|
||||
./enr
|
||||
|
||||
export stint
|
||||
|
||||
|
@ -82,6 +83,9 @@ func `==`*(a, b: Node): bool =
|
|||
(a.isNil and b.isNil) or
|
||||
(not a.isNil and not b.isNil and a.pubkey == b.pubkey)
|
||||
|
||||
func hash*(id: NodeId): Hash =
|
||||
hash(id.toByteArrayBE)
|
||||
|
||||
proc random*(T: type NodeId, rng: var BrHmacDrbgContext): T =
|
||||
var id: NodeId
|
||||
brHmacDrbgGenerate(addr rng, addr id, csize_t(sizeof(id)))
|
||||
|
@ -106,7 +110,8 @@ func shortLog*(id: NodeId): string =
|
|||
chronicles.formatIt(NodeId): shortLog(it)
|
||||
|
||||
func hash*(a: Address): hashes.Hash =
|
||||
hashData(unsafeAddr a, sizeof(a))
|
||||
let res = a.ip.hash !& a.port.hash
|
||||
!$res
|
||||
|
||||
func `$`*(a: Address): string =
|
||||
result.add($a.ip)
|
||||
|
|
Loading…
Reference in New Issue