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