uquic/qlog/tracer.go
2024-03-09 19:32:15 +09:30

38 lines
922 B
Go

package qlog
import (
"io"
"net"
"time"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/logging"
)
func NewTracer(w io.WriteCloser) *logging.Tracer {
tr := &trace{
VantagePoint: vantagePoint{Type: "transport"},
CommonFields: commonFields{ReferenceTime: time.Now()},
}
wr := *newWriter(w, tr)
go wr.Run()
return &logging.Tracer{
SentPacket: nil,
SentVersionNegotiationPacket: nil,
DroppedPacket: func(addr net.Addr, p logging.PacketType, count logging.ByteCount, reason logging.PacketDropReason) {
wr.RecordEvent(time.Now(), eventPacketDropped{
PacketType: p,
PacketNumber: protocol.InvalidPacketNumber,
PacketSize: count,
Trigger: packetDropReason(reason),
})
},
Debug: func(name, msg string) {
wr.RecordEvent(time.Now(), &eventGeneric{
name: name,
msg: msg,
})
},
Close: func() { wr.Close() },
}
}