move parsing of version negotiation packets to the wire.Header

This commit is contained in:
Marten Seemann 2018-11-25 12:36:45 +07:00
parent 5581fee684
commit 9bcedd988d
15 changed files with 167 additions and 176 deletions

View file

@ -16,19 +16,17 @@ 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), 4)
Expect(err).ToNot(HaveOccurred())
b := bytes.NewReader(data)
extHdr, err := hdr.Parse(b, versionIETFFrames)
hdr, err := ParseHeader(b, 4)
Expect(err).ToNot(HaveOccurred())
Expect(extHdr.IsVersionNegotiation).To(BeTrue())
Expect(extHdr.DestConnectionID).To(Equal(destConnID))
Expect(extHdr.SrcConnectionID).To(Equal(srcConnID))
Expect(extHdr.Version).To(BeZero())
Expect(err).ToNot(HaveOccurred())
Expect(hdr.DestConnectionID).To(Equal(destConnID))
Expect(hdr.SrcConnectionID).To(Equal(srcConnID))
Expect(hdr.Version).To(BeZero())
// the supported versions should include one reserved version number
Expect(extHdr.SupportedVersions).To(HaveLen(len(versions) + 1))
Expect(hdr.SupportedVersions).To(HaveLen(len(versions) + 1))
for _, version := range versions {
Expect(extHdr.SupportedVersions).To(ContainElement(version))
Expect(hdr.SupportedVersions).To(ContainElement(version))
}
Expect(b.Len()).To(BeZero())
})