Add discv5 provided ENR directly to Portal protocol routing table (#1714)
* Add discv5 provided ENR directly to Portal protocol routing table Previous version of getting the ENR from the discv5 routing table would not work due to the order of first calling the talk protocol handler and only after that the addEnr to the disc5 routing table. Instead of changing this order, pass along the ENR directly to avoid this additional getNode call. * Still request ENR from discv5 if it wasn't passed via handshake
This commit is contained in:
parent
f177f5bf11
commit
7ae333ac8b
|
@ -381,7 +381,7 @@ proc handleOffer(p: PortalProtocol, o: OfferMessage, srcId: NodeId): seq[byte] =
|
||||||
AcceptMessage(connectionId: connectionId, contentKeys: contentKeysBitList))
|
AcceptMessage(connectionId: connectionId, contentKeys: contentKeysBitList))
|
||||||
|
|
||||||
proc messageHandler(protocol: TalkProtocol, request: seq[byte],
|
proc messageHandler(protocol: TalkProtocol, request: seq[byte],
|
||||||
srcId: NodeId, srcUdpAddress: Address): seq[byte] =
|
srcId: NodeId, srcUdpAddress: Address, node: Opt[Node]): seq[byte] =
|
||||||
doAssert(protocol of PortalProtocol)
|
doAssert(protocol of PortalProtocol)
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
|
@ -393,18 +393,22 @@ proc messageHandler(protocol: TalkProtocol, request: seq[byte],
|
||||||
if decoded.isOk():
|
if decoded.isOk():
|
||||||
let message = decoded.get()
|
let message = decoded.get()
|
||||||
trace "Received message request", srcId, srcUdpAddress, kind = message.kind
|
trace "Received message request", srcId, srcUdpAddress, kind = message.kind
|
||||||
# Received a proper Portal message, check if this node exists in the base
|
# Received a proper Portal message, check first if an ENR is provided by
|
||||||
# routing table and add if so.
|
# the discovery v5 layer and add it to the portal network routing table.
|
||||||
# When the node exists in the base discv5 routing table it is likely that
|
# If not provided through the handshake, try to get it from the discovery v5
|
||||||
# it will/would end up in the portal routing tables too but that is not
|
# routing table.
|
||||||
# certain as more nodes might exists on the base layer, and it will depend
|
# When the node would be eligable for the portal network routing table, it
|
||||||
# on the distance, order of lookups, etc.
|
# is possible that it exists in the base discv5 routing table as the same
|
||||||
# Note: Could add a findNodes with distance 0 call when not, and perhaps,
|
# node ids are used. It is not certain at all however as more nodes might
|
||||||
# optionally pass ENRs if the message was a discv5 handshake containing the
|
# exists on the base layer, and it will also depend on the distance,
|
||||||
# ENR.
|
# order of lookups, etc.
|
||||||
let node = p.baseProtocol.getNode(srcId)
|
# Note: As third measure, could run a findNodes request with distance 0.
|
||||||
if node.isSome():
|
if node.isSome():
|
||||||
discard p.routingTable.addNode(node.get())
|
discard p.routingTable.addNode(node.get())
|
||||||
|
else:
|
||||||
|
let node = p.baseProtocol.getNode(srcId)
|
||||||
|
if node.isSome():
|
||||||
|
discard p.routingTable.addNode(node.get())
|
||||||
|
|
||||||
portal_message_requests_incoming.inc(
|
portal_message_requests_incoming.inc(
|
||||||
labelValues = [$p.protocolId, $message.kind])
|
labelValues = [$p.protocolId, $message.kind])
|
||||||
|
|
|
@ -131,10 +131,6 @@ procSuite "Portal Wire Protocol Tests":
|
||||||
check (await proto1.baseProtocol.ping(proto2.localNode)).isOk()
|
check (await proto1.baseProtocol.ping(proto2.localNode)).isOk()
|
||||||
check (await proto2.baseProtocol.ping(proto1.localNode)).isOk()
|
check (await proto2.baseProtocol.ping(proto1.localNode)).isOk()
|
||||||
|
|
||||||
# Start the portal protocol to seed nodes from the discoveryv5 routing
|
|
||||||
# table.
|
|
||||||
proto2.start()
|
|
||||||
|
|
||||||
let contentKey = ByteList.init(@[1'u8])
|
let contentKey = ByteList.init(@[1'u8])
|
||||||
|
|
||||||
# content does not exist so this should provide us with the closest nodes
|
# content does not exist so this should provide us with the closest nodes
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 074edff1b4cdbc9989e2ee9f996437a28a3ba182
|
Subproject commit 0d7e7448c4a2a50136e726be7d4e4a38e094e8e3
|
Loading…
Reference in New Issue