diff --git a/p2p/transport/quic/transport.go b/p2p/transport/quic/transport.go index 0b908db43..b22450107 100644 --- a/p2p/transport/quic/transport.go +++ b/p2p/transport/quic/transport.go @@ -10,6 +10,8 @@ import ( "sync" "time" + "github.com/libp2p/go-libp2p/p2p/transport/quicutils" + "golang.org/x/crypto/hkdf" "github.com/libp2p/go-libp2p/core/connmgr" @@ -201,7 +203,7 @@ func NewTransport(key ic.PrivKey, psk pnet.PSK, gater connmgr.ConnectionGater, r return nil, err } var tracers []quiclogging.Tracer - if qlogTracer != nil { + if qlogTracer := quicutils.QLOGTracer; qlogTracer != nil { tracers = append(tracers, qlogTracer) } if cfg.metrics { diff --git a/p2p/transport/quic/tracer.go b/p2p/transport/quicutils/tracer.go similarity index 90% rename from p2p/transport/quic/tracer.go rename to p2p/transport/quicutils/tracer.go index 50f429dca..272b1be29 100644 --- a/p2p/transport/quic/tracer.go +++ b/p2p/transport/quicutils/tracer.go @@ -1,4 +1,4 @@ -package libp2pquic +package quicutils import ( "bufio" @@ -7,17 +7,21 @@ import ( "os" "time" + golog "github.com/ipfs/go-log/v2" "github.com/klauspost/compress/zstd" - "github.com/lucas-clemente/quic-go/logging" "github.com/lucas-clemente/quic-go/qlog" ) -var qlogTracer logging.Tracer +var log = golog.Logger("quic-utils") + +// QLOGTracer holds a qlog tracer, if qlogging is enabled (enabled using the QLOGDIR environment variable). +// Otherwise it is nil. +var QLOGTracer logging.Tracer func init() { if qlogDir := os.Getenv("QLOGDIR"); len(qlogDir) > 0 { - qlogTracer = initQlogger(qlogDir) + QLOGTracer = initQlogger(qlogDir) } } diff --git a/p2p/transport/quic/tracer_test.go b/p2p/transport/quicutils/tracer_test.go similarity index 99% rename from p2p/transport/quic/tracer_test.go rename to p2p/transport/quicutils/tracer_test.go index c651032d0..0d095d342 100644 --- a/p2p/transport/quic/tracer_test.go +++ b/p2p/transport/quicutils/tracer_test.go @@ -1,4 +1,4 @@ -package libp2pquic +package quicutils import ( "bytes"