forked from quic-go/quic-go
save version numbers such that can be written in big endian
This makes the version number representation consistent with the IETF draft.
This commit is contained in:
@@ -61,7 +61,7 @@ func (h *Header) writePublicHeader(b *bytes.Buffer, pers protocol.Perspective, v
|
||||
utils.BigEndian.WriteUint64(b, uint64(h.ConnectionID))
|
||||
}
|
||||
if h.VersionFlag && pers == protocol.PerspectiveClient {
|
||||
utils.LittleEndian.WriteUint32(b, protocol.VersionNumberToTag(h.Version))
|
||||
utils.BigEndian.WriteUint32(b, uint32(h.Version))
|
||||
}
|
||||
if len(h.DiversificationNonce) > 0 {
|
||||
b.Write(h.DiversificationNonce)
|
||||
@@ -163,11 +163,11 @@ func parsePublicHeader(b *bytes.Reader, packetSentBy protocol.Perspective, versi
|
||||
header.SupportedVersions = make([]protocol.VersionNumber, 0)
|
||||
for {
|
||||
var versionTag uint32
|
||||
versionTag, err = utils.LittleEndian.ReadUint32(b)
|
||||
versionTag, err = utils.BigEndian.ReadUint32(b)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
v := protocol.VersionTagToNumber(versionTag)
|
||||
v := protocol.VersionNumber(versionTag)
|
||||
header.SupportedVersions = append(header.SupportedVersions, v)
|
||||
}
|
||||
// a version negotiation packet doesn't have a packet number
|
||||
@@ -175,11 +175,11 @@ func parsePublicHeader(b *bytes.Reader, packetSentBy protocol.Perspective, versi
|
||||
}
|
||||
// packet was sent by the client. Read the version number
|
||||
var versionTag uint32
|
||||
versionTag, err = utils.LittleEndian.ReadUint32(b)
|
||||
versionTag, err = utils.BigEndian.ReadUint32(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
header.Version = protocol.VersionTagToNumber(versionTag)
|
||||
header.Version = protocol.VersionNumber(versionTag)
|
||||
version = header.Version
|
||||
}
|
||||
|
||||
|
||||
@@ -14,13 +14,15 @@ import (
|
||||
var _ = Describe("Public Header", func() {
|
||||
Context("when parsing", func() {
|
||||
It("accepts a sample client header", func() {
|
||||
b := bytes.NewReader([]byte{0x09, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0x51, 0x30, 0x33, 0x34, 0x01})
|
||||
ver := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(ver, uint32(protocol.SupportedVersions[0]))
|
||||
b := bytes.NewReader(append(append([]byte{0x09, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6}, ver...), 0x01))
|
||||
hdr, err := parsePublicHeader(b, protocol.PerspectiveClient, protocol.VersionUnknown)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(hdr.VersionFlag).To(BeTrue())
|
||||
Expect(hdr.ResetFlag).To(BeFalse())
|
||||
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x4cfa9f9b668619f6)))
|
||||
Expect(hdr.Version).To(Equal(protocol.VersionNumber(34)))
|
||||
Expect(hdr.Version).To(Equal(protocol.SupportedVersions[0]))
|
||||
Expect(hdr.SupportedVersions).To(BeEmpty())
|
||||
Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(1)))
|
||||
Expect(b.Len()).To(BeZero())
|
||||
@@ -93,7 +95,7 @@ var _ = Describe("Public Header", func() {
|
||||
Context("version negotiation packets", func() {
|
||||
appendVersion := func(data []byte, v protocol.VersionNumber) []byte {
|
||||
data = append(data, []byte{0, 0, 0, 0}...)
|
||||
binary.LittleEndian.PutUint32(data[len(data)-4:], protocol.VersionNumberToTag(v))
|
||||
binary.BigEndian.PutUint32(data[len(data)-4:], uint32(v))
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ func ComposeVersionNegotiation(connectionID protocol.ConnectionID, versions []pr
|
||||
utils.Errorf("error composing version negotiation packet: %s", err.Error())
|
||||
}
|
||||
for _, v := range versions {
|
||||
utils.LittleEndian.WriteUint32(fullReply, protocol.VersionNumberToTag(v))
|
||||
utils.BigEndian.WriteUint32(fullReply, uint32(v))
|
||||
}
|
||||
return fullReply.Bytes()
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ var _ = Describe("Version Negotiation Packet", func() {
|
||||
It("composes version negotiation packets", func() {
|
||||
expected := append(
|
||||
[]byte{0x01 | 0x08, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
|
||||
[]byte{'Q', '0', '9', '9'}...,
|
||||
[]byte{'Q', '0', '3', '9'}...,
|
||||
)
|
||||
Expect(ComposeVersionNegotiation(1, []protocol.VersionNumber{99})).To(Equal(expected))
|
||||
Expect(ComposeVersionNegotiation(1, []protocol.VersionNumber{protocol.Version39})).To(Equal(expected))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user