github.com/TugasAkhir-QUIC/quic-go@v0.0.2-0.20240215011318-d20e25a9054c/qlog/types.go (about) 1 package qlog 2 3 import ( 4 "fmt" 5 6 "github.com/TugasAkhir-QUIC/quic-go/internal/protocol" 7 "github.com/TugasAkhir-QUIC/quic-go/internal/qerr" 8 "github.com/TugasAkhir-QUIC/quic-go/logging" 9 ) 10 11 type owner uint8 12 13 const ( 14 ownerLocal owner = iota 15 ownerRemote 16 ) 17 18 func (o owner) String() string { 19 switch o { 20 case ownerLocal: 21 return "local" 22 case ownerRemote: 23 return "remote" 24 default: 25 return "unknown owner" 26 } 27 } 28 29 type streamType protocol.StreamType 30 31 func (s streamType) String() string { 32 switch protocol.StreamType(s) { 33 case protocol.StreamTypeUni: 34 return "unidirectional" 35 case protocol.StreamTypeBidi: 36 return "bidirectional" 37 default: 38 return "unknown stream type" 39 } 40 } 41 42 // category is the qlog event category. 43 type category uint8 44 45 const ( 46 categoryConnectivity category = iota 47 categoryTransport 48 categorySecurity 49 categoryRecovery 50 ) 51 52 func (c category) String() string { 53 switch c { 54 case categoryConnectivity: 55 return "connectivity" 56 case categoryTransport: 57 return "transport" 58 case categorySecurity: 59 return "security" 60 case categoryRecovery: 61 return "recovery" 62 default: 63 return "unknown category" 64 } 65 } 66 67 type versionNumber protocol.Version 68 69 func (v versionNumber) String() string { 70 return fmt.Sprintf("%x", uint32(v)) 71 } 72 73 func (packetHeader) IsNil() bool { return false } 74 75 func encLevelToPacketNumberSpace(encLevel protocol.EncryptionLevel) string { 76 switch encLevel { 77 case protocol.EncryptionInitial: 78 return "initial" 79 case protocol.EncryptionHandshake: 80 return "handshake" 81 case protocol.Encryption0RTT, protocol.Encryption1RTT: 82 return "application_data" 83 default: 84 return "unknown encryption level" 85 } 86 } 87 88 type keyType uint8 89 90 const ( 91 keyTypeServerInitial keyType = 1 + iota 92 keyTypeClientInitial 93 keyTypeServerHandshake 94 keyTypeClientHandshake 95 keyTypeServer0RTT 96 keyTypeClient0RTT 97 keyTypeServer1RTT 98 keyTypeClient1RTT 99 ) 100 101 func encLevelToKeyType(encLevel protocol.EncryptionLevel, pers protocol.Perspective) keyType { 102 if pers == protocol.PerspectiveServer { 103 switch encLevel { 104 case protocol.EncryptionInitial: 105 return keyTypeServerInitial 106 case protocol.EncryptionHandshake: 107 return keyTypeServerHandshake 108 case protocol.Encryption0RTT: 109 return keyTypeServer0RTT 110 case protocol.Encryption1RTT: 111 return keyTypeServer1RTT 112 default: 113 return 0 114 } 115 } 116 switch encLevel { 117 case protocol.EncryptionInitial: 118 return keyTypeClientInitial 119 case protocol.EncryptionHandshake: 120 return keyTypeClientHandshake 121 case protocol.Encryption0RTT: 122 return keyTypeClient0RTT 123 case protocol.Encryption1RTT: 124 return keyTypeClient1RTT 125 default: 126 return 0 127 } 128 } 129 130 func (t keyType) String() string { 131 switch t { 132 case keyTypeServerInitial: 133 return "server_initial_secret" 134 case keyTypeClientInitial: 135 return "client_initial_secret" 136 case keyTypeServerHandshake: 137 return "server_handshake_secret" 138 case keyTypeClientHandshake: 139 return "client_handshake_secret" 140 case keyTypeServer0RTT: 141 return "server_0rtt_secret" 142 case keyTypeClient0RTT: 143 return "client_0rtt_secret" 144 case keyTypeServer1RTT: 145 return "server_1rtt_secret" 146 case keyTypeClient1RTT: 147 return "client_1rtt_secret" 148 default: 149 return "unknown key type" 150 } 151 } 152 153 type keyUpdateTrigger uint8 154 155 const ( 156 keyUpdateTLS keyUpdateTrigger = iota 157 keyUpdateRemote 158 keyUpdateLocal 159 ) 160 161 func (t keyUpdateTrigger) String() string { 162 switch t { 163 case keyUpdateTLS: 164 return "tls" 165 case keyUpdateRemote: 166 return "remote_update" 167 case keyUpdateLocal: 168 return "local_update" 169 default: 170 return "unknown key update trigger" 171 } 172 } 173 174 type transportError uint64 175 176 func (e transportError) String() string { 177 switch qerr.TransportErrorCode(e) { 178 case qerr.NoError: 179 return "no_error" 180 case qerr.InternalError: 181 return "internal_error" 182 case qerr.ConnectionRefused: 183 return "connection_refused" 184 case qerr.FlowControlError: 185 return "flow_control_error" 186 case qerr.StreamLimitError: 187 return "stream_limit_error" 188 case qerr.StreamStateError: 189 return "stream_state_error" 190 case qerr.FinalSizeError: 191 return "final_size_error" 192 case qerr.FrameEncodingError: 193 return "frame_encoding_error" 194 case qerr.TransportParameterError: 195 return "transport_parameter_error" 196 case qerr.ConnectionIDLimitError: 197 return "connection_id_limit_error" 198 case qerr.ProtocolViolation: 199 return "protocol_violation" 200 case qerr.InvalidToken: 201 return "invalid_token" 202 case qerr.ApplicationErrorErrorCode: 203 return "application_error" 204 case qerr.CryptoBufferExceeded: 205 return "crypto_buffer_exceeded" 206 case qerr.KeyUpdateError: 207 return "key_update_error" 208 case qerr.AEADLimitReached: 209 return "aead_limit_reached" 210 case qerr.NoViablePathError: 211 return "no_viable_path" 212 default: 213 return "" 214 } 215 } 216 217 type packetType logging.PacketType 218 219 func (t packetType) String() string { 220 switch logging.PacketType(t) { 221 case logging.PacketTypeInitial: 222 return "initial" 223 case logging.PacketTypeHandshake: 224 return "handshake" 225 case logging.PacketTypeRetry: 226 return "retry" 227 case logging.PacketType0RTT: 228 return "0RTT" 229 case logging.PacketTypeVersionNegotiation: 230 return "version_negotiation" 231 case logging.PacketTypeStatelessReset: 232 return "stateless_reset" 233 case logging.PacketType1RTT: 234 return "1RTT" 235 case logging.PacketTypeNotDetermined: 236 return "" 237 default: 238 return "unknown packet type" 239 } 240 } 241 242 type packetLossReason logging.PacketLossReason 243 244 func (r packetLossReason) String() string { 245 switch logging.PacketLossReason(r) { 246 case logging.PacketLossReorderingThreshold: 247 return "reordering_threshold" 248 case logging.PacketLossTimeThreshold: 249 return "time_threshold" 250 default: 251 return "unknown loss reason" 252 } 253 } 254 255 type packetDropReason logging.PacketDropReason 256 257 func (r packetDropReason) String() string { 258 switch logging.PacketDropReason(r) { 259 case logging.PacketDropKeyUnavailable: 260 return "key_unavailable" 261 case logging.PacketDropUnknownConnectionID: 262 return "unknown_connection_id" 263 case logging.PacketDropHeaderParseError: 264 return "header_parse_error" 265 case logging.PacketDropPayloadDecryptError: 266 return "payload_decrypt_error" 267 case logging.PacketDropProtocolViolation: 268 return "protocol_violation" 269 case logging.PacketDropDOSPrevention: 270 return "dos_prevention" 271 case logging.PacketDropUnsupportedVersion: 272 return "unsupported_version" 273 case logging.PacketDropUnexpectedPacket: 274 return "unexpected_packet" 275 case logging.PacketDropUnexpectedSourceConnectionID: 276 return "unexpected_source_connection_id" 277 case logging.PacketDropUnexpectedVersion: 278 return "unexpected_version" 279 case logging.PacketDropDuplicate: 280 return "duplicate" 281 default: 282 return "unknown packet drop reason" 283 } 284 } 285 286 type timerType logging.TimerType 287 288 func (t timerType) String() string { 289 switch logging.TimerType(t) { 290 case logging.TimerTypeACK: 291 return "ack" 292 case logging.TimerTypePTO: 293 return "pto" 294 default: 295 return "unknown timer type" 296 } 297 } 298 299 type congestionState logging.CongestionState 300 301 func (s congestionState) String() string { 302 switch logging.CongestionState(s) { 303 case logging.CongestionStateSlowStart: 304 return "slow_start" 305 case logging.CongestionStateCongestionAvoidance: 306 return "congestion_avoidance" 307 case logging.CongestionStateRecovery: 308 return "recovery" 309 case logging.CongestionStateApplicationLimited: 310 return "application_limited" 311 default: 312 return "unknown congestion state" 313 } 314 } 315 316 type ecn logging.ECN 317 318 func (e ecn) String() string { 319 //nolint:exhaustive // The unsupported value is never logged. 320 switch logging.ECN(e) { 321 case logging.ECTNot: 322 return "Not-ECT" 323 case logging.ECT0: 324 return "ECT(0)" 325 case logging.ECT1: 326 return "ECT(1)" 327 case logging.ECNCE: 328 return "CE" 329 default: 330 return "unknown ECN" 331 } 332 } 333 334 type ecnState logging.ECNState 335 336 func (e ecnState) String() string { 337 switch logging.ECNState(e) { 338 case logging.ECNStateTesting: 339 return "testing" 340 case logging.ECNStateUnknown: 341 return "unknown" 342 case logging.ECNStateCapable: 343 return "capable" 344 case logging.ECNStateFailed: 345 return "failed" 346 default: 347 return "unknown ECN state" 348 } 349 } 350 351 type ecnStateTrigger logging.ECNStateTrigger 352 353 func (e ecnStateTrigger) String() string { 354 switch logging.ECNStateTrigger(e) { 355 case logging.ECNTriggerNoTrigger: 356 return "" 357 case logging.ECNFailedNoECNCounts: 358 return "ACK doesn't contain ECN marks" 359 case logging.ECNFailedDecreasedECNCounts: 360 return "ACK decreases ECN counts" 361 case logging.ECNFailedLostAllTestingPackets: 362 return "all ECN testing packets declared lost" 363 case logging.ECNFailedMoreECNCountsThanSent: 364 return "ACK contains more ECN counts than ECN-marked packets sent" 365 case logging.ECNFailedTooFewECNCounts: 366 return "ACK contains fewer new ECN counts than acknowledged ECN-marked packets" 367 case logging.ECNFailedManglingDetected: 368 return "ECN mangling detected" 369 default: 370 return "unknown ECN state trigger" 371 } 372 }