github.com/psiphon-labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/common/quic/gquic-go/internal/protocol/protocol.go (about)

     1  package protocol
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // A PacketNumber in QUIC
     8  type PacketNumber uint64
     9  
    10  // PacketNumberLen is the length of the packet number in bytes
    11  type PacketNumberLen uint8
    12  
    13  const (
    14  	// PacketNumberLenInvalid is the default value and not a valid length for a packet number
    15  	PacketNumberLenInvalid PacketNumberLen = 0
    16  	// PacketNumberLen1 is a packet number length of 1 byte
    17  	PacketNumberLen1 PacketNumberLen = 1
    18  	// PacketNumberLen2 is a packet number length of 2 bytes
    19  	PacketNumberLen2 PacketNumberLen = 2
    20  	// PacketNumberLen4 is a packet number length of 4 bytes
    21  	PacketNumberLen4 PacketNumberLen = 4
    22  	// PacketNumberLen6 is a packet number length of 6 bytes
    23  	PacketNumberLen6 PacketNumberLen = 6
    24  )
    25  
    26  // The PacketType is the Long Header Type (only used for the IETF draft header format)
    27  type PacketType uint8
    28  
    29  const (
    30  	// PacketTypeInitial is the packet type of an Initial packet
    31  	PacketTypeInitial PacketType = 0x7f
    32  	// PacketTypeRetry is the packet type of a Retry packet
    33  	PacketTypeRetry PacketType = 0x7e
    34  	// PacketTypeHandshake is the packet type of a Handshake packet
    35  	PacketTypeHandshake PacketType = 0x7d
    36  	// PacketType0RTT is the packet type of a 0-RTT packet
    37  	PacketType0RTT PacketType = 0x7c
    38  )
    39  
    40  func (t PacketType) String() string {
    41  	switch t {
    42  	case PacketTypeInitial:
    43  		return "Initial"
    44  	case PacketTypeRetry:
    45  		return "Retry"
    46  	case PacketTypeHandshake:
    47  		return "Handshake"
    48  	case PacketType0RTT:
    49  		return "0-RTT Protected"
    50  	default:
    51  		return fmt.Sprintf("unknown packet type: %d", t)
    52  	}
    53  }
    54  
    55  // A ByteCount in QUIC
    56  type ByteCount uint64
    57  
    58  // MaxByteCount is the maximum value of a ByteCount
    59  const MaxByteCount = ByteCount(1<<62 - 1)
    60  
    61  // An ApplicationErrorCode is an application-defined error code.
    62  type ApplicationErrorCode uint16
    63  
    64  // MaxReceivePacketSize maximum packet size of any QUIC packet, based on
    65  // ethernet's max size, minus the IP and UDP headers. IPv6 has a 40 byte header,
    66  // UDP adds an additional 8 bytes.  This is a total overhead of 48 bytes.
    67  // Ethernet's max packet size is 1500 bytes,  1500 - 48 = 1452.
    68  const MaxReceivePacketSize ByteCount = 1452
    69  
    70  // DefaultTCPMSS is the default maximum packet size used in the Linux TCP implementation.
    71  // Used in QUIC for congestion window computations in bytes.
    72  const DefaultTCPMSS ByteCount = 1460
    73  
    74  // MinClientHelloSize is the minimum size the server expects an inchoate CHLO to have (in gQUIC)
    75  const MinClientHelloSize = 1024
    76  
    77  // MinInitialPacketSize is the minimum size an Initial packet (in IETF QUIC) is required to have.
    78  const MinInitialPacketSize = 1200
    79  
    80  // MaxClientHellos is the maximum number of times we'll send a client hello
    81  // The value 3 accounts for:
    82  // * one failure due to an incorrect or missing source-address token
    83  // * one failure due the server's certificate chain being unavailable and the server being unwilling to send it without a valid source-address token
    84  const MaxClientHellos = 3
    85  
    86  // ConnectionIDLenGQUIC is the length of the source Connection ID used on gQUIC QUIC packets.
    87  const ConnectionIDLenGQUIC = 8
    88  
    89  // MinConnectionIDLenInitial is the minimum length of the destination connection ID on an Initial packet.
    90  const MinConnectionIDLenInitial = 8