mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 04:37:36 +03:00
echo the offered version in IETF Version Negotiation Packets
This commit is contained in:
parent
bf1ee17e67
commit
234d5aab36
4 changed files with 13 additions and 5 deletions
|
@ -115,14 +115,15 @@ var _ = Describe("Header", func() {
|
|||
Expect(hdr.SupportedVersions).To(Equal(versions))
|
||||
})
|
||||
|
||||
It("parses a gQUIC Version Negotiation Packet", func() {
|
||||
It("parses an IETF draft style Version Negotiation Packet", func() {
|
||||
versions := []protocol.VersionNumber{0x13, 0x37}
|
||||
data := ComposeVersionNegotiation(0x42, 0x77, versions)
|
||||
data := ComposeVersionNegotiation(0x42, 0x77, 0x4321, versions)
|
||||
hdr, err := ParseHeaderSentByServer(bytes.NewReader(data), protocol.VersionUnknown)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(hdr.isPublicHeader).To(BeFalse())
|
||||
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x42)))
|
||||
Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(0x77)))
|
||||
Expect(hdr.Version).To(Equal(protocol.VersionNumber(0x4321)))
|
||||
Expect(hdr.SupportedVersions).To(Equal(versions))
|
||||
Expect(hdr.Type).To(Equal(protocol.PacketTypeVersionNegotiation))
|
||||
})
|
||||
|
|
|
@ -26,13 +26,19 @@ func ComposeGQUICVersionNegotiation(connID protocol.ConnectionID, versions []pro
|
|||
}
|
||||
|
||||
// ComposeVersionNegotiation composes a Version Negotiation according to the IETF draft
|
||||
func ComposeVersionNegotiation(connID protocol.ConnectionID, pn protocol.PacketNumber, versions []protocol.VersionNumber) []byte {
|
||||
func ComposeVersionNegotiation(
|
||||
connID protocol.ConnectionID,
|
||||
pn protocol.PacketNumber,
|
||||
versionOffered protocol.VersionNumber,
|
||||
versions []protocol.VersionNumber,
|
||||
) []byte {
|
||||
fullReply := &bytes.Buffer{}
|
||||
ph := Header{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeVersionNegotiation,
|
||||
ConnectionID: connID,
|
||||
PacketNumber: pn,
|
||||
Version: versionOffered,
|
||||
}
|
||||
if err := ph.writeHeader(fullReply); err != nil {
|
||||
utils.Errorf("error composing version negotiation packet: %s", err.Error())
|
||||
|
|
|
@ -21,12 +21,13 @@ var _ = Describe("Version Negotiation Packets", func() {
|
|||
|
||||
It("writes IETF draft style", func() {
|
||||
versions := []protocol.VersionNumber{1001, 1003}
|
||||
data := ComposeVersionNegotiation(0x1337, 0x42, versions)
|
||||
data := ComposeVersionNegotiation(0x1337, 0x42, 0x1234, versions)
|
||||
hdr, err := parseHeader(bytes.NewReader(data), protocol.PerspectiveServer)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(hdr.Type).To(Equal(protocol.PacketTypeVersionNegotiation))
|
||||
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x1337)))
|
||||
Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(0x42)))
|
||||
Expect(hdr.Version).To(Equal(protocol.VersionNumber(0x1234)))
|
||||
Expect(hdr.SupportedVersions).To(Equal(versions))
|
||||
})
|
||||
})
|
||||
|
|
|
@ -280,7 +280,7 @@ func (s *server) handlePacket(pconn net.PacketConn, remoteAddr net.Addr, packet
|
|||
}
|
||||
// send an IETF draft style Version Negotiation Packet, if the client sent an unsupported version with an IETF draft style header
|
||||
if hdr.Type == protocol.PacketTypeInitial && !protocol.IsSupportedVersion(s.config.Versions, hdr.Version) {
|
||||
_, err := pconn.WriteTo(wire.ComposeVersionNegotiation(hdr.ConnectionID, hdr.PacketNumber, s.config.Versions), remoteAddr)
|
||||
_, err := pconn.WriteTo(wire.ComposeVersionNegotiation(hdr.ConnectionID, hdr.PacketNumber, hdr.Version, s.config.Versions), remoteAddr)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue