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