diff --git a/eth/p2p/discoveryv5/enr.nim b/eth/p2p/discoveryv5/enr.nim index 1cad2f7..bb5c575 100644 --- a/eth/p2p/discoveryv5/enr.nim +++ b/eth/p2p/discoveryv5/enr.nim @@ -13,6 +13,7 @@ import std/[strutils, macros, algorithm, options], nimcrypto/[keccak, utils], stew/shims/net, stew/[base64, results], + chronicles, ".."/../[rlp, keys] export options, results, keys @@ -489,6 +490,9 @@ proc `$`(f: Field): string = of kList: "(Raw RLP list) " & "0x" & f.listRaw.toHex +func `$`*(fp: FieldPair): string = + fp[0] & ":" & $fp[1] + proc `$`*(r: Record): string = result = "(" result &= $r.seqNum @@ -526,3 +530,5 @@ proc read*(rlp: var Rlp, T: typedesc[Record]): proc append*(rlpWriter: var RlpWriter, value: Record) = rlpWriter.appendRawBytes(value.raw) + +chronicles.formatIt(seq[FieldPair]): $it diff --git a/eth/p2p/discoveryv5/node.nim b/eth/p2p/discoveryv5/node.nim index eda62ac..391ba95 100644 --- a/eth/p2p/discoveryv5/node.nim +++ b/eth/p2p/discoveryv5/node.nim @@ -104,7 +104,6 @@ func shortLog*(id: NodeId): string = result.add("*") for i in (len(sid) - 6)..sid.high: result.add(sid[i]) -chronicles.formatIt(NodeId): shortLog(it) func hash*(a: Address): hashes.Hash = let res = a.ip.hash !& a.port.hash @@ -121,7 +120,6 @@ func shortLog*(n: Node): string = shortLog(n.id) & ":unaddressable" else: shortLog(n.id) & ":" & $n.address.get() -chronicles.formatIt(Node): shortLog(it) func shortLog*(nodes: seq[Node]): string = result = "[" @@ -135,4 +133,8 @@ func shortLog*(nodes: seq[Node]): string = result.add(shortLog(n)) result.add("]") + +chronicles.formatIt(NodeId): shortLog(it) +chronicles.formatIt(Address): $it +chronicles.formatIt(Node): shortLog(it) chronicles.formatIt(seq[Node]): shortLog(it) diff --git a/eth/p2p/discoveryv5/protocol.nim b/eth/p2p/discoveryv5/protocol.nim index 0ad9d74..69e6a40 100644 --- a/eth/p2p/discoveryv5/protocol.nim +++ b/eth/p2p/discoveryv5/protocol.nim @@ -173,6 +173,9 @@ const responseTimeout: defaultResponseTimeout ) +chronicles.formatIt(Option[Port]): $it +chronicles.formatIt(Option[ValidIpAddress]): $it + proc addNode*(d: Protocol, node: Node): bool = ## Add `Node` to discovery routing table. ## @@ -967,7 +970,7 @@ proc newProtocol*( # Anyhow, nim-beacon-chain would also require some changes to support port # remapping through NAT and this API is also subject to change once we # introduce support for ipv4 + ipv6 binding/listening. - let extraFields = mapIt(localEnrFields, toFieldPair(it[0], it[1])) + let customEnrFields = mapIt(localEnrFields, toFieldPair(it[0], it[1])) # TODO: # - Defect as is now or return a result for enr errors? # - In case incorrect key, allow for new enr based on new key (new node id)? @@ -975,18 +978,14 @@ proc newProtocol*( if previousRecord.isSome(): record = previousRecord.get() record.update(privKey, enrIp, enrTcpPort, enrUdpPort, - extraFields).expect("Record within size limits and correct key") + customEnrFields).expect("Record within size limits and correct key") else: record = enr.Record.init(1, privKey, enrIp, enrTcpPort, enrUdpPort, - extraFields).expect("Record within size limits") + customEnrFields).expect("Record within size limits") - debug "Initializing discovery v5", - enrIp, enrTcpPort, enrUdpPort, enrAutoUpdate, - bootstrapEnrs = bootstrapRecords, localEnrFields, - bindPort, bindIp - - info "ENR initialized", ip = enrIp, tcp = enrTcpPort, udp = enrUdpPort, - seqNum = record.seqNum, uri = toURI(record) + info "Discovery ENR initialized", enrAutoUpdate, seqNum = record.seqNum, + ip = enrIp, tcpPort = enrTcpPort, udpPort = enrUdpPort, + customEnrFields, uri = toURI(record) if enrIp.isNone(): if enrAutoUpdate: notice "No external IP provided for the ENR, this node will not be " &