Skip to content

Commit

Permalink
Fix gap block in edge condition
Browse files Browse the repository at this point in the history
Fix gap block in edge condition
  • Loading branch information
cnderrauber committed Jul 1, 2024
1 parent 06c44b3 commit fc54aec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
24 changes: 14 additions & 10 deletions receive_payload_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,25 @@ func (q *receivePayloadQueue) getGapAckBlocks() (gapAckBlocks []gapAckBlock) {
if zeroBit, ok := getFirstZeroBit(q.tsnBitmask[index], offset, 64); ok {
b.end = uint16(tsn + uint32(zeroBit-offset) - 1 - q.cumulativeTSN)
tsn += uint32(zeroBit - offset)
gapAckBlocks = append(gapAckBlocks, gapAckBlock{
start: b.start,
end: b.end,
})
findEnd = false
} else {
tsn += uint32(64 - offset)
if tsn > endTSN {
b.end = uint16(endTSN - q.cumulativeTSN)
if sna32LTE(tsn, endTSN) {
gapAckBlocks = append(gapAckBlocks, gapAckBlock{
start: b.start,
end: b.end,
})
break
}
findEnd = false
} else {
tsn += uint32(64 - offset)
}

// no zero bit at the end, close and append the last gap
if sna32GT(tsn, endTSN) {
b.end = uint16(endTSN - q.cumulativeTSN)
gapAckBlocks = append(gapAckBlocks, gapAckBlock{
start: b.start,
end: b.end,
})
break
}
}
}
Expand Down
23 changes: 13 additions & 10 deletions receive_payload_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,25 @@ func TestReceivePayloadQueue(t *testing.T) {
assert.Zero(t, q.size())
assert.Empty(t, q.getGapAckBlocks())

nextTSN := initTSN + maxOffset - 1
assert.True(t, q.push(nextTSN))
assert.Equal(t, 1, q.size())
lastTSN, ok := q.getLastTSNReceived()
assert.True(t, lastTSN == nextTSN && ok, "lastTSN:%d, ok:%t", lastTSN, ok)
assert.True(t, q.hasChunk(nextTSN))

assert.True(t, q.push(initTSN))
assert.False(t, q.canPush(initTSN-1))
assert.True(t, q.canPush(initTSN+maxOffset-1))
assert.False(t, q.canPush(initTSN+maxOffset))
assert.False(t, q.push(initTSN+maxOffset))
assert.Equal(t, 1, q.size())
assert.True(t, q.canPush(nextTSN-1))
assert.Equal(t, 2, q.size())

gaps := q.getGapAckBlocks()
assert.EqualValues(t, []gapAckBlock{{start: uint16(1), end: uint16(1)}}, gaps)

nextTSN := initTSN + maxOffset - 1
assert.True(t, q.push(nextTSN))
assert.Equal(t, 2, q.size())
lastTSN, ok := q.getLastTSNReceived()
assert.True(t, lastTSN == nextTSN && ok, "lastTSN:%d, ok:%t", lastTSN, ok)
assert.True(t, q.hasChunk(nextTSN))
assert.EqualValues(t, []gapAckBlock{
{start: uint16(1), end: uint16(1)},
{start: uint16(maxOffset), end: uint16(maxOffset)},
}, gaps)

assert.True(t, q.pop(false))
assert.Equal(t, 1, q.size())
Expand Down

0 comments on commit fc54aec

Please sign in to comment.