Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uTP: compare AckNr's for ST_STATE packets #709

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { Heap } from "heap-js";
import { MAX_IN_FLIGHT_PACKETS, type RequestId } from "./types.js";

const packetComparator: Comparator<Packet<PacketType>> = (a: Packet<PacketType>, b: Packet<PacketType>) => {
// If packets belong to the same connection, sort by sequence number
// If packets belong to the same connection, sort by sequence number (or ackNr for ST_STATE packets)
if (a.header.connectionId === b.header.connectionId) {
return a.header.seqNr - b.header.seqNr;
return a.header.pType === PacketType.ST_STATE ? a.header.ackNr - b.header.ackNr : a.header.seqNr - b.header.seqNr;
}
// Otherwise, sort by timestamp
return a.header.timestampMicroseconds - b.header.timestampMicroseconds;
Expand Down Expand Up @@ -90,7 +90,7 @@ export class RequestManager {
} else {
this.packetHeap.push(packet)
}
this.logger.extend('HANDLE_PACKET')(`Adding ${PacketType[packet.header.pType]} [${packet.header.seqNr}] for Req:${packet.header.connectionId} to queue (size: ${this.packetHeap.size()} packets)`)
this.logger.extend('HANDLE_PACKET')(`Adding ${PacketType[packet.header.pType]} [${packet.header.pType === PacketType.ST_STATE ? packet.header.ackNr : packet.header.seqNr}] for Req:${packet.header.connectionId} to queue (size: ${this.packetHeap.size()} packets)`)
if (this.currentPacket === undefined) {
this.currentPacket = this.packetHeap.pop()
await this.processCurrentPacket()
Expand All @@ -108,7 +108,7 @@ export class RequestManager {
await this.processCurrentPacket()
return
}
this.logger.extend('PROCESS_CURRENT_PACKET')(`Processing ${PacketType[this.currentPacket.header.pType]} [${this.currentPacket.header.seqNr}] for Req:${this.currentPacket.header.connectionId}`)
this.logger.extend('PROCESS_CURRENT_PACKET')(`Processing ${PacketType[this.currentPacket.header.pType]} [${this.currentPacket.header.pType === PacketType.ST_STATE ? this.currentPacket.header.ackNr : this.currentPacket.header.seqNr}] for Req:${this.currentPacket.header.connectionId}`)
const request = this.lookupRequest(this.currentPacket.header.connectionId)
if (request === undefined) {
this.logger.extend('PROCESS_CURRENT_PACKET')(`Request not found for current packet - connectionId: ${this.currentPacket.header.connectionId}`)
Expand Down
2 changes: 1 addition & 1 deletion packages/portalnetwork/src/wire/utp/Socket/WriteSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class WriteSocket extends UtpSocket {
this._clearTimeout()
}
logProgress() {
const needed = this.writer!.dataChunks.filter((n) => !this.ackNrs.includes(n[0]))
const needed = this.writer!.dataChunks.filter((n) => !this.ackNrs.includes(n[0])).map((n) => n[0])
this.logger(
`AckNr's received (${this.ackNrs.length}/${
this.writer!.sentChunks.length
Expand Down
Loading