forked from quic-go/quic-go
ignore delayed version negotiation packets
This commit is contained in:
11
client.go
11
client.go
@@ -20,8 +20,9 @@ type Client struct {
|
|||||||
conn *net.UDPConn
|
conn *net.UDPConn
|
||||||
hostname string
|
hostname string
|
||||||
|
|
||||||
connectionID protocol.ConnectionID
|
connectionID protocol.ConnectionID
|
||||||
version protocol.VersionNumber
|
version protocol.VersionNumber
|
||||||
|
versionNegotiated bool
|
||||||
|
|
||||||
session packetHandler
|
session packetHandler
|
||||||
}
|
}
|
||||||
@@ -123,7 +124,10 @@ func (c *Client) handlePacket(packet []byte) error {
|
|||||||
}
|
}
|
||||||
hdr.Raw = packet[:len(packet)-r.Len()]
|
hdr.Raw = packet[:len(packet)-r.Len()]
|
||||||
|
|
||||||
// TODO: ignore delayed / duplicated version negotiation packets
|
// ignore delayed / duplicated version negotiation packets
|
||||||
|
if c.versionNegotiated && hdr.VersionFlag {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if hdr.VersionFlag {
|
if hdr.VersionFlag {
|
||||||
// check if the server sent the offered version in supported versions
|
// check if the server sent the offered version in supported versions
|
||||||
@@ -140,6 +144,7 @@ func (c *Client) handlePacket(packet []byte) error {
|
|||||||
|
|
||||||
utils.Infof("Switching to QUIC version %d", highestSupportedVersion)
|
utils.Infof("Switching to QUIC version %d", highestSupportedVersion)
|
||||||
c.version = highestSupportedVersion
|
c.version = highestSupportedVersion
|
||||||
|
c.versionNegotiated = true
|
||||||
c.session.Close(errCloseSessionForNewVersion)
|
c.session.Close(errCloseSessionForNewVersion)
|
||||||
err = c.createNewSession()
|
err = c.createNewSession()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ var _ = Describe("Client", func() {
|
|||||||
Expect(session.packetCount).To(BeZero())
|
Expect(session.packetCount).To(BeZero())
|
||||||
err := client.handlePacket(getVersionNegotiation([]protocol.VersionNumber{newVersion}))
|
err := client.handlePacket(getVersionNegotiation([]protocol.VersionNumber{newVersion}))
|
||||||
Expect(client.version).To(Equal(newVersion))
|
Expect(client.version).To(Equal(newVersion))
|
||||||
|
Expect(client.versionNegotiated).To(BeTrue())
|
||||||
// it swapped the sessions
|
// it swapped the sessions
|
||||||
Expect(client.session).ToNot(Equal(session))
|
Expect(client.session).ToNot(Equal(session))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@@ -165,6 +166,16 @@ var _ = Describe("Client", func() {
|
|||||||
Expect(err).To(MatchError(qerr.VersionNegotiationMismatch))
|
Expect(err).To(MatchError(qerr.VersionNegotiationMismatch))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("ignores delayed version negotiation packets", func() {
|
||||||
|
// if the version was not yet negotiated, handlePacket would return a VersionNegotiationMismatch error, see above test
|
||||||
|
client.versionNegotiated = true
|
||||||
|
Expect(session.packetCount).To(BeZero())
|
||||||
|
err := client.handlePacket(getVersionNegotiation([]protocol.VersionNumber{1}))
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(client.versionNegotiated).To(BeTrue())
|
||||||
|
Expect(session.packetCount).To(BeZero())
|
||||||
|
})
|
||||||
|
|
||||||
It("errors if the server should have accepted the offered version", func() {
|
It("errors if the server should have accepted the offered version", func() {
|
||||||
err := client.handlePacket(getVersionNegotiation([]protocol.VersionNumber{client.version}))
|
err := client.handlePacket(getVersionNegotiation([]protocol.VersionNumber{client.version}))
|
||||||
Expect(err).To(MatchError(errInvalidVersionNegotiation))
|
Expect(err).To(MatchError(errInvalidVersionNegotiation))
|
||||||
|
|||||||
Reference in New Issue
Block a user