forked from quic-go/quic-go
Merge pull request #849 from lucas-clemente/version-stringer
implement a string representation of the version number
This commit is contained in:
@@ -26,7 +26,7 @@ func init() {
|
|||||||
for i := range protocol.SupportedVersions {
|
for i := range protocol.SupportedVersions {
|
||||||
version := protocol.SupportedVersions[i]
|
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) {
|
Measure(fmt.Sprintf("transferring a %d MB file", size), func(b Benchmarker) {
|
||||||
var ln quic.Listener
|
var ln quic.Listener
|
||||||
serverAddr := make(chan net.Addr)
|
serverAddr := make(chan net.Addr)
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ func DialNonFWSecure(
|
|||||||
versionNegotiationChan: make(chan struct{}),
|
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 {
|
if err := c.establishSecureConnection(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -338,7 +338,7 @@ func (c *client) handlePacketWithVersionFlag(hdr *wire.PublicHeader) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// create a new session and close the old one
|
||||||
// the new session must be created first to update client member variables
|
// the new session must be created first to update client member variables
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ var _ = Describe("Chrome tests", func() {
|
|||||||
for i := range protocol.SupportedVersions {
|
for i := range protocol.SupportedVersions {
|
||||||
version = protocol.SupportedVersions[i]
|
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() {
|
It("downloads a small file", func() {
|
||||||
chromeTest(
|
chromeTest(
|
||||||
version,
|
version,
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ var _ = Describe("Drop tests", func() {
|
|||||||
for _, v := range protocol.SupportedVersions {
|
for _, v := range protocol.SupportedVersions {
|
||||||
version := v
|
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() {
|
Context("during the crypto handshake", func() {
|
||||||
for _, d := range directions {
|
for _, d := range directions {
|
||||||
direction := d
|
direction := d
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ var _ = Describe("Integration tests", func() {
|
|||||||
for i := range protocol.SupportedVersions {
|
for i := range protocol.SupportedVersions {
|
||||||
version := protocol.SupportedVersions[i]
|
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() {
|
It("gets a simple file", func() {
|
||||||
command := exec.Command(
|
command := exec.Command(
|
||||||
clientPath,
|
clientPath,
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ var _ = Describe("Random RTT", func() {
|
|||||||
for i := range protocol.SupportedVersions {
|
for i := range protocol.SupportedVersions {
|
||||||
version := protocol.SupportedVersions[i]
|
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() {
|
It("gets a file a random RTT between 10ms and 30ms", func() {
|
||||||
runRTTTest(10*time.Millisecond, 30*time.Millisecond, version)
|
runRTTTest(10*time.Millisecond, 30*time.Millisecond, version)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ var _ = Describe("non-zero RTT", func() {
|
|||||||
for i := range protocol.SupportedVersions {
|
for i := range protocol.SupportedVersions {
|
||||||
version := protocol.SupportedVersions[i]
|
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}
|
roundTrips := [...]int{10, 50, 100, 200}
|
||||||
for _, rtt := range roundTrips {
|
for _, rtt := range roundTrips {
|
||||||
It(fmt.Sprintf("gets a 500kB file with %dms RTT", rtt), func() {
|
It(fmt.Sprintf("gets a 500kB file with %dms RTT", rtt), func() {
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ var _ = Describe("Server tests", func() {
|
|||||||
tmpDir = ""
|
tmpDir = ""
|
||||||
})
|
})
|
||||||
|
|
||||||
Context(fmt.Sprintf("with QUIC version %d", version), func() {
|
Context(fmt.Sprintf("with QUIC version %s", version), func() {
|
||||||
It("downloads a hello", func() {
|
It("downloads a hello", func() {
|
||||||
data := []byte("Hello world!\n")
|
data := []byte("Hello world!\n")
|
||||||
createDownloadFile("hello", data)
|
createDownloadFile("hello", data)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ var _ = Describe("Client tests", func() {
|
|||||||
for _, v := range protocol.SupportedVersions {
|
for _, v := range protocol.SupportedVersions {
|
||||||
version := v
|
version := v
|
||||||
|
|
||||||
Context(fmt.Sprintf("with quic version %d", version), func() {
|
Context(fmt.Sprintf("with QUIC version %s", version), func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
client = &http.Client{
|
client = &http.Client{
|
||||||
Transport: &h2quic.RoundTripper{
|
Transport: &h2quic.RoundTripper{
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
// VersionNumber is a version number as int
|
// VersionNumber is a version number as int
|
||||||
type VersionNumber int
|
type VersionNumber int
|
||||||
|
|
||||||
@@ -27,6 +29,21 @@ func (vn VersionNumber) UsesTLS() bool {
|
|||||||
return vn == VersionTLS
|
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')
|
// VersionNumberToTag maps version numbers ('32') to tags ('Q032')
|
||||||
func VersionNumberToTag(vn VersionNumber) uint32 {
|
func VersionNumberToTag(vn VersionNumber) uint32 {
|
||||||
v := uint32(vn)
|
v := uint32(vn)
|
||||||
|
|||||||
@@ -13,6 +13,16 @@ var _ = Describe("Version", func() {
|
|||||||
Expect(VersionTLS.UsesTLS()).To(BeTrue())
|
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() {
|
It("converts tags to numbers", func() {
|
||||||
Expect(VersionTagToNumber('Q' + '1'<<8 + '2'<<16 + '3'<<24)).To(Equal(VersionNumber(123)))
|
Expect(VersionTagToNumber('Q' + '1'<<8 + '2'<<16 + '3'<<24)).To(Equal(VersionNumber(123)))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ func (s *server) handlePacket(pconn net.PacketConn, remoteAddr net.Addr, packet
|
|||||||
if len(packet) < protocol.ClientHelloMinimumSize+len(hdr.Raw) {
|
if len(packet) < protocol.ClientHelloMinimumSize+len(hdr.Raw) {
|
||||||
return errors.New("dropping small packet with unknown version")
|
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)
|
_, err = pconn.WriteTo(wire.ComposeVersionNegotiation(hdr.ConnectionID, s.config.Versions), remoteAddr)
|
||||||
return err
|
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")
|
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
|
var handshakeChan <-chan handshakeEvent
|
||||||
session, handshakeChan, err = s.newSession(
|
session, handshakeChan, err = s.newSession(
|
||||||
&conn{pconn: pconn, currentAddr: remoteAddr},
|
&conn{pconn: pconn, currentAddr: remoteAddr},
|
||||||
|
|||||||
Reference in New Issue
Block a user