transport.sendMessage: avoid passing address twice

Node already has the address, so it does not make sense to
pass it as a separate parameter.
This commit is contained in:
Csaba Kiraly 2022-02-23 20:54:11 +01:00
parent 8298acd410
commit a7d8082fc7
2 changed files with 6 additions and 5 deletions

View File

@ -383,14 +383,13 @@ proc sendMessage*[T: SomeMessage](d: Protocol, toNode: Node, m: T):
RequestId = RequestId =
doAssert(toNode.address.isSome()) doAssert(toNode.address.isSome())
let let
address = toNode.address.get()
reqId = RequestId.init(d.rng[]) reqId = RequestId.init(d.rng[])
message = encodeMessage(m, reqId) message = encodeMessage(m, reqId)
trace "Send message packet", dstId = toNode.id, address, kind = messageKind(T) trace "Send message packet", dstId = toNode.id, address, kind = messageKind(T)
discovery_message_requests_outgoing.inc() discovery_message_requests_outgoing.inc()
d.transport.sendMessage(toNode, address, message) d.transport.sendMessage(toNode, message)
return reqId return reqId
proc ping*(d: Protocol, toNode: Node): proc ping*(d: Protocol, toNode: Node):

View File

@ -68,9 +68,11 @@ proc registerRequest(t: Transport, n: Node, message: seq[byte],
t.pendingRequests.del(nonce) t.pendingRequests.del(nonce)
##Todo: remove dependence on message. This should be higher ##Todo: remove dependence on message. This should be higher
proc sendMessage*(t: Transport, toNode: Node, address: Address, message: seq[byte]) = proc sendMessage*(t: Transport, toNode: Node, message: seq[byte]) =
let (data, nonce) = encodeMessagePacket(t.rng[], t.codec, toNode.id, doAssert(toNode.address.isSome())
address, message) let address = toNode.address.get()
let (data, nonce) = encodeMessagePacket(t.rng[], t.codec,
toNode.id, address, message)
t.registerRequest(toNode, message, nonce) t.registerRequest(toNode, message, nonce)
t.send(toNode, data) t.send(toNode, data)