add a command line option to export qlogs from the integration tests

This commit is contained in:
Marten Seemann 2020-03-26 17:08:18 +07:00
parent 3ea4a66d63
commit a5b967a309
17 changed files with 137 additions and 105 deletions

View file

@ -26,7 +26,7 @@ var _ = Describe("Stream Cancelations", func() {
runServer := func() <-chan int32 { runServer := func() <-chan int32 {
numCanceledStreamsChan := make(chan int32) numCanceledStreamsChan := make(chan int32)
var err error var err error
server, err = quic.ListenAddr("localhost:0", getTLSConfig(), nil) server, err = quic.ListenAddr("localhost:0", getTLSConfig(), getQuicConfigForServer(nil))
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
var canceledCounter int32 var canceledCounter int32
@ -65,7 +65,7 @@ var _ = Describe("Stream Cancelations", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{MaxIncomingUniStreams: numStreams / 2}, getQuicConfigForClient(&quic.Config{MaxIncomingUniStreams: numStreams / 2}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -109,7 +109,7 @@ var _ = Describe("Stream Cancelations", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{MaxIncomingUniStreams: numStreams / 2}, getQuicConfigForClient(&quic.Config{MaxIncomingUniStreams: numStreams / 2}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -157,7 +157,7 @@ var _ = Describe("Stream Cancelations", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{MaxIncomingUniStreams: numStreams / 2}, getQuicConfigForClient(&quic.Config{MaxIncomingUniStreams: numStreams / 2}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -293,7 +293,7 @@ var _ = Describe("Stream Cancelations", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{MaxIncomingUniStreams: numStreams / 2}, getQuicConfigForClient(&quic.Config{MaxIncomingUniStreams: numStreams / 2}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -371,7 +371,7 @@ var _ = Describe("Stream Cancelations", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{MaxIncomingUniStreams: numStreams / 2}, getQuicConfigForClient(&quic.Config{MaxIncomingUniStreams: numStreams / 2}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -446,7 +446,7 @@ var _ = Describe("Stream Cancelations", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{MaxIncomingUniStreams: numStreams / 3}, getQuicConfigForClient(&quic.Config{MaxIncomingUniStreams: numStreams / 3}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -529,9 +529,7 @@ var _ = Describe("Stream Cancelations", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{ getQuicConfigForClient(&quic.Config{MaxIncomingUniStreams: 5}),
MaxIncomingUniStreams: 5,
},
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())

View file

@ -60,13 +60,13 @@ var _ = Describe("Connection ID lengths tests", func() {
} }
It("downloads a file using a 0-byte connection ID for the client", func() { It("downloads a file using a 0-byte connection ID for the client", func() {
serverConf := &quic.Config{ serverConf := getQuicConfigForServer(&quic.Config{
ConnectionIDLength: randomConnIDLen(), ConnectionIDLength: randomConnIDLen(),
Versions: []protocol.VersionNumber{protocol.VersionTLS}, Versions: []protocol.VersionNumber{protocol.VersionTLS},
} })
clientConf := &quic.Config{ clientConf := getQuicConfigForClient(&quic.Config{
Versions: []protocol.VersionNumber{protocol.VersionTLS}, Versions: []protocol.VersionNumber{protocol.VersionTLS},
} })
ln := runServer(serverConf) ln := runServer(serverConf)
defer ln.Close() defer ln.Close()
@ -74,14 +74,14 @@ var _ = Describe("Connection ID lengths tests", func() {
}) })
It("downloads a file when both client and server use a random connection ID length", func() { It("downloads a file when both client and server use a random connection ID length", func() {
serverConf := &quic.Config{ serverConf := getQuicConfigForServer(&quic.Config{
ConnectionIDLength: randomConnIDLen(), ConnectionIDLength: randomConnIDLen(),
Versions: []protocol.VersionNumber{protocol.VersionTLS}, Versions: []protocol.VersionNumber{protocol.VersionTLS},
} })
clientConf := &quic.Config{ clientConf := getQuicConfigForClient(&quic.Config{
ConnectionIDLength: randomConnIDLen(), ConnectionIDLength: randomConnIDLen(),
Versions: []protocol.VersionNumber{protocol.VersionTLS}, Versions: []protocol.VersionNumber{protocol.VersionTLS},
} })
ln := runServer(serverConf) ln := runServer(serverConf)
defer ln.Close() defer ln.Close()

View file

@ -31,9 +31,7 @@ var _ = Describe("Drop Tests", func() {
ln, err = quic.ListenAddr( ln, err = quic.ListenAddr(
"localhost:0", "localhost:0",
getTLSConfig(), getTLSConfig(),
&quic.Config{ getQuicConfigForServer(&quic.Config{Versions: []protocol.VersionNumber{version}}),
Versions: []protocol.VersionNumber{version},
},
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
serverPort := ln.Addr().(*net.UDPAddr).Port serverPort := ln.Addr().(*net.UDPAddr).Port
@ -106,7 +104,7 @@ var _ = Describe("Drop Tests", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForClient(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "") defer sess.CloseWithError(0, "")

View file

@ -25,7 +25,7 @@ var _ = Describe("early data", func() {
ln, err := quic.ListenAddrEarly( ln, err := quic.ListenAddrEarly(
"localhost:0", "localhost:0",
getTLSConfig(), getTLSConfig(),
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForServer(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
done := make(chan struct{}) done := make(chan struct{})
@ -56,7 +56,7 @@ var _ = Describe("early data", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForClient(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptUniStream(context.Background()) str, err := sess.AcceptUniStream(context.Background())

View file

@ -33,11 +33,11 @@ var _ = Describe("Handshake drop tests", func() {
const timeout = 10 * time.Minute const timeout = 10 * time.Minute
startListenerAndProxy := func(dropCallback quicproxy.DropCallback, doRetry bool, version protocol.VersionNumber) { startListenerAndProxy := func(dropCallback quicproxy.DropCallback, doRetry bool, version protocol.VersionNumber) {
conf := &quic.Config{ conf := getQuicConfigForServer(&quic.Config{
MaxIdleTimeout: timeout, MaxIdleTimeout: timeout,
HandshakeTimeout: timeout, HandshakeTimeout: timeout,
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
} })
if !doRetry { if !doRetry {
conf.AcceptToken = func(net.Addr, *quic.Token) bool { return true } conf.AcceptToken = func(net.Addr, *quic.Token) bool { return true }
} }
@ -79,11 +79,11 @@ var _ = Describe("Handshake drop tests", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{ getQuicConfigForClient(&quic.Config{
MaxIdleTimeout: timeout, MaxIdleTimeout: timeout,
HandshakeTimeout: timeout, HandshakeTimeout: timeout,
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenStream() str, err := sess.OpenStream()
@ -115,11 +115,11 @@ var _ = Describe("Handshake drop tests", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{ getQuicConfigForClient(&quic.Config{
MaxIdleTimeout: timeout, MaxIdleTimeout: timeout,
HandshakeTimeout: timeout, HandshakeTimeout: timeout,
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptStream(context.Background()) str, err := sess.AcceptStream(context.Background())
@ -149,11 +149,11 @@ var _ = Describe("Handshake drop tests", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{ getQuicConfigForClient(&quic.Config{
MaxIdleTimeout: timeout, MaxIdleTimeout: timeout,
HandshakeTimeout: timeout, HandshakeTimeout: timeout,
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
var serverSession quic.Session var serverSession quic.Session

View file

@ -29,7 +29,7 @@ var _ = Describe("Handshake RTT tests", func() {
BeforeEach(func() { BeforeEach(func() {
acceptStopped = make(chan struct{}) acceptStopped = make(chan struct{})
serverConfig = &quic.Config{} serverConfig = getQuicConfigForServer(nil)
serverTLSConfig = getTLSConfig() serverTLSConfig = getTLSConfig()
}) })
@ -79,9 +79,7 @@ var _ = Describe("Handshake RTT tests", func() {
} }
serverConfig.Versions = protocol.SupportedVersions[:1] serverConfig.Versions = protocol.SupportedVersions[:1]
runServerAndProxy() runServerAndProxy()
clientConfig := &quic.Config{ clientConfig := getQuicConfigForClient(&quic.Config{Versions: protocol.SupportedVersions[1:2]})
Versions: protocol.SupportedVersions[1:2],
}
_, err := quic.DialAddr( _, err := quic.DialAddr(
proxy.LocalAddr().String(), proxy.LocalAddr().String(),
getTLSClientConfig(), getTLSClientConfig(),
@ -96,7 +94,7 @@ var _ = Describe("Handshake RTT tests", func() {
BeforeEach(func() { BeforeEach(func() {
serverConfig.Versions = []protocol.VersionNumber{protocol.VersionTLS} serverConfig.Versions = []protocol.VersionNumber{protocol.VersionTLS}
clientConfig = &quic.Config{Versions: []protocol.VersionNumber{protocol.VersionTLS}} clientConfig = getQuicConfigForClient(&quic.Config{Versions: []protocol.VersionNumber{protocol.VersionTLS}})
clientConfig := getTLSClientConfig() clientConfig := getTLSClientConfig()
clientConfig.InsecureSkipVerify = true clientConfig.InsecureSkipVerify = true
}) })

View file

@ -57,7 +57,7 @@ var _ = Describe("Handshake tests", func() {
BeforeEach(func() { BeforeEach(func() {
server = nil server = nil
acceptStopped = make(chan struct{}) acceptStopped = make(chan struct{})
serverConfig = &quic.Config{} serverConfig = getQuicConfigForServer(nil)
tlsServerConf = getTLSConfig() tlsServerConf = getTLSConfig()
}) })
@ -121,13 +121,12 @@ var _ = Describe("Handshake tests", func() {
serverConfig.Versions = supportedVersions serverConfig.Versions = supportedVersions
server := runServer() server := runServer()
defer server.Close() defer server.Close()
conf := &quic.Config{
Versions: []protocol.VersionNumber{7, 8, 9, protocol.SupportedVersions[0], 10},
}
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),
conf, getQuicConfigForClient(&quic.Config{
Versions: []protocol.VersionNumber{7, 8, 9, protocol.SupportedVersions[0], 10},
}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(sess.(versioner).GetVersion()).To(Equal(protocol.SupportedVersions[0])) Expect(sess.(versioner).GetVersion()).To(Equal(protocol.SupportedVersions[0]))
@ -187,9 +186,7 @@ var _ = Describe("Handshake tests", func() {
BeforeEach(func() { BeforeEach(func() {
serverConfig.Versions = []protocol.VersionNumber{version} serverConfig.Versions = []protocol.VersionNumber{version}
clientConfig = &quic.Config{ clientConfig = getQuicConfigForClient(&quic.Config{Versions: []protocol.VersionNumber{version}})
Versions: []protocol.VersionNumber{version},
}
}) })
JustBeforeEach(func() { JustBeforeEach(func() {
@ -421,7 +418,7 @@ var _ = Describe("Handshake tests", func() {
gets := make(chan string, 100) gets := make(chan string, 100)
puts := make(chan string, 100) puts := make(chan string, 100)
tokenStore := newTokenStore(gets, puts) tokenStore := newTokenStore(gets, puts)
quicConf := &quic.Config{TokenStore: tokenStore} quicConf := getQuicConfigForClient(&quic.Config{TokenStore: tokenStore})
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),

View file

@ -76,7 +76,7 @@ var _ = Describe("HTTP tests", func() {
Handler: mux, Handler: mux,
TLSConfig: testdata.GetTLSConfig(), TLSConfig: testdata.GetTLSConfig(),
}, },
QuicConfig: &quic.Config{Versions: versions}, QuicConfig: getQuicConfigForServer(&quic.Config{Versions: versions}),
} }
addr, err := net.ResolveUDPAddr("udp", "0.0.0.0:0") addr, err := net.ResolveUDPAddr("udp", "0.0.0.0:0")
@ -110,10 +110,10 @@ var _ = Describe("HTTP tests", func() {
RootCAs: testdata.GetRootCA(), RootCAs: testdata.GetRootCA(),
}, },
DisableCompression: true, DisableCompression: true,
QuicConfig: &quic.Config{ QuicConfig: getQuicConfigForClient(&quic.Config{
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
MaxIdleTimeout: 10 * time.Second, MaxIdleTimeout: 10 * time.Second,
}, }),
}, },
} }
}) })

View file

@ -63,10 +63,10 @@ var _ = Describe("MITM test", func() {
} }
BeforeEach(func() { BeforeEach(func() {
serverConfig = &quic.Config{ serverConfig = getQuicConfigForServer(&quic.Config{
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
ConnectionIDLength: connIDLen, ConnectionIDLength: connIDLen,
} })
addr, err := net.ResolveUDPAddr("udp", "localhost:0") addr, err := net.ResolveUDPAddr("udp", "localhost:0")
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
clientConn, err = net.ListenUDP("udp", addr) clientConn, err = net.ListenUDP("udp", addr)
@ -128,10 +128,10 @@ var _ = Describe("MITM test", func() {
raddr, raddr,
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{ getQuicConfigForClient(&quic.Config{
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
ConnectionIDLength: connIDLen, ConnectionIDLength: connIDLen,
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptUniStream(context.Background()) str, err := sess.AcceptUniStream(context.Background())
@ -174,10 +174,10 @@ var _ = Describe("MITM test", func() {
raddr, raddr,
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{ getQuicConfigForClient(&quic.Config{
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
ConnectionIDLength: connIDLen, ConnectionIDLength: connIDLen,
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptUniStream(context.Background()) str, err := sess.AcceptUniStream(context.Background())
@ -335,11 +335,11 @@ var _ = Describe("MITM test", func() {
raddr, raddr,
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{ getQuicConfigForClient(&quic.Config{
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
ConnectionIDLength: connIDLen, ConnectionIDLength: connIDLen,
HandshakeTimeout: 2 * time.Second, HandshakeTimeout: 2 * time.Second,
}, }),
) )
return err return err
} }

View file

@ -46,7 +46,7 @@ var _ = Describe("Multiplexing", func() {
addr, addr,
fmt.Sprintf("localhost:%d", addr.(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", addr.(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForClient(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "") defer sess.CloseWithError(0, "")
@ -62,7 +62,7 @@ var _ = Describe("Multiplexing", func() {
ln, err := quic.ListenAddr( ln, err := quic.ListenAddr(
"localhost:0", "localhost:0",
getTLSConfig(), getTLSConfig(),
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForServer(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
return ln return ln
@ -145,7 +145,7 @@ var _ = Describe("Multiplexing", func() {
server, err := quic.Listen( server, err := quic.Listen(
conn, conn,
getTLSConfig(), getTLSConfig(),
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForServer(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
runServer(server) runServer(server)
@ -181,7 +181,7 @@ var _ = Describe("Multiplexing", func() {
server1, err := quic.Listen( server1, err := quic.Listen(
conn1, conn1,
getTLSConfig(), getTLSConfig(),
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForServer(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
runServer(server1) runServer(server1)
@ -190,7 +190,7 @@ var _ = Describe("Multiplexing", func() {
server2, err := quic.Listen( server2, err := quic.Listen(
conn2, conn2,
getTLSConfig(), getTLSConfig(),
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForServer(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
runServer(server2) runServer(server2)

View file

@ -23,9 +23,7 @@ var _ = Describe("non-zero RTT", func() {
ln, err := quic.ListenAddr( ln, err := quic.ListenAddr(
"localhost:0", "localhost:0",
getTLSConfig(), getTLSConfig(),
&quic.Config{ getQuicConfigForServer(&quic.Config{Versions: []protocol.VersionNumber{version}}),
Versions: []protocol.VersionNumber{version},
},
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
go func() { go func() {
@ -45,7 +43,7 @@ var _ = Describe("non-zero RTT", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", port), fmt.Sprintf("localhost:%d", port),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForClient(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptStream(context.Background()) str, err := sess.AcceptStream(context.Background())
@ -81,7 +79,7 @@ var _ = Describe("non-zero RTT", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForClient(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptStream(context.Background()) str, err := sess.AcceptStream(context.Background())

View file

@ -1,15 +1,20 @@
package self_test package self_test
import ( import (
"bufio"
"bytes" "bytes"
"crypto/tls" "crypto/tls"
"flag" "flag"
"fmt"
"io"
"log" "log"
"math/rand" "math/rand"
"os" "os"
"sync" "sync"
"testing" "testing"
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/internal/testdata" "github.com/lucas-clemente/quic-go/internal/testdata"
"github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/utils"
@ -87,12 +92,42 @@ var (
logFileName string // the log file set in the ginkgo flags logFileName string // the log file set in the ginkgo flags
logBufOnce sync.Once logBufOnce sync.Once
logBuf *syncedBuffer logBuf *syncedBuffer
enableQlog bool
) )
// read the logfile command line flag // read the logfile command line flag
// to set call ginkgo -- -logfile=log.txt // to set call ginkgo -- -logfile=log.txt
func init() { func init() {
flag.StringVar(&logFileName, "logfile", "", "log file") flag.StringVar(&logFileName, "logfile", "", "log file")
flag.BoolVar(&enableQlog, "qlog", false, "enable qlog")
}
func getQuicConfigForClient(conf *quic.Config) *quic.Config {
return getQuicConfigForRole("client", conf)
}
func getQuicConfigForServer(conf *quic.Config) *quic.Config {
return getQuicConfigForRole("server", conf)
}
func getQuicConfigForRole(role string, conf *quic.Config) *quic.Config {
if conf == nil {
conf = &quic.Config{}
} else {
conf = conf.Clone()
}
if !enableQlog {
return conf
}
conf.GetLogWriter = func(connectionID []byte) io.WriteCloser {
filename := fmt.Sprintf("log_%x_%s.qlog", connectionID, role)
fmt.Fprintf(GinkgoWriter, "Creating %s.\n", filename)
f, err := os.Create(filename)
Expect(err).ToNot(HaveOccurred())
bw := bufio.NewWriter(f)
return utils.NewBufferedWriteCloser(bw, f)
}
return conf
} }
var _ = BeforeEach(func() { var _ = BeforeEach(func() {

View file

@ -24,7 +24,7 @@ var _ = Describe("Stateless Resets", func() {
It(fmt.Sprintf("sends and recognizes stateless resets, for %d byte connection IDs", connIDLen), func() { It(fmt.Sprintf("sends and recognizes stateless resets, for %d byte connection IDs", connIDLen), func() {
statelessResetKey := make([]byte, 32) statelessResetKey := make([]byte, 32)
rand.Read(statelessResetKey) rand.Read(statelessResetKey)
serverConfig := &quic.Config{StatelessResetKey: statelessResetKey} serverConfig := getQuicConfigForServer(&quic.Config{StatelessResetKey: statelessResetKey})
ln, err := quic.ListenAddr("localhost:0", getTLSConfig(), serverConfig) ln, err := quic.ListenAddr("localhost:0", getTLSConfig(), serverConfig)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -58,10 +58,10 @@ var _ = Describe("Stateless Resets", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{ getQuicConfigForClient(&quic.Config{
ConnectionIDLength: connIDLen, ConnectionIDLength: connIDLen,
MaxIdleTimeout: 2 * time.Second, MaxIdleTimeout: 2 * time.Second,
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptStream(context.Background()) str, err := sess.AcceptStream(context.Background())

View file

@ -33,7 +33,7 @@ var _ = Describe("Bidirectional streams", func() {
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
MaxIncomingStreams: 0, MaxIncomingStreams: 0,
} }
server, err = quic.ListenAddr("localhost:0", getTLSConfig(), qconf) server, err = quic.ListenAddr("localhost:0", getTLSConfig(), getQuicConfigForServer(qconf))
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
serverAddr = fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port) serverAddr = fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port)
}) })
@ -100,7 +100,7 @@ var _ = Describe("Bidirectional streams", func() {
client, err := quic.DialAddr( client, err := quic.DialAddr(
serverAddr, serverAddr,
getTLSClientConfig(), getTLSClientConfig(),
qconf, getQuicConfigForClient(qconf),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
runSendingPeer(client) runSendingPeer(client)
@ -118,7 +118,7 @@ var _ = Describe("Bidirectional streams", func() {
client, err := quic.DialAddr( client, err := quic.DialAddr(
serverAddr, serverAddr,
getTLSClientConfig(), getTLSClientConfig(),
qconf, getQuicConfigForClient(qconf),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
runReceivingPeer(client) runReceivingPeer(client)
@ -145,7 +145,7 @@ var _ = Describe("Bidirectional streams", func() {
client, err := quic.DialAddr( client, err := quic.DialAddr(
serverAddr, serverAddr,
getTLSClientConfig(), getTLSClientConfig(),
qconf, getQuicConfigForClient(qconf),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
done2 := make(chan struct{}) done2 := make(chan struct{})

View file

@ -29,7 +29,7 @@ var _ = Describe("Timeout tests", func() {
_, err := quic.DialAddr( _, err := quic.DialAddr(
"localhost:12345", "localhost:12345",
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{HandshakeTimeout: 10 * time.Millisecond}, getQuicConfigForClient(&quic.Config{HandshakeTimeout: 10 * time.Millisecond}),
) )
errChan <- err errChan <- err
}() }()
@ -47,7 +47,7 @@ var _ = Describe("Timeout tests", func() {
ctx, ctx,
"localhost:12345", "localhost:12345",
getTLSClientConfig(), getTLSClientConfig(),
nil, getQuicConfigForClient(nil),
) )
errChan <- err errChan <- err
}() }()
@ -63,7 +63,7 @@ var _ = Describe("Timeout tests", func() {
server, err := quic.ListenAddr( server, err := quic.ListenAddr(
"localhost:0", "localhost:0",
getTLSConfig(), getTLSConfig(),
nil, getQuicConfigForServer(nil),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer server.Close() defer server.Close()
@ -92,7 +92,7 @@ var _ = Describe("Timeout tests", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{MaxIdleTimeout: idleTimeout}, getQuicConfigForClient(&quic.Config{MaxIdleTimeout: idleTimeout}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
strIn, err := sess.AcceptStream(context.Background()) strIn, err := sess.AcceptStream(context.Background())
@ -139,7 +139,11 @@ var _ = Describe("Timeout tests", func() {
}) })
It("times out after inactivity", func() { It("times out after inactivity", func() {
server, err := quic.ListenAddr("localhost:0", getTLSConfig(), nil) server, err := quic.ListenAddr(
"localhost:0",
getTLSConfig(),
getQuicConfigForServer(nil),
)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer server.Close() defer server.Close()
@ -155,7 +159,7 @@ var _ = Describe("Timeout tests", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{MaxIdleTimeout: idleTimeout}, getQuicConfigForClient(&quic.Config{MaxIdleTimeout: idleTimeout}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
startTime := time.Now() startTime := time.Now()
@ -180,7 +184,11 @@ var _ = Describe("Timeout tests", func() {
}) })
It("times out after sending a packet", func() { It("times out after sending a packet", func() {
server, err := quic.ListenAddr("localhost:0", getTLSConfig(), nil) server, err := quic.ListenAddr(
"localhost:0",
getTLSConfig(),
getQuicConfigForServer(nil),
)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer server.Close() defer server.Close()
@ -196,7 +204,7 @@ var _ = Describe("Timeout tests", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{MaxIdleTimeout: idleTimeout}, getQuicConfigForClient(&quic.Config{MaxIdleTimeout: idleTimeout}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -236,7 +244,7 @@ var _ = Describe("Timeout tests", func() {
server, err := quic.ListenAddr( server, err := quic.ListenAddr(
"localhost:0", "localhost:0",
getTLSConfig(), getTLSConfig(),
nil, getQuicConfigForServer(nil),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer server.Close() defer server.Close()
@ -264,10 +272,10 @@ var _ = Describe("Timeout tests", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(), getTLSClientConfig(),
&quic.Config{ getQuicConfigForClient(&quic.Config{
MaxIdleTimeout: idleTimeout, MaxIdleTimeout: idleTimeout,
KeepAlive: true, KeepAlive: true,
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())

View file

@ -26,7 +26,7 @@ var _ = Describe("Unidirectional Streams", func() {
BeforeEach(func() { BeforeEach(func() {
var err error var err error
qconf = &quic.Config{Versions: []protocol.VersionNumber{protocol.VersionTLS}} qconf = &quic.Config{Versions: []protocol.VersionNumber{protocol.VersionTLS}}
server, err = quic.ListenAddr("localhost:0", getTLSConfig(), qconf) server, err = quic.ListenAddr("localhost:0", getTLSConfig(), getQuicConfigForServer(qconf))
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
serverAddr = fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port) serverAddr = fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port)
}) })
@ -81,7 +81,7 @@ var _ = Describe("Unidirectional Streams", func() {
client, err := quic.DialAddr( client, err := quic.DialAddr(
serverAddr, serverAddr,
getTLSClientConfig(), getTLSClientConfig(),
qconf, getQuicConfigForClient(qconf),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
runSendingPeer(client) runSendingPeer(client)
@ -99,7 +99,7 @@ var _ = Describe("Unidirectional Streams", func() {
client, err := quic.DialAddr( client, err := quic.DialAddr(
serverAddr, serverAddr,
getTLSClientConfig(), getTLSClientConfig(),
qconf, getQuicConfigForClient(qconf),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
runReceivingPeer(client) runReceivingPeer(client)
@ -125,7 +125,7 @@ var _ = Describe("Unidirectional Streams", func() {
client, err := quic.DialAddr( client, err := quic.DialAddr(
serverAddr, serverAddr,
getTLSClientConfig(), getTLSClientConfig(),
qconf, getQuicConfigForClient(qconf),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
done2 := make(chan struct{}) done2 := make(chan struct{})

View file

@ -59,7 +59,7 @@ var _ = Describe("0-RTT", func() {
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxyPort), fmt.Sprintf("localhost:%d", proxyPort),
clientConf, clientConf,
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForClient(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Eventually(puts).Should(Receive()) Eventually(puts).Should(Receive())
@ -93,7 +93,7 @@ var _ = Describe("0-RTT", func() {
sess, err := quic.DialAddrEarly( sess, err := quic.DialAddrEarly(
fmt.Sprintf("localhost:%d", proxyPort), fmt.Sprintf("localhost:%d", proxyPort),
clientConf, clientConf,
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForClient(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenUniStream() str, err := sess.OpenUniStream()
@ -109,10 +109,10 @@ var _ = Describe("0-RTT", func() {
ln, err := quic.ListenAddrEarly( ln, err := quic.ListenAddrEarly(
"localhost:0", "localhost:0",
getTLSConfig(), getTLSConfig(),
&quic.Config{ getQuicConfigForServer(&quic.Config{
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true }, AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer ln.Close() defer ln.Close()
@ -171,7 +171,7 @@ var _ = Describe("0-RTT", func() {
sess, err := quic.DialAddrEarly( sess, err := quic.DialAddrEarly(
fmt.Sprintf("localhost:%d", proxy.LocalPort()), fmt.Sprintf("localhost:%d", proxy.LocalPort()),
clientConf, clientConf,
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForClient(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
sent0RTT := make(chan struct{}) sent0RTT := make(chan struct{})
@ -210,10 +210,10 @@ var _ = Describe("0-RTT", func() {
ln, err := quic.ListenAddrEarly( ln, err := quic.ListenAddrEarly(
"localhost:0", "localhost:0",
getTLSConfig(), getTLSConfig(),
&quic.Config{ getQuicConfigForServer(&quic.Config{
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true }, AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer ln.Close() defer ln.Close()
@ -264,7 +264,7 @@ var _ = Describe("0-RTT", func() {
ln, err := quic.ListenAddrEarly( ln, err := quic.ListenAddrEarly(
"localhost:0", "localhost:0",
getTLSConfig(), getTLSConfig(),
&quic.Config{Versions: []protocol.VersionNumber{version}}, getQuicConfigForServer(&quic.Config{Versions: []protocol.VersionNumber{version}}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer ln.Close() defer ln.Close()
@ -330,11 +330,11 @@ var _ = Describe("0-RTT", func() {
ln, err := quic.ListenAddrEarly( ln, err := quic.ListenAddrEarly(
"localhost:0", "localhost:0",
tlsConf, tlsConf,
&quic.Config{ getQuicConfigForServer(&quic.Config{
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true }, AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
MaxIncomingStreams: maxStreams, MaxIncomingStreams: maxStreams,
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -345,11 +345,11 @@ var _ = Describe("0-RTT", func() {
ln, err = quic.ListenAddrEarly( ln, err = quic.ListenAddrEarly(
"localhost:0", "localhost:0",
tlsConf, tlsConf,
&quic.Config{ getQuicConfigForServer(&quic.Config{
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true }, AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
MaxIncomingStreams: maxStreams + 1, MaxIncomingStreams: maxStreams + 1,
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port) proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)
@ -367,10 +367,10 @@ var _ = Describe("0-RTT", func() {
ln, err := quic.ListenAddrEarly( ln, err := quic.ListenAddrEarly(
"localhost:0", "localhost:0",
tlsConf, tlsConf,
&quic.Config{ getQuicConfigForServer(&quic.Config{
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true }, AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -383,10 +383,10 @@ var _ = Describe("0-RTT", func() {
ln, err = quic.ListenAddrEarly( ln, err = quic.ListenAddrEarly(
"localhost:0", "localhost:0",
tlsConf, tlsConf,
&quic.Config{ getQuicConfigForServer(&quic.Config{
Versions: []protocol.VersionNumber{version}, Versions: []protocol.VersionNumber{version},
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true }, AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
}, }),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port) proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)