Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example: remove -qlog flag in favor of QLOGDIR #4243

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
example: remove -qlog flag in favor of QLOGDIR
  • Loading branch information
marten-seemann committed Jan 13, 2024
commit 6cd02a56302c5230ecfab963191bd835a2d05742
22 changes: 3 additions & 19 deletions example/client/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package main

import (
"bufio"
"bytes"
"context"
"crypto/tls"
"crypto/x509"
"flag"
"fmt"
"io"
"log"
"net/http"
Expand All @@ -17,16 +14,13 @@ import (
"github.com/quic-go/quic-go"
"github.com/quic-go/quic-go/http3"
"github.com/quic-go/quic-go/internal/testdata"
"github.com/quic-go/quic-go/internal/utils"
"github.com/quic-go/quic-go/logging"
"github.com/quic-go/quic-go/qlog"
)

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")
enableQlog := flag.Bool("qlog", false, "output a qlog (in the same directory)")
flag.Parse()
urls := flag.Args()

Expand All @@ -46,25 +40,15 @@ func main() {
}
testdata.AddRootCA(pool)

var qconf quic.Config
if *enableQlog {
qconf.Tracer = func(ctx context.Context, p logging.Perspective, connID quic.ConnectionID) *logging.ConnectionTracer {
filename := fmt.Sprintf("client_%s.qlog", connID)
f, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
log.Printf("Creating qlog file %s.\n", filename)
return qlog.NewConnectionTracer(utils.NewBufferedWriteCloser(bufio.NewWriter(f), f), p, connID)
}
}
roundTripper := &http3.RoundTripper{
TLSClientConfig: &tls.Config{
RootCAs: pool,
InsecureSkipVerify: *insecure,
KeyLogWriter: keyLog,
},
QuicConfig: &qconf,
QuicConfig: &quic.Config{
Tracer: qlog.DefaultTracer,
},
}
defer roundTripper.Close()
hclient := &http.Client{
Expand Down
27 changes: 6 additions & 21 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"bufio"
"context"
"crypto/md5"
"errors"
"flag"
Expand All @@ -11,7 +9,6 @@ import (
"log"
"mime/multipart"
"net/http"
"os"
"strconv"
"strings"
"sync"
Expand All @@ -21,8 +18,6 @@ import (
"github.com/quic-go/quic-go"
"github.com/quic-go/quic-go/http3"
"github.com/quic-go/quic-go/internal/testdata"
"github.com/quic-go/quic-go/internal/utils"
"github.com/quic-go/quic-go/logging"
"github.com/quic-go/quic-go/qlog"
)

Expand Down Expand Up @@ -145,26 +140,13 @@ func main() {
tcp := flag.Bool("tcp", false, "also listen on TCP")
key := flag.String("key", "", "TLS key (requires -cert option)")
cert := flag.String("cert", "", "TLS certificate (requires -key option)")
enableQlog := flag.Bool("qlog", false, "output a qlog (in the same directory)")
flag.Parse()

if len(bs) == 0 {
bs = binds{"localhost:6121"}
}

handler := setupHandler(*www)
quicConf := &quic.Config{}
if *enableQlog {
quicConf.Tracer = func(ctx context.Context, p logging.Perspective, connID quic.ConnectionID) *logging.ConnectionTracer {
filename := fmt.Sprintf("server_%s.qlog", connID)
f, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
log.Printf("Creating qlog file %s.\n", filename)
return qlog.NewConnectionTracer(utils.NewBufferedWriteCloser(bufio.NewWriter(f), f), p, connID)
}
}

var wg sync.WaitGroup
wg.Add(len(bs))
Expand All @@ -176,16 +158,19 @@ func main() {
certFile, keyFile = testdata.GetCertificatePaths()
}
for _, b := range bs {
fmt.Println("listening on", b)
bCap := b
go func() {
var err error
if *tcp {
err = http3.ListenAndServe(bCap, certFile, keyFile, handler)
} else {
server := http3.Server{
Handler: handler,
Addr: bCap,
QuicConfig: quicConf,
Handler: handler,
Addr: bCap,
QuicConfig: &quic.Config{
Tracer: qlog.DefaultTracer,
},
}
err = server.ListenAndServeTLS(certFile, keyFile)
}
Expand Down