Skip to content

Commit

Permalink
Merge branch 'master' into fluffy-peer-ban-list
Browse files Browse the repository at this point in the history
  • Loading branch information
bhartnett committed Jan 20, 2025
2 parents 5f91b1b + 285b6de commit 5e38c95
Showing 1 changed file with 1 addition and 53 deletions.
54 changes: 1 addition & 53 deletions fluffy/network/wire/portal_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,7 @@ proc offerImpl*(

return await reqResponse[OfferMessage, AcceptMessage](p, dst, offer)

proc recordsFromBytes*(
rawRecords: List[ByteList[2048], 32]
): PortalResult[seq[Record]] =
proc recordsFromBytes(rawRecords: List[ByteList[2048], 32]): PortalResult[seq[Record]] =
var records: seq[Record]
for r in rawRecords.asSeq():
let record = enr.Record.fromBytes(r.asSeq()).valueOr:
Expand Down Expand Up @@ -1551,18 +1549,6 @@ proc queryRandom*(
## Perform a query for a random target, return all nodes discovered.
p.query(NodeId.random(p.baseProtocol.rng[]))

proc getNClosestNodesWithRadius*(
p: PortalProtocol, targetId: NodeId, n: int, seenOnly: bool = false
): seq[(Node, UInt256)] =
let closestLocalNodes = p.neighbours(targetId, k = n, seenOnly = seenOnly)

var nodesWithRadiuses: seq[(Node, UInt256)]
for node in closestLocalNodes:
let radius = p.radiusCache.get(node.id)
if radius.isSome():
nodesWithRadiuses.add((node, radius.unsafeGet()))
return nodesWithRadiuses

proc neighborhoodGossip*(
p: PortalProtocol,
srcNodeId: Opt[NodeId],
Expand Down Expand Up @@ -1871,41 +1857,3 @@ proc resolve*(
return Opt.some(n)

return node

proc resolveWithRadius*(
p: PortalProtocol, id: NodeId
): Future[Opt[(Node, UInt256)]] {.async: (raises: [CancelledError]).} =
## Resolve a `Node` based on provided `NodeId`, also try to establish what
## is known radius of found node.
##
## This will first look in the own routing table. If the node is known, it
## will try to contact if for newer information. If node is not known or it
## does not reply, a lookup is done to see if it can find a (newer) record of
## the node on the network.
##
## If node is found, radius will be first checked in radius cache, it radius
## is not known node will be pinged to establish what is its current radius
##

let n = await p.resolve(id)
if n.isNone():
return Opt.none((Node, UInt256))

let node = n.unsafeGet()

let r = p.radiusCache.get(id)
if r.isSome():
return Opt.some((node, r.unsafeGet()))

let pongResult = await p.ping(node)
if pongResult.isOk():
let maybeRadius = p.radiusCache.get(id)
# After successful ping radius should already be in cache, but for the
# unlikely case that it is not, check it just to be sure.
# TODO: refactor ping to return node radius.
if maybeRadius.isNone():
return Opt.none((Node, UInt256))
else:
return Opt.some((node, maybeRadius.unsafeGet()))
else:
return Opt.none((Node, UInt256))

0 comments on commit 5e38c95

Please sign in to comment.