mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
qlog: log sent Version Negotiation packets
This commit is contained in:
parent
3a7a53fdb9
commit
aff90a6ffa
3 changed files with 53 additions and 2 deletions
|
@ -233,6 +233,20 @@ func (e eventVersionNegotiationReceived) MarshalJSONObject(enc *gojay.Encoder) {
|
||||||
enc.ArrayKey("supported_versions", versions(e.SupportedVersions))
|
enc.ArrayKey("supported_versions", versions(e.SupportedVersions))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type eventVersionNegotiationSent struct {
|
||||||
|
Header packetHeaderVersionNegotiation
|
||||||
|
SupportedVersions []versionNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventVersionNegotiationSent) Category() category { return categoryTransport }
|
||||||
|
func (e eventVersionNegotiationSent) Name() string { return "packet_sent" }
|
||||||
|
func (e eventVersionNegotiationSent) IsNil() bool { return false }
|
||||||
|
|
||||||
|
func (e eventVersionNegotiationSent) MarshalJSONObject(enc *gojay.Encoder) {
|
||||||
|
enc.ObjectKey("header", e.Header)
|
||||||
|
enc.ArrayKey("supported_versions", versions(e.SupportedVersions))
|
||||||
|
}
|
||||||
|
|
||||||
type eventPacketBuffered struct {
|
type eventPacketBuffered struct {
|
||||||
PacketType logging.PacketType
|
PacketType logging.PacketType
|
||||||
PacketSize protocol.ByteCount
|
PacketSize protocol.ByteCount
|
||||||
|
|
|
@ -17,8 +17,20 @@ func NewTracer(w io.WriteCloser) *logging.Tracer {
|
||||||
wr := *newWriter(w, tr)
|
wr := *newWriter(w, tr)
|
||||||
go wr.Run()
|
go wr.Run()
|
||||||
return &logging.Tracer{
|
return &logging.Tracer{
|
||||||
SentPacket: nil,
|
SentPacket: nil,
|
||||||
SentVersionNegotiationPacket: 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) {
|
DroppedPacket: func(addr net.Addr, p logging.PacketType, count logging.ByteCount, reason logging.PacketDropReason) {
|
||||||
wr.RecordEvent(time.Now(), eventPacketDropped{
|
wr.RecordEvent(time.Now(), eventPacketDropped{
|
||||||
PacketType: p,
|
PacketType: p,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/quic-go/quic-go/internal/protocol"
|
||||||
"github.com/quic-go/quic-go/logging"
|
"github.com/quic-go/quic-go/logging"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
@ -46,6 +47,30 @@ var _ = Describe("Tracing", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("Events", func() {
|
Context("Events", func() {
|
||||||
|
It("records sending of a Version Negotiation packet", func() {
|
||||||
|
tracer.SentVersionNegotiationPacket(
|
||||||
|
nil,
|
||||||
|
protocol.ArbitraryLenConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
|
protocol.ArbitraryLenConnectionID{4, 3, 2, 1},
|
||||||
|
[]protocol.Version{0xdeadbeef, 0xdecafbad},
|
||||||
|
)
|
||||||
|
tracer.Close()
|
||||||
|
entry := exportAndParseSingle(buf)
|
||||||
|
Expect(entry.Time).To(BeTemporally("~", time.Now(), scaleDuration(10*time.Millisecond)))
|
||||||
|
Expect(entry.Name).To(Equal("transport:packet_sent"))
|
||||||
|
ev := entry.Event
|
||||||
|
Expect(ev).To(HaveKey("header"))
|
||||||
|
Expect(ev).ToNot(HaveKey("frames"))
|
||||||
|
Expect(ev).To(HaveKey("supported_versions"))
|
||||||
|
Expect(ev["supported_versions"].([]interface{})).To(Equal([]interface{}{"deadbeef", "decafbad"}))
|
||||||
|
header := ev["header"]
|
||||||
|
Expect(header).To(HaveKeyWithValue("packet_type", "version_negotiation"))
|
||||||
|
Expect(header).ToNot(HaveKey("packet_number"))
|
||||||
|
Expect(header).ToNot(HaveKey("version"))
|
||||||
|
Expect(header).To(HaveKeyWithValue("dcid", "0102030405060708"))
|
||||||
|
Expect(header).To(HaveKeyWithValue("scid", "04030201"))
|
||||||
|
})
|
||||||
|
|
||||||
It("records dropped packets", func() {
|
It("records dropped packets", func() {
|
||||||
addr := net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 1234}
|
addr := net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 1234}
|
||||||
tracer.DroppedPacket(&addr, logging.PacketTypeInitial, 1337, logging.PacketDropPayloadDecryptError)
|
tracer.DroppedPacket(&addr, logging.PacketTypeInitial, 1337, logging.PacketDropPayloadDecryptError)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue