-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move the SupportedVersions slice out of the wire.Header
- Loading branch information
1 parent
953f347
commit 993d71f
Showing
11 changed files
with
119 additions
and
97 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,86 @@ | ||
package wire | ||
|
||
import ( | ||
"bytes" | ||
"encoding/binary" | ||
|
||
"github.com/lucas-clemente/quic-go/internal/protocol" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Version Negotiation Packets", func() { | ||
It("writes", func() { | ||
It("parses a Version Negotiation packet", func() { | ||
srcConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} | ||
destConnID := protocol.ConnectionID{9, 8, 7, 6, 5, 4, 3, 2, 1} | ||
versions := []protocol.VersionNumber{0x22334455, 0x33445566} | ||
data := []byte{0x80, 0, 0, 0, 0} | ||
data = append(data, uint8(len(destConnID))) | ||
data = append(data, destConnID...) | ||
data = append(data, uint8(len(srcConnID))) | ||
data = append(data, srcConnID...) | ||
for _, v := range versions { | ||
data = append(data, []byte{0, 0, 0, 0}...) | ||
binary.BigEndian.PutUint32(data[len(data)-4:], uint32(v)) | ||
} | ||
Expect(IsVersionNegotiationPacket(data)).To(BeTrue()) | ||
hdr, supportedVersions, err := ParseVersionNegotiationPacket(bytes.NewReader(data)) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(hdr.DestConnectionID).To(Equal(destConnID)) | ||
Expect(hdr.SrcConnectionID).To(Equal(srcConnID)) | ||
Expect(hdr.IsLongHeader).To(BeTrue()) | ||
Expect(hdr.Version).To(BeZero()) | ||
Expect(supportedVersions).To(Equal(versions)) | ||
}) | ||
|
||
It("errors if it contains versions of the wrong length", func() { | ||
connID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8} | ||
versions := []protocol.VersionNumber{0x22334455, 0x33445566} | ||
data, err := ComposeVersionNegotiation(connID, connID, versions) | ||
Expect(err).ToNot(HaveOccurred()) | ||
_, _, err = ParseVersionNegotiationPacket(bytes.NewReader(data[:len(data)-2])) | ||
Expect(err).To(MatchError("Version Negotiation packet has a version list with an invalid length")) | ||
}) | ||
|
||
It("errors if the version list is empty", func() { | ||
connID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8} | ||
versions := []protocol.VersionNumber{0x22334455} | ||
data, err := ComposeVersionNegotiation(connID, connID, versions) | ||
Expect(err).ToNot(HaveOccurred()) | ||
// remove 8 bytes (two versions), since ComposeVersionNegotiation also added a reserved version number | ||
data = data[:len(data)-8] | ||
_, _, err = ParseVersionNegotiationPacket(bytes.NewReader(data)) | ||
Expect(err).To(MatchError("Version Negotiation packet has empty version list")) | ||
}) | ||
|
||
It("adds a reserved version", func() { | ||
srcConnID := protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37} | ||
destConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8} | ||
versions := []protocol.VersionNumber{1001, 1003} | ||
data, err := ComposeVersionNegotiation(destConnID, srcConnID, versions) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(data[0] & 0x80).ToNot(BeZero()) | ||
hdr, _, rest, err := ParsePacket(data, 4) | ||
hdr, supportedVersions, err := ParseVersionNegotiationPacket(bytes.NewReader(data)) | ||
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(hdr.SupportedVersions).To(HaveLen(len(versions) + 1)) | ||
for _, version := range versions { | ||
Expect(hdr.SupportedVersions).To(ContainElement(version)) | ||
Expect(supportedVersions).To(HaveLen(len(versions) + 1)) | ||
for _, v := range versions { | ||
Expect(supportedVersions).To(ContainElement(v)) | ||
} | ||
var reservedVersion protocol.VersionNumber | ||
versionLoop: | ||
for _, ver := range supportedVersions { | ||
for _, v := range versions { | ||
if v == ver { | ||
continue versionLoop | ||
} | ||
} | ||
reservedVersion = ver | ||
} | ||
Expect(rest).To(BeEmpty()) | ||
Expect(reservedVersion).ToNot(BeZero()) | ||
Expect(reservedVersion&0x0f0f0f0f == 0x0a0a0a0a).To(BeTrue()) // check that it's a greased version number | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters