params.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package protocol
  2. import "time"
  3. // MaxPacketSizeIPv4 is the maximum packet size that we use for sending IPv4 packets.
  4. const MaxPacketSizeIPv4 = 1252
  5. // MaxPacketSizeIPv6 is the maximum packet size that we use for sending IPv6 packets.
  6. const MaxPacketSizeIPv6 = 1232
  7. const defaultMaxCongestionWindowPackets = 1000
  8. // DefaultMaxCongestionWindow is the default for the max congestion window
  9. const DefaultMaxCongestionWindow ByteCount = defaultMaxCongestionWindowPackets * DefaultTCPMSS
  10. // InitialCongestionWindow is the initial congestion window in QUIC packets
  11. const InitialCongestionWindow ByteCount = 32 * DefaultTCPMSS
  12. // MaxUndecryptablePackets limits the number of undecryptable packets that are queued in the session.
  13. const MaxUndecryptablePackets = 10
  14. // ConnectionFlowControlMultiplier determines how much larger the connection flow control windows needs to be relative to any stream's flow control window
  15. // This is the value that Chromium is using
  16. const ConnectionFlowControlMultiplier = 1.5
  17. // InitialMaxStreamData is the stream-level flow control window for receiving data
  18. const InitialMaxStreamData = (1 << 10) * 512 // 512 kb
  19. // InitialMaxData is the connection-level flow control window for receiving data
  20. const InitialMaxData = ConnectionFlowControlMultiplier * InitialMaxStreamData
  21. // DefaultMaxReceiveStreamFlowControlWindow is the default maximum stream-level flow control window for receiving data, for the server
  22. const DefaultMaxReceiveStreamFlowControlWindow = 6 * (1 << 20) // 6 MB
  23. // DefaultMaxReceiveConnectionFlowControlWindow is the default connection-level flow control window for receiving data, for the server
  24. const DefaultMaxReceiveConnectionFlowControlWindow = 15 * (1 << 20) // 12 MB
  25. // WindowUpdateThreshold is the fraction of the receive window that has to be consumed before an higher offset is advertised to the client
  26. const WindowUpdateThreshold = 0.25
  27. // DefaultMaxIncomingStreams is the maximum number of streams that a peer may open
  28. const DefaultMaxIncomingStreams = 100
  29. // DefaultMaxIncomingUniStreams is the maximum number of unidirectional streams that a peer may open
  30. const DefaultMaxIncomingUniStreams = 100
  31. // MaxSessionUnprocessedPackets is the max number of packets stored in each session that are not yet processed.
  32. const MaxSessionUnprocessedPackets = defaultMaxCongestionWindowPackets
  33. // SkipPacketAveragePeriodLength is the average period length in which one packet number is skipped to prevent an Optimistic ACK attack
  34. const SkipPacketAveragePeriodLength PacketNumber = 500
  35. // MaxTrackedSkippedPackets is the maximum number of skipped packet numbers the SentPacketHandler keep track of for Optimistic ACK attack mitigation
  36. const MaxTrackedSkippedPackets = 10
  37. // MaxAcceptQueueSize is the maximum number of sessions that the server queues for accepting.
  38. // If the queue is full, new connection attempts will be rejected.
  39. const MaxAcceptQueueSize = 32
  40. // CookieExpiryTime is the valid time of a cookie
  41. const CookieExpiryTime = 24 * time.Hour
  42. // MaxOutstandingSentPackets is maximum number of packets saved for retransmission.
  43. // When reached, it imposes a soft limit on sending new packets:
  44. // Sending ACKs and retransmission is still allowed, but now new regular packets can be sent.
  45. const MaxOutstandingSentPackets = 2 * defaultMaxCongestionWindowPackets
  46. // MaxTrackedSentPackets is maximum number of sent packets saved for retransmission.
  47. // When reached, no more packets will be sent.
  48. // This value *must* be larger than MaxOutstandingSentPackets.
  49. const MaxTrackedSentPackets = MaxOutstandingSentPackets * 5 / 4
  50. // MaxTrackedReceivedAckRanges is the maximum number of ACK ranges tracked
  51. const MaxTrackedReceivedAckRanges = defaultMaxCongestionWindowPackets
  52. // MaxNonRetransmittableAcks is the maximum number of packets containing an ACK, but no retransmittable frames, that we send in a row
  53. const MaxNonRetransmittableAcks = 19
  54. // MaxStreamFrameSorterGaps is the maximum number of gaps between received StreamFrames
  55. // prevents DoS attacks against the streamFrameSorter
  56. const MaxStreamFrameSorterGaps = 1000
  57. // MaxCryptoStreamOffset is the maximum offset allowed on any of the crypto streams.
  58. // This limits the size of the ClientHello and Certificates that can be received.
  59. const MaxCryptoStreamOffset = 16 * (1 << 10)
  60. // MinRemoteIdleTimeout is the minimum value that we accept for the remote idle timeout
  61. const MinRemoteIdleTimeout = 5 * time.Second
  62. // DefaultIdleTimeout is the default idle timeout
  63. const DefaultIdleTimeout = 30 * time.Second
  64. // DefaultHandshakeTimeout is the default timeout for a connection until the crypto handshake succeeds.
  65. const DefaultHandshakeTimeout = 10 * time.Second
  66. // RetiredConnectionIDDeleteTimeout is the time we keep closed sessions around in order to retransmit the CONNECTION_CLOSE.
  67. // after this time all information about the old connection will be deleted
  68. const RetiredConnectionIDDeleteTimeout = 5 * time.Second
  69. // MinStreamFrameSize is the minimum size that has to be left in a packet, so that we add another STREAM frame.
  70. // This avoids splitting up STREAM frames into small pieces, which has 2 advantages:
  71. // 1. it reduces the framing overhead
  72. // 2. it reduces the head-of-line blocking, when a packet is lost
  73. const MinStreamFrameSize ByteCount = 128
  74. // MaxAckFrameSize is the maximum size for an ACK frame that we write
  75. // Due to the varint encoding, ACK frames can grow (almost) indefinitely large.
  76. // The MaxAckFrameSize should be large enough to encode many ACK range,
  77. // but must ensure that a maximum size ACK frame fits into one packet.
  78. const MaxAckFrameSize ByteCount = 1000
  79. // MinPacingDelay is the minimum duration that is used for packet pacing
  80. // If the packet packing frequency is higher, multiple packets might be sent at once.
  81. // Example: For a packet pacing delay of 20 microseconds, we would send 5 packets at once, wait for 100 microseconds, and so forth.
  82. const MinPacingDelay time.Duration = 100 * time.Microsecond
  83. // DefaultConnectionIDLength is the connection ID length that is used for multiplexed connections
  84. // if no other value is configured.
  85. const DefaultConnectionIDLength = 4