Add resyn on next packet to buffer.Bucket (#968)

This commit is contained in:
Raja Subramanian
2022-08-30 12:58:10 +05:30
committed by GitHub
parent 69bf31944e
commit df189984f3
3 changed files with 56 additions and 9 deletions
+16 -4
View File
@@ -18,10 +18,11 @@ type Bucket struct {
buf []byte
src *[]byte
init bool
step int
headSN uint16
maxSteps int
init bool
resyncOnNextPacket bool
step int
headSN uint16
maxSteps int
}
func NewBucket(buf *[]byte) *Bucket {
@@ -35,6 +36,10 @@ func NewBucket(buf *[]byte) *Bucket {
return b
}
func (b *Bucket) ResyncOnNextPacket() {
b.resyncOnNextPacket = true
}
func (b *Bucket) AddPacket(pkt []byte) ([]byte, error) {
sn := binary.BigEndian.Uint16(pkt[seqNumOffset : seqNumOffset+seqNumSize])
if !b.init {
@@ -42,6 +47,13 @@ func (b *Bucket) AddPacket(pkt []byte) ([]byte, error) {
b.init = true
}
if b.resyncOnNextPacket {
b.resyncOnNextPacket = false
b.headSN = sn - 1
b.invalidate(0, b.maxSteps)
}
diff := sn - b.headSN
if diff == 0 || diff > (1<<15) {
// duplicate of last packet or out-of-order