fix AckFrame writing with gap lengths which are a multiple of 255

fixes #306
This commit is contained in:
Marten Seemann 2016-09-02 11:47:20 +07:00
parent 76e67803ac
commit 05265bd3c5
No known key found for this signature in database
GPG key ID: 3603F40B121FCDEA
2 changed files with 62 additions and 5 deletions

View file

@ -287,7 +287,7 @@ func (f *AckFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error
if i == int(num)-1 { // last block
lengthWritten = uint64(length)
gapWritten = uint8(gap % 0xFF)
gapWritten = uint8(1 + ((gap - 1) % 255))
} else {
lengthWritten = 0
gapWritten = 0xFF
@ -403,10 +403,10 @@ func (f *AckFrame) numWritableNackRanges() uint64 {
}
lastAckRange := f.AckRanges[i-1]
gap := lastAckRange.FirstPacketNumber - ackRange.LastPacketNumber
rangeLength := uint64(gap) / (0xFF + 1)
if uint64(gap)%(0xFF+1) != 0 {
rangeLength++
gap := lastAckRange.FirstPacketNumber - ackRange.LastPacketNumber - 1
rangeLength := 1 + uint64(gap)/0xFF
if uint64(gap)%0xFF == 0 {
rangeLength--
}
if numRanges+rangeLength < 0xFF {