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