1 // Copyright (c) 2016 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 #ifndef QUICHE_QUIC_CORE_QUIC_VERSION_MANAGER_H_ 6 #define QUICHE_QUIC_CORE_QUIC_VERSION_MANAGER_H_ 7 8 #include "quiche/quic/core/quic_versions.h" 9 #include "quiche/quic/platform/api/quic_export.h" 10 11 namespace quic { 12 13 // Used to generate filtered supported versions based on flags. 14 class QUIC_EXPORT_PRIVATE QuicVersionManager { 15 public: 16 // |supported_versions| should be sorted in the order of preference (typically 17 // highest supported version to the lowest supported version). 18 explicit QuicVersionManager(ParsedQuicVersionVector supported_versions); 19 virtual ~QuicVersionManager(); 20 21 // Returns currently supported QUIC versions. This vector has the same order 22 // as the versions passed to the constructor. 23 const ParsedQuicVersionVector& GetSupportedVersions(); 24 25 // Returns currently supported versions using HTTP/3. 26 const ParsedQuicVersionVector& GetSupportedVersionsWithOnlyHttp3(); 27 28 // Returns the list of supported ALPNs, based on the current supported 29 // versions and any custom additions by subclasses. 30 const std::vector<std::string>& GetSupportedAlpns(); 31 32 protected: 33 // If the value of any reloadable flag is different from the cached value, 34 // re-filter |filtered_supported_versions_| and update the cached flag values. 35 // Otherwise, does nothing. 36 // TODO(dschinazi): Make private when deprecating 37 // FLAGS_gfe2_restart_flag_quic_disable_old_alt_svc_format. 38 void MaybeRefilterSupportedVersions(); 39 40 // Refilters filtered_supported_versions_. 41 virtual void RefilterSupportedVersions(); 42 43 // RefilterSupportedVersions() must be called before calling this method. 44 // TODO(dschinazi): Remove when deprecating 45 // FLAGS_gfe2_restart_flag_quic_disable_old_alt_svc_format. filtered_transport_versions()46 const QuicTransportVersionVector& filtered_transport_versions() const { 47 return filtered_transport_versions_; 48 } 49 50 // Subclasses may add custom ALPNs to the supported list by overriding 51 // RefilterSupportedVersions() to first call 52 // QuicVersionManager::RefilterSupportedVersions() then AddCustomAlpn(). 53 // Must not be called elsewhere. 54 void AddCustomAlpn(const std::string& alpn); 55 56 private: 57 // Cached value of reloadable flags. 58 // quic_enable_version_2_draft_08 flag 59 bool enable_version_2_draft_08_ = false; 60 // quic_disable_version_rfcv1 flag 61 bool disable_version_rfcv1_ = true; 62 // quic_disable_version_draft_29 flag 63 bool disable_version_draft_29_ = true; 64 // quic_disable_version_q050 flag 65 bool disable_version_q050_ = true; 66 // quic_disable_version_q046 flag 67 bool disable_version_q046_ = true; 68 // quic_disable_version_q043 flag 69 bool disable_version_q043_ = true; 70 71 // The list of versions that may be supported. 72 const ParsedQuicVersionVector allowed_supported_versions_; 73 74 // The following vectors are calculated from reloadable flags by 75 // RefilterSupportedVersions(). It is performed lazily when first needed, and 76 // after that, since the calculation is relatively expensive, only if the flag 77 // values change. 78 79 // This vector contains QUIC versions which are currently supported based on 80 // flags. 81 ParsedQuicVersionVector filtered_supported_versions_; 82 // Currently supported versions using HTTP/3. 83 ParsedQuicVersionVector filtered_supported_versions_with_http3_; 84 // This vector contains the transport versions from 85 // |filtered_supported_versions_|. No guarantees are made that the same 86 // transport version isn't repeated. 87 QuicTransportVersionVector filtered_transport_versions_; 88 // Contains the list of ALPNs corresponding to filtered_supported_versions_ 89 // with custom ALPNs added. 90 std::vector<std::string> filtered_supported_alpns_; 91 }; 92 93 } // namespace quic 94 95 #endif // QUICHE_QUIC_CORE_QUIC_VERSION_MANAGER_H_ 96