interface.go 5.1 KB

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