From 91961c8c6f36c64638f481ca790311a1845f3440 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 8 Jul 2019 12:53:45 +0700 Subject: [PATCH] add the Retire Prior To field to the NEW_CONNECTION_ID frame --- internal/wire/new_connection_id_frame.go | 9 ++++++++- internal/wire/new_connection_id_frame_test.go | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/wire/new_connection_id_frame.go b/internal/wire/new_connection_id_frame.go index 9a612aa6c..ea472e41b 100644 --- a/internal/wire/new_connection_id_frame.go +++ b/internal/wire/new_connection_id_frame.go @@ -13,6 +13,7 @@ import ( // A NewConnectionIDFrame is a NEW_CONNECTION_ID frame type NewConnectionIDFrame struct { SequenceNumber uint64 + RetirePriorTo uint64 ConnectionID protocol.ConnectionID StatelessResetToken [16]byte } @@ -26,6 +27,10 @@ func parseNewConnectionIDFrame(r *bytes.Reader, _ protocol.VersionNumber) (*NewC if err != nil { return nil, err } + ret, err := utils.ReadVarInt(r) + if err != nil { + return nil, err + } connIDLen, err := r.ReadByte() if err != nil { return nil, err @@ -39,6 +44,7 @@ func parseNewConnectionIDFrame(r *bytes.Reader, _ protocol.VersionNumber) (*NewC } frame := &NewConnectionIDFrame{ SequenceNumber: seq, + RetirePriorTo: ret, ConnectionID: connID, } if _, err := io.ReadFull(r, frame.StatelessResetToken[:]); err != nil { @@ -54,6 +60,7 @@ func parseNewConnectionIDFrame(r *bytes.Reader, _ protocol.VersionNumber) (*NewC func (f *NewConnectionIDFrame) Write(b *bytes.Buffer, _ protocol.VersionNumber) error { b.WriteByte(0x18) utils.WriteVarInt(b, f.SequenceNumber) + utils.WriteVarInt(b, f.RetirePriorTo) connIDLen := f.ConnectionID.Len() if connIDLen < 4 || connIDLen > 18 { return fmt.Errorf("invalid connection ID length: %d", connIDLen) @@ -66,5 +73,5 @@ func (f *NewConnectionIDFrame) Write(b *bytes.Buffer, _ protocol.VersionNumber) // Length of a written frame func (f *NewConnectionIDFrame) Length(protocol.VersionNumber) protocol.ByteCount { - return 1 + utils.VarIntLen(f.SequenceNumber) + 1 /* connection ID length */ + protocol.ByteCount(f.ConnectionID.Len()) + 16 + return 1 + utils.VarIntLen(f.SequenceNumber) + utils.VarIntLen(f.RetirePriorTo) + 1 /* connection ID length */ + protocol.ByteCount(f.ConnectionID.Len()) + 16 } diff --git a/internal/wire/new_connection_id_frame_test.go b/internal/wire/new_connection_id_frame_test.go index 55c38a81a..5a299918d 100644 --- a/internal/wire/new_connection_id_frame_test.go +++ b/internal/wire/new_connection_id_frame_test.go @@ -15,6 +15,7 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() { It("accepts a sample frame", func() { data := []byte{0x18} data = append(data, encodeVarInt(0xdeadbeef)...) // sequence number + data = append(data, encodeVarInt(0xcafe)...) // retire prior to data = append(data, 10) // connection ID length data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...) // connection ID data = append(data, []byte("deadbeefdecafbad")...) // stateless reset token @@ -22,6 +23,7 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() { frame, err := parseNewConnectionIDFrame(b, versionIETFFrames) Expect(err).ToNot(HaveOccurred()) Expect(frame.SequenceNumber).To(Equal(uint64(0xdeadbeef))) + Expect(frame.RetirePriorTo).To(Equal(uint64(0xcafe))) Expect(frame.ConnectionID).To(Equal(protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})) Expect(string(frame.StatelessResetToken[:])).To(Equal("deadbeefdecafbad")) }) @@ -29,6 +31,7 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() { It("errors when the connection ID has an invalid length", func() { data := []byte{0x18} data = append(data, encodeVarInt(0xdeadbeef)...) // sequence number + data = append(data, encodeVarInt(0xcafe)...) // retire prior to data = append(data, 3) // connection ID length data = append(data, []byte{1, 2, 3}...) // connection ID data = append(data, []byte("deadbeefdecafbad")...) // stateless reset token @@ -40,6 +43,7 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() { It("errors on EOFs", func() { data := []byte{0x18} data = append(data, encodeVarInt(0xdeadbeef)...) // sequence number + data = append(data, encodeVarInt(0xcafe1234)...) // retire prior to data = append(data, 10) // connection ID length data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...) // connection ID data = append(data, []byte("deadbeefdecafbad")...) // stateless reset token @@ -57,6 +61,7 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() { token := [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} frame := &NewConnectionIDFrame{ SequenceNumber: 0x1337, + RetirePriorTo: 0x42, ConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6}, StatelessResetToken: token, } @@ -64,6 +69,7 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() { Expect(frame.Write(b, versionIETFFrames)).To(Succeed()) expected := []byte{0x18} expected = append(expected, encodeVarInt(0x1337)...) + expected = append(expected, encodeVarInt(0x42)...) expected = append(expected, 6) expected = append(expected, []byte{1, 2, 3, 4, 5, 6}...) expected = append(expected, token[:]...) @@ -74,6 +80,7 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() { token := [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} frame := &NewConnectionIDFrame{ SequenceNumber: 0xdecafbad, + RetirePriorTo: 0xdeadbeefcafe, ConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8}, StatelessResetToken: token, }