quic_stream_factory.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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. #ifndef NET_QUIC_QUIC_STREAM_FACTORY_H_
  5. #define NET_QUIC_QUIC_STREAM_FACTORY_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <map>
  9. #include <memory>
  10. #include <set>
  11. #include <string>
  12. #include <vector>
  13. #include "base/containers/lru_cache.h"
  14. #include "base/gtest_prod_util.h"
  15. #include "base/memory/raw_ptr.h"
  16. #include "base/memory/weak_ptr.h"
  17. #include "base/time/tick_clock.h"
  18. #include "base/time/time.h"
  19. #include "net/base/address_list.h"
  20. #include "net/base/completion_once_callback.h"
  21. #include "net/base/host_port_pair.h"
  22. #include "net/base/net_export.h"
  23. #include "net/base/network_change_notifier.h"
  24. #include "net/base/network_handle.h"
  25. #include "net/base/proxy_server.h"
  26. #include "net/cert/cert_database.h"
  27. #include "net/dns/public/secure_dns_policy.h"
  28. #include "net/http/http_server_properties.h"
  29. #include "net/http/http_stream_factory.h"
  30. #include "net/log/net_log_with_source.h"
  31. #include "net/quic/network_connection.h"
  32. #include "net/quic/quic_chromium_client_session.h"
  33. #include "net/quic/quic_clock_skew_detector.h"
  34. #include "net/quic/quic_connectivity_monitor.h"
  35. #include "net/quic/quic_context.h"
  36. #include "net/quic/quic_crypto_client_config_handle.h"
  37. #include "net/quic/quic_session_key.h"
  38. #include "net/socket/client_socket_pool.h"
  39. #include "net/ssl/ssl_config_service.h"
  40. #include "net/third_party/quiche/src/quiche/quic/core/quic_config.h"
  41. #include "net/third_party/quiche/src/quiche/quic/core/quic_crypto_stream.h"
  42. #include "net/third_party/quiche/src/quiche/quic/core/quic_packets.h"
  43. #include "net/third_party/quiche/src/quiche/quic/core/quic_server_id.h"
  44. #include "url/scheme_host_port.h"
  45. namespace base {
  46. class Value;
  47. } // namespace base
  48. namespace quic {
  49. class QuicAlarmFactory;
  50. class QuicClock;
  51. class QuicRandom;
  52. } // namespace quic
  53. namespace net {
  54. class CTPolicyEnforcer;
  55. class CertVerifier;
  56. class ClientSocketFactory;
  57. class HostResolver;
  58. class HttpServerProperties;
  59. class NetLog;
  60. class NetworkIsolationKey;
  61. class QuicChromiumConnectionHelper;
  62. class QuicCryptoClientStreamFactory;
  63. class QuicServerInfo;
  64. class QuicStreamFactory;
  65. class QuicContext;
  66. class SCTAuditingDelegate;
  67. class SocketPerformanceWatcherFactory;
  68. class SocketTag;
  69. class TransportSecurityState;
  70. namespace test {
  71. class QuicStreamFactoryPeer;
  72. } // namespace test
  73. // Maximum number of not currently in use QuicCryptoClientConfig that can be
  74. // stored in |recent_crypto_config_map_|.
  75. //
  76. // TODO(mmenke): Should figure out a reasonable value of this, using field
  77. // trials. The optimal value may increase over time, as QUIC becomes more
  78. // prevalent. Whether or not NetworkIsolationKeys end up including subframe URLs
  79. // will also influence the ideal value.
  80. const int kMaxRecentCryptoConfigs = 100;
  81. enum QuicPlatformNotification {
  82. NETWORK_CONNECTED,
  83. NETWORK_MADE_DEFAULT,
  84. NETWORK_DISCONNECTED,
  85. NETWORK_SOON_TO_DISCONNECT,
  86. NETWORK_IP_ADDRESS_CHANGED,
  87. NETWORK_NOTIFICATION_MAX
  88. };
  89. enum AllActiveSessionsGoingAwayReason {
  90. kClockSkewDetected,
  91. kIPAddressChanged,
  92. kCertDBChanged
  93. };
  94. // Encapsulates a pending request for a QuicChromiumClientSession.
  95. // If the request is still pending when it is destroyed, it will
  96. // cancel the request with the factory.
  97. class NET_EXPORT_PRIVATE QuicStreamRequest {
  98. public:
  99. explicit QuicStreamRequest(QuicStreamFactory* factory);
  100. QuicStreamRequest(const QuicStreamRequest&) = delete;
  101. QuicStreamRequest& operator=(const QuicStreamRequest&) = delete;
  102. ~QuicStreamRequest();
  103. // |cert_verify_flags| is bitwise OR'd of CertVerifier::VerifyFlags and it is
  104. // passed to CertVerifier::Verify.
  105. // |destination| will be resolved and resulting IPEndPoint used to open a
  106. // quic::QuicConnection. This can be different than
  107. // HostPortPair::FromURL(url).
  108. // When |use_dns_aliases| is true, any DNS aliases found in host resolution
  109. // are stored in the |dns_aliases_by_session_key_| map. |use_dns_aliases|
  110. // should be false in the case of a proxy.
  111. int Request(url::SchemeHostPort destination,
  112. quic::ParsedQuicVersion quic_version,
  113. PrivacyMode privacy_mode,
  114. RequestPriority priority,
  115. const SocketTag& socket_tag,
  116. const NetworkIsolationKey& network_isolation_key,
  117. SecureDnsPolicy secure_dns_policy,
  118. bool use_dns_aliases,
  119. bool require_dns_https_alpn,
  120. int cert_verify_flags,
  121. const GURL& url,
  122. const NetLogWithSource& net_log,
  123. NetErrorDetails* net_error_details,
  124. CompletionOnceCallback failed_on_default_network_callback,
  125. CompletionOnceCallback callback);
  126. // This function must be called after Request() returns ERR_IO_PENDING.
  127. // Returns true if Request() requires host resolution and it hasn't completed
  128. // yet. If true is returned, |callback| will run when host resolution
  129. // completes. It will be called with the result after host resolution during
  130. // the connection process. For example, if host resolution returns OK and then
  131. // crypto handshake returns ERR_IO_PENDING, then |callback| will run with
  132. // ERR_IO_PENDING.
  133. bool WaitForHostResolution(CompletionOnceCallback callback);
  134. // Tells QuicStreamRequest it should expect OnHostResolutionComplete()
  135. // to be called in the future.
  136. void ExpectOnHostResolution();
  137. // Will be called by the associated QuicStreamFactory::Job when host
  138. // resolution completes asynchronously after Request().
  139. void OnHostResolutionComplete(int rv);
  140. void OnRequestComplete(int rv);
  141. // Called when the original connection created on the default network for
  142. // |this| fails and a new connection has been created on the alternate
  143. // network.
  144. void OnConnectionFailedOnDefaultNetwork();
  145. // Helper method that calls |factory_|'s GetTimeDelayForWaitingJob(). It
  146. // returns the amount of time waiting job should be delayed.
  147. base::TimeDelta GetTimeDelayForWaitingJob() const;
  148. // If host resolution is underway, changes the priority of the host resolver
  149. // request.
  150. void SetPriority(RequestPriority priority);
  151. // Releases the handle to the QUIC session retrieved as a result of Request().
  152. std::unique_ptr<QuicChromiumClientSession::Handle> ReleaseSessionHandle();
  153. // Sets |session_|.
  154. void SetSession(std::unique_ptr<QuicChromiumClientSession::Handle> session);
  155. NetErrorDetails* net_error_details() { return net_error_details_; }
  156. const QuicSessionKey& session_key() const { return session_key_; }
  157. const NetLogWithSource& net_log() const { return net_log_; }
  158. bool CanUseExistingSession(const GURL& url,
  159. PrivacyMode privacy_mode,
  160. const SocketTag& socket_tag,
  161. const NetworkIsolationKey& network_isolation_key,
  162. SecureDnsPolicy secure_dns_policy,
  163. bool require_dns_https_alpn,
  164. const url::SchemeHostPort& destination) const;
  165. private:
  166. raw_ptr<QuicStreamFactory> factory_;
  167. QuicSessionKey session_key_;
  168. NetLogWithSource net_log_;
  169. CompletionOnceCallback callback_;
  170. CompletionOnceCallback failed_on_default_network_callback_;
  171. raw_ptr<NetErrorDetails> net_error_details_; // Unowned.
  172. std::unique_ptr<QuicChromiumClientSession::Handle> session_;
  173. // Set in Request(). If true, then OnHostResolutionComplete() is expected to
  174. // be called in the future.
  175. bool expect_on_host_resolution_ = false;
  176. // Callback passed to WaitForHostResolution().
  177. CompletionOnceCallback host_resolution_callback_;
  178. };
  179. // A factory for fetching QuicChromiumClientSessions.
  180. class NET_EXPORT_PRIVATE QuicStreamFactory
  181. : public NetworkChangeNotifier::IPAddressObserver,
  182. public NetworkChangeNotifier::NetworkObserver,
  183. public CertDatabase::Observer {
  184. public:
  185. // This class encompasses |destination| and |server_id|.
  186. // |destination| is a HostPortPair which is resolved
  187. // and a quic::QuicConnection is made to the resulting IP address.
  188. // |server_id| identifies the origin of the request,
  189. // the crypto handshake advertises |server_id.host()| to the server,
  190. // and the certificate is also matched against |server_id.host()|.
  191. class NET_EXPORT_PRIVATE QuicSessionAliasKey {
  192. public:
  193. QuicSessionAliasKey() = default;
  194. QuicSessionAliasKey(url::SchemeHostPort destination,
  195. QuicSessionKey session_key);
  196. ~QuicSessionAliasKey() = default;
  197. // Needed to be an element of std::set.
  198. bool operator<(const QuicSessionAliasKey& other) const;
  199. bool operator==(const QuicSessionAliasKey& other) const;
  200. const url::SchemeHostPort& destination() const { return destination_; }
  201. const quic::QuicServerId& server_id() const {
  202. return session_key_.server_id();
  203. }
  204. const QuicSessionKey& session_key() const { return session_key_; }
  205. // Returns the estimate of dynamically allocated memory in bytes.
  206. private:
  207. url::SchemeHostPort destination_;
  208. QuicSessionKey session_key_;
  209. };
  210. QuicStreamFactory(
  211. NetLog* net_log,
  212. HostResolver* host_resolver,
  213. SSLConfigService* ssl_config_service,
  214. ClientSocketFactory* client_socket_factory,
  215. HttpServerProperties* http_server_properties,
  216. CertVerifier* cert_verifier,
  217. CTPolicyEnforcer* ct_policy_enforcer,
  218. TransportSecurityState* transport_security_state,
  219. SCTAuditingDelegate* sct_auditing_delegate,
  220. SocketPerformanceWatcherFactory* socket_performance_watcher_factory,
  221. QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory,
  222. QuicContext* context);
  223. QuicStreamFactory(const QuicStreamFactory&) = delete;
  224. QuicStreamFactory& operator=(const QuicStreamFactory&) = delete;
  225. ~QuicStreamFactory() override;
  226. // Returns true if there is an existing session for |session_key| or if the
  227. // request can be pooled to an existing session to the IP address of
  228. // |destination|.
  229. bool CanUseExistingSession(const QuicSessionKey& session_key,
  230. const url::SchemeHostPort& destination) const;
  231. // Fetches a QuicChromiumClientSession to |host_port_pair| which will be
  232. // owned by |request|.
  233. // If a matching session already exists, this method will return OK. If no
  234. // matching session exists, this will return ERR_IO_PENDING and will invoke
  235. // OnRequestComplete asynchronously.
  236. // When |use_dns_aliases| is true, any DNS aliases found in host resolution
  237. // are stored in the |dns_aliases_by_session_key_| map. |use_dns_aliases|
  238. // should be false in the case of a proxy.
  239. int Create(const QuicSessionKey& session_key,
  240. url::SchemeHostPort destination,
  241. quic::ParsedQuicVersion quic_version,
  242. RequestPriority priority,
  243. bool use_dns_aliases,
  244. int cert_verify_flags,
  245. const GURL& url,
  246. const NetLogWithSource& net_log,
  247. QuicStreamRequest* request);
  248. // Called by a session when it is going away and no more streams should be
  249. // created on it.
  250. void OnSessionGoingAway(QuicChromiumClientSession* session);
  251. // Called by a session after it shuts down.
  252. void OnSessionClosed(QuicChromiumClientSession* session);
  253. // Called by a session when it blackholes after the handshake is confirmed.
  254. void OnBlackholeAfterHandshakeConfirmed(QuicChromiumClientSession* session);
  255. // Cancels a pending request.
  256. void CancelRequest(QuicStreamRequest* request);
  257. // Sets priority of a request.
  258. void SetRequestPriority(QuicStreamRequest* request, RequestPriority priority);
  259. // Closes all current sessions with specified network, QUIC error codes.
  260. // It sends connection close packet when closing connections.
  261. void CloseAllSessions(int error, quic::QuicErrorCode quic_error);
  262. base::Value QuicStreamFactoryInfoToValue() const;
  263. // Delete cached state objects in |crypto_config_|. If |origin_filter| is not
  264. // null, only objects on matching origins will be deleted.
  265. void ClearCachedStatesInCryptoConfig(
  266. const base::RepeatingCallback<bool(const GURL&)>& origin_filter);
  267. // Helper method that configures a DatagramClientSocket. Socket is
  268. // bound to the default network if the |network| param is
  269. // handles::kInvalidNetworkHandle.
  270. // Returns net_error code.
  271. int ConfigureSocket(DatagramClientSocket* socket,
  272. IPEndPoint addr,
  273. handles::NetworkHandle network,
  274. const SocketTag& socket_tag);
  275. // Finds an alternative to |old_network| from the platform's list of connected
  276. // networks. Returns handles::kInvalidNetworkHandle if no
  277. // alternative is found.
  278. handles::NetworkHandle FindAlternateNetwork(
  279. handles::NetworkHandle old_network);
  280. // Creates a datagram socket. |source| is the NetLogSource for the entity
  281. // trying to create the socket, if it has one.
  282. std::unique_ptr<DatagramClientSocket> CreateSocket(
  283. NetLog* net_log,
  284. const NetLogSource& source);
  285. // NetworkChangeNotifier::IPAddressObserver methods:
  286. // Until the servers support roaming, close all connections when the local
  287. // IP address changes.
  288. void OnIPAddressChanged() override;
  289. // NetworkChangeNotifier::NetworkObserver methods:
  290. void OnNetworkConnected(handles::NetworkHandle network) override;
  291. void OnNetworkDisconnected(handles::NetworkHandle network) override;
  292. void OnNetworkSoonToDisconnect(handles::NetworkHandle network) override;
  293. void OnNetworkMadeDefault(handles::NetworkHandle network) override;
  294. // CertDatabase::Observer methods:
  295. // We close all sessions when certificate database is changed.
  296. void OnCertDBChanged() override;
  297. bool is_quic_known_to_work_on_current_network() const {
  298. return is_quic_known_to_work_on_current_network_;
  299. }
  300. bool allow_server_migration() const { return params_.allow_server_migration; }
  301. // Returns true is gQUIC 0-RTT is disabled from quic_context.
  302. bool gquic_zero_rtt_disabled() const {
  303. return params_.disable_gquic_zero_rtt;
  304. }
  305. void set_is_quic_known_to_work_on_current_network(
  306. bool is_quic_known_to_work_on_current_network);
  307. // It returns the amount of time waiting job should be delayed.
  308. base::TimeDelta GetTimeDelayForWaitingJob(const QuicSessionKey& session_key);
  309. QuicChromiumConnectionHelper* helper() { return helper_.get(); }
  310. quic::QuicAlarmFactory* alarm_factory() { return alarm_factory_.get(); }
  311. void set_server_push_delegate(ServerPushDelegate* push_delegate) {
  312. push_delegate_ = push_delegate;
  313. }
  314. handles::NetworkHandle default_network() const { return default_network_; }
  315. // Returns the stored DNS aliases for the session key.
  316. const std::set<std::string>& GetDnsAliasesForSessionKey(
  317. const QuicSessionKey& key) const;
  318. private:
  319. class Job;
  320. class QuicCryptoClientConfigOwner;
  321. class CryptoClientConfigHandle;
  322. friend class test::QuicStreamFactoryPeer;
  323. using SessionMap = std::map<QuicSessionKey, QuicChromiumClientSession*>;
  324. using SessionIdMap =
  325. std::map<QuicChromiumClientSession*, QuicSessionAliasKey>;
  326. using AliasSet = std::set<QuicSessionAliasKey>;
  327. using SessionAliasMap = std::map<QuicChromiumClientSession*, AliasSet>;
  328. using SessionSet = std::set<QuicChromiumClientSession*>;
  329. using IPAliasMap = std::map<IPEndPoint, SessionSet>;
  330. using SessionPeerIPMap = std::map<QuicChromiumClientSession*, IPEndPoint>;
  331. using JobMap = std::map<QuicSessionKey, std::unique_ptr<Job>>;
  332. using DnsAliasesBySessionKeyMap =
  333. std::map<QuicSessionKey, std::set<std::string>>;
  334. using QuicCryptoClientConfigMap =
  335. std::map<NetworkIsolationKey,
  336. std::unique_ptr<QuicCryptoClientConfigOwner>>;
  337. bool HasMatchingIpSession(const QuicSessionAliasKey& key,
  338. const AddressList& address_list,
  339. bool use_dns_aliases);
  340. void OnJobComplete(Job* job, int rv);
  341. bool HasActiveSession(const QuicSessionKey& session_key) const;
  342. bool HasActiveJob(const QuicSessionKey& session_key) const;
  343. int CreateSession(const QuicSessionAliasKey& key,
  344. quic::ParsedQuicVersion quic_version,
  345. int cert_verify_flags,
  346. bool require_confirmation,
  347. const AddressList& address_list,
  348. base::TimeTicks dns_resolution_start_time,
  349. base::TimeTicks dns_resolution_end_time,
  350. const NetLogWithSource& net_log,
  351. QuicChromiumClientSession** session,
  352. handles::NetworkHandle* network);
  353. void ActivateSession(const QuicSessionAliasKey& key,
  354. QuicChromiumClientSession* session,
  355. std::set<std::string> dns_aliases);
  356. // Go away all active sessions. May disable session's connectivity monitoring
  357. // based on the |reason|.
  358. void MarkAllActiveSessionsGoingAway(AllActiveSessionsGoingAwayReason reason);
  359. void ConfigureInitialRttEstimate(
  360. const quic::QuicServerId& server_id,
  361. const NetworkIsolationKey& network_isolation_key,
  362. quic::QuicConfig* config);
  363. // Returns |srtt| in micro seconds from ServerNetworkStats. Returns 0 if there
  364. // is no |http_server_properties_| or if |http_server_properties_| doesn't
  365. // have ServerNetworkStats for the given |server_id|.
  366. int64_t GetServerNetworkStatsSmoothedRttInMicroseconds(
  367. const quic::QuicServerId& server_id,
  368. const NetworkIsolationKey& network_isolation_key) const;
  369. // Returns |srtt| from ServerNetworkStats. Returns null if there
  370. // is no |http_server_properties_| or if |http_server_properties_| doesn't
  371. // have ServerNetworkStats for the given |server_id|.
  372. const base::TimeDelta* GetServerNetworkStatsSmoothedRtt(
  373. const quic::QuicServerId& server_id,
  374. const NetworkIsolationKey& network_isolation_key) const;
  375. // Helper methods.
  376. bool WasQuicRecentlyBroken(const QuicSessionKey& session_key) const;
  377. // Helper method to initialize the following migration options and check
  378. // pre-requisites:
  379. // - |params_.migrate_sessions_on_network_change_v2|
  380. // - |params_.migrate_sessions_early_v2|
  381. // - |params_.migrate_idle_sessions|
  382. // - |params_.retry_on_alternate_network_before_handshake|
  383. // If pre-requisites are not met, turn off the corresponding options.
  384. void InitializeMigrationOptions();
  385. // Initializes the cached state associated with |server_id| in
  386. // |crypto_config_| with the information in |server_info|.
  387. void InitializeCachedStateInCryptoConfig(
  388. const CryptoClientConfigHandle& crypto_config_handle,
  389. const quic::QuicServerId& server_id,
  390. const std::unique_ptr<QuicServerInfo>& server_info);
  391. void ProcessGoingAwaySession(QuicChromiumClientSession* session,
  392. const quic::QuicServerId& server_id,
  393. bool was_session_active);
  394. // Insert the given alias `key` in the AliasSet for the given `session` in
  395. // the map `session_aliases_`, and add the given `dns_aliases` for
  396. // `key.session_key()` in `dns_aliases_by_session_key_`.
  397. void MapSessionToAliasKey(QuicChromiumClientSession* session,
  398. const QuicSessionAliasKey& key,
  399. std::set<std::string> dns_aliases);
  400. // For all alias keys for `session` in `session_aliases_`, erase the
  401. // corresponding DNS aliases in `dns_aliases_by_session_key_`. Then erase
  402. // `session` from `session_aliases_`.
  403. void UnmapSessionFromSessionAliases(QuicChromiumClientSession* session);
  404. // Creates a CreateCryptoConfigHandle for the specified NetworkIsolationKey.
  405. // If there's already a corresponding entry in |active_crypto_config_map_|,
  406. // reuses it. If there's a corresponding entry in |recent_crypto_config_map_|,
  407. // promotes it to |active_crypto_config_map_| and then reuses it. Otherwise,
  408. // creates a new entry in |active_crypto_config_map_|.
  409. std::unique_ptr<CryptoClientConfigHandle> CreateCryptoConfigHandle(
  410. const NetworkIsolationKey& network_isolation_key);
  411. // Salled when the indicated member of |active_crypto_config_map_| has no
  412. // outstanding references. The QuicCryptoClientConfigOwner is then moved to
  413. // |recent_crypto_config_map_|, an MRU cache.
  414. void OnAllCryptoClientRefReleased(
  415. QuicCryptoClientConfigMap::iterator& map_iterator);
  416. // Called when a network change happens.
  417. // Collect platform notification metrics, and if the change affects the
  418. // original default network interface, collect connectivity degradation
  419. // metrics from |connectivity_monitor_| and add to histograms.
  420. void CollectDataOnPlatformNotification(
  421. enum QuicPlatformNotification notification,
  422. handles::NetworkHandle affected_network) const;
  423. std::unique_ptr<QuicCryptoClientConfigHandle> GetCryptoConfigForTesting(
  424. const NetworkIsolationKey& network_isolation_key);
  425. bool CryptoConfigCacheIsEmptyForTesting(
  426. const quic::QuicServerId& server_id,
  427. const NetworkIsolationKey& network_isolation_key);
  428. const quic::ParsedQuicVersionVector& supported_versions() const {
  429. return params_.supported_versions;
  430. }
  431. // Whether QUIC is known to work on current network. This is true when QUIC is
  432. // expected to work in general, rather than whether QUIC was broken / recently
  433. // broken when used with a particular server. That information is stored in
  434. // the broken alternative service map in HttpServerProperties.
  435. bool is_quic_known_to_work_on_current_network_ = false;
  436. raw_ptr<NetLog> net_log_;
  437. raw_ptr<HostResolver> host_resolver_;
  438. raw_ptr<ClientSocketFactory> client_socket_factory_;
  439. raw_ptr<HttpServerProperties> http_server_properties_;
  440. raw_ptr<ServerPushDelegate> push_delegate_ = nullptr;
  441. const raw_ptr<CertVerifier> cert_verifier_;
  442. const raw_ptr<CTPolicyEnforcer> ct_policy_enforcer_;
  443. const raw_ptr<TransportSecurityState> transport_security_state_;
  444. const raw_ptr<SCTAuditingDelegate> sct_auditing_delegate_;
  445. raw_ptr<QuicCryptoClientStreamFactory> quic_crypto_client_stream_factory_;
  446. raw_ptr<quic::QuicRandom> random_generator_; // Unowned.
  447. raw_ptr<const quic::QuicClock> clock_; // Unowned.
  448. QuicParams params_;
  449. QuicClockSkewDetector clock_skew_detector_;
  450. // Factory which is used to create socket performance watcher. A new watcher
  451. // is created for every QUIC connection.
  452. // |socket_performance_watcher_factory_| may be null.
  453. raw_ptr<SocketPerformanceWatcherFactory> socket_performance_watcher_factory_;
  454. // The helper used for all connections.
  455. std::unique_ptr<QuicChromiumConnectionHelper> helper_;
  456. // The alarm factory used for all connections.
  457. std::unique_ptr<quic::QuicAlarmFactory> alarm_factory_;
  458. // Contains owning pointers to all sessions that currently exist.
  459. SessionIdMap all_sessions_;
  460. // Contains non-owning pointers to currently active session
  461. // (not going away session, once they're implemented).
  462. SessionMap active_sessions_;
  463. // Map from session to set of aliases that this session is known by.
  464. SessionAliasMap session_aliases_;
  465. // Map from IP address to sessions which are connected to this address.
  466. IPAliasMap ip_aliases_;
  467. // Map from session to its original peer IP address.
  468. SessionPeerIPMap session_peer_ip_;
  469. // Origins which have gone away recently.
  470. AliasSet gone_away_aliases_;
  471. // A map of DNS alias vectors by session keys.
  472. DnsAliasesBySessionKeyMap dns_aliases_by_session_key_;
  473. // When a QuicCryptoClientConfig is in use, it has one or more live
  474. // CryptoClientConfigHandles, and is stored in |active_crypto_config_map_|.
  475. // Once all the handles are deleted, it's moved to
  476. // |recent_crypto_config_map_|. If reused before it is evicted from LRUCache,
  477. // it will be removed from the cache and return to the active config map.
  478. // These two maps should never both have entries with the same
  479. // NetworkIsolationKey.
  480. QuicCryptoClientConfigMap active_crypto_config_map_;
  481. base::LRUCache<NetworkIsolationKey,
  482. std::unique_ptr<QuicCryptoClientConfigOwner>>
  483. recent_crypto_config_map_;
  484. const quic::QuicConfig config_;
  485. JobMap active_jobs_;
  486. // PING timeout for connections.
  487. quic::QuicTime::Delta ping_timeout_;
  488. quic::QuicTime::Delta reduced_ping_timeout_;
  489. // Timeout for how long the wire can have no retransmittable packets.
  490. quic::QuicTime::Delta retransmittable_on_wire_timeout_;
  491. // If more than |yield_after_packets_| packets have been read or more than
  492. // |yield_after_duration_| time has passed, then
  493. // QuicChromiumPacketReader::StartReading() yields by doing a PostTask().
  494. int yield_after_packets_;
  495. quic::QuicTime::Delta yield_after_duration_;
  496. // If |migrate_sessions_early_v2_| is true, tracks the current default
  497. // network, and is updated OnNetworkMadeDefault.
  498. // Otherwise, always set to NetworkChangeNotifier::kInvalidNetwork.
  499. handles::NetworkHandle default_network_;
  500. // Local address of socket that was created in CreateSession.
  501. IPEndPoint local_address_;
  502. // True if we need to check HttpServerProperties if QUIC was supported last
  503. // time.
  504. bool need_to_check_persisted_supports_quic_ = true;
  505. bool prefer_aes_gcm_recorded_ = false;
  506. NetworkConnection network_connection_;
  507. int num_push_streams_created_ = 0;
  508. QuicConnectivityMonitor connectivity_monitor_;
  509. raw_ptr<const base::TickClock> tick_clock_ = nullptr;
  510. raw_ptr<base::SequencedTaskRunner> task_runner_ = nullptr;
  511. const raw_ptr<SSLConfigService> ssl_config_service_;
  512. // Whether NetworkIsolationKeys should be used for
  513. // |active_crypto_config_map_|. If false, there will just be one config with
  514. // an empty NetworkIsolationKey. Whether QuicSessionAliasKeys all have an
  515. // empty NIK is based on whether socket pools are respecting NIKs, but whether
  516. // those NIKs are also used when accessing |active_crypto_config_map_| is also
  517. // gated this, which is set based on whether HttpServerProperties is
  518. // respecting NIKs, as that data is fed into the crypto config map using the
  519. // corresponding NIK.
  520. const bool use_network_isolation_key_for_crypto_configs_;
  521. base::WeakPtrFactory<QuicStreamFactory> weak_factory_{this};
  522. };
  523. } // namespace net
  524. #endif // NET_QUIC_QUIC_STREAM_FACTORY_H_