blob: c2dbfbcf89ffbaaf22eba28ca71c84ca4b07a3b5 [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"
rch02d87792015-09-09 09:05:5339#include "net/ssl/ssl_config_service.h"
[email protected]e13201d82012-12-12 05:00:3240
41namespace net {
42
estark6f9b3d82016-01-12 21:37:0543class CTPolicyEnforcer;
[email protected]6d1b4ed2013-07-10 03:57:5444class CertVerifier;
[email protected]6b8a3c742014-07-25 00:25:3545class ChannelIDService;
[email protected]e13201d82012-12-12 05:00:3246class ClientSocketFactory;
rtenneti052774e2015-11-24 21:00:1247class CTVerifier;
[email protected]6d1b4ed2013-07-10 03:57:5448class HostResolver;
[email protected]77c6c162013-08-17 02:57:4549class HttpServerProperties;
[email protected]e13201d82012-12-12 05:00:3250class QuicClock;
ckrasic4f9d88d2015-07-22 22:23:1651class QuicChromiumClientSession;
rch12fef552016-01-15 16:26:3152class QuicChromiumConnectionHelper;
[email protected]e8ff26842013-03-22 21:02:0553class QuicCryptoClientStreamFactory;
[email protected]9558c5d32012-12-22 00:08:1454class QuicRandom;
[email protected]257f24f2014-04-01 09:15:3755class QuicServerId;
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.
[email protected]bf4ea2f2014-03-10 22:57:5380 int Request(const HostPortPair& host_port_pair,
[email protected]9dd3ff0f2014-03-26 09:51:2881 PrivacyMode privacy_mode,
rtennetia75df622015-06-21 23:59:5082 int cert_verify_flags,
ckrasic3865ee0f2016-02-29 22:04:5683 const GURL& url,
[email protected]974849d2014-02-06 01:32:5984 base::StringPiece method,
[email protected]e13201d82012-12-12 05:00:3285 const BoundNetLog& net_log,
86 const CompletionCallback& callback);
87
88 void OnRequestComplete(int rv);
89
rtenneti8332ba52015-09-17 19:33:4190 // Helper method that calls |factory_|'s GetTimeDelayForWaitingJob(). It
91 // returns the amount of time waiting job should be delayed.
92 base::TimeDelta GetTimeDelayForWaitingJob() const;
93
xunjieli2608f9b2016-03-14 13:39:2394 scoped_ptr<QuicHttpStream> CreateStream();
[email protected]e13201d82012-12-12 05:00:3295
xunjieli5749218c2016-03-22 16:43:0696 scoped_ptr<BidirectionalStreamImpl> CreateBidirectionalStreamImpl();
xunjieli2608f9b2016-03-14 13:39:2397
98 // Sets |session_|.
99 void SetSession(QuicChromiumClientSession* session);
[email protected]e13201d82012-12-12 05:00:32100
shiva.jmd4e2adf2015-09-02 06:35:02101 const std::string& origin_host() const { return origin_host_; }
bnccb7ff3c2015-05-21 20:51:55102
103 PrivacyMode privacy_mode() const { return privacy_mode_; }
104
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_;
[email protected]bf4ea2f2014-03-10 22:57:53109 HostPortPair host_port_pair_;
bnccb7ff3c2015-05-21 20:51:55110 std::string origin_host_;
bnc614a92d32016-04-04 13:56:07111 std::string url_;
bnccb7ff3c2015-05-21 20:51:55112 PrivacyMode privacy_mode_;
[email protected]e13201d82012-12-12 05:00:32113 BoundNetLog net_log_;
114 CompletionCallback callback_;
xunjieli2608f9b2016-03-14 13:39:23115 base::WeakPtr<QuicChromiumClientSession> session_;
[email protected]e13201d82012-12-12 05:00:32116
117 DISALLOW_COPY_AND_ASSIGN(QuicStreamRequest);
118};
119
120// A factory for creating new QuicHttpStreams on top of a pool of
ckrasic4f9d88d2015-07-22 22:23:16121// QuicChromiumClientSessions.
[email protected]f698a012013-05-06 20:18:59122class NET_EXPORT_PRIVATE QuicStreamFactory
[email protected]d7d1e50b2013-11-25 22:08:09123 : public NetworkChangeNotifier::IPAddressObserver,
jri7e636642016-01-14 06:57:08124 public NetworkChangeNotifier::NetworkObserver,
rch02d87792015-09-09 09:05:53125 public SSLConfigService::Observer,
[email protected]d7d1e50b2013-11-25 22:08:09126 public CertDatabase::Observer {
[email protected]e13201d82012-12-12 05:00:32127 public:
[email protected]e8ff26842013-03-22 21:02:05128 QuicStreamFactory(
129 HostResolver* host_resolver,
130 ClientSocketFactory* client_socket_factory,
[email protected]77c6c162013-08-17 02:57:45131 base::WeakPtr<HttpServerProperties> http_server_properties,
[email protected]59c0bbd2014-03-22 04:08:12132 CertVerifier* cert_verifier,
estark6f9b3d82016-01-12 21:37:05133 CTPolicyEnforcer* ct_policy_enforcer,
[email protected]6b8a3c742014-07-25 00:25:35134 ChannelIDService* channel_id_service,
[email protected]080b77932014-08-04 01:22:46135 TransportSecurityState* transport_security_state,
rtenneti052774e2015-11-24 21:00:12136 CTVerifier* cert_transparency_verifier,
tbansalc8a94ea2015-11-02 23:58:51137 SocketPerformanceWatcherFactory* socket_performance_watcher_factory,
[email protected]e8ff26842013-03-22 21:02:05138 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory,
139 QuicRandom* random_generator,
[email protected]256fe9b2013-11-27 01:58:02140 QuicClock* clock,
[email protected]1e960032013-12-20 19:00:20141 size_t max_packet_length,
[email protected]0c4017ca2014-06-06 03:30:45142 const std::string& user_agent_id,
[email protected]376d38a2014-01-22 03:47:35143 const QuicVersionVector& supported_versions,
[email protected]c80f7c92014-02-27 13:12:02144 bool enable_port_selection,
jri2b966f22014-09-02 22:25:36145 bool always_require_handshake_confirmation,
jri584002d12014-09-09 00:51:28146 bool disable_connection_pooling,
rtenneti2912825c2015-01-06 01:19:46147 float load_server_info_timeout_srtt_multiplier,
rtenneti4f809972015-02-11 19:38:34148 bool enable_connection_racing,
qyearsley3257b7de2015-02-28 06:59:03149 bool enable_non_blocking_io,
rtenneti34dffe752015-02-24 23:27:32150 bool disable_disk_cache,
rch9976b0c2015-06-10 21:27:23151 bool prefer_aes,
rtenneti85dcfac22015-03-27 20:22:19152 int max_number_of_lossy_connections,
153 float packet_loss_threshold,
ckrasic1e53b642015-07-08 22:39:35154 int max_recent_disabled_reasons,
155 int threshold_timeouts_with_streams_open,
156 int threshold_public_resets_post_handshake,
rchc7433572015-02-27 18:16:51157 int socket_receive_buffer_size,
rtenneti8332ba52015-09-17 19:33:41158 bool delay_tcp_race,
rtenneti6971c172016-01-15 20:12:10159 int max_server_configs_stored_in_properties,
jri8c44d692015-10-23 23:53:41160 bool close_sessions_on_ip_change,
zhongyi89649c32016-01-22 00:14:01161 bool disable_quic_on_timeout_with_open_streams,
rtenneti41c09992015-11-30 18:24:01162 int idle_connection_timeout_seconds,
jri7e636642016-01-14 06:57:08163 bool migrate_sessions_on_network_change,
jrid36ada62016-02-06 02:42:08164 bool migrate_sessions_early,
nharperd5cddca2016-02-27 03:37:52165 const QuicTagVector& connection_options,
166 bool enable_token_binding);
dchengb03027d2014-10-21 12:00:20167 ~QuicStreamFactory() override;
[email protected]e13201d82012-12-12 05:00:32168
zhongyi32569c62016-01-08 02:54:30169 // Returns true if there is an existing session to |server_id| which can be
170 // used for request to |origin_host|.
171 bool CanUseExistingSession(QuicServerId server_id,
172 PrivacyMode privacy_mode,
173 StringPiece origin_host);
174
[email protected]bf4ea2f2014-03-10 22:57:53175 // Creates a new QuicHttpStream to |host_port_pair| which will be
rchf114d982015-10-21 01:34:56176 // owned by |request|.
[email protected]0cceb922014-07-01 02:00:56177 // If a matching session already exists, this method will return OK. If no
178 // matching session exists, this will return ERR_IO_PENDING and will invoke
179 // OnRequestComplete asynchronously.
[email protected]bf4ea2f2014-03-10 22:57:53180 int Create(const HostPortPair& host_port_pair,
[email protected]9dd3ff0f2014-03-26 09:51:28181 PrivacyMode privacy_mode,
rtennetia75df622015-06-21 23:59:50182 int cert_verify_flags,
ckrasic3865ee0f2016-02-29 22:04:56183 const GURL& url,
[email protected]974849d2014-02-06 01:32:59184 base::StringPiece method,
[email protected]e13201d82012-12-12 05:00:32185 const BoundNetLog& net_log,
186 QuicStreamRequest* request);
187
rtenneti97137a92015-06-18 06:00:31188 // If |packet_loss_rate| is greater than or equal to |packet_loss_threshold_|
189 // it marks QUIC as recently broken for the port of the session. Increments
190 // |number_of_lossy_connections_| by port. If |number_of_lossy_connections_|
191 // is greater than or equal to |max_number_of_lossy_connections_| then it
192 // disables QUIC. If QUIC is disabled then it closes the connection.
193 //
194 // Returns true if QUIC is disabled for the port of the session.
ckrasic4f9d88d2015-07-22 22:23:16195 bool OnHandshakeConfirmed(QuicChromiumClientSession* session,
196 float packet_loss_rate);
rtenneti85dcfac22015-03-27 20:22:19197
rchcee7beb2016-03-11 06:16:14198 // Called when a TCP job completes for an origin that QUIC potentially
199 // could be used for.
200 void OnTcpJobCompleted(bool succeeded);
201
rtenneti85dcfac22015-03-27 20:22:19202 // Returns true if QUIC is disabled for this port.
rchcee7beb2016-03-11 06:16:14203 bool IsQuicDisabled(uint16_t port) const;
rtenneti85dcfac22015-03-27 20:22:19204
ckrasic1e53b642015-07-08 22:39:35205 // Returns reason QUIC is disabled for this port, or QUIC_DISABLED_NOT if not.
ckrasic4f9d88d2015-07-22 22:23:16206 QuicChromiumClientSession::QuicDisabledReason QuicDisabledReason(
Avi Drissman13fc8932015-12-20 04:40:46207 uint16_t port) const;
ckrasic1e53b642015-07-08 22:39:35208
209 // Returns reason QUIC is disabled as string for net-internals, or
210 // returns empty string if QUIC is not disabled.
211 const char* QuicDisabledReasonString() const;
212
[email protected]e13201d82012-12-12 05:00:32213 // Called by a session when it becomes idle.
ckrasic4f9d88d2015-07-22 22:23:16214 void OnIdleSession(QuicChromiumClientSession* session);
[email protected]e13201d82012-12-12 05:00:32215
[email protected]4d283b32013-10-17 12:57:27216 // Called by a session when it is going away and no more streams should be
217 // created on it.
ckrasic4f9d88d2015-07-22 22:23:16218 void OnSessionGoingAway(QuicChromiumClientSession* session);
[email protected]4d283b32013-10-17 12:57:27219
[email protected]e13201d82012-12-12 05:00:32220 // Called by a session after it shuts down.
ckrasic4f9d88d2015-07-22 22:23:16221 void OnSessionClosed(QuicChromiumClientSession* session);
[email protected]e13201d82012-12-12 05:00:32222
[email protected]65768442014-06-06 23:37:03223 // Called by a session whose connection has timed out.
ckrasic4f9d88d2015-07-22 22:23:16224 void OnSessionConnectTimeout(QuicChromiumClientSession* session);
[email protected]65768442014-06-06 23:37:03225
[email protected]e13201d82012-12-12 05:00:32226 // Cancels a pending request.
227 void CancelRequest(QuicStreamRequest* request);
228
jri7e636642016-01-14 06:57:08229 // Closes all current sessions with specified network and QUIC error codes.
230 void CloseAllSessions(int error, QuicErrorCode quic_error);
[email protected]56dfb902013-01-03 23:17:55231
payal.pandeya18956a2015-05-27 05:57:55232 scoped_ptr<base::Value> QuicStreamFactoryInfoToValue() const;
[email protected]c5b061b2013-01-05 00:31:34233
[email protected]f7e21a432014-04-21 22:17:57234 // Delete all cached state objects in |crypto_config_|.
[email protected]60cf50e2014-04-28 23:23:18235 void ClearCachedStatesInCryptoConfig();
[email protected]f7e21a432014-04-21 22:17:57236
jri7e636642016-01-14 06:57:08237 // Helper method that configures a DatagramClientSocket. Socket is
238 // bound to the default network if the |network| param is
239 // NetworkChangeNotifier::kInvalidNetworkHandle.
240 // Returns net_error code.
241 int ConfigureSocket(DatagramClientSocket* socket,
242 IPEndPoint addr,
243 NetworkChangeNotifier::NetworkHandle network);
244
jriae8cfdc2016-01-21 19:44:35245 // Finds an alternative to |old_network| from the platform's list of connected
246 // networks. Returns NetworkChangeNotifier::kInvalidNetworkHandle if no
247 // alternative is found.
248 NetworkChangeNotifier::NetworkHandle FindAlternateNetwork(
249 NetworkChangeNotifier::NetworkHandle old_network);
250
251 // Method that initiates migration of active sessions
jri7e636642016-01-14 06:57:08252 // currently bound to |network| to an alternate network, if one
253 // exists. Idle sessions bound to |network| are closed. If there is
254 // no alternate network to migrate active sessions onto, active
255 // sessions are closed if |force_close| is true, and continue using
256 // |network| otherwise. Sessions not bound to |network| are left unchanged.
257 void MaybeMigrateOrCloseSessions(NetworkChangeNotifier::NetworkHandle network,
258 bool force_close);
259
jriae8cfdc2016-01-21 19:44:35260 // Method that initiates early migration of |session| if |session| is
261 // active and if there is an alternate network than the one to which
262 // |session| is currently bound.
263 void MaybeMigrateSessionEarly(QuicChromiumClientSession* session);
264
265 // Method that migrates |session| over to using |new_network|.
266 void MigrateSessionToNetwork(
267 QuicChromiumClientSession* session,
268 NetworkChangeNotifier::NetworkHandle new_network);
269
[email protected]f698a012013-05-06 20:18:59270 // NetworkChangeNotifier::IPAddressObserver methods:
271
272 // Until the servers support roaming, close all connections when the local
273 // IP address changes.
dchengb03027d2014-10-21 12:00:20274 void OnIPAddressChanged() override;
[email protected]f698a012013-05-06 20:18:59275
jri7e636642016-01-14 06:57:08276 // NetworkChangeNotifier::NetworkObserver methods:
277 void OnNetworkConnected(
278 NetworkChangeNotifier::NetworkHandle network) override;
279 void OnNetworkDisconnected(
280 NetworkChangeNotifier::NetworkHandle network) override;
281 void OnNetworkSoonToDisconnect(
282 NetworkChangeNotifier::NetworkHandle network) override;
283 void OnNetworkMadeDefault(
284 NetworkChangeNotifier::NetworkHandle network) override;
285
rch02d87792015-09-09 09:05:53286 // SSLConfigService::Observer methods:
287
288 // We perform the same flushing as described above when SSL settings change.
289 void OnSSLConfigChanged() override;
290
[email protected]d7d1e50b2013-11-25 22:08:09291 // CertDatabase::Observer methods:
292
293 // We close all sessions when certificate database is changed.
dchengb03027d2014-10-21 12:00:20294 void OnCertAdded(const X509Certificate* cert) override;
295 void OnCACertChanged(const X509Certificate* cert) override;
[email protected]d7d1e50b2013-11-25 22:08:09296
rjshaded5ced072015-12-18 19:26:02297 bool require_confirmation() const { return require_confirmation_; }
[email protected]11c05872013-08-20 02:04:12298
rtennetifc47e0e2014-09-26 02:54:05299 void set_require_confirmation(bool require_confirmation);
[email protected]11c05872013-08-20 02:04:12300
rtennetid2e74caa2015-12-09 00:51:57301 bool ZeroRTTEnabledFor(const QuicServerId& server_id);
302
rtenneti8332ba52015-09-17 19:33:41303 // It returns the amount of time waiting job should be delayed.
304 base::TimeDelta GetTimeDelayForWaitingJob(const QuicServerId& server_id);
305
rch12fef552016-01-15 16:26:31306 QuicChromiumConnectionHelper* helper() { return helper_.get(); }
[email protected]2cfc6bb82013-10-27 03:40:44307
[email protected]376d38a2014-01-22 03:47:35308 bool enable_port_selection() const { return enable_port_selection_; }
309
[email protected]a4205202014-06-02 16:03:08310 bool has_quic_server_info_factory() {
rtenneti6971c172016-01-15 20:12:10311 return quic_server_info_factory_.get() != nullptr;
[email protected]a4205202014-06-02 16:03:08312 }
313
[email protected]e8cf7555b2014-02-28 23:52:53314 void set_quic_server_info_factory(
rtenneti13c9d38d2015-10-12 21:25:01315 QuicServerInfoFactory* quic_server_info_factory);
[email protected]e8cf7555b2014-02-28 23:52:53316
rtenneti14abd312015-02-06 21:56:01317 bool enable_connection_racing() const { return enable_connection_racing_; }
318 void set_enable_connection_racing(bool enable_connection_racing) {
319 enable_connection_racing_ = enable_connection_racing;
320 }
321
rch185ebee2015-07-14 23:56:22322 int socket_receive_buffer_size() const { return socket_receive_buffer_size_; }
323
rtenneti8332ba52015-09-17 19:33:41324 bool delay_tcp_race() const { return delay_tcp_race_; }
325
[email protected]e13201d82012-12-12 05:00:32326 private:
327 class Job;
[email protected]c49ff182013-09-28 08:33:26328 friend class test::QuicStreamFactoryPeer;
tbansala5268e22015-06-30 02:57:58329 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryTest, QuicLossyProxyMarkedAsBad);
[email protected]e13201d82012-12-12 05:00:32330
ckrasic4f9d88d2015-07-22 22:23:16331 typedef std::map<QuicServerId, QuicChromiumClientSession*> SessionMap;
332 typedef std::map<QuicChromiumClientSession*, QuicServerId> SessionIdMap;
[email protected]257f24f2014-04-01 09:15:37333 typedef std::set<QuicServerId> AliasSet;
ckrasic4f9d88d2015-07-22 22:23:16334 typedef std::map<QuicChromiumClientSession*, AliasSet> SessionAliasMap;
335 typedef std::set<QuicChromiumClientSession*> SessionSet;
rchf114d982015-10-21 01:34:56336 typedef std::map<IPEndPoint, SessionSet> IPAliasMap;
[email protected]257f24f2014-04-01 09:15:37337 typedef std::map<QuicServerId, QuicCryptoClientConfig*> CryptoConfigMap;
rtenneti14abd312015-02-06 21:56:01338 typedef std::set<Job*> JobSet;
339 typedef std::map<QuicServerId, JobSet> JobMap;
340 typedef std::map<QuicStreamRequest*, QuicServerId> RequestMap;
[email protected]e13201d82012-12-12 05:00:32341 typedef std::set<QuicStreamRequest*> RequestSet;
rtenneti14abd312015-02-06 21:56:01342 typedef std::map<QuicServerId, RequestSet> ServerIDRequestsMap;
ckrasic4f9d88d2015-07-22 22:23:16343 typedef std::deque<enum QuicChromiumClientSession::QuicDisabledReason>
ckrasic1e53b642015-07-08 22:39:35344 DisabledReasonsQueue;
rtenneti14abd312015-02-06 21:56:01345
rchcee7beb2016-03-11 06:16:14346 enum FactoryStatus {
347 OPEN, // New streams may be created.
348 CLOSED, // No new streams may be created temporarily.
349 DISABLED // No more streams may be created until the network changes.
350 };
351
rtenneti14abd312015-02-06 21:56:01352 // Creates a job which doesn't wait for server config to be loaded from the
353 // disk cache. This job is started via a PostTask.
354 void CreateAuxilaryJob(const QuicServerId server_id,
rtennetia75df622015-06-21 23:59:50355 int cert_verify_flags,
bnc68d401dd2015-05-18 20:31:48356 bool server_and_origin_have_same_host,
rtenneti14abd312015-02-06 21:56:01357 bool is_post,
358 const BoundNetLog& net_log);
[email protected]e13201d82012-12-12 05:00:32359
bnccb7ff3c2015-05-21 20:51:55360 // Returns a newly created QuicHttpStream owned by the caller.
thestiga0e18cd2015-09-25 04:58:36361 scoped_ptr<QuicHttpStream> CreateFromSession(
362 QuicChromiumClientSession* session);
[email protected]df157d9d2014-03-10 07:27:27363
[email protected]257f24f2014-04-01 09:15:37364 bool OnResolution(const QuicServerId& server_id,
[email protected]eed749f92013-12-23 18:57:38365 const AddressList& address_list);
[email protected]e13201d82012-12-12 05:00:32366 void OnJobComplete(Job* job, int rv);
[email protected]257f24f2014-04-01 09:15:37367 bool HasActiveSession(const QuicServerId& server_id) const;
368 bool HasActiveJob(const QuicServerId& server_id) const;
369 int CreateSession(const QuicServerId& server_id,
rtennetia75df622015-06-21 23:59:50370 int cert_verify_flags,
[email protected]17bf15c2014-03-14 10:08:04371 scoped_ptr<QuicServerInfo> quic_server_info,
[email protected]338e7982013-12-13 11:15:32372 const AddressList& address_list,
rtennetif4f08852015-02-27 17:50:04373 base::TimeTicks dns_resolution_end_time,
[email protected]338e7982013-12-13 11:15:32374 const BoundNetLog& net_log,
ckrasic4f9d88d2015-07-22 22:23:16375 QuicChromiumClientSession** session);
[email protected]257f24f2014-04-01 09:15:37376 void ActivateSession(const QuicServerId& key,
ckrasic4f9d88d2015-07-22 22:23:16377 QuicChromiumClientSession* session);
[email protected]e13201d82012-12-12 05:00:32378
rtenneti2912825c2015-01-06 01:19:46379 // Returns |srtt| in micro seconds from ServerNetworkStats. Returns 0 if there
380 // is no |http_server_properties_| or if |http_server_properties_| doesn't
381 // have ServerNetworkStats for the given |server_id|.
Avi Drissman13fc8932015-12-20 04:40:46382 int64_t GetServerNetworkStatsSmoothedRttInMicroseconds(
rtenneti2912825c2015-01-06 01:19:46383 const QuicServerId& server_id) const;
384
bnccacc0992015-03-20 20:22:22385 // Helper methods.
386 bool WasQuicRecentlyBroken(const QuicServerId& server_id) const;
rtenneti8332ba52015-09-17 19:33:41387
rtenneti14abd312015-02-06 21:56:01388 bool CryptoConfigCacheIsEmpty(const QuicServerId& server_id);
389
[email protected]257f24f2014-04-01 09:15:37390 // Initializes the cached state associated with |server_id| in
rchf37ccc782016-01-31 05:13:50391 // |crypto_config_| with the information in |server_info|. Populates
392 // |connection_id| with the next server designated connection id,
393 // if any, and otherwise leaves it unchanged.
[email protected]60cf50e2014-04-28 23:23:18394 void InitializeCachedStateInCryptoConfig(
395 const QuicServerId& server_id,
rchf37ccc782016-01-31 05:13:50396 const scoped_ptr<QuicServerInfo>& server_info,
397 QuicConnectionId* connection_id);
[email protected]b694e48c2014-03-18 17:10:13398
rtenneti8a80a6dc2015-09-21 19:51:13399 // Initialize |quic_supported_servers_at_startup_| with the list of servers
rtenneticd2aaa15b2015-10-10 20:29:33400 // that supported QUIC at start up and also initialize in-memory cache of
401 // QuicServerInfo objects from HttpServerProperties.
402 void MaybeInitialize();
rtenneti8a80a6dc2015-09-21 19:51:13403
ckrasic4f9d88d2015-07-22 22:23:16404 void ProcessGoingAwaySession(QuicChromiumClientSession* session,
[email protected]eb71ab62014-05-23 07:57:53405 const QuicServerId& server_id,
406 bool was_session_active);
[email protected]4d590c9c2014-05-02 05:14:33407
ckrasic1e53b642015-07-08 22:39:35408 // Collect stats from recent connections, possibly disabling Quic.
ckrasic4f9d88d2015-07-22 22:23:16409 void MaybeDisableQuic(QuicChromiumClientSession* session);
ckrasic1e53b642015-07-08 22:39:35410
rchcee7beb2016-03-11 06:16:14411 void MaybeDisableQuic(uint16_t port);
412
[email protected]11c05872013-08-20 02:04:12413 bool require_confirmation_;
[email protected]e13201d82012-12-12 05:00:32414 HostResolver* host_resolver_;
415 ClientSocketFactory* client_socket_factory_;
[email protected]77c6c162013-08-17 02:57:45416 base::WeakPtr<HttpServerProperties> http_server_properties_;
[email protected]5db452202014-08-19 05:22:15417 TransportSecurityState* transport_security_state_;
rtenneti052774e2015-11-24 21:00:12418 CTVerifier* cert_transparency_verifier_;
rtenneti13c9d38d2015-10-12 21:25:01419 scoped_ptr<QuicServerInfoFactory> quic_server_info_factory_;
[email protected]e8ff26842013-03-22 21:02:05420 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory_;
[email protected]9558c5d32012-12-22 00:08:14421 QuicRandom* random_generator_;
[email protected]f1e97e92012-12-16 04:53:25422 scoped_ptr<QuicClock> clock_;
[email protected]256fe9b2013-11-27 01:58:02423 const size_t max_packet_length_;
[email protected]e13201d82012-12-12 05:00:32424
tbansalfdf5665b2015-09-21 22:46:40425 // Factory which is used to create socket performance watcher. A new watcher
426 // is created for every QUIC connection.
427 // |socket_performance_watcher_factory_| may be null.
tbansalc8a94ea2015-11-02 23:58:51428 SocketPerformanceWatcherFactory* socket_performance_watcher_factory_;
tbansalfdf5665b2015-09-21 22:46:40429
[email protected]2cfc6bb82013-10-27 03:40:44430 // The helper used for all connections.
rch12fef552016-01-15 16:26:31431 scoped_ptr<QuicChromiumConnectionHelper> helper_;
[email protected]2cfc6bb82013-10-27 03:40:44432
[email protected]e13201d82012-12-12 05:00:32433 // Contains owning pointers to all sessions that currently exist.
[email protected]4d590c9c2014-05-02 05:14:33434 SessionIdMap all_sessions_;
[email protected]e13201d82012-12-12 05:00:32435 // Contains non-owning pointers to currently active session
436 // (not going away session, once they're implemented).
437 SessionMap active_sessions_;
[email protected]eed749f92013-12-23 18:57:38438 // Map from session to set of aliases that this session is known by.
[email protected]e13201d82012-12-12 05:00:32439 SessionAliasMap session_aliases_;
[email protected]eed749f92013-12-23 18:57:38440 // Map from IP address to sessions which are connected to this address.
441 IPAliasMap ip_aliases_;
[email protected]e13201d82012-12-12 05:00:32442
[email protected]d8e2abf82014-03-06 10:30:10443 // Origins which have gone away recently.
444 AliasSet gone_away_aliases_;
445
[email protected]fd276a282014-06-11 04:26:14446 const QuicConfig config_;
[email protected]59c0bbd2014-03-22 04:08:12447 QuicCryptoClientConfig crypto_config_;
[email protected]b064310782013-05-30 21:12:17448
[email protected]e13201d82012-12-12 05:00:32449 JobMap active_jobs_;
rtenneti14abd312015-02-06 21:56:01450 ServerIDRequestsMap job_requests_map_;
[email protected]e13201d82012-12-12 05:00:32451 RequestMap active_requests_;
452
[email protected]1e960032013-12-20 19:00:20453 QuicVersionVector supported_versions_;
[email protected]e13201d82012-12-12 05:00:32454
[email protected]376d38a2014-01-22 03:47:35455 // Determine if we should consistently select a client UDP port. If false,
456 // then we will just let the OS select a random client port for each new
457 // connection.
458 bool enable_port_selection_;
459
jri2b966f22014-09-02 22:25:36460 // Set if we always require handshake confirmation. If true, this will
461 // introduce at least one RTT for the handshake before the client sends data.
462 bool always_require_handshake_confirmation_;
463
jri584002d12014-09-09 00:51:28464 // Set if we do not want connection pooling.
465 bool disable_connection_pooling_;
466
rtenneti2912825c2015-01-06 01:19:46467 // Specifies the ratio between time to load QUIC server information from disk
468 // cache to 'smoothed RTT'. This ratio is used to calculate the timeout in
469 // milliseconds to wait for loading of QUIC server information. If we don't
470 // want to timeout, set |load_server_info_timeout_srtt_multiplier_| to 0.
471 float load_server_info_timeout_srtt_multiplier_;
472
rtenneti14abd312015-02-06 21:56:01473 // Set if we want to race connections - one connection that sends
474 // INCHOATE_HELLO and another connection that sends CHLO after loading server
475 // config from the disk cache.
476 bool enable_connection_racing_;
477
qyearsley3257b7de2015-02-28 06:59:03478 // Set if experimental non-blocking IO should be used on windows sockets.
479 bool enable_non_blocking_io_;
480
rtenneti34dffe752015-02-24 23:27:32481 // Set if we do not want to load server config from the disk cache.
482 bool disable_disk_cache_;
483
rch9976b0c2015-06-10 21:27:23484 // Set if AES-GCM should be preferred, even if there is no hardware support.
485 bool prefer_aes_;
486
rtenneti85dcfac22015-03-27 20:22:19487 // Set if we want to disable QUIC when there is high packet loss rate.
488 // Specifies the maximum number of connections with high packet loss in a row
489 // after which QUIC will be disabled.
490 int max_number_of_lossy_connections_;
rtenneti374e56882015-03-28 13:49:54491 // Specifies packet loss rate in fraction after which a connection is closed
rtenneti85dcfac22015-03-27 20:22:19492 // and is considered as a lossy connection.
493 float packet_loss_threshold_;
494 // Count number of lossy connections by port.
Avi Drissman13fc8932015-12-20 04:40:46495 std::map<uint16_t, int> number_of_lossy_connections_;
rtenneti85dcfac22015-03-27 20:22:19496
ckrasic1e53b642015-07-08 22:39:35497 // Keep track of stats for recently closed connections, using a
498 // bounded queue.
499 int max_disabled_reasons_;
500 DisabledReasonsQueue disabled_reasons_;
501 // Events that can trigger disabling QUIC
502 int num_public_resets_post_handshake_;
503 int num_timeouts_with_open_streams_;
504 // Keep track the largest values for UMA histograms, that will help
505 // determine good threshold values.
506 int max_public_resets_post_handshake_;
507 int max_timeouts_with_open_streams_;
508 // Thresholds if greater than zero, determine when to
509 int threshold_timeouts_with_open_streams_;
510 int threshold_public_resets_post_handshake_;
511
rchc7433572015-02-27 18:16:51512 // Size of the UDP receive buffer.
513 int socket_receive_buffer_size_;
514
rtenneti8332ba52015-09-17 19:33:41515 // Set if we do want to delay TCP connection when it is racing with QUIC.
516 bool delay_tcp_race_;
517
rtenneti1cd3b162015-09-29 02:58:28518 // If more than |yield_after_packets_| packets have been read or more than
519 // |yield_after_duration_| time has passed, then
rcha02807b42016-01-29 21:56:15520 // QuicChromiumPacketReader::StartReading() yields by doing a PostTask().
rtenneti1cd3b162015-09-29 02:58:28521 int yield_after_packets_;
522 QuicTime::Delta yield_after_duration_;
523
jri8c44d692015-10-23 23:53:41524 // Set if all sessions should be closed when any local IP address changes.
525 const bool close_sessions_on_ip_change_;
526
jri7e636642016-01-14 06:57:08527 // Set if migration should be attempted on active sessions when primary
528 // interface changes.
529 const bool migrate_sessions_on_network_change_;
530
jrid36ada62016-02-06 02:42:08531 // Set if early migration should be attempted when the connection
532 // experiences poor connectivity.
533 const bool migrate_sessions_early_;
534
rchc7433572015-02-27 18:16:51535 // Each profile will (probably) have a unique port_seed_ value. This value
536 // is used to help seed a pseudo-random number generator (PortSuggester) so
537 // that we consistently (within this profile) suggest the same ephemeral
538 // port when we re-connect to any given server/port. The differences between
539 // profiles (probablistically) prevent two profiles from colliding in their
540 // ephemeral port requests.
Avi Drissman13fc8932015-12-20 04:40:46541 uint64_t port_seed_;
[email protected]7034cf12013-12-13 22:47:07542
rtennetifc47e0e2014-09-26 02:54:05543 // Local address of socket that was created in CreateSession.
544 IPEndPoint local_address_;
545 bool check_persisted_supports_quic_;
rtenneticd2aaa15b2015-10-10 20:29:33546 bool has_initialized_data_;
rtenneti1681f852014-11-13 20:34:03547 std::set<HostPortPair> quic_supported_servers_at_startup_;
rtennetifc47e0e2014-09-26 02:54:05548
rtenneti041b2992015-02-23 23:03:28549 NetworkConnection network_connection_;
550
ckrasic3865ee0f2016-02-29 22:04:56551 int num_push_streams_created_;
552
ckrasic244375a32016-02-04 21:21:22553 QuicClientPushPromiseIndex push_promise_index_;
jric533399b2016-01-29 07:36:01554
rchcee7beb2016-03-11 06:16:14555 // Current status of the factory's ability to create streams.
556 FactoryStatus status_;
557
rtenneti38f5cd52014-10-28 20:28:28558 base::TaskRunner* task_runner_;
559
[email protected]1e960032013-12-20 19:00:20560 base::WeakPtrFactory<QuicStreamFactory> weak_factory_;
561
[email protected]e13201d82012-12-12 05:00:32562 DISALLOW_COPY_AND_ASSIGN(QuicStreamFactory);
563};
564
565} // namespace net
566
567#endif // NET_QUIC_QUIC_STREAM_FACTORY_H_