blob: 77fb744d66c8b46d69118c805e36db933f5ffb9f [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,
nharper642ae4b2016-06-30 00:40:36153 SSLConfigService* ssl_config_service,
[email protected]e8ff26842013-03-22 21:02:05154 ClientSocketFactory* client_socket_factory,
bnc525e175a2016-06-20 12:36:40155 HttpServerProperties* http_server_properties,
[email protected]59c0bbd2014-03-22 04:08:12156 CertVerifier* cert_verifier,
estark6f9b3d82016-01-12 21:37:05157 CTPolicyEnforcer* ct_policy_enforcer,
[email protected]6b8a3c742014-07-25 00:25:35158 ChannelIDService* channel_id_service,
[email protected]080b77932014-08-04 01:22:46159 TransportSecurityState* transport_security_state,
rtenneti052774e2015-11-24 21:00:12160 CTVerifier* cert_transparency_verifier,
tbansalc8a94ea2015-11-02 23:58:51161 SocketPerformanceWatcherFactory* socket_performance_watcher_factory,
[email protected]e8ff26842013-03-22 21:02:05162 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory,
163 QuicRandom* random_generator,
[email protected]256fe9b2013-11-27 01:58:02164 QuicClock* clock,
[email protected]1e960032013-12-20 19:00:20165 size_t max_packet_length,
[email protected]0c4017ca2014-06-06 03:30:45166 const std::string& user_agent_id,
[email protected]376d38a2014-01-22 03:47:35167 const QuicVersionVector& supported_versions,
[email protected]c80f7c92014-02-27 13:12:02168 bool enable_port_selection,
jri2b966f22014-09-02 22:25:36169 bool always_require_handshake_confirmation,
jri584002d12014-09-09 00:51:28170 bool disable_connection_pooling,
rtenneti2912825c2015-01-06 01:19:46171 float load_server_info_timeout_srtt_multiplier,
rtenneti4f809972015-02-11 19:38:34172 bool enable_connection_racing,
qyearsley3257b7de2015-02-28 06:59:03173 bool enable_non_blocking_io,
rtenneti34dffe752015-02-24 23:27:32174 bool disable_disk_cache,
rch9976b0c2015-06-10 21:27:23175 bool prefer_aes,
rtenneti85dcfac22015-03-27 20:22:19176 int max_number_of_lossy_connections,
177 float packet_loss_threshold,
ckrasic1e53b642015-07-08 22:39:35178 int max_recent_disabled_reasons,
179 int threshold_timeouts_with_streams_open,
180 int threshold_public_resets_post_handshake,
rchc7433572015-02-27 18:16:51181 int socket_receive_buffer_size,
rtennetib8e80fb2016-05-16 00:12:09182 bool delay_tcp_race,
rtenneti6971c172016-01-15 20:12:10183 int max_server_configs_stored_in_properties,
jri8c44d692015-10-23 23:53:41184 bool close_sessions_on_ip_change,
zhongyi89649c32016-01-22 00:14:01185 bool disable_quic_on_timeout_with_open_streams,
rtenneti41c09992015-11-30 18:24:01186 int idle_connection_timeout_seconds,
jri7e636642016-01-14 06:57:08187 bool migrate_sessions_on_network_change,
jrid36ada62016-02-06 02:42:08188 bool migrate_sessions_early,
nharperd5cddca2016-02-27 03:37:52189 const QuicTagVector& connection_options,
190 bool enable_token_binding);
dchengb03027d2014-10-21 12:00:20191 ~QuicStreamFactory() override;
[email protected]e13201d82012-12-12 05:00:32192
bnc359ed2a2016-04-29 20:43:45193 // Returns true if there is an existing session for |server_id| or if the
194 // request can be pooled to an existing session to the IP address of
195 // |destination|.
bnc912a04b2016-04-20 14:19:50196 bool CanUseExistingSession(const QuicServerId& server_id,
bnc359ed2a2016-04-29 20:43:45197 const HostPortPair& destination);
zhongyi32569c62016-01-08 02:54:30198
[email protected]bf4ea2f2014-03-10 22:57:53199 // Creates a new QuicHttpStream to |host_port_pair| which will be
rchf114d982015-10-21 01:34:56200 // owned by |request|.
[email protected]0cceb922014-07-01 02:00:56201 // If a matching session already exists, this method will return OK. If no
202 // matching session exists, this will return ERR_IO_PENDING and will invoke
203 // OnRequestComplete asynchronously.
bnc359ed2a2016-04-29 20:43:45204 int Create(const QuicServerId& server_id,
205 const HostPortPair& destination,
rtennetia75df622015-06-21 23:59:50206 int cert_verify_flags,
ckrasic3865ee0f2016-02-29 22:04:56207 const GURL& url,
[email protected]974849d2014-02-06 01:32:59208 base::StringPiece method,
[email protected]e13201d82012-12-12 05:00:32209 const BoundNetLog& net_log,
210 QuicStreamRequest* request);
211
rtenneti97137a92015-06-18 06:00:31212 // If |packet_loss_rate| is greater than or equal to |packet_loss_threshold_|
213 // it marks QUIC as recently broken for the port of the session. Increments
214 // |number_of_lossy_connections_| by port. If |number_of_lossy_connections_|
215 // is greater than or equal to |max_number_of_lossy_connections_| then it
216 // disables QUIC. If QUIC is disabled then it closes the connection.
217 //
218 // Returns true if QUIC is disabled for the port of the session.
ckrasic4f9d88d2015-07-22 22:23:16219 bool OnHandshakeConfirmed(QuicChromiumClientSession* session,
220 float packet_loss_rate);
rtenneti85dcfac22015-03-27 20:22:19221
rchcee7beb2016-03-11 06:16:14222 // Called when a TCP job completes for an origin that QUIC potentially
223 // could be used for.
224 void OnTcpJobCompleted(bool succeeded);
225
rtenneti85dcfac22015-03-27 20:22:19226 // Returns true if QUIC is disabled for this port.
rchcee7beb2016-03-11 06:16:14227 bool IsQuicDisabled(uint16_t port) const;
rtenneti85dcfac22015-03-27 20:22:19228
ckrasic1e53b642015-07-08 22:39:35229 // Returns reason QUIC is disabled for this port, or QUIC_DISABLED_NOT if not.
ckrasic4f9d88d2015-07-22 22:23:16230 QuicChromiumClientSession::QuicDisabledReason QuicDisabledReason(
Avi Drissman13fc8932015-12-20 04:40:46231 uint16_t port) const;
ckrasic1e53b642015-07-08 22:39:35232
233 // Returns reason QUIC is disabled as string for net-internals, or
234 // returns empty string if QUIC is not disabled.
235 const char* QuicDisabledReasonString() const;
236
[email protected]e13201d82012-12-12 05:00:32237 // Called by a session when it becomes idle.
ckrasic4f9d88d2015-07-22 22:23:16238 void OnIdleSession(QuicChromiumClientSession* session);
[email protected]e13201d82012-12-12 05:00:32239
[email protected]4d283b32013-10-17 12:57:27240 // Called by a session when it is going away and no more streams should be
241 // created on it.
ckrasic4f9d88d2015-07-22 22:23:16242 void OnSessionGoingAway(QuicChromiumClientSession* session);
[email protected]4d283b32013-10-17 12:57:27243
[email protected]e13201d82012-12-12 05:00:32244 // Called by a session after it shuts down.
ckrasic4f9d88d2015-07-22 22:23:16245 void OnSessionClosed(QuicChromiumClientSession* session);
[email protected]e13201d82012-12-12 05:00:32246
[email protected]65768442014-06-06 23:37:03247 // Called by a session whose connection has timed out.
ckrasic4f9d88d2015-07-22 22:23:16248 void OnSessionConnectTimeout(QuicChromiumClientSession* session);
[email protected]65768442014-06-06 23:37:03249
[email protected]e13201d82012-12-12 05:00:32250 // Cancels a pending request.
251 void CancelRequest(QuicStreamRequest* request);
252
jri7e636642016-01-14 06:57:08253 // Closes all current sessions with specified network and QUIC error codes.
254 void CloseAllSessions(int error, QuicErrorCode quic_error);
[email protected]56dfb902013-01-03 23:17:55255
danakjad1777e2016-04-16 00:56:42256 std::unique_ptr<base::Value> QuicStreamFactoryInfoToValue() const;
[email protected]c5b061b2013-01-05 00:31:34257
[email protected]f7e21a432014-04-21 22:17:57258 // Delete all cached state objects in |crypto_config_|.
[email protected]60cf50e2014-04-28 23:23:18259 void ClearCachedStatesInCryptoConfig();
[email protected]f7e21a432014-04-21 22:17:57260
jri7e636642016-01-14 06:57:08261 // Helper method that configures a DatagramClientSocket. Socket is
262 // bound to the default network if the |network| param is
263 // NetworkChangeNotifier::kInvalidNetworkHandle.
264 // Returns net_error code.
265 int ConfigureSocket(DatagramClientSocket* socket,
266 IPEndPoint addr,
267 NetworkChangeNotifier::NetworkHandle network);
268
jriae8cfdc2016-01-21 19:44:35269 // Finds an alternative to |old_network| from the platform's list of connected
270 // networks. Returns NetworkChangeNotifier::kInvalidNetworkHandle if no
271 // alternative is found.
272 NetworkChangeNotifier::NetworkHandle FindAlternateNetwork(
273 NetworkChangeNotifier::NetworkHandle old_network);
274
275 // Method that initiates migration of active sessions
jri7e636642016-01-14 06:57:08276 // currently bound to |network| to an alternate network, if one
277 // exists. Idle sessions bound to |network| are closed. If there is
278 // no alternate network to migrate active sessions onto, active
279 // sessions are closed if |force_close| is true, and continue using
280 // |network| otherwise. Sessions not bound to |network| are left unchanged.
281 void MaybeMigrateOrCloseSessions(NetworkChangeNotifier::NetworkHandle network,
jridf673d22016-06-02 22:06:33282 bool force_close,
283 const BoundNetLog& bound_net_log);
jri7e636642016-01-14 06:57:08284
jriae8cfdc2016-01-21 19:44:35285 // Method that initiates early migration of |session| if |session| is
286 // active and if there is an alternate network than the one to which
287 // |session| is currently bound.
288 void MaybeMigrateSessionEarly(QuicChromiumClientSession* session);
289
290 // Method that migrates |session| over to using |new_network|.
jridf673d22016-06-02 22:06:33291 void MigrateSessionToNetwork(QuicChromiumClientSession* session,
292 NetworkChangeNotifier::NetworkHandle new_network,
293 const BoundNetLog& bound_net_log);
jriae8cfdc2016-01-21 19:44:35294
[email protected]f698a012013-05-06 20:18:59295 // NetworkChangeNotifier::IPAddressObserver methods:
296
297 // Until the servers support roaming, close all connections when the local
298 // IP address changes.
dchengb03027d2014-10-21 12:00:20299 void OnIPAddressChanged() override;
[email protected]f698a012013-05-06 20:18:59300
jri7e636642016-01-14 06:57:08301 // NetworkChangeNotifier::NetworkObserver methods:
302 void OnNetworkConnected(
303 NetworkChangeNotifier::NetworkHandle network) override;
304 void OnNetworkDisconnected(
305 NetworkChangeNotifier::NetworkHandle network) override;
306 void OnNetworkSoonToDisconnect(
307 NetworkChangeNotifier::NetworkHandle network) override;
308 void OnNetworkMadeDefault(
309 NetworkChangeNotifier::NetworkHandle network) override;
310
rch02d87792015-09-09 09:05:53311 // SSLConfigService::Observer methods:
312
313 // We perform the same flushing as described above when SSL settings change.
314 void OnSSLConfigChanged() override;
315
[email protected]d7d1e50b2013-11-25 22:08:09316 // CertDatabase::Observer methods:
317
318 // We close all sessions when certificate database is changed.
dchengb03027d2014-10-21 12:00:20319 void OnCertAdded(const X509Certificate* cert) override;
320 void OnCACertChanged(const X509Certificate* cert) override;
[email protected]d7d1e50b2013-11-25 22:08:09321
rjshaded5ced072015-12-18 19:26:02322 bool require_confirmation() const { return require_confirmation_; }
[email protected]11c05872013-08-20 02:04:12323
rtennetifc47e0e2014-09-26 02:54:05324 void set_require_confirmation(bool require_confirmation);
[email protected]11c05872013-08-20 02:04:12325
rtennetid2e74caa2015-12-09 00:51:57326 bool ZeroRTTEnabledFor(const QuicServerId& server_id);
327
rtenneti8332ba52015-09-17 19:33:41328 // It returns the amount of time waiting job should be delayed.
329 base::TimeDelta GetTimeDelayForWaitingJob(const QuicServerId& server_id);
330
rch12fef552016-01-15 16:26:31331 QuicChromiumConnectionHelper* helper() { return helper_.get(); }
[email protected]2cfc6bb82013-10-27 03:40:44332
rch16c74d1d2016-04-22 06:14:07333 QuicChromiumAlarmFactory* alarm_factory() { return alarm_factory_.get(); }
334
[email protected]376d38a2014-01-22 03:47:35335 bool enable_port_selection() const { return enable_port_selection_; }
336
[email protected]a4205202014-06-02 16:03:08337 bool has_quic_server_info_factory() {
rtenneti6971c172016-01-15 20:12:10338 return quic_server_info_factory_.get() != nullptr;
[email protected]a4205202014-06-02 16:03:08339 }
340
[email protected]e8cf7555b2014-02-28 23:52:53341 void set_quic_server_info_factory(
rtenneti13c9d38d2015-10-12 21:25:01342 QuicServerInfoFactory* quic_server_info_factory);
[email protected]e8cf7555b2014-02-28 23:52:53343
rtenneti14abd312015-02-06 21:56:01344 bool enable_connection_racing() const { return enable_connection_racing_; }
345 void set_enable_connection_racing(bool enable_connection_racing) {
346 enable_connection_racing_ = enable_connection_racing;
347 }
348
rch185ebee2015-07-14 23:56:22349 int socket_receive_buffer_size() const { return socket_receive_buffer_size_; }
350
rtennetib8e80fb2016-05-16 00:12:09351 bool delay_tcp_race() const { return delay_tcp_race_; }
352
[email protected]e13201d82012-12-12 05:00:32353 private:
354 class Job;
[email protected]c49ff182013-09-28 08:33:26355 friend class test::QuicStreamFactoryPeer;
tbansala5268e22015-06-30 02:57:58356 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryTest, QuicLossyProxyMarkedAsBad);
[email protected]e13201d82012-12-12 05:00:32357
ckrasic4f9d88d2015-07-22 22:23:16358 typedef std::map<QuicServerId, QuicChromiumClientSession*> SessionMap;
bnc359ed2a2016-04-29 20:43:45359 typedef std::map<QuicChromiumClientSession*, QuicSessionKey> SessionIdMap;
360 typedef std::set<QuicSessionKey> AliasSet;
ckrasic4f9d88d2015-07-22 22:23:16361 typedef std::map<QuicChromiumClientSession*, AliasSet> SessionAliasMap;
362 typedef std::set<QuicChromiumClientSession*> SessionSet;
rchf114d982015-10-21 01:34:56363 typedef std::map<IPEndPoint, SessionSet> IPAliasMap;
[email protected]257f24f2014-04-01 09:15:37364 typedef std::map<QuicServerId, QuicCryptoClientConfig*> CryptoConfigMap;
rtenneti14abd312015-02-06 21:56:01365 typedef std::set<Job*> JobSet;
366 typedef std::map<QuicServerId, JobSet> JobMap;
367 typedef std::map<QuicStreamRequest*, QuicServerId> RequestMap;
[email protected]e13201d82012-12-12 05:00:32368 typedef std::set<QuicStreamRequest*> RequestSet;
rtenneti14abd312015-02-06 21:56:01369 typedef std::map<QuicServerId, RequestSet> ServerIDRequestsMap;
ckrasic4f9d88d2015-07-22 22:23:16370 typedef std::deque<enum QuicChromiumClientSession::QuicDisabledReason>
ckrasic1e53b642015-07-08 22:39:35371 DisabledReasonsQueue;
rtenneti14abd312015-02-06 21:56:01372
rchcee7beb2016-03-11 06:16:14373 enum FactoryStatus {
374 OPEN, // New streams may be created.
375 CLOSED, // No new streams may be created temporarily.
376 DISABLED // No more streams may be created until the network changes.
377 };
378
rtenneti14abd312015-02-06 21:56:01379 // Creates a job which doesn't wait for server config to be loaded from the
380 // disk cache. This job is started via a PostTask.
bnc359ed2a2016-04-29 20:43:45381 void CreateAuxilaryJob(const QuicSessionKey& key,
rtennetia75df622015-06-21 23:59:50382 int cert_verify_flags,
rtenneti14abd312015-02-06 21:56:01383 const BoundNetLog& net_log);
[email protected]e13201d82012-12-12 05:00:32384
bnccb7ff3c2015-05-21 20:51:55385 // Returns a newly created QuicHttpStream owned by the caller.
danakjad1777e2016-04-16 00:56:42386 std::unique_ptr<QuicHttpStream> CreateFromSession(
thestiga0e18cd2015-09-25 04:58:36387 QuicChromiumClientSession* session);
[email protected]df157d9d2014-03-10 07:27:27388
bnc359ed2a2016-04-29 20:43:45389 bool OnResolution(const QuicSessionKey& key, const AddressList& address_list);
[email protected]e13201d82012-12-12 05:00:32390 void OnJobComplete(Job* job, int rv);
[email protected]257f24f2014-04-01 09:15:37391 bool HasActiveSession(const QuicServerId& server_id) const;
392 bool HasActiveJob(const QuicServerId& server_id) const;
bnc359ed2a2016-04-29 20:43:45393 int CreateSession(const QuicSessionKey& key,
rtennetia75df622015-06-21 23:59:50394 int cert_verify_flags,
danakjad1777e2016-04-16 00:56:42395 std::unique_ptr<QuicServerInfo> quic_server_info,
[email protected]338e7982013-12-13 11:15:32396 const AddressList& address_list,
rtennetif4f08852015-02-27 17:50:04397 base::TimeTicks dns_resolution_end_time,
[email protected]338e7982013-12-13 11:15:32398 const BoundNetLog& net_log,
ckrasic4f9d88d2015-07-22 22:23:16399 QuicChromiumClientSession** session);
bnc359ed2a2016-04-29 20:43:45400 void ActivateSession(const QuicSessionKey& key,
ckrasic4f9d88d2015-07-22 22:23:16401 QuicChromiumClientSession* session);
[email protected]e13201d82012-12-12 05:00:32402
rtenneti2912825c2015-01-06 01:19:46403 // Returns |srtt| in micro seconds from ServerNetworkStats. Returns 0 if there
404 // is no |http_server_properties_| or if |http_server_properties_| doesn't
405 // have ServerNetworkStats for the given |server_id|.
Avi Drissman13fc8932015-12-20 04:40:46406 int64_t GetServerNetworkStatsSmoothedRttInMicroseconds(
rtenneti2912825c2015-01-06 01:19:46407 const QuicServerId& server_id) const;
408
bnccacc0992015-03-20 20:22:22409 // Helper methods.
410 bool WasQuicRecentlyBroken(const QuicServerId& server_id) const;
rtenneti8332ba52015-09-17 19:33:41411
rtenneti14abd312015-02-06 21:56:01412 bool CryptoConfigCacheIsEmpty(const QuicServerId& server_id);
413
[email protected]257f24f2014-04-01 09:15:37414 // Initializes the cached state associated with |server_id| in
rchf37ccc782016-01-31 05:13:50415 // |crypto_config_| with the information in |server_info|. Populates
416 // |connection_id| with the next server designated connection id,
417 // if any, and otherwise leaves it unchanged.
[email protected]60cf50e2014-04-28 23:23:18418 void InitializeCachedStateInCryptoConfig(
419 const QuicServerId& server_id,
danakjad1777e2016-04-16 00:56:42420 const std::unique_ptr<QuicServerInfo>& server_info,
rchf37ccc782016-01-31 05:13:50421 QuicConnectionId* connection_id);
[email protected]b694e48c2014-03-18 17:10:13422
rtenneti8a80a6dc2015-09-21 19:51:13423 // Initialize |quic_supported_servers_at_startup_| with the list of servers
rtenneticd2aaa15b2015-10-10 20:29:33424 // that supported QUIC at start up and also initialize in-memory cache of
425 // QuicServerInfo objects from HttpServerProperties.
426 void MaybeInitialize();
rtenneti8a80a6dc2015-09-21 19:51:13427
ckrasic4f9d88d2015-07-22 22:23:16428 void ProcessGoingAwaySession(QuicChromiumClientSession* session,
[email protected]eb71ab62014-05-23 07:57:53429 const QuicServerId& server_id,
430 bool was_session_active);
[email protected]4d590c9c2014-05-02 05:14:33431
ckrasic1e53b642015-07-08 22:39:35432 // Collect stats from recent connections, possibly disabling Quic.
ckrasic4f9d88d2015-07-22 22:23:16433 void MaybeDisableQuic(QuicChromiumClientSession* session);
ckrasic1e53b642015-07-08 22:39:35434
rchcee7beb2016-03-11 06:16:14435 void MaybeDisableQuic(uint16_t port);
436
[email protected]11c05872013-08-20 02:04:12437 bool require_confirmation_;
jridf673d22016-06-02 22:06:33438 NetLog* net_log_;
[email protected]e13201d82012-12-12 05:00:32439 HostResolver* host_resolver_;
440 ClientSocketFactory* client_socket_factory_;
bnc525e175a2016-06-20 12:36:40441 HttpServerProperties* http_server_properties_;
[email protected]5db452202014-08-19 05:22:15442 TransportSecurityState* transport_security_state_;
rtenneti052774e2015-11-24 21:00:12443 CTVerifier* cert_transparency_verifier_;
danakjad1777e2016-04-16 00:56:42444 std::unique_ptr<QuicServerInfoFactory> quic_server_info_factory_;
[email protected]e8ff26842013-03-22 21:02:05445 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory_;
[email protected]9558c5d32012-12-22 00:08:14446 QuicRandom* random_generator_;
danakjad1777e2016-04-16 00:56:42447 std::unique_ptr<QuicClock> clock_;
[email protected]256fe9b2013-11-27 01:58:02448 const size_t max_packet_length_;
[email protected]e13201d82012-12-12 05:00:32449
tbansalfdf5665b2015-09-21 22:46:40450 // Factory which is used to create socket performance watcher. A new watcher
451 // is created for every QUIC connection.
452 // |socket_performance_watcher_factory_| may be null.
tbansalc8a94ea2015-11-02 23:58:51453 SocketPerformanceWatcherFactory* socket_performance_watcher_factory_;
tbansalfdf5665b2015-09-21 22:46:40454
[email protected]2cfc6bb82013-10-27 03:40:44455 // The helper used for all connections.
danakjad1777e2016-04-16 00:56:42456 std::unique_ptr<QuicChromiumConnectionHelper> helper_;
[email protected]2cfc6bb82013-10-27 03:40:44457
rch16c74d1d2016-04-22 06:14:07458 // The alarm factory used for all connections.
459 std::unique_ptr<QuicChromiumAlarmFactory> alarm_factory_;
460
[email protected]e13201d82012-12-12 05:00:32461 // Contains owning pointers to all sessions that currently exist.
[email protected]4d590c9c2014-05-02 05:14:33462 SessionIdMap all_sessions_;
[email protected]e13201d82012-12-12 05:00:32463 // Contains non-owning pointers to currently active session
464 // (not going away session, once they're implemented).
465 SessionMap active_sessions_;
[email protected]eed749f92013-12-23 18:57:38466 // Map from session to set of aliases that this session is known by.
[email protected]e13201d82012-12-12 05:00:32467 SessionAliasMap session_aliases_;
[email protected]eed749f92013-12-23 18:57:38468 // Map from IP address to sessions which are connected to this address.
469 IPAliasMap ip_aliases_;
[email protected]e13201d82012-12-12 05:00:32470
[email protected]d8e2abf82014-03-06 10:30:10471 // Origins which have gone away recently.
472 AliasSet gone_away_aliases_;
473
[email protected]fd276a282014-06-11 04:26:14474 const QuicConfig config_;
[email protected]59c0bbd2014-03-22 04:08:12475 QuicCryptoClientConfig crypto_config_;
[email protected]b064310782013-05-30 21:12:17476
[email protected]e13201d82012-12-12 05:00:32477 JobMap active_jobs_;
rtenneti14abd312015-02-06 21:56:01478 ServerIDRequestsMap job_requests_map_;
[email protected]e13201d82012-12-12 05:00:32479 RequestMap active_requests_;
480
[email protected]1e960032013-12-20 19:00:20481 QuicVersionVector supported_versions_;
[email protected]e13201d82012-12-12 05:00:32482
[email protected]376d38a2014-01-22 03:47:35483 // Determine if we should consistently select a client UDP port. If false,
484 // then we will just let the OS select a random client port for each new
485 // connection.
486 bool enable_port_selection_;
487
jri2b966f22014-09-02 22:25:36488 // Set if we always require handshake confirmation. If true, this will
489 // introduce at least one RTT for the handshake before the client sends data.
490 bool always_require_handshake_confirmation_;
491
jri584002d12014-09-09 00:51:28492 // Set if we do not want connection pooling.
493 bool disable_connection_pooling_;
494
rtenneti2912825c2015-01-06 01:19:46495 // Specifies the ratio between time to load QUIC server information from disk
496 // cache to 'smoothed RTT'. This ratio is used to calculate the timeout in
497 // milliseconds to wait for loading of QUIC server information. If we don't
498 // want to timeout, set |load_server_info_timeout_srtt_multiplier_| to 0.
499 float load_server_info_timeout_srtt_multiplier_;
500
rtenneti14abd312015-02-06 21:56:01501 // Set if we want to race connections - one connection that sends
502 // INCHOATE_HELLO and another connection that sends CHLO after loading server
503 // config from the disk cache.
504 bool enable_connection_racing_;
505
qyearsley3257b7de2015-02-28 06:59:03506 // Set if experimental non-blocking IO should be used on windows sockets.
507 bool enable_non_blocking_io_;
508
rtenneti34dffe752015-02-24 23:27:32509 // Set if we do not want to load server config from the disk cache.
510 bool disable_disk_cache_;
511
rch9976b0c2015-06-10 21:27:23512 // Set if AES-GCM should be preferred, even if there is no hardware support.
513 bool prefer_aes_;
514
rtenneti85dcfac22015-03-27 20:22:19515 // Set if we want to disable QUIC when there is high packet loss rate.
516 // Specifies the maximum number of connections with high packet loss in a row
517 // after which QUIC will be disabled.
518 int max_number_of_lossy_connections_;
rtenneti374e56882015-03-28 13:49:54519 // Specifies packet loss rate in fraction after which a connection is closed
rtenneti85dcfac22015-03-27 20:22:19520 // and is considered as a lossy connection.
521 float packet_loss_threshold_;
522 // Count number of lossy connections by port.
Avi Drissman13fc8932015-12-20 04:40:46523 std::map<uint16_t, int> number_of_lossy_connections_;
rtenneti85dcfac22015-03-27 20:22:19524
ckrasic1e53b642015-07-08 22:39:35525 // Keep track of stats for recently closed connections, using a
526 // bounded queue.
527 int max_disabled_reasons_;
528 DisabledReasonsQueue disabled_reasons_;
529 // Events that can trigger disabling QUIC
530 int num_public_resets_post_handshake_;
531 int num_timeouts_with_open_streams_;
532 // Keep track the largest values for UMA histograms, that will help
533 // determine good threshold values.
534 int max_public_resets_post_handshake_;
535 int max_timeouts_with_open_streams_;
536 // Thresholds if greater than zero, determine when to
537 int threshold_timeouts_with_open_streams_;
538 int threshold_public_resets_post_handshake_;
539
rchc7433572015-02-27 18:16:51540 // Size of the UDP receive buffer.
541 int socket_receive_buffer_size_;
542
rtennetib8e80fb2016-05-16 00:12:09543 // Set if we do want to delay TCP connection when it is racing with QUIC.
544 bool delay_tcp_race_;
545
rtenneti1cd3b162015-09-29 02:58:28546 // If more than |yield_after_packets_| packets have been read or more than
547 // |yield_after_duration_| time has passed, then
rcha02807b42016-01-29 21:56:15548 // QuicChromiumPacketReader::StartReading() yields by doing a PostTask().
rtenneti1cd3b162015-09-29 02:58:28549 int yield_after_packets_;
550 QuicTime::Delta yield_after_duration_;
551
jri8c44d692015-10-23 23:53:41552 // Set if all sessions should be closed when any local IP address changes.
553 const bool close_sessions_on_ip_change_;
554
jri7e636642016-01-14 06:57:08555 // Set if migration should be attempted on active sessions when primary
556 // interface changes.
557 const bool migrate_sessions_on_network_change_;
558
jrid36ada62016-02-06 02:42:08559 // Set if early migration should be attempted when the connection
560 // experiences poor connectivity.
561 const bool migrate_sessions_early_;
562
rchc7433572015-02-27 18:16:51563 // Each profile will (probably) have a unique port_seed_ value. This value
564 // is used to help seed a pseudo-random number generator (PortSuggester) so
565 // that we consistently (within this profile) suggest the same ephemeral
566 // port when we re-connect to any given server/port. The differences between
567 // profiles (probablistically) prevent two profiles from colliding in their
568 // ephemeral port requests.
Avi Drissman13fc8932015-12-20 04:40:46569 uint64_t port_seed_;
[email protected]7034cf12013-12-13 22:47:07570
rtennetifc47e0e2014-09-26 02:54:05571 // Local address of socket that was created in CreateSession.
572 IPEndPoint local_address_;
573 bool check_persisted_supports_quic_;
rtenneticd2aaa15b2015-10-10 20:29:33574 bool has_initialized_data_;
rtenneti1681f852014-11-13 20:34:03575 std::set<HostPortPair> quic_supported_servers_at_startup_;
rtennetifc47e0e2014-09-26 02:54:05576
rtenneti041b2992015-02-23 23:03:28577 NetworkConnection network_connection_;
578
ckrasic3865ee0f2016-02-29 22:04:56579 int num_push_streams_created_;
580
ckrasic244375a32016-02-04 21:21:22581 QuicClientPushPromiseIndex push_promise_index_;
jric533399b2016-01-29 07:36:01582
rchcee7beb2016-03-11 06:16:14583 // Current status of the factory's ability to create streams.
584 FactoryStatus status_;
585
rtenneti38f5cd52014-10-28 20:28:28586 base::TaskRunner* task_runner_;
587
nharper642ae4b2016-06-30 00:40:36588 const scoped_refptr<SSLConfigService> ssl_config_service_;
589
[email protected]1e960032013-12-20 19:00:20590 base::WeakPtrFactory<QuicStreamFactory> weak_factory_;
591
[email protected]e13201d82012-12-12 05:00:32592 DISALLOW_COPY_AND_ASSIGN(QuicStreamFactory);
593};
594
595} // namespace net
596
597#endif // NET_QUIC_QUIC_STREAM_FACTORY_H_