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 packet heap #702

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Utp packet heap #702

wants to merge 7 commits into from

Conversation

ScottyPoi
Copy link
Collaborator

Replaces uTP Packet Queue array with Heap from heap-js.

Heap will sort packets waiting in queue so that out-of-order packets are reordered. This will cut back on unnecessary Selective Ack responses.

When receiving streams, especially from Trin nodes, we often receive pairs of packets with identical timestamps, and regularly end up processing them in the wrong order.

  • For example, we receive packets 1 and 2 simultaneously, but process packet 2 then packet 1. Next we recieve 3 and 4, but process 4 before 3.
  • This results in a lot of extra packets being exchanged due the the Selective Ack function. We report every other packet at missing, even though it isn't. So We get multiples of every other packet and send extra ACK packets.

The processCurrentPacket method was updated to skip repeat packets, and to requeue packets that arrive ahead of the current reader position. This update allows the packet-pair phenomenon to self correct.

Also updated and improved some logs, and added a method to report the total number of open uTP streams.

this.logger.extend('PROCESS_CURRENT_PACKET')(`Packet ${this.currentPacket.header.seqNr} already processed.`)
this.currentPacket = this.packetHeap.pop()
return this.processCurrentPacket()
} else if (this.currentPacket.header.seqNr > request.socket.reader!.nextDataNr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what makes selective acks basically never happen, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right -- this still lacks a way to respond to actual packet loss. This will just happen infinitely (or till other side sends a RESET).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit 774053c adds some logic to process out of order packets if there are 3 or more packets for that request in the heap. This preserves the reordering for the packet pair phenomenon, but still allows the selective ack response to happen if we get more than 3 packets ahead.

@ScottyPoi ScottyPoi marked this pull request as draft January 10, 2025 16:45
@ScottyPoi ScottyPoi marked this pull request as ready for review January 10, 2025 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants