From ecc8320c2c3ee848a0098833938385de10bd9e5c Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 28 Aug 2022 13:54:33 +0300 Subject: [PATCH] add a tracer function to trace sending of Version Negotiation packets --- internal/mocks/logging/tracer.go | 12 ++++++++++++ logging/interface.go | 3 +++ logging/mock_tracer_test.go | 12 ++++++++++++ logging/multiplex.go | 6 ++++++ logging/multiplex_test.go | 10 ++++++++++ logging/null_tracer.go | 8 +++++++- qlog/qlog.go | 6 ++---- 7 files changed, 52 insertions(+), 5 deletions(-) diff --git a/internal/mocks/logging/tracer.go b/internal/mocks/logging/tracer.go index 04c72623..762d5900 100644 --- a/internal/mocks/logging/tracer.go +++ b/internal/mocks/logging/tracer.go @@ -62,6 +62,18 @@ func (mr *MockTracerMockRecorder) SentPacket(arg0, arg1, arg2, arg3 interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SentPacket", reflect.TypeOf((*MockTracer)(nil).SentPacket), arg0, arg1, arg2, arg3) } +// SentVersionNegotiationPacket mocks base method. +func (m *MockTracer) SentVersionNegotiationPacket(arg0 net.Addr, arg1, arg2 protocol.ArbitraryLenConnectionID, arg3 []protocol.VersionNumber) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SentVersionNegotiationPacket", arg0, arg1, arg2, arg3) +} + +// SentVersionNegotiationPacket indicates an expected call of SentVersionNegotiationPacket. +func (mr *MockTracerMockRecorder) SentVersionNegotiationPacket(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SentVersionNegotiationPacket", reflect.TypeOf((*MockTracer)(nil).SentVersionNegotiationPacket), arg0, arg1, arg2, arg3) +} + // TracerForConnection mocks base method. func (m *MockTracer) TracerForConnection(arg0 context.Context, arg1 protocol.Perspective, arg2 protocol.ConnectionID) logging.ConnectionTracer { m.ctrl.T.Helper() diff --git a/logging/interface.go b/logging/interface.go index f71d68f7..595fc7b0 100644 --- a/logging/interface.go +++ b/logging/interface.go @@ -19,6 +19,8 @@ type ( ByteCount = protocol.ByteCount // A ConnectionID is a QUIC Connection ID. ConnectionID = protocol.ConnectionID + // An ArbitraryLenConnectionID is a QUIC Connection ID that can be up to 255 bytes long. + ArbitraryLenConnectionID = protocol.ArbitraryLenConnectionID // The EncryptionLevel is the encryption level of a packet. EncryptionLevel = protocol.EncryptionLevel // The KeyPhase is the key phase of the 1-RTT keys. @@ -99,6 +101,7 @@ type Tracer interface { TracerForConnection(ctx context.Context, p Perspective, odcid ConnectionID) ConnectionTracer SentPacket(net.Addr, *Header, ByteCount, []Frame) + SentVersionNegotiationPacket(_ net.Addr, dest, src ArbitraryLenConnectionID, _ []VersionNumber) DroppedPacket(net.Addr, PacketType, ByteCount, PacketDropReason) } diff --git a/logging/mock_tracer_test.go b/logging/mock_tracer_test.go index e970c09b..ff6e8525 100644 --- a/logging/mock_tracer_test.go +++ b/logging/mock_tracer_test.go @@ -61,6 +61,18 @@ func (mr *MockTracerMockRecorder) SentPacket(arg0, arg1, arg2, arg3 interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SentPacket", reflect.TypeOf((*MockTracer)(nil).SentPacket), arg0, arg1, arg2, arg3) } +// SentVersionNegotiationPacket mocks base method. +func (m *MockTracer) SentVersionNegotiationPacket(arg0 net.Addr, arg1, arg2 protocol.ArbitraryLenConnectionID, arg3 []protocol.VersionNumber) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SentVersionNegotiationPacket", arg0, arg1, arg2, arg3) +} + +// SentVersionNegotiationPacket indicates an expected call of SentVersionNegotiationPacket. +func (mr *MockTracerMockRecorder) SentVersionNegotiationPacket(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SentVersionNegotiationPacket", reflect.TypeOf((*MockTracer)(nil).SentVersionNegotiationPacket), arg0, arg1, arg2, arg3) +} + // TracerForConnection mocks base method. func (m *MockTracer) TracerForConnection(arg0 context.Context, arg1 protocol.Perspective, arg2 protocol.ConnectionID) ConnectionTracer { m.ctrl.T.Helper() diff --git a/logging/multiplex.go b/logging/multiplex.go index 8280e8cd..689e6366 100644 --- a/logging/multiplex.go +++ b/logging/multiplex.go @@ -39,6 +39,12 @@ func (m *tracerMultiplexer) SentPacket(remote net.Addr, hdr *Header, size ByteCo } } +func (m *tracerMultiplexer) SentVersionNegotiationPacket(remote net.Addr, dest, src ArbitraryLenConnectionID, versions []VersionNumber) { + for _, t := range m.tracers { + t.SentVersionNegotiationPacket(remote, dest, src, versions) + } +} + func (m *tracerMultiplexer) DroppedPacket(remote net.Addr, typ PacketType, size ByteCount, reason PacketDropReason) { for _, t := range m.tracers { t.DroppedPacket(remote, typ, size, reason) diff --git a/logging/multiplex_test.go b/logging/multiplex_test.go index 84b44d92..134dcb16 100644 --- a/logging/multiplex_test.go +++ b/logging/multiplex_test.go @@ -81,6 +81,16 @@ var _ = Describe("Tracing", func() { tracer.SentPacket(remote, hdr, 1024, []Frame{f}) }) + It("traces the PacketSent event", func() { + remote := &net.UDPAddr{IP: net.IPv4(4, 3, 2, 1)} + src := ArbitraryLenConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13} + dest := ArbitraryLenConnectionID{1, 2, 3, 4} + versions := []VersionNumber{1, 2, 3} + tr1.EXPECT().SentVersionNegotiationPacket(remote, dest, src, versions) + tr2.EXPECT().SentVersionNegotiationPacket(remote, dest, src, versions) + tracer.SentVersionNegotiationPacket(remote, dest, src, versions) + }) + It("traces the PacketDropped event", func() { remote := &net.UDPAddr{IP: net.IPv4(4, 3, 2, 1)} tr1.EXPECT().DroppedPacket(remote, PacketTypeRetry, ByteCount(1024), PacketDropDuplicate) diff --git a/logging/null_tracer.go b/logging/null_tracer.go index 4e0bb60b..45ad0c9d 100644 --- a/logging/null_tracer.go +++ b/logging/null_tracer.go @@ -10,16 +10,22 @@ import ( // It is useful for embedding. type NullTracer struct{} +var _ Tracer = &NullTracer{} + func (n NullTracer) TracerForConnection(context.Context, Perspective, ConnectionID) ConnectionTracer { return NullConnectionTracer{} } -func (n NullTracer) SentPacket(net.Addr, *Header, ByteCount, []Frame) {} +func (n NullTracer) SentPacket(net.Addr, *Header, ByteCount, []Frame) {} +func (n NullTracer) SentVersionNegotiationPacket(_ net.Addr, dest, src ArbitraryLenConnectionID, _ []VersionNumber) { +} func (n NullTracer) DroppedPacket(net.Addr, PacketType, ByteCount, PacketDropReason) {} // The NullConnectionTracer is a ConnectionTracer that does nothing. // It is useful for embedding. type NullConnectionTracer struct{} +var _ ConnectionTracer = &NullConnectionTracer{} + func (n NullConnectionTracer) StartedConnection(local, remote net.Addr, srcConnID, destConnID ConnectionID) { } diff --git a/qlog/qlog.go b/qlog/qlog.go index 5b411742..00aab291 100644 --- a/qlog/qlog.go +++ b/qlog/qlog.go @@ -50,6 +50,8 @@ func init() { const eventChanSize = 50 type tracer struct { + logging.NullTracer + getLogWriter func(p logging.Perspective, connectionID []byte) io.WriteCloser } @@ -67,10 +69,6 @@ func (t *tracer) TracerForConnection(_ context.Context, p logging.Perspective, o return nil } -func (t *tracer) SentPacket(net.Addr, *logging.Header, protocol.ByteCount, []logging.Frame) {} -func (t *tracer) DroppedPacket(net.Addr, logging.PacketType, protocol.ByteCount, logging.PacketDropReason) { -} - type connectionTracer struct { mutex sync.Mutex