[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 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 | |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 5 | #ifndef NET_QUIC_QUIC_STREAM_FACTORY_H_ |
| 6 | #define NET_QUIC_QUIC_STREAM_FACTORY_H_ |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 7 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
| 10 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 11 | #include <map> |
Matt Menke | fca05b6 | 2019-09-20 23:15:56 | [diff] [blame] | 12 | #include <memory> |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 13 | #include <set> |
[email protected] | 41d6b17 | 2013-01-29 16:10:57 | [diff] [blame] | 14 | #include <string> |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 15 | #include <vector> |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 16 | |
cfredric | 8fdc2243 | 2021-10-14 03:24:00 | [diff] [blame] | 17 | #include "base/containers/lru_cache.h" |
thestig | a0e18cd | 2015-09-25 04:58:36 | [diff] [blame] | 18 | #include "base/gtest_prod_util.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 19 | #include "base/memory/raw_ptr.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 20 | #include "base/memory/weak_ptr.h" |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 21 | #include "base/time/tick_clock.h" |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 22 | #include "base/time/time.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 23 | #include "net/base/address_list.h" |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 24 | #include "net/base/completion_once_callback.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 25 | #include "net/base/host_port_pair.h" |
bnc | 81c46c1f | 2016-10-04 16:25:59 | [diff] [blame] | 26 | #include "net/base/net_export.h" |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 27 | #include "net/base/network_change_notifier.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 28 | #include "net/base/proxy_server.h" |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 29 | #include "net/cert/cert_database.h" |
Ben Schwartz | 3ff4dc1e6 | 2021-04-27 21:15:23 | [diff] [blame] | 30 | #include "net/dns/public/secure_dns_policy.h" |
zhongyi | 32569c6 | 2016-01-08 02:54:30 | [diff] [blame] | 31 | #include "net/http/http_server_properties.h" |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 32 | #include "net/http/http_stream_factory.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 33 | #include "net/log/net_log_with_source.h" |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 34 | #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 Shi | c6b3f03f | 2020-06-25 21:28:22 | [diff] [blame] | 37 | #include "net/quic/quic_connectivity_monitor.h" |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 38 | #include "net/quic/quic_context.h" |
Matt Menke | fca05b6 | 2019-09-20 23:15:56 | [diff] [blame] | 39 | #include "net/quic/quic_crypto_client_config_handle.h" |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 40 | #include "net/quic/quic_session_key.h" |
Yixin Wang | 7f3cdc3f | 2017-11-10 01:44:14 | [diff] [blame] | 41 | #include "net/socket/client_socket_pool.h" |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 42 | #include "net/ssl/ssl_config_service.h" |
Ryan Hamilton | ea4fa19 | 2022-04-12 18:30:49 | [diff] [blame] | 43 | #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 McArdle | 68a5f62 | 2021-07-09 20:56:53 | [diff] [blame] | 47 | #include "url/scheme_host_port.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 48 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 49 | namespace base { |
| 50 | class Value; |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 51 | } // namespace base |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 52 | |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 53 | namespace quic { |
| 54 | class QuicAlarmFactory; |
| 55 | class QuicClock; |
| 56 | class QuicRandom; |
| 57 | } // namespace quic |
| 58 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 59 | namespace net { |
| 60 | |
estark | 6f9b3d8 | 2016-01-12 21:37:05 | [diff] [blame] | 61 | class CTPolicyEnforcer; |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 62 | class CertVerifier; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 63 | class ClientSocketFactory; |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 64 | class HostResolver; |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 65 | class HttpServerProperties; |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 66 | class NetLog; |
Matt Menke | 26e4154 | 2019-06-05 01:09:51 | [diff] [blame] | 67 | class NetworkIsolationKey; |
rch | 12fef55 | 2016-01-15 16:26:31 | [diff] [blame] | 68 | class QuicChromiumConnectionHelper; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 69 | class QuicCryptoClientStreamFactory; |
rtenneti | 13c9d38d | 2015-10-12 21:25:01 | [diff] [blame] | 70 | class QuicServerInfo; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 71 | class QuicStreamFactory; |
Victor Vasiliev | 7752898d | 2019-11-14 21:30:22 | [diff] [blame] | 72 | class QuicContext; |
Chris Thompson | f31b249 | 2020-07-21 05:47:42 | [diff] [blame] | 73 | class SCTAuditingDelegate; |
tbansal | fdf5665b | 2015-09-21 22:46:40 | [diff] [blame] | 74 | class SocketPerformanceWatcherFactory; |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 75 | class SocketTag; |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 76 | class TransportSecurityState; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 77 | |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 78 | namespace test { |
| 79 | class QuicStreamFactoryPeer; |
| 80 | } // namespace test |
| 81 | |
Matt Menke | fca05b6 | 2019-09-20 23:15:56 | [diff] [blame] | 82 | // 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. |
| 89 | const int kMaxRecentCryptoConfigs = 100; |
| 90 | |
Zhongyi Shi | b4737c6 | 2017-09-28 00:49:31 | [diff] [blame] | 91 | enum 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 Shi | c6b3f03f | 2020-06-25 21:28:22 | [diff] [blame] | 100 | enum AllActiveSessionsGoingAwayReason { |
| 101 | kClockSkewDetected, |
| 102 | kIPAddressChanged, |
| 103 | kCertDBChanged |
| 104 | }; |
| 105 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 106 | // Encapsulates a pending request for a QuicChromiumClientSession. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 107 | // If the request is still pending when it is destroyed, it will |
| 108 | // cancel the request with the factory. |
| 109 | class NET_EXPORT_PRIVATE QuicStreamRequest { |
| 110 | public: |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 111 | explicit QuicStreamRequest(QuicStreamFactory* factory); |
Peter Boström | 293b134 | 2021-09-22 17:31:43 | [diff] [blame] | 112 | |
| 113 | QuicStreamRequest(const QuicStreamRequest&) = delete; |
| 114 | QuicStreamRequest& operator=(const QuicStreamRequest&) = delete; |
| 115 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 116 | ~QuicStreamRequest(); |
| 117 | |
rtenneti | a75df62 | 2015-06-21 23:59:50 | [diff] [blame] | 118 | // |cert_verify_flags| is bitwise OR'd of CertVerifier::VerifyFlags and it is |
| 119 | // passed to CertVerifier::Verify. |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 120 | // |destination| will be resolved and resulting IPEndPoint used to open a |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 121 | // quic::QuicConnection. This can be different than |
| 122 | // HostPortPair::FromURL(url). |
Cammie Smith Barnes | 0f38aff | 2021-03-02 23:14:35 | [diff] [blame] | 123 | // 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 McArdle | 68a5f62 | 2021-07-09 20:56:53 | [diff] [blame] | 126 | int Request(url::SchemeHostPort destination, |
Ryan Hamilton | 9ef8c10 | 2019-06-28 03:58:52 | [diff] [blame] | 127 | quic::ParsedQuicVersion quic_version, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 128 | PrivacyMode privacy_mode, |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 129 | RequestPriority priority, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 130 | const SocketTag& socket_tag, |
Matt Menke | 26e4154 | 2019-06-05 01:09:51 | [diff] [blame] | 131 | const NetworkIsolationKey& network_isolation_key, |
Ben Schwartz | 3ff4dc1e6 | 2021-04-27 21:15:23 | [diff] [blame] | 132 | SecureDnsPolicy secure_dns_policy, |
Cammie Smith Barnes | 0f38aff | 2021-03-02 23:14:35 | [diff] [blame] | 133 | bool use_dns_aliases, |
Tsuyoshi Horo | 7acebce | 2022-05-12 06:13:23 | [diff] [blame] | 134 | bool require_dns_https_alpn, |
rtenneti | a75df62 | 2015-06-21 23:59:50 | [diff] [blame] | 135 | int cert_verify_flags, |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 136 | const GURL& url, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 137 | const NetLogWithSource& net_log, |
Ryan Hamilton | 75f19726 | 2017-08-17 14:00:07 | [diff] [blame] | 138 | NetErrorDetails* net_error_details, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 139 | CompletionOnceCallback failed_on_default_network_callback, |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 140 | CompletionOnceCallback callback); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 141 | |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 142 | // 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éky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 149 | bool WaitForHostResolution(CompletionOnceCallback callback); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 150 | |
| 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] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 159 | void OnRequestComplete(int rv); |
| 160 | |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 161 | // 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 | |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 166 | // 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 Chen | f11e129 | 2018-11-29 16:42:09 | [diff] [blame] | 170 | // If host resolution is underway, changes the priority of the host resolver |
| 171 | // request. |
| 172 | void SetPriority(RequestPriority priority); |
| 173 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 174 | // Releases the handle to the QUIC session retrieved as a result of Request(). |
| 175 | std::unique_ptr<QuicChromiumClientSession::Handle> ReleaseSessionHandle(); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 176 | |
| 177 | // Sets |session_|. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 178 | void SetSession(std::unique_ptr<QuicChromiumClientSession::Handle> session); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 179 | |
Ryan Hamilton | 75f19726 | 2017-08-17 14:00:07 | [diff] [blame] | 180 | NetErrorDetails* net_error_details() { return net_error_details_; } |
| 181 | |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 182 | const QuicSessionKey& session_key() const { return session_key_; } |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 183 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 184 | const NetLogWithSource& net_log() const { return net_log_; } |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 185 | |
| 186 | private: |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 187 | raw_ptr<QuicStreamFactory> factory_; |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 188 | QuicSessionKey session_key_; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 189 | NetLogWithSource net_log_; |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 190 | CompletionOnceCallback callback_; |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 191 | CompletionOnceCallback failed_on_default_network_callback_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 192 | raw_ptr<NetErrorDetails> net_error_details_; // Unowned. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 193 | std::unique_ptr<QuicChromiumClientSession::Handle> session_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 194 | |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 195 | // Set in Request(). If true, then OnHostResolutionComplete() is expected to |
| 196 | // be called in the future. |
Tsuyoshi Horo | 4478fd3 | 2022-06-09 01:41:25 | [diff] [blame] | 197 | bool expect_on_host_resolution_ = false; |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 198 | // Callback passed to WaitForHostResolution(). |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 199 | CompletionOnceCallback host_resolution_callback_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 200 | }; |
| 201 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 202 | // A factory for fetching QuicChromiumClientSessions. |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 203 | class NET_EXPORT_PRIVATE QuicStreamFactory |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 204 | : public NetworkChangeNotifier::IPAddressObserver, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 205 | public NetworkChangeNotifier::NetworkObserver, |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 206 | public CertDatabase::Observer { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 207 | public: |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 208 | // This class encompasses |destination| and |server_id|. |
| 209 | // |destination| is a HostPortPair which is resolved |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 210 | // and a quic::QuicConnection is made to the resulting IP address. |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 211 | // |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 Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 214 | class NET_EXPORT_PRIVATE QuicSessionAliasKey { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 215 | public: |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 216 | QuicSessionAliasKey() = default; |
Dan McArdle | 68a5f62 | 2021-07-09 20:56:53 | [diff] [blame] | 217 | QuicSessionAliasKey(url::SchemeHostPort destination, |
| 218 | QuicSessionKey session_key); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 219 | ~QuicSessionAliasKey() = default; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 220 | |
| 221 | // Needed to be an element of std::set. |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 222 | bool operator<(const QuicSessionAliasKey& other) const; |
| 223 | bool operator==(const QuicSessionAliasKey& other) const; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 224 | |
Dan McArdle | 68a5f62 | 2021-07-09 20:56:53 | [diff] [blame] | 225 | const url::SchemeHostPort& destination() const { return destination_; } |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 226 | const quic::QuicServerId& server_id() const { |
| 227 | return session_key_.server_id(); |
| 228 | } |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 229 | const QuicSessionKey& session_key() const { return session_key_; } |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 230 | |
xunjieli | 69720dd | 2017-01-30 15:36:29 | [diff] [blame] | 231 | // Returns the estimate of dynamically allocated memory in bytes. |
xunjieli | 69720dd | 2017-01-30 15:36:29 | [diff] [blame] | 232 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 233 | private: |
Dan McArdle | 68a5f62 | 2021-07-09 20:56:53 | [diff] [blame] | 234 | url::SchemeHostPort destination_; |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 235 | QuicSessionKey session_key_; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 236 | }; |
| 237 | |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 238 | QuicStreamFactory( |
jri | df673d2 | 2016-06-02 22:06:33 | [diff] [blame] | 239 | NetLog* net_log, |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 240 | HostResolver* host_resolver, |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 241 | SSLConfigService* ssl_config_service, |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 242 | ClientSocketFactory* client_socket_factory, |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 243 | HttpServerProperties* http_server_properties, |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 244 | CertVerifier* cert_verifier, |
estark | 6f9b3d8 | 2016-01-12 21:37:05 | [diff] [blame] | 245 | CTPolicyEnforcer* ct_policy_enforcer, |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 246 | TransportSecurityState* transport_security_state, |
Chris Thompson | f31b249 | 2020-07-21 05:47:42 | [diff] [blame] | 247 | SCTAuditingDelegate* sct_auditing_delegate, |
tbansal | c8a94ea | 2015-11-02 23:58:51 | [diff] [blame] | 248 | SocketPerformanceWatcherFactory* socket_performance_watcher_factory, |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 249 | QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory, |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 250 | QuicContext* context); |
Peter Boström | 407869b | 2021-10-07 04:42:48 | [diff] [blame] | 251 | |
| 252 | QuicStreamFactory(const QuicStreamFactory&) = delete; |
| 253 | QuicStreamFactory& operator=(const QuicStreamFactory&) = delete; |
| 254 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 255 | ~QuicStreamFactory() override; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 256 | |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 257 | // Returns true if there is an existing session for |session_key| or if the |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 258 | // request can be pooled to an existing session to the IP address of |
| 259 | // |destination|. |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 260 | bool CanUseExistingSession(const QuicSessionKey& session_key, |
Dan McArdle | 68a5f62 | 2021-07-09 20:56:53 | [diff] [blame] | 261 | const url::SchemeHostPort& destination); |
zhongyi | 32569c6 | 2016-01-08 02:54:30 | [diff] [blame] | 262 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 263 | // Fetches a QuicChromiumClientSession to |host_port_pair| which will be |
rch | f114d98 | 2015-10-21 01:34:56 | [diff] [blame] | 264 | // owned by |request|. |
[email protected] | 0cceb92 | 2014-07-01 02:00:56 | [diff] [blame] | 265 | // 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 Barnes | 0f38aff | 2021-03-02 23:14:35 | [diff] [blame] | 268 | // 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 Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 271 | int Create(const QuicSessionKey& session_key, |
Dan McArdle | 68a5f62 | 2021-07-09 20:56:53 | [diff] [blame] | 272 | url::SchemeHostPort destination, |
Ryan Hamilton | 9ef8c10 | 2019-06-28 03:58:52 | [diff] [blame] | 273 | quic::ParsedQuicVersion quic_version, |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 274 | RequestPriority priority, |
Cammie Smith Barnes | 0f38aff | 2021-03-02 23:14:35 | [diff] [blame] | 275 | bool use_dns_aliases, |
rtenneti | a75df62 | 2015-06-21 23:59:50 | [diff] [blame] | 276 | int cert_verify_flags, |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 277 | const GURL& url, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 278 | const NetLogWithSource& net_log, |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 279 | QuicStreamRequest* request); |
| 280 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 281 | // Called by a session when it is going away and no more streams should be |
| 282 | // created on it. |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 283 | void OnSessionGoingAway(QuicChromiumClientSession* session); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 284 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 285 | // Called by a session after it shuts down. |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 286 | void OnSessionClosed(QuicChromiumClientSession* session); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 287 | |
rch | 9ecde09b | 2017-04-08 00:18:23 | [diff] [blame] | 288 | // Called by a session when it blackholes after the handshake is confirmed. |
| 289 | void OnBlackholeAfterHandshakeConfirmed(QuicChromiumClientSession* session); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 290 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 291 | // Cancels a pending request. |
| 292 | void CancelRequest(QuicStreamRequest* request); |
| 293 | |
Lily Chen | f11e129 | 2018-11-29 16:42:09 | [diff] [blame] | 294 | // Sets priority of a request. |
| 295 | void SetRequestPriority(QuicStreamRequest* request, RequestPriority priority); |
| 296 | |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 297 | // Closes all current sessions with specified network, QUIC error codes. |
| 298 | // It sends connection close packet when closing connections. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 299 | void CloseAllSessions(int error, quic::QuicErrorCode quic_error); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 300 | |
Matt Menke | 355d7b1e | 2022-05-27 23:19:53 | [diff] [blame] | 301 | base::Value QuicStreamFactoryInfoToValue() const; |
[email protected] | c5b061b | 2013-01-05 00:31:34 | [diff] [blame] | 302 | |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 303 | // 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 Malova | 997d73f6 | 2020-03-02 19:01:13 | [diff] [blame] | 306 | const base::RepeatingCallback<bool(const GURL&)>& origin_filter); |
[email protected] | f7e21a43 | 2014-04-21 22:17:57 | [diff] [blame] | 307 | |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 308 | // 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 Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 314 | NetworkChangeNotifier::NetworkHandle network, |
| 315 | const SocketTag& socket_tag); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 316 | |
jri | ae8cfdc | 2016-01-21 19:44:35 | [diff] [blame] | 317 | // 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 Shi | 673f22ef | 2017-10-18 00:00:47 | [diff] [blame] | 323 | // 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] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 329 | // NetworkChangeNotifier::IPAddressObserver methods: |
| 330 | |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 331 | // Until the servers support roaming, close all connections when the local |
| 332 | // IP address changes. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 333 | void OnIPAddressChanged() override; |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 334 | |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 335 | // 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] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 345 | // CertDatabase::Observer methods: |
| 346 | |
| 347 | // We close all sessions when certificate database is changed. |
mattm | fd05a1f | 2017-02-18 06:18:44 | [diff] [blame] | 348 | void OnCertDBChanged() override; |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 349 | |
Matt Menke | b566c39 | 2019-09-11 23:22:43 | [diff] [blame] | 350 | bool is_quic_known_to_work_on_current_network() const { |
| 351 | return is_quic_known_to_work_on_current_network_; |
| 352 | } |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 353 | |
Nick Harper | 72ade19 | 2019-07-17 03:30:42 | [diff] [blame] | 354 | bool allow_server_migration() const { return params_.allow_server_migration; } |
Zhongyi Shi | f124a58 | 2017-11-02 00:15:04 | [diff] [blame] | 355 | |
Renjie Tang | b23d9998 | 2020-08-20 01:51:17 | [diff] [blame] | 356 | // 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 Menke | b566c39 | 2019-09-11 23:22:43 | [diff] [blame] | 361 | void set_is_quic_known_to_work_on_current_network( |
| 362 | bool is_quic_known_to_work_on_current_network); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 363 | |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 364 | // It returns the amount of time waiting job should be delayed. |
Renjie Tang | dd70897 | 2019-10-03 20:56:21 | [diff] [blame] | 365 | base::TimeDelta GetTimeDelayForWaitingJob(const QuicSessionKey& session_key); |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 366 | |
rch | 12fef55 | 2016-01-15 16:26:31 | [diff] [blame] | 367 | QuicChromiumConnectionHelper* helper() { return helper_.get(); } |
[email protected] | 2cfc6bb8 | 2013-10-27 03:40:44 | [diff] [blame] | 368 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 369 | quic::QuicAlarmFactory* alarm_factory() { return alarm_factory_.get(); } |
rch | 16c74d1d | 2016-04-22 06:14:07 | [diff] [blame] | 370 | |
zhongyi | af25754 | 2016-12-19 03:36:01 | [diff] [blame] | 371 | void set_server_push_delegate(ServerPushDelegate* push_delegate) { |
| 372 | push_delegate_ = push_delegate; |
| 373 | } |
| 374 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 375 | NetworkChangeNotifier::NetworkHandle default_network() const { |
| 376 | return default_network_; |
| 377 | } |
| 378 | |
Cammie Smith Barnes | 0f38aff | 2021-03-02 23:14:35 | [diff] [blame] | 379 | // Returns the stored DNS aliases for the session key. |
Eric Orth | ac66191 | 2022-01-10 21:44:17 | [diff] [blame] | 380 | const std::set<std::string>& GetDnsAliasesForSessionKey( |
Cammie Smith Barnes | 0f38aff | 2021-03-02 23:14:35 | [diff] [blame] | 381 | const QuicSessionKey& key) const; |
| 382 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 383 | private: |
| 384 | class Job; |
Matt Menke | fca05b6 | 2019-09-20 23:15:56 | [diff] [blame] | 385 | class QuicCryptoClientConfigOwner; |
| 386 | class CryptoClientConfigHandle; |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 387 | friend class test::QuicStreamFactoryPeer; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 388 | |
Cammie Smith Barnes | 0f38aff | 2021-03-02 23:14:35 | [diff] [blame] | 389 | 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 Orth | ac66191 | 2022-01-10 21:44:17 | [diff] [blame] | 399 | std::map<QuicSessionKey, std::set<std::string>>; |
Matt Menke | fca05b6 | 2019-09-20 23:15:56 | [diff] [blame] | 400 | using QuicCryptoClientConfigMap = |
| 401 | std::map<NetworkIsolationKey, |
| 402 | std::unique_ptr<QuicCryptoClientConfigOwner>>; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 403 | |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 404 | bool HasMatchingIpSession(const QuicSessionAliasKey& key, |
Cammie Smith Barnes | 0f38aff | 2021-03-02 23:14:35 | [diff] [blame] | 405 | const AddressList& address_list, |
| 406 | bool use_dns_aliases); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 407 | void OnJobComplete(Job* job, int rv); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 408 | bool HasActiveSession(const QuicSessionKey& session_key) const; |
| 409 | bool HasActiveJob(const QuicSessionKey& session_key) const; |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 410 | int CreateSession(const QuicSessionAliasKey& key, |
Ryan Hamilton | 9ef8c10 | 2019-06-28 03:58:52 | [diff] [blame] | 411 | quic::ParsedQuicVersion quic_version, |
rtenneti | a75df62 | 2015-06-21 23:59:50 | [diff] [blame] | 412 | int cert_verify_flags, |
rch | 433bf5f | 2017-02-14 04:10:47 | [diff] [blame] | 413 | bool require_confirmation, |
[email protected] | 338e798 | 2013-12-13 11:15:32 | [diff] [blame] | 414 | const AddressList& address_list, |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 415 | base::TimeTicks dns_resolution_start_time, |
rtenneti | f4f0885 | 2015-02-27 17:50:04 | [diff] [blame] | 416 | base::TimeTicks dns_resolution_end_time, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 417 | const NetLogWithSource& net_log, |
Zhongyi Shi | 55ec953 | 2018-07-24 03:57:39 | [diff] [blame] | 418 | QuicChromiumClientSession** session, |
| 419 | NetworkChangeNotifier::NetworkHandle* network); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 420 | void ActivateSession(const QuicSessionAliasKey& key, |
Cammie Smith Barnes | 0f38aff | 2021-03-02 23:14:35 | [diff] [blame] | 421 | QuicChromiumClientSession* session, |
Eric Orth | ac66191 | 2022-01-10 21:44:17 | [diff] [blame] | 422 | std::set<std::string> dns_aliases); |
Zhongyi Shi | c6b3f03f | 2020-06-25 21:28:22 | [diff] [blame] | 423 | // Go away all active sessions. May disable session's connectivity monitoring |
| 424 | // based on the |reason|. |
| 425 | void MarkAllActiveSessionsGoingAway(AllActiveSessionsGoingAwayReason reason); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 426 | |
Matt Menke | 19475f7 | 2019-08-21 18:57:44 | [diff] [blame] | 427 | void ConfigureInitialRttEstimate( |
| 428 | const quic::QuicServerId& server_id, |
| 429 | const NetworkIsolationKey& network_isolation_key, |
| 430 | quic::QuicConfig* config); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 431 | |
rtenneti | 2912825c | 2015-01-06 01:19:46 | [diff] [blame] | 432 | // 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 Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 435 | int64_t GetServerNetworkStatsSmoothedRttInMicroseconds( |
Matt Menke | 19475f7 | 2019-08-21 18:57:44 | [diff] [blame] | 436 | const quic::QuicServerId& server_id, |
| 437 | const NetworkIsolationKey& network_isolation_key) const; |
rtenneti | 2912825c | 2015-01-06 01:19:46 | [diff] [blame] | 438 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 439 | // 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 Menke | 19475f7 | 2019-08-21 18:57:44 | [diff] [blame] | 443 | const quic::QuicServerId& server_id, |
| 444 | const NetworkIsolationKey& network_isolation_key) const; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 445 | |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 446 | // Helper methods. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 447 | bool WasQuicRecentlyBroken(const QuicSessionKey& session_key) const; |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 448 | |
Zhongyi Shi | d04bd41 | 2019-08-26 23:31:08 | [diff] [blame] | 449 | // 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] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 458 | // Initializes the cached state associated with |server_id| in |
David Benjamin | 6256691 | 2021-10-14 00:56:16 | [diff] [blame] | 459 | // |crypto_config_| with the information in |server_info|. |
[email protected] | 60cf50e | 2014-04-28 23:23:18 | [diff] [blame] | 460 | void InitializeCachedStateInCryptoConfig( |
Matt Menke | fca05b6 | 2019-09-20 23:15:56 | [diff] [blame] | 461 | const CryptoClientConfigHandle& crypto_config_handle, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 462 | const quic::QuicServerId& server_id, |
David Benjamin | 6256691 | 2021-10-14 00:56:16 | [diff] [blame] | 463 | const std::unique_ptr<QuicServerInfo>& server_info); |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 464 | |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 465 | void ProcessGoingAwaySession(QuicChromiumClientSession* session, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 466 | const quic::QuicServerId& server_id, |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 467 | bool was_session_active); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 468 | |
Cammie Smith Barnes | 0f38aff | 2021-03-02 23:14:35 | [diff] [blame] | 469 | // 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 Orth | ac66191 | 2022-01-10 21:44:17 | [diff] [blame] | 474 | std::set<std::string> dns_aliases); |
Cammie Smith Barnes | 0f38aff | 2021-03-02 23:14:35 | [diff] [blame] | 475 | |
| 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 Menke | fca05b6 | 2019-09-20 23:15:56 | [diff] [blame] | 481 | // 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 Shi | c6b3f03f | 2020-06-25 21:28:22 | [diff] [blame] | 495 | // 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 Menke | fca05b6 | 2019-09-20 23:15:56 | [diff] [blame] | 503 | std::unique_ptr<QuicCryptoClientConfigHandle> GetCryptoConfigForTesting( |
| 504 | const NetworkIsolationKey& network_isolation_key); |
| 505 | |
Matt Menke | ca525331 | 2019-09-23 18:59:37 | [diff] [blame] | 506 | bool CryptoConfigCacheIsEmptyForTesting( |
| 507 | const quic::QuicServerId& server_id, |
| 508 | const NetworkIsolationKey& network_isolation_key); |
| 509 | |
Tsuyoshi Horo | 7acebce | 2022-05-12 06:13:23 | [diff] [blame] | 510 | const quic::ParsedQuicVersionVector& supported_versions() const { |
| 511 | return params_.supported_versions; |
| 512 | } |
| 513 | |
Matt Menke | b566c39 | 2019-09-11 23:22:43 | [diff] [blame] | 514 | // 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 Horo | 4478fd3 | 2022-06-09 01:41:25 | [diff] [blame] | 518 | bool is_quic_known_to_work_on_current_network_ = false; |
Matt Menke | b566c39 | 2019-09-11 23:22:43 | [diff] [blame] | 519 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 520 | 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 Harper | 72ade19 | 2019-07-17 03:30:42 | [diff] [blame] | 532 | QuicParams params_; |
rch | f11cc0f | 2016-11-15 03:04:32 | [diff] [blame] | 533 | QuicClockSkewDetector clock_skew_detector_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 534 | |
tbansal | fdf5665b | 2015-09-21 22:46:40 | [diff] [blame] | 535 | // 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 Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 538 | raw_ptr<SocketPerformanceWatcherFactory> socket_performance_watcher_factory_; |
tbansal | fdf5665b | 2015-09-21 22:46:40 | [diff] [blame] | 539 | |
[email protected] | 2cfc6bb8 | 2013-10-27 03:40:44 | [diff] [blame] | 540 | // The helper used for all connections. |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 541 | std::unique_ptr<QuicChromiumConnectionHelper> helper_; |
[email protected] | 2cfc6bb8 | 2013-10-27 03:40:44 | [diff] [blame] | 542 | |
rch | 16c74d1d | 2016-04-22 06:14:07 | [diff] [blame] | 543 | // The alarm factory used for all connections. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 544 | std::unique_ptr<quic::QuicAlarmFactory> alarm_factory_; |
rch | 16c74d1d | 2016-04-22 06:14:07 | [diff] [blame] | 545 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 546 | // Contains owning pointers to all sessions that currently exist. |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 547 | SessionIdMap all_sessions_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 548 | // Contains non-owning pointers to currently active session |
| 549 | // (not going away session, once they're implemented). |
| 550 | SessionMap active_sessions_; |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 551 | // Map from session to set of aliases that this session is known by. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 552 | SessionAliasMap session_aliases_; |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 553 | // Map from IP address to sessions which are connected to this address. |
| 554 | IPAliasMap ip_aliases_; |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 555 | // Map from session to its original peer IP address. |
| 556 | SessionPeerIPMap session_peer_ip_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 557 | |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 558 | // Origins which have gone away recently. |
| 559 | AliasSet gone_away_aliases_; |
| 560 | |
Cammie Smith Barnes | 0f38aff | 2021-03-02 23:14:35 | [diff] [blame] | 561 | // A map of DNS alias vectors by session keys. |
| 562 | DnsAliasesBySessionKeyMap dns_aliases_by_session_key_; |
| 563 | |
Matt Menke | fca05b6 | 2019-09-20 23:15:56 | [diff] [blame] | 564 | // 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 |
cfredric | 8fdc2243 | 2021-10-14 03:24:00 | [diff] [blame] | 567 | // |recent_crypto_config_map_|. If reused before it is evicted from LRUCache, |
Matt Menke | fca05b6 | 2019-09-20 23:15:56 | [diff] [blame] | 568 | // 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_; |
cfredric | 8fdc2243 | 2021-10-14 03:24:00 | [diff] [blame] | 572 | base::LRUCache<NetworkIsolationKey, |
Matt Menke | fca05b6 | 2019-09-20 23:15:56 | [diff] [blame] | 573 | std::unique_ptr<QuicCryptoClientConfigOwner>> |
| 574 | recent_crypto_config_map_; |
| 575 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 576 | const quic::QuicConfig config_; |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 577 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 578 | JobMap active_jobs_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 579 | |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 580 | // PING timeout for connections. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 581 | quic::QuicTime::Delta ping_timeout_; |
| 582 | quic::QuicTime::Delta reduced_ping_timeout_; |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 583 | |
Zhongyi Shi | e01f2db | 2019-02-22 19:53:23 | [diff] [blame] | 584 | // Timeout for how long the wire can have no retransmittable packets. |
| 585 | quic::QuicTime::Delta retransmittable_on_wire_timeout_; |
| 586 | |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 587 | // If more than |yield_after_packets_| packets have been read or more than |
| 588 | // |yield_after_duration_| time has passed, then |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 589 | // QuicChromiumPacketReader::StartReading() yields by doing a PostTask(). |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 590 | int yield_after_packets_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 591 | quic::QuicTime::Delta yield_after_duration_; |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 592 | |
Zhongyi Shi | 6db1346 | 2018-05-19 01:36:26 | [diff] [blame] | 593 | // 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 | |
rtenneti | fc47e0e | 2014-09-26 02:54:05 | [diff] [blame] | 598 | // Local address of socket that was created in CreateSession. |
| 599 | IPEndPoint local_address_; |
Zhongyi Shi | a0cef108 | 2017-08-25 01:49:50 | [diff] [blame] | 600 | // True if we need to check HttpServerProperties if QUIC was supported last |
| 601 | // time. |
Tsuyoshi Horo | 4478fd3 | 2022-06-09 01:41:25 | [diff] [blame] | 602 | bool need_to_check_persisted_supports_quic_ = true; |
| 603 | bool prefer_aes_gcm_recorded_ = false; |
rtenneti | fc47e0e | 2014-09-26 02:54:05 | [diff] [blame] | 604 | |
rtenneti | 041b299 | 2015-02-23 23:03:28 | [diff] [blame] | 605 | NetworkConnection network_connection_; |
| 606 | |
Tsuyoshi Horo | 4478fd3 | 2022-06-09 01:41:25 | [diff] [blame] | 607 | int num_push_streams_created_ = 0; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 608 | |
Zhongyi Shi | c6b3f03f | 2020-06-25 21:28:22 | [diff] [blame] | 609 | QuicConnectivityMonitor connectivity_monitor_; |
| 610 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 611 | raw_ptr<const base::TickClock> tick_clock_; |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 612 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 613 | raw_ptr<base::SequencedTaskRunner> task_runner_; |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 614 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 615 | const raw_ptr<SSLConfigService> ssl_config_service_; |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 616 | |
Matt Menke | fca05b6 | 2019-09-20 23:15:56 | [diff] [blame] | 617 | // 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 Roman | d54000b2 | 2019-07-08 18:40:16 | [diff] [blame] | 627 | base::WeakPtrFactory<QuicStreamFactory> weak_factory_{this}; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 628 | }; |
| 629 | |
| 630 | } // namespace net |
| 631 | |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 632 | #endif // NET_QUIC_QUIC_STREAM_FACTORY_H_ |