diff --git a/codecov.yml b/codecov.yml index ee9cfd3b..074d9832 100644 --- a/codecov.yml +++ b/codecov.yml @@ -12,6 +12,7 @@ coverage: - internal/utils/newconnectionid_linkedlist.go - internal/utils/packetinterval_linkedlist.go - internal/utils/linkedlist/linkedlist.go + - logging/null_tracer.go - fuzzing/ - metrics/ status: diff --git a/integrationtests/self/handshake_test.go b/integrationtests/self/handshake_test.go index 6cdef36d..20209796 100644 --- a/integrationtests/self/handshake_test.go +++ b/integrationtests/self/handshake_test.go @@ -50,7 +50,7 @@ func (c *tokenStore) Pop(key string) *quic.ClientToken { } type versionNegotiationTracer struct { - connTracer + logging.NullConnectionTracer loggedVersions bool receivedVersionNegotiation bool diff --git a/integrationtests/self/key_update_test.go b/integrationtests/self/key_update_test.go index 4012f018..f9a6d5a8 100644 --- a/integrationtests/self/key_update_test.go +++ b/integrationtests/self/key_update_test.go @@ -45,7 +45,7 @@ func countKeyPhases() (sent, received int) { } type keyUpdateConnTracer struct { - connTracer + logging.NullConnectionTracer } func (t *keyUpdateConnTracer) SentPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, ack *logging.AckFrame, frames []logging.Frame) { diff --git a/integrationtests/self/self_suite_test.go b/integrationtests/self/self_suite_test.go index 242f8602..6a3e3a33 100644 --- a/integrationtests/self/self_suite_test.go +++ b/integrationtests/self/self_suite_test.go @@ -15,7 +15,6 @@ import ( "log" "math/big" mrand "math/rand" - "net" "os" "runtime/pprof" "strconv" @@ -328,6 +327,7 @@ func scaleDuration(d time.Duration) time.Duration { } type tracer struct { + logging.NullTracer createNewConnTracer func() logging.ConnectionTracer } @@ -340,48 +340,6 @@ func newTracer(c func() logging.ConnectionTracer) logging.Tracer { func (t *tracer) TracerForConnection(context.Context, logging.Perspective, logging.ConnectionID) logging.ConnectionTracer { return t.createNewConnTracer() } -func (t *tracer) SentPacket(net.Addr, *logging.Header, logging.ByteCount, []logging.Frame) {} -func (t *tracer) DroppedPacket(net.Addr, logging.PacketType, logging.ByteCount, logging.PacketDropReason) { -} - -type connTracer struct{} - -var _ logging.ConnectionTracer = &connTracer{} - -func (t *connTracer) StartedConnection(local, remote net.Addr, srcConnID, destConnID logging.ConnectionID) { -} - -func (t *connTracer) NegotiatedVersion(chosen logging.VersionNumber, clientVersions, serverVersions []logging.VersionNumber) { -} -func (t *connTracer) ClosedConnection(error) {} -func (t *connTracer) SentTransportParameters(*logging.TransportParameters) {} -func (t *connTracer) ReceivedTransportParameters(*logging.TransportParameters) {} -func (t *connTracer) RestoredTransportParameters(*logging.TransportParameters) {} -func (t *connTracer) SentPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, ack *logging.AckFrame, frames []logging.Frame) { -} -func (t *connTracer) ReceivedVersionNegotiationPacket(*logging.Header, []logging.VersionNumber) {} -func (t *connTracer) ReceivedRetry(*logging.Header) {} -func (t *connTracer) ReceivedPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, frames []logging.Frame) { -} -func (t *connTracer) BufferedPacket(logging.PacketType) {} -func (t *connTracer) DroppedPacket(logging.PacketType, logging.ByteCount, logging.PacketDropReason) {} -func (t *connTracer) UpdatedMetrics(rttStats *logging.RTTStats, cwnd, bytesInFlight logging.ByteCount, packetsInFlight int) { -} - -func (t *connTracer) AcknowledgedPacket(logging.EncryptionLevel, logging.PacketNumber) {} -func (t *connTracer) LostPacket(logging.EncryptionLevel, logging.PacketNumber, logging.PacketLossReason) { -} -func (t *connTracer) UpdatedCongestionState(logging.CongestionState) {} -func (t *connTracer) UpdatedPTOCount(value uint32) {} -func (t *connTracer) UpdatedKeyFromTLS(logging.EncryptionLevel, logging.Perspective) {} -func (t *connTracer) UpdatedKey(generation logging.KeyPhase, remote bool) {} -func (t *connTracer) DroppedEncryptionLevel(logging.EncryptionLevel) {} -func (t *connTracer) DroppedKey(logging.KeyPhase) {} -func (t *connTracer) SetLossTimer(logging.TimerType, logging.EncryptionLevel, time.Time) {} -func (t *connTracer) LossTimerExpired(logging.TimerType, logging.EncryptionLevel) {} -func (t *connTracer) LossTimerCanceled() {} -func (t *connTracer) Debug(string, string) {} -func (t *connTracer) Close() {} type packet struct { time time.Time @@ -390,7 +348,7 @@ type packet struct { } type packetTracer struct { - connTracer + logging.NullConnectionTracer closed chan struct{} sent, rcvd []packet } diff --git a/logging/null_tracer.go b/logging/null_tracer.go new file mode 100644 index 00000000..4e0bb60b --- /dev/null +++ b/logging/null_tracer.go @@ -0,0 +1,52 @@ +package logging + +import ( + "context" + "net" + "time" +) + +// The NullTracer is a Tracer that does nothing. +// It is useful for embedding. +type NullTracer struct{} + +func (n NullTracer) TracerForConnection(context.Context, Perspective, ConnectionID) ConnectionTracer { + return NullConnectionTracer{} +} +func (n NullTracer) SentPacket(net.Addr, *Header, ByteCount, []Frame) {} +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{} + +func (n NullConnectionTracer) StartedConnection(local, remote net.Addr, srcConnID, destConnID ConnectionID) { +} + +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) ReceivedVersionNegotiationPacket(*Header, []VersionNumber) {} +func (n NullConnectionTracer) ReceivedRetry(*Header) {} +func (n NullConnectionTracer) ReceivedPacket(hdr *ExtendedHeader, size ByteCount, frames []Frame) {} +func (n NullConnectionTracer) BufferedPacket(PacketType) {} +func (n NullConnectionTracer) DroppedPacket(PacketType, ByteCount, PacketDropReason) {} +func (n NullConnectionTracer) UpdatedMetrics(rttStats *RTTStats, cwnd, bytesInFlight ByteCount, packetsInFlight int) { +} +func (n NullConnectionTracer) AcknowledgedPacket(EncryptionLevel, PacketNumber) {} +func (n NullConnectionTracer) LostPacket(EncryptionLevel, PacketNumber, PacketLossReason) {} +func (n NullConnectionTracer) UpdatedCongestionState(CongestionState) {} +func (n NullConnectionTracer) UpdatedPTOCount(uint32) {} +func (n NullConnectionTracer) UpdatedKeyFromTLS(EncryptionLevel, Perspective) {} +func (n NullConnectionTracer) UpdatedKey(keyPhase KeyPhase, remote bool) {} +func (n NullConnectionTracer) DroppedEncryptionLevel(EncryptionLevel) {} +func (n NullConnectionTracer) DroppedKey(KeyPhase) {} +func (n NullConnectionTracer) SetLossTimer(TimerType, EncryptionLevel, time.Time) {} +func (n NullConnectionTracer) LossTimerExpired(timerType TimerType, level EncryptionLevel) {} +func (n NullConnectionTracer) LossTimerCanceled() {} +func (n NullConnectionTracer) Close() {} +func (n NullConnectionTracer) Debug(name, msg string) {}