diff --git a/Changelog.md b/Changelog.md index 9b47637a..4725779f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,7 +2,7 @@ ## v0.6.0 (unreleased) -- Add support for QUIC 38 and 39, drop support for QUIC 35 and 36 +- Add support for QUIC 39, drop support for QUIC 35 - 37 - Added `quic.Config` options for maximal flow control windows - Add a `quic.Config` option for QUIC versions - Add a `quic.Config` option to request omission of the connection ID from a server diff --git a/client_test.go b/client_test.go index 25baa5dd..60b2546d 100644 --- a/client_test.go +++ b/client_test.go @@ -412,7 +412,7 @@ var _ = Describe("Client", func() { }) It("errors if the version is supported by quic-go, but disabled by the quic.Config", func() { - v := protocol.SupportedVersions[1] + v := protocol.VersionNumber(111) Expect(v).ToNot(Equal(cl.version)) Expect(config.Versions).ToNot(ContainElement(v)) cl.handlePacket(nil, wire.ComposeGQUICVersionNegotiation(0x1337, []protocol.VersionNumber{v})) diff --git a/integrationtests/self/handshake_rtt_test.go b/integrationtests/self/handshake_rtt_test.go index 803ace2b..1e49b0b9 100644 --- a/integrationtests/self/handshake_rtt_test.go +++ b/integrationtests/self/handshake_rtt_test.go @@ -75,7 +75,9 @@ var _ = Describe("Handshake RTT tests", func() { } It("fails when there's no matching version, after 1 RTT", func() { - Expect(len(protocol.SupportedVersions)).To(BeNumerically(">", 1)) + if len(protocol.SupportedVersions) == 1 { + Skip("Test requires at least 2 supported versions.") + } serverConfig.Versions = protocol.SupportedVersions[:1] runServerAndProxy() clientConfig := &quic.Config{ @@ -98,7 +100,9 @@ var _ = Describe("Handshake RTT tests", func() { }) It("does version negotiation in 1 RTT", func() { - Expect(len(protocol.SupportedVersions)).To(BeNumerically(">", 1)) + if len(protocol.SupportedVersions) == 1 { + Skip("Test requires at least 2 supported versions.") + } // the server doesn't support the highest supported version, which is the first one the client will try serverConfig.Versions = []protocol.VersionNumber{protocol.SupportedVersions[1]} runServerAndProxy() diff --git a/integrationtests/self/handshake_test.go b/integrationtests/self/handshake_test.go index cd5b69ad..b17104c9 100644 --- a/integrationtests/self/handshake_test.go +++ b/integrationtests/self/handshake_test.go @@ -49,7 +49,9 @@ var _ = Describe("Handshake tests", func() { Context("Version Negotiation", func() { It("when the server supports more versions than the client", func() { - Expect(len(protocol.SupportedVersions)).To(BeNumerically(">", 1)) + if len(protocol.SupportedVersions) == 1 { + Skip("Test requires at least 2 supported versions.") + } // the server doesn't support the highest supported version, which is the first one the client will try // but it supports a bunch of versions that the client doesn't speak serverConfig.Versions = []protocol.VersionNumber{protocol.SupportedVersions[1], 7, 8, 9} @@ -59,7 +61,9 @@ var _ = Describe("Handshake tests", func() { }) It("when the client supports more versions than the supports", func() { - Expect(len(protocol.SupportedVersions)).To(BeNumerically(">", 1)) + if len(protocol.SupportedVersions) == 1 { + Skip("Test requires at least 2 supported versions.") + } // the server doesn't support the highest supported version, which is the first one the client will try // but it supports a bunch of versions that the client doesn't speak runServer() diff --git a/internal/handshake/crypto_setup_client_test.go b/internal/handshake/crypto_setup_client_test.go index a88df546..39bf15d9 100644 --- a/internal/handshake/crypto_setup_client_test.go +++ b/internal/handshake/crypto_setup_client_test.go @@ -118,7 +118,7 @@ var _ = Describe("Client Crypto Setup", func() { &TransportParameters{IdleTimeout: protocol.DefaultIdleTimeout}, paramsChan, aeadChanged, - protocol.Version37, + protocol.Version39, nil, ) Expect(err).ToNot(HaveOccurred()) @@ -491,14 +491,14 @@ var _ = Describe("Client Crypto Setup", func() { }) It("has the right values for an inchoate CHLO", func() { - Expect(cs.version).ToNot(Equal(cs.initialVersion)) // make sure we can test that TagVER actually has the initial version, and not the current version + cs.version = cs.initialVersion - 1 cs.hostname = "sni-hostname" certManager.commonCertificateHashes = []byte("common certs") tags, err := cs.getTags() Expect(err).ToNot(HaveOccurred()) Expect(string(tags[TagSNI])).To(Equal(cs.hostname)) Expect(tags[TagPDMD]).To(Equal([]byte("X509"))) - Expect(tags[TagVER]).To(Equal([]byte("Q037"))) + Expect(tags[TagVER]).To(Equal([]byte("Q039"))) Expect(tags[TagCCS]).To(Equal(certManager.commonCertificateHashes)) Expect(tags).ToNot(HaveKey(TagTCID)) }) diff --git a/internal/protocol/version.go b/internal/protocol/version.go index c3cec86f..5ad04f00 100644 --- a/internal/protocol/version.go +++ b/internal/protocol/version.go @@ -15,9 +15,7 @@ const ( // The version numbers, making grepping easier const ( - Version37 VersionNumber = gquicVersion0 + 3*0x100 + 0x7 + iota - Version38 - Version39 + Version39 VersionNumber = gquicVersion0 + 3*0x100 + 0x9 + iota VersionTLS VersionNumber = 101 VersionWhatever VersionNumber = 0 // for when the version doesn't matter VersionUnknown VersionNumber = -1 @@ -27,8 +25,6 @@ const ( // must be in sorted descending order var SupportedVersions = []VersionNumber{ Version39, - Version38, - Version37, } // UsesTLS says if this QUIC version uses TLS 1.3 for the handshake diff --git a/internal/protocol/version_test.go b/internal/protocol/version_test.go index 6a25a9a7..c69888dd 100644 --- a/internal/protocol/version_test.go +++ b/internal/protocol/version_test.go @@ -8,21 +8,15 @@ import ( var _ = Describe("Version", func() { // version numbers taken from the wiki: https://github.com/quicwg/base-drafts/wiki/QUIC-Versions It("has the right gQUIC version number", func() { - Expect(Version37).To(BeEquivalentTo(0x51303337)) - Expect(Version38).To(BeEquivalentTo(0x51303338)) Expect(Version39).To(BeEquivalentTo(0x51303339)) }) It("says if a version supports TLS", func() { - Expect(Version37.UsesTLS()).To(BeFalse()) - Expect(Version38.UsesTLS()).To(BeFalse()) Expect(Version39.UsesTLS()).To(BeFalse()) Expect(VersionTLS.UsesTLS()).To(BeTrue()) }) It("has the right string representation", func() { - Expect(Version37.String()).To(Equal("gQUIC 37")) - Expect(Version38.String()).To(Equal("gQUIC 38")) Expect(Version39.String()).To(Equal("gQUIC 39")) Expect(VersionTLS.String()).To(ContainSubstring("TLS")) Expect(VersionWhatever.String()).To(Equal("whatever")) @@ -35,8 +29,6 @@ var _ = Describe("Version", func() { }) It("has the right representation for the H2 Alt-Svc tag", func() { - Expect(Version37.ToAltSvc()).To(Equal("37")) - Expect(Version38.ToAltSvc()).To(Equal("38")) Expect(Version39.ToAltSvc()).To(Equal("39")) Expect(VersionTLS.ToAltSvc()).To(Equal("101")) // check with unsupported version numbers from the wiki @@ -46,15 +38,11 @@ var _ = Describe("Version", func() { }) It("tells the Stream ID of the crypto stream", func() { - Expect(Version37.CryptoStreamID()).To(Equal(StreamID(1))) - Expect(Version38.CryptoStreamID()).To(Equal(StreamID(1))) Expect(Version39.CryptoStreamID()).To(Equal(StreamID(1))) Expect(VersionTLS.CryptoStreamID()).To(Equal(StreamID(0))) }) It("tells if a version uses the MAX_DATA, MAX_STREAM_DATA, BLOCKED and STREAM_BLOCKED frames", func() { - Expect(Version37.UsesMaxDataFrame()).To(BeFalse()) - Expect(Version38.UsesMaxDataFrame()).To(BeFalse()) Expect(Version39.UsesMaxDataFrame()).To(BeFalse()) Expect(VersionTLS.UsesMaxDataFrame()).To(BeTrue()) }) diff --git a/internal/utils/byteorder.go b/internal/utils/byteorder.go index d53025e6..35549f63 100644 --- a/internal/utils/byteorder.go +++ b/internal/utils/byteorder.go @@ -26,11 +26,8 @@ type ByteOrder interface { WriteUfloat16(*bytes.Buffer, uint64) } -// GetByteOrder gets the ByteOrder (little endian or big endian) used to represent values on the wire +// GetByteOrder gets the ByteOrder to represent values on the wire // from QUIC 39, values are encoded in big endian, before that in little endian func GetByteOrder(v protocol.VersionNumber) ByteOrder { - if v == protocol.Version37 || v == protocol.Version38 { - return LittleEndian - } return BigEndian } diff --git a/internal/utils/byteorder_test.go b/internal/utils/byteorder_test.go index 7547bafe..352475e9 100644 --- a/internal/utils/byteorder_test.go +++ b/internal/utils/byteorder_test.go @@ -7,12 +7,8 @@ import ( ) var _ = Describe("Byte Order", func() { - It("says little Little Endian before QUIC 39", func() { - Expect(GetByteOrder(protocol.Version37)).To(Equal(LittleEndian)) - Expect(GetByteOrder(protocol.Version38)).To(Equal(LittleEndian)) - }) - - It("says little Little Endian for QUIC 39", func() { + It("says little Little Endian for QUIC 39 and TLS", func() { Expect(GetByteOrder(protocol.Version39)).To(Equal(BigEndian)) + Expect(GetByteOrder(protocol.VersionTLS)).To(Equal(BigEndian)) }) }) diff --git a/internal/wire/ack_frame_test.go b/internal/wire/ack_frame_test.go index 3b10a5e8..a123f2be 100644 --- a/internal/wire/ack_frame_test.go +++ b/internal/wire/ack_frame_test.go @@ -2,7 +2,6 @@ package wire import ( "bytes" - "fmt" "io" "time" @@ -98,93 +97,6 @@ var _ = Describe("AckFrame", func() { Expect(err).To(MatchError(ErrInvalidFirstAckRange)) }) - Context("in little endian", func() { - It("parses the delay time", func() { - b := bytes.NewReader([]byte{0x40, - 0x3, // largest acked - 0x8e, 0x0, // delay time - 0x3, // block length - 0, - }) - frame, err := ParseAckFrame(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(3))) - Expect(frame.DelayTime).To(Equal(142 * time.Microsecond)) - }) - - It("errors on EOFs", func() { - data := []byte{0x60 ^ 0x4 ^ 0x1, - 0x66, 0x9, // largest acked - 0x23, 0x1, // delay time - 0x7, // num ACk blocks - 0x7, 0x0, // 1st block - 0xff, 0x0, 0x0, // 2nd block - 0xf5, 0x8a, 0x2, // 3rd block - 0xc8, 0xe6, 0x0, // 4th block - 0xff, 0x0, 0x0, // 5th block - 0xff, 0x0, 0x0, // 6th block - 0xff, 0x0, 0x0, // 7th block - 0x23, 0x13, 0x0, // 8th blocks - 0x2, // num timestamps - 0x1, 0x13, 0xae, 0xb, 0x0, // 1st timestamp - 0x0, 0x80, 0x5, // 2nd timestamp - } - _, err := ParseAckFrame(bytes.NewReader(data), versionLittleEndian) - Expect(err).NotTo(HaveOccurred()) - for i := range data { - _, err := ParseAckFrame(bytes.NewReader(data[0:i]), versionLittleEndian) - Expect(err).To(MatchError(io.EOF)) - } - }) - - Context("largest acked length", func() { - It("parses a frame with a 2 byte packet number", func() { - b := bytes.NewReader([]byte{0x40 | 0x4, - 0x37, 0x13, // largest acked - 0x0, 0x0, // delay time - 0x9, // block length - 0, - }) - frame, err := ParseAckFrame(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x1337))) - Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(0x1337 - 0x9 + 1))) - Expect(frame.HasMissingRanges()).To(BeFalse()) - Expect(b.Len()).To(BeZero()) - }) - - It("parses a frame with a 4 byte packet number", func() { - b := bytes.NewReader([]byte{0x40 | 0x8, - 0xad, 0xfb, 0xca, 0xde, // largest acked - 0x0, 0x0, // timesatmp - 0x5, // block length - 0, - }) - frame, err := ParseAckFrame(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0xdecafbad))) - Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(0xdecafbad - 5 + 1))) - Expect(frame.HasMissingRanges()).To(BeFalse()) - Expect(b.Len()).To(BeZero()) - }) - - It("parses a frame with a 6 byte packet number", func() { - b := bytes.NewReader([]byte{0x4 | 0xc, - 0x37, 0x13, 0xad, 0xfb, 0xca, 0xde, // largest acked - 0x0, 0x0, // delay time - 0x5, // block length - 0, - }) - frame, err := ParseAckFrame(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0xdecafbad1337))) - Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(0xdecafbad1337 - 5 + 1))) - Expect(frame.HasMissingRanges()).To(BeFalse()) - Expect(b.Len()).To(BeZero()) - }) - }) - }) - Context("in big endian", func() { It("parses the delay time", func() { b := bytes.NewReader([]byte{0x40, @@ -376,14 +288,14 @@ var _ = Describe("AckFrame", func() { // 255 missing packets fit into a single ACK block It("parses a frame with a range of 255 missing packets", func() { b := bytes.NewReader([]byte{0x60 ^ 0x4, - 0x15, 0x1, // largest acked + 0x1, 0x15, // largest acked 0x0, 0x0, // delay time 0x1, // num ACK blocks 0x3, // 1st block 0xff, 0x13, // 2nd block 0, }) - frame, err := ParseAckFrame(b, versionLittleEndian) + frame, err := ParseAckFrame(b, versionBigEndian) Expect(err).ToNot(HaveOccurred()) Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x115))) Expect(frame.HasMissingRanges()).To(BeTrue()) @@ -397,7 +309,7 @@ var _ = Describe("AckFrame", func() { // 256 missing packets fit into two ACK blocks It("parses a frame with a range of 256 missing packets", func() { b := bytes.NewReader([]byte{0x60 ^ 0x4, - 0x14, 0x1, // largest acked + 0x1, 0x14, // largest acked 0x0, 0x0, // delay time 0x2, // num ACK blocks 0x1, // 1st block @@ -405,7 +317,7 @@ var _ = Describe("AckFrame", func() { 0x1, 0x13, // 3rd block 0, }) - frame, err := ParseAckFrame(b, versionLittleEndian) + frame, err := ParseAckFrame(b, versionBigEndian) Expect(err).ToNot(HaveOccurred()) Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x114))) Expect(frame.HasMissingRanges()).To(BeTrue()) @@ -421,7 +333,7 @@ var _ = Describe("AckFrame", func() { // each gap is 300 packets and thus takes 2 ranges // the last range is incomplete, and should be completely ignored b := bytes.NewReader([]byte{0x60 ^ 0x4, - 0x9b, 0x3, // largest acked + 0x3, 0x9b, // largest acked 0x0, 0x0, // delay time 0x5, // num ACK blocks, instead of 0x6 0x1, // 1st block @@ -432,7 +344,7 @@ var _ = Describe("AckFrame", func() { 0xff, 0x0, /*0x2d, 0x14,*/ // 6th block 0, }) - frame, err := ParseAckFrame(b, versionLittleEndian) + frame, err := ParseAckFrame(b, versionBigEndian) Expect(err).ToNot(HaveOccurred()) Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x39b))) Expect(frame.HasMissingRanges()).To(BeTrue()) @@ -446,7 +358,7 @@ var _ = Describe("AckFrame", func() { It("parses a frame with one long range, spanning 2 blocks, of missing packets", func() { // 280 missing packets b := bytes.NewReader([]byte{0x60 ^ 0x4, - 0x44, 0x1, // largest acked + 0x1, 0x44, // largest acked 0x0, 0x0, // delay time 0x2, // num ACK blocks 0x19, // 1st block @@ -454,7 +366,7 @@ var _ = Describe("AckFrame", func() { 0x19, 0x13, // 3rd block 0, }) - frame, err := ParseAckFrame(b, versionLittleEndian) + frame, err := ParseAckFrame(b, versionBigEndian) Expect(err).ToNot(HaveOccurred()) Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x144))) Expect(frame.HasMissingRanges()).To(BeTrue()) @@ -468,7 +380,7 @@ var _ = Describe("AckFrame", func() { It("parses a frame with one long range, spanning multiple blocks, of missing packets", func() { // 2345 missing packets b := bytes.NewReader([]byte{0x60 ^ 0x4, - 0x5b, 0x9, // largest acked + 0x9, 0x5b, // largest acked 0x0, 0x0, // delay time 0xa, // num ACK blocks 0x1f, // 1st block @@ -484,7 +396,7 @@ var _ = Describe("AckFrame", func() { 0x32, 0x13, // 11th block 0, }) - frame, err := ParseAckFrame(b, versionLittleEndian) + frame, err := ParseAckFrame(b, versionBigEndian) Expect(err).ToNot(HaveOccurred()) Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x95b))) Expect(frame.HasMissingRanges()).To(BeTrue()) @@ -495,72 +407,6 @@ var _ = Describe("AckFrame", func() { Expect(b.Len()).To(BeZero()) }) - Context("in little endian", func() { - It("parses a frame with multiple 2 byte long ranges of missing packets", func() { - b := bytes.NewReader([]byte{0x60 ^ 0x4 ^ 0x1, - 0x66, 0x9, // largest acked - 0x0, 0x0, // delay time - 0x7, // num ACK blocks - 0x7, 0x0, // 1st block - 0xff, 0x0, 0x0, // 2nd block - 0xf5, 0x8a, 0x2, // 3rd block - 0xc8, 0xe6, 0x0, // 4th block - 0xff, 0x0, 0x0, // 5th block - 0xff, 0x0, 0x0, // 6th block - 0xff, 0x0, 0x0, // 7th block - 0x23, 0x13, 0x0, // 8th block - 0, - }) - frame, err := ParseAckFrame(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x966))) - Expect(frame.HasMissingRanges()).To(BeTrue()) - Expect(frame.AckRanges).To(HaveLen(4)) - Expect(frame.AckRanges[0]).To(Equal(AckRange{First: 2400, Last: 0x966})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: 1250, Last: 1899})) - Expect(frame.AckRanges[2]).To(Equal(AckRange{First: 820, Last: 1049})) - Expect(frame.AckRanges[3]).To(Equal(AckRange{First: 1, Last: 19})) - Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(1))) - Expect(b.Len()).To(BeZero()) - }) - - It("parses a frame with with a 4 byte ack block length", func() { - b := bytes.NewReader([]byte{0x60 ^ 0xc ^ 0x2, - 0xfe, 0xca, 0xef, 0xbe, 0xad, 0xde, // largest acked - 0x0, 0x0, // delay time - 0x1, // num ACK blocks - 0x37, 0x13, 0, 0, // 1st block - 0x20, 0x78, 0x56, 0x34, 0x12, // 2nd block - 0, - }) - frame, err := ParseAckFrame(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0xdeadbeefcafe))) - Expect(frame.HasMissingRanges()).To(BeTrue()) - Expect(frame.AckRanges).To(HaveLen(2)) - Expect(frame.AckRanges[0]).To(Equal(AckRange{First: 0xdeadbeefcafe - 0x1337 + 1, Last: 0xdeadbeefcafe})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: (0xdeadbeefcafe - 0x1337 + 1) - (0x20 + 1) - (0x12345678 - 1), Last: (0xdeadbeefcafe - 0x1337 + 1) - (0x20 + 1)})) - }) - - It("parses a frame with with a 6 byte ack block length", func() { - b := bytes.NewReader([]byte{0x60 ^ 0xc ^ 0x3, - 0xfe, 0xca, 0xef, 0xbe, 0xad, 0xde, // largest acked - 0x0, 0x0, // delay time - 0x1, // num ACk blocks - 0x37, 0x13, 0, 0, 0, 0, // 1st block - 0x20, 0x78, 0x56, 0x34, 0x12, 0xab, 0, // 2nd block - 0, - }) - frame, err := ParseAckFrame(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0xdeadbeefcafe))) - Expect(frame.HasMissingRanges()).To(BeTrue()) - Expect(frame.AckRanges).To(HaveLen(2)) - Expect(frame.AckRanges[0]).To(Equal(AckRange{First: 0xdeadbeefcafe - 0x1337 + 1, Last: 0xdeadbeefcafe})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: (0xdeadbeefcafe - 0x1337 + 1) - (0x20 + 1) - (0xab12345678 - 1), Last: (0xdeadbeefcafe - 0x1337 + 1) - (0x20 + 1)})) - }) - }) - Context("in big endian", func() { It("parses a frame with multiple 2 byte long ranges of missing packets", func() { b := bytes.NewReader([]byte{0x60 ^ 0x4 ^ 0x1, @@ -638,498 +484,488 @@ var _ = Describe("AckFrame", func() { }) Context("self-consistency", func() { - for _, v := range []protocol.VersionNumber{versionLittleEndian, versionBigEndian} { - version := v - name := "little endian" - if version == versionBigEndian { - name = "big endian" + It("writes a simple ACK frame", func() { + frameOrig := &AckFrame{ + LargestAcked: 1, + LowestAcked: 1, } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.HasMissingRanges()).To(BeFalse()) + Expect(r.Len()).To(BeZero()) + }) - Context(fmt.Sprintf("in %s", name), func() { - It("writes a simple ACK frame", func() { - frameOrig := &AckFrame{ - LargestAcked: 1, - LowestAcked: 1, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.HasMissingRanges()).To(BeFalse()) - Expect(r.Len()).To(BeZero()) - }) + It("writes the correct block length in a simple ACK frame", func() { + frameOrig := &AckFrame{ + LargestAcked: 20, + LowestAcked: 10, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(frame.HasMissingRanges()).To(BeFalse()) + Expect(r.Len()).To(BeZero()) + }) - It("writes the correct block length in a simple ACK frame", func() { - frameOrig := &AckFrame{ - LargestAcked: 20, - LowestAcked: 10, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(frame.HasMissingRanges()).To(BeFalse()) - Expect(r.Len()).To(BeZero()) - }) + It("writes a simple ACK frame with a high packet number", func() { + frameOrig := &AckFrame{ + LargestAcked: 0xdeadbeefcafe, + LowestAcked: 0xdeadbeefcafe, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.HasMissingRanges()).To(BeFalse()) + Expect(r.Len()).To(BeZero()) + }) - It("writes a simple ACK frame with a high packet number", func() { - frameOrig := &AckFrame{ - LargestAcked: 0xdeadbeefcafe, - LowestAcked: 0xdeadbeefcafe, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.HasMissingRanges()).To(BeFalse()) - Expect(r.Len()).To(BeZero()) - }) + It("writes an ACK frame with one packet missing", func() { + frameOrig := &AckFrame{ + LargestAcked: 40, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 25, Last: 40}, + {First: 1, Last: 23}, + }, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + Expect(r.Len()).To(BeZero()) + }) - It("writes an ACK frame with one packet missing", func() { - frameOrig := &AckFrame{ - LargestAcked: 40, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 25, Last: 40}, - {First: 1, Last: 23}, - }, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - Expect(r.Len()).To(BeZero()) - }) + It("writes an ACK frame with multiple missing packets", func() { + frameOrig := &AckFrame{ + LargestAcked: 25, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 22, Last: 25}, + {First: 15, Last: 18}, + {First: 13, Last: 13}, + {First: 1, Last: 10}, + }, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + Expect(r.Len()).To(BeZero()) + }) - It("writes an ACK frame with multiple missing packets", func() { - frameOrig := &AckFrame{ - LargestAcked: 25, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 22, Last: 25}, - {First: 15, Last: 18}, - {First: 13, Last: 13}, - {First: 1, Last: 10}, - }, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - Expect(r.Len()).To(BeZero()) - }) + It("rejects a frame with incorrect LargestObserved value", func() { + frame := &AckFrame{ + LargestAcked: 26, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 12, Last: 25}, + {First: 1, Last: 10}, + }, + } + err := frame.Write(b, versionBigEndian) + Expect(err).To(MatchError(errInconsistentAckLargestAcked)) + }) - It("rejects a frame with incorrect LargestObserved value", func() { - frame := &AckFrame{ - LargestAcked: 26, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 12, Last: 25}, - {First: 1, Last: 10}, - }, - } - err := frame.Write(b, version) - Expect(err).To(MatchError(errInconsistentAckLargestAcked)) - }) + It("rejects a frame with incorrect LargestObserved value", func() { + frame := &AckFrame{ + LargestAcked: 25, + LowestAcked: 2, + AckRanges: []AckRange{ + {First: 12, Last: 25}, + {First: 1, Last: 10}, + }, + } + err := frame.Write(b, versionBigEndian) + Expect(err).To(MatchError(errInconsistentAckLowestAcked)) + }) - It("rejects a frame with incorrect LargestObserved value", func() { - frame := &AckFrame{ - LargestAcked: 25, - LowestAcked: 2, - AckRanges: []AckRange{ - {First: 12, Last: 25}, - {First: 1, Last: 10}, - }, - } - err := frame.Write(b, version) - Expect(err).To(MatchError(errInconsistentAckLowestAcked)) - }) - - Context("longer gaps between ACK blocks", func() { - It("only writes one block for 254 lost packets", func() { - frameOrig := &AckFrame{ - LargestAcked: 300, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 20 + 254, Last: 300}, - {First: 1, Last: 19}, - }, - } - Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(2))) - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - }) - - It("only writes one block for 255 lost packets", func() { - frameOrig := &AckFrame{ - LargestAcked: 300, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 20 + 255, Last: 300}, - {First: 1, Last: 19}, - }, - } - Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(2))) - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - }) - - It("writes two blocks for 256 lost packets", func() { - frameOrig := &AckFrame{ - LargestAcked: 300, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 20 + 256, Last: 300}, - {First: 1, Last: 19}, - }, - } - Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(3))) - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - }) - - It("writes two blocks for 510 lost packets", func() { - frameOrig := &AckFrame{ - LargestAcked: 600, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 20 + 510, Last: 600}, - {First: 1, Last: 19}, - }, - } - Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(3))) - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - }) - - It("writes three blocks for 511 lost packets", func() { - frameOrig := &AckFrame{ - LargestAcked: 600, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 20 + 511, Last: 600}, - {First: 1, Last: 19}, - }, - } - Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(4))) - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - }) - - It("writes three blocks for 512 lost packets", func() { - frameOrig := &AckFrame{ - LargestAcked: 600, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 20 + 512, Last: 600}, - {First: 1, Last: 19}, - }, - } - Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(4))) - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - }) - - It("writes multiple blocks for a lot of lost packets", func() { - frameOrig := &AckFrame{ - LargestAcked: 3000, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 2900, Last: 3000}, - {First: 1, Last: 19}, - }, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - }) - - It("writes multiple longer blocks for 256 lost packets", func() { - frameOrig := &AckFrame{ - LargestAcked: 3600, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 2900, Last: 3600}, - {First: 1000, Last: 2500}, - {First: 1, Last: 19}, - }, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - }) - }) - - Context("largest acked length", func() { - It("writes a 1 largest acked", func() { - frameOrig := &AckFrame{ - LargestAcked: 200, - LowestAcked: 1, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x0))) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(r.Len()).To(BeZero()) - }) - - It("writes a 2 byte largest acked", func() { - frameOrig := &AckFrame{ - LargestAcked: 0x100, - LowestAcked: 1, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x1))) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(r.Len()).To(BeZero()) - }) - - It("writes a 4 byte largest acked", func() { - frameOrig := &AckFrame{ - LargestAcked: 0x10000, - LowestAcked: 1, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x2))) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(r.Len()).To(BeZero()) - }) - - It("writes a 6 byte largest acked", func() { - frameOrig := &AckFrame{ - LargestAcked: 0x100000000, - LowestAcked: 1, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x3))) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(r.Len()).To(BeZero()) - }) - }) - - Context("ack block length", func() { - It("writes a 1 byte ack block length, if all ACK blocks are short", func() { - frameOrig := &AckFrame{ - LargestAcked: 5001, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 5000, Last: 5001}, - {First: 250, Last: 300}, - {First: 1, Last: 200}, - }, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x0))) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - Expect(r.Len()).To(BeZero()) - }) - - It("writes a 2 byte ack block length, for a frame with one ACK block", func() { - frameOrig := &AckFrame{ - LargestAcked: 10000, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 9990, Last: 10000}, - {First: 1, Last: 9988}, - }, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x1))) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - Expect(r.Len()).To(BeZero()) - }) - - It("writes a 2 byte ack block length, for a frame with multiple ACK blocks", func() { - frameOrig := &AckFrame{ - LargestAcked: 10000, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 9990, Last: 10000}, - {First: 1, Last: 256}, - }, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x1))) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - Expect(r.Len()).To(BeZero()) - }) - - It("writes a 4 byte ack block length, for a frame with single ACK blocks", func() { - frameOrig := &AckFrame{ - LargestAcked: 0xdeadbeef, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 9990, Last: 0xdeadbeef}, - {First: 1, Last: 9988}, - }, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x2))) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - Expect(r.Len()).To(BeZero()) - }) - - It("writes a 4 byte ack block length, for a frame with multiple ACK blocks", func() { - frameOrig := &AckFrame{ - LargestAcked: 0xdeadbeef, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 9990, Last: 0xdeadbeef}, - {First: 1, Last: 256}, - }, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x2))) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - Expect(r.Len()).To(BeZero()) - }) - - It("writes a 6 byte ack block length, for a frame with a single ACK blocks", func() { - frameOrig := &AckFrame{ - LargestAcked: 0xdeadbeefcafe, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 9990, Last: 0xdeadbeefcafe}, - {First: 1, Last: 9988}, - }, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x3))) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - Expect(r.Len()).To(BeZero()) - }) - - It("writes a 6 byte ack block length, for a frame with multiple ACK blocks", func() { - frameOrig := &AckFrame{ - LargestAcked: 0xdeadbeefcafe, - LowestAcked: 1, - AckRanges: []AckRange{ - {First: 9990, Last: 0xdeadbeefcafe}, - {First: 1, Last: 256}, - }, - } - err := frameOrig.Write(b, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x3))) - r := bytes.NewReader(b.Bytes()) - frame, err := ParseAckFrame(r, version) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) - Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) - Expect(r.Len()).To(BeZero()) - }) - }) + Context("longer gaps between ACK blocks", func() { + It("only writes one block for 254 lost packets", func() { + frameOrig := &AckFrame{ + LargestAcked: 300, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 20 + 254, Last: 300}, + {First: 1, Last: 19}, + }, + } + Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(2))) + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) }) - } + + It("only writes one block for 255 lost packets", func() { + frameOrig := &AckFrame{ + LargestAcked: 300, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 20 + 255, Last: 300}, + {First: 1, Last: 19}, + }, + } + Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(2))) + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + }) + + It("writes two blocks for 256 lost packets", func() { + frameOrig := &AckFrame{ + LargestAcked: 300, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 20 + 256, Last: 300}, + {First: 1, Last: 19}, + }, + } + Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(3))) + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + }) + + It("writes two blocks for 510 lost packets", func() { + frameOrig := &AckFrame{ + LargestAcked: 600, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 20 + 510, Last: 600}, + {First: 1, Last: 19}, + }, + } + Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(3))) + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + }) + + It("writes three blocks for 511 lost packets", func() { + frameOrig := &AckFrame{ + LargestAcked: 600, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 20 + 511, Last: 600}, + {First: 1, Last: 19}, + }, + } + Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(4))) + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + }) + + It("writes three blocks for 512 lost packets", func() { + frameOrig := &AckFrame{ + LargestAcked: 600, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 20 + 512, Last: 600}, + {First: 1, Last: 19}, + }, + } + Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(4))) + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + }) + + It("writes multiple blocks for a lot of lost packets", func() { + frameOrig := &AckFrame{ + LargestAcked: 3000, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 2900, Last: 3000}, + {First: 1, Last: 19}, + }, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + }) + + It("writes multiple longer blocks for 256 lost packets", func() { + frameOrig := &AckFrame{ + LargestAcked: 3600, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 2900, Last: 3600}, + {First: 1000, Last: 2500}, + {First: 1, Last: 19}, + }, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + }) + }) + + Context("largest acked length", func() { + It("writes a 1 largest acked", func() { + frameOrig := &AckFrame{ + LargestAcked: 200, + LowestAcked: 1, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x0))) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(r.Len()).To(BeZero()) + }) + + It("writes a 2 byte largest acked", func() { + frameOrig := &AckFrame{ + LargestAcked: 0x100, + LowestAcked: 1, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x1))) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(r.Len()).To(BeZero()) + }) + + It("writes a 4 byte largest acked", func() { + frameOrig := &AckFrame{ + LargestAcked: 0x10000, + LowestAcked: 1, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x2))) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(r.Len()).To(BeZero()) + }) + + It("writes a 6 byte largest acked", func() { + frameOrig := &AckFrame{ + LargestAcked: 0x100000000, + LowestAcked: 1, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x3))) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(r.Len()).To(BeZero()) + }) + }) + + Context("ack block length", func() { + It("writes a 1 byte ack block length, if all ACK blocks are short", func() { + frameOrig := &AckFrame{ + LargestAcked: 5001, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 5000, Last: 5001}, + {First: 250, Last: 300}, + {First: 1, Last: 200}, + }, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x0))) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + Expect(r.Len()).To(BeZero()) + }) + + It("writes a 2 byte ack block length, for a frame with one ACK block", func() { + frameOrig := &AckFrame{ + LargestAcked: 10000, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 9990, Last: 10000}, + {First: 1, Last: 9988}, + }, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x1))) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + Expect(r.Len()).To(BeZero()) + }) + + It("writes a 2 byte ack block length, for a frame with multiple ACK blocks", func() { + frameOrig := &AckFrame{ + LargestAcked: 10000, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 9990, Last: 10000}, + {First: 1, Last: 256}, + }, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x1))) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + Expect(r.Len()).To(BeZero()) + }) + + It("writes a 4 byte ack block length, for a frame with single ACK blocks", func() { + frameOrig := &AckFrame{ + LargestAcked: 0xdeadbeef, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 9990, Last: 0xdeadbeef}, + {First: 1, Last: 9988}, + }, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x2))) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + Expect(r.Len()).To(BeZero()) + }) + + It("writes a 4 byte ack block length, for a frame with multiple ACK blocks", func() { + frameOrig := &AckFrame{ + LargestAcked: 0xdeadbeef, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 9990, Last: 0xdeadbeef}, + {First: 1, Last: 256}, + }, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x2))) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + Expect(r.Len()).To(BeZero()) + }) + + It("writes a 6 byte ack block length, for a frame with a single ACK blocks", func() { + frameOrig := &AckFrame{ + LargestAcked: 0xdeadbeefcafe, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 9990, Last: 0xdeadbeefcafe}, + {First: 1, Last: 9988}, + }, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x3))) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + Expect(r.Len()).To(BeZero()) + }) + + It("writes a 6 byte ack block length, for a frame with multiple ACK blocks", func() { + frameOrig := &AckFrame{ + LargestAcked: 0xdeadbeefcafe, + LowestAcked: 1, + AckRanges: []AckRange{ + {First: 9990, Last: 0xdeadbeefcafe}, + {First: 1, Last: 256}, + }, + } + err := frameOrig.Write(b, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(b.Bytes()[0] & 0x3).To(Equal(byte(0x3))) + r := bytes.NewReader(b.Bytes()) + frame, err := ParseAckFrame(r, versionBigEndian) + Expect(err).ToNot(HaveOccurred()) + Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) + Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked)) + Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges)) + Expect(r.Len()).To(BeZero()) + }) + }) Context("too many ACK blocks", func() { It("skips the lowest ACK ranges, if there are more than 255 AckRanges", func() { diff --git a/internal/wire/blocked_frame_legacy_test.go b/internal/wire/blocked_frame_legacy_test.go index 1bddd14b..6d959480 100644 --- a/internal/wire/blocked_frame_legacy_test.go +++ b/internal/wire/blocked_frame_legacy_test.go @@ -10,17 +10,6 @@ import ( var _ = Describe("legacy BLOCKED Frame", func() { Context("when parsing", func() { - Context("in little endian", func() { - It("accepts sample frame", func() { - b := bytes.NewReader([]byte{0x5, 0xef, 0xbe, 0xad, 0xde}) - f, err := ParseBlockedFrameLegacy(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(f).To(BeAssignableToTypeOf(&StreamBlockedFrame{})) - frame := f.(*StreamBlockedFrame) - Expect(frame.StreamID).To(Equal(protocol.StreamID(0xdeadbeef))) - }) - }) - Context("in big endian", func() { It("accepts sample frame for a stream", func() { b := bytes.NewReader([]byte{0x5, 0xde, 0xad, 0xbe, 0xef}) @@ -51,15 +40,6 @@ var _ = Describe("legacy BLOCKED Frame", func() { }) Context("when writing", func() { - Context("in little endian", func() { - It("writes a sample frame", func() { - b := &bytes.Buffer{} - frame := StreamBlockedFrame{StreamID: 0x1337} - frame.Write(b, versionLittleEndian) - Expect(b.Bytes()).To(Equal([]byte{0x5, 0x37, 0x13, 0x0, 0x0})) - }) - }) - Context("in big endian", func() { It("writes a BLOCKED frame for a stream", func() { b := &bytes.Buffer{} diff --git a/internal/wire/connection_close_frame_test.go b/internal/wire/connection_close_frame_test.go index 012ca02d..150d4c45 100644 --- a/internal/wire/connection_close_frame_test.go +++ b/internal/wire/connection_close_frame_test.go @@ -13,44 +13,6 @@ import ( var _ = Describe("ConnectionCloseFrame", func() { Context("when parsing", func() { - Context("in little endian", func() { - It("accepts sample frame", func() { - b := bytes.NewReader([]byte{0x2, - 0x19, 0x0, 0x0, 0x0, // error code - 0x1b, 0x0, // reason phrase length - 'N', 'o', ' ', 'r', 'e', 'c', 'e', 'n', 't', ' ', 'n', 'e', 't', 'w', 'o', 'r', 'k', ' ', 'a', 'c', 't', 'i', 'v', 'i', 't', 'y', '.', - }) - frame, err := ParseConnectionCloseFrame(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.ErrorCode).To(Equal(qerr.ErrorCode(0x19))) - Expect(frame.ReasonPhrase).To(Equal("No recent network activity.")) - Expect(b.Len()).To(BeZero()) - }) - - It("rejects long reason phrases", func() { - b := bytes.NewReader([]byte{0x2, - 0xad, 0xfb, 0xca, 0xde, // error code - 0x0, 0xff, // reason phrase length - }) - _, err := ParseConnectionCloseFrame(b, versionLittleEndian) - Expect(err).To(MatchError(io.EOF)) - }) - - It("errors on EOFs", func() { - data := []byte{0x2, - 0x19, 0x0, 0x0, 0x0, // error code - 0x1b, 0x0, // reason phrase length - 'N', 'o', ' ', 'r', 'e', 'c', 'e', 'n', 't', ' ', 'n', 'e', 't', 'w', 'o', 'r', 'k', ' ', 'a', 'c', 't', 'i', 'v', 'i', 't', 'y', '.', - } - _, err := ParseConnectionCloseFrame(bytes.NewReader(data), versionLittleEndian) - Expect(err).NotTo(HaveOccurred()) - for i := range data { - _, err := ParseConnectionCloseFrame(bytes.NewReader(data[0:i]), versionLittleEndian) - Expect(err).To(HaveOccurred()) - } - }) - }) - Context("in big endian", func() { It("accepts sample frame", func() { b := bytes.NewReader([]byte{0x2, @@ -102,38 +64,6 @@ var _ = Describe("ConnectionCloseFrame", func() { }) Context("when writing", func() { - Context("in little endian", func() { - It("writes a frame without a reason phrase", func() { - b := &bytes.Buffer{} - frame := &ConnectionCloseFrame{ - ErrorCode: 0xdeadbeef, - } - err := frame.Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Len()).To(Equal(1 + 2 + 4)) - Expect(b.Bytes()).To(Equal([]byte{0x2, - 0xef, 0xbe, 0xad, 0xde, // error code - 0x0, 0x0, // reason phrase length - })) - }) - - It("writes a frame with a reason phrase", func() { - b := &bytes.Buffer{} - frame := &ConnectionCloseFrame{ - ErrorCode: 0xdeadbeef, - ReasonPhrase: "foobar", - } - err := frame.Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Len()).To(Equal(1 + 2 + 4 + len(frame.ReasonPhrase))) - Expect(b.Bytes()).To(Equal([]byte{0x2, - 0xef, 0xbe, 0xad, 0xde, // error code - 0x6, 0x0, // reason phrase length - 'f', 'o', 'o', 'b', 'a', 'r', - })) - }) - }) - Context("in big endian", func() { It("writes a frame without a ReasonPhrase", func() { b := &bytes.Buffer{} diff --git a/internal/wire/goaway_frame_test.go b/internal/wire/goaway_frame_test.go index f9b02db1..d9f33d7f 100644 --- a/internal/wire/goaway_frame_test.go +++ b/internal/wire/goaway_frame_test.go @@ -12,40 +12,6 @@ import ( var _ = Describe("GoawayFrame", func() { Context("when parsing", func() { - Context("in little endian", func() { - It("accepts sample frame", func() { - b := bytes.NewReader([]byte{0x3, - 0x37, 0x13, 0x0, 0x0, // error code - 0x34, 0x12, 0x0, 0x0, // last good stream id - 0x3, 0x0, // reason phrase length - 'f', 'o', 'o', - }) - frame, err := ParseGoawayFrame(b, versionLittleEndian) - Expect(frame).To(Equal(&GoawayFrame{ - ErrorCode: 0x1337, - LastGoodStream: 0x1234, - ReasonPhrase: "foo", - })) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Len()).To(BeZero()) - }) - - It("errors on EOFs", func() { - data := []byte{0x3, - 0x1, 0x0, 0x0, 0x0, // error code - 0x2, 0x0, 0x0, 0x0, // last good stream id - 0x3, 0x0, // reason phrase length - 'f', 'o', 'o', - } - _, err := ParseGoawayFrame(bytes.NewReader(data), versionLittleEndian) - Expect(err).NotTo(HaveOccurred()) - for i := range data { - _, err := ParseGoawayFrame(bytes.NewReader(data[0:i]), versionLittleEndian) - Expect(err).To(HaveOccurred()) - } - }) - }) - Context("in big endian", func() { It("accepts sample frame", func() { b := bytes.NewReader([]byte{0x3, @@ -92,25 +58,6 @@ var _ = Describe("GoawayFrame", func() { }) Context("when writing", func() { - Context("in little endian", func() { - It("writes a sample frame", func() { - b := &bytes.Buffer{} - frame := GoawayFrame{ - ErrorCode: 0x1337, - LastGoodStream: 2, - ReasonPhrase: "foo", - } - err := frame.Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()).To(Equal([]byte{0x3, - 0x37, 0x13, 0x0, 0x0, // error code - 0x2, 0x0, 0x0, 0x0, // last good stream - 0x3, 0x0, // reason phrase length - 'f', 'o', 'o', - })) - }) - }) - Context("in big endian", func() { It("writes a sample frame", func() { b := &bytes.Buffer{} diff --git a/internal/wire/public_header_test.go b/internal/wire/public_header_test.go index e8064183..d62f5caf 100644 --- a/internal/wire/public_header_test.go +++ b/internal/wire/public_header_test.go @@ -140,50 +140,6 @@ var _ = Describe("Public Header", func() { }) Context("Packet Number lengths", func() { - Context("in little endian encoding", func() { - version := protocol.Version37 - - BeforeEach(func() { - Expect(utils.GetByteOrder(version)).To(Equal(utils.LittleEndian)) - }) - - It("accepts 1-byte packet numbers", func() { - b := bytes.NewReader([]byte{0x08, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0xde}) - hdr, err := parsePublicHeader(b, protocol.PerspectiveClient, version) - Expect(err).ToNot(HaveOccurred()) - Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(0xde))) - Expect(hdr.PacketNumberLen).To(Equal(protocol.PacketNumberLen1)) - Expect(b.Len()).To(BeZero()) - }) - - It("accepts 2-byte packet numbers", func() { - b := bytes.NewReader([]byte{0x18, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0xde, 0xca}) - hdr, err := parsePublicHeader(b, protocol.PerspectiveClient, version) - Expect(err).ToNot(HaveOccurred()) - Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(0xcade))) - Expect(hdr.PacketNumberLen).To(Equal(protocol.PacketNumberLen2)) - Expect(b.Len()).To(BeZero()) - }) - - It("accepts 4-byte packet numbers", func() { - b := bytes.NewReader([]byte{0x28, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0xad, 0xfb, 0xca, 0xde}) - hdr, err := parsePublicHeader(b, protocol.PerspectiveClient, version) - Expect(err).ToNot(HaveOccurred()) - Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(0xdecafbad))) - Expect(hdr.PacketNumberLen).To(Equal(protocol.PacketNumberLen4)) - Expect(b.Len()).To(BeZero()) - }) - - It("accepts 6-byte packet numbers", func() { - b := bytes.NewReader([]byte{0x38, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0x23, 0x42, 0xad, 0xfb, 0xca, 0xde}) - hdr, err := parsePublicHeader(b, protocol.PerspectiveClient, version) - Expect(err).ToNot(HaveOccurred()) - Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(0xdecafbad4223))) - Expect(hdr.PacketNumberLen).To(Equal(protocol.PacketNumberLen6)) - Expect(b.Len()).To(BeZero()) - }) - }) - Context("in big endian encoding", func() { version := protocol.Version39 @@ -238,9 +194,9 @@ var _ = Describe("Public Header", func() { PacketNumber: 2, PacketNumberLen: protocol.PacketNumberLen6, } - err := hdr.writePublicHeader(b, protocol.PerspectiveServer, versionLittleEndian) + err := hdr.writePublicHeader(b, protocol.PerspectiveServer, versionBigEndian) Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()).To(Equal([]byte{0x38, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 2, 0, 0, 0, 0, 0})) + Expect(b.Bytes()).To(Equal([]byte{0x38, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0, 0, 0, 0, 0, 2})) }) It("writes a sample header as a client", func() { @@ -250,9 +206,9 @@ var _ = Describe("Public Header", func() { PacketNumber: 0x1337, PacketNumberLen: protocol.PacketNumberLen6, } - err := hdr.writePublicHeader(b, protocol.PerspectiveClient, versionLittleEndian) + err := hdr.writePublicHeader(b, protocol.PerspectiveClient, versionBigEndian) Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()).To(Equal([]byte{0x38, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0x37, 0x13, 0, 0, 0, 0})) + Expect(b.Bytes()).To(Equal([]byte{0x38, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0x0, 0x0, 0x0, 0x0, 0x13, 0x37})) }) It("refuses to write a Public Header if the PacketNumberLen is not set", func() { @@ -286,7 +242,7 @@ var _ = Describe("Public Header", func() { PacketNumberLen: protocol.PacketNumberLen1, DiversificationNonce: bytes.Repeat([]byte{1}, 32), } - err := hdr.writePublicHeader(b, protocol.PerspectiveServer, versionLittleEndian) + err := hdr.writePublicHeader(b, protocol.PerspectiveServer, versionBigEndian) Expect(err).ToNot(HaveOccurred()) Expect(b.Bytes()).To(Equal([]byte{ 0x0c, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, @@ -327,7 +283,7 @@ var _ = Describe("Public Header", func() { b := &bytes.Buffer{} hdr := Header{ VersionFlag: true, - Version: protocol.Version38, + Version: protocol.Version39, ConnectionID: 0x4cfa9f9b668619f6, PacketNumber: 0x42, PacketNumberLen: protocol.PacketNumberLen1, @@ -339,7 +295,7 @@ var _ = Describe("Public Header", func() { firstByte, _ := b.ReadByte() Expect(firstByte & 0x01).To(Equal(uint8(1))) Expect(firstByte & 0x30).To(Equal(uint8(0x0))) - Expect(string(b.Bytes()[8:12])).To(Equal("Q038")) + Expect(string(b.Bytes()[8:12])).To(Equal("Q039")) Expect(b.Bytes()[12:13]).To(Equal([]byte{0x42})) }) }) @@ -393,7 +349,7 @@ var _ = Describe("Public Header", func() { It("errors when PacketNumberLen is not set", func() { hdr := Header{ ConnectionID: 0x4cfa9f9b668619f6, - PacketNumber: 0xDECAFBAD, + PacketNumber: 0xdecafbad, } _, err := hdr.getPublicHeaderLength(protocol.PerspectiveServer) Expect(err).To(MatchError(errPacketNumberLenNotSet)) @@ -402,7 +358,7 @@ var _ = Describe("Public Header", func() { It("gets the length of a packet with longest packet number length and connectionID", func() { hdr := Header{ ConnectionID: 0x4cfa9f9b668619f6, - PacketNumber: 0xDECAFBAD, + PacketNumber: 0xdecafbad, PacketNumberLen: protocol.PacketNumberLen6, } length, err := hdr.getPublicHeaderLength(protocol.PerspectiveServer) @@ -414,10 +370,10 @@ var _ = Describe("Public Header", func() { hdr := Header{ ConnectionID: 0x4cfa9f9b668619f6, OmitConnectionID: true, - PacketNumber: 0xDECAFBAD, + PacketNumber: 0xdecafbad, PacketNumberLen: protocol.PacketNumberLen6, VersionFlag: true, - Version: versionLittleEndian, + Version: versionBigEndian, } length, err := hdr.getPublicHeaderLength(protocol.PerspectiveClient) Expect(err).ToNot(HaveOccurred()) @@ -479,62 +435,6 @@ var _ = Describe("Public Header", func() { Expect(err).To(MatchError("PublicHeader: PacketNumberLen not set")) }) - Context("in little endian", func() { - version := protocol.Version37 - - BeforeEach(func() { - Expect(utils.GetByteOrder(version)).To(Equal(utils.LittleEndian)) - }) - - It("writes a header with a 1-byte packet number", func() { - b := &bytes.Buffer{} - hdr := Header{ - ConnectionID: 0x4cfa9f9b668619f6, - PacketNumber: 0xDECAFBAD, - PacketNumberLen: protocol.PacketNumberLen1, - } - err := hdr.writePublicHeader(b, protocol.PerspectiveServer, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()).To(Equal([]byte{0x08, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0xAD})) - }) - - It("writes a header with a 2-byte packet number", func() { - b := &bytes.Buffer{} - hdr := Header{ - ConnectionID: 0x4cfa9f9b668619f6, - PacketNumber: 0xDECAFBAD, - PacketNumberLen: protocol.PacketNumberLen2, - } - err := hdr.writePublicHeader(b, protocol.PerspectiveServer, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()).To(Equal([]byte{0x18, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0xad, 0xfb})) - }) - - It("writes a header with a 4-byte packet number", func() { - b := &bytes.Buffer{} - hdr := Header{ - ConnectionID: 0x4cfa9f9b668619f6, - PacketNumber: 0x13DECAFBAD, - PacketNumberLen: protocol.PacketNumberLen4, - } - err := hdr.writePublicHeader(b, protocol.PerspectiveServer, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()).To(Equal([]byte{0x28, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0xAD, 0xfb, 0xca, 0xde})) - }) - - It("writes a header with a 6-byte packet number", func() { - b := &bytes.Buffer{} - hdr := Header{ - ConnectionID: 0x4cfa9f9b668619f6, - PacketNumber: 0xBE1337DECAFBAD, - PacketNumberLen: protocol.PacketNumberLen6, - } - err := hdr.writePublicHeader(b, protocol.PerspectiveServer, version) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()).To(Equal([]byte{0x38, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0xad, 0xfb, 0xca, 0xde, 0x37, 0x13})) - }) - }) - Context("in big endian", func() { version := protocol.Version39 diff --git a/internal/wire/rst_stream_frame_test.go b/internal/wire/rst_stream_frame_test.go index 53c6e157..5a615705 100644 --- a/internal/wire/rst_stream_frame_test.go +++ b/internal/wire/rst_stream_frame_test.go @@ -10,21 +10,6 @@ import ( var _ = Describe("RstStreamFrame", func() { Context("when parsing", func() { - Context("in little endian", func() { - It("accepts sample frame", func() { - b := bytes.NewReader([]byte{0x1, - 0xef, 0xbe, 0xad, 0xde, // stream id - 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, // byte offset - 0x34, 0x12, 0x37, 0x13, // error code - }) - frame, err := ParseRstStreamFrame(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.StreamID).To(Equal(protocol.StreamID(0xdeadbeef))) - Expect(frame.ByteOffset).To(Equal(protocol.ByteCount(0x1122334455667788))) - Expect(frame.ErrorCode).To(Equal(uint32(0x13371234))) - }) - }) - Context("in big endian", func() { It("accepts sample frame", func() { b := bytes.NewReader([]byte{0x1, @@ -56,24 +41,6 @@ var _ = Describe("RstStreamFrame", func() { }) Context("when writing", func() { - Context("in little endian", func() { - It("writes a sample RstStreamFrame", func() { - frame := RstStreamFrame{ - StreamID: 0x1337, - ByteOffset: 0x11223344decafbad, - ErrorCode: 0xdeadbeef, - } - b := &bytes.Buffer{} - err := frame.Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()).To(Equal([]byte{0x01, - 0x37, 0x13, 0x0, 0x0, // stream id - 0xad, 0xfb, 0xca, 0xde, 0x44, 0x33, 0x22, 0x11, // byte offset - 0xef, 0xbe, 0xad, 0xde, // error code - })) - }) - }) - Context("in big endian", func() { It("writes a sample RstStreamFrame", func() { frame := RstStreamFrame{ diff --git a/internal/wire/stop_waiting_frame_test.go b/internal/wire/stop_waiting_frame_test.go index 02e7dd3f..58613f3f 100644 --- a/internal/wire/stop_waiting_frame_test.go +++ b/internal/wire/stop_waiting_frame_test.go @@ -10,16 +10,6 @@ import ( var _ = Describe("StopWaitingFrame", func() { Context("when parsing", func() { - Context("in little endian", func() { - It("accepts sample frame", func() { - b := bytes.NewReader([]byte{0x06, 0x34, 0x12}) - frame, err := ParseStopWaitingFrame(b, 0x1337, 2, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.LeastUnacked).To(Equal(protocol.PacketNumber(0x1337 - 0x1234))) - Expect(b.Len()).To(BeZero()) - }) - }) - Context("in big endian", func() { It("accepts sample frame", func() { b := bytes.NewReader([]byte{0x06, 0x12, 0x34}) @@ -56,21 +46,6 @@ var _ = Describe("StopWaitingFrame", func() { }) Context("when writing", func() { - Context("in little endian", func() { - It("writes a sample frame", func() { - b := &bytes.Buffer{} - frame := &StopWaitingFrame{ - LeastUnacked: 10, - PacketNumber: 13, - PacketNumberLen: protocol.PacketNumberLen6, - } - err := frame.Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0]).To(Equal(uint8(0x06))) - Expect(b.Bytes()[1:7]).To(Equal([]byte{3, 0, 0, 0, 0, 0})) - }) - }) - Context("in big endian", func() { It("writes a sample frame", func() { b := &bytes.Buffer{} @@ -118,60 +93,6 @@ var _ = Describe("StopWaitingFrame", func() { }) Context("LeastUnackedDelta length", func() { - Context("in little endian", func() { - It("writes a 1-byte LeastUnackedDelta", func() { - b := &bytes.Buffer{} - frame := &StopWaitingFrame{ - LeastUnacked: 10, - PacketNumber: 13, - PacketNumberLen: protocol.PacketNumberLen1, - } - err := frame.Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Len()).To(Equal(2)) - Expect(b.Bytes()[1]).To(Equal(uint8(3))) - }) - - It("writes a 2-byte LeastUnackedDelta", func() { - b := &bytes.Buffer{} - frame := &StopWaitingFrame{ - LeastUnacked: 0x10, - PacketNumber: 0x1300, - PacketNumberLen: protocol.PacketNumberLen2, - } - err := frame.Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Len()).To(Equal(3)) - Expect(b.Bytes()[1:3]).To(Equal([]byte{0xf0, 0x12})) - }) - - It("writes a 4-byte LeastUnackedDelta", func() { - b := &bytes.Buffer{} - frame := &StopWaitingFrame{ - LeastUnacked: 0x1000, - PacketNumber: 0x12345678, - PacketNumberLen: protocol.PacketNumberLen4, - } - err := frame.Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Len()).To(Equal(5)) - Expect(b.Bytes()[1:5]).To(Equal([]byte{0x78, 0x46, 0x34, 0x12})) - }) - - It("writes a 6-byte LeastUnackedDelta, for a delta that fits into 6 bytes", func() { - b := &bytes.Buffer{} - frame := &StopWaitingFrame{ - LeastUnacked: 0x10, - PacketNumber: 0x123456789abc, - PacketNumberLen: protocol.PacketNumberLen6, - } - err := frame.Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Len()).To(Equal(7)) - Expect(b.Bytes()[1:7]).To(Equal([]byte{0xbc - 0x10, 0x9a, 0x78, 0x56, 0x34, 0x12})) - }) - }) - Context("in big endian", func() { It("writes a 1-byte LeastUnackedDelta", func() { b := &bytes.Buffer{} diff --git a/internal/wire/stream_frame_test.go b/internal/wire/stream_frame_test.go index d01d15d9..1a455d6d 100644 --- a/internal/wire/stream_frame_test.go +++ b/internal/wire/stream_frame_test.go @@ -12,58 +12,6 @@ import ( var _ = Describe("StreamFrame", func() { Context("when parsing", func() { - Context("in little endian", func() { - It("accepts a sample frame", func() { - // a STREAM frame, plus 3 additional bytes, not belonging to this frame - b := bytes.NewReader([]byte{0x80 ^ 0x20, - 0x1, // stream id - 0x6, 0x0, // data length - 'f', 'o', 'o', 'b', 'a', 'r', - 'f', 'o', 'o', // additional bytes - }) - frame, err := ParseStreamFrame(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.FinBit).To(BeFalse()) - Expect(frame.StreamID).To(Equal(protocol.StreamID(1))) - Expect(frame.Offset).To(BeZero()) - Expect(frame.DataLenPresent).To(BeTrue()) - Expect(frame.Data).To(Equal([]byte("foobar"))) - Expect(b.Len()).To(Equal(3)) - }) - - It("accepts frames with offsets", func() { - b := bytes.NewReader([]byte{0x80 ^ 0x20 /* 2 byte offset */ ^ 0x4, - 0x1, // stream id - 0x42, 0x0, // offset - 0x6, 0x0, // data length - 'f', 'o', 'o', 'b', 'a', 'r', - }) - frame, err := ParseStreamFrame(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(frame.FinBit).To(BeFalse()) - Expect(frame.StreamID).To(Equal(protocol.StreamID(1))) - Expect(frame.Offset).To(Equal(protocol.ByteCount(0x42))) - Expect(frame.DataLenPresent).To(BeTrue()) - Expect(frame.Data).To(Equal([]byte("foobar"))) - Expect(b.Len()).To(BeZero()) - }) - - It("errors on EOFs", func() { - data := []byte{0x80 ^ 0x20 ^ 0x4, - 0x1, // stream id - 0x2a, 0x0, // offset - 0x6, 0x0, // data length, - 'f', 'o', 'o', 'b', 'a', 'r', - } - _, err := ParseStreamFrame(bytes.NewReader(data), versionLittleEndian) - Expect(err).NotTo(HaveOccurred()) - for i := range data { - _, err := ParseStreamFrame(bytes.NewReader(data[0:i]), versionLittleEndian) - Expect(err).To(HaveOccurred()) - } - }) - }) - Context("in big endian", func() { It("accepts a sample frame", func() { // a STREAM frame, plus 3 additional bytes, not belonging to this frame @@ -190,23 +138,6 @@ var _ = Describe("StreamFrame", func() { }) Context("when writing", func() { - Context("in little endian", func() { - It("writes sample frame", func() { - b := &bytes.Buffer{} - err := (&StreamFrame{ - StreamID: 1, - Data: []byte("foobar"), - DataLenPresent: true, - }).Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()).To(Equal([]byte{0x80 ^ 0x20, - 0x1, // stream id - 0x6, 0x0, // data length - 'f', 'o', 'o', 'b', 'a', 'r', - })) - }) - }) - Context("in big endian", func() { It("writes sample frame", func() { b := &bytes.Buffer{} @@ -214,11 +145,11 @@ var _ = Describe("StreamFrame", func() { StreamID: 1, Data: []byte("foobar"), DataLenPresent: true, - }).Write(b, versionLittleEndian) + }).Write(b, versionBigEndian) Expect(err).ToNot(HaveOccurred()) Expect(b.Bytes()).To(Equal([]byte{0x80 ^ 0x20, 0x1, // stream id - 0x6, 0x0, // data length + 0x0, 0x6, // data length 'f', 'o', 'o', 'b', 'a', 'r', })) }) @@ -270,24 +201,6 @@ var _ = Describe("StreamFrame", func() { }) Context("data length field", func() { - Context("in little endian", func() { - It("writes the data length", func() { - dataLen := 0x1337 - b := &bytes.Buffer{} - f := &StreamFrame{ - StreamID: 1, - Data: bytes.Repeat([]byte{'f'}, dataLen), - DataLenPresent: true, - Offset: 0, - } - err := f.Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - minLength, _ := f.MinLength(0) - Expect(b.Bytes()[0] & 0x20).To(Equal(uint8(0x20))) - Expect(b.Bytes()[minLength-2 : minLength]).To(Equal([]byte{0x37, 0x13})) - }) - }) - Context("in big endian", func() { It("writes the data length", func() { dataLen := 0x1337 @@ -339,102 +252,6 @@ var _ = Describe("StreamFrame", func() { }) Context("offset lengths", func() { - Context("in little endian", func() { - It("does not write an offset if the offset is 0", func() { - b := &bytes.Buffer{} - err := (&StreamFrame{ - StreamID: 1, - Data: []byte("foobar"), - Offset: 0, - }).Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x0))) - }) - - It("writes a 2-byte offset if the offset is larger than 0", func() { - b := &bytes.Buffer{} - err := (&StreamFrame{ - StreamID: 1, - Data: []byte("foobar"), - Offset: 0x1337, - }).Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x1 << 2))) - Expect(b.Bytes()[2:4]).To(Equal([]byte{0x37, 0x13})) - }) - - It("writes a 3-byte offset if the offset", func() { - b := &bytes.Buffer{} - (&StreamFrame{ - StreamID: 1, - Data: []byte("foobar"), - Offset: 0x13cafe, - }).Write(b, versionLittleEndian) - Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x2 << 2))) - Expect(b.Bytes()[2:5]).To(Equal([]byte{0xfe, 0xca, 0x13})) - }) - - It("writes a 4-byte offset if the offset", func() { - b := &bytes.Buffer{} - err := (&StreamFrame{ - StreamID: 1, - Data: []byte("foobar"), - Offset: 0xdeadbeef, - }).Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x3 << 2))) - Expect(b.Bytes()[2:6]).To(Equal([]byte{0xef, 0xbe, 0xad, 0xde})) - }) - - It("writes a 5-byte offset if the offset", func() { - b := &bytes.Buffer{} - err := (&StreamFrame{ - StreamID: 1, - Data: []byte("foobar"), - Offset: 0x13deadbeef, - }).Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x4 << 2))) - Expect(b.Bytes()[2:7]).To(Equal([]byte{0xef, 0xbe, 0xad, 0xde, 0x13})) - }) - - It("writes a 6-byte offset if the offset", func() { - b := &bytes.Buffer{} - err := (&StreamFrame{ - StreamID: 1, - Data: []byte("foobar"), - Offset: 0xdeadbeefcafe, - }).Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x5 << 2))) - Expect(b.Bytes()[2:8]).To(Equal([]byte{0xfe, 0xca, 0xef, 0xbe, 0xad, 0xde})) - }) - - It("writes a 7-byte offset if the offset", func() { - b := &bytes.Buffer{} - err := (&StreamFrame{ - StreamID: 1, - Data: []byte("foobar"), - Offset: 0x13deadbeefcafe, - }).Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x6 << 2))) - Expect(b.Bytes()[2:9]).To(Equal([]byte{0xfe, 0xca, 0xef, 0xbe, 0xad, 0xde, 0x13})) - }) - - It("writes a 8-byte offset if the offset", func() { - b := &bytes.Buffer{} - err := (&StreamFrame{ - StreamID: 1, - Data: []byte("foobar"), - Offset: 0x1337deadbeefcafe, - }).Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x7 << 2))) - Expect(b.Bytes()[2:10]).To(Equal([]byte{0xfe, 0xca, 0xef, 0xbe, 0xad, 0xde, 0x37, 0x13})) - }) - }) - Context("in big endian", func() { It("does not write an offset if the offset is 0", func() { b := &bytes.Buffer{} @@ -533,65 +350,6 @@ var _ = Describe("StreamFrame", func() { }) Context("lengths of StreamIDs", func() { - Context("in little endian", func() { - It("writes a 1 byte StreamID", func() { - b := &bytes.Buffer{} - err := (&StreamFrame{ - StreamID: 13, - Data: []byte("foobar"), - }).Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(uint8(0x0))) - Expect(b.Bytes()[1]).To(Equal(uint8(13))) - }) - - It("writes a 2 byte StreamID", func() { - b := &bytes.Buffer{} - err := (&StreamFrame{ - StreamID: 0xcafe, - Data: []byte("foobar"), - }).Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(uint8(0x1))) - Expect(b.Bytes()[1:3]).To(Equal([]byte{0xfe, 0xca})) - }) - - It("writes a 3 byte StreamID", func() { - b := &bytes.Buffer{} - err := (&StreamFrame{ - StreamID: 0x13beef, - Data: []byte("foobar"), - }).Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(uint8(0x2))) - Expect(b.Bytes()[1:4]).To(Equal([]byte{0xef, 0xbe, 0x13})) - }) - - It("writes a 4 byte StreamID", func() { - b := &bytes.Buffer{} - err := (&StreamFrame{ - StreamID: 0xdecafbad, - Data: []byte("foobar"), - }).Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(uint8(0x3))) - Expect(b.Bytes()[1:5]).To(Equal([]byte{0xad, 0xfb, 0xca, 0xde})) - }) - - It("writes a multiple byte StreamID, after the Stream length was already determined by MinLenght()", func() { - b := &bytes.Buffer{} - frame := &StreamFrame{ - StreamID: 0xdecafbad, - Data: []byte("foobar"), - } - frame.MinLength(0) - err := frame.Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()[0] & 0x3).To(Equal(uint8(0x3))) - Expect(b.Bytes()[1:5]).To(Equal([]byte{0xad, 0xfb, 0xca, 0xde})) - }) - }) - Context("in big endian", func() { It("writes a 1 byte StreamID", func() { b := &bytes.Buffer{} diff --git a/internal/wire/window_update_frame_test.go b/internal/wire/window_update_frame_test.go index 5086cd77..c5ec6812 100644 --- a/internal/wire/window_update_frame_test.go +++ b/internal/wire/window_update_frame_test.go @@ -10,22 +10,6 @@ import ( var _ = Describe("WINDOW_UPDATE frame", func() { Context("parsing", func() { - Context("in little endian", func() { - It("accepts sample frame", func() { - b := bytes.NewReader([]byte{0x4, - 0xef, 0xbe, 0xad, 0xde, // stream id - 0x44, 0x33, 0x22, 0x11, 0xad, 0xfb, 0xca, 0xde, // byte offset - }) - f, err := ParseWindowUpdateFrame(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(f).To(BeAssignableToTypeOf(&MaxStreamDataFrame{})) - frame := f.(*MaxStreamDataFrame) - Expect(frame.StreamID).To(Equal(protocol.StreamID(0xdeadbeef))) - Expect(frame.ByteOffset).To(Equal(protocol.ByteCount(0xdecafbad11223344))) - Expect(b.Len()).To(BeZero()) - }) - }) - Context("in big endian", func() { It("parses a stream-level WINDOW_UPDATE", func() { b := bytes.NewReader([]byte{0x4, @@ -82,22 +66,6 @@ var _ = Describe("WINDOW_UPDATE frame", func() { Expect(f.MinLength(versionBigEndian)).To(Equal(protocol.ByteCount(1 + 4 + 8))) }) - Context("in little endian", func() { - It("writes a sample frame", func() { - b := &bytes.Buffer{} - f := &windowUpdateFrame{ - StreamID: 0xdecafbad, - ByteOffset: 0xdeadbeefcafe1337, - } - err := f.Write(b, versionLittleEndian) - Expect(err).ToNot(HaveOccurred()) - Expect(b.Bytes()).To(Equal([]byte{0x4, - 0xad, 0xfb, 0xca, 0xde, // stream id - 0x37, 0x13, 0xfe, 0xca, 0xef, 0xbe, 0xad, 0xde, // byte offset - })) - }) - }) - Context("in big endian", func() { It("writes a stream-level WINDOW_UPDATE frame", func() { b := &bytes.Buffer{} diff --git a/internal/wire/wire_suite_test.go b/internal/wire/wire_suite_test.go index 4cd39e6f..df492f73 100644 --- a/internal/wire/wire_suite_test.go +++ b/internal/wire/wire_suite_test.go @@ -15,8 +15,6 @@ func TestCrypto(t *testing.T) { } const ( - // a QUIC version that uses little endian encoding - versionLittleEndian = protocol.Version37 // a QUIC version that uses big endian encoding versionBigEndian = protocol.Version39 // a QUIC version that uses the MAX_DATA / MAX_STREAM_DATA and BLOCKED / STREAM_BLOCKED frames @@ -24,10 +22,8 @@ const ( ) var _ = BeforeSuite(func() { - Expect(utils.GetByteOrder(versionLittleEndian)).To(Equal(utils.LittleEndian)) Expect(utils.GetByteOrder(versionBigEndian)).To(Equal(utils.BigEndian)) Expect(utils.GetByteOrder(versionMaxDataFrame)).To(Equal(utils.BigEndian)) - Expect(versionLittleEndian.UsesMaxDataFrame()).To(BeFalse()) Expect(versionBigEndian.UsesMaxDataFrame()).To(BeFalse()) Expect(versionMaxDataFrame.UsesMaxDataFrame()).To(BeTrue()) }) diff --git a/session_test.go b/session_test.go index cca47f97..f31163d9 100644 --- a/session_test.go +++ b/session_test.go @@ -181,7 +181,7 @@ var _ = Describe("Session", func() { var pSess Session pSess, handshakeChan, err = newSession( mconn, - protocol.Version37, + protocol.Version39, 0, scfg, nil, @@ -230,7 +230,7 @@ var _ = Describe("Session", func() { } pSess, _, err := newSession( mconn, - protocol.Version37, + protocol.Version39, 0, scfg, nil, @@ -621,7 +621,10 @@ var _ = Describe("Session", func() { sess.Close(nil) Eventually(areSessionsRunning).Should(BeFalse()) Expect(mconn.written).To(HaveLen(1)) - Expect(mconn.written).To(Receive(ContainSubstring(string([]byte{0x02, byte(qerr.PeerGoingAway), 0, 0, 0, 0, 0})))) + buf := &bytes.Buffer{} + err := (&wire.ConnectionCloseFrame{ErrorCode: qerr.PeerGoingAway}).Write(buf, sess.version) + Expect(err).ToNot(HaveOccurred()) + Expect(mconn.written).To(Receive(ContainSubstring(string(buf.Bytes())))) Expect(sess.Context().Done()).To(BeClosed()) }) @@ -782,23 +785,23 @@ var _ = Describe("Session", func() { Context("sending packets", func() { It("sends ACK frames", func() { - packetNumber := protocol.PacketNumber(0x035E) + packetNumber := protocol.PacketNumber(0x035e) sess.receivedPacketHandler.ReceivedPacket(packetNumber, true) err := sess.sendPacket() Expect(err).NotTo(HaveOccurred()) Expect(mconn.written).To(HaveLen(1)) - Expect(mconn.written).To(Receive(ContainSubstring(string([]byte{0x5E, 0x03})))) + Expect(mconn.written).To(Receive(ContainSubstring(string([]byte{0x03, 0x5e})))) }) It("sends ACK frames when congestion limited", func() { sess.sentPacketHandler = &mockSentPacketHandler{congestionLimited: true} sess.packer.packetNumberGenerator.next = 0x1338 - packetNumber := protocol.PacketNumber(0x035E) + packetNumber := protocol.PacketNumber(0x035e) sess.receivedPacketHandler.ReceivedPacket(packetNumber, true) err := sess.sendPacket() Expect(err).NotTo(HaveOccurred()) Expect(mconn.written).To(HaveLen(1)) - Expect(mconn.written).To(Receive(ContainSubstring(string([]byte{0x5E, 0x03})))) + Expect(mconn.written).To(Receive(ContainSubstring(string([]byte{0x03, 0x5e})))) }) It("sends a retransmittable packet when required by the SentPacketHandler", func() { @@ -1046,7 +1049,7 @@ var _ = Describe("Session", func() { defer sess.Close(nil) time.Sleep(10 * time.Millisecond) Eventually(func() int { return len(mconn.written) }).ShouldNot(BeZero()) - Expect(mconn.written).To(Receive(ContainSubstring(string([]byte{0x37, 0x13})))) + Expect(mconn.written).To(Receive(ContainSubstring(string([]byte{0x13, 0x37})))) }) Context("bundling of small packets", func() { @@ -1114,8 +1117,8 @@ var _ = Describe("Session", func() { Expect(err).NotTo(HaveOccurred()) Eventually(mconn.written).Should(HaveLen(2)) - Expect(mconn.written).To(Receive(ContainSubstring(string([]byte{0x37, 0x13})))) - Expect(mconn.written).ToNot(Receive(ContainSubstring(string([]byte{0x37, 0x13})))) + Expect(mconn.written).To(Receive(ContainSubstring(string([]byte{0x13, 0x37})))) + Expect(mconn.written).ToNot(Receive(ContainSubstring(string([]byte{0x13, 0x37})))) }) }) }) @@ -1529,7 +1532,7 @@ var _ = Describe("Client Session", func() { sessP, _, err := newClientSession( mconn, "hostname", - protocol.Version37, + protocol.Version39, 0, nil, populateClientConfig(&Config{}),