github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/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) * 8 // 8 MB
     7  
     8  // DesiredSendBufferSize is the kernel UDP send buffer size that we'd like to use.
     9  const DesiredSendBufferSize = (1 << 20) * 8 // 8 MB
    10  
    11  // InitialPacketSize is the initial (before Path MTU discovery) maximum packet size used.
    12  const InitialPacketSize = 1280
    13  
    14  // MaxCongestionWindowPackets is the maximum congestion window in packet.
    15  const MaxCongestionWindowPackets = 20000
    16  
    17  // MaxUndecryptablePackets limits the number of undecryptable packets that are queued in the connection.
    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 << 20) * 2 // 2 MB
    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  // MaxConnUnprocessedPackets is the max number of packets stored in each connection that are not yet processed.
    49  const MaxConnUnprocessedPackets = 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 connections 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  // MaxOutstandingSentPackets is maximum number of packets saved for retransmission.
    66  // When reached, it imposes a soft limit on sending new packets:
    67  // Sending ACKs and retransmission is still allowed, but now new regular packets can be sent.
    68  const MaxOutstandingSentPackets = 2 * MaxCongestionWindowPackets
    69  
    70  // MaxTrackedSentPackets is maximum number of sent packets saved for retransmission.
    71  // When reached, no more packets will be sent.
    72  // This value *must* be larger than MaxOutstandingSentPackets.
    73  const MaxTrackedSentPackets = MaxOutstandingSentPackets * 5 / 4
    74  
    75  // MaxNonAckElicitingAcks is the maximum number of packets containing an ACK,
    76  // but no ack-eliciting frames, that we send in a row
    77  const MaxNonAckElicitingAcks = 19
    78  
    79  // MaxStreamFrameSorterGaps is the maximum number of gaps between received StreamFrames
    80  // prevents DoS attacks against the streamFrameSorter
    81  const MaxStreamFrameSorterGaps = 20000
    82  
    83  // MinStreamFrameBufferSize is the minimum data length of a received STREAM frame
    84  // that we use the buffer for. This protects against a DoS where an attacker would send us
    85  // very small STREAM frames to consume a lot of memory.
    86  const MinStreamFrameBufferSize = 128
    87  
    88  // MinCoalescedPacketSize is the minimum size of a coalesced packet that we pack.
    89  // If a packet has less than this number of bytes, we won't coalesce any more packets onto it.
    90  const MinCoalescedPacketSize = 128
    91  
    92  // MaxCryptoStreamOffset is the maximum offset allowed on any of the crypto streams.
    93  // This limits the size of the ClientHello and Certificates that can be received.
    94  const MaxCryptoStreamOffset = 16 * (1 << 10)
    95  
    96  // MinRemoteIdleTimeout is the minimum value that we accept for the remote idle timeout
    97  const MinRemoteIdleTimeout = 5 * time.Second
    98  
    99  // DefaultIdleTimeout is the default idle timeout
   100  const DefaultIdleTimeout = 30 * time.Second
   101  
   102  // DefaultHandshakeIdleTimeout is the default idle timeout used before handshake completion.
   103  const DefaultHandshakeIdleTimeout = 5 * time.Second
   104  
   105  // MaxKeepAliveInterval is the maximum time until we send a packet to keep a connection alive.
   106  // It should be shorter than the time that NATs clear their mapping.
   107  const MaxKeepAliveInterval = 20 * time.Second
   108  
   109  // RetiredConnectionIDDeleteTimeout is the time we keep closed connections around in order to retransmit the CONNECTION_CLOSE.
   110  // after this time all information about the old connection will be deleted
   111  const RetiredConnectionIDDeleteTimeout = 5 * time.Second
   112  
   113  // MinStreamFrameSize is the minimum size that has to be left in a packet, so that we add another STREAM frame.
   114  // This avoids splitting up STREAM frames into small pieces, which has 2 advantages:
   115  // 1. it reduces the framing overhead
   116  // 2. it reduces the head-of-line blocking, when a packet is lost
   117  const MinStreamFrameSize ByteCount = 128
   118  
   119  // MaxPostHandshakeCryptoFrameSize is the maximum size of CRYPTO frames
   120  // we send after the handshake completes.
   121  const MaxPostHandshakeCryptoFrameSize = 1000
   122  
   123  // MaxAckFrameSize is the maximum size for an ACK frame that we write
   124  // Due to the varint encoding, ACK frames can grow (almost) indefinitely large.
   125  // The MaxAckFrameSize should be large enough to encode many ACK range,
   126  // but must ensure that a maximum size ACK frame fits into one packet.
   127  const MaxAckFrameSize ByteCount = 1000
   128  
   129  // MaxNumAckRanges is the maximum number of ACK ranges that we send in an ACK frame.
   130  // It also serves as a limit for the packet history.
   131  // If at any point we keep track of more ranges, old ranges are discarded.
   132  const MaxNumAckRanges = 32
   133  
   134  // MinPacingDelay is the minimum duration that is used for packet pacing
   135  // If the packet packing frequency is higher, multiple packets might be sent at once.
   136  // Example: For a packet pacing delay of 200μs, we would send 5 packets at once, wait for 1ms, and so forth.
   137  const MinPacingDelay = time.Millisecond
   138  
   139  // DefaultConnectionIDLength is the connection ID length that is used for multiplexed connections
   140  // if no other value is configured.
   141  const DefaultConnectionIDLength = 4
   142  
   143  // MaxActiveConnectionIDs is the number of connection IDs that we're storing.
   144  const MaxActiveConnectionIDs = 4
   145  
   146  // MaxIssuedConnectionIDs is the maximum number of connection IDs that we're issuing at the same time.
   147  const MaxIssuedConnectionIDs = 6
   148  
   149  // PacketsPerConnectionID is the number of packets we send using one connection ID.
   150  // If the peer provices us with enough new connection IDs, we switch to a new connection ID.
   151  const PacketsPerConnectionID = 10000
   152  
   153  // AckDelayExponent is the ack delay exponent used when sending ACKs.
   154  const AckDelayExponent = 3
   155  
   156  // Estimated timer granularity.
   157  // The loss detection timer will not be set to a value smaller than granularity.
   158  const TimerGranularity = time.Millisecond
   159  
   160  // MaxAckDelay is the maximum time by which we delay sending ACKs.
   161  const MaxAckDelay = 25 * time.Millisecond
   162  
   163  // MaxAckDelayInclGranularity is the max_ack_delay including the timer granularity.
   164  // This is the value that should be advertised to the peer.
   165  const MaxAckDelayInclGranularity = MaxAckDelay + TimerGranularity
   166  
   167  // KeyUpdateInterval is the maximum number of packets we send or receive before initiating a key update.
   168  const KeyUpdateInterval = 100 * 1000
   169  
   170  // Max0RTTQueueingDuration is the maximum time that we store 0-RTT packets in order to wait for the corresponding Initial to be received.
   171  const Max0RTTQueueingDuration = 100 * time.Millisecond
   172  
   173  // Max0RTTQueues is the maximum number of connections that we buffer 0-RTT packets for.
   174  const Max0RTTQueues = 32
   175  
   176  // Max0RTTQueueLen is the maximum number of 0-RTT packets that we buffer for each connection.
   177  // When a new connection is created, all buffered packets are passed to the connection immediately.
   178  // To avoid blocking, this value has to be smaller than MaxConnUnprocessedPackets.
   179  // To avoid packets being dropped as undecryptable by the connection, this value has to be smaller than MaxUndecryptablePackets.
   180  const Max0RTTQueueLen = 31