only use little endian byte order for gQUIC 37 and 38

That way, when adding new non-gQUIC versions, they will use big endian.
This commit is contained in:
Marten Seemann 2017-10-30 12:43:05 +07:00
parent 085702df36
commit aba1dd13ba
4 changed files with 51 additions and 51 deletions

View file

@ -29,7 +29,7 @@ type ByteOrder interface {
// GetByteOrder gets the ByteOrder (little endian or big endian) used 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.Version39 {
if v == protocol.Version37 || v == protocol.Version38 {
return LittleEndian
}
return BigEndian

View file

@ -270,12 +270,12 @@ var _ = Describe("Public Header", func() {
hdr := Header{
ConnectionID: 0x4cfa9f9b668619f6,
OmitConnectionID: true,
PacketNumberLen: protocol.PacketNumberLen6,
PacketNumberLen: protocol.PacketNumberLen1,
PacketNumber: 1,
}
err := hdr.writePublicHeader(b, protocol.PerspectiveServer, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x30, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0}))
Expect(b.Bytes()).To(Equal([]byte{0x0, 0x1}))
})
It("writes diversification nonces", func() {
@ -329,18 +329,18 @@ var _ = Describe("Public Header", func() {
VersionFlag: true,
Version: protocol.Version38,
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 0x1337,
PacketNumberLen: protocol.PacketNumberLen6,
PacketNumber: 0x42,
PacketNumberLen: protocol.PacketNumberLen1,
}
err := hdr.writePublicHeader(b, protocol.PerspectiveClient, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
// must be the first assertion
Expect(b.Len()).To(Equal(1 + 8 + 4 + 6)) // 1 FlagByte + 8 ConnectionID + 4 version number + 6 PacketNumber
Expect(b.Len()).To(Equal(1 + 8 + 4 + 1)) // 1 FlagByte + 8 ConnectionID + 4 version number + 1 PacketNumber
firstByte, _ := b.ReadByte()
Expect(firstByte & 0x01).To(Equal(uint8(1)))
Expect(firstByte & 0x30).To(Equal(uint8(0x30)))
Expect(firstByte & 0x30).To(Equal(uint8(0x0)))
Expect(string(b.Bytes()[8:12])).To(Equal("Q038"))
Expect(b.Bytes()[12:18]).To(Equal([]byte{0x37, 0x13, 0, 0, 0, 0}))
Expect(b.Bytes()[12:13]).To(Equal([]byte{0x42}))
})
})

View file

@ -120,20 +120,35 @@ var _ = Describe("Packet unpacker", func() {
})
It("unpacks RST_STREAM frames", func() {
setData([]byte{0x01, 0xEF, 0xBE, 0xAD, 0xDE, 0x44, 0x33, 0x22, 0x11, 0xAD, 0xFB, 0xCA, 0xDE, 0x34, 0x12, 0x37, 0x13})
f := &wire.RstStreamFrame{
StreamID: 0xdeadbeef,
ByteOffset: 0xdecafbad11223344,
ErrorCode: 0x13371234,
}
err := f.Write(buf, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]wire.Frame{
&wire.RstStreamFrame{
StreamID: 0xDEADBEEF,
ByteOffset: 0xDECAFBAD11223344,
ErrorCode: 0x13371234,
},
}))
Expect(packet.frames).To(Equal([]wire.Frame{f}))
})
It("unpacks CONNECTION_CLOSE frames", func() {
f := &wire.ConnectionCloseFrame{ReasonPhrase: "foo"}
err := f.Write(buf, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]wire.Frame{f}))
})
It("unpacks GOAWAY frames", func() {
f := &wire.GoawayFrame{
ErrorCode: 1,
LastGoodStream: 2,
ReasonPhrase: "foo",
}
err := f.Write(buf, 0)
Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes())
@ -142,44 +157,29 @@ var _ = Describe("Packet unpacker", func() {
Expect(packet.frames).To(Equal([]wire.Frame{f}))
})
It("accepts GOAWAY frames", func() {
setData([]byte{
0x03,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x03, 0x00,
'f', 'o', 'o',
})
It("unpacks WINDOW_UPDATE frames", func() {
f := &wire.WindowUpdateFrame{
StreamID: 0xDEADBEEF,
ByteOffset: 0xCAFE000000001337,
}
buf := &bytes.Buffer{}
err := f.Write(buf, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]wire.Frame{
&wire.GoawayFrame{
ErrorCode: 1,
LastGoodStream: 2,
ReasonPhrase: "foo",
},
}))
Expect(packet.frames).To(Equal([]wire.Frame{f}))
})
It("accepts WINDOW_UPDATE frames", func() {
setData([]byte{0x04, 0xEF, 0xBE, 0xAD, 0xDE, 0x37, 0x13, 0, 0, 0, 0, 0xFE, 0xCA})
It("unpakcs BLOCKED frames", func() {
f := &wire.BlockedFrame{StreamID: 0xDEADBEEF}
buf := &bytes.Buffer{}
err := f.Write(buf, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]wire.Frame{
&wire.WindowUpdateFrame{
StreamID: 0xDEADBEEF,
ByteOffset: 0xCAFE000000001337,
},
}))
})
It("accepts BLOCKED frames", func() {
setData([]byte{0x05, 0xEF, 0xBE, 0xAD, 0xDE})
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]wire.Frame{
&wire.BlockedFrame{StreamID: 0xDEADBEEF},
}))
Expect(packet.frames).To(Equal([]wire.Frame{f}))
})
It("unpacks STOP_WAITING frames", func() {
@ -191,7 +191,7 @@ var _ = Describe("Packet unpacker", func() {
}))
})
It("accepts PING frames", func() {
It("unpacks PING frames", func() {
setData([]byte{0x07})
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())

View file

@ -813,7 +813,7 @@ var _ = Describe("Session", func() {
Expect(sess.sentPacketHandler.(*mockSentPacketHandler).sentPackets[0].Frames).To(ContainElement(&wire.PingFrame{}))
})
It("sends two WindowUpdate frames", func() {
It("sends two WINDOW_UPDATE frames", func() {
mockFC := mocks.NewMockStreamFlowController(mockCtrl)
mockFC.EXPECT().GetWindowUpdate().Return(protocol.ByteCount(0x1000))
mockFC.EXPECT().GetWindowUpdate().Return(protocol.ByteCount(0)).Times(2)
@ -830,7 +830,7 @@ var _ = Describe("Session", func() {
(&wire.WindowUpdateFrame{
StreamID: 5,
ByteOffset: 0x1000,
}).Write(buf, protocol.VersionWhatever)
}).Write(buf, sess.version)
Expect(mconn.written).To(HaveLen(2))
Expect(mconn.written).To(Receive(ContainSubstring(string(buf.Bytes()))))
Expect(mconn.written).To(Receive(ContainSubstring(string(buf.Bytes()))))