diff --git a/benchmark/benchmark_test.go b/benchmark/benchmark_test.go index 59108fba..0f5123ca 100644 --- a/benchmark/benchmark_test.go +++ b/benchmark/benchmark_test.go @@ -26,7 +26,7 @@ func init() { for i := range protocol.SupportedVersions { version := protocol.SupportedVersions[i] - Context(fmt.Sprintf("with version %d", version), func() { + Context(fmt.Sprintf("with version %s", version), func() { Measure(fmt.Sprintf("transferring a %d MB file", size), func(b Benchmarker) { var ln quic.Listener serverAddr := make(chan net.Addr) diff --git a/client.go b/client.go index 18533dba..d1449627 100644 --- a/client.go +++ b/client.go @@ -112,7 +112,7 @@ func DialNonFWSecure( versionNegotiationChan: make(chan struct{}), } - utils.Infof("Starting new connection to %s (%s -> %s), connectionID %x, version %d", hostname, c.conn.LocalAddr().String(), c.conn.RemoteAddr().String(), c.connectionID, c.version) + utils.Infof("Starting new connection to %s (%s -> %s), connectionID %x, version %s", hostname, c.conn.LocalAddr().String(), c.conn.RemoteAddr().String(), c.connectionID, c.version) if err := c.establishSecureConnection(); err != nil { return nil, err @@ -338,7 +338,7 @@ func (c *client) handlePacketWithVersionFlag(hdr *wire.PublicHeader) error { if err != nil { return err } - utils.Infof("Switching to QUIC version %d. New connection ID: %x", newVersion, c.connectionID) + utils.Infof("Switching to QUIC version %s. New connection ID: %x", newVersion, c.connectionID) // create a new session and close the old one // the new session must be created first to update client member variables diff --git a/integrationtests/chrome/chrome_test.go b/integrationtests/chrome/chrome_test.go index 8fd6dbfc..72d1edcc 100644 --- a/integrationtests/chrome/chrome_test.go +++ b/integrationtests/chrome/chrome_test.go @@ -12,7 +12,7 @@ var _ = Describe("Chrome tests", func() { for i := range protocol.SupportedVersions { version = protocol.SupportedVersions[i] - Context(fmt.Sprintf("with quic version %d", version), func() { + Context(fmt.Sprintf("with quic version %s", version), func() { It("downloads a small file", func() { chromeTest( version, diff --git a/integrationtests/gquic/drop_test.go b/integrationtests/gquic/drop_test.go index cffa3fb4..ca4535bb 100644 --- a/integrationtests/gquic/drop_test.go +++ b/integrationtests/gquic/drop_test.go @@ -78,7 +78,7 @@ var _ = Describe("Drop tests", func() { for _, v := range protocol.SupportedVersions { version := v - Context(fmt.Sprintf("with QUIC version %d", version), func() { + Context(fmt.Sprintf("with QUIC version %s", version), func() { Context("during the crypto handshake", func() { for _, d := range directions { direction := d diff --git a/integrationtests/gquic/integration_test.go b/integrationtests/gquic/integration_test.go index 5de42558..2f449aec 100644 --- a/integrationtests/gquic/integration_test.go +++ b/integrationtests/gquic/integration_test.go @@ -22,7 +22,7 @@ var _ = Describe("Integration tests", func() { for i := range protocol.SupportedVersions { version := protocol.SupportedVersions[i] - Context(fmt.Sprintf("with quic version %d", version), func() { + Context(fmt.Sprintf("with QUIC version %s", version), func() { It("gets a simple file", func() { command := exec.Command( clientPath, diff --git a/integrationtests/gquic/random_rtt_test.go b/integrationtests/gquic/random_rtt_test.go index fdb406e7..e86b0614 100644 --- a/integrationtests/gquic/random_rtt_test.go +++ b/integrationtests/gquic/random_rtt_test.go @@ -88,7 +88,7 @@ var _ = Describe("Random RTT", func() { for i := range protocol.SupportedVersions { version := protocol.SupportedVersions[i] - Context(fmt.Sprintf("with quic version %d", version), func() { + Context(fmt.Sprintf("with QUIC version %s", version), func() { It("gets a file a random RTT between 10ms and 30ms", func() { runRTTTest(10*time.Millisecond, 30*time.Millisecond, version) }) diff --git a/integrationtests/gquic/rtt_test.go b/integrationtests/gquic/rtt_test.go index 89419f54..66a467b1 100644 --- a/integrationtests/gquic/rtt_test.go +++ b/integrationtests/gquic/rtt_test.go @@ -54,7 +54,7 @@ var _ = Describe("non-zero RTT", func() { for i := range protocol.SupportedVersions { version := protocol.SupportedVersions[i] - Context(fmt.Sprintf("with quic version %d", version), func() { + Context(fmt.Sprintf("with QUIC version %s", version), func() { roundTrips := [...]int{10, 50, 100, 200} for _, rtt := range roundTrips { It(fmt.Sprintf("gets a 500kB file with %dms RTT", rtt), func() { diff --git a/integrationtests/gquic/server_test.go b/integrationtests/gquic/server_test.go index 1d9e7cc9..832386d3 100644 --- a/integrationtests/gquic/server_test.go +++ b/integrationtests/gquic/server_test.go @@ -170,7 +170,7 @@ var _ = Describe("Server tests", func() { tmpDir = "" }) - Context(fmt.Sprintf("with QUIC version %d", version), func() { + Context(fmt.Sprintf("with QUIC version %s", version), func() { It("downloads a hello", func() { data := []byte("Hello world!\n") createDownloadFile("hello", data) diff --git a/integrationtests/self/client_test.go b/integrationtests/self/client_test.go index 0c63a36c..6ab06cdd 100644 --- a/integrationtests/self/client_test.go +++ b/integrationtests/self/client_test.go @@ -39,7 +39,7 @@ var _ = Describe("Client tests", func() { for _, v := range protocol.SupportedVersions { version := v - Context(fmt.Sprintf("with quic version %d", version), func() { + Context(fmt.Sprintf("with QUIC version %s", version), func() { BeforeEach(func() { client = &http.Client{ Transport: &h2quic.RoundTripper{ diff --git a/internal/protocol/version.go b/internal/protocol/version.go index 5f269808..8c6ebc2c 100644 --- a/internal/protocol/version.go +++ b/internal/protocol/version.go @@ -1,5 +1,7 @@ package protocol +import "fmt" + // VersionNumber is a version number as int type VersionNumber int @@ -27,6 +29,21 @@ func (vn VersionNumber) UsesTLS() bool { return vn == VersionTLS } +func (vn VersionNumber) String() string { + switch vn { + case VersionWhatever: + return "whatever" + case VersionUnsupported: + return "unsupported" + case VersionUnknown: + return "unknown" + case VersionTLS: + return "TLS dev version (WIP)" + default: + return fmt.Sprintf("%d", vn) + } +} + // VersionNumberToTag maps version numbers ('32') to tags ('Q032') func VersionNumberToTag(vn VersionNumber) uint32 { v := uint32(vn) diff --git a/internal/protocol/version_test.go b/internal/protocol/version_test.go index 4f7436c7..647a8c15 100644 --- a/internal/protocol/version_test.go +++ b/internal/protocol/version_test.go @@ -13,6 +13,16 @@ var _ = Describe("Version", func() { Expect(VersionTLS.UsesTLS()).To(BeTrue()) }) + It("has the right string representation", func() { + Expect(Version37.String()).To(Equal("37")) + Expect(Version38.String()).To(Equal("38")) + Expect(Version39.String()).To(Equal("39")) + Expect(VersionTLS.String()).To(ContainSubstring("TLS")) + Expect(VersionWhatever.String()).To(Equal("whatever")) + Expect(VersionUnsupported.String()).To(Equal("unsupported")) + Expect(VersionUnknown.String()).To(Equal("unknown")) + }) + It("converts tags to numbers", func() { Expect(VersionTagToNumber('Q' + '1'<<8 + '2'<<16 + '3'<<24)).To(Equal(VersionNumber(123))) }) diff --git a/server.go b/server.go index 25e975a3..b4be3cb3 100644 --- a/server.go +++ b/server.go @@ -272,7 +272,7 @@ func (s *server) handlePacket(pconn net.PacketConn, remoteAddr net.Addr, packet if len(packet) < protocol.ClientHelloMinimumSize+len(hdr.Raw) { return errors.New("dropping small packet with unknown version") } - utils.Infof("Client offered version %d, sending VersionNegotiationPacket", hdr.VersionNumber) + utils.Infof("Client offered version %s, sending VersionNegotiationPacket", hdr.VersionNumber) _, err = pconn.WriteTo(wire.ComposeVersionNegotiation(hdr.ConnectionID, s.config.Versions), remoteAddr) return err } @@ -283,7 +283,7 @@ func (s *server) handlePacket(pconn net.PacketConn, remoteAddr net.Addr, packet return errors.New("Server BUG: negotiated version not supported") } - utils.Infof("Serving new connection: %x, version %d from %v", hdr.ConnectionID, version, remoteAddr) + utils.Infof("Serving new connection: %x, version %s from %v", hdr.ConnectionID, version, remoteAddr) var handshakeChan <-chan handshakeEvent session, handshakeChan, err = s.newSession( &conn{pconn: pconn, currentAddr: remoteAddr},