Skip to content

Commit

Permalink
uTP: Add comments and constant to OOP packet conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Jan 13, 2025
1 parent 5619502 commit eb6df1a
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const packetComparator: Comparator<Packet<PacketType>> = (a: Packet<PacketType>,
return a.header.timestampMicroseconds - b.header.timestampMicroseconds;
}

const MAX_IN_FLIGHT_PACKETS = 3

export class RequestManager {
peerId: string
requestMap: Record<RequestId, ContentRequest>
Expand Down Expand Up @@ -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.`)
}
}
Expand Down

0 comments on commit eb6df1a

Please sign in to comment.