From 55c05aceed4bcc47219058f8d777076bb844815c Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 2 Feb 2024 17:35:58 +0700 Subject: [PATCH] qlog: log sent packets outside of a QUIC connection --- qlog/tracer.go | 12 +++++++++++- qlog/tracer_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/qlog/tracer.go b/qlog/tracer.go index 708e80ab..562f7a26 100644 --- a/qlog/tracer.go +++ b/qlog/tracer.go @@ -17,7 +17,17 @@ func NewTracer(w io.WriteCloser) *logging.Tracer { wr := *newWriter(w, tr) go wr.Run() return &logging.Tracer{ - SentPacket: nil, + 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 { diff --git a/qlog/tracer_test.go b/qlog/tracer_test.go index 75d97059..8aa8faa5 100644 --- a/qlog/tracer_test.go +++ b/qlog/tracer_test.go @@ -47,6 +47,41 @@ var _ = Describe("Tracing", func() { }) Context("Events", func() { + It("records a sent long header packet, without an ACK", func() { + tracer.SentPacket( + nil, + &logging.Header{ + Type: protocol.PacketTypeHandshake, + DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}), + SrcConnectionID: protocol.ParseConnectionID([]byte{4, 3, 2, 1}), + Length: 1337, + Version: protocol.Version1, + }, + 1234, + []logging.Frame{ + &logging.MaxStreamDataFrame{StreamID: 42, MaximumStreamData: 987}, + &logging.StreamFrame{StreamID: 123, Offset: 1234, Length: 6, Fin: true}, + }, + ) + 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("raw")) + raw := ev["raw"].(map[string]interface{}) + Expect(raw).To(HaveKeyWithValue("length", float64(1234))) + Expect(ev).To(HaveKey("header")) + hdr := ev["header"].(map[string]interface{}) + Expect(hdr).To(HaveKeyWithValue("packet_type", "handshake")) + Expect(hdr).To(HaveKeyWithValue("scid", "04030201")) + Expect(ev).To(HaveKey("frames")) + frames := ev["frames"].([]interface{}) + Expect(frames).To(HaveLen(2)) + Expect(frames[0].(map[string]interface{})).To(HaveKeyWithValue("frame_type", "max_stream_data")) + Expect(frames[1].(map[string]interface{})).To(HaveKeyWithValue("frame_type", "stream")) + }) + It("records sending of a Version Negotiation packet", func() { tracer.SentVersionNegotiationPacket( nil,