Fix one more usage of the old-style IP-as-number handling in ENR

This commit is contained in:
Zahary Karadjov 2020-02-12 15:36:39 +02:00
parent 7b18d6e642
commit 31a4e8f959
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 9 additions and 7 deletions

View File

@ -27,17 +27,19 @@ proc newNode*(enode: ENode): Node =
result.id = result.node.pubkey.toNodeId()
proc newNode*(r: Record): Node =
var a: Address
var pk: PublicKey
# TODO: Handle IPv6
var ip = r.get("ip", int32)
let
ipBytes = r.get("ip", array[4, byte])
udpPort = r.get("udp", uint16)
a.ip = IpAddress(family: IpAddressFamily.IPv4)
bigEndian32(addr a.ip.address_v4, addr ip)
a.udpPort = Port(r.get("udp", int))
var pk: PublicKey
if recoverPublicKey(r.get("secp256k1", seq[byte]), pk) != EthKeysStatus.Success:
echo "Could not recover public key"
return
let a = Address(ip: IpAddress(family: IpAddressFamily.IPv4,
address_v4: ipBytes),
udpPort: Port udpPort)
result = newNode(initENode(pk, a))
result.record = r