mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 01:26:17 +02:00
rollovers are now handled in SingleSenderStats::trackInboundPacket
This commit is contained in:
parent
3d4fae4b3f
commit
b210b07b81
1 changed files with 27 additions and 7 deletions
|
@ -156,6 +156,7 @@ SingleSenderStats::SingleSenderStats()
|
||||||
_totalLockWaitTime(0),
|
_totalLockWaitTime(0),
|
||||||
_totalElementsInPacket(0),
|
_totalElementsInPacket(0),
|
||||||
_totalPackets(0),
|
_totalPackets(0),
|
||||||
|
_incomingLastSequence(0),
|
||||||
_missingSequenceNumbers()
|
_missingSequenceNumbers()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -168,23 +169,42 @@ void SingleSenderStats::trackInboundPacket(unsigned short int incomingSequence,
|
||||||
const int MAX_MISSING_SEQUENCE_SIZE = 100;
|
const int MAX_MISSING_SEQUENCE_SIZE = 100;
|
||||||
|
|
||||||
unsigned short int expectedSequence = _totalPackets == 0 ? incomingSequence : _incomingLastSequence + 1;
|
unsigned short int expectedSequence = _totalPackets == 0 ? incomingSequence : _incomingLastSequence + 1;
|
||||||
|
|
||||||
if (incomingSequence == expectedSequence) { // on time
|
if (incomingSequence == expectedSequence) { // on time
|
||||||
_incomingLastSequence = incomingSequence;
|
_incomingLastSequence = incomingSequence;
|
||||||
}
|
}
|
||||||
else {
|
else { // out of order
|
||||||
// ignore packet if sequence number gap is unreasonable
|
|
||||||
if (std::abs(incomingSequence - expectedSequence) > MAX_REASONABLE_SEQUENCE_GAP) {
|
const int UINT16_RANGE = 65536;
|
||||||
|
|
||||||
|
int incoming = (int)incomingSequence;
|
||||||
|
int expected = (int)expectedSequence;
|
||||||
|
|
||||||
|
// check if the gap between incoming and expected is reasonable, taking possible rollover into consideration
|
||||||
|
int absGap = std::abs(incoming - expected);
|
||||||
|
if (absGap >= UINT16_RANGE - MAX_REASONABLE_SEQUENCE_GAP) {
|
||||||
|
// rollover likely occurred between incoming and expected.
|
||||||
|
// correct the larger of the two so that it's within [-65536, -1] while the other remains within [0, 65535]
|
||||||
|
if (incoming > expected) {
|
||||||
|
incoming -= UINT16_RANGE;
|
||||||
|
} else {
|
||||||
|
expected -= UINT16_RANGE;
|
||||||
|
}
|
||||||
|
} else if (absGap > MAX_REASONABLE_SEQUENCE_GAP) {
|
||||||
|
// ignore packet if gap is unreasonable
|
||||||
qDebug() << "ignoring unreasonable packet... sequence:" << incomingSequence
|
qDebug() << "ignoring unreasonable packet... sequence:" << incomingSequence
|
||||||
<< "_incomingLastSequence:" << _incomingLastSequence;
|
<< "_incomingLastSequence:" << _incomingLastSequence;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// now that rollover has been corrected for (if it occurred), incoming and expected can be
|
||||||
|
// compared to each other directly, though one of them might be negative
|
||||||
|
|
||||||
if (incomingSequence > expectedSequence) { // early
|
if (incoming > expected) { // early
|
||||||
|
|
||||||
// add all sequence numbers that were skipped to the missing sequence numbers list
|
// add all sequence numbers that were skipped to the missing sequence numbers list
|
||||||
for (int missingSequence = expectedSequence; missingSequence < incomingSequence; missingSequence++) {
|
for (int missingSequence = expected; missingSequence < incoming; missingSequence++) {
|
||||||
_missingSequenceNumbers.insert(missingSequence);
|
_missingSequenceNumbers.insert(missingSequence < 0 ? missingSequence + UINT16_RANGE : missingSequence);
|
||||||
}
|
}
|
||||||
_incomingLastSequence = incomingSequence;
|
_incomingLastSequence = incomingSequence;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue