diff --git a/.gitignore b/.gitignore index 5eb300d8..86317213 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ debug.test main mockgen_tmp.go *.qtr +*.qlog fuzzing/*/*.zip fuzzing/*/coverprofile diff --git a/example/client/main.go b/example/client/main.go index 8f2c6a3d..67d59a17 100644 --- a/example/client/main.go +++ b/example/client/main.go @@ -5,12 +5,14 @@ import ( "crypto/tls" "crypto/x509" "flag" + "fmt" "io" "log" "net/http" "os" "sync" + "github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go/http3" "github.com/lucas-clemente/quic-go/internal/testdata" "github.com/lucas-clemente/quic-go/internal/utils" @@ -21,6 +23,7 @@ func main() { quiet := flag.Bool("q", false, "don't print the data") keyLogFile := flag.String("keylog", "", "key log file") insecure := flag.Bool("insecure", false, "skip certificate verification") + qlog := flag.Bool("qlog", false, "output a qlog (in the same directory)") flag.Parse() urls := flag.Args() @@ -48,12 +51,26 @@ func main() { log.Fatal(err) } testdata.AddRootCA(pool) + + var qconf quic.Config + if *qlog { + qconf.GetLogWriter = func(connID []byte) io.WriteCloser { + filename := fmt.Sprintf("client_%x.qlog", connID) + f, err := os.Create(filename) + if err != nil { + log.Fatal(err) + } + log.Printf("Creating qlog file %s.\n", filename) + return f + } + } roundTripper := &http3.RoundTripper{ TLSClientConfig: &tls.Config{ RootCAs: pool, InsecureSkipVerify: *insecure, KeyLogWriter: keyLog, }, + QuicConfig: &qconf, } defer roundTripper.Close() hclient := &http.Client{ diff --git a/example/main.go b/example/main.go index 6ab47d08..60fe0d71 100644 --- a/example/main.go +++ b/example/main.go @@ -186,6 +186,7 @@ func main() { www := flag.String("www", "", "www data") tcp := flag.Bool("tcp", false, "also listen on TCP") trace := flag.Bool("trace", false, "enable quic-trace") + qlog := flag.Bool("qlog", false, "output a qlog (in the same directory)") flag.Parse() logger := utils.DefaultLogger @@ -202,9 +203,20 @@ func main() { } handler := setupHandler(*www, *trace) - var quicConf *quic.Config + quicConf := &quic.Config{} if *trace { - quicConf = &quic.Config{QuicTracer: tracer} + quicConf.QuicTracer = tracer + } + if *qlog { + quicConf.GetLogWriter = func(connID []byte) io.WriteCloser { + filename := fmt.Sprintf("server_%x.qlog", connID) + f, err := os.Create(filename) + if err != nil { + log.Fatal(err) + } + log.Printf("Creating qlog file %s.\n", filename) + return f + } } var wg sync.WaitGroup