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