From eb6df1af0735e840a7afdb3e35b05773f0cafae1 Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Mon, 13 Jan 2025 11:42:21 -0700 Subject: [PATCH] uTP: Add comments and constant to OOP packet conditional --- .../src/wire/utp/PortalNetworkUtp/requestManager.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/portalnetwork/src/wire/utp/PortalNetworkUtp/requestManager.ts b/packages/portalnetwork/src/wire/utp/PortalNetworkUtp/requestManager.ts index e051d6eaf..b4c07b5cc 100644 --- a/packages/portalnetwork/src/wire/utp/PortalNetworkUtp/requestManager.ts +++ b/packages/portalnetwork/src/wire/utp/PortalNetworkUtp/requestManager.ts @@ -15,6 +15,8 @@ const packetComparator: Comparator> = (a: Packet, return a.header.timestampMicroseconds - b.header.timestampMicroseconds; } +const MAX_IN_FLIGHT_PACKETS = 3 + export class RequestManager { peerId: string requestMap: Record @@ -124,12 +126,14 @@ export class RequestManager { this.currentPacket = this.packetHeap.pop() return this.processCurrentPacket() } else if (this.currentPacket.header.seqNr > request.socket.reader!.nextDataNr) { - if (this.getPacketCount(this.currentPacket.header.connectionId) < 3) { + if (this.getPacketCount(this.currentPacket.header.connectionId) < MAX_IN_FLIGHT_PACKETS) { + // Requeue packet. Optimistically assume expected packet has arrived out of order. this.logger.extend('PROCESS_CURRENT_PACKET')(`Packet is ahead of current reader position - seqNr: ${this.currentPacket.header.seqNr} > ${request.socket.reader?.nextDataNr}. Pushing packet back to heap.`) this.packetHeap.push(this.currentPacket) this.currentPacket = undefined return } else { + // Treat expected packet as lost. Process next packet (should trigger SELECTIVE_ACK) this.logger.extend('PROCESS_CURRENT_PACKET')(`Packet is ahead of current reader position - seqNr: ${this.currentPacket.header.seqNr} > ${request.socket.reader?.nextDataNr}. Treating expected packet as lost.`) } }