implement reading and writing of ACK delay time

This commit is contained in:
Lucas Clemente 2016-04-28 18:08:43 +02:00
parent a079b3e662
commit c07ad6ab76
3 changed files with 10 additions and 10 deletions

View file

@ -14,7 +14,7 @@ var errInvalidNackRanges = errors.New("AckFrame: ACK frame contains invalid NACK
type AckFrame struct {
Entropy byte
LargestObserved protocol.PacketNumber
DelayTime uint16 // Todo: properly interpret this value as described in the specification
DelayTime uint64
NackRanges []NackRange // has to be ordered. The NACK range with the highest FirstPacketNumber goes first, the NACK range with the lowest FirstPacketNumber goes last
}
@ -29,10 +29,10 @@ func (f *AckFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, pa
b.WriteByte(typeByte)
b.WriteByte(f.Entropy)
utils.WriteUint48(b, uint64(f.LargestObserved)) // TODO: send the correct length
utils.WriteUint16(b, 1) // TODO: Ack delay time
b.WriteByte(0x01) // Just one timestamp
b.WriteByte(0x00) // Delta Largest observed
utils.WriteUint32(b, 0) // First timestamp
utils.WriteUfloat16(b, f.DelayTime)
b.WriteByte(0x01) // Just one timestamp
b.WriteByte(0x00) // Delta Largest observed
utils.WriteUint32(b, 0) // First timestamp
if f.HasNACK() {
numRanges := uint64(0)
@ -150,7 +150,7 @@ func ParseAckFrame(r *bytes.Reader) (*AckFrame, error) {
}
frame.LargestObserved = protocol.PacketNumber(largestObserved)
frame.DelayTime, err = utils.ReadUint16(r)
frame.DelayTime, err = utils.ReadUfloat16(r)
if err != nil {
return nil, err
}

View file

@ -16,7 +16,7 @@ var _ = Describe("AckFrame", func() {
Expect(err).ToNot(HaveOccurred())
Expect(frame.Entropy).To(Equal(byte(0xA4)))
Expect(frame.LargestObserved).To(Equal(protocol.PacketNumber(0x03)))
Expect(frame.DelayTime).To(Equal(uint16(0x4523)))
Expect(frame.DelayTime).To(Equal(uint64(430464)))
Expect(frame.HasNACK()).To(Equal(false))
Expect(b.Len()).To(Equal(0))
})
@ -231,7 +231,7 @@ var _ = Describe("AckFrame", func() {
}
err := frame.Write(b, 1, 6)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x4c, 0x02, 0x01, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0}))
Expect(b.Bytes()).To(Equal([]byte{0x4c, 0x02, 0x01, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}))
})
It("writes a frame with one NACK range", func() {

View file

@ -228,7 +228,7 @@ var _ = Describe("Session", func() {
err := session.sendPacket()
Expect(err).NotTo(HaveOccurred())
Expect(conn.written).To(HaveLen(1))
Expect(conn.written[0]).To(ContainSubstring(string([]byte{0x4c, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0})))
Expect(conn.written[0]).To(ContainSubstring(string([]byte{0x4c, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0})))
})
It("sends queued stream frames", func() {
@ -240,7 +240,7 @@ var _ = Describe("Session", func() {
err := session.sendPacket()
Expect(err).NotTo(HaveOccurred())
Expect(conn.written).To(HaveLen(1))
Expect(conn.written[0]).To(ContainSubstring(string([]byte{0x4c, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0})))
Expect(conn.written[0]).To(ContainSubstring(string([]byte{0x4c, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0})))
Expect(conn.written[0]).To(ContainSubstring(string("foobar")))
})
})