Provide constexpr equivalent to AllSupportedVersions
diff --git a/quic/core/quic_versions.cc b/quic/core/quic_versions.cc
index 372d5d0..9a0f469 100644
--- a/quic/core/quic_versions.cc
+++ b/quic/core/quic_versions.cc
@@ -206,7 +206,15 @@
}
ParsedQuicVersionVector AllSupportedVersions() {
- ParsedQuicVersionVector supported_versions;
+ const auto& supported_versions = SupportedVersions();
+ return ParsedQuicVersionVector(supported_versions.begin(),
+ supported_versions.end());
+}
+
+constexpr std::array<ParsedQuicVersion, NumSupportedVersions()>
+SupportedVersions() {
+ std::array<ParsedQuicVersion, NumSupportedVersions()> supported_versions{};
+ size_t index = 0;
for (HandshakeProtocol protocol : kSupportedHandshakeProtocols) {
for (QuicTransportVersion version : kSupportedTransportVersions) {
if (protocol == PROTOCOL_TLS1_3 &&
@@ -216,7 +224,8 @@
// We explicitly removed support for T048 and T049 to reduce test load.
continue;
}
- supported_versions.push_back(ParsedQuicVersion(protocol, version));
+ supported_versions[index] = ParsedQuicVersion(protocol, version);
+ index++;
}
}
return supported_versions;
diff --git a/quic/core/quic_versions.h b/quic/core/quic_versions.h
index 5b09ad6..44a2fa5 100644
--- a/quic/core/quic_versions.h
+++ b/quic/core/quic_versions.h
@@ -15,6 +15,7 @@
#ifndef QUICHE_QUIC_CORE_QUIC_VERSIONS_H_
#define QUICHE_QUIC_CORE_QUIC_VERSIONS_H_
+#include <array>
#include <string>
#include <vector>
@@ -143,6 +144,10 @@
: handshake_protocol(other.handshake_protocol),
transport_version(other.transport_version) {}
+ constexpr ParsedQuicVersion()
+ : handshake_protocol(PROTOCOL_UNSUPPORTED),
+ transport_version(QUIC_VERSION_UNSUPPORTED) {}
+
ParsedQuicVersion& operator=(const ParsedQuicVersion& other) {
if (this != &other) {
handshake_protocol = other.handshake_protocol;
@@ -218,13 +223,13 @@
// skipped as necessary).
//
// See go/new-quic-version for more details on how to roll out new versions.
-static const QuicTransportVersion kSupportedTransportVersions[] = {
+static const constexpr QuicTransportVersion kSupportedTransportVersions[] = {
QUIC_VERSION_99, QUIC_VERSION_50, QUIC_VERSION_49,
QUIC_VERSION_48, QUIC_VERSION_46, QUIC_VERSION_43,
};
// This vector contains all crypto handshake protocols that are supported.
-static const HandshakeProtocol kSupportedHandshakeProtocols[] = {
+static const constexpr HandshakeProtocol kSupportedHandshakeProtocols[] = {
PROTOCOL_QUIC_CRYPTO, PROTOCOL_TLS1_3};
typedef std::vector<QuicTransportVersion> QuicTransportVersionVector;
@@ -232,10 +237,42 @@
// Returns a vector of QUIC versions in kSupportedTransportVersions.
QUIC_EXPORT_PRIVATE QuicTransportVersionVector AllSupportedTransportVersions();
-// Returns a vector of QUIC versions that is the cartesian product of
-// kSupportedTransportVersions and kSupportedHandshakeProtocols.
+// DEPRECATED: Use SupportedVersions() instead.
+// Returns a vector of all ParsedQuicVersions that are valid.
QUIC_EXPORT_PRIVATE ParsedQuicVersionVector AllSupportedVersions();
+// Returns whether |transport_version| uses CRYPTO frames for the handshake
+// instead of stream 1.
+QUIC_EXPORT_PRIVATE inline constexpr bool QuicVersionUsesCryptoFrames(
+ QuicTransportVersion transport_version) {
+ return transport_version >= QUIC_VERSION_48;
+}
+
+// Returns the size of the array/vector for
+// SupportedVersions/AllSupportedVersions.
+constexpr size_t NumSupportedVersions() {
+ size_t count = 0;
+ for (HandshakeProtocol protocol : kSupportedHandshakeProtocols) {
+ for (QuicTransportVersion version : kSupportedTransportVersions) {
+ if (protocol == PROTOCOL_TLS1_3 &&
+ (!QuicVersionUsesCryptoFrames(version) ||
+ version <= QUIC_VERSION_49)) {
+ // The TLS handshake is only deployable if CRYPTO frames are also used.
+ // We explicitly removed support for T048 and T049 to reduce test load.
+ continue;
+ }
+ count++;
+ }
+ }
+ return count;
+}
+
+// Returns an array of all ParsedQuicVersions that are valid. This is a
+// constexpr equivalent of AllSupportedVersions.
+QUIC_EXPORT_PRIVATE constexpr std::array<ParsedQuicVersion,
+ NumSupportedVersions()>
+SupportedVersions();
+
// Returns a vector of QUIC versions that is the cartesian product of
// kSupportedTransportVersions and kSupportedHandshakeProtocols, with any
// versions disabled by flags excluded.
@@ -390,13 +427,6 @@
return transport_version >= QUIC_VERSION_49;
}
-// Returns whether |transport_version| uses CRYPTO frames for the handshake
-// instead of stream 1.
-QUIC_EXPORT_PRIVATE inline bool QuicVersionUsesCryptoFrames(
- QuicTransportVersion transport_version) {
- return transport_version >= QUIC_VERSION_48;
-}
-
// Returns whether |transport_version| makes use of IETF QUIC
// frames or not.
QUIC_EXPORT_PRIVATE inline bool VersionHasIetfQuicFrames(