forked from quic-go/quic-go
remove Tracer from Config, put ConnectionTracer constructor there
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
@@ -101,12 +100,6 @@ type ShortHeader struct {
|
||||
|
||||
// A Tracer traces events.
|
||||
type Tracer interface {
|
||||
// TracerForConnection requests a new tracer for a connection.
|
||||
// The ODCID is the original destination connection ID:
|
||||
// The destination connection ID that the client used on the first Initial packet it sent on this connection.
|
||||
// If nil is returned, tracing will be disabled for this connection.
|
||||
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)
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
context "context"
|
||||
net "net"
|
||||
reflect "reflect"
|
||||
|
||||
@@ -72,17 +71,3 @@ func (mr *MockTracerMockRecorder) SentVersionNegotiationPacket(arg0, arg1, arg2,
|
||||
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()
|
||||
ret := m.ctrl.Call(m, "TracerForConnection", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(ConnectionTracer)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// TracerForConnection indicates an expected call of TracerForConnection.
|
||||
func (mr *MockTracerMockRecorder) TracerForConnection(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TracerForConnection", reflect.TypeOf((*MockTracer)(nil).TracerForConnection), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
@@ -23,16 +22,6 @@ func NewMultiplexedTracer(tracers ...Tracer) Tracer {
|
||||
return &tracerMultiplexer{tracers}
|
||||
}
|
||||
|
||||
func (m *tracerMultiplexer) TracerForConnection(ctx context.Context, p Perspective, odcid ConnectionID) ConnectionTracer {
|
||||
var connTracers []ConnectionTracer
|
||||
for _, t := range m.tracers {
|
||||
if ct := t.TracerForConnection(ctx, p, odcid); ct != nil {
|
||||
connTracers = append(connTracers, ct)
|
||||
}
|
||||
}
|
||||
return NewMultiplexedConnectionTracer(connTracers...)
|
||||
}
|
||||
|
||||
func (m *tracerMultiplexer) SentPacket(remote net.Addr, hdr *Header, size ByteCount, frames []Frame) {
|
||||
for _, t := range m.tracers {
|
||||
t.SentPacket(remote, hdr, size, frames)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"time"
|
||||
@@ -37,46 +36,6 @@ var _ = Describe("Tracing", func() {
|
||||
tracer = NewMultiplexedTracer(tr1, tr2)
|
||||
})
|
||||
|
||||
It("multiplexes the TracerForConnection call", func() {
|
||||
ctx := context.Background()
|
||||
connID := protocol.ParseConnectionID([]byte{1, 2, 3})
|
||||
tr1.EXPECT().TracerForConnection(ctx, PerspectiveClient, connID)
|
||||
tr2.EXPECT().TracerForConnection(ctx, PerspectiveClient, connID)
|
||||
tracer.TracerForConnection(ctx, PerspectiveClient, connID)
|
||||
})
|
||||
|
||||
It("uses multiple connection tracers", func() {
|
||||
ctx := context.Background()
|
||||
ctr1 := NewMockConnectionTracer(mockCtrl)
|
||||
ctr2 := NewMockConnectionTracer(mockCtrl)
|
||||
connID := protocol.ParseConnectionID([]byte{1, 2, 3})
|
||||
tr1.EXPECT().TracerForConnection(ctx, PerspectiveServer, connID).Return(ctr1)
|
||||
tr2.EXPECT().TracerForConnection(ctx, PerspectiveServer, connID).Return(ctr2)
|
||||
tr := tracer.TracerForConnection(ctx, PerspectiveServer, connID)
|
||||
ctr1.EXPECT().LossTimerCanceled()
|
||||
ctr2.EXPECT().LossTimerCanceled()
|
||||
tr.LossTimerCanceled()
|
||||
})
|
||||
|
||||
It("handles tracers that return a nil ConnectionTracer", func() {
|
||||
ctx := context.Background()
|
||||
ctr1 := NewMockConnectionTracer(mockCtrl)
|
||||
connID := protocol.ParseConnectionID([]byte{1, 2, 3, 4})
|
||||
tr1.EXPECT().TracerForConnection(ctx, PerspectiveServer, connID).Return(ctr1)
|
||||
tr2.EXPECT().TracerForConnection(ctx, PerspectiveServer, connID)
|
||||
tr := tracer.TracerForConnection(ctx, PerspectiveServer, connID)
|
||||
ctr1.EXPECT().LossTimerCanceled()
|
||||
tr.LossTimerCanceled()
|
||||
})
|
||||
|
||||
It("returns nil when all tracers return a nil ConnectionTracer", func() {
|
||||
ctx := context.Background()
|
||||
connID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5})
|
||||
tr1.EXPECT().TracerForConnection(ctx, PerspectiveClient, connID)
|
||||
tr2.EXPECT().TracerForConnection(ctx, PerspectiveClient, connID)
|
||||
Expect(tracer.TracerForConnection(ctx, PerspectiveClient, connID)).To(BeNil())
|
||||
})
|
||||
|
||||
It("traces the PacketSent event", func() {
|
||||
remote := &net.UDPAddr{IP: net.IPv4(4, 3, 2, 1)}
|
||||
hdr := &Header{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3})}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
@@ -12,9 +11,6 @@ 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) SentVersionNegotiationPacket(_ net.Addr, dest, src ArbitraryLenConnectionID, _ []VersionNumber) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user