Skip to content

Commit

Permalink
qlog: log sent packets outside of a QUIC connection
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Mar 9, 2024
1 parent aff90a6 commit 55c05ac
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
12 changes: 11 additions & 1 deletion qlog/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 35 additions & 0 deletions qlog/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 55c05ac

Please sign in to comment.