blob: 7151d302f6466d51922c0d3a0c74a3a2974f9fa3 [file] [log] [blame]
[email protected]e13201d82012-12-12 05:00:321// 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
Ryan Hamiltona3ee93a72018-08-01 22:03:085#ifndef NET_QUIC_QUIC_STREAM_FACTORY_H_
6#define NET_QUIC_QUIC_STREAM_FACTORY_H_
[email protected]e13201d82012-12-12 05:00:327
Avi Drissman13fc8932015-12-20 04:40:468#include <stddef.h>
9#include <stdint.h>
10
[email protected]e13201d82012-12-12 05:00:3211#include <map>
Matt Menkefca05b62019-09-20 23:15:5612#include <memory>
bnc614a92d32016-04-04 13:56:0713#include <set>
[email protected]41d6b172013-01-29 16:10:5714#include <string>
[email protected]6e12d702013-11-13 00:17:1715#include <vector>
[email protected]e13201d82012-12-12 05:00:3216
cfredric8fdc22432021-10-14 03:24:0017#include "base/containers/lru_cache.h"
thestiga0e18cd2015-09-25 04:58:3618#include "base/gtest_prod_util.h"
Keishi Hattori0e45c022021-11-27 09:25:5219#include "base/memory/raw_ptr.h"
[email protected]e13201d82012-12-12 05:00:3220#include "base/memory/weak_ptr.h"
Zhongyi Shic16b4102019-02-12 00:37:4021#include "base/time/tick_clock.h"
rtenneti8332ba52015-09-17 19:33:4122#include "base/time/time.h"
[email protected]e13201d82012-12-12 05:00:3223#include "net/base/address_list.h"
Bence Békyd8a21fc32018-06-27 18:29:5824#include "net/base/completion_once_callback.h"
[email protected]e13201d82012-12-12 05:00:3225#include "net/base/host_port_pair.h"
bnc81c46c1f2016-10-04 16:25:5926#include "net/base/net_export.h"
[email protected]f698a012013-05-06 20:18:5927#include "net/base/network_change_notifier.h"
Lily Houghton582d4622018-01-22 22:43:4028#include "net/base/proxy_server.h"
[email protected]d7d1e50b2013-11-25 22:08:0929#include "net/cert/cert_database.h"
Ben Schwartz3ff4dc1e62021-04-27 21:15:2330#include "net/dns/public/secure_dns_policy.h"
zhongyi32569c62016-01-08 02:54:3031#include "net/http/http_server_properties.h"
xunjieli2608f9b2016-03-14 13:39:2332#include "net/http/http_stream_factory.h"
mikecironef22f9812016-10-04 03:40:1933#include "net/log/net_log_with_source.h"
Ryan Hamiltona3ee93a72018-08-01 22:03:0834#include "net/quic/network_connection.h"
35#include "net/quic/quic_chromium_client_session.h"
36#include "net/quic/quic_clock_skew_detector.h"
Zhongyi Shic6b3f03f2020-06-25 21:28:2237#include "net/quic/quic_connectivity_monitor.h"
Victor Vasilieva1e66d72019-12-05 17:55:3838#include "net/quic/quic_context.h"
Matt Menkefca05b62019-09-20 23:15:5639#include "net/quic/quic_crypto_client_config_handle.h"
Ryan Hamiltona3ee93a72018-08-01 22:03:0840#include "net/quic/quic_session_key.h"
Yixin Wang7f3cdc3f2017-11-10 01:44:1441#include "net/socket/client_socket_pool.h"
rch02d87792015-09-09 09:05:5342#include "net/ssl/ssl_config_service.h"
Ryan Hamiltonea4fa192022-04-12 18:30:4943#include "net/third_party/quiche/src/quiche/quic/core/quic_config.h"
44#include "net/third_party/quiche/src/quiche/quic/core/quic_crypto_stream.h"
45#include "net/third_party/quiche/src/quiche/quic/core/quic_packets.h"
46#include "net/third_party/quiche/src/quiche/quic/core/quic_server_id.h"
Dan McArdle68a5f622021-07-09 20:56:5347#include "url/scheme_host_port.h"
[email protected]e13201d82012-12-12 05:00:3248
mikecironef22f9812016-10-04 03:40:1949namespace base {
50class Value;
Ryan Hamiltona3ee93a72018-08-01 22:03:0851} // namespace base
mikecironef22f9812016-10-04 03:40:1952
Ryan Hamilton9835e662018-08-02 05:36:2753namespace quic {
54class QuicAlarmFactory;
55class QuicClock;
56class QuicRandom;
57} // namespace quic
58
[email protected]e13201d82012-12-12 05:00:3259namespace net {
60
estark6f9b3d82016-01-12 21:37:0561class CTPolicyEnforcer;
[email protected]6d1b4ed2013-07-10 03:57:5462class CertVerifier;
[email protected]e13201d82012-12-12 05:00:3263class ClientSocketFactory;
[email protected]6d1b4ed2013-07-10 03:57:5464class HostResolver;
[email protected]77c6c162013-08-17 02:57:4565class HttpServerProperties;
mikecironef22f9812016-10-04 03:40:1966class NetLog;
Matt Menke26e41542019-06-05 01:09:5167class NetworkIsolationKey;
rch12fef552016-01-15 16:26:3168class QuicChromiumConnectionHelper;
[email protected]e8ff26842013-03-22 21:02:0569class QuicCryptoClientStreamFactory;
rtenneti13c9d38d2015-10-12 21:25:0170class QuicServerInfo;
[email protected]e13201d82012-12-12 05:00:3271class QuicStreamFactory;
Victor Vasiliev7752898d2019-11-14 21:30:2272class QuicContext;
Chris Thompsonf31b2492020-07-21 05:47:4273class SCTAuditingDelegate;
tbansalfdf5665b2015-09-21 22:46:4074class SocketPerformanceWatcherFactory;
Paul Jensen8e3c5d32018-02-19 17:06:3375class SocketTag;
[email protected]080b77932014-08-04 01:22:4676class TransportSecurityState;
[email protected]e13201d82012-12-12 05:00:3277
[email protected]c49ff182013-09-28 08:33:2678namespace test {
79class QuicStreamFactoryPeer;
80} // namespace test
81
Matt Menkefca05b62019-09-20 23:15:5682// Maximum number of not currently in use QuicCryptoClientConfig that can be
83// stored in |recent_crypto_config_map_|.
84//
85// TODO(mmenke): Should figure out a reasonable value of this, using field
86// trials. The optimal value may increase over time, as QUIC becomes more
87// prevalent. Whether or not NetworkIsolationKeys end up including subframe URLs
88// will also influence the ideal value.
89const int kMaxRecentCryptoConfigs = 100;
90
Zhongyi Shib4737c62017-09-28 00:49:3191enum QuicPlatformNotification {
92 NETWORK_CONNECTED,
93 NETWORK_MADE_DEFAULT,
94 NETWORK_DISCONNECTED,
95 NETWORK_SOON_TO_DISCONNECT,
96 NETWORK_IP_ADDRESS_CHANGED,
97 NETWORK_NOTIFICATION_MAX
98};
99
Zhongyi Shic6b3f03f2020-06-25 21:28:22100enum AllActiveSessionsGoingAwayReason {
101 kClockSkewDetected,
102 kIPAddressChanged,
103 kCertDBChanged
104};
105
Yixin Wang7891a39d2017-11-08 20:59:24106// Encapsulates a pending request for a QuicChromiumClientSession.
[email protected]e13201d82012-12-12 05:00:32107// If the request is still pending when it is destroyed, it will
108// cancel the request with the factory.
109class NET_EXPORT_PRIVATE QuicStreamRequest {
110 public:
zhongyi98d6a9262017-05-19 02:47:45111 explicit QuicStreamRequest(QuicStreamFactory* factory);
Peter Boström293b1342021-09-22 17:31:43112
113 QuicStreamRequest(const QuicStreamRequest&) = delete;
114 QuicStreamRequest& operator=(const QuicStreamRequest&) = delete;
115
[email protected]e13201d82012-12-12 05:00:32116 ~QuicStreamRequest();
117
rtennetia75df622015-06-21 23:59:50118 // |cert_verify_flags| is bitwise OR'd of CertVerifier::VerifyFlags and it is
119 // passed to CertVerifier::Verify.
bnc359ed2a2016-04-29 20:43:45120 // |destination| will be resolved and resulting IPEndPoint used to open a
Ryan Hamilton8d9ee76e2018-05-29 23:52:52121 // quic::QuicConnection. This can be different than
122 // HostPortPair::FromURL(url).
Cammie Smith Barnes0f38aff2021-03-02 23:14:35123 // When |use_dns_aliases| is true, any DNS aliases found in host resolution
124 // are stored in the |dns_aliases_by_session_key_| map. |use_dns_aliases|
125 // should be false in the case of a proxy.
Dan McArdle68a5f622021-07-09 20:56:53126 int Request(url::SchemeHostPort destination,
Ryan Hamilton9ef8c102019-06-28 03:58:52127 quic::ParsedQuicVersion quic_version,
[email protected]9dd3ff0f2014-03-26 09:51:28128 PrivacyMode privacy_mode,
Yixin Wang247ea642017-11-15 01:15:50129 RequestPriority priority,
Paul Jensen8e3c5d32018-02-19 17:06:33130 const SocketTag& socket_tag,
Matt Menke26e41542019-06-05 01:09:51131 const NetworkIsolationKey& network_isolation_key,
Ben Schwartz3ff4dc1e62021-04-27 21:15:23132 SecureDnsPolicy secure_dns_policy,
Cammie Smith Barnes0f38aff2021-03-02 23:14:35133 bool use_dns_aliases,
Tsuyoshi Horo7acebce2022-05-12 06:13:23134 bool require_dns_https_alpn,
rtennetia75df622015-06-21 23:59:50135 int cert_verify_flags,
ckrasic3865ee0f2016-02-29 22:04:56136 const GURL& url,
tfarina42834112016-09-22 13:38:20137 const NetLogWithSource& net_log,
Ryan Hamilton75f197262017-08-17 14:00:07138 NetErrorDetails* net_error_details,
Zhongyi Shia6b68d112018-09-24 07:49:03139 CompletionOnceCallback failed_on_default_network_callback,
Bence Békyd8a21fc32018-06-27 18:29:58140 CompletionOnceCallback callback);
[email protected]e13201d82012-12-12 05:00:32141
Yixin Wang7c5d11a82017-12-21 02:40:00142 // This function must be called after Request() returns ERR_IO_PENDING.
143 // Returns true if Request() requires host resolution and it hasn't completed
144 // yet. If true is returned, |callback| will run when host resolution
145 // completes. It will be called with the result after host resolution during
146 // the connection process. For example, if host resolution returns OK and then
147 // crypto handshake returns ERR_IO_PENDING, then |callback| will run with
148 // ERR_IO_PENDING.
Bence Békyd8a21fc32018-06-27 18:29:58149 bool WaitForHostResolution(CompletionOnceCallback callback);
Yixin Wang7c5d11a82017-12-21 02:40:00150
151 // Tells QuicStreamRequest it should expect OnHostResolutionComplete()
152 // to be called in the future.
153 void ExpectOnHostResolution();
154
155 // Will be called by the associated QuicStreamFactory::Job when host
156 // resolution completes asynchronously after Request().
157 void OnHostResolutionComplete(int rv);
158
[email protected]e13201d82012-12-12 05:00:32159 void OnRequestComplete(int rv);
160
Zhongyi Shia6b68d112018-09-24 07:49:03161 // Called when the original connection created on the default network for
162 // |this| fails and a new connection has been created on the alternate
163 // network.
164 void OnConnectionFailedOnDefaultNetwork();
165
rtenneti8332ba52015-09-17 19:33:41166 // Helper method that calls |factory_|'s GetTimeDelayForWaitingJob(). It
167 // returns the amount of time waiting job should be delayed.
168 base::TimeDelta GetTimeDelayForWaitingJob() const;
169
Lily Chenf11e1292018-11-29 16:42:09170 // If host resolution is underway, changes the priority of the host resolver
171 // request.
172 void SetPriority(RequestPriority priority);
173
Yixin Wang7891a39d2017-11-08 20:59:24174 // Releases the handle to the QUIC session retrieved as a result of Request().
175 std::unique_ptr<QuicChromiumClientSession::Handle> ReleaseSessionHandle();
xunjieli2608f9b2016-03-14 13:39:23176
177 // Sets |session_|.
rchf0b18c8a2017-05-05 19:31:57178 void SetSession(std::unique_ptr<QuicChromiumClientSession::Handle> session);
[email protected]e13201d82012-12-12 05:00:32179
Ryan Hamilton75f197262017-08-17 14:00:07180 NetErrorDetails* net_error_details() { return net_error_details_; }
181
Paul Jensen8e3c5d32018-02-19 17:06:33182 const QuicSessionKey& session_key() const { return session_key_; }
bnccb7ff3c2015-05-21 20:51:55183
tfarina42834112016-09-22 13:38:20184 const NetLogWithSource& net_log() const { return net_log_; }
[email protected]e13201d82012-12-12 05:00:32185
186 private:
Keishi Hattori0e45c022021-11-27 09:25:52187 raw_ptr<QuicStreamFactory> factory_;
Paul Jensen8e3c5d32018-02-19 17:06:33188 QuicSessionKey session_key_;
tfarina42834112016-09-22 13:38:20189 NetLogWithSource net_log_;
Bence Békyd8a21fc32018-06-27 18:29:58190 CompletionOnceCallback callback_;
Zhongyi Shia6b68d112018-09-24 07:49:03191 CompletionOnceCallback failed_on_default_network_callback_;
Keishi Hattori0e45c022021-11-27 09:25:52192 raw_ptr<NetErrorDetails> net_error_details_; // Unowned.
rchf0b18c8a2017-05-05 19:31:57193 std::unique_ptr<QuicChromiumClientSession::Handle> session_;
[email protected]e13201d82012-12-12 05:00:32194
Yixin Wang7c5d11a82017-12-21 02:40:00195 // Set in Request(). If true, then OnHostResolutionComplete() is expected to
196 // be called in the future.
Tsuyoshi Horo4478fd32022-06-09 01:41:25197 bool expect_on_host_resolution_ = false;
Yixin Wang7c5d11a82017-12-21 02:40:00198 // Callback passed to WaitForHostResolution().
Bence Békyd8a21fc32018-06-27 18:29:58199 CompletionOnceCallback host_resolution_callback_;
[email protected]e13201d82012-12-12 05:00:32200};
201
Yixin Wang7891a39d2017-11-08 20:59:24202// A factory for fetching QuicChromiumClientSessions.
[email protected]f698a012013-05-06 20:18:59203class NET_EXPORT_PRIVATE QuicStreamFactory
[email protected]d7d1e50b2013-11-25 22:08:09204 : public NetworkChangeNotifier::IPAddressObserver,
jri7e636642016-01-14 06:57:08205 public NetworkChangeNotifier::NetworkObserver,
[email protected]d7d1e50b2013-11-25 22:08:09206 public CertDatabase::Observer {
[email protected]e13201d82012-12-12 05:00:32207 public:
bnc359ed2a2016-04-29 20:43:45208 // This class encompasses |destination| and |server_id|.
209 // |destination| is a HostPortPair which is resolved
Ryan Hamilton8d9ee76e2018-05-29 23:52:52210 // and a quic::QuicConnection is made to the resulting IP address.
bnc359ed2a2016-04-29 20:43:45211 // |server_id| identifies the origin of the request,
212 // the crypto handshake advertises |server_id.host()| to the server,
213 // and the certificate is also matched against |server_id.host()|.
Paul Jensen8e3c5d32018-02-19 17:06:33214 class NET_EXPORT_PRIVATE QuicSessionAliasKey {
bnc359ed2a2016-04-29 20:43:45215 public:
Paul Jensen8e3c5d32018-02-19 17:06:33216 QuicSessionAliasKey() = default;
Dan McArdle68a5f622021-07-09 20:56:53217 QuicSessionAliasKey(url::SchemeHostPort destination,
218 QuicSessionKey session_key);
Paul Jensen8e3c5d32018-02-19 17:06:33219 ~QuicSessionAliasKey() = default;
bnc359ed2a2016-04-29 20:43:45220
221 // Needed to be an element of std::set.
Paul Jensen8e3c5d32018-02-19 17:06:33222 bool operator<(const QuicSessionAliasKey& other) const;
223 bool operator==(const QuicSessionAliasKey& other) const;
bnc359ed2a2016-04-29 20:43:45224
Dan McArdle68a5f622021-07-09 20:56:53225 const url::SchemeHostPort& destination() const { return destination_; }
Ryan Hamilton8d9ee76e2018-05-29 23:52:52226 const quic::QuicServerId& server_id() const {
227 return session_key_.server_id();
228 }
Paul Jensen8e3c5d32018-02-19 17:06:33229 const QuicSessionKey& session_key() const { return session_key_; }
bnc359ed2a2016-04-29 20:43:45230
xunjieli69720dd2017-01-30 15:36:29231 // Returns the estimate of dynamically allocated memory in bytes.
xunjieli69720dd2017-01-30 15:36:29232
bnc359ed2a2016-04-29 20:43:45233 private:
Dan McArdle68a5f622021-07-09 20:56:53234 url::SchemeHostPort destination_;
Paul Jensen8e3c5d32018-02-19 17:06:33235 QuicSessionKey session_key_;
bnc359ed2a2016-04-29 20:43:45236 };
237
[email protected]e8ff26842013-03-22 21:02:05238 QuicStreamFactory(
jridf673d22016-06-02 22:06:33239 NetLog* net_log,
[email protected]e8ff26842013-03-22 21:02:05240 HostResolver* host_resolver,
nharper642ae4b2016-06-30 00:40:36241 SSLConfigService* ssl_config_service,
[email protected]e8ff26842013-03-22 21:02:05242 ClientSocketFactory* client_socket_factory,
bnc525e175a2016-06-20 12:36:40243 HttpServerProperties* http_server_properties,
[email protected]59c0bbd2014-03-22 04:08:12244 CertVerifier* cert_verifier,
estark6f9b3d82016-01-12 21:37:05245 CTPolicyEnforcer* ct_policy_enforcer,
[email protected]080b77932014-08-04 01:22:46246 TransportSecurityState* transport_security_state,
Chris Thompsonf31b2492020-07-21 05:47:42247 SCTAuditingDelegate* sct_auditing_delegate,
tbansalc8a94ea2015-11-02 23:58:51248 SocketPerformanceWatcherFactory* socket_performance_watcher_factory,
[email protected]e8ff26842013-03-22 21:02:05249 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory,
Victor Vasilieva1e66d72019-12-05 17:55:38250 QuicContext* context);
Peter Boström407869b2021-10-07 04:42:48251
252 QuicStreamFactory(const QuicStreamFactory&) = delete;
253 QuicStreamFactory& operator=(const QuicStreamFactory&) = delete;
254
dchengb03027d2014-10-21 12:00:20255 ~QuicStreamFactory() override;
[email protected]e13201d82012-12-12 05:00:32256
Paul Jensen8e3c5d32018-02-19 17:06:33257 // Returns true if there is an existing session for |session_key| or if the
bnc359ed2a2016-04-29 20:43:45258 // request can be pooled to an existing session to the IP address of
259 // |destination|.
Paul Jensen8e3c5d32018-02-19 17:06:33260 bool CanUseExistingSession(const QuicSessionKey& session_key,
Dan McArdle68a5f622021-07-09 20:56:53261 const url::SchemeHostPort& destination);
zhongyi32569c62016-01-08 02:54:30262
Yixin Wang7891a39d2017-11-08 20:59:24263 // Fetches a QuicChromiumClientSession to |host_port_pair| which will be
rchf114d982015-10-21 01:34:56264 // owned by |request|.
[email protected]0cceb922014-07-01 02:00:56265 // If a matching session already exists, this method will return OK. If no
266 // matching session exists, this will return ERR_IO_PENDING and will invoke
267 // OnRequestComplete asynchronously.
Cammie Smith Barnes0f38aff2021-03-02 23:14:35268 // When |use_dns_aliases| is true, any DNS aliases found in host resolution
269 // are stored in the |dns_aliases_by_session_key_| map. |use_dns_aliases|
270 // should be false in the case of a proxy.
Paul Jensen8e3c5d32018-02-19 17:06:33271 int Create(const QuicSessionKey& session_key,
Dan McArdle68a5f622021-07-09 20:56:53272 url::SchemeHostPort destination,
Ryan Hamilton9ef8c102019-06-28 03:58:52273 quic::ParsedQuicVersion quic_version,
Yixin Wang247ea642017-11-15 01:15:50274 RequestPriority priority,
Cammie Smith Barnes0f38aff2021-03-02 23:14:35275 bool use_dns_aliases,
rtennetia75df622015-06-21 23:59:50276 int cert_verify_flags,
ckrasic3865ee0f2016-02-29 22:04:56277 const GURL& url,
tfarina42834112016-09-22 13:38:20278 const NetLogWithSource& net_log,
[email protected]e13201d82012-12-12 05:00:32279 QuicStreamRequest* request);
280
[email protected]4d283b32013-10-17 12:57:27281 // Called by a session when it is going away and no more streams should be
282 // created on it.
ckrasic4f9d88d2015-07-22 22:23:16283 void OnSessionGoingAway(QuicChromiumClientSession* session);
[email protected]4d283b32013-10-17 12:57:27284
[email protected]e13201d82012-12-12 05:00:32285 // Called by a session after it shuts down.
ckrasic4f9d88d2015-07-22 22:23:16286 void OnSessionClosed(QuicChromiumClientSession* session);
[email protected]e13201d82012-12-12 05:00:32287
rch9ecde09b2017-04-08 00:18:23288 // Called by a session when it blackholes after the handshake is confirmed.
289 void OnBlackholeAfterHandshakeConfirmed(QuicChromiumClientSession* session);
zhongyidd1439f62016-09-02 02:02:26290
[email protected]e13201d82012-12-12 05:00:32291 // Cancels a pending request.
292 void CancelRequest(QuicStreamRequest* request);
293
Lily Chenf11e1292018-11-29 16:42:09294 // Sets priority of a request.
295 void SetRequestPriority(QuicStreamRequest* request, RequestPriority priority);
296
Renjieba55fae2018-09-20 03:05:16297 // Closes all current sessions with specified network, QUIC error codes.
298 // It sends connection close packet when closing connections.
Ryan Hamilton8d9ee76e2018-05-29 23:52:52299 void CloseAllSessions(int error, quic::QuicErrorCode quic_error);
[email protected]56dfb902013-01-03 23:17:55300
Matt Menke355d7b1e2022-05-27 23:19:53301 base::Value QuicStreamFactoryInfoToValue() const;
[email protected]c5b061b2013-01-05 00:31:34302
msramek992625ec2016-08-04 18:33:58303 // Delete cached state objects in |crypto_config_|. If |origin_filter| is not
304 // null, only objects on matching origins will be deleted.
305 void ClearCachedStatesInCryptoConfig(
Anna Malova997d73f62020-03-02 19:01:13306 const base::RepeatingCallback<bool(const GURL&)>& origin_filter);
[email protected]f7e21a432014-04-21 22:17:57307
jri7e636642016-01-14 06:57:08308 // Helper method that configures a DatagramClientSocket. Socket is
309 // bound to the default network if the |network| param is
310 // NetworkChangeNotifier::kInvalidNetworkHandle.
311 // Returns net_error code.
312 int ConfigureSocket(DatagramClientSocket* socket,
313 IPEndPoint addr,
Paul Jensen8e3c5d32018-02-19 17:06:33314 NetworkChangeNotifier::NetworkHandle network,
315 const SocketTag& socket_tag);
jri7e636642016-01-14 06:57:08316
jriae8cfdc2016-01-21 19:44:35317 // Finds an alternative to |old_network| from the platform's list of connected
318 // networks. Returns NetworkChangeNotifier::kInvalidNetworkHandle if no
319 // alternative is found.
320 NetworkChangeNotifier::NetworkHandle FindAlternateNetwork(
321 NetworkChangeNotifier::NetworkHandle old_network);
322
Zhongyi Shi673f22ef2017-10-18 00:00:47323 // Creates a datagram socket. |source| is the NetLogSource for the entity
324 // trying to create the socket, if it has one.
325 std::unique_ptr<DatagramClientSocket> CreateSocket(
326 NetLog* net_log,
327 const NetLogSource& source);
328
[email protected]f698a012013-05-06 20:18:59329 // NetworkChangeNotifier::IPAddressObserver methods:
330
Jana Iyengar903dec22017-11-28 00:44:23331 // Until the servers support roaming, close all connections when the local
332 // IP address changes.
dchengb03027d2014-10-21 12:00:20333 void OnIPAddressChanged() override;
[email protected]f698a012013-05-06 20:18:59334
jri7e636642016-01-14 06:57:08335 // NetworkChangeNotifier::NetworkObserver methods:
336 void OnNetworkConnected(
337 NetworkChangeNotifier::NetworkHandle network) override;
338 void OnNetworkDisconnected(
339 NetworkChangeNotifier::NetworkHandle network) override;
340 void OnNetworkSoonToDisconnect(
341 NetworkChangeNotifier::NetworkHandle network) override;
342 void OnNetworkMadeDefault(
343 NetworkChangeNotifier::NetworkHandle network) override;
344
[email protected]d7d1e50b2013-11-25 22:08:09345 // CertDatabase::Observer methods:
346
347 // We close all sessions when certificate database is changed.
mattmfd05a1f2017-02-18 06:18:44348 void OnCertDBChanged() override;
[email protected]d7d1e50b2013-11-25 22:08:09349
Matt Menkeb566c392019-09-11 23:22:43350 bool is_quic_known_to_work_on_current_network() const {
351 return is_quic_known_to_work_on_current_network_;
352 }
[email protected]11c05872013-08-20 02:04:12353
Nick Harper72ade192019-07-17 03:30:42354 bool allow_server_migration() const { return params_.allow_server_migration; }
Zhongyi Shif124a582017-11-02 00:15:04355
Renjie Tangb23d99982020-08-20 01:51:17356 // Returns true is gQUIC 0-RTT is disabled from quic_context.
357 bool gquic_zero_rtt_disabled() const {
358 return params_.disable_gquic_zero_rtt;
359 }
360
Matt Menkeb566c392019-09-11 23:22:43361 void set_is_quic_known_to_work_on_current_network(
362 bool is_quic_known_to_work_on_current_network);
[email protected]11c05872013-08-20 02:04:12363
rtenneti8332ba52015-09-17 19:33:41364 // It returns the amount of time waiting job should be delayed.
Renjie Tangdd708972019-10-03 20:56:21365 base::TimeDelta GetTimeDelayForWaitingJob(const QuicSessionKey& session_key);
rtenneti8332ba52015-09-17 19:33:41366
rch12fef552016-01-15 16:26:31367 QuicChromiumConnectionHelper* helper() { return helper_.get(); }
[email protected]2cfc6bb82013-10-27 03:40:44368
Ryan Hamilton8d9ee76e2018-05-29 23:52:52369 quic::QuicAlarmFactory* alarm_factory() { return alarm_factory_.get(); }
rch16c74d1d2016-04-22 06:14:07370
zhongyiaf257542016-12-19 03:36:01371 void set_server_push_delegate(ServerPushDelegate* push_delegate) {
372 push_delegate_ = push_delegate;
373 }
374
Zhongyi Shi8de43832018-08-15 23:40:00375 NetworkChangeNotifier::NetworkHandle default_network() const {
376 return default_network_;
377 }
378
Cammie Smith Barnes0f38aff2021-03-02 23:14:35379 // Returns the stored DNS aliases for the session key.
Eric Orthac661912022-01-10 21:44:17380 const std::set<std::string>& GetDnsAliasesForSessionKey(
Cammie Smith Barnes0f38aff2021-03-02 23:14:35381 const QuicSessionKey& key) const;
382
[email protected]e13201d82012-12-12 05:00:32383 private:
384 class Job;
Matt Menkefca05b62019-09-20 23:15:56385 class QuicCryptoClientConfigOwner;
386 class CryptoClientConfigHandle;
[email protected]c49ff182013-09-28 08:33:26387 friend class test::QuicStreamFactoryPeer;
[email protected]e13201d82012-12-12 05:00:32388
Cammie Smith Barnes0f38aff2021-03-02 23:14:35389 using SessionMap = std::map<QuicSessionKey, QuicChromiumClientSession*>;
390 using SessionIdMap =
391 std::map<QuicChromiumClientSession*, QuicSessionAliasKey>;
392 using AliasSet = std::set<QuicSessionAliasKey>;
393 using SessionAliasMap = std::map<QuicChromiumClientSession*, AliasSet>;
394 using SessionSet = std::set<QuicChromiumClientSession*>;
395 using IPAliasMap = std::map<IPEndPoint, SessionSet>;
396 using SessionPeerIPMap = std::map<QuicChromiumClientSession*, IPEndPoint>;
397 using JobMap = std::map<QuicSessionKey, std::unique_ptr<Job>>;
398 using DnsAliasesBySessionKeyMap =
Eric Orthac661912022-01-10 21:44:17399 std::map<QuicSessionKey, std::set<std::string>>;
Matt Menkefca05b62019-09-20 23:15:56400 using QuicCryptoClientConfigMap =
401 std::map<NetworkIsolationKey,
402 std::unique_ptr<QuicCryptoClientConfigOwner>>;
rtenneti14abd312015-02-06 21:56:01403
Paul Jensen8e3c5d32018-02-19 17:06:33404 bool HasMatchingIpSession(const QuicSessionAliasKey& key,
Cammie Smith Barnes0f38aff2021-03-02 23:14:35405 const AddressList& address_list,
406 bool use_dns_aliases);
[email protected]e13201d82012-12-12 05:00:32407 void OnJobComplete(Job* job, int rv);
Paul Jensen8e3c5d32018-02-19 17:06:33408 bool HasActiveSession(const QuicSessionKey& session_key) const;
409 bool HasActiveJob(const QuicSessionKey& session_key) const;
Paul Jensen8e3c5d32018-02-19 17:06:33410 int CreateSession(const QuicSessionAliasKey& key,
Ryan Hamilton9ef8c102019-06-28 03:58:52411 quic::ParsedQuicVersion quic_version,
rtennetia75df622015-06-21 23:59:50412 int cert_verify_flags,
rch433bf5f2017-02-14 04:10:47413 bool require_confirmation,
[email protected]338e7982013-12-13 11:15:32414 const AddressList& address_list,
xunjieli100937eb52016-09-15 20:09:37415 base::TimeTicks dns_resolution_start_time,
rtennetif4f08852015-02-27 17:50:04416 base::TimeTicks dns_resolution_end_time,
tfarina42834112016-09-22 13:38:20417 const NetLogWithSource& net_log,
Zhongyi Shi55ec9532018-07-24 03:57:39418 QuicChromiumClientSession** session,
419 NetworkChangeNotifier::NetworkHandle* network);
Paul Jensen8e3c5d32018-02-19 17:06:33420 void ActivateSession(const QuicSessionAliasKey& key,
Cammie Smith Barnes0f38aff2021-03-02 23:14:35421 QuicChromiumClientSession* session,
Eric Orthac661912022-01-10 21:44:17422 std::set<std::string> dns_aliases);
Zhongyi Shic6b3f03f2020-06-25 21:28:22423 // Go away all active sessions. May disable session's connectivity monitoring
424 // based on the |reason|.
425 void MarkAllActiveSessionsGoingAway(AllActiveSessionsGoingAwayReason reason);
[email protected]e13201d82012-12-12 05:00:32426
Matt Menke19475f72019-08-21 18:57:44427 void ConfigureInitialRttEstimate(
428 const quic::QuicServerId& server_id,
429 const NetworkIsolationKey& network_isolation_key,
430 quic::QuicConfig* config);
rchd6163f32017-01-30 23:50:38431
rtenneti2912825c2015-01-06 01:19:46432 // Returns |srtt| in micro seconds from ServerNetworkStats. Returns 0 if there
433 // is no |http_server_properties_| or if |http_server_properties_| doesn't
434 // have ServerNetworkStats for the given |server_id|.
Avi Drissman13fc8932015-12-20 04:40:46435 int64_t GetServerNetworkStatsSmoothedRttInMicroseconds(
Matt Menke19475f72019-08-21 18:57:44436 const quic::QuicServerId& server_id,
437 const NetworkIsolationKey& network_isolation_key) const;
rtenneti2912825c2015-01-06 01:19:46438
rchd6163f32017-01-30 23:50:38439 // Returns |srtt| from ServerNetworkStats. Returns null if there
440 // is no |http_server_properties_| or if |http_server_properties_| doesn't
441 // have ServerNetworkStats for the given |server_id|.
442 const base::TimeDelta* GetServerNetworkStatsSmoothedRtt(
Matt Menke19475f72019-08-21 18:57:44443 const quic::QuicServerId& server_id,
444 const NetworkIsolationKey& network_isolation_key) const;
rchd6163f32017-01-30 23:50:38445
bnccacc0992015-03-20 20:22:22446 // Helper methods.
Matt Menkeb32ba5122019-09-10 19:17:05447 bool WasQuicRecentlyBroken(const QuicSessionKey& session_key) const;
rtenneti8332ba52015-09-17 19:33:41448
Zhongyi Shid04bd412019-08-26 23:31:08449 // Helper method to initialize the following migration options and check
450 // pre-requisites:
451 // - |params_.migrate_sessions_on_network_change_v2|
452 // - |params_.migrate_sessions_early_v2|
453 // - |params_.migrate_idle_sessions|
454 // - |params_.retry_on_alternate_network_before_handshake|
455 // If pre-requisites are not met, turn off the corresponding options.
456 void InitializeMigrationOptions();
457
[email protected]257f24f2014-04-01 09:15:37458 // Initializes the cached state associated with |server_id| in
David Benjamin62566912021-10-14 00:56:16459 // |crypto_config_| with the information in |server_info|.
[email protected]60cf50e2014-04-28 23:23:18460 void InitializeCachedStateInCryptoConfig(
Matt Menkefca05b62019-09-20 23:15:56461 const CryptoClientConfigHandle& crypto_config_handle,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52462 const quic::QuicServerId& server_id,
David Benjamin62566912021-10-14 00:56:16463 const std::unique_ptr<QuicServerInfo>& server_info);
[email protected]b694e48c2014-03-18 17:10:13464
ckrasic4f9d88d2015-07-22 22:23:16465 void ProcessGoingAwaySession(QuicChromiumClientSession* session,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52466 const quic::QuicServerId& server_id,
[email protected]eb71ab62014-05-23 07:57:53467 bool was_session_active);
[email protected]4d590c9c2014-05-02 05:14:33468
Cammie Smith Barnes0f38aff2021-03-02 23:14:35469 // Insert the given alias `key` in the AliasSet for the given `session` in
470 // the map `session_aliases_`, and add the given `dns_aliases` for
471 // `key.session_key()` in `dns_aliases_by_session_key_`.
472 void MapSessionToAliasKey(QuicChromiumClientSession* session,
473 const QuicSessionAliasKey& key,
Eric Orthac661912022-01-10 21:44:17474 std::set<std::string> dns_aliases);
Cammie Smith Barnes0f38aff2021-03-02 23:14:35475
476 // For all alias keys for `session` in `session_aliases_`, erase the
477 // corresponding DNS aliases in `dns_aliases_by_session_key_`. Then erase
478 // `session` from `session_aliases_`.
479 void UnmapSessionFromSessionAliases(QuicChromiumClientSession* session);
480
Matt Menkefca05b62019-09-20 23:15:56481 // Creates a CreateCryptoConfigHandle for the specified NetworkIsolationKey.
482 // If there's already a corresponding entry in |active_crypto_config_map_|,
483 // reuses it. If there's a corresponding entry in |recent_crypto_config_map_|,
484 // promotes it to |active_crypto_config_map_| and then reuses it. Otherwise,
485 // creates a new entry in |active_crypto_config_map_|.
486 std::unique_ptr<CryptoClientConfigHandle> CreateCryptoConfigHandle(
487 const NetworkIsolationKey& network_isolation_key);
488
489 // Salled when the indicated member of |active_crypto_config_map_| has no
490 // outstanding references. The QuicCryptoClientConfigOwner is then moved to
491 // |recent_crypto_config_map_|, an MRU cache.
492 void OnAllCryptoClientRefReleased(
493 QuicCryptoClientConfigMap::iterator& map_iterator);
494
Zhongyi Shic6b3f03f2020-06-25 21:28:22495 // Called when a network change happens.
496 // Collect platform notification metrics, and if the change affects the
497 // original default network interface, collect connectivity degradation
498 // metrics from |connectivity_monitor_| and add to histograms.
499 void CollectDataOnPlatformNotification(
500 enum QuicPlatformNotification notification,
501 NetworkChangeNotifier::NetworkHandle affected_network) const;
502
Matt Menkefca05b62019-09-20 23:15:56503 std::unique_ptr<QuicCryptoClientConfigHandle> GetCryptoConfigForTesting(
504 const NetworkIsolationKey& network_isolation_key);
505
Matt Menkeca5253312019-09-23 18:59:37506 bool CryptoConfigCacheIsEmptyForTesting(
507 const quic::QuicServerId& server_id,
508 const NetworkIsolationKey& network_isolation_key);
509
Tsuyoshi Horo7acebce2022-05-12 06:13:23510 const quic::ParsedQuicVersionVector& supported_versions() const {
511 return params_.supported_versions;
512 }
513
Matt Menkeb566c392019-09-11 23:22:43514 // Whether QUIC is known to work on current network. This is true when QUIC is
515 // expected to work in general, rather than whether QUIC was broken / recently
516 // broken when used with a particular server. That information is stored in
517 // the broken alternative service map in HttpServerProperties.
Tsuyoshi Horo4478fd32022-06-09 01:41:25518 bool is_quic_known_to_work_on_current_network_ = false;
Matt Menkeb566c392019-09-11 23:22:43519
Keishi Hattori0e45c022021-11-27 09:25:52520 raw_ptr<NetLog> net_log_;
521 raw_ptr<HostResolver> host_resolver_;
522 raw_ptr<ClientSocketFactory> client_socket_factory_;
523 raw_ptr<HttpServerProperties> http_server_properties_;
524 raw_ptr<ServerPushDelegate> push_delegate_;
525 const raw_ptr<CertVerifier> cert_verifier_;
526 const raw_ptr<CTPolicyEnforcer> ct_policy_enforcer_;
527 const raw_ptr<TransportSecurityState> transport_security_state_;
528 const raw_ptr<SCTAuditingDelegate> sct_auditing_delegate_;
529 raw_ptr<QuicCryptoClientStreamFactory> quic_crypto_client_stream_factory_;
530 raw_ptr<quic::QuicRandom> random_generator_; // Unowned.
531 raw_ptr<const quic::QuicClock> clock_; // Unowned.
Nick Harper72ade192019-07-17 03:30:42532 QuicParams params_;
rchf11cc0f2016-11-15 03:04:32533 QuicClockSkewDetector clock_skew_detector_;
[email protected]e13201d82012-12-12 05:00:32534
tbansalfdf5665b2015-09-21 22:46:40535 // Factory which is used to create socket performance watcher. A new watcher
536 // is created for every QUIC connection.
537 // |socket_performance_watcher_factory_| may be null.
Keishi Hattori0e45c022021-11-27 09:25:52538 raw_ptr<SocketPerformanceWatcherFactory> socket_performance_watcher_factory_;
tbansalfdf5665b2015-09-21 22:46:40539
[email protected]2cfc6bb82013-10-27 03:40:44540 // The helper used for all connections.
danakjad1777e2016-04-16 00:56:42541 std::unique_ptr<QuicChromiumConnectionHelper> helper_;
[email protected]2cfc6bb82013-10-27 03:40:44542
rch16c74d1d2016-04-22 06:14:07543 // The alarm factory used for all connections.
Ryan Hamilton8d9ee76e2018-05-29 23:52:52544 std::unique_ptr<quic::QuicAlarmFactory> alarm_factory_;
rch16c74d1d2016-04-22 06:14:07545
[email protected]e13201d82012-12-12 05:00:32546 // Contains owning pointers to all sessions that currently exist.
[email protected]4d590c9c2014-05-02 05:14:33547 SessionIdMap all_sessions_;
[email protected]e13201d82012-12-12 05:00:32548 // Contains non-owning pointers to currently active session
549 // (not going away session, once they're implemented).
550 SessionMap active_sessions_;
[email protected]eed749f92013-12-23 18:57:38551 // Map from session to set of aliases that this session is known by.
[email protected]e13201d82012-12-12 05:00:32552 SessionAliasMap session_aliases_;
[email protected]eed749f92013-12-23 18:57:38553 // Map from IP address to sessions which are connected to this address.
554 IPAliasMap ip_aliases_;
jri94ddc3142016-08-26 01:32:43555 // Map from session to its original peer IP address.
556 SessionPeerIPMap session_peer_ip_;
[email protected]e13201d82012-12-12 05:00:32557
[email protected]d8e2abf82014-03-06 10:30:10558 // Origins which have gone away recently.
559 AliasSet gone_away_aliases_;
560
Cammie Smith Barnes0f38aff2021-03-02 23:14:35561 // A map of DNS alias vectors by session keys.
562 DnsAliasesBySessionKeyMap dns_aliases_by_session_key_;
563
Matt Menkefca05b62019-09-20 23:15:56564 // When a QuicCryptoClientConfig is in use, it has one or more live
565 // CryptoClientConfigHandles, and is stored in |active_crypto_config_map_|.
566 // Once all the handles are deleted, it's moved to
cfredric8fdc22432021-10-14 03:24:00567 // |recent_crypto_config_map_|. If reused before it is evicted from LRUCache,
Matt Menkefca05b62019-09-20 23:15:56568 // it will be removed from the cache and return to the active config map.
569 // These two maps should never both have entries with the same
570 // NetworkIsolationKey.
571 QuicCryptoClientConfigMap active_crypto_config_map_;
cfredric8fdc22432021-10-14 03:24:00572 base::LRUCache<NetworkIsolationKey,
Matt Menkefca05b62019-09-20 23:15:56573 std::unique_ptr<QuicCryptoClientConfigOwner>>
574 recent_crypto_config_map_;
575
Ryan Hamilton8d9ee76e2018-05-29 23:52:52576 const quic::QuicConfig config_;
[email protected]b064310782013-05-30 21:12:17577
[email protected]e13201d82012-12-12 05:00:32578 JobMap active_jobs_;
[email protected]e13201d82012-12-12 05:00:32579
zhongyidd1439f62016-09-02 02:02:26580 // PING timeout for connections.
Ryan Hamilton8d9ee76e2018-05-29 23:52:52581 quic::QuicTime::Delta ping_timeout_;
582 quic::QuicTime::Delta reduced_ping_timeout_;
zhongyidd1439f62016-09-02 02:02:26583
Zhongyi Shie01f2db2019-02-22 19:53:23584 // Timeout for how long the wire can have no retransmittable packets.
585 quic::QuicTime::Delta retransmittable_on_wire_timeout_;
586
rtenneti1cd3b162015-09-29 02:58:28587 // If more than |yield_after_packets_| packets have been read or more than
588 // |yield_after_duration_| time has passed, then
rcha02807b42016-01-29 21:56:15589 // QuicChromiumPacketReader::StartReading() yields by doing a PostTask().
rtenneti1cd3b162015-09-29 02:58:28590 int yield_after_packets_;
Ryan Hamilton8d9ee76e2018-05-29 23:52:52591 quic::QuicTime::Delta yield_after_duration_;
rtenneti1cd3b162015-09-29 02:58:28592
Zhongyi Shi6db13462018-05-19 01:36:26593 // If |migrate_sessions_early_v2_| is true, tracks the current default
594 // network, and is updated OnNetworkMadeDefault.
595 // Otherwise, always set to NetworkChangeNotifier::kInvalidNetwork.
596 NetworkChangeNotifier::NetworkHandle default_network_;
597
rtennetifc47e0e2014-09-26 02:54:05598 // Local address of socket that was created in CreateSession.
599 IPEndPoint local_address_;
Zhongyi Shia0cef1082017-08-25 01:49:50600 // True if we need to check HttpServerProperties if QUIC was supported last
601 // time.
Tsuyoshi Horo4478fd32022-06-09 01:41:25602 bool need_to_check_persisted_supports_quic_ = true;
603 bool prefer_aes_gcm_recorded_ = false;
rtennetifc47e0e2014-09-26 02:54:05604
rtenneti041b2992015-02-23 23:03:28605 NetworkConnection network_connection_;
606
Tsuyoshi Horo4478fd32022-06-09 01:41:25607 int num_push_streams_created_ = 0;
ckrasic3865ee0f2016-02-29 22:04:56608
Zhongyi Shic6b3f03f2020-06-25 21:28:22609 QuicConnectivityMonitor connectivity_monitor_;
610
Keishi Hattori0e45c022021-11-27 09:25:52611 raw_ptr<const base::TickClock> tick_clock_;
Zhongyi Shic16b4102019-02-12 00:37:40612
Keishi Hattori0e45c022021-11-27 09:25:52613 raw_ptr<base::SequencedTaskRunner> task_runner_;
rtenneti38f5cd52014-10-28 20:28:28614
Keishi Hattori0e45c022021-11-27 09:25:52615 const raw_ptr<SSLConfigService> ssl_config_service_;
nharper642ae4b2016-06-30 00:40:36616
Matt Menkefca05b62019-09-20 23:15:56617 // Whether NetworkIsolationKeys should be used for
618 // |active_crypto_config_map_|. If false, there will just be one config with
619 // an empty NetworkIsolationKey. Whether QuicSessionAliasKeys all have an
620 // empty NIK is based on whether socket pools are respecting NIKs, but whether
621 // those NIKs are also used when accessing |active_crypto_config_map_| is also
622 // gated this, which is set based on whether HttpServerProperties is
623 // respecting NIKs, as that data is fed into the crypto config map using the
624 // corresponding NIK.
625 const bool use_network_isolation_key_for_crypto_configs_;
626
Jeremy Romand54000b22019-07-08 18:40:16627 base::WeakPtrFactory<QuicStreamFactory> weak_factory_{this};
[email protected]e13201d82012-12-12 05:00:32628};
629
630} // namespace net
631
Ryan Hamiltona3ee93a72018-08-01 22:03:08632#endif // NET_QUIC_QUIC_STREAM_FACTORY_H_