mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
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: 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() },
|
|
}
|
|
}
|