[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_QUIC_QUIC_STREAM_FACTORY_H_ |
| 6 | #define NET_QUIC_QUIC_STREAM_FACTORY_H_ |
| 7 | |
[email protected] | 1cd2a5f | 2014-03-14 06:33:25 | [diff] [blame] | 8 | #include <list> |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 9 | #include <map> |
[email protected] | 41d6b17 | 2013-01-29 16:10:57 | [diff] [blame] | 10 | #include <string> |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 11 | #include <vector> |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 12 | |
thestig | a0e18cd | 2015-09-25 04:58:36 | [diff] [blame] | 13 | #include "base/gtest_prod_util.h" |
[email protected] | e8cf7555b | 2014-02-28 23:52:53 | [diff] [blame] | 14 | #include "base/logging.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 16 | #include "base/time/time.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 17 | #include "net/base/address_list.h" |
| 18 | #include "net/base/completion_callback.h" |
| 19 | #include "net/base/host_port_pair.h" |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 20 | #include "net/base/network_change_notifier.h" |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 21 | #include "net/cert/cert_database.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 22 | #include "net/log/net_log.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 23 | #include "net/proxy/proxy_server.h" |
rtenneti | 041b299 | 2015-02-23 23:03:28 | [diff] [blame] | 24 | #include "net/quic/network_connection.h" |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 25 | #include "net/quic/quic_chromium_client_session.h" |
[email protected] | ef95114d | 2013-04-17 17:57:01 | [diff] [blame] | 26 | #include "net/quic/quic_config.h" |
| 27 | #include "net/quic/quic_crypto_stream.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 28 | #include "net/quic/quic_http_stream.h" |
| 29 | #include "net/quic/quic_protocol.h" |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 30 | #include "net/ssl/ssl_config_service.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 31 | |
| 32 | namespace net { |
| 33 | |
rsleevi | 9541f863 | 2015-07-31 00:07:00 | [diff] [blame] | 34 | class CertPolicyEnforcer; |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 35 | class CertVerifier; |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 36 | class ChannelIDService; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 37 | class ClientSocketFactory; |
rtenneti | 052774e | 2015-11-24 21:00:12 | [diff] [blame] | 38 | class CTVerifier; |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 39 | class HostResolver; |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 40 | class HttpServerProperties; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 41 | class QuicClock; |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 42 | class QuicChromiumClientSession; |
[email protected] | 2cfc6bb8 | 2013-10-27 03:40:44 | [diff] [blame] | 43 | class QuicConnectionHelper; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 44 | class QuicCryptoClientStreamFactory; |
[email protected] | 9558c5d3 | 2012-12-22 00:08:14 | [diff] [blame] | 45 | class QuicRandom; |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 46 | class QuicServerId; |
rtenneti | 13c9d38d | 2015-10-12 21:25:01 | [diff] [blame] | 47 | class QuicServerInfo; |
| 48 | class QuicServerInfoFactory; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 49 | class QuicStreamFactory; |
tbansal | fdf5665b | 2015-09-21 22:46:40 | [diff] [blame] | 50 | class SocketPerformanceWatcherFactory; |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 51 | class TransportSecurityState; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 52 | |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 53 | namespace test { |
| 54 | class QuicStreamFactoryPeer; |
| 55 | } // namespace test |
| 56 | |
rtenneti | 41c0999 | 2015-11-30 18:24:01 | [diff] [blame] | 57 | // When a connection is idle for 30 seconds it will be closed. |
| 58 | const int kIdleConnectionTimeoutSeconds = 30; |
| 59 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 60 | // Encapsulates a pending request for a QuicHttpStream. |
| 61 | // If the request is still pending when it is destroyed, it will |
| 62 | // cancel the request with the factory. |
| 63 | class NET_EXPORT_PRIVATE QuicStreamRequest { |
| 64 | public: |
| 65 | explicit QuicStreamRequest(QuicStreamFactory* factory); |
| 66 | ~QuicStreamRequest(); |
| 67 | |
rtenneti | a75df62 | 2015-06-21 23:59:50 | [diff] [blame] | 68 | // |cert_verify_flags| is bitwise OR'd of CertVerifier::VerifyFlags and it is |
| 69 | // passed to CertVerifier::Verify. |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 70 | int Request(const HostPortPair& host_port_pair, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 71 | PrivacyMode privacy_mode, |
rtenneti | a75df62 | 2015-06-21 23:59:50 | [diff] [blame] | 72 | int cert_verify_flags, |
bnc | 68d401dd | 2015-05-18 20:31:48 | [diff] [blame] | 73 | base::StringPiece origin_host, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 74 | base::StringPiece method, |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 75 | const BoundNetLog& net_log, |
| 76 | const CompletionCallback& callback); |
| 77 | |
| 78 | void OnRequestComplete(int rv); |
| 79 | |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 80 | // Helper method that calls |factory_|'s GetTimeDelayForWaitingJob(). It |
| 81 | // returns the amount of time waiting job should be delayed. |
| 82 | base::TimeDelta GetTimeDelayForWaitingJob() const; |
| 83 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 84 | scoped_ptr<QuicHttpStream> ReleaseStream(); |
| 85 | |
| 86 | void set_stream(scoped_ptr<QuicHttpStream> stream); |
| 87 | |
shiva.jm | d4e2adf | 2015-09-02 06:35:02 | [diff] [blame] | 88 | const std::string& origin_host() const { return origin_host_; } |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 89 | |
| 90 | PrivacyMode privacy_mode() const { return privacy_mode_; } |
| 91 | |
thestig | a0e18cd | 2015-09-25 04:58:36 | [diff] [blame] | 92 | const BoundNetLog& net_log() const { return net_log_; } |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 93 | |
| 94 | private: |
| 95 | QuicStreamFactory* factory_; |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 96 | HostPortPair host_port_pair_; |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 97 | std::string origin_host_; |
| 98 | PrivacyMode privacy_mode_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 99 | BoundNetLog net_log_; |
| 100 | CompletionCallback callback_; |
| 101 | scoped_ptr<QuicHttpStream> stream_; |
| 102 | |
| 103 | DISALLOW_COPY_AND_ASSIGN(QuicStreamRequest); |
| 104 | }; |
| 105 | |
| 106 | // A factory for creating new QuicHttpStreams on top of a pool of |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 107 | // QuicChromiumClientSessions. |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 108 | class NET_EXPORT_PRIVATE QuicStreamFactory |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 109 | : public NetworkChangeNotifier::IPAddressObserver, |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 110 | public SSLConfigService::Observer, |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 111 | public CertDatabase::Observer { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 112 | public: |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 113 | QuicStreamFactory( |
| 114 | HostResolver* host_resolver, |
| 115 | ClientSocketFactory* client_socket_factory, |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 116 | base::WeakPtr<HttpServerProperties> http_server_properties, |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 117 | CertVerifier* cert_verifier, |
rsleevi | 9541f863 | 2015-07-31 00:07:00 | [diff] [blame] | 118 | CertPolicyEnforcer* cert_policy_enforcer, |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 119 | ChannelIDService* channel_id_service, |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 120 | TransportSecurityState* transport_security_state, |
rtenneti | 052774e | 2015-11-24 21:00:12 | [diff] [blame] | 121 | CTVerifier* cert_transparency_verifier, |
tbansal | c8a94ea | 2015-11-02 23:58:51 | [diff] [blame] | 122 | SocketPerformanceWatcherFactory* socket_performance_watcher_factory, |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 123 | QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory, |
| 124 | QuicRandom* random_generator, |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 125 | QuicClock* clock, |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 126 | size_t max_packet_length, |
[email protected] | 0c4017ca | 2014-06-06 03:30:45 | [diff] [blame] | 127 | const std::string& user_agent_id, |
[email protected] | 376d38a | 2014-01-22 03:47:35 | [diff] [blame] | 128 | const QuicVersionVector& supported_versions, |
[email protected] | c80f7c9 | 2014-02-27 13:12:02 | [diff] [blame] | 129 | bool enable_port_selection, |
jri | 2b966f2 | 2014-09-02 22:25:36 | [diff] [blame] | 130 | bool always_require_handshake_confirmation, |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 131 | bool disable_connection_pooling, |
rtenneti | 2912825c | 2015-01-06 01:19:46 | [diff] [blame] | 132 | float load_server_info_timeout_srtt_multiplier, |
rtenneti | 4f80997 | 2015-02-11 19:38:34 | [diff] [blame] | 133 | bool enable_connection_racing, |
qyearsley | 3257b7de | 2015-02-28 06:59:03 | [diff] [blame] | 134 | bool enable_non_blocking_io, |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 135 | bool disable_disk_cache, |
rch | 9976b0c | 2015-06-10 21:27:23 | [diff] [blame] | 136 | bool prefer_aes, |
rtenneti | 85dcfac2 | 2015-03-27 20:22:19 | [diff] [blame] | 137 | int max_number_of_lossy_connections, |
| 138 | float packet_loss_threshold, |
ckrasic | 1e53b64 | 2015-07-08 22:39:35 | [diff] [blame] | 139 | int max_recent_disabled_reasons, |
| 140 | int threshold_timeouts_with_streams_open, |
| 141 | int threshold_public_resets_post_handshake, |
rch | c743357 | 2015-02-27 18:16:51 | [diff] [blame] | 142 | int socket_receive_buffer_size, |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 143 | bool delay_tcp_race, |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 144 | bool store_server_configs_in_properties, |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 145 | bool close_sessions_on_ip_change, |
rtenneti | 41c0999 | 2015-11-30 18:24:01 | [diff] [blame] | 146 | int idle_connection_timeout_seconds, |
[email protected] | 4b4efab3 | 2014-07-01 02:36:16 | [diff] [blame] | 147 | const QuicTagVector& connection_options); |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 148 | ~QuicStreamFactory() override; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 149 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 150 | // Creates a new QuicHttpStream to |host_port_pair| which will be |
rch | f114d98 | 2015-10-21 01:34:56 | [diff] [blame] | 151 | // owned by |request|. |
[email protected] | 0cceb92 | 2014-07-01 02:00:56 | [diff] [blame] | 152 | // If a matching session already exists, this method will return OK. If no |
| 153 | // matching session exists, this will return ERR_IO_PENDING and will invoke |
| 154 | // OnRequestComplete asynchronously. |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 155 | int Create(const HostPortPair& host_port_pair, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 156 | PrivacyMode privacy_mode, |
rtenneti | a75df62 | 2015-06-21 23:59:50 | [diff] [blame] | 157 | int cert_verify_flags, |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 158 | base::StringPiece origin_host, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 159 | base::StringPiece method, |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 160 | const BoundNetLog& net_log, |
| 161 | QuicStreamRequest* request); |
| 162 | |
rtenneti | 97137a9 | 2015-06-18 06:00:31 | [diff] [blame] | 163 | // If |packet_loss_rate| is greater than or equal to |packet_loss_threshold_| |
| 164 | // it marks QUIC as recently broken for the port of the session. Increments |
| 165 | // |number_of_lossy_connections_| by port. If |number_of_lossy_connections_| |
| 166 | // is greater than or equal to |max_number_of_lossy_connections_| then it |
| 167 | // disables QUIC. If QUIC is disabled then it closes the connection. |
| 168 | // |
| 169 | // Returns true if QUIC is disabled for the port of the session. |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 170 | bool OnHandshakeConfirmed(QuicChromiumClientSession* session, |
| 171 | float packet_loss_rate); |
rtenneti | 85dcfac2 | 2015-03-27 20:22:19 | [diff] [blame] | 172 | |
| 173 | // Returns true if QUIC is disabled for this port. |
| 174 | bool IsQuicDisabled(uint16 port); |
| 175 | |
ckrasic | 1e53b64 | 2015-07-08 22:39:35 | [diff] [blame] | 176 | // Returns reason QUIC is disabled for this port, or QUIC_DISABLED_NOT if not. |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 177 | QuicChromiumClientSession::QuicDisabledReason QuicDisabledReason( |
| 178 | uint16 port) const; |
ckrasic | 1e53b64 | 2015-07-08 22:39:35 | [diff] [blame] | 179 | |
| 180 | // Returns reason QUIC is disabled as string for net-internals, or |
| 181 | // returns empty string if QUIC is not disabled. |
| 182 | const char* QuicDisabledReasonString() const; |
| 183 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 184 | // Called by a session when it becomes idle. |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 185 | void OnIdleSession(QuicChromiumClientSession* session); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 186 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 187 | // Called by a session when it is going away and no more streams should be |
| 188 | // created on it. |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 189 | void OnSessionGoingAway(QuicChromiumClientSession* session); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 190 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 191 | // Called by a session after it shuts down. |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 192 | void OnSessionClosed(QuicChromiumClientSession* session); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 193 | |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 194 | // Called by a session whose connection has timed out. |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 195 | void OnSessionConnectTimeout(QuicChromiumClientSession* session); |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 196 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 197 | // Cancels a pending request. |
| 198 | void CancelRequest(QuicStreamRequest* request); |
| 199 | |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 200 | // Closes all current sessions. |
| 201 | void CloseAllSessions(int error); |
| 202 | |
payal.pandey | a18956a | 2015-05-27 05:57:55 | [diff] [blame] | 203 | scoped_ptr<base::Value> QuicStreamFactoryInfoToValue() const; |
[email protected] | c5b061b | 2013-01-05 00:31:34 | [diff] [blame] | 204 | |
[email protected] | f7e21a43 | 2014-04-21 22:17:57 | [diff] [blame] | 205 | // Delete all cached state objects in |crypto_config_|. |
[email protected] | 60cf50e | 2014-04-28 23:23:18 | [diff] [blame] | 206 | void ClearCachedStatesInCryptoConfig(); |
[email protected] | f7e21a43 | 2014-04-21 22:17:57 | [diff] [blame] | 207 | |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 208 | // NetworkChangeNotifier::IPAddressObserver methods: |
| 209 | |
| 210 | // Until the servers support roaming, close all connections when the local |
| 211 | // IP address changes. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 212 | void OnIPAddressChanged() override; |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 213 | |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 214 | // SSLConfigService::Observer methods: |
| 215 | |
| 216 | // We perform the same flushing as described above when SSL settings change. |
| 217 | void OnSSLConfigChanged() override; |
| 218 | |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 219 | // CertDatabase::Observer methods: |
| 220 | |
| 221 | // We close all sessions when certificate database is changed. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 222 | void OnCertAdded(const X509Certificate* cert) override; |
| 223 | void OnCACertChanged(const X509Certificate* cert) override; |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 224 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame^] | 225 | bool require_confirmation() const { return require_confirmation_; } |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 226 | |
rtenneti | fc47e0e | 2014-09-26 02:54:05 | [diff] [blame] | 227 | void set_require_confirmation(bool require_confirmation); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 228 | |
rtenneti | d2e74caa | 2015-12-09 00:51:57 | [diff] [blame] | 229 | bool ZeroRTTEnabledFor(const QuicServerId& server_id); |
| 230 | |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 231 | // It returns the amount of time waiting job should be delayed. |
| 232 | base::TimeDelta GetTimeDelayForWaitingJob(const QuicServerId& server_id); |
| 233 | |
[email protected] | 2cfc6bb8 | 2013-10-27 03:40:44 | [diff] [blame] | 234 | QuicConnectionHelper* helper() { return helper_.get(); } |
| 235 | |
[email protected] | 376d38a | 2014-01-22 03:47:35 | [diff] [blame] | 236 | bool enable_port_selection() const { return enable_port_selection_; } |
| 237 | |
[email protected] | a420520 | 2014-06-02 16:03:08 | [diff] [blame] | 238 | bool has_quic_server_info_factory() { |
rtenneti | 13c9d38d | 2015-10-12 21:25:01 | [diff] [blame] | 239 | return !quic_server_info_factory_.get(); |
[email protected] | a420520 | 2014-06-02 16:03:08 | [diff] [blame] | 240 | } |
| 241 | |
[email protected] | e8cf7555b | 2014-02-28 23:52:53 | [diff] [blame] | 242 | void set_quic_server_info_factory( |
rtenneti | 13c9d38d | 2015-10-12 21:25:01 | [diff] [blame] | 243 | QuicServerInfoFactory* quic_server_info_factory); |
[email protected] | e8cf7555b | 2014-02-28 23:52:53 | [diff] [blame] | 244 | |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 245 | bool enable_connection_racing() const { return enable_connection_racing_; } |
| 246 | void set_enable_connection_racing(bool enable_connection_racing) { |
| 247 | enable_connection_racing_ = enable_connection_racing; |
| 248 | } |
| 249 | |
rch | 185ebee | 2015-07-14 23:56:22 | [diff] [blame] | 250 | int socket_receive_buffer_size() const { return socket_receive_buffer_size_; } |
| 251 | |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 252 | bool delay_tcp_race() const { return delay_tcp_race_; } |
| 253 | |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 254 | bool store_server_configs_in_properties() const { |
| 255 | return store_server_configs_in_properties_; |
| 256 | } |
| 257 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 258 | private: |
| 259 | class Job; |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 260 | friend class test::QuicStreamFactoryPeer; |
tbansal | a5268e2 | 2015-06-30 02:57:58 | [diff] [blame] | 261 | FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryTest, QuicLossyProxyMarkedAsBad); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 262 | |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 263 | typedef std::map<QuicServerId, QuicChromiumClientSession*> SessionMap; |
| 264 | typedef std::map<QuicChromiumClientSession*, QuicServerId> SessionIdMap; |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 265 | typedef std::set<QuicServerId> AliasSet; |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 266 | typedef std::map<QuicChromiumClientSession*, AliasSet> SessionAliasMap; |
| 267 | typedef std::set<QuicChromiumClientSession*> SessionSet; |
rch | f114d98 | 2015-10-21 01:34:56 | [diff] [blame] | 268 | typedef std::map<IPEndPoint, SessionSet> IPAliasMap; |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 269 | typedef std::map<QuicServerId, QuicCryptoClientConfig*> CryptoConfigMap; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 270 | typedef std::set<Job*> JobSet; |
| 271 | typedef std::map<QuicServerId, JobSet> JobMap; |
| 272 | typedef std::map<QuicStreamRequest*, QuicServerId> RequestMap; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 273 | typedef std::set<QuicStreamRequest*> RequestSet; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 274 | typedef std::map<QuicServerId, RequestSet> ServerIDRequestsMap; |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 275 | typedef std::deque<enum QuicChromiumClientSession::QuicDisabledReason> |
ckrasic | 1e53b64 | 2015-07-08 22:39:35 | [diff] [blame] | 276 | DisabledReasonsQueue; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 277 | |
| 278 | // Creates a job which doesn't wait for server config to be loaded from the |
| 279 | // disk cache. This job is started via a PostTask. |
| 280 | void CreateAuxilaryJob(const QuicServerId server_id, |
rtenneti | a75df62 | 2015-06-21 23:59:50 | [diff] [blame] | 281 | int cert_verify_flags, |
bnc | 68d401dd | 2015-05-18 20:31:48 | [diff] [blame] | 282 | bool server_and_origin_have_same_host, |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 283 | bool is_post, |
| 284 | const BoundNetLog& net_log); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 285 | |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 286 | // Returns a newly created QuicHttpStream owned by the caller. |
thestig | a0e18cd | 2015-09-25 04:58:36 | [diff] [blame] | 287 | scoped_ptr<QuicHttpStream> CreateFromSession( |
| 288 | QuicChromiumClientSession* session); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 289 | |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 290 | bool OnResolution(const QuicServerId& server_id, |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 291 | const AddressList& address_list); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 292 | void OnJobComplete(Job* job, int rv); |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 293 | bool HasActiveSession(const QuicServerId& server_id) const; |
| 294 | bool HasActiveJob(const QuicServerId& server_id) const; |
| 295 | int CreateSession(const QuicServerId& server_id, |
rtenneti | a75df62 | 2015-06-21 23:59:50 | [diff] [blame] | 296 | int cert_verify_flags, |
[email protected] | 17bf15c | 2014-03-14 10:08:04 | [diff] [blame] | 297 | scoped_ptr<QuicServerInfo> quic_server_info, |
[email protected] | 338e798 | 2013-12-13 11:15:32 | [diff] [blame] | 298 | const AddressList& address_list, |
rtenneti | f4f0885 | 2015-02-27 17:50:04 | [diff] [blame] | 299 | base::TimeTicks dns_resolution_end_time, |
[email protected] | 338e798 | 2013-12-13 11:15:32 | [diff] [blame] | 300 | const BoundNetLog& net_log, |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 301 | QuicChromiumClientSession** session); |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 302 | void ActivateSession(const QuicServerId& key, |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 303 | QuicChromiumClientSession* session); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 304 | |
rtenneti | 2912825c | 2015-01-06 01:19:46 | [diff] [blame] | 305 | // Returns |srtt| in micro seconds from ServerNetworkStats. Returns 0 if there |
| 306 | // is no |http_server_properties_| or if |http_server_properties_| doesn't |
| 307 | // have ServerNetworkStats for the given |server_id|. |
| 308 | int64 GetServerNetworkStatsSmoothedRttInMicroseconds( |
| 309 | const QuicServerId& server_id) const; |
| 310 | |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 311 | // Helper methods. |
| 312 | bool WasQuicRecentlyBroken(const QuicServerId& server_id) const; |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 313 | |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 314 | bool CryptoConfigCacheIsEmpty(const QuicServerId& server_id); |
| 315 | |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 316 | // Initializes the cached state associated with |server_id| in |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 317 | // |crypto_config_| with the information in |server_info|. |
[email protected] | 60cf50e | 2014-04-28 23:23:18 | [diff] [blame] | 318 | void InitializeCachedStateInCryptoConfig( |
| 319 | const QuicServerId& server_id, |
| 320 | const scoped_ptr<QuicServerInfo>& server_info); |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 321 | |
rtenneti | 8a80a6dc | 2015-09-21 19:51:13 | [diff] [blame] | 322 | // Initialize |quic_supported_servers_at_startup_| with the list of servers |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 323 | // that supported QUIC at start up and also initialize in-memory cache of |
| 324 | // QuicServerInfo objects from HttpServerProperties. |
| 325 | void MaybeInitialize(); |
rtenneti | 8a80a6dc | 2015-09-21 19:51:13 | [diff] [blame] | 326 | |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 327 | void ProcessGoingAwaySession(QuicChromiumClientSession* session, |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 328 | const QuicServerId& server_id, |
| 329 | bool was_session_active); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 330 | |
ckrasic | 1e53b64 | 2015-07-08 22:39:35 | [diff] [blame] | 331 | // Collect stats from recent connections, possibly disabling Quic. |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 332 | void MaybeDisableQuic(QuicChromiumClientSession* session); |
ckrasic | 1e53b64 | 2015-07-08 22:39:35 | [diff] [blame] | 333 | |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 334 | bool require_confirmation_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 335 | HostResolver* host_resolver_; |
| 336 | ClientSocketFactory* client_socket_factory_; |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 337 | base::WeakPtr<HttpServerProperties> http_server_properties_; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 338 | TransportSecurityState* transport_security_state_; |
rtenneti | 052774e | 2015-11-24 21:00:12 | [diff] [blame] | 339 | CTVerifier* cert_transparency_verifier_; |
rtenneti | 13c9d38d | 2015-10-12 21:25:01 | [diff] [blame] | 340 | scoped_ptr<QuicServerInfoFactory> quic_server_info_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 341 | QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory_; |
[email protected] | 9558c5d3 | 2012-12-22 00:08:14 | [diff] [blame] | 342 | QuicRandom* random_generator_; |
[email protected] | f1e97e9 | 2012-12-16 04:53:25 | [diff] [blame] | 343 | scoped_ptr<QuicClock> clock_; |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 344 | const size_t max_packet_length_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 345 | |
tbansal | fdf5665b | 2015-09-21 22:46:40 | [diff] [blame] | 346 | // Factory which is used to create socket performance watcher. A new watcher |
| 347 | // is created for every QUIC connection. |
| 348 | // |socket_performance_watcher_factory_| may be null. |
tbansal | c8a94ea | 2015-11-02 23:58:51 | [diff] [blame] | 349 | SocketPerformanceWatcherFactory* socket_performance_watcher_factory_; |
tbansal | fdf5665b | 2015-09-21 22:46:40 | [diff] [blame] | 350 | |
[email protected] | 2cfc6bb8 | 2013-10-27 03:40:44 | [diff] [blame] | 351 | // The helper used for all connections. |
| 352 | scoped_ptr<QuicConnectionHelper> helper_; |
| 353 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 354 | // Contains owning pointers to all sessions that currently exist. |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 355 | SessionIdMap all_sessions_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 356 | // Contains non-owning pointers to currently active session |
| 357 | // (not going away session, once they're implemented). |
| 358 | SessionMap active_sessions_; |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 359 | // Map from session to set of aliases that this session is known by. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 360 | SessionAliasMap session_aliases_; |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 361 | // Map from IP address to sessions which are connected to this address. |
| 362 | IPAliasMap ip_aliases_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 363 | |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 364 | // Origins which have gone away recently. |
| 365 | AliasSet gone_away_aliases_; |
| 366 | |
[email protected] | fd276a28 | 2014-06-11 04:26:14 | [diff] [blame] | 367 | const QuicConfig config_; |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 368 | QuicCryptoClientConfig crypto_config_; |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 369 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 370 | JobMap active_jobs_; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 371 | ServerIDRequestsMap job_requests_map_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 372 | RequestMap active_requests_; |
| 373 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 374 | QuicVersionVector supported_versions_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 375 | |
[email protected] | 376d38a | 2014-01-22 03:47:35 | [diff] [blame] | 376 | // Determine if we should consistently select a client UDP port. If false, |
| 377 | // then we will just let the OS select a random client port for each new |
| 378 | // connection. |
| 379 | bool enable_port_selection_; |
| 380 | |
jri | 2b966f2 | 2014-09-02 22:25:36 | [diff] [blame] | 381 | // Set if we always require handshake confirmation. If true, this will |
| 382 | // introduce at least one RTT for the handshake before the client sends data. |
| 383 | bool always_require_handshake_confirmation_; |
| 384 | |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 385 | // Set if we do not want connection pooling. |
| 386 | bool disable_connection_pooling_; |
| 387 | |
rtenneti | 2912825c | 2015-01-06 01:19:46 | [diff] [blame] | 388 | // Specifies the ratio between time to load QUIC server information from disk |
| 389 | // cache to 'smoothed RTT'. This ratio is used to calculate the timeout in |
| 390 | // milliseconds to wait for loading of QUIC server information. If we don't |
| 391 | // want to timeout, set |load_server_info_timeout_srtt_multiplier_| to 0. |
| 392 | float load_server_info_timeout_srtt_multiplier_; |
| 393 | |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 394 | // Set if we want to race connections - one connection that sends |
| 395 | // INCHOATE_HELLO and another connection that sends CHLO after loading server |
| 396 | // config from the disk cache. |
| 397 | bool enable_connection_racing_; |
| 398 | |
qyearsley | 3257b7de | 2015-02-28 06:59:03 | [diff] [blame] | 399 | // Set if experimental non-blocking IO should be used on windows sockets. |
| 400 | bool enable_non_blocking_io_; |
| 401 | |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 402 | // Set if we do not want to load server config from the disk cache. |
| 403 | bool disable_disk_cache_; |
| 404 | |
rch | 9976b0c | 2015-06-10 21:27:23 | [diff] [blame] | 405 | // Set if AES-GCM should be preferred, even if there is no hardware support. |
| 406 | bool prefer_aes_; |
| 407 | |
rtenneti | 85dcfac2 | 2015-03-27 20:22:19 | [diff] [blame] | 408 | // Set if we want to disable QUIC when there is high packet loss rate. |
| 409 | // Specifies the maximum number of connections with high packet loss in a row |
| 410 | // after which QUIC will be disabled. |
| 411 | int max_number_of_lossy_connections_; |
rtenneti | 374e5688 | 2015-03-28 13:49:54 | [diff] [blame] | 412 | // Specifies packet loss rate in fraction after which a connection is closed |
rtenneti | 85dcfac2 | 2015-03-27 20:22:19 | [diff] [blame] | 413 | // and is considered as a lossy connection. |
| 414 | float packet_loss_threshold_; |
| 415 | // Count number of lossy connections by port. |
| 416 | std::map<uint16, int> number_of_lossy_connections_; |
| 417 | |
ckrasic | 1e53b64 | 2015-07-08 22:39:35 | [diff] [blame] | 418 | // Keep track of stats for recently closed connections, using a |
| 419 | // bounded queue. |
| 420 | int max_disabled_reasons_; |
| 421 | DisabledReasonsQueue disabled_reasons_; |
| 422 | // Events that can trigger disabling QUIC |
| 423 | int num_public_resets_post_handshake_; |
| 424 | int num_timeouts_with_open_streams_; |
| 425 | // Keep track the largest values for UMA histograms, that will help |
| 426 | // determine good threshold values. |
| 427 | int max_public_resets_post_handshake_; |
| 428 | int max_timeouts_with_open_streams_; |
| 429 | // Thresholds if greater than zero, determine when to |
| 430 | int threshold_timeouts_with_open_streams_; |
| 431 | int threshold_public_resets_post_handshake_; |
| 432 | |
rch | c743357 | 2015-02-27 18:16:51 | [diff] [blame] | 433 | // Size of the UDP receive buffer. |
| 434 | int socket_receive_buffer_size_; |
| 435 | |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 436 | // Set if we do want to delay TCP connection when it is racing with QUIC. |
| 437 | bool delay_tcp_race_; |
| 438 | |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 439 | // If more than |yield_after_packets_| packets have been read or more than |
| 440 | // |yield_after_duration_| time has passed, then |
| 441 | // QuicPacketReader::StartReading() yields by doing a PostTask(). |
| 442 | int yield_after_packets_; |
| 443 | QuicTime::Delta yield_after_duration_; |
| 444 | |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 445 | // Set if server configs are to be stored in HttpServerProperties. |
| 446 | bool store_server_configs_in_properties_; |
| 447 | |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 448 | // Set if all sessions should be closed when any local IP address changes. |
| 449 | const bool close_sessions_on_ip_change_; |
| 450 | |
rch | c743357 | 2015-02-27 18:16:51 | [diff] [blame] | 451 | // Each profile will (probably) have a unique port_seed_ value. This value |
| 452 | // is used to help seed a pseudo-random number generator (PortSuggester) so |
| 453 | // that we consistently (within this profile) suggest the same ephemeral |
| 454 | // port when we re-connect to any given server/port. The differences between |
| 455 | // profiles (probablistically) prevent two profiles from colliding in their |
| 456 | // ephemeral port requests. |
[email protected] | 337e145 | 2013-12-16 23:57:50 | [diff] [blame] | 457 | uint64 port_seed_; |
[email protected] | 7034cf1 | 2013-12-13 22:47:07 | [diff] [blame] | 458 | |
rtenneti | fc47e0e | 2014-09-26 02:54:05 | [diff] [blame] | 459 | // Local address of socket that was created in CreateSession. |
| 460 | IPEndPoint local_address_; |
| 461 | bool check_persisted_supports_quic_; |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 462 | bool has_initialized_data_; |
rtenneti | 1681f85 | 2014-11-13 20:34:03 | [diff] [blame] | 463 | std::set<HostPortPair> quic_supported_servers_at_startup_; |
rtenneti | fc47e0e | 2014-09-26 02:54:05 | [diff] [blame] | 464 | |
rtenneti | 041b299 | 2015-02-23 23:03:28 | [diff] [blame] | 465 | NetworkConnection network_connection_; |
| 466 | |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 467 | base::TaskRunner* task_runner_; |
| 468 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 469 | base::WeakPtrFactory<QuicStreamFactory> weak_factory_; |
| 470 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 471 | DISALLOW_COPY_AND_ASSIGN(QuicStreamFactory); |
| 472 | }; |
| 473 | |
| 474 | } // namespace net |
| 475 | |
| 476 | #endif // NET_QUIC_QUIC_STREAM_FACTORY_H_ |