Skip to content

[core] Refactored ACK window management to avoid false error reports#1888

Open
ethouris wants to merge 12 commits into
Haivision:masterfrom
ethouris:dev-refax-ack-window
Open

[core] Refactored ACK window management to avoid false error reports#1888
ethouris wants to merge 12 commits into
Haivision:masterfrom
ethouris:dev-refax-ack-window

Conversation

@ethouris

@ethouris ethouris commented Mar 24, 2021

Copy link
Copy Markdown
Collaborator

Fixes #253

This refactors the acknowledge function from Window tools, which not only returns what it was supposed to return so far as results, but also returns a status that allows to distinguish the reason as to why the ACK node could not be used this time to calculate RTT:

  • ROGUE: The node journal is completely out of tolerable range for existing ACK nodes (normally when it's from the future, or for ACK that has never been sent). IPE log should report this case.
  • OLD: One of the returning ACKACK packets was likely lost and therefore the next ACKACK swallowed this node as well (likely ACKACK packets have been reordered). Do not report this case, it's an unimportant problem. Note also that it's completely intended to remove the ACK node for which ACKACK has come together with all older nodes, even though an ACKACK could theoretically come for them - even if it happens (and results in OLD), the RTT measurement from such a node would be far from trustworthy.
  • WIPED: The node journal has been removed, although it was definitely within the range. IPE log should report this case.

Effectively, only if OK is returned should the RTT calculation be taken. If OLD, simply ignore the case (no log required), otherwise issue an IPE log message, as these situations shall never happen in a healthy code.

The body of acknowledge has been also completely rewritten for clarity and better performance. Also test cases have been provided.

@ethouris
ethouris force-pushed the dev-refax-ack-window branch from f3d43c3 to a5de970 Compare May 31, 2021 14:44
@ethouris
ethouris requested a review from maxsharabayko May 31, 2021 14:54
@ethouris
ethouris marked this pull request as ready for review May 31, 2021 15:19
Comment thread srtcore/window.cpp
Comment on lines +204 to +265
/* Updated old version remains for historical reasons
Status old_acknowledge(AckNode* r_aSeq, const size_t size, int& r_iHead, int& r_iTail, int32_t jrn, int32_t& w_ack, const steady_clock::time_point& currtime, int32_t& w_timediff)
{
// Head has not exceeded the physical boundary of the window
if (r_iHead >= r_iTail)
{
for (int i = r_iTail, n = r_iHead; i < n; ++ i)
{
// Looking for an identical ACK Seq. No.
if (seq == r_aSeq[i].iACKSeqNo)
// looking for an identical ACK AckNode. No.
if (jrn == r_aSeq[i].iJournal)
{
// Return the Data ACK it carried
r_ack = r_aSeq[i].iACK;
w_ack = r_aSeq[i].iAckSeq;

// Calculate RTT estimate
const int rtt = (int)count_microseconds(currtime - r_aSeq[i].tsTimeStamp);
w_timediff = (int32_t)count_microseconds(currtime - r_aSeq[i].tsTimeStamp);

if (i + 1 == r_iHead)
{
r_iTail = r_iHead = 0;
r_aSeq[0].iACKSeqNo = SRT_SEQNO_NONE;
r_aSeq[0].iJournal = SRT_SEQNO_NONE;
}
else
r_iTail = (i + 1) % size;

return rtt;
return OK;
}
}

// The record about ACK is not found in the buffer, RTT can not be calculated
return -1;
return ROGUE;
}

// Head has exceeded the physical window boundary, so it is behind tail
for (int j = r_iTail, n = r_iHead + (int)size; j < n; ++ j)
{
// Looking for an identical ACK Seq. No.
if (seq == r_aSeq[j % size].iACKSeqNo)
if (jrn == r_aSeq[j % size].iJournal)
{
// Return the Data ACK it carried
j %= size;
r_ack = r_aSeq[j].iACK;
w_ack = r_aSeq[j].iAckSeq;

// Calculate RTT estimate
const int rtt = (int)count_microseconds(currtime - r_aSeq[j].tsTimeStamp);
w_timediff = (int32_t)count_microseconds(currtime - r_aSeq[j].tsTimeStamp);

if (j == r_iHead)
{
r_iTail = r_iHead = 0;
r_aSeq[0].iACKSeqNo = -1;
r_aSeq[0].iJournal = -1;
}
else
r_iTail = (j + 1) % size;

return rtt;
return OK;
}
}

// The record about ACK is not found in the buffer, RTT can not be calculated
return -1;
return ROGUE;
}

} // namespace AckTools
*/
Comment thread srtcore/window.h
Comment on lines +125 to +131
/*
ACKWindow::Status old_acknowledge(int32_t jrn, int32_t& w_ackseq, const srt::sync::steady_clock::time_point& currtime, int32_t& w_timediff)
{
return ACKWindow::old_acknowledge(m_aSeq, SIZE, m_iHead, m_iTail, jrn, (w_ackseq), currtime, (w_timediff));
}
unblock for testing
*/
@ethouris ethouris added this to the v1.6.0 milestone Jun 15, 2026
@ethouris ethouris added Type: Maintenance Work required to maintain or clean up the code [core] Area: Changes in SRT library core labels Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[core] Area: Changes in SRT library core Type: Maintenance Work required to maintain or clean up the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IPE: ACK node overwritten message (impact unknown)

2 participants