Skip to content

Commit

Permalink
[core] Fix consistency of packet seqno in CRcvLossList (#2195)
Browse files Browse the repository at this point in the history
Make sure data to be inserted into CRcvLossList is monotonic, i.e. don't insert sequence numbers less (earlier) than the latest one.
  • Loading branch information
gou4shi1 authored Dec 3, 2021
1 parent 244d2f4 commit c9a8db7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
24 changes: 23 additions & 1 deletion srtcore/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ CRcvLossList::CRcvLossList(int size)
, m_iTail(-1)
, m_iLength(0)
, m_iSize(size)
, m_iLargestSeq(SRT_SEQNO_NONE)
{
m_caSeq = new Seq[m_iSize];

Expand All @@ -506,7 +507,25 @@ CRcvLossList::~CRcvLossList()
void CRcvLossList::insert(int32_t seqno1, int32_t seqno2)
{
// Data to be inserted must be larger than all those in the list
// guaranteed by the UDT receiver
if (m_iLargestSeq != SRT_SEQNO_NONE && CSeqNo::seqcmp(seqno1, m_iLargestSeq) <= 0)
{
if (CSeqNo::seqcmp(seqno2, m_iLargestSeq) > 0)
{
LOGC(qrlog.Warn,
log << "RCV-LOSS/insert: seqno1=" << seqno1 << " too small, adjust to "
<< CSeqNo::incseq(m_iLargestSeq));
seqno1 = CSeqNo::incseq(m_iLargestSeq);
}
else
{
LOGC(qrlog.Warn,
log << "RCV-LOSS/insert: (" << seqno1 << "," << seqno2
<< ") to be inserted is too small: m_iLargestSeq=" << m_iLargestSeq << ", m_iLength=" << m_iLength
<< ", m_iHead=" << m_iHead << ", m_iTail=" << m_iTail << " -- REJECTING");
return;
}
}
m_iLargestSeq = seqno2;

if (0 == m_iLength)
{
Expand Down Expand Up @@ -561,6 +580,9 @@ void CRcvLossList::insert(int32_t seqno1, int32_t seqno2)

bool CRcvLossList::remove(int32_t seqno)
{
if (m_iLargestSeq == SRT_SEQNO_NONE || CSeqNo::seqcmp(seqno, m_iLargestSeq) > 0)
m_iLargestSeq = seqno;

if (0 == m_iLength)
return false;

Expand Down
1 change: 1 addition & 0 deletions srtcore/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class CRcvLossList
int m_iTail; // last node in the list;
int m_iLength; // loss length
int m_iSize; // size of the static array
int m_iLargestSeq; // largest seq ever seen

private:
CRcvLossList(const CRcvLossList&);
Expand Down

0 comments on commit c9a8db7

Please sign in to comment.