From 8298acd410b79de81a210e811326cbe4ff7e90c8 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Wed, 16 Feb 2022 18:50:41 +0100 Subject: [PATCH] attempt to clean up send proc names - interface between Transport and Protocol is at the encoded Message level --- eth/p2p/discoveryv5/protocol.nim | 6 +++--- eth/p2p/discoveryv5/transport.nim | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/eth/p2p/discoveryv5/protocol.nim b/eth/p2p/discoveryv5/protocol.nim index 81bf59d..583d6a0 100644 --- a/eth/p2p/discoveryv5/protocol.nim +++ b/eth/p2p/discoveryv5/protocol.nim @@ -230,7 +230,7 @@ proc sendNodes(d: Protocol, toId: NodeId, toAddr: Address, reqId: RequestId, message: NodesMessage, reqId: RequestId) {.nimcall.} = trace "Respond message packet", dstId = toId, address = toAddr, kind = MessageKind.nodes - d.transport.send(toId, toAddr, encodeMessage(message, reqId)) + d.transport.sendMessage(toId, toAddr, encodeMessage(message, reqId)) if nodes.len == 0: # In case of 0 nodes, a reply is still needed @@ -258,7 +258,7 @@ proc handlePing(d: Protocol, fromId: NodeId, fromAddr: Address, port: fromAddr.port.uint16) trace "Respond message packet", dstId = fromId, address = fromAddr, kind = MessageKind.pong - d.transport.send(fromId, fromAddr, encodeMessage(pong, reqId)) + d.transport.sendMessage(fromId, fromAddr, encodeMessage(pong, reqId)) proc handleFindNode(d: Protocol, fromId: NodeId, fromAddr: Address, fn: FindNodeMessage, reqId: RequestId) = @@ -294,7 +294,7 @@ proc handleTalkReq(d: Protocol, fromId: NodeId, fromAddr: Address, trace "Respond message packet", dstId = fromId, address = fromAddr, kind = MessageKind.talkresp - d.transport.send(fromId, fromAddr, encodeMessage(talkresp, reqId)) + d.transport.sendMessage(fromId, fromAddr, encodeMessage(talkresp, reqId)) proc handleMessage(d: Protocol, srcId: NodeId, fromAddr: Address, message: Message) = diff --git a/eth/p2p/discoveryv5/transport.nim b/eth/p2p/discoveryv5/transport.nim index ef22469..7965fa2 100644 --- a/eth/p2p/discoveryv5/transport.nim +++ b/eth/p2p/discoveryv5/transport.nim @@ -31,7 +31,7 @@ type node: Node message: seq[byte] -proc send*(t: Transport, a: Address, data: seq[byte]) = +proc sendToA(t: Transport, a: Address, data: seq[byte]) = let ta = initTAddress(a.ip, a.port) let f = t.transp.sendTo(ta, data) f.callback = proc(data: pointer) {.gcsafe.} = @@ -50,12 +50,12 @@ proc send*(t: Transport, a: Address, data: seq[byte]) = proc send(t: Transport, n: Node, data: seq[byte]) = doAssert(n.address.isSome()) - t.send(n.address.get(), data) + t.sendToA(n.address.get(), data) -proc send*(t: Transport, toId: NodeId, toAddr: Address, message: seq[byte]) = +proc sendMessage*(t: Transport, toId: NodeId, toAddr: Address, message: seq[byte]) = let (data, _) = encodeMessagePacket(t.rng[], t.codec, toId, toAddr, message) - t.send(toAddr, data) + t.sendToA(toAddr, data) # TODO: This could be improved to do the clean-up immediatily in case a non # whoareyou response does arrive, but we would need to store the AuthTag @@ -93,7 +93,7 @@ proc sendWhoareyou(t: Transport, toId: NodeId, a: Address, t.codec.handshakes.del(key) trace "Send whoareyou", dstId = toId, address = a - t.send(a, data) + t.sendToA(a, data) else: debug "Node with this id already has ongoing handshake, ignoring packet"