diff --git a/client.go b/client.go index f58a0490..882a1b58 100644 --- a/client.go +++ b/client.go @@ -129,6 +129,12 @@ func (c *Client) handlePacket(packet []byte) error { return nil } + // this is the first packet after the client sent a packet with the VersionFlag set + // if the server doesn't send a version negotiation packet, it supports the suggested version + if !hdr.VersionFlag && !c.versionNegotiated { + c.versionNegotiated = true + } + if hdr.VersionFlag { // check if the server sent the offered version in supported versions for _, v := range hdr.SupportedVersions { diff --git a/client_test.go b/client_test.go index f2740c0a..b546c1d1 100644 --- a/client_test.go +++ b/client_test.go @@ -150,6 +150,20 @@ var _ = Describe("Client", func() { return packet } + It("recognizes that a packet without VersionFlag means that the server accepted the suggested version", func() { + ph := PublicHeader{ + PacketNumber: 1, + PacketNumberLen: protocol.PacketNumberLen2, + ConnectionID: 0x1337, + } + b := &bytes.Buffer{} + err := ph.Write(b, protocol.VersionWhatever, protocol.PerspectiveServer) + Expect(err).ToNot(HaveOccurred()) + err = client.handlePacket(b.Bytes()) + Expect(err).ToNot(HaveOccurred()) + Expect(client.versionNegotiated).To(BeTrue()) + }) + It("changes the version after receiving a version negotiation packet", func() { startUDPConn() newVersion := protocol.Version35