blob: 4be260fcdde9eed1c3c6624513669875689844c4 [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
5#ifndef NET_QUIC_QUIC_STREAM_FACTORY_H_
6#define NET_QUIC_QUIC_STREAM_FACTORY_H_
7
Avi Drissman13fc8932015-12-20 04:40:468#include <stddef.h>
9#include <stdint.h>
10
bnc614a92d32016-04-04 13:56:0711#include <deque>
[email protected]1cd2a5f2014-03-14 06:33:2512#include <list>
[email protected]e13201d82012-12-12 05:00:3213#include <map>
bnc614a92d32016-04-04 13:56:0714#include <set>
[email protected]41d6b172013-01-29 16:10:5715#include <string>
[email protected]6e12d702013-11-13 00:17:1716#include <vector>
[email protected]e13201d82012-12-12 05:00:3217
thestiga0e18cd2015-09-25 04:58:3618#include "base/gtest_prod_util.h"
[email protected]e8cf7555b2014-02-28 23:52:5319#include "base/logging.h"
Avi Drissman13fc8932015-12-20 04:40:4620#include "base/macros.h"
[email protected]e13201d82012-12-12 05:00:3221#include "base/memory/weak_ptr.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"
24#include "net/base/completion_callback.h"
25#include "net/base/host_port_pair.h"
[email protected]f698a012013-05-06 20:18:5926#include "net/base/network_change_notifier.h"
[email protected]d7d1e50b2013-11-25 22:08:0927#include "net/cert/cert_database.h"
zhongyi32569c62016-01-08 02:54:3028#include "net/http/http_server_properties.h"
xunjieli2608f9b2016-03-14 13:39:2329#include "net/http/http_stream_factory.h"
eroman87c53d62015-04-02 06:51:0730#include "net/log/net_log.h"
[email protected]e13201d82012-12-12 05:00:3231#include "net/proxy/proxy_server.h"
rtenneti041b2992015-02-23 23:03:2832#include "net/quic/network_connection.h"
ckrasic4f9d88d2015-07-22 22:23:1633#include "net/quic/quic_chromium_client_session.h"
ckrasic244375a32016-02-04 21:21:2234#include "net/quic/quic_client_push_promise_index.h"
[email protected]ef95114d2013-04-17 17:57:0135#include "net/quic/quic_config.h"
36#include "net/quic/quic_crypto_stream.h"
[email protected]e13201d82012-12-12 05:00:3237#include "net/quic/quic_http_stream.h"
38#include "net/quic/quic_protocol.h"
bnc912a04b2016-04-20 14:19:5039#include "net/quic/quic_server_id.h"
rch02d87792015-09-09 09:05:5340#include "net/ssl/ssl_config_service.h"
[email protected]e13201d82012-12-12 05:00:3241
42namespace net {
43
estark6f9b3d82016-01-12 21:37:0544class CTPolicyEnforcer;
[email protected]6d1b4ed2013-07-10 03:57:5445class CertVerifier;
[email protected]6b8a3c742014-07-25 00:25:3546class ChannelIDService;
[email protected]e13201d82012-12-12 05:00:3247class ClientSocketFactory;
rtenneti052774e2015-11-24 21:00:1248class CTVerifier;
[email protected]6d1b4ed2013-07-10 03:57:5449class HostResolver;
[email protected]77c6c162013-08-17 02:57:4550class HttpServerProperties;
[email protected]e13201d82012-12-12 05:00:3251class QuicClock;
rch16c74d1d2016-04-22 06:14:0752class QuicChromiumAlarmFactory;
rch12fef552016-01-15 16:26:3153class QuicChromiumConnectionHelper;
[email protected]e8ff26842013-03-22 21:02:0554class QuicCryptoClientStreamFactory;
[email protected]9558c5d32012-12-22 00:08:1455class QuicRandom;
rtenneti13c9d38d2015-10-12 21:25:0156class QuicServerInfo;
57class QuicServerInfoFactory;
[email protected]e13201d82012-12-12 05:00:3258class QuicStreamFactory;
tbansalfdf5665b2015-09-21 22:46:4059class SocketPerformanceWatcherFactory;
[email protected]080b77932014-08-04 01:22:4660class TransportSecurityState;
xunjieli5749218c2016-03-22 16:43:0661class BidirectionalStreamImpl;
[email protected]e13201d82012-12-12 05:00:3262
[email protected]c49ff182013-09-28 08:33:2663namespace test {
64class QuicStreamFactoryPeer;
65} // namespace test
66
rtenneti41c09992015-11-30 18:24:0167// When a connection is idle for 30 seconds it will be closed.
68const int kIdleConnectionTimeoutSeconds = 30;
69
[email protected]e13201d82012-12-12 05:00:3270// Encapsulates a pending request for a QuicHttpStream.
71// If the request is still pending when it is destroyed, it will
72// cancel the request with the factory.
73class NET_EXPORT_PRIVATE QuicStreamRequest {
74 public:
75 explicit QuicStreamRequest(QuicStreamFactory* factory);
76 ~QuicStreamRequest();
77
rtennetia75df622015-06-21 23:59:5078 // |cert_verify_flags| is bitwise OR'd of CertVerifier::VerifyFlags and it is
79 // passed to CertVerifier::Verify.
bnc359ed2a2016-04-29 20:43:4580 // |destination| will be resolved and resulting IPEndPoint used to open a
81 // QuicConnection. This can be different than HostPortPair::FromURL(url).
82 int Request(const HostPortPair& destination,
[email protected]9dd3ff0f2014-03-26 09:51:2883 PrivacyMode privacy_mode,
rtennetia75df622015-06-21 23:59:5084 int cert_verify_flags,
ckrasic3865ee0f2016-02-29 22:04:5685 const GURL& url,
[email protected]974849d2014-02-06 01:32:5986 base::StringPiece method,
[email protected]e13201d82012-12-12 05:00:3287 const BoundNetLog& net_log,
88 const CompletionCallback& callback);
89
90 void OnRequestComplete(int rv);
91
rtenneti8332ba52015-09-17 19:33:4192 // Helper method that calls |factory_|'s GetTimeDelayForWaitingJob(). It
93 // returns the amount of time waiting job should be delayed.
94 base::TimeDelta GetTimeDelayForWaitingJob() const;
95
danakjad1777e2016-04-16 00:56:4296 std::unique_ptr<QuicHttpStream> CreateStream();
[email protected]e13201d82012-12-12 05:00:3297
danakjad1777e2016-04-16 00:56:4298 std::unique_ptr<BidirectionalStreamImpl> CreateBidirectionalStreamImpl();
xunjieli2608f9b2016-03-14 13:39:2399
100 // Sets |session_|.
101 void SetSession(QuicChromiumClientSession* session);
[email protected]e13201d82012-12-12 05:00:32102
bnc359ed2a2016-04-29 20:43:45103 const QuicServerId& server_id() const { return server_id_; }
bnccb7ff3c2015-05-21 20:51:55104
thestiga0e18cd2015-09-25 04:58:36105 const BoundNetLog& net_log() const { return net_log_; }
[email protected]e13201d82012-12-12 05:00:32106
107 private:
108 QuicStreamFactory* factory_;
bnc359ed2a2016-04-29 20:43:45109 QuicServerId server_id_;
[email protected]e13201d82012-12-12 05:00:32110 BoundNetLog net_log_;
111 CompletionCallback callback_;
xunjieli2608f9b2016-03-14 13:39:23112 base::WeakPtr<QuicChromiumClientSession> session_;
[email protected]e13201d82012-12-12 05:00:32113
114 DISALLOW_COPY_AND_ASSIGN(QuicStreamRequest);
115};
116
117// A factory for creating new QuicHttpStreams on top of a pool of
ckrasic4f9d88d2015-07-22 22:23:16118// QuicChromiumClientSessions.
[email protected]f698a012013-05-06 20:18:59119class NET_EXPORT_PRIVATE QuicStreamFactory
[email protected]d7d1e50b2013-11-25 22:08:09120 : public NetworkChangeNotifier::IPAddressObserver,
jri7e636642016-01-14 06:57:08121 public NetworkChangeNotifier::NetworkObserver,
rch02d87792015-09-09 09:05:53122 public SSLConfigService::Observer,
[email protected]d7d1e50b2013-11-25 22:08:09123 public CertDatabase::Observer {
[email protected]e13201d82012-12-12 05:00:32124 public:
bnc359ed2a2016-04-29 20:43:45125 // This class encompasses |destination| and |server_id|.
126 // |destination| is a HostPortPair which is resolved
127 // and a QuicConnection is made to the resulting IP address.
128 // |server_id| identifies the origin of the request,
129 // the crypto handshake advertises |server_id.host()| to the server,
130 // and the certificate is also matched against |server_id.host()|.
131 class NET_EXPORT_PRIVATE QuicSessionKey {
132 public:
133 QuicSessionKey() = default;
134 QuicSessionKey(const HostPortPair& destination,
135 const QuicServerId& server_id);
136 ~QuicSessionKey() = default;
137
138 // Needed to be an element of std::set.
139 bool operator<(const QuicSessionKey& other) const;
140 bool operator==(const QuicSessionKey& other) const;
141
142 const HostPortPair& destination() const { return destination_; }
143 const QuicServerId& server_id() const { return server_id_; }
144
145 private:
146 HostPortPair destination_;
147 QuicServerId server_id_;
148 };
149
[email protected]e8ff26842013-03-22 21:02:05150 QuicStreamFactory(
jridf673d22016-06-02 22:06:33151 NetLog* net_log,
[email protected]e8ff26842013-03-22 21:02:05152 HostResolver* host_resolver,
153 ClientSocketFactory* client_socket_factory,
bnc525e175a2016-06-20 12:36:40154 HttpServerProperties* http_server_properties,
[email protected]59c0bbd2014-03-22 04:08:12155 CertVerifier* cert_verifier,
estark6f9b3d82016-01-12 21:37:05156 CTPolicyEnforcer* ct_policy_enforcer,
[email protected]6b8a3c742014-07-25 00:25:35157 ChannelIDService* channel_id_service,
[email protected]080b77932014-08-04 01:22:46158 TransportSecurityState* transport_security_state,
rtenneti052774e2015-11-24 21:00:12159 CTVerifier* cert_transparency_verifier,
tbansalc8a94ea2015-11-02 23:58:51160 SocketPerformanceWatcherFactory* socket_performance_watcher_factory,
[email protected]e8ff26842013-03-22 21:02:05161 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory,
162 QuicRandom* random_generator,
[email protected]256fe9b2013-11-27 01:58:02163 QuicClock* clock,
[email protected]1e960032013-12-20 19:00:20164 size_t max_packet_length,
[email protected]0c4017ca2014-06-06 03:30:45165 const std::string& user_agent_id,
[email protected]376d38a2014-01-22 03:47:35166 const QuicVersionVector& supported_versions,
[email protected]c80f7c92014-02-27 13:12:02167 bool enable_port_selection,
jri2b966f22014-09-02 22:25:36168 bool always_require_handshake_confirmation,
jri584002d12014-09-09 00:51:28169 bool disable_connection_pooling,
rtenneti2912825c2015-01-06 01:19:46170 float load_server_info_timeout_srtt_multiplier,
rtenneti4f809972015-02-11 19:38:34171 bool enable_connection_racing,
qyearsley3257b7de2015-02-28 06:59:03172 bool enable_non_blocking_io,
rtenneti34dffe752015-02-24 23:27:32173 bool disable_disk_cache,
rch9976b0c2015-06-10 21:27:23174 bool prefer_aes,
rtenneti85dcfac22015-03-27 20:22:19175 int max_number_of_lossy_connections,
176 float packet_loss_threshold,
ckrasic1e53b642015-07-08 22:39:35177 int max_recent_disabled_reasons,
178 int threshold_timeouts_with_streams_open,
179 int threshold_public_resets_post_handshake,
rchc7433572015-02-27 18:16:51180 int socket_receive_buffer_size,
rtennetib8e80fb2016-05-16 00:12:09181 bool delay_tcp_race,
rtenneti6971c172016-01-15 20:12:10182 int max_server_configs_stored_in_properties,
jri8c44d692015-10-23 23:53:41183 bool close_sessions_on_ip_change,
zhongyi89649c32016-01-22 00:14:01184 bool disable_quic_on_timeout_with_open_streams,
rtenneti41c09992015-11-30 18:24:01185 int idle_connection_timeout_seconds,
jri7e636642016-01-14 06:57:08186 bool migrate_sessions_on_network_change,
jrid36ada62016-02-06 02:42:08187 bool migrate_sessions_early,
nharperd5cddca2016-02-27 03:37:52188 const QuicTagVector& connection_options,
189 bool enable_token_binding);
dchengb03027d2014-10-21 12:00:20190 ~QuicStreamFactory() override;
[email protected]e13201d82012-12-12 05:00:32191
bnc359ed2a2016-04-29 20:43:45192 // Returns true if there is an existing session for |server_id| or if the
193 // request can be pooled to an existing session to the IP address of
194 // |destination|.
bnc912a04b2016-04-20 14:19:50195 bool CanUseExistingSession(const QuicServerId& server_id,
bnc359ed2a2016-04-29 20:43:45196 const HostPortPair& destination);
zhongyi32569c62016-01-08 02:54:30197
[email protected]bf4ea2f2014-03-10 22:57:53198 // Creates a new QuicHttpStream to |host_port_pair| which will be
rchf114d982015-10-21 01:34:56199 // owned by |request|.
[email protected]0cceb922014-07-01 02:00:56200 // If a matching session already exists, this method will return OK. If no
201 // matching session exists, this will return ERR_IO_PENDING and will invoke
202 // OnRequestComplete asynchronously.
bnc359ed2a2016-04-29 20:43:45203 int Create(const QuicServerId& server_id,
204 const HostPortPair& destination,
rtennetia75df622015-06-21 23:59:50205 int cert_verify_flags,
ckrasic3865ee0f2016-02-29 22:04:56206 const GURL& url,
[email protected]974849d2014-02-06 01:32:59207 base::StringPiece method,
[email protected]e13201d82012-12-12 05:00:32208 const BoundNetLog& net_log,
209 QuicStreamRequest* request);
210
rtenneti97137a92015-06-18 06:00:31211 // If |packet_loss_rate| is greater than or equal to |packet_loss_threshold_|
212 // it marks QUIC as recently broken for the port of the session. Increments
213 // |number_of_lossy_connections_| by port. If |number_of_lossy_connections_|
214 // is greater than or equal to |max_number_of_lossy_connections_| then it
215 // disables QUIC. If QUIC is disabled then it closes the connection.
216 //
217 // Returns true if QUIC is disabled for the port of the session.
ckrasic4f9d88d2015-07-22 22:23:16218 bool OnHandshakeConfirmed(QuicChromiumClientSession* session,
219 float packet_loss_rate);
rtenneti85dcfac22015-03-27 20:22:19220
rchcee7beb2016-03-11 06:16:14221 // Called when a TCP job completes for an origin that QUIC potentially
222 // could be used for.
223 void OnTcpJobCompleted(bool succeeded);
224
rtenneti85dcfac22015-03-27 20:22:19225 // Returns true if QUIC is disabled for this port.
rchcee7beb2016-03-11 06:16:14226 bool IsQuicDisabled(uint16_t port) const;
rtenneti85dcfac22015-03-27 20:22:19227
ckrasic1e53b642015-07-08 22:39:35228 // Returns reason QUIC is disabled for this port, or QUIC_DISABLED_NOT if not.
ckrasic4f9d88d2015-07-22 22:23:16229 QuicChromiumClientSession::QuicDisabledReason QuicDisabledReason(
Avi Drissman13fc8932015-12-20 04:40:46230 uint16_t port) const;
ckrasic1e53b642015-07-08 22:39:35231
232 // Returns reason QUIC is disabled as string for net-internals, or
233 // returns empty string if QUIC is not disabled.
234 const char* QuicDisabledReasonString() const;
235
[email protected]e13201d82012-12-12 05:00:32236 // Called by a session when it becomes idle.
ckrasic4f9d88d2015-07-22 22:23:16237 void OnIdleSession(QuicChromiumClientSession* session);
[email protected]e13201d82012-12-12 05:00:32238
[email protected]4d283b32013-10-17 12:57:27239 // Called by a session when it is going away and no more streams should be
240 // created on it.
ckrasic4f9d88d2015-07-22 22:23:16241 void OnSessionGoingAway(QuicChromiumClientSession* session);
[email protected]4d283b32013-10-17 12:57:27242
[email protected]e13201d82012-12-12 05:00:32243 // Called by a session after it shuts down.
ckrasic4f9d88d2015-07-22 22:23:16244 void OnSessionClosed(QuicChromiumClientSession* session);
[email protected]e13201d82012-12-12 05:00:32245
[email protected]65768442014-06-06 23:37:03246 // Called by a session whose connection has timed out.
ckrasic4f9d88d2015-07-22 22:23:16247 void OnSessionConnectTimeout(QuicChromiumClientSession* session);
[email protected]65768442014-06-06 23:37:03248
[email protected]e13201d82012-12-12 05:00:32249 // Cancels a pending request.
250 void CancelRequest(QuicStreamRequest* request);
251
jri7e636642016-01-14 06:57:08252 // Closes all current sessions with specified network and QUIC error codes.
253 void CloseAllSessions(int error, QuicErrorCode quic_error);
[email protected]56dfb902013-01-03 23:17:55254
danakjad1777e2016-04-16 00:56:42255 std::unique_ptr<base::Value> QuicStreamFactoryInfoToValue() const;
[email protected]c5b061b2013-01-05 00:31:34256
[email protected]f7e21a432014-04-21 22:17:57257 // Delete all cached state objects in |crypto_config_|.
[email protected]60cf50e2014-04-28 23:23:18258 void ClearCachedStatesInCryptoConfig();
[email protected]f7e21a432014-04-21 22:17:57259
jri7e636642016-01-14 06:57:08260 // Helper method that configures a DatagramClientSocket. Socket is
261 // bound to the default network if the |network| param is
262 // NetworkChangeNotifier::kInvalidNetworkHandle.
263 // Returns net_error code.
264 int ConfigureSocket(DatagramClientSocket* socket,
265 IPEndPoint addr,
266 NetworkChangeNotifier::NetworkHandle network);
267
jriae8cfdc2016-01-21 19:44:35268 // Finds an alternative to |old_network| from the platform's list of connected
269 // networks. Returns NetworkChangeNotifier::kInvalidNetworkHandle if no
270 // alternative is found.
271 NetworkChangeNotifier::NetworkHandle FindAlternateNetwork(
272 NetworkChangeNotifier::NetworkHandle old_network);
273
274 // Method that initiates migration of active sessions
jri7e636642016-01-14 06:57:08275 // currently bound to |network| to an alternate network, if one
276 // exists. Idle sessions bound to |network| are closed. If there is
277 // no alternate network to migrate active sessions onto, active
278 // sessions are closed if |force_close| is true, and continue using
279 // |network| otherwise. Sessions not bound to |network| are left unchanged.
280 void MaybeMigrateOrCloseSessions(NetworkChangeNotifier::NetworkHandle network,
jridf673d22016-06-02 22:06:33281 bool force_close,
282 const BoundNetLog& bound_net_log);
jri7e636642016-01-14 06:57:08283
jriae8cfdc2016-01-21 19:44:35284 // Method that initiates early migration of |session| if |session| is
285 // active and if there is an alternate network than the one to which
286 // |session| is currently bound.
287 void MaybeMigrateSessionEarly(QuicChromiumClientSession* session);
288
289 // Method that migrates |session| over to using |new_network|.
jridf673d22016-06-02 22:06:33290 void MigrateSessionToNetwork(QuicChromiumClientSession* session,
291 NetworkChangeNotifier::NetworkHandle new_network,
292 const BoundNetLog& bound_net_log);
jriae8cfdc2016-01-21 19:44:35293
[email protected]f698a012013-05-06 20:18:59294 // NetworkChangeNotifier::IPAddressObserver methods:
295
296 // Until the servers support roaming, close all connections when the local
297 // IP address changes.
dchengb03027d2014-10-21 12:00:20298 void OnIPAddressChanged() override;
[email protected]f698a012013-05-06 20:18:59299
jri7e636642016-01-14 06:57:08300 // NetworkChangeNotifier::NetworkObserver methods:
301 void OnNetworkConnected(
302 NetworkChangeNotifier::NetworkHandle network) override;
303 void OnNetworkDisconnected(
304 NetworkChangeNotifier::NetworkHandle network) override;
305 void OnNetworkSoonToDisconnect(
306 NetworkChangeNotifier::NetworkHandle network) override;
307 void OnNetworkMadeDefault(
308 NetworkChangeNotifier::NetworkHandle network) override;
309
rch02d87792015-09-09 09:05:53310 // SSLConfigService::Observer methods:
311
312 // We perform the same flushing as described above when SSL settings change.
313 void OnSSLConfigChanged() override;
314
[email protected]d7d1e50b2013-11-25 22:08:09315 // CertDatabase::Observer methods:
316
317 // We close all sessions when certificate database is changed.
dchengb03027d2014-10-21 12:00:20318 void OnCertAdded(const X509Certificate* cert) override;
319 void OnCACertChanged(const X509Certificate* cert) override;
[email protected]d7d1e50b2013-11-25 22:08:09320
rjshaded5ced072015-12-18 19:26:02321 bool require_confirmation() const { return require_confirmation_; }
[email protected]11c05872013-08-20 02:04:12322
rtennetifc47e0e2014-09-26 02:54:05323 void set_require_confirmation(bool require_confirmation);
[email protected]11c05872013-08-20 02:04:12324
rtennetid2e74caa2015-12-09 00:51:57325 bool ZeroRTTEnabledFor(const QuicServerId& server_id);
326
rtenneti8332ba52015-09-17 19:33:41327 // It returns the amount of time waiting job should be delayed.
328 base::TimeDelta GetTimeDelayForWaitingJob(const QuicServerId& server_id);
329
rch12fef552016-01-15 16:26:31330 QuicChromiumConnectionHelper* helper() { return helper_.get(); }
[email protected]2cfc6bb82013-10-27 03:40:44331
rch16c74d1d2016-04-22 06:14:07332 QuicChromiumAlarmFactory* alarm_factory() { return alarm_factory_.get(); }
333
[email protected]376d38a2014-01-22 03:47:35334 bool enable_port_selection() const { return enable_port_selection_; }
335
[email protected]a4205202014-06-02 16:03:08336 bool has_quic_server_info_factory() {
rtenneti6971c172016-01-15 20:12:10337 return quic_server_info_factory_.get() != nullptr;
[email protected]a4205202014-06-02 16:03:08338 }
339
[email protected]e8cf7555b2014-02-28 23:52:53340 void set_quic_server_info_factory(
rtenneti13c9d38d2015-10-12 21:25:01341 QuicServerInfoFactory* quic_server_info_factory);
[email protected]e8cf7555b2014-02-28 23:52:53342
rtenneti14abd312015-02-06 21:56:01343 bool enable_connection_racing() const { return enable_connection_racing_; }
344 void set_enable_connection_racing(bool enable_connection_racing) {
345 enable_connection_racing_ = enable_connection_racing;
346 }
347
rch185ebee2015-07-14 23:56:22348 int socket_receive_buffer_size() const { return socket_receive_buffer_size_; }
349
rtennetib8e80fb2016-05-16 00:12:09350 bool delay_tcp_race() const { return delay_tcp_race_; }
351
[email protected]e13201d82012-12-12 05:00:32352 private:
353 class Job;
[email protected]c49ff182013-09-28 08:33:26354 friend class test::QuicStreamFactoryPeer;
tbansala5268e22015-06-30 02:57:58355 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryTest, QuicLossyProxyMarkedAsBad);
[email protected]e13201d82012-12-12 05:00:32356
ckrasic4f9d88d2015-07-22 22:23:16357 typedef std::map<QuicServerId, QuicChromiumClientSession*> SessionMap;
bnc359ed2a2016-04-29 20:43:45358 typedef std::map<QuicChromiumClientSession*, QuicSessionKey> SessionIdMap;
359 typedef std::set<QuicSessionKey> AliasSet;
ckrasic4f9d88d2015-07-22 22:23:16360 typedef std::map<QuicChromiumClientSession*, AliasSet> SessionAliasMap;
361 typedef std::set<QuicChromiumClientSession*> SessionSet;
rchf114d982015-10-21 01:34:56362 typedef std::map<IPEndPoint, SessionSet> IPAliasMap;
[email protected]257f24f2014-04-01 09:15:37363 typedef std::map<QuicServerId, QuicCryptoClientConfig*> CryptoConfigMap;
rtenneti14abd312015-02-06 21:56:01364 typedef std::set<Job*> JobSet;
365 typedef std::map<QuicServerId, JobSet> JobMap;
366 typedef std::map<QuicStreamRequest*, QuicServerId> RequestMap;
[email protected]e13201d82012-12-12 05:00:32367 typedef std::set<QuicStreamRequest*> RequestSet;
rtenneti14abd312015-02-06 21:56:01368 typedef std::map<QuicServerId, RequestSet> ServerIDRequestsMap;
ckrasic4f9d88d2015-07-22 22:23:16369 typedef std::deque<enum QuicChromiumClientSession::QuicDisabledReason>
ckrasic1e53b642015-07-08 22:39:35370 DisabledReasonsQueue;
rtenneti14abd312015-02-06 21:56:01371
rchcee7beb2016-03-11 06:16:14372 enum FactoryStatus {
373 OPEN, // New streams may be created.
374 CLOSED, // No new streams may be created temporarily.
375 DISABLED // No more streams may be created until the network changes.
376 };
377
rtenneti14abd312015-02-06 21:56:01378 // Creates a job which doesn't wait for server config to be loaded from the
379 // disk cache. This job is started via a PostTask.
bnc359ed2a2016-04-29 20:43:45380 void CreateAuxilaryJob(const QuicSessionKey& key,
rtennetia75df622015-06-21 23:59:50381 int cert_verify_flags,
rtenneti14abd312015-02-06 21:56:01382 const BoundNetLog& net_log);
[email protected]e13201d82012-12-12 05:00:32383
bnccb7ff3c2015-05-21 20:51:55384 // Returns a newly created QuicHttpStream owned by the caller.
danakjad1777e2016-04-16 00:56:42385 std::unique_ptr<QuicHttpStream> CreateFromSession(
thestiga0e18cd2015-09-25 04:58:36386 QuicChromiumClientSession* session);
[email protected]df157d9d2014-03-10 07:27:27387
bnc359ed2a2016-04-29 20:43:45388 bool OnResolution(const QuicSessionKey& key, const AddressList& address_list);
[email protected]e13201d82012-12-12 05:00:32389 void OnJobComplete(Job* job, int rv);
[email protected]257f24f2014-04-01 09:15:37390 bool HasActiveSession(const QuicServerId& server_id) const;
391 bool HasActiveJob(const QuicServerId& server_id) const;
bnc359ed2a2016-04-29 20:43:45392 int CreateSession(const QuicSessionKey& key,
rtennetia75df622015-06-21 23:59:50393 int cert_verify_flags,
danakjad1777e2016-04-16 00:56:42394 std::unique_ptr<QuicServerInfo> quic_server_info,
[email protected]338e7982013-12-13 11:15:32395 const AddressList& address_list,
rtennetif4f08852015-02-27 17:50:04396 base::TimeTicks dns_resolution_end_time,
[email protected]338e7982013-12-13 11:15:32397 const BoundNetLog& net_log,
ckrasic4f9d88d2015-07-22 22:23:16398 QuicChromiumClientSession** session);
bnc359ed2a2016-04-29 20:43:45399 void ActivateSession(const QuicSessionKey& key,
ckrasic4f9d88d2015-07-22 22:23:16400 QuicChromiumClientSession* session);
[email protected]e13201d82012-12-12 05:00:32401
rtenneti2912825c2015-01-06 01:19:46402 // Returns |srtt| in micro seconds from ServerNetworkStats. Returns 0 if there
403 // is no |http_server_properties_| or if |http_server_properties_| doesn't
404 // have ServerNetworkStats for the given |server_id|.
Avi Drissman13fc8932015-12-20 04:40:46405 int64_t GetServerNetworkStatsSmoothedRttInMicroseconds(
rtenneti2912825c2015-01-06 01:19:46406 const QuicServerId& server_id) const;
407
bnccacc0992015-03-20 20:22:22408 // Helper methods.
409 bool WasQuicRecentlyBroken(const QuicServerId& server_id) const;
rtenneti8332ba52015-09-17 19:33:41410
rtenneti14abd312015-02-06 21:56:01411 bool CryptoConfigCacheIsEmpty(const QuicServerId& server_id);
412
[email protected]257f24f2014-04-01 09:15:37413 // Initializes the cached state associated with |server_id| in
rchf37ccc782016-01-31 05:13:50414 // |crypto_config_| with the information in |server_info|. Populates
415 // |connection_id| with the next server designated connection id,
416 // if any, and otherwise leaves it unchanged.
[email protected]60cf50e2014-04-28 23:23:18417 void InitializeCachedStateInCryptoConfig(
418 const QuicServerId& server_id,
danakjad1777e2016-04-16 00:56:42419 const std::unique_ptr<QuicServerInfo>& server_info,
rchf37ccc782016-01-31 05:13:50420 QuicConnectionId* connection_id);
[email protected]b694e48c2014-03-18 17:10:13421
rtenneti8a80a6dc2015-09-21 19:51:13422 // Initialize |quic_supported_servers_at_startup_| with the list of servers
rtenneticd2aaa15b2015-10-10 20:29:33423 // that supported QUIC at start up and also initialize in-memory cache of
424 // QuicServerInfo objects from HttpServerProperties.
425 void MaybeInitialize();
rtenneti8a80a6dc2015-09-21 19:51:13426
ckrasic4f9d88d2015-07-22 22:23:16427 void ProcessGoingAwaySession(QuicChromiumClientSession* session,
[email protected]eb71ab62014-05-23 07:57:53428 const QuicServerId& server_id,
429 bool was_session_active);
[email protected]4d590c9c2014-05-02 05:14:33430
ckrasic1e53b642015-07-08 22:39:35431 // Collect stats from recent connections, possibly disabling Quic.
ckrasic4f9d88d2015-07-22 22:23:16432 void MaybeDisableQuic(QuicChromiumClientSession* session);
ckrasic1e53b642015-07-08 22:39:35433
rchcee7beb2016-03-11 06:16:14434 void MaybeDisableQuic(uint16_t port);
435
[email protected]11c05872013-08-20 02:04:12436 bool require_confirmation_;
jridf673d22016-06-02 22:06:33437 NetLog* net_log_;
[email protected]e13201d82012-12-12 05:00:32438 HostResolver* host_resolver_;
439 ClientSocketFactory* client_socket_factory_;
bnc525e175a2016-06-20 12:36:40440 HttpServerProperties* http_server_properties_;
[email protected]5db452202014-08-19 05:22:15441 TransportSecurityState* transport_security_state_;
rtenneti052774e2015-11-24 21:00:12442 CTVerifier* cert_transparency_verifier_;
danakjad1777e2016-04-16 00:56:42443 std::unique_ptr<QuicServerInfoFactory> quic_server_info_factory_;
[email protected]e8ff26842013-03-22 21:02:05444 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory_;
[email protected]9558c5d32012-12-22 00:08:14445 QuicRandom* random_generator_;
danakjad1777e2016-04-16 00:56:42446 std::unique_ptr<QuicClock> clock_;
[email protected]256fe9b2013-11-27 01:58:02447 const size_t max_packet_length_;
[email protected]e13201d82012-12-12 05:00:32448
tbansalfdf5665b2015-09-21 22:46:40449 // Factory which is used to create socket performance watcher. A new watcher
450 // is created for every QUIC connection.
451 // |socket_performance_watcher_factory_| may be null.
tbansalc8a94ea2015-11-02 23:58:51452 SocketPerformanceWatcherFactory* socket_performance_watcher_factory_;
tbansalfdf5665b2015-09-21 22:46:40453
[email protected]2cfc6bb82013-10-27 03:40:44454 // The helper used for all connections.
danakjad1777e2016-04-16 00:56:42455 std::unique_ptr<QuicChromiumConnectionHelper> helper_;
[email protected]2cfc6bb82013-10-27 03:40:44456
rch16c74d1d2016-04-22 06:14:07457 // The alarm factory used for all connections.
458 std::unique_ptr<QuicChromiumAlarmFactory> alarm_factory_;
459
[email protected]e13201d82012-12-12 05:00:32460 // Contains owning pointers to all sessions that currently exist.
[email protected]4d590c9c2014-05-02 05:14:33461 SessionIdMap all_sessions_;
[email protected]e13201d82012-12-12 05:00:32462 // Contains non-owning pointers to currently active session
463 // (not going away session, once they're implemented).
464 SessionMap active_sessions_;
[email protected]eed749f92013-12-23 18:57:38465 // Map from session to set of aliases that this session is known by.
[email protected]e13201d82012-12-12 05:00:32466 SessionAliasMap session_aliases_;
[email protected]eed749f92013-12-23 18:57:38467 // Map from IP address to sessions which are connected to this address.
468 IPAliasMap ip_aliases_;
[email protected]e13201d82012-12-12 05:00:32469
[email protected]d8e2abf82014-03-06 10:30:10470 // Origins which have gone away recently.
471 AliasSet gone_away_aliases_;
472
[email protected]fd276a282014-06-11 04:26:14473 const QuicConfig config_;
[email protected]59c0bbd2014-03-22 04:08:12474 QuicCryptoClientConfig crypto_config_;
[email protected]b064310782013-05-30 21:12:17475
[email protected]e13201d82012-12-12 05:00:32476 JobMap active_jobs_;
rtenneti14abd312015-02-06 21:56:01477 ServerIDRequestsMap job_requests_map_;
[email protected]e13201d82012-12-12 05:00:32478 RequestMap active_requests_;
479
[email protected]1e960032013-12-20 19:00:20480 QuicVersionVector supported_versions_;
[email protected]e13201d82012-12-12 05:00:32481
[email protected]376d38a2014-01-22 03:47:35482 // Determine if we should consistently select a client UDP port. If false,
483 // then we will just let the OS select a random client port for each new
484 // connection.
485 bool enable_port_selection_;
486
jri2b966f22014-09-02 22:25:36487 // Set if we always require handshake confirmation. If true, this will
488 // introduce at least one RTT for the handshake before the client sends data.
489 bool always_require_handshake_confirmation_;
490
jri584002d12014-09-09 00:51:28491 // Set if we do not want connection pooling.
492 bool disable_connection_pooling_;
493
rtenneti2912825c2015-01-06 01:19:46494 // Specifies the ratio between time to load QUIC server information from disk
495 // cache to 'smoothed RTT'. This ratio is used to calculate the timeout in
496 // milliseconds to wait for loading of QUIC server information. If we don't
497 // want to timeout, set |load_server_info_timeout_srtt_multiplier_| to 0.
498 float load_server_info_timeout_srtt_multiplier_;
499
rtenneti14abd312015-02-06 21:56:01500 // Set if we want to race connections - one connection that sends
501 // INCHOATE_HELLO and another connection that sends CHLO after loading server
502 // config from the disk cache.
503 bool enable_connection_racing_;
504
qyearsley3257b7de2015-02-28 06:59:03505 // Set if experimental non-blocking IO should be used on windows sockets.
506 bool enable_non_blocking_io_;
507
rtenneti34dffe752015-02-24 23:27:32508 // Set if we do not want to load server config from the disk cache.
509 bool disable_disk_cache_;
510
rch9976b0c2015-06-10 21:27:23511 // Set if AES-GCM should be preferred, even if there is no hardware support.
512 bool prefer_aes_;
513
rtenneti85dcfac22015-03-27 20:22:19514 // Set if we want to disable QUIC when there is high packet loss rate.
515 // Specifies the maximum number of connections with high packet loss in a row
516 // after which QUIC will be disabled.
517 int max_number_of_lossy_connections_;
rtenneti374e56882015-03-28 13:49:54518 // Specifies packet loss rate in fraction after which a connection is closed
rtenneti85dcfac22015-03-27 20:22:19519 // and is considered as a lossy connection.
520 float packet_loss_threshold_;
521 // Count number of lossy connections by port.
Avi Drissman13fc8932015-12-20 04:40:46522 std::map<uint16_t, int> number_of_lossy_connections_;
rtenneti85dcfac22015-03-27 20:22:19523
ckrasic1e53b642015-07-08 22:39:35524 // Keep track of stats for recently closed connections, using a
525 // bounded queue.
526 int max_disabled_reasons_;
527 DisabledReasonsQueue disabled_reasons_;
528 // Events that can trigger disabling QUIC
529 int num_public_resets_post_handshake_;
530 int num_timeouts_with_open_streams_;
531 // Keep track the largest values for UMA histograms, that will help
532 // determine good threshold values.
533 int max_public_resets_post_handshake_;
534 int max_timeouts_with_open_streams_;
535 // Thresholds if greater than zero, determine when to
536 int threshold_timeouts_with_open_streams_;
537 int threshold_public_resets_post_handshake_;
538
rchc7433572015-02-27 18:16:51539 // Size of the UDP receive buffer.
540 int socket_receive_buffer_size_;
541
rtennetib8e80fb2016-05-16 00:12:09542 // Set if we do want to delay TCP connection when it is racing with QUIC.
543 bool delay_tcp_race_;
544
rtenneti1cd3b162015-09-29 02:58:28545 // If more than |yield_after_packets_| packets have been read or more than
546 // |yield_after_duration_| time has passed, then
rcha02807b42016-01-29 21:56:15547 // QuicChromiumPacketReader::StartReading() yields by doing a PostTask().
rtenneti1cd3b162015-09-29 02:58:28548 int yield_after_packets_;
549 QuicTime::Delta yield_after_duration_;
550
jri8c44d692015-10-23 23:53:41551 // Set if all sessions should be closed when any local IP address changes.
552 const bool close_sessions_on_ip_change_;
553
jri7e636642016-01-14 06:57:08554 // Set if migration should be attempted on active sessions when primary
555 // interface changes.
556 const bool migrate_sessions_on_network_change_;
557
jrid36ada62016-02-06 02:42:08558 // Set if early migration should be attempted when the connection
559 // experiences poor connectivity.
560 const bool migrate_sessions_early_;
561
rchc7433572015-02-27 18:16:51562 // Each profile will (probably) have a unique port_seed_ value. This value
563 // is used to help seed a pseudo-random number generator (PortSuggester) so
564 // that we consistently (within this profile) suggest the same ephemeral
565 // port when we re-connect to any given server/port. The differences between
566 // profiles (probablistically) prevent two profiles from colliding in their
567 // ephemeral port requests.
Avi Drissman13fc8932015-12-20 04:40:46568 uint64_t port_seed_;
[email protected]7034cf12013-12-13 22:47:07569
rtennetifc47e0e2014-09-26 02:54:05570 // Local address of socket that was created in CreateSession.
571 IPEndPoint local_address_;
572 bool check_persisted_supports_quic_;
rtenneticd2aaa15b2015-10-10 20:29:33573 bool has_initialized_data_;
rtenneti1681f852014-11-13 20:34:03574 std::set<HostPortPair> quic_supported_servers_at_startup_;
rtennetifc47e0e2014-09-26 02:54:05575
rtenneti041b2992015-02-23 23:03:28576 NetworkConnection network_connection_;
577
ckrasic3865ee0f2016-02-29 22:04:56578 int num_push_streams_created_;
579
ckrasic244375a32016-02-04 21:21:22580 QuicClientPushPromiseIndex push_promise_index_;
jric533399b2016-01-29 07:36:01581
rchcee7beb2016-03-11 06:16:14582 // Current status of the factory's ability to create streams.
583 FactoryStatus status_;
584
rtenneti38f5cd52014-10-28 20:28:28585 base::TaskRunner* task_runner_;
586
[email protected]1e960032013-12-20 19:00:20587 base::WeakPtrFactory<QuicStreamFactory> weak_factory_;
588
[email protected]e13201d82012-12-12 05:00:32589 DISALLOW_COPY_AND_ASSIGN(QuicStreamFactory);
590};
591
592} // namespace net
593
594#endif // NET_QUIC_QUIC_STREAM_FACTORY_H_