Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Dec 12, 2024
1 parent e6a4bf0 commit 7c0e1ac
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
3 changes: 2 additions & 1 deletion packages/portalnetwork/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,11 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent
await this.handleUTP(nodeAddress, message, message.request)
return
}

const network = this.networks.get(bytesToHex(message.protocol) as NetworkId)
if (!network) {
this.logger(`Received TALKREQ message on unsupported network ${bytesToHex(message.protocol)}`)
await this.sendPortalNetworkResponse(nodeAddress, message.id, new Uint8Array())

return
}

Expand Down
16 changes: 8 additions & 8 deletions packages/portalnetwork/src/networks/contentLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +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)) {
continue
}
// // 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 @@ -196,10 +196,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)) {
continue
}
// // 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
2 changes: 1 addition & 1 deletion packages/portalnetwork/src/networks/history/gossip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class GossipManager {
*/
private gossip(peer: ENR) {
// Skip if the node has an active uTP request
if (this.history.portal.uTP.hasRequests(peer.nodeId)) {
if (this.history.portal.uTP.hasRequests(peer.nodeId) === true) {
return
}
const queue = this.gossipQueues[peer.nodeId]
Expand Down
8 changes: 0 additions & 8 deletions packages/portalnetwork/src/networks/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,11 @@ export abstract class BaseNetwork extends EventEmitter {
networkId: NetworkId,
utpMessage?: boolean,
): Promise<Uint8Array> {
if (this.routingTable.isIgnored(enr.nodeId)) {
return new Uint8Array()
}
try {
const res = await this.portal.sendPortalNetworkMessage(enr, payload, networkId, utpMessage)
return res
} catch (err: any) {
this.logger.extend('error')(`${err.message}`)
this.routingTable['ignoreNode'](enr.nodeId)
return new Uint8Array()
}
}
Expand Down Expand Up @@ -322,10 +318,6 @@ export abstract class BaseNetwork extends EventEmitter {
value: findNodesMsg,
})
const res = await this.sendMessage(enr, payload, this.networkId)
if (res.length === 0) {
this.routingTable['ignoreNode'](enr.nodeId)
return
}
if (bytesToInt(res.slice(0, 1)) === MessageCodes.NODES) {
this.portal.metrics?.nodesMessagesReceived.inc()
const decoded = PortalWireMessageType.deserialize(res).value as NodesMessage
Expand Down
4 changes: 2 additions & 2 deletions packages/portalnetwork/src/networks/nodeLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class NodeLookup {
}

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

Expand Down Expand Up @@ -130,7 +130,7 @@ export class NodeLookup {

// Query selected nodes in parallel with timeout
const lookupPromises = currentBatch
.filter((peer) => !this.network.portal.uTP.hasRequests(peer.nodeId))
.filter((peer) => this.network.portal.uTP.hasRequests(peer.nodeId) === false)
.map((peer) => this.queryPeer(peer))

try {
Expand Down
1 change: 0 additions & 1 deletion packages/portalnetwork/src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
bigIntToBytes,
bytesToBigInt,
bytesToUnprefixedHex,
bytesToUtf8,
unprefixedHexToBytes,
} from '@ethereumjs/util'

Expand Down

0 comments on commit 7c0e1ac

Please sign in to comment.