diff --git a/interop/client/main.go b/interop/client/main.go index 90c748d04..1f051f1ec 100644 --- a/interop/client/main.go +++ b/interop/client/main.go @@ -13,6 +13,7 @@ import ( "golang.org/x/sync/errgroup" + "github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go/http3" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/interop/http09" @@ -60,9 +61,18 @@ func runTestcase(testcase string) error { flag.Parse() urls := flag.Args() + getLogWriter, err := utils.GetQLOGWriter() + if err != nil { + return err + } + quicConf := &quic.Config{GetLogWriter: getLogWriter} + switch testcase { case "http3": - r := &http3.RoundTripper{TLSClientConfig: tlsConf} + r := &http3.RoundTripper{ + TLSClientConfig: tlsConf, + QuicConfig: quicConf, + } defer r.Close() return downloadFiles(r, urls) case "handshake", "transfer", "retry": @@ -76,7 +86,10 @@ func runTestcase(testcase string) error { return errUnsupported } - r := &http09.RoundTripper{TLSClientConfig: tlsConf} + r := &http09.RoundTripper{ + TLSClientConfig: tlsConf, + QuicConfig: quicConf, + } defer r.Close() return downloadFiles(r, urls) } diff --git a/interop/server/main.go b/interop/server/main.go index bdaee82d6..7f3484515 100644 --- a/interop/server/main.go +++ b/interop/server/main.go @@ -37,9 +37,15 @@ func main() { testcase := os.Getenv("TESTCASE") + getLogWriter, err := utils.GetQLOGWriter() + if err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } // a quic.Config that doesn't do a Retry quicConf := &quic.Config{ - AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true }, + AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true }, + GetLogWriter: getLogWriter, } tlsConf = testdata.GetTLSConfig() tlsConf.KeyLogWriter = keyLog diff --git a/interop/utils/logging.go b/interop/utils/logging.go index 11e4e897e..97eb297a6 100644 --- a/interop/utils/logging.go +++ b/interop/utils/logging.go @@ -1,8 +1,11 @@ package utils import ( + "fmt" "io" + "log" "os" + "strings" ) // GetSSLKeyLog creates a file for the TLS key log @@ -17,3 +20,24 @@ func GetSSLKeyLog() (io.WriteCloser, error) { } return f, nil } + +// GetQLOGWriter creates the QLOGDIR and returns the GetLogWriter callback +func GetQLOGWriter() (func(connID []byte) io.WriteCloser, error) { + qlogDir := os.Getenv("QLOGDIR") + if len(qlogDir) == 0 { + return nil, nil + } + if _, err := os.Stat(qlogDir); os.IsNotExist(err) { + if err := os.MkdirAll(qlogDir, 0666); err != nil { + return nil, fmt.Errorf("failed to create qlog dir %s: %s", qlogDir, err.Error()) + } + } + return func(connID []byte) io.WriteCloser { + path := fmt.Sprintf("%s/%x.qlog", strings.TrimRight(qlogDir, "/"), connID) + f, err := os.Create(path) + if err != nil { + log.Fatalf("Failed to create qlog file %s: %s", path, err.Error()) + } + return f + }, nil +}