interface.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Package logging defines a logging interface for quic-go.
  2. // This package should not be considered stable
  3. package logging
  4. import (
  5. "context"
  6. "net"
  7. "time"
  8. "github.com/Psiphon-Labs/quic-go/internal/protocol"
  9. "github.com/Psiphon-Labs/quic-go/internal/qerr"
  10. "github.com/Psiphon-Labs/quic-go/internal/utils"
  11. "github.com/Psiphon-Labs/quic-go/internal/wire"
  12. )
  13. type (
  14. // A ByteCount is used to count bytes.
  15. ByteCount = protocol.ByteCount
  16. // A ConnectionID is a QUIC Connection ID.
  17. ConnectionID = protocol.ConnectionID
  18. // An ArbitraryLenConnectionID is a QUIC Connection ID that can be up to 255 bytes long.
  19. ArbitraryLenConnectionID = protocol.ArbitraryLenConnectionID
  20. // The EncryptionLevel is the encryption level of a packet.
  21. EncryptionLevel = protocol.EncryptionLevel
  22. // The KeyPhase is the key phase of the 1-RTT keys.
  23. KeyPhase = protocol.KeyPhase
  24. // The KeyPhaseBit is the value of the key phase bit of the 1-RTT packets.
  25. KeyPhaseBit = protocol.KeyPhaseBit
  26. // The PacketNumber is the packet number of a packet.
  27. PacketNumber = protocol.PacketNumber
  28. // The Perspective is the role of a QUIC endpoint (client or server).
  29. Perspective = protocol.Perspective
  30. // A StatelessResetToken is a stateless reset token.
  31. StatelessResetToken = protocol.StatelessResetToken
  32. // The StreamID is the stream ID.
  33. StreamID = protocol.StreamID
  34. // The StreamNum is the number of the stream.
  35. StreamNum = protocol.StreamNum
  36. // The StreamType is the type of the stream (unidirectional or bidirectional).
  37. StreamType = protocol.StreamType
  38. // The VersionNumber is the QUIC version.
  39. VersionNumber = protocol.VersionNumber
  40. // The Header is the QUIC packet header, before removing header protection.
  41. Header = wire.Header
  42. // The ExtendedHeader is the QUIC Long Header packet header, after removing header protection.
  43. ExtendedHeader = wire.ExtendedHeader
  44. // The TransportParameters are QUIC transport parameters.
  45. TransportParameters = wire.TransportParameters
  46. // The PreferredAddress is the preferred address sent in the transport parameters.
  47. PreferredAddress = wire.PreferredAddress
  48. // A TransportError is a transport-level error code.
  49. TransportError = qerr.TransportErrorCode
  50. // An ApplicationError is an application-defined error code.
  51. ApplicationError = qerr.TransportErrorCode
  52. // The RTTStats contain statistics used by the congestion controller.
  53. RTTStats = utils.RTTStats
  54. )
  55. const (
  56. // KeyPhaseZero is key phase bit 0
  57. KeyPhaseZero KeyPhaseBit = protocol.KeyPhaseZero
  58. // KeyPhaseOne is key phase bit 1
  59. KeyPhaseOne KeyPhaseBit = protocol.KeyPhaseOne
  60. )
  61. const (
  62. // PerspectiveServer is used for a QUIC server
  63. PerspectiveServer Perspective = protocol.PerspectiveServer
  64. // PerspectiveClient is used for a QUIC client
  65. PerspectiveClient Perspective = protocol.PerspectiveClient
  66. )
  67. const (
  68. // EncryptionInitial is the Initial encryption level
  69. EncryptionInitial EncryptionLevel = protocol.EncryptionInitial
  70. // EncryptionHandshake is the Handshake encryption level
  71. EncryptionHandshake EncryptionLevel = protocol.EncryptionHandshake
  72. // Encryption1RTT is the 1-RTT encryption level
  73. Encryption1RTT EncryptionLevel = protocol.Encryption1RTT
  74. // Encryption0RTT is the 0-RTT encryption level
  75. Encryption0RTT EncryptionLevel = protocol.Encryption0RTT
  76. )
  77. const (
  78. // StreamTypeUni is a unidirectional stream
  79. StreamTypeUni = protocol.StreamTypeUni
  80. // StreamTypeBidi is a bidirectional stream
  81. StreamTypeBidi = protocol.StreamTypeBidi
  82. )
  83. // The ShortHeader is the QUIC Short Header packet header, after removing header protection.
  84. type ShortHeader struct {
  85. DestConnectionID ConnectionID
  86. PacketNumber PacketNumber
  87. PacketNumberLen protocol.PacketNumberLen
  88. KeyPhase KeyPhaseBit
  89. }
  90. // A Tracer traces events.
  91. type Tracer interface {
  92. // TracerForConnection requests a new tracer for a connection.
  93. // The ODCID is the original destination connection ID:
  94. // The destination connection ID that the client used on the first Initial packet it sent on this connection.
  95. // If nil is returned, tracing will be disabled for this connection.
  96. TracerForConnection(ctx context.Context, p Perspective, odcid ConnectionID) ConnectionTracer
  97. SentPacket(net.Addr, *Header, ByteCount, []Frame)
  98. SentVersionNegotiationPacket(_ net.Addr, dest, src ArbitraryLenConnectionID, _ []VersionNumber)
  99. DroppedPacket(net.Addr, PacketType, ByteCount, PacketDropReason)
  100. }
  101. // A ConnectionTracer records events.
  102. type ConnectionTracer interface {
  103. StartedConnection(local, remote net.Addr, srcConnID, destConnID ConnectionID)
  104. NegotiatedVersion(chosen VersionNumber, clientVersions, serverVersions []VersionNumber)
  105. ClosedConnection(error)
  106. SentTransportParameters(*TransportParameters)
  107. ReceivedTransportParameters(*TransportParameters)
  108. RestoredTransportParameters(parameters *TransportParameters) // for 0-RTT
  109. SentLongHeaderPacket(hdr *ExtendedHeader, size ByteCount, ack *AckFrame, frames []Frame)
  110. SentShortHeaderPacket(hdr *ShortHeader, size ByteCount, ack *AckFrame, frames []Frame)
  111. ReceivedVersionNegotiationPacket(dest, src ArbitraryLenConnectionID, _ []VersionNumber)
  112. ReceivedRetry(*Header)
  113. ReceivedLongHeaderPacket(hdr *ExtendedHeader, size ByteCount, frames []Frame)
  114. ReceivedShortHeaderPacket(hdr *ShortHeader, size ByteCount, frames []Frame)
  115. BufferedPacket(PacketType, ByteCount)
  116. DroppedPacket(PacketType, ByteCount, PacketDropReason)
  117. UpdatedMetrics(rttStats *RTTStats, cwnd, bytesInFlight ByteCount, packetsInFlight int)
  118. AcknowledgedPacket(EncryptionLevel, PacketNumber)
  119. LostPacket(EncryptionLevel, PacketNumber, PacketLossReason)
  120. UpdatedCongestionState(CongestionState)
  121. UpdatedPTOCount(value uint32)
  122. UpdatedKeyFromTLS(EncryptionLevel, Perspective)
  123. UpdatedKey(generation KeyPhase, remote bool)
  124. DroppedEncryptionLevel(EncryptionLevel)
  125. DroppedKey(generation KeyPhase)
  126. SetLossTimer(TimerType, EncryptionLevel, time.Time)
  127. LossTimerExpired(TimerType, EncryptionLevel)
  128. LossTimerCanceled()
  129. // Close is called when the connection is closed.
  130. Close()
  131. Debug(name, msg string)
  132. }