mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 04:07:35 +03:00
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package qlog
|
|
|
|
import (
|
|
"io"
|
|
"net"
|
|
"time"
|
|
|
|
"github.com/refraction-networking/uquic/internal/protocol"
|
|
"github.com/refraction-networking/uquic/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: func(_ net.Addr, hdr *logging.Header, size logging.ByteCount, frames []logging.Frame) {
|
|
fs := make([]frame, 0, len(frames))
|
|
for _, f := range frames {
|
|
fs = append(fs, frame{Frame: f})
|
|
}
|
|
wr.RecordEvent(time.Now(), &eventPacketSent{
|
|
Header: transformHeader(hdr),
|
|
Length: size,
|
|
Frames: fs,
|
|
})
|
|
},
|
|
SentVersionNegotiationPacket: func(_ net.Addr, dest, src logging.ArbitraryLenConnectionID, versions []logging.VersionNumber) {
|
|
ver := make([]versionNumber, len(versions))
|
|
for i, v := range versions {
|
|
ver[i] = versionNumber(v)
|
|
}
|
|
wr.RecordEvent(time.Now(), &eventVersionNegotiationSent{
|
|
Header: packetHeaderVersionNegotiation{
|
|
SrcConnectionID: src,
|
|
DestConnectionID: dest,
|
|
},
|
|
SupportedVersions: ver,
|
|
})
|
|
},
|
|
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() },
|
|
}
|
|
}
|