export qlog files if the QLOGDIR env is set in interop client and server

This commit is contained in:
Marten Seemann
2020-02-12 11:55:23 +07:00
parent 89728126cc
commit 5aaab80698
3 changed files with 46 additions and 3 deletions

View File

@@ -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)
}

View File

@@ -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

View File

@@ -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
}