add support for receiving truncated acks

fixes #57
This commit is contained in:
Lucas Clemente
2016-05-06 21:06:29 +02:00
parent bb807fa5bd
commit 4167442032
2 changed files with 9 additions and 3 deletions

View File

@@ -17,6 +17,7 @@ type AckFrame struct {
Entropy byte
DelayTime time.Duration
NackRanges []NackRange // has to be ordered. The NACK range with the highest FirstPacketNumber goes first, the NACK range with the lowest FirstPacketNumber goes last
Truncated bool
}
// Write writes an ACK frame.
@@ -126,9 +127,7 @@ func ParseAckFrame(r *bytes.Reader) (*AckFrame, error) {
if typeByte&0x20 == 0x20 {
hasNACK = true
}
if typeByte&0x10 == 0x10 {
panic("truncated ACKs not yet implemented.")
}
frame.Truncated = typeByte&0x10 > 0
largestObservedLen := 2 * ((typeByte & 0x0C) >> 2)
if largestObservedLen == 0 {

View File

@@ -81,6 +81,13 @@ var _ = Describe("AckFrame", func() {
Expect(err).To(Equal(errInvalidNackRanges))
})
It("accepts truncated acks", func() {
b := bytes.NewReader([]byte{0x50, 0xA4, 0x03, 0x23, 0x45, 0x01, 0x02, 0xFF, 0xEE, 0xDD, 0xCC})
frame, err := ParseAckFrame(b)
Expect(err).ToNot(HaveOccurred())
Expect(frame.Truncated).To(BeTrue())
})
Context("contiguous NACK ranges", func() {
It("parses a frame with a contiguous NACK range spanning two fields", func() {
b := bytes.NewReader([]byte{0x64, 0x8, 0x2E, 0x01, 0x72, 0x1, 0x1, 0x0, 0xc0, 0x15, 0x0, 0x0, 0x2, 0x1, 0x2b, 0x0, 0xff})