From 24be84cd00406e10f3418dd44efcf0d7ca5a03a1 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 30 Aug 2022 15:59:55 +0300 Subject: [PATCH] introduce separate tracing calls for sent long and short header packets --- connection.go | 16 +++++++++++- connection_test.go | 27 ++++++++++++--------- integrationtests/self/key_update_test.go | 7 ++---- integrationtests/self/self_suite_test.go | 16 ++++++------ integrationtests/self/timeout_test.go | 2 +- internal/mocks/logging/connection_tracer.go | 24 +++++++++++++----- logging/interface.go | 3 ++- logging/mock_connection_tracer_test.go | 24 +++++++++++++----- logging/multiplex.go | 10 ++++++-- logging/multiplex_test.go | 17 ++++++++++--- logging/null_tracer.go | 11 +++++---- qlog/event.go | 2 +- qlog/qlog.go | 15 +++++++++--- qlog/qlog_test.go | 14 +++++------ 14 files changed, 127 insertions(+), 61 deletions(-) diff --git a/connection.go b/connection.go index 4256fbdf..80797814 100644 --- a/connection.go +++ b/connection.go @@ -1971,7 +1971,21 @@ func (s *connection) logPacketContents(p *packetContents) { if p.ack != nil { ack = logutils.ConvertAckFrame(p.ack) } - s.tracer.SentPacket(p.header, p.length, ack, frames) + if p.header.IsLongHeader { + s.tracer.SentLongHeaderPacket(p.header, p.length, ack, frames) + } else { + s.tracer.SentShortHeaderPacket( + &logging.ShortHeader{ + DestConnectionID: p.header.DestConnectionID, + PacketNumber: p.header.PacketNumber, + PacketNumberLen: p.header.PacketNumberLen, + KeyPhase: p.header.KeyPhase, + }, + p.length, + ack, + frames, + ) + } } // quic-go logging diff --git a/connection_test.go b/connection_test.go index d080ae7e..94ea4980 100644 --- a/connection_test.go +++ b/connection_test.go @@ -605,7 +605,7 @@ var _ = Describe("Connection", func() { sph.EXPECT().HasPacingBudget().Return(true).AnyTimes() // only expect a single SentPacket() call sph.EXPECT().SentPacket(gomock.Any()) - tracer.EXPECT().SentPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) + tracer.EXPECT().SentShortHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) tracer.EXPECT().ClosedConnection(gomock.Any()) tracer.EXPECT().Close() streamManager.EXPECT().CloseWithError(gomock.Any()) @@ -1245,7 +1245,12 @@ var _ = Describe("Connection", func() { sent := make(chan struct{}) sender.EXPECT().WouldBlock().AnyTimes() sender.EXPECT().Send(gomock.Any()).Do(func(packet *packetBuffer) { close(sent) }) - tracer.EXPECT().SentPacket(p.header, p.buffer.Len(), nil, []logging.Frame{}) + tracer.EXPECT().SentShortHeaderPacket(&logging.ShortHeader{ + DestConnectionID: p.header.DestConnectionID, + PacketNumber: p.header.PacketNumber, + PacketNumberLen: p.header.PacketNumberLen, + KeyPhase: p.header.KeyPhase, + }, p.buffer.Len(), nil, []logging.Frame{}) conn.scheduleSending() Eventually(sent).Should(BeClosed()) }) @@ -1291,7 +1296,7 @@ var _ = Describe("Connection", func() { runConn() sent := make(chan struct{}) sender.EXPECT().Send(gomock.Any()).Do(func(packet *packetBuffer) { close(sent) }) - tracer.EXPECT().SentPacket(p.header, p.length, nil, []logging.Frame{}) + tracer.EXPECT().SentShortHeaderPacket(gomock.Any(), p.length, nil, []logging.Frame{}) conn.scheduleSending() Eventually(sent).Should(BeClosed()) frames, _ := conn.framer.AppendControlFrames(nil, 1000) @@ -1347,7 +1352,7 @@ var _ = Describe("Connection", func() { runConn() sent := make(chan struct{}) sender.EXPECT().Send(gomock.Any()).Do(func(packet *packetBuffer) { close(sent) }) - tracer.EXPECT().SentPacket(p.packets[0].header, p.packets[0].length, gomock.Any(), gomock.Any()) + tracer.EXPECT().SentShortHeaderPacket(gomock.Any(), p.packets[0].length, gomock.Any(), gomock.Any()) conn.scheduleSending() Eventually(sent).Should(BeClosed()) }) @@ -1368,7 +1373,7 @@ var _ = Describe("Connection", func() { runConn() sent := make(chan struct{}) sender.EXPECT().Send(gomock.Any()).Do(func(packet *packetBuffer) { close(sent) }) - tracer.EXPECT().SentPacket(p.packets[0].header, p.packets[0].length, gomock.Any(), gomock.Any()) + tracer.EXPECT().SentShortHeaderPacket(gomock.Any(), p.packets[0].length, gomock.Any(), gomock.Any()) conn.scheduleSending() Eventually(sent).Should(BeClosed()) // We're using a mock packet packer in this test. @@ -1386,7 +1391,7 @@ var _ = Describe("Connection", func() { ) BeforeEach(func() { - tracer.EXPECT().SentPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() + tracer.EXPECT().SentShortHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() sph = mockackhandler.NewMockSentPacketHandler(mockCtrl) sph.EXPECT().GetLossDetectionTimeout().AnyTimes() conn.handshakeConfirmed = true @@ -1705,7 +1710,7 @@ var _ = Describe("Connection", func() { // only EXPECT calls after scheduleSending is called written := make(chan struct{}) sender.EXPECT().Send(gomock.Any()).Do(func(*packetBuffer) { close(written) }) - tracer.EXPECT().SentPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() + tracer.EXPECT().SentShortHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() conn.scheduleSending() Eventually(written).Should(BeClosed()) }) @@ -1729,7 +1734,7 @@ var _ = Describe("Connection", func() { written := make(chan struct{}) sender.EXPECT().Send(gomock.Any()).Do(func(*packetBuffer) { close(written) }) - tracer.EXPECT().SentPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() + tracer.EXPECT().SentShortHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() go func() { defer GinkgoRecover() cryptoSetup.EXPECT().RunHandshake().MaxTimes(1) @@ -1789,10 +1794,10 @@ var _ = Describe("Connection", func() { }), ) gomock.InOrder( - tracer.EXPECT().SentPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Do(func(hdr *wire.ExtendedHeader, _ protocol.ByteCount, _ *wire.AckFrame, _ []logging.Frame) { + tracer.EXPECT().SentLongHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Do(func(hdr *wire.ExtendedHeader, _ protocol.ByteCount, _ *wire.AckFrame, _ []logging.Frame) { Expect(hdr.Type).To(Equal(protocol.PacketTypeInitial)) }), - tracer.EXPECT().SentPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Do(func(hdr *wire.ExtendedHeader, _ protocol.ByteCount, _ *wire.AckFrame, _ []logging.Frame) { + tracer.EXPECT().SentLongHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Do(func(hdr *wire.ExtendedHeader, _ protocol.ByteCount, _ *wire.AckFrame, _ []logging.Frame) { Expect(hdr.Type).To(Equal(protocol.PacketTypeHandshake)) }), ) @@ -1931,7 +1936,7 @@ var _ = Describe("Connection", func() { sph.EXPECT().SetHandshakeConfirmed() sph.EXPECT().SentPacket(gomock.Any()) mconn.EXPECT().Write(gomock.Any()) - tracer.EXPECT().SentPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) + tracer.EXPECT().SentShortHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) conn.sentPacketHandler = sph done := make(chan struct{}) connRunner.EXPECT().Retire(clientDestConnID) diff --git a/integrationtests/self/key_update_test.go b/integrationtests/self/key_update_test.go index 762aa86c..90a3d53f 100644 --- a/integrationtests/self/key_update_test.go +++ b/integrationtests/self/key_update_test.go @@ -16,16 +16,13 @@ import ( ) var ( - sentHeaders []*logging.ExtendedHeader + sentHeaders []*logging.ShortHeader receivedHeaders []*logging.ShortHeader ) func countKeyPhases() (sent, received int) { lastKeyPhase := protocol.KeyPhaseOne for _, hdr := range sentHeaders { - if hdr.IsLongHeader { - continue - } if hdr.KeyPhase != lastKeyPhase { sent++ lastKeyPhase = hdr.KeyPhase @@ -45,7 +42,7 @@ type keyUpdateConnTracer struct { logging.NullConnectionTracer } -func (t *keyUpdateConnTracer) SentPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, ack *logging.AckFrame, frames []logging.Frame) { +func (t *keyUpdateConnTracer) SentShortHeaderPacket(hdr *logging.ShortHeader, _ logging.ByteCount, _ *logging.AckFrame, _ []logging.Frame) { sentHeaders = append(sentHeaders, hdr) } diff --git a/integrationtests/self/self_suite_test.go b/integrationtests/self/self_suite_test.go index 692e50ae..287ab305 100644 --- a/integrationtests/self/self_suite_test.go +++ b/integrationtests/self/self_suite_test.go @@ -358,9 +358,9 @@ type shortHeaderPacket struct { type packetTracer struct { logging.NullConnectionTracer - closed chan struct{} - rcvdShortHdr []shortHeaderPacket - sent, rcvdLongHdr []packet + closed chan struct{} + sentShortHdr, rcvdShortHdr []shortHeaderPacket + rcvdLongHdr []packet } func newPacketTracer() *packetTracer { @@ -375,16 +375,18 @@ func (t *packetTracer) ReceivedShortHeaderPacket(hdr *logging.ShortHeader, _ log t.rcvdShortHdr = append(t.rcvdShortHdr, shortHeaderPacket{time: time.Now(), hdr: hdr, frames: frames}) } -func (t *packetTracer) SentPacket(hdr *logging.ExtendedHeader, _ logging.ByteCount, ack *wire.AckFrame, frames []logging.Frame) { +func (t *packetTracer) SentShortHeaderPacket(hdr *logging.ShortHeader, _ logging.ByteCount, ack *wire.AckFrame, frames []logging.Frame) { if ack != nil { frames = append(frames, ack) } - t.sent = append(t.sent, packet{time: time.Now(), hdr: hdr, frames: frames}) + t.sentShortHdr = append(t.sentShortHdr, shortHeaderPacket{time: time.Now(), hdr: hdr, frames: frames}) } + func (t *packetTracer) Close() { close(t.closed) } -func (t *packetTracer) getSentPackets() []packet { + +func (t *packetTracer) getSentShortHeaderPackets() []shortHeaderPacket { <-t.closed - return t.sent + return t.sentShortHdr } func (t *packetTracer) getRcvdLongHeaderPackets() []packet { diff --git a/integrationtests/self/timeout_test.go b/integrationtests/self/timeout_test.go index d678b00d..5198ee17 100644 --- a/integrationtests/self/timeout_test.go +++ b/integrationtests/self/timeout_test.go @@ -213,7 +213,7 @@ var _ = Describe("Timeout tests", func() { }() Eventually(done, 2*idleTimeout).Should(BeClosed()) var lastAckElicitingPacketSentAt time.Time - for _, p := range tr.getSentPackets() { + for _, p := range tr.getSentShortHeaderPackets() { var hasAckElicitingFrame bool for _, f := range p.frames { if _, ok := f.(*logging.AckFrame); ok { diff --git a/internal/mocks/logging/connection_tracer.go b/internal/mocks/logging/connection_tracer.go index a23b65eb..ad30fdf6 100644 --- a/internal/mocks/logging/connection_tracer.go +++ b/internal/mocks/logging/connection_tracer.go @@ -255,16 +255,28 @@ func (mr *MockConnectionTracerMockRecorder) RestoredTransportParameters(arg0 int return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RestoredTransportParameters", reflect.TypeOf((*MockConnectionTracer)(nil).RestoredTransportParameters), arg0) } -// SentPacket mocks base method. -func (m *MockConnectionTracer) SentPacket(arg0 *wire.ExtendedHeader, arg1 protocol.ByteCount, arg2 *wire.AckFrame, arg3 []logging.Frame) { +// SentLongHeaderPacket mocks base method. +func (m *MockConnectionTracer) SentLongHeaderPacket(arg0 *wire.ExtendedHeader, arg1 protocol.ByteCount, arg2 *wire.AckFrame, arg3 []logging.Frame) { m.ctrl.T.Helper() - m.ctrl.Call(m, "SentPacket", arg0, arg1, arg2, arg3) + m.ctrl.Call(m, "SentLongHeaderPacket", arg0, arg1, arg2, arg3) } -// SentPacket indicates an expected call of SentPacket. -func (mr *MockConnectionTracerMockRecorder) SentPacket(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +// SentLongHeaderPacket indicates an expected call of SentLongHeaderPacket. +func (mr *MockConnectionTracerMockRecorder) SentLongHeaderPacket(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SentPacket", reflect.TypeOf((*MockConnectionTracer)(nil).SentPacket), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SentLongHeaderPacket", reflect.TypeOf((*MockConnectionTracer)(nil).SentLongHeaderPacket), arg0, arg1, arg2, arg3) +} + +// SentShortHeaderPacket mocks base method. +func (m *MockConnectionTracer) SentShortHeaderPacket(arg0 *logging.ShortHeader, arg1 protocol.ByteCount, arg2 *wire.AckFrame, arg3 []logging.Frame) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SentShortHeaderPacket", arg0, arg1, arg2, arg3) +} + +// SentShortHeaderPacket indicates an expected call of SentShortHeaderPacket. +func (mr *MockConnectionTracerMockRecorder) SentShortHeaderPacket(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SentShortHeaderPacket", reflect.TypeOf((*MockConnectionTracer)(nil).SentShortHeaderPacket), arg0, arg1, arg2, arg3) } // SentTransportParameters mocks base method. diff --git a/logging/interface.go b/logging/interface.go index 9d086866..b68ab73c 100644 --- a/logging/interface.go +++ b/logging/interface.go @@ -121,7 +121,8 @@ type ConnectionTracer interface { SentTransportParameters(*TransportParameters) ReceivedTransportParameters(*TransportParameters) RestoredTransportParameters(parameters *TransportParameters) // for 0-RTT - SentPacket(hdr *ExtendedHeader, size ByteCount, ack *AckFrame, frames []Frame) + SentLongHeaderPacket(hdr *ExtendedHeader, size ByteCount, ack *AckFrame, frames []Frame) + SentShortHeaderPacket(hdr *ShortHeader, size ByteCount, ack *AckFrame, frames []Frame) ReceivedVersionNegotiationPacket(dest, src ArbitraryLenConnectionID, _ []VersionNumber) ReceivedRetry(*Header) ReceivedLongHeaderPacket(hdr *ExtendedHeader, size ByteCount, frames []Frame) diff --git a/logging/mock_connection_tracer_test.go b/logging/mock_connection_tracer_test.go index 04eb777a..da94218f 100644 --- a/logging/mock_connection_tracer_test.go +++ b/logging/mock_connection_tracer_test.go @@ -254,16 +254,28 @@ func (mr *MockConnectionTracerMockRecorder) RestoredTransportParameters(arg0 int return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RestoredTransportParameters", reflect.TypeOf((*MockConnectionTracer)(nil).RestoredTransportParameters), arg0) } -// SentPacket mocks base method. -func (m *MockConnectionTracer) SentPacket(arg0 *wire.ExtendedHeader, arg1 protocol.ByteCount, arg2 *wire.AckFrame, arg3 []Frame) { +// SentLongHeaderPacket mocks base method. +func (m *MockConnectionTracer) SentLongHeaderPacket(arg0 *wire.ExtendedHeader, arg1 protocol.ByteCount, arg2 *wire.AckFrame, arg3 []Frame) { m.ctrl.T.Helper() - m.ctrl.Call(m, "SentPacket", arg0, arg1, arg2, arg3) + m.ctrl.Call(m, "SentLongHeaderPacket", arg0, arg1, arg2, arg3) } -// SentPacket indicates an expected call of SentPacket. -func (mr *MockConnectionTracerMockRecorder) SentPacket(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +// SentLongHeaderPacket indicates an expected call of SentLongHeaderPacket. +func (mr *MockConnectionTracerMockRecorder) SentLongHeaderPacket(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SentPacket", reflect.TypeOf((*MockConnectionTracer)(nil).SentPacket), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SentLongHeaderPacket", reflect.TypeOf((*MockConnectionTracer)(nil).SentLongHeaderPacket), arg0, arg1, arg2, arg3) +} + +// SentShortHeaderPacket mocks base method. +func (m *MockConnectionTracer) SentShortHeaderPacket(arg0 *ShortHeader, arg1 protocol.ByteCount, arg2 *wire.AckFrame, arg3 []Frame) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SentShortHeaderPacket", arg0, arg1, arg2, arg3) +} + +// SentShortHeaderPacket indicates an expected call of SentShortHeaderPacket. +func (mr *MockConnectionTracerMockRecorder) SentShortHeaderPacket(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SentShortHeaderPacket", reflect.TypeOf((*MockConnectionTracer)(nil).SentShortHeaderPacket), arg0, arg1, arg2, arg3) } // SentTransportParameters mocks base method. diff --git a/logging/multiplex.go b/logging/multiplex.go index d7166f1a..8e85db49 100644 --- a/logging/multiplex.go +++ b/logging/multiplex.go @@ -104,9 +104,15 @@ func (m *connTracerMultiplexer) RestoredTransportParameters(tp *TransportParamet } } -func (m *connTracerMultiplexer) SentPacket(hdr *ExtendedHeader, size ByteCount, ack *AckFrame, frames []Frame) { +func (m *connTracerMultiplexer) SentLongHeaderPacket(hdr *ExtendedHeader, size ByteCount, ack *AckFrame, frames []Frame) { for _, t := range m.tracers { - t.SentPacket(hdr, size, ack, frames) + t.SentLongHeaderPacket(hdr, size, ack, frames) + } +} + +func (m *connTracerMultiplexer) SentShortHeaderPacket(hdr *ShortHeader, size ByteCount, ack *AckFrame, frames []Frame) { + for _, t := range m.tracers { + t.SentShortHeaderPacket(hdr, size, ack, frames) } } diff --git a/logging/multiplex_test.go b/logging/multiplex_test.go index 2e92407f..45e5b435 100644 --- a/logging/multiplex_test.go +++ b/logging/multiplex_test.go @@ -157,13 +157,22 @@ var _ = Describe("Tracing", func() { tracer.RestoredTransportParameters(tp) }) - It("traces the SentPacket event", func() { + It("traces the SentLongHeaderPacket event", func() { hdr := &ExtendedHeader{Header: Header{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3})}} ack := &AckFrame{AckRanges: []AckRange{{Smallest: 1, Largest: 10}}} ping := &PingFrame{} - tr1.EXPECT().SentPacket(hdr, ByteCount(1337), ack, []Frame{ping}) - tr2.EXPECT().SentPacket(hdr, ByteCount(1337), ack, []Frame{ping}) - tracer.SentPacket(hdr, 1337, ack, []Frame{ping}) + tr1.EXPECT().SentLongHeaderPacket(hdr, ByteCount(1337), ack, []Frame{ping}) + tr2.EXPECT().SentLongHeaderPacket(hdr, ByteCount(1337), ack, []Frame{ping}) + tracer.SentLongHeaderPacket(hdr, 1337, ack, []Frame{ping}) + }) + + It("traces the SentShortHeaderPacket event", func() { + hdr := &ShortHeader{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3})} + ack := &AckFrame{AckRanges: []AckRange{{Smallest: 1, Largest: 10}}} + ping := &PingFrame{} + tr1.EXPECT().SentShortHeaderPacket(hdr, ByteCount(1337), ack, []Frame{ping}) + tr2.EXPECT().SentShortHeaderPacket(hdr, ByteCount(1337), ack, []Frame{ping}) + tracer.SentShortHeaderPacket(hdr, 1337, ack, []Frame{ping}) }) It("traces the ReceivedVersionNegotiationPacket event", func() { diff --git a/logging/null_tracer.go b/logging/null_tracer.go index 3103ae90..38052ae3 100644 --- a/logging/null_tracer.go +++ b/logging/null_tracer.go @@ -31,11 +31,12 @@ func (n NullConnectionTracer) StartedConnection(local, remote net.Addr, srcConnI func (n NullConnectionTracer) NegotiatedVersion(chosen VersionNumber, clientVersions, serverVersions []VersionNumber) { } -func (n NullConnectionTracer) ClosedConnection(err error) {} -func (n NullConnectionTracer) SentTransportParameters(*TransportParameters) {} -func (n NullConnectionTracer) ReceivedTransportParameters(*TransportParameters) {} -func (n NullConnectionTracer) RestoredTransportParameters(*TransportParameters) {} -func (n NullConnectionTracer) SentPacket(*ExtendedHeader, ByteCount, *AckFrame, []Frame) {} +func (n NullConnectionTracer) ClosedConnection(err error) {} +func (n NullConnectionTracer) SentTransportParameters(*TransportParameters) {} +func (n NullConnectionTracer) ReceivedTransportParameters(*TransportParameters) {} +func (n NullConnectionTracer) RestoredTransportParameters(*TransportParameters) {} +func (n NullConnectionTracer) SentLongHeaderPacket(*ExtendedHeader, ByteCount, *AckFrame, []Frame) {} +func (n NullConnectionTracer) SentShortHeaderPacket(*ShortHeader, ByteCount, *AckFrame, []Frame) {} func (n NullConnectionTracer) ReceivedVersionNegotiationPacket(dest, src ArbitraryLenConnectionID, _ []VersionNumber) { } func (n NullConnectionTracer) ReceivedRetry(*Header) {} diff --git a/qlog/event.go b/qlog/event.go index f6799652..099105bd 100644 --- a/qlog/event.go +++ b/qlog/event.go @@ -154,7 +154,7 @@ func (e eventConnectionClosed) MarshalJSONObject(enc *gojay.Encoder) { } type eventPacketSent struct { - Header packetHeader + Header gojay.MarshalerJSONObject // either a shortHeader or a packetHeader Length logging.ByteCount PayloadLength logging.ByteCount Frames frames diff --git a/qlog/qlog.go b/qlog/qlog.go index 7c74590f..3db0727e 100644 --- a/qlog/qlog.go +++ b/qlog/qlog.go @@ -274,7 +274,15 @@ func (t *connectionTracer) toTransportParameters(tp *wire.TransportParameters) * } } -func (t *connectionTracer) SentPacket(hdr *wire.ExtendedHeader, packetSize logging.ByteCount, ack *logging.AckFrame, frames []logging.Frame) { +func (t *connectionTracer) SentLongHeaderPacket(hdr *logging.ExtendedHeader, packetSize logging.ByteCount, ack *logging.AckFrame, frames []logging.Frame) { + t.sentPacket(*transformLongHeader(hdr), packetSize, hdr.Length, ack, frames) +} + +func (t *connectionTracer) SentShortHeaderPacket(hdr *logging.ShortHeader, packetSize logging.ByteCount, ack *logging.AckFrame, frames []logging.Frame) { + t.sentPacket(*transformShortHeader(hdr), packetSize, 0, ack, frames) +} + +func (t *connectionTracer) sentPacket(hdr gojay.MarshalerJSONObject, packetSize, payloadLen logging.ByteCount, ack *logging.AckFrame, frames []logging.Frame) { numFrames := len(frames) if ack != nil { numFrames++ @@ -286,12 +294,11 @@ func (t *connectionTracer) SentPacket(hdr *wire.ExtendedHeader, packetSize loggi for _, f := range frames { fs = append(fs, frame{Frame: f}) } - header := *transformLongHeader(hdr) t.mutex.Lock() t.recordEvent(time.Now(), &eventPacketSent{ - Header: header, + Header: hdr, Length: packetSize, - PayloadLength: hdr.Length, + PayloadLength: payloadLen, Frames: fs, }) t.mutex.Unlock() diff --git a/qlog/qlog_test.go b/qlog/qlog_test.go index c9aa17de..18995868 100644 --- a/qlog/qlog_test.go +++ b/qlog/qlog_test.go @@ -420,8 +420,8 @@ var _ = Describe("Tracing", func() { Expect(ev).To(HaveKeyWithValue("initial_max_stream_data_uni", float64(300))) }) - It("records a sent packet, without an ACK", func() { - tracer.SentPacket( + It("records a sent long header packet, without an ACK", func() { + tracer.SentLongHeaderPacket( &logging.ExtendedHeader{ Header: logging.Header{ IsLongHeader: true, @@ -460,11 +460,11 @@ var _ = Describe("Tracing", func() { Expect(frames[1].(map[string]interface{})).To(HaveKeyWithValue("frame_type", "stream")) }) - It("records a sent packet, without an ACK", func() { - tracer.SentPacket( - &logging.ExtendedHeader{ - Header: logging.Header{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4})}, - PacketNumber: 1337, + It("records a sent short header packet, without an ACK", func() { + tracer.SentShortHeaderPacket( + &logging.ShortHeader{ + DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}), + PacketNumber: 1337, }, 123, &logging.AckFrame{AckRanges: []logging.AckRange{{Smallest: 1, Largest: 10}}},