github.com/tumi8/quic-go@v0.37.4-tum/logging/multiplex.go (about)

     1  package logging
     2  
     3  import (
     4  	"net"
     5  	"time"
     6  )
     7  
     8  type tracerMultiplexer struct {
     9  	tracers []Tracer
    10  }
    11  
    12  var _ Tracer = &tracerMultiplexer{}
    13  
    14  // NewMultiplexedTracer creates a new tracer that multiplexes events to multiple tracers.
    15  func NewMultiplexedTracer(tracers ...Tracer) Tracer {
    16  	if len(tracers) == 0 {
    17  		return nil
    18  	}
    19  	if len(tracers) == 1 {
    20  		return tracers[0]
    21  	}
    22  	return &tracerMultiplexer{tracers}
    23  }
    24  
    25  func (m *tracerMultiplexer) SentPacket(remote net.Addr, hdr *Header, size ByteCount, frames []Frame) {
    26  	for _, t := range m.tracers {
    27  		t.SentPacket(remote, hdr, size, frames)
    28  	}
    29  }
    30  
    31  func (m *tracerMultiplexer) SentVersionNegotiationPacket(remote net.Addr, dest, src ArbitraryLenConnectionID, versions []VersionNumber) {
    32  	for _, t := range m.tracers {
    33  		t.SentVersionNegotiationPacket(remote, dest, src, versions)
    34  	}
    35  }
    36  
    37  func (m *tracerMultiplexer) DroppedPacket(remote net.Addr, typ PacketType, size ByteCount, reason PacketDropReason) {
    38  	for _, t := range m.tracers {
    39  		t.DroppedPacket(remote, typ, size, reason)
    40  	}
    41  }
    42  
    43  type connTracerMultiplexer struct {
    44  	tracers []ConnectionTracer
    45  }
    46  
    47  var _ ConnectionTracer = &connTracerMultiplexer{}
    48  
    49  // NewMultiplexedConnectionTracer creates a new connection tracer that multiplexes events to multiple tracers.
    50  func NewMultiplexedConnectionTracer(tracers ...ConnectionTracer) ConnectionTracer {
    51  	if len(tracers) == 0 {
    52  		return nil
    53  	}
    54  	if len(tracers) == 1 {
    55  		return tracers[0]
    56  	}
    57  	return &connTracerMultiplexer{tracers: tracers}
    58  }
    59  
    60  func (m *connTracerMultiplexer) StartedConnection(local, remote net.Addr, srcConnID, destConnID ConnectionID) {
    61  	for _, t := range m.tracers {
    62  		t.StartedConnection(local, remote, srcConnID, destConnID)
    63  	}
    64  }
    65  
    66  func (m *connTracerMultiplexer) NegotiatedVersion(chosen VersionNumber, clientVersions, serverVersions []VersionNumber) {
    67  	for _, t := range m.tracers {
    68  		t.NegotiatedVersion(chosen, clientVersions, serverVersions)
    69  	}
    70  }
    71  
    72  func (m *connTracerMultiplexer) ClosedConnection(e error) {
    73  	for _, t := range m.tracers {
    74  		t.ClosedConnection(e)
    75  	}
    76  }
    77  
    78  func (m *connTracerMultiplexer) SentTransportParameters(tp *TransportParameters) {
    79  	for _, t := range m.tracers {
    80  		t.SentTransportParameters(tp)
    81  	}
    82  }
    83  
    84  func (m *connTracerMultiplexer) ReceivedTransportParameters(tp *TransportParameters) {
    85  	for _, t := range m.tracers {
    86  		t.ReceivedTransportParameters(tp)
    87  	}
    88  }
    89  
    90  func (m *connTracerMultiplexer) RestoredTransportParameters(tp *TransportParameters) {
    91  	for _, t := range m.tracers {
    92  		t.RestoredTransportParameters(tp)
    93  	}
    94  }
    95  
    96  func (m *connTracerMultiplexer) SentLongHeaderPacket(hdr *ExtendedHeader, size ByteCount, ack *AckFrame, frames []Frame) {
    97  	for _, t := range m.tracers {
    98  		t.SentLongHeaderPacket(hdr, size, ack, frames)
    99  	}
   100  }
   101  
   102  func (m *connTracerMultiplexer) SentShortHeaderPacket(hdr *ShortHeader, size ByteCount, ack *AckFrame, frames []Frame) {
   103  	for _, t := range m.tracers {
   104  		t.SentShortHeaderPacket(hdr, size, ack, frames)
   105  	}
   106  }
   107  
   108  func (m *connTracerMultiplexer) ReceivedVersionNegotiationPacket(dest, src ArbitraryLenConnectionID, versions []VersionNumber) {
   109  	for _, t := range m.tracers {
   110  		t.ReceivedVersionNegotiationPacket(dest, src, versions)
   111  	}
   112  }
   113  
   114  func (m *connTracerMultiplexer) ReceivedRetry(hdr *Header) {
   115  	for _, t := range m.tracers {
   116  		t.ReceivedRetry(hdr)
   117  	}
   118  }
   119  
   120  func (m *connTracerMultiplexer) ReceivedLongHeaderPacket(hdr *ExtendedHeader, size ByteCount, frames []Frame) {
   121  	for _, t := range m.tracers {
   122  		t.ReceivedLongHeaderPacket(hdr, size, frames)
   123  	}
   124  }
   125  
   126  func (m *connTracerMultiplexer) ReceivedShortHeaderPacket(hdr *ShortHeader, size ByteCount, frames []Frame) {
   127  	for _, t := range m.tracers {
   128  		t.ReceivedShortHeaderPacket(hdr, size, frames)
   129  	}
   130  }
   131  
   132  func (m *connTracerMultiplexer) BufferedPacket(typ PacketType, size ByteCount) {
   133  	for _, t := range m.tracers {
   134  		t.BufferedPacket(typ, size)
   135  	}
   136  }
   137  
   138  func (m *connTracerMultiplexer) DroppedPacket(typ PacketType, size ByteCount, reason PacketDropReason) {
   139  	for _, t := range m.tracers {
   140  		t.DroppedPacket(typ, size, reason)
   141  	}
   142  }
   143  
   144  func (m *connTracerMultiplexer) UpdatedCongestionState(state CongestionState) {
   145  	for _, t := range m.tracers {
   146  		t.UpdatedCongestionState(state)
   147  	}
   148  }
   149  
   150  func (m *connTracerMultiplexer) UpdatedMetrics(rttStats *RTTStats, cwnd, bytesInFLight ByteCount, packetsInFlight int) {
   151  	for _, t := range m.tracers {
   152  		t.UpdatedMetrics(rttStats, cwnd, bytesInFLight, packetsInFlight)
   153  	}
   154  }
   155  
   156  func (m *connTracerMultiplexer) AcknowledgedPacket(encLevel EncryptionLevel, pn PacketNumber) {
   157  	for _, t := range m.tracers {
   158  		t.AcknowledgedPacket(encLevel, pn)
   159  	}
   160  }
   161  
   162  func (m *connTracerMultiplexer) LostPacket(encLevel EncryptionLevel, pn PacketNumber, reason PacketLossReason) {
   163  	for _, t := range m.tracers {
   164  		t.LostPacket(encLevel, pn, reason)
   165  	}
   166  }
   167  
   168  func (m *connTracerMultiplexer) UpdatedPTOCount(value uint32) {
   169  	for _, t := range m.tracers {
   170  		t.UpdatedPTOCount(value)
   171  	}
   172  }
   173  
   174  func (m *connTracerMultiplexer) UpdatedKeyFromTLS(encLevel EncryptionLevel, perspective Perspective) {
   175  	for _, t := range m.tracers {
   176  		t.UpdatedKeyFromTLS(encLevel, perspective)
   177  	}
   178  }
   179  
   180  func (m *connTracerMultiplexer) UpdatedKey(generation KeyPhase, remote bool) {
   181  	for _, t := range m.tracers {
   182  		t.UpdatedKey(generation, remote)
   183  	}
   184  }
   185  
   186  func (m *connTracerMultiplexer) DroppedEncryptionLevel(encLevel EncryptionLevel) {
   187  	for _, t := range m.tracers {
   188  		t.DroppedEncryptionLevel(encLevel)
   189  	}
   190  }
   191  
   192  func (m *connTracerMultiplexer) DroppedKey(generation KeyPhase) {
   193  	for _, t := range m.tracers {
   194  		t.DroppedKey(generation)
   195  	}
   196  }
   197  
   198  func (m *connTracerMultiplexer) SetLossTimer(typ TimerType, encLevel EncryptionLevel, exp time.Time) {
   199  	for _, t := range m.tracers {
   200  		t.SetLossTimer(typ, encLevel, exp)
   201  	}
   202  }
   203  
   204  func (m *connTracerMultiplexer) LossTimerExpired(typ TimerType, encLevel EncryptionLevel) {
   205  	for _, t := range m.tracers {
   206  		t.LossTimerExpired(typ, encLevel)
   207  	}
   208  }
   209  
   210  func (m *connTracerMultiplexer) LossTimerCanceled() {
   211  	for _, t := range m.tracers {
   212  		t.LossTimerCanceled()
   213  	}
   214  }
   215  
   216  func (m *connTracerMultiplexer) Debug(name, msg string) {
   217  	for _, t := range m.tracers {
   218  		t.Debug(name, msg)
   219  	}
   220  }
   221  
   222  func (m *connTracerMultiplexer) Close() {
   223  	for _, t := range m.tracers {
   224  		t.Close()
   225  	}
   226  }