From c07ad6ab76aeedba9dfbedd38e975f47deebe8bb Mon Sep 17 00:00:00 2001 From: Lucas Clemente Date: Thu, 28 Apr 2016 18:08:43 +0200 Subject: [PATCH] implement reading and writing of ACK delay time --- frames/ack_frame.go | 12 ++++++------ frames/ack_frame_test.go | 4 ++-- session_test.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frames/ack_frame.go b/frames/ack_frame.go index b5820a3e..703eea22 100644 --- a/frames/ack_frame.go +++ b/frames/ack_frame.go @@ -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 } diff --git a/frames/ack_frame_test.go b/frames/ack_frame_test.go index 892c2f63..871fadd9 100644 --- a/frames/ack_frame_test.go +++ b/frames/ack_frame_test.go @@ -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() { diff --git a/session_test.go b/session_test.go index b108a15b..4440e0f6 100644 --- a/session_test.go +++ b/session_test.go @@ -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"))) }) })