github.com/ooni/psiphon/tunnel-core@v0.0.0-20230105123940-fe12a24c96ee/oovendor/quic-go/internal/protocol/params.go (about)

     1  package protocol
     2  
     3  import "time"
     4  
     5  // DesiredReceiveBufferSize is the kernel UDP receive buffer size that we'd like to use.
     6  const DesiredReceiveBufferSize = (1 << 20) * 2 // 2 MB
     7  
     8  // InitialPacketSizeIPv4 is the maximum packet size that we use for sending IPv4 packets.
     9  const InitialPacketSizeIPv4 = 1252
    10  
    11  // InitialPacketSizeIPv6 is the maximum packet size that we use for sending IPv6 packets.
    12  const InitialPacketSizeIPv6 = 1232
    13  
    14  // MaxCongestionWindowPackets is the maximum congestion window in packet.
    15  const MaxCongestionWindowPackets = 10000
    16  
    17  // MaxUndecryptablePackets limits the number of undecryptable packets that are queued in the session.
    18  const MaxUndecryptablePackets = 32
    19  
    20  // ConnectionFlowControlMultiplier determines how much larger the connection flow control windows needs to be relative to any stream's flow control window
    21  // This is the value that Chromium is using
    22  const ConnectionFlowControlMultiplier = 1.5
    23  
    24  // DefaultInitialMaxStreamData is the default initial stream-level flow control window for receiving data
    25  const DefaultInitialMaxStreamData = (1 << 10) * 512 // 512 kb
    26  
    27  // DefaultInitialMaxData is the connection-level flow control window for receiving data
    28  const DefaultInitialMaxData = ConnectionFlowControlMultiplier * DefaultInitialMaxStreamData
    29  
    30  // DefaultMaxReceiveStreamFlowControlWindow is the default maximum stream-level flow control window for receiving data
    31  const DefaultMaxReceiveStreamFlowControlWindow = 6 * (1 << 20) // 6 MB
    32  
    33  // DefaultMaxReceiveConnectionFlowControlWindow is the default connection-level flow control window for receiving data
    34  const DefaultMaxReceiveConnectionFlowControlWindow = 15 * (1 << 20) // 15 MB
    35  
    36  // WindowUpdateThreshold is the fraction of the receive window that has to be consumed before an higher offset is advertised to the client
    37  const WindowUpdateThreshold = 0.25
    38  
    39  // DefaultMaxIncomingStreams is the maximum number of streams that a peer may open
    40  const DefaultMaxIncomingStreams = 100
    41  
    42  // DefaultMaxIncomingUniStreams is the maximum number of unidirectional streams that a peer may open
    43  const DefaultMaxIncomingUniStreams = 100
    44  
    45  // MaxServerUnprocessedPackets is the max number of packets stored in the server that are not yet processed.
    46  const MaxServerUnprocessedPackets = 1024
    47  
    48  // MaxSessionUnprocessedPackets is the max number of packets stored in each session that are not yet processed.
    49  const MaxSessionUnprocessedPackets = 256
    50  
    51  // SkipPacketInitialPeriod is the initial period length used for packet number skipping to prevent an Optimistic ACK attack.
    52  // Every time a packet number is skipped, the period is doubled, up to SkipPacketMaxPeriod.
    53  const SkipPacketInitialPeriod PacketNumber = 256
    54  
    55  // SkipPacketMaxPeriod is the maximum period length used for packet number skipping.
    56  const SkipPacketMaxPeriod PacketNumber = 128 * 1024
    57  
    58  // MaxAcceptQueueSize is the maximum number of sessions that the server queues for accepting.
    59  // If the queue is full, new connection attempts will be rejected.
    60  const MaxAcceptQueueSize = 32
    61  
    62  // TokenValidity is the duration that a (non-retry) token is considered valid
    63  const TokenValidity = 24 * time.Hour
    64  
    65  // RetryTokenValidity is the duration that a retry token is considered valid
    66  const RetryTokenValidity = 10 * time.Second
    67  
    68  // MaxOutstandingSentPackets is maximum number of packets saved for retransmission.
    69  // When reached, it imposes a soft limit on sending new packets:
    70  // Sending ACKs and retransmission is still allowed, but now new regular packets can be sent.
    71  const MaxOutstandingSentPackets = 2 * MaxCongestionWindowPackets
    72  
    73  // MaxTrackedSentPackets is maximum number of sent packets saved for retransmission.
    74  // When reached, no more packets will be sent.
    75  // This value *must* be larger than MaxOutstandingSentPackets.
    76  const MaxTrackedSentPackets = MaxOutstandingSentPackets * 5 / 4
    77  
    78  // MaxNonAckElicitingAcks is the maximum number of packets containing an ACK,
    79  // but no ack-eliciting frames, that we send in a row
    80  const MaxNonAckElicitingAcks = 19
    81  
    82  // MaxStreamFrameSorterGaps is the maximum number of gaps between received StreamFrames
    83  // prevents DoS attacks against the streamFrameSorter
    84  const MaxStreamFrameSorterGaps = 1000
    85  
    86  // MinStreamFrameBufferSize is the minimum data length of a received STREAM frame
    87  // that we use the buffer for. This protects against a DoS where an attacker would send us
    88  // very small STREAM frames to consume a lot of memory.
    89  const MinStreamFrameBufferSize = 128
    90  
    91  // MinCoalescedPacketSize is the minimum size of a coalesced packet that we pack.
    92  // If a packet has less than this number of bytes, we won't coalesce any more packets onto it.
    93  const MinCoalescedPacketSize = 128
    94  
    95  // MaxCryptoStreamOffset is the maximum offset allowed on any of the crypto streams.
    96  // This limits the size of the ClientHello and Certificates that can be received.
    97  const MaxCryptoStreamOffset = 16 * (1 << 10)
    98  
    99  // MinRemoteIdleTimeout is the minimum value that we accept for the remote idle timeout
   100  const MinRemoteIdleTimeout = 5 * time.Second
   101  
   102  // DefaultIdleTimeout is the default idle timeout
   103  const DefaultIdleTimeout = 30 * time.Second
   104  
   105  // DefaultHandshakeIdleTimeout is the default idle timeout used before handshake completion.
   106  const DefaultHandshakeIdleTimeout = 5 * time.Second
   107  
   108  // DefaultHandshakeTimeout is the default timeout for a connection until the crypto handshake succeeds.
   109  const DefaultHandshakeTimeout = 10 * time.Second
   110  
   111  // MaxKeepAliveInterval is the maximum time until we send a packet to keep a connection alive.
   112  // It should be shorter than the time that NATs clear their mapping.
   113  const MaxKeepAliveInterval = 20 * time.Second
   114  
   115  // RetiredConnectionIDDeleteTimeout is the time we keep closed sessions around in order to retransmit the CONNECTION_CLOSE.
   116  // after this time all information about the old connection will be deleted
   117  const RetiredConnectionIDDeleteTimeout = 5 * time.Second
   118  
   119  // MinStreamFrameSize is the minimum size that has to be left in a packet, so that we add another STREAM frame.
   120  // This avoids splitting up STREAM frames into small pieces, which has 2 advantages:
   121  // 1. it reduces the framing overhead
   122  // 2. it reduces the head-of-line blocking, when a packet is lost
   123  const MinStreamFrameSize ByteCount = 128
   124  
   125  // MaxPostHandshakeCryptoFrameSize is the maximum size of CRYPTO frames
   126  // we send after the handshake completes.
   127  const MaxPostHandshakeCryptoFrameSize = 1000
   128  
   129  // MaxAckFrameSize is the maximum size for an ACK frame that we write
   130  // Due to the varint encoding, ACK frames can grow (almost) indefinitely large.
   131  // The MaxAckFrameSize should be large enough to encode many ACK range,
   132  // but must ensure that a maximum size ACK frame fits into one packet.
   133  const MaxAckFrameSize ByteCount = 1000
   134  
   135  // MaxDatagramFrameSize is the maximum size of a DATAGRAM frame as defined in
   136  // https://datatracker.ietf.org/doc/draft-pauly-quic-datagram/.
   137  // The size is chosen such that a DATAGRAM frame fits into a QUIC packet.
   138  const MaxDatagramFrameSize ByteCount = 1220
   139  
   140  // DatagramRcvQueueLen is the length of the receive queue for DATAGRAM frames.
   141  // See https://datatracker.ietf.org/doc/draft-pauly-quic-datagram/.
   142  const DatagramRcvQueueLen = 128
   143  
   144  // MaxNumAckRanges is the maximum number of ACK ranges that we send in an ACK frame.
   145  // It also serves as a limit for the packet history.
   146  // If at any point we keep track of more ranges, old ranges are discarded.
   147  const MaxNumAckRanges = 32
   148  
   149  // MinPacingDelay is the minimum duration that is used for packet pacing
   150  // If the packet packing frequency is higher, multiple packets might be sent at once.
   151  // Example: For a packet pacing delay of 200μs, we would send 5 packets at once, wait for 1ms, and so forth.
   152  const MinPacingDelay = time.Millisecond
   153  
   154  // DefaultConnectionIDLength is the connection ID length that is used for multiplexed connections
   155  // if no other value is configured.
   156  const DefaultConnectionIDLength = 4
   157  
   158  // MaxActiveConnectionIDs is the number of connection IDs that we're storing.
   159  const MaxActiveConnectionIDs = 4
   160  
   161  // MaxIssuedConnectionIDs is the maximum number of connection IDs that we're issuing at the same time.
   162  const MaxIssuedConnectionIDs = 6
   163  
   164  // PacketsPerConnectionID is the number of packets we send using one connection ID.
   165  // If the peer provices us with enough new connection IDs, we switch to a new connection ID.
   166  const PacketsPerConnectionID = 10000
   167  
   168  // AckDelayExponent is the ack delay exponent used when sending ACKs.
   169  const AckDelayExponent = 3
   170  
   171  // Estimated timer granularity.
   172  // The loss detection timer will not be set to a value smaller than granularity.
   173  const TimerGranularity = time.Millisecond
   174  
   175  // MaxAckDelay is the maximum time by which we delay sending ACKs.
   176  const MaxAckDelay = 25 * time.Millisecond
   177  
   178  // MaxAckDelayInclGranularity is the max_ack_delay including the timer granularity.
   179  // This is the value that should be advertised to the peer.
   180  const MaxAckDelayInclGranularity = MaxAckDelay + TimerGranularity
   181  
   182  // KeyUpdateInterval is the maximum number of packets we send or receive before initiating a key update.
   183  const KeyUpdateInterval = 100 * 1000
   184  
   185  // Max0RTTQueueingDuration is the maximum time that we store 0-RTT packets in order to wait for the corresponding Initial to be received.
   186  const Max0RTTQueueingDuration = 100 * time.Millisecond
   187  
   188  // Max0RTTQueues is the maximum number of connections that we buffer 0-RTT packets for.
   189  const Max0RTTQueues = 32
   190  
   191  // Max0RTTQueueLen is the maximum number of 0-RTT packets that we buffer for each connection.
   192  // When a new session is created, all buffered packets are passed to the session immediately.
   193  // To avoid blocking, this value has to be smaller than MaxSessionUnprocessedPackets.
   194  // To avoid packets being dropped as undecryptable by the session, this value has to be smaller than MaxUndecryptablePackets.
   195  const Max0RTTQueueLen = 31