1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Definitions and utility functions related to handling of QUIC versions.
6 //
7 // QUIC versions are encoded over the wire as an opaque 32bit field. The wire
8 // encoding is represented in memory as a QuicVersionLabel type (which is an
9 // alias to uint32_t). Conceptual versions are represented in memory as
10 // ParsedQuicVersion.
11 //
12 // We currently support two kinds of QUIC versions, GoogleQUIC and IETF QUIC.
13 //
14 // All GoogleQUIC versions use a wire encoding that matches the following regex
15 // when converted to ASCII: "[QT]0\d\d" (e.g. Q046). Q or T distinguishes the
16 // type of handshake used (Q for the QUIC_CRYPTO handshake, T for the QUIC+TLS
17 // handshake), and the two digits at the end contain the numeric value of
18 // the transport version used.
19 //
20 // All IETF QUIC versions use the wire encoding described in:
21 // https://tools.ietf.org/html/draft-ietf-quic-transport
22
23 #ifndef QUICHE_QUIC_CORE_QUIC_VERSIONS_H_
24 #define QUICHE_QUIC_CORE_QUIC_VERSIONS_H_
25
26 #include <cstdint>
27 #include <string>
28 #include <vector>
29
30 #include "absl/base/macros.h"
31 #include "absl/strings/string_view.h"
32 #include "quiche/quic/core/quic_tag.h"
33 #include "quiche/quic/core/quic_types.h"
34 #include "quiche/quic/platform/api/quic_export.h"
35
36 namespace quic {
37
38 // The list of existing QUIC transport versions. Note that QUIC versions are
39 // sent over the wire as an encoding of ParsedQuicVersion, which requires a
40 // QUIC transport version and handshake protocol. For transport versions of the
41 // form QUIC_VERSION_XX where XX is decimal, the enum numeric value is
42 // guaranteed to match the name. Older deprecated transport versions are
43 // documented in comments below.
44 enum QuicTransportVersion {
45 // Special case to indicate unknown/unsupported QUIC version.
46 QUIC_VERSION_UNSUPPORTED = 0,
47
48 // Version 1 was the first version of QUIC that supported versioning.
49 // Version 2 decoupled versioning of non-cryptographic parameters from the
50 // SCFG.
51 // Version 3 moved public flags into the beginning of the packet.
52 // Version 4 added support for variable-length connection IDs.
53 // Version 5 made specifying FEC groups optional.
54 // Version 6 introduced variable-length packet numbers.
55 // Version 7 introduced a lower-overhead encoding for stream frames.
56 // Version 8 made salt length equal to digest length for the RSA-PSS
57 // signatures.
58 // Version 9 added stream priority.
59 // Version 10 redid the frame type numbering.
60 // Version 11 reduced the length of null encryption authentication tag
61 // from 16 to 12 bytes.
62 // Version 12 made the sequence numbers in the ACK frames variable-sized.
63 // Version 13 added the dedicated header stream.
64 // Version 14 added byte_offset to RST_STREAM frame.
65 // Version 15 added a list of packets recovered using FEC to the ACK frame.
66 // Version 16 added STOP_WAITING frame.
67 // Version 17 added per-stream flow control.
68 // Version 18 added PING frame.
69 // Version 19 added connection-level flow control
70 // Version 20 allowed to set stream- and connection-level flow control windows
71 // to different values.
72 // Version 21 made header and crypto streams flow-controlled.
73 // Version 22 added support for SCUP (server config update) messages.
74 // Version 23 added timestamps into the ACK frame.
75 // Version 24 added SPDY/4 header compression.
76 // Version 25 added support for SPDY/4 header keys and removed error_details
77 // from RST_STREAM frame.
78 // Version 26 added XLCT (expected leaf certificate) tag into CHLO.
79 // Version 27 added a nonce into SHLO.
80 // Version 28 allowed receiver to refuse creating a requested stream.
81 // Version 29 added support for QUIC_STREAM_NO_ERROR.
82 // Version 30 added server-side support for certificate transparency.
83 // Version 31 incorporated the hash of CHLO into the crypto proof supplied by
84 // the server.
85 // Version 32 removed FEC-related fields from wire format.
86 // Version 33 added diversification nonces.
87 // Version 34 removed entropy bits from packets and ACK frames, removed
88 // private flag from packet header and changed the ACK format to
89 // specify ranges of packets acknowledged rather than missing
90 // ranges.
91 // Version 35 allows endpoints to independently set stream limit.
92 // Version 36 added support for forced head-of-line blocking experiments.
93 // Version 37 added perspective into null encryption.
94 // Version 38 switched to IETF padding frame format and support for NSTP (no
95 // stop waiting frame) connection option.
96
97 // Version 39 writes integers and floating numbers in big endian, stops acking
98 // acks, sends a connection level WINDOW_UPDATE every 20 sent packets which do
99 // not contain retransmittable frames.
100
101 // Version 40 was an attempt to convert QUIC to IETF frame format; it was
102 // never shipped due to a bug.
103 // Version 41 was a bugfix for version 40. The working group changed the wire
104 // format before it shipped, which caused it to be never shipped
105 // and all the changes from it to be reverted. No changes from v40
106 // or v41 are present in subsequent versions.
107 // Version 42 allowed receiving overlapping stream data.
108
109 // Version 43 PRIORITY frames are sent by client and accepted by server.
110 // Version 44 used IETF header format from draft-ietf-quic-invariants-05.
111
112 // Version 45 added MESSAGE frame.
113
114 QUIC_VERSION_46 = 46, // Use IETF draft-17 header format with demultiplexing
115 // bit.
116 // Version 47 added variable-length QUIC server connection IDs.
117 // Version 48 added CRYPTO frames for the handshake.
118 // Version 49 added client connection IDs, long header lengths, and the IETF
119 // header format from draft-ietf-quic-invariants-06
120 // Number 50 added header protection and initial obfuscators.
121 // Number 51 was T051 which used draft-29 features but with GoogleQUIC frames.
122 // Number 70 used to represent draft-ietf-quic-transport-25.
123 // Number 71 used to represent draft-ietf-quic-transport-27.
124 // Number 72 used to represent draft-ietf-quic-transport-28.
125 QUIC_VERSION_IETF_DRAFT_29 = 73, // draft-ietf-quic-transport-29.
126 QUIC_VERSION_IETF_RFC_V1 = 80, // RFC 9000.
127 // Number 81 used to represent draft-ietf-quic-v2-01.
128 QUIC_VERSION_IETF_RFC_V2 = 82, // RFC 9369.
129 // Version 99 was a dumping ground for IETF QUIC changes which were not yet
130 // ready for production between 2018-02 and 2020-02.
131
132 // QUIC_VERSION_RESERVED_FOR_NEGOTIATION is sent over the wire as ?a?a?a?a
133 // which is part of a range reserved by the IETF for version negotiation
134 // testing (see the "Versions" section of draft-ietf-quic-transport).
135 // This version is intentionally meant to never be supported to trigger
136 // version negotiation when proposed by clients and to prevent client
137 // ossification when sent by servers.
138 QUIC_VERSION_RESERVED_FOR_NEGOTIATION = 999,
139 };
140
141 // Helper function which translates from a QuicTransportVersion to a string.
142 // Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
143 QUICHE_EXPORT std::string QuicVersionToString(
144 QuicTransportVersion transport_version);
145
146 // The crypto handshake protocols that can be used with QUIC.
147 // We are planning on eventually deprecating PROTOCOL_QUIC_CRYPTO in favor of
148 // PROTOCOL_TLS1_3.
149 enum HandshakeProtocol {
150 PROTOCOL_UNSUPPORTED,
151 PROTOCOL_QUIC_CRYPTO,
152 PROTOCOL_TLS1_3,
153 };
154
155 // Helper function which translates from a HandshakeProtocol to a string.
156 QUICHE_EXPORT std::string HandshakeProtocolToString(
157 HandshakeProtocol handshake_protocol);
158
159 // Returns whether |transport_version| uses CRYPTO frames for the handshake
160 // instead of stream 1.
QuicVersionUsesCryptoFrames(QuicTransportVersion transport_version)161 QUICHE_EXPORT constexpr bool QuicVersionUsesCryptoFrames(
162 QuicTransportVersion transport_version) {
163 // CRYPTO frames were added in version 48.
164 return transport_version > QUIC_VERSION_46;
165 }
166
167 // Returns whether this combination of handshake protocol and transport
168 // version is allowed. For example, {PROTOCOL_TLS1_3, QUIC_VERSION_46} is NOT
169 // allowed as TLS requires crypto frames which v46 does not support. Note that
170 // UnsupportedQuicVersion is a valid version.
ParsedQuicVersionIsValid(HandshakeProtocol handshake_protocol,QuicTransportVersion transport_version)171 QUICHE_EXPORT constexpr bool ParsedQuicVersionIsValid(
172 HandshakeProtocol handshake_protocol,
173 QuicTransportVersion transport_version) {
174 bool transport_version_is_valid = false;
175 constexpr QuicTransportVersion valid_transport_versions[] = {
176 QUIC_VERSION_IETF_RFC_V2,
177 QUIC_VERSION_IETF_RFC_V1,
178 QUIC_VERSION_IETF_DRAFT_29,
179 QUIC_VERSION_46,
180 QUIC_VERSION_RESERVED_FOR_NEGOTIATION,
181 QUIC_VERSION_UNSUPPORTED,
182 };
183 for (size_t i = 0; i < ABSL_ARRAYSIZE(valid_transport_versions); ++i) {
184 if (transport_version == valid_transport_versions[i]) {
185 transport_version_is_valid = true;
186 break;
187 }
188 }
189 if (!transport_version_is_valid) {
190 return false;
191 }
192 switch (handshake_protocol) {
193 case PROTOCOL_UNSUPPORTED:
194 return transport_version == QUIC_VERSION_UNSUPPORTED;
195 case PROTOCOL_QUIC_CRYPTO:
196 return transport_version != QUIC_VERSION_UNSUPPORTED &&
197 transport_version != QUIC_VERSION_RESERVED_FOR_NEGOTIATION &&
198 transport_version != QUIC_VERSION_IETF_DRAFT_29 &&
199 transport_version != QUIC_VERSION_IETF_RFC_V1 &&
200 transport_version != QUIC_VERSION_IETF_RFC_V2;
201 case PROTOCOL_TLS1_3:
202 return transport_version != QUIC_VERSION_UNSUPPORTED &&
203 QuicVersionUsesCryptoFrames(transport_version);
204 }
205 return false;
206 }
207
208 // A parsed QUIC version label which determines that handshake protocol
209 // and the transport version.
210 struct QUICHE_EXPORT ParsedQuicVersion {
211 HandshakeProtocol handshake_protocol;
212 QuicTransportVersion transport_version;
213
ParsedQuicVersionParsedQuicVersion214 constexpr ParsedQuicVersion(HandshakeProtocol handshake_protocol,
215 QuicTransportVersion transport_version)
216 : handshake_protocol(handshake_protocol),
217 transport_version(transport_version) {
218 QUICHE_DCHECK(
219 ParsedQuicVersionIsValid(handshake_protocol, transport_version))
220 << QuicVersionToString(transport_version) << " "
221 << HandshakeProtocolToString(handshake_protocol);
222 }
223
ParsedQuicVersionParsedQuicVersion224 constexpr ParsedQuicVersion(const ParsedQuicVersion& other)
225 : ParsedQuicVersion(other.handshake_protocol, other.transport_version) {}
226
227 ParsedQuicVersion& operator=(const ParsedQuicVersion& other) {
228 QUICHE_DCHECK(ParsedQuicVersionIsValid(other.handshake_protocol,
229 other.transport_version))
230 << QuicVersionToString(other.transport_version) << " "
231 << HandshakeProtocolToString(other.handshake_protocol);
232 if (this != &other) {
233 handshake_protocol = other.handshake_protocol;
234 transport_version = other.transport_version;
235 }
236 return *this;
237 }
238
239 bool operator==(const ParsedQuicVersion& other) const {
240 return handshake_protocol == other.handshake_protocol &&
241 transport_version == other.transport_version;
242 }
243
244 bool operator!=(const ParsedQuicVersion& other) const {
245 return handshake_protocol != other.handshake_protocol ||
246 transport_version != other.transport_version;
247 }
248
RFCv2ParsedQuicVersion249 static constexpr ParsedQuicVersion RFCv2() {
250 return ParsedQuicVersion(PROTOCOL_TLS1_3, QUIC_VERSION_IETF_RFC_V2);
251 }
252
RFCv1ParsedQuicVersion253 static constexpr ParsedQuicVersion RFCv1() {
254 return ParsedQuicVersion(PROTOCOL_TLS1_3, QUIC_VERSION_IETF_RFC_V1);
255 }
256
Draft29ParsedQuicVersion257 static constexpr ParsedQuicVersion Draft29() {
258 return ParsedQuicVersion(PROTOCOL_TLS1_3, QUIC_VERSION_IETF_DRAFT_29);
259 }
260
Q046ParsedQuicVersion261 static constexpr ParsedQuicVersion Q046() {
262 return ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_46);
263 }
264
UnsupportedParsedQuicVersion265 static constexpr ParsedQuicVersion Unsupported() {
266 return ParsedQuicVersion(PROTOCOL_UNSUPPORTED, QUIC_VERSION_UNSUPPORTED);
267 }
268
ReservedForNegotiationParsedQuicVersion269 static constexpr ParsedQuicVersion ReservedForNegotiation() {
270 return ParsedQuicVersion(PROTOCOL_TLS1_3,
271 QUIC_VERSION_RESERVED_FOR_NEGOTIATION);
272 }
273
274 // Returns whether our codebase understands this version. This should only be
275 // called on valid versions, see ParsedQuicVersionIsValid. Assuming the
276 // version is valid, IsKnown returns whether the version is not
277 // UnsupportedQuicVersion.
278 bool IsKnown() const;
279
280 bool KnowsWhichDecrypterToUse() const;
281
282 // Returns whether this version uses keys derived from the Connection ID for
283 // ENCRYPTION_INITIAL keys (instead of NullEncrypter/NullDecrypter).
284 bool UsesInitialObfuscators() const;
285
286 // Indicates that this QUIC version does not have an enforced minimum value
287 // for flow control values negotiated during the handshake.
288 bool AllowsLowFlowControlLimits() const;
289
290 // Returns whether header protection is used in this version of QUIC.
291 bool HasHeaderProtection() const;
292
293 // Returns whether this version supports IETF RETRY packets.
294 bool SupportsRetry() const;
295
296 // Returns true if this version sends variable length packet number in long
297 // header.
298 bool SendsVariableLengthPacketNumberInLongHeader() const;
299
300 // Returns whether this version allows server connection ID lengths
301 // that are not 64 bits.
302 bool AllowsVariableLengthConnectionIds() const;
303
304 // Returns whether this version supports client connection ID.
305 bool SupportsClientConnectionIds() const;
306
307 // Returns whether this version supports long header 8-bit encoded
308 // connection ID lengths as described in draft-ietf-quic-invariants-06 and
309 // draft-ietf-quic-transport-22.
310 bool HasLengthPrefixedConnectionIds() const;
311
312 // Returns whether this version supports IETF style anti-amplification limit,
313 // i.e., server will send no more than FLAGS_quic_anti_amplification_factor
314 // times received bytes until address can be validated.
315 bool SupportsAntiAmplificationLimit() const;
316
317 // Returns true if this version can send coalesced packets.
318 bool CanSendCoalescedPackets() const;
319
320 // Returns true if this version supports the old Google-style Alt-Svc
321 // advertisement format.
322 bool SupportsGoogleAltSvcFormat() const;
323
324 // If true, HTTP/3 instead of gQUIC will be used at the HTTP layer.
325 // Notable changes are:
326 // * Headers stream no longer exists.
327 // * PRIORITY, HEADERS are moved from headers stream to HTTP/3 control stream.
328 // * PUSH_PROMISE is moved to request stream.
329 // * Unidirectional streams will have their first byte as a stream type.
330 // * HEADERS frames are compressed using QPACK.
331 // * DATA frame has frame headers.
332 // * GOAWAY is moved to HTTP layer.
333 bool UsesHttp3() const;
334
335 // Returns whether the transport_version supports the variable length integer
336 // length field as defined by IETF QUIC draft-13 and later.
337 bool HasLongHeaderLengths() const;
338
339 // Returns whether |transport_version| uses CRYPTO frames for the handshake
340 // instead of stream 1.
341 bool UsesCryptoFrames() const;
342
343 // Returns whether |transport_version| makes use of IETF QUIC
344 // frames or not.
345 bool HasIetfQuicFrames() const;
346
347 // Returns whether this version uses the legacy TLS extension codepoint.
348 bool UsesLegacyTlsExtension() const;
349
350 // Returns whether this version uses PROTOCOL_TLS1_3.
351 bool UsesTls() const;
352
353 // Returns whether this version uses PROTOCOL_QUIC_CRYPTO.
354 bool UsesQuicCrypto() const;
355
356 // Returns whether this version uses the QUICv2 Long Header Packet Types.
357 bool UsesV2PacketTypes() const;
358
359 // Returns true if this shares ALPN codes with RFCv1, and endpoints should
360 // choose RFCv1 when presented with a v1 ALPN. Note that this is false for
361 // RFCv1.
362 bool AlpnDeferToRFCv1() const;
363 };
364
365 QUICHE_EXPORT ParsedQuicVersion UnsupportedQuicVersion();
366
367 QUICHE_EXPORT ParsedQuicVersion QuicVersionReservedForNegotiation();
368
369 QUICHE_EXPORT std::ostream& operator<<(std::ostream& os,
370 const ParsedQuicVersion& version);
371
372 using ParsedQuicVersionVector = std::vector<ParsedQuicVersion>;
373
374 QUICHE_EXPORT std::ostream& operator<<(std::ostream& os,
375 const ParsedQuicVersionVector& versions);
376
377 // Representation of the on-the-wire QUIC version number. Will be written/read
378 // to the wire in network-byte-order.
379 using QuicVersionLabel = uint32_t;
380 using QuicVersionLabelVector = std::vector<QuicVersionLabel>;
381
382 // Constructs a version label from the 4 bytes such that the on-the-wire
383 // order will be: d, c, b, a.
384 QUICHE_EXPORT QuicVersionLabel MakeVersionLabel(uint8_t a, uint8_t b, uint8_t c,
385 uint8_t d);
386
387 QUICHE_EXPORT std::ostream& operator<<(
388 std::ostream& os, const QuicVersionLabelVector& version_labels);
389
390 // This vector contains all crypto handshake protocols that are supported.
SupportedHandshakeProtocols()391 constexpr std::array<HandshakeProtocol, 2> SupportedHandshakeProtocols() {
392 return {PROTOCOL_TLS1_3, PROTOCOL_QUIC_CRYPTO};
393 }
394
SupportedVersions()395 constexpr std::array<ParsedQuicVersion, 4> SupportedVersions() {
396 return {
397 ParsedQuicVersion::RFCv2(),
398 ParsedQuicVersion::RFCv1(),
399 ParsedQuicVersion::Draft29(),
400 ParsedQuicVersion::Q046(),
401 };
402 }
403
404 using QuicTransportVersionVector = std::vector<QuicTransportVersion>;
405
406 QUICHE_EXPORT std::ostream& operator<<(
407 std::ostream& os, const QuicTransportVersionVector& transport_versions);
408
409 // Returns a vector of supported QUIC versions.
410 QUICHE_EXPORT ParsedQuicVersionVector AllSupportedVersions();
411
412 // Returns a vector of supported QUIC versions, with any versions disabled by
413 // flags excluded.
414 QUICHE_EXPORT ParsedQuicVersionVector CurrentSupportedVersions();
415
416 // Obsolete QUIC supported versions are versions that are supported in
417 // QUICHE but which should not be used by by modern clients.
418 QUICHE_EXPORT ParsedQuicVersionVector ObsoleteSupportedVersions();
419
420 // Returns true if `version` is in `ObsoleteSupportedVersions`.
421 QUICHE_EXPORT bool IsObsoleteSupportedVersion(ParsedQuicVersion version);
422
423 // Returns a vector of supported QUIC versions which should be used by clients.
424 // Server need to support old clients, but new client should only be using
425 // QUIC versions in this list.
426 QUICHE_EXPORT ParsedQuicVersionVector CurrentSupportedVersionsForClients();
427
428 // Returns a vector of QUIC versions from |versions| which exclude any versions
429 // which are disabled by flags.
430 QUICHE_EXPORT ParsedQuicVersionVector
431 FilterSupportedVersions(ParsedQuicVersionVector versions);
432
433 // Returns a subset of AllSupportedVersions() with
434 // handshake_protocol == PROTOCOL_QUIC_CRYPTO, in the same order.
435 // Deprecated; only to be used in components that do not yet support
436 // PROTOCOL_TLS1_3.
437 QUICHE_EXPORT ParsedQuicVersionVector AllSupportedVersionsWithQuicCrypto();
438
439 // Returns a subset of CurrentSupportedVersions() with
440 // handshake_protocol == PROTOCOL_QUIC_CRYPTO, in the same order.
441 QUICHE_EXPORT ParsedQuicVersionVector CurrentSupportedVersionsWithQuicCrypto();
442
443 // Returns a subset of AllSupportedVersions() with
444 // handshake_protocol == PROTOCOL_TLS1_3, in the same order.
445 QUICHE_EXPORT ParsedQuicVersionVector AllSupportedVersionsWithTls();
446
447 // Returns a subset of CurrentSupportedVersions() with handshake_protocol ==
448 // PROTOCOL_TLS1_3.
449 QUICHE_EXPORT ParsedQuicVersionVector CurrentSupportedVersionsWithTls();
450
451 // Returns a subset of CurrentSupportedVersions() using HTTP/3 at the HTTP
452 // layer.
453 QUICHE_EXPORT ParsedQuicVersionVector CurrentSupportedHttp3Versions();
454
455 // Returns QUIC version of |index| in result of |versions|. Returns
456 // UnsupportedQuicVersion() if |index| is out of bounds.
457 QUICHE_EXPORT ParsedQuicVersionVector
458 ParsedVersionOfIndex(const ParsedQuicVersionVector& versions, int index);
459
460 // QuicVersionLabel is written to and read from the wire, but we prefer to use
461 // the more readable ParsedQuicVersion at other levels.
462 // Helper function which translates from a QuicVersionLabel to a
463 // ParsedQuicVersion.
464 QUICHE_EXPORT ParsedQuicVersion
465 ParseQuicVersionLabel(QuicVersionLabel version_label);
466
467 // Helper function that translates from a QuicVersionLabelVector to a
468 // ParsedQuicVersionVector.
469 QUICHE_EXPORT ParsedQuicVersionVector
470 ParseQuicVersionLabelVector(const QuicVersionLabelVector& version_labels);
471
472 // Parses a QUIC version string such as "Q043" or "T051". Also supports parsing
473 // ALPN such as "h3-29" or "h3-Q046". For PROTOCOL_QUIC_CRYPTO versions, also
474 // supports parsing numbers such as "46".
475 QUICHE_EXPORT ParsedQuicVersion
476 ParseQuicVersionString(absl::string_view version_string);
477
478 // Parses a comma-separated list of QUIC version strings. Supports parsing by
479 // label, ALPN and numbers for PROTOCOL_QUIC_CRYPTO. Skips unknown versions.
480 // For example: "h3-29,Q046,46".
481 QUICHE_EXPORT ParsedQuicVersionVector
482 ParseQuicVersionVectorString(absl::string_view versions_string);
483
484 // Constructs a QuicVersionLabel from the provided ParsedQuicVersion.
485 // QuicVersionLabel is written to and read from the wire, but we prefer to use
486 // the more readable ParsedQuicVersion at other levels.
487 // Helper function which translates from a ParsedQuicVersion to a
488 // QuicVersionLabel. Returns 0 if |parsed_version| is unsupported.
489 QUICHE_EXPORT QuicVersionLabel
490 CreateQuicVersionLabel(ParsedQuicVersion parsed_version);
491
492 // Constructs a QuicVersionLabelVector from the provided
493 // ParsedQuicVersionVector.
494 QUICHE_EXPORT QuicVersionLabelVector
495 CreateQuicVersionLabelVector(const ParsedQuicVersionVector& versions);
496
497 // Helper function which translates from a QuicVersionLabel to a string.
498 QUICHE_EXPORT std::string QuicVersionLabelToString(
499 QuicVersionLabel version_label);
500
501 // Helper function which translates from a QuicVersionLabel string to a
502 // ParsedQuicVersion. The version label string must be of the form returned
503 // by QuicVersionLabelToString, for example, "00000001" or "Q046", but not
504 // "51303433" (the hex encoding of the Q064 version label). Returns
505 // the ParsedQuicVersion which matches the label or UnsupportedQuicVersion()
506 // otherwise.
507 QUICHE_EXPORT ParsedQuicVersion
508 ParseQuicVersionLabelString(absl::string_view version_label_string);
509
510 // Returns |separator|-separated list of string representations of
511 // QuicVersionLabel values in the supplied |version_labels| vector. The values
512 // after the (0-based) |skip_after_nth_version|'th are skipped.
513 QUICHE_EXPORT std::string QuicVersionLabelVectorToString(
514 const QuicVersionLabelVector& version_labels, const std::string& separator,
515 size_t skip_after_nth_version);
516
517 // Returns comma separated list of string representations of QuicVersionLabel
518 // values in the supplied |version_labels| vector.
QuicVersionLabelVectorToString(const QuicVersionLabelVector & version_labels)519 QUICHE_EXPORT inline std::string QuicVersionLabelVectorToString(
520 const QuicVersionLabelVector& version_labels) {
521 return QuicVersionLabelVectorToString(version_labels, ",",
522 std::numeric_limits<size_t>::max());
523 }
524
525 // Helper function which translates from a ParsedQuicVersion to a string.
526 // Returns strings corresponding to the on-the-wire tag.
527 QUICHE_EXPORT std::string ParsedQuicVersionToString(ParsedQuicVersion version);
528
529 // Returns a vector of supported QUIC transport versions. DEPRECATED, use
530 // AllSupportedVersions instead.
531 QUICHE_EXPORT QuicTransportVersionVector AllSupportedTransportVersions();
532
533 // Returns comma separated list of string representations of
534 // QuicTransportVersion enum values in the supplied |versions| vector.
535 QUICHE_EXPORT std::string QuicTransportVersionVectorToString(
536 const QuicTransportVersionVector& versions);
537
538 // Returns comma separated list of string representations of ParsedQuicVersion
539 // values in the supplied |versions| vector.
540 QUICHE_EXPORT std::string ParsedQuicVersionVectorToString(
541 const ParsedQuicVersionVector& versions);
542
543 // Returns |separator|-separated list of string representations of
544 // ParsedQuicVersion values in the supplied |versions| vector. The values after
545 // the (0-based) |skip_after_nth_version|'th are skipped.
546 QUICHE_EXPORT std::string ParsedQuicVersionVectorToString(
547 const ParsedQuicVersionVector& versions, const std::string& separator,
548 size_t skip_after_nth_version);
549
550 // Returns comma separated list of string representations of ParsedQuicVersion
551 // values in the supplied |versions| vector.
ParsedQuicVersionVectorToString(const ParsedQuicVersionVector & versions)552 QUICHE_EXPORT inline std::string ParsedQuicVersionVectorToString(
553 const ParsedQuicVersionVector& versions) {
554 return ParsedQuicVersionVectorToString(versions, ",",
555 std::numeric_limits<size_t>::max());
556 }
557
558 // If true, HTTP/3 instead of gQUIC will be used at the HTTP layer.
559 // Notable changes are:
560 // * Headers stream no longer exists.
561 // * PRIORITY, HEADERS are moved from headers stream to HTTP/3 control stream.
562 // * PUSH_PROMISE is moved to request stream.
563 // * Unidirectional streams will have their first byte as a stream type.
564 // * HEADERS frames are compressed using QPACK.
565 // * DATA frame has frame headers.
566 // * GOAWAY is moved to HTTP layer.
VersionUsesHttp3(QuicTransportVersion transport_version)567 QUICHE_EXPORT constexpr bool VersionUsesHttp3(
568 QuicTransportVersion transport_version) {
569 return transport_version >= QUIC_VERSION_IETF_DRAFT_29;
570 }
571
572 // Returns whether the transport_version supports the variable length integer
573 // length field as defined by IETF QUIC draft-13 and later.
QuicVersionHasLongHeaderLengths(QuicTransportVersion transport_version)574 QUICHE_EXPORT constexpr bool QuicVersionHasLongHeaderLengths(
575 QuicTransportVersion transport_version) {
576 // Long header lengths were added in version 49.
577 return transport_version > QUIC_VERSION_46;
578 }
579
580 // Returns whether |transport_version| makes use of IETF QUIC
581 // frames or not.
VersionHasIetfQuicFrames(QuicTransportVersion transport_version)582 QUICHE_EXPORT constexpr bool VersionHasIetfQuicFrames(
583 QuicTransportVersion transport_version) {
584 return VersionUsesHttp3(transport_version);
585 }
586
587 // Returns whether this version supports long header 8-bit encoded
588 // connection ID lengths as described in draft-ietf-quic-invariants-06 and
589 // draft-ietf-quic-transport-22.
590 QUICHE_EXPORT bool VersionHasLengthPrefixedConnectionIds(
591 QuicTransportVersion transport_version);
592
593 // Returns true if this version supports the old Google-style Alt-Svc
594 // advertisement format.
595 QUICHE_EXPORT bool VersionSupportsGoogleAltSvcFormat(
596 QuicTransportVersion transport_version);
597
598 // Returns whether this version allows server connection ID lengths that are
599 // not 64 bits.
600 QUICHE_EXPORT bool VersionAllowsVariableLengthConnectionIds(
601 QuicTransportVersion transport_version);
602
603 // Returns whether this version label supports long header 4-bit encoded
604 // connection ID lengths as described in draft-ietf-quic-invariants-05 and
605 // draft-ietf-quic-transport-21.
606 QUICHE_EXPORT bool QuicVersionLabelUses4BitConnectionIdLength(
607 QuicVersionLabel version_label);
608
609 // Returns the ALPN string to use in TLS for this version of QUIC.
610 QUICHE_EXPORT std::string AlpnForVersion(ParsedQuicVersion parsed_version);
611
612 // Configures the flags required to enable support for this version of QUIC.
613 QUICHE_EXPORT void QuicEnableVersion(const ParsedQuicVersion& version);
614
615 // Configures the flags required to disable support for this version of QUIC.
616 QUICHE_EXPORT void QuicDisableVersion(const ParsedQuicVersion& version);
617
618 // Returns whether support for this version of QUIC is currently enabled.
619 QUICHE_EXPORT bool QuicVersionIsEnabled(const ParsedQuicVersion& version);
620
621 } // namespace quic
622
623 #endif // QUICHE_QUIC_CORE_QUIC_VERSIONS_H_
624