Skip to content

Commit

Permalink
example: remove -qlog flag in favor of QLOGDIR (quic-go#4243)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored and Constantine Shablia committed Feb 1, 2024
1 parent 96b290f commit 90ba7ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 40 deletions.
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

0 comments on commit 90ba7ff

Please sign in to comment.