refactor header parsing in a version independent and dependent part

This commit is contained in:
Marten Seemann 2018-06-30 23:32:26 +07:00
parent 74ed3f7037
commit 4109c85c8a
20 changed files with 1587 additions and 1804 deletions

View file

@ -13,7 +13,10 @@ var _ = Describe("Version Negotiation Packets", func() {
connID := protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}
versions := []protocol.VersionNumber{1001, 1003}
data := ComposeGQUICVersionNegotiation(connID, versions)
hdr, err := parsePublicHeader(bytes.NewReader(data), protocol.PerspectiveServer)
b := bytes.NewReader(data)
iHdr, err := ParseInvariantHeader(b)
Expect(err).ToNot(HaveOccurred())
hdr, err := iHdr.Parse(b, protocol.PerspectiveServer, versionPublicHeader)
Expect(err).ToNot(HaveOccurred())
Expect(hdr.VersionFlag).To(BeTrue())
Expect(hdr.DestConnectionID).To(Equal(connID))
@ -28,7 +31,10 @@ var _ = Describe("Version Negotiation Packets", func() {
data, err := ComposeVersionNegotiation(destConnID, srcConnID, versions)
Expect(err).ToNot(HaveOccurred())
Expect(data[0] & 0x80).ToNot(BeZero())
hdr, err := parseHeader(bytes.NewReader(data))
b := bytes.NewReader(data)
iHdr, err := ParseInvariantHeader(b)
Expect(err).ToNot(HaveOccurred())
hdr, err := iHdr.Parse(b, protocol.PerspectiveServer, versionIETFHeader)
Expect(err).ToNot(HaveOccurred())
Expect(hdr.IsVersionNegotiation).To(BeTrue())
Expect(hdr.DestConnectionID).To(Equal(destConnID))