Skip to content

Commit

Permalink
networks: skip nodes with active utp transfers during lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Dec 18, 2024
1 parent 2aaffda commit 77b1da0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/portalnetwork/src/networks/contentLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export class ContentLookup {
// Sort known peers by distance to the content
const nearest = this.network.routingTable.values()
for (const enr of nearest) {
// // Skip if the node has an active uTP request
if (this.network.portal.uTP.hasRequests(enr.nodeId) === true) {
continue
}
const dist = distance(enr.nodeId, this.contentId)
this.lookupPeers.push({ enr, distance: Number(dist) })
this.meta.set(enr.nodeId, { enr: enr.encodeTxt(), distance: bigIntToHex(dist) })
Expand Down Expand Up @@ -189,6 +193,10 @@ export class ContentLookup {
this.logger(`received ${res.enrs.length} ENRs for closer nodes`)
for (const enr of res.enrs) {
const decodedEnr = ENR.decode(enr as Uint8Array)
// // Skip if the node has an active uTP request
if (this.network.portal.uTP.hasRequests(decodedEnr.nodeId) === true) {
continue
}
if (!this.meta.has(decodedEnr.nodeId)) {
const dist = distance(decodedEnr.nodeId, this.contentId)
this.lookupPeers.push({ enr: decodedEnr, distance: Number(dist) })
Expand Down
7 changes: 7 additions & 0 deletions packages/portalnetwork/src/networks/nodeLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class NodeLookup {

private selectClosestPending(): ENR[] {
return Array.from(this.pendingNodes.values())
// Skip nodes with active uTP requests
.filter((peer) => this.network.portal.uTP.hasRequests(peer.nodeId) === false)
.sort((a, b) =>
Number(distance(a.nodeId, this.nodeSought) - distance(b.nodeId, this.nodeSought)),
)
Expand Down Expand Up @@ -91,6 +93,11 @@ export class NodeLookup {
continue
}

// Skip if the node has an active uTP request
if (this.network.portal.uTP.hasRequests(nodeId) === true) {
continue
}

// Add to pending
this.pendingNodes.set(nodeId, decodedEnr)
} catch (error) {
Expand Down

0 comments on commit 77b1da0

Please sign in to comment.