OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_QUIC_QUIC_STREAM_FACTORY_H_ | 5 #ifndef NET_QUIC_QUIC_STREAM_FACTORY_H_ |
6 #define NET_QUIC_QUIC_STREAM_FACTORY_H_ | 6 #define NET_QUIC_QUIC_STREAM_FACTORY_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 QuicClock* clock, | 100 QuicClock* clock, |
101 size_t max_packet_length, | 101 size_t max_packet_length, |
102 const std::string& user_agent_id, | 102 const std::string& user_agent_id, |
103 const QuicVersionVector& supported_versions, | 103 const QuicVersionVector& supported_versions, |
104 bool enable_port_selection, | 104 bool enable_port_selection, |
105 bool always_require_handshake_confirmation, | 105 bool always_require_handshake_confirmation, |
106 bool disable_connection_pooling, | 106 bool disable_connection_pooling, |
107 int load_server_info_timeout, | 107 int load_server_info_timeout, |
108 float load_server_info_timeout_srtt_multiplier, | 108 float load_server_info_timeout_srtt_multiplier, |
109 bool enable_truncated_connection_ids, | 109 bool enable_truncated_connection_ids, |
| 110 bool enable_connection_racing, |
110 const QuicTagVector& connection_options); | 111 const QuicTagVector& connection_options); |
111 ~QuicStreamFactory() override; | 112 ~QuicStreamFactory() override; |
112 | 113 |
113 // Creates a new QuicHttpStream to |host_port_pair| which will be | 114 // Creates a new QuicHttpStream to |host_port_pair| which will be |
114 // owned by |request|. |is_https| specifies if the protocol is https or not. | 115 // owned by |request|. |is_https| specifies if the protocol is https or not. |
115 // If a matching session already exists, this method will return OK. If no | 116 // If a matching session already exists, this method will return OK. If no |
116 // matching session exists, this will return ERR_IO_PENDING and will invoke | 117 // matching session exists, this will return ERR_IO_PENDING and will invoke |
117 // OnRequestComplete asynchronously. | 118 // OnRequestComplete asynchronously. |
118 int Create(const HostPortPair& host_port_pair, | 119 int Create(const HostPortPair& host_port_pair, |
119 bool is_https, | 120 bool is_https, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 bool has_quic_server_info_factory() { | 172 bool has_quic_server_info_factory() { |
172 return quic_server_info_factory_ != NULL; | 173 return quic_server_info_factory_ != NULL; |
173 } | 174 } |
174 | 175 |
175 void set_quic_server_info_factory( | 176 void set_quic_server_info_factory( |
176 QuicServerInfoFactory* quic_server_info_factory) { | 177 QuicServerInfoFactory* quic_server_info_factory) { |
177 DCHECK(!quic_server_info_factory_); | 178 DCHECK(!quic_server_info_factory_); |
178 quic_server_info_factory_ = quic_server_info_factory; | 179 quic_server_info_factory_ = quic_server_info_factory; |
179 } | 180 } |
180 | 181 |
| 182 bool enable_connection_racing() const { return enable_connection_racing_; } |
| 183 void set_enable_connection_racing(bool enable_connection_racing) { |
| 184 enable_connection_racing_ = enable_connection_racing; |
| 185 } |
| 186 |
181 private: | 187 private: |
182 class Job; | 188 class Job; |
183 friend class test::QuicStreamFactoryPeer; | 189 friend class test::QuicStreamFactoryPeer; |
184 | 190 |
185 // The key used to find session by ip. Includes | 191 // The key used to find session by ip. Includes |
186 // the ip address, port, and scheme. | 192 // the ip address, port, and scheme. |
187 struct NET_EXPORT_PRIVATE IpAliasKey { | 193 struct NET_EXPORT_PRIVATE IpAliasKey { |
188 IpAliasKey(); | 194 IpAliasKey(); |
189 IpAliasKey(IPEndPoint ip_endpoint, bool is_https); | 195 IpAliasKey(IPEndPoint ip_endpoint, bool is_https); |
190 ~IpAliasKey(); | 196 ~IpAliasKey(); |
191 | 197 |
192 IPEndPoint ip_endpoint; | 198 IPEndPoint ip_endpoint; |
193 bool is_https; | 199 bool is_https; |
194 | 200 |
195 // Needed to be an element of std::set. | 201 // Needed to be an element of std::set. |
196 bool operator<(const IpAliasKey &other) const; | 202 bool operator<(const IpAliasKey &other) const; |
197 bool operator==(const IpAliasKey &other) const; | 203 bool operator==(const IpAliasKey &other) const; |
198 }; | 204 }; |
199 | 205 |
200 typedef std::map<QuicServerId, QuicClientSession*> SessionMap; | 206 typedef std::map<QuicServerId, QuicClientSession*> SessionMap; |
201 typedef std::map<QuicClientSession*, QuicServerId> SessionIdMap; | 207 typedef std::map<QuicClientSession*, QuicServerId> SessionIdMap; |
202 typedef std::set<QuicServerId> AliasSet; | 208 typedef std::set<QuicServerId> AliasSet; |
203 typedef std::map<QuicClientSession*, AliasSet> SessionAliasMap; | 209 typedef std::map<QuicClientSession*, AliasSet> SessionAliasMap; |
204 typedef std::set<QuicClientSession*> SessionSet; | 210 typedef std::set<QuicClientSession*> SessionSet; |
205 typedef std::map<IpAliasKey, SessionSet> IPAliasMap; | 211 typedef std::map<IpAliasKey, SessionSet> IPAliasMap; |
206 typedef std::map<QuicServerId, QuicCryptoClientConfig*> CryptoConfigMap; | 212 typedef std::map<QuicServerId, QuicCryptoClientConfig*> CryptoConfigMap; |
207 typedef std::map<QuicServerId, Job*> JobMap; | 213 typedef std::set<Job*> JobSet; |
208 typedef std::map<QuicStreamRequest*, Job*> RequestMap; | 214 typedef std::map<QuicServerId, JobSet> JobMap; |
| 215 typedef std::map<QuicStreamRequest*, QuicServerId> RequestMap; |
209 typedef std::set<QuicStreamRequest*> RequestSet; | 216 typedef std::set<QuicStreamRequest*> RequestSet; |
210 typedef std::map<Job*, RequestSet> JobRequestsMap; | 217 typedef std::map<QuicServerId, RequestSet> ServerIDRequestsMap; |
| 218 |
| 219 // Creates a job which doesn't wait for server config to be loaded from the |
| 220 // disk cache. This job is started via a PostTask. |
| 221 void CreateAuxilaryJob(const QuicServerId server_id, |
| 222 bool is_post, |
| 223 const BoundNetLog& net_log); |
211 | 224 |
212 // Returns a newly created QuicHttpStream owned by the caller, if a | 225 // Returns a newly created QuicHttpStream owned by the caller, if a |
213 // matching session already exists. Returns NULL otherwise. | 226 // matching session already exists. Returns NULL otherwise. |
214 scoped_ptr<QuicHttpStream> CreateIfSessionExists(const QuicServerId& key, | 227 scoped_ptr<QuicHttpStream> CreateIfSessionExists(const QuicServerId& key, |
215 const BoundNetLog& net_log); | 228 const BoundNetLog& net_log); |
216 | 229 |
217 bool OnResolution(const QuicServerId& server_id, | 230 bool OnResolution(const QuicServerId& server_id, |
218 const AddressList& address_list); | 231 const AddressList& address_list); |
219 void OnJobComplete(Job* job, int rv); | 232 void OnJobComplete(Job* job, int rv); |
220 bool HasActiveSession(const QuicServerId& server_id) const; | 233 bool HasActiveSession(const QuicServerId& server_id) const; |
221 bool HasActiveJob(const QuicServerId& server_id) const; | 234 bool HasActiveJob(const QuicServerId& server_id) const; |
222 int CreateSession(const QuicServerId& server_id, | 235 int CreateSession(const QuicServerId& server_id, |
223 scoped_ptr<QuicServerInfo> quic_server_info, | 236 scoped_ptr<QuicServerInfo> quic_server_info, |
224 const AddressList& address_list, | 237 const AddressList& address_list, |
225 const BoundNetLog& net_log, | 238 const BoundNetLog& net_log, |
226 QuicClientSession** session); | 239 QuicClientSession** session); |
227 void ActivateSession(const QuicServerId& key, | 240 void ActivateSession(const QuicServerId& key, |
228 QuicClientSession* session); | 241 QuicClientSession* session); |
229 | 242 |
230 // Returns |srtt| in micro seconds from ServerNetworkStats. Returns 0 if there | 243 // Returns |srtt| in micro seconds from ServerNetworkStats. Returns 0 if there |
231 // is no |http_server_properties_| or if |http_server_properties_| doesn't | 244 // is no |http_server_properties_| or if |http_server_properties_| doesn't |
232 // have ServerNetworkStats for the given |server_id|. | 245 // have ServerNetworkStats for the given |server_id|. |
233 int64 GetServerNetworkStatsSmoothedRttInMicroseconds( | 246 int64 GetServerNetworkStatsSmoothedRttInMicroseconds( |
234 const QuicServerId& server_id) const; | 247 const QuicServerId& server_id) const; |
235 | 248 |
| 249 // Helped methods. |
| 250 bool WasAlternateProtocolRecentlyBroken(const QuicServerId& server_id) const; |
| 251 bool CryptoConfigCacheIsEmpty(const QuicServerId& server_id); |
| 252 |
236 // Initializes the cached state associated with |server_id| in | 253 // Initializes the cached state associated with |server_id| in |
237 // |crypto_config_| with the information in |server_info|. | 254 // |crypto_config_| with the information in |server_info|. |
238 void InitializeCachedStateInCryptoConfig( | 255 void InitializeCachedStateInCryptoConfig( |
239 const QuicServerId& server_id, | 256 const QuicServerId& server_id, |
240 const scoped_ptr<QuicServerInfo>& server_info); | 257 const scoped_ptr<QuicServerInfo>& server_info); |
241 | 258 |
242 void ProcessGoingAwaySession(QuicClientSession* session, | 259 void ProcessGoingAwaySession(QuicClientSession* session, |
243 const QuicServerId& server_id, | 260 const QuicServerId& server_id, |
244 bool was_session_active); | 261 bool was_session_active); |
245 | 262 |
(...skipping 21 matching lines...) Expand all Loading... |
267 // Map from IP address to sessions which are connected to this address. | 284 // Map from IP address to sessions which are connected to this address. |
268 IPAliasMap ip_aliases_; | 285 IPAliasMap ip_aliases_; |
269 | 286 |
270 // Origins which have gone away recently. | 287 // Origins which have gone away recently. |
271 AliasSet gone_away_aliases_; | 288 AliasSet gone_away_aliases_; |
272 | 289 |
273 const QuicConfig config_; | 290 const QuicConfig config_; |
274 QuicCryptoClientConfig crypto_config_; | 291 QuicCryptoClientConfig crypto_config_; |
275 | 292 |
276 JobMap active_jobs_; | 293 JobMap active_jobs_; |
277 JobRequestsMap job_requests_map_; | 294 ServerIDRequestsMap job_requests_map_; |
278 RequestMap active_requests_; | 295 RequestMap active_requests_; |
279 | 296 |
280 QuicVersionVector supported_versions_; | 297 QuicVersionVector supported_versions_; |
281 | 298 |
282 // Determine if we should consistently select a client UDP port. If false, | 299 // Determine if we should consistently select a client UDP port. If false, |
283 // then we will just let the OS select a random client port for each new | 300 // then we will just let the OS select a random client port for each new |
284 // connection. | 301 // connection. |
285 bool enable_port_selection_; | 302 bool enable_port_selection_; |
286 | 303 |
287 // Set if we always require handshake confirmation. If true, this will | 304 // Set if we always require handshake confirmation. If true, this will |
(...skipping 10 matching lines...) Expand all Loading... |
298 | 315 |
299 // Specifies the ratio between time to load QUIC server information from disk | 316 // Specifies the ratio between time to load QUIC server information from disk |
300 // cache to 'smoothed RTT'. This ratio is used to calculate the timeout in | 317 // cache to 'smoothed RTT'. This ratio is used to calculate the timeout in |
301 // milliseconds to wait for loading of QUIC server information. If we don't | 318 // milliseconds to wait for loading of QUIC server information. If we don't |
302 // want to timeout, set |load_server_info_timeout_srtt_multiplier_| to 0. | 319 // want to timeout, set |load_server_info_timeout_srtt_multiplier_| to 0. |
303 float load_server_info_timeout_srtt_multiplier_; | 320 float load_server_info_timeout_srtt_multiplier_; |
304 | 321 |
305 // Set this for setting config's BytesForConnectionIdToSend (TCID param) to 0. | 322 // Set this for setting config's BytesForConnectionIdToSend (TCID param) to 0. |
306 bool enable_truncated_connection_ids_; | 323 bool enable_truncated_connection_ids_; |
307 | 324 |
| 325 // Set if we want to race connections - one connection that sends |
| 326 // INCHOATE_HELLO and another connection that sends CHLO after loading server |
| 327 // config from the disk cache. |
| 328 bool enable_connection_racing_; |
| 329 |
308 // Each profile will (probably) have a unique port_seed_ value. This value is | 330 // Each profile will (probably) have a unique port_seed_ value. This value is |
309 // used to help seed a pseudo-random number generator (PortSuggester) so that | 331 // used to help seed a pseudo-random number generator (PortSuggester) so that |
310 // we consistently (within this profile) suggest the same ephemeral port when | 332 // we consistently (within this profile) suggest the same ephemeral port when |
311 // we re-connect to any given server/port. The differences between profiles | 333 // we re-connect to any given server/port. The differences between profiles |
312 // (probablistically) prevent two profiles from colliding in their ephemeral | 334 // (probablistically) prevent two profiles from colliding in their ephemeral |
313 // port requests. | 335 // port requests. |
314 uint64 port_seed_; | 336 uint64 port_seed_; |
315 | 337 |
316 // Local address of socket that was created in CreateSession. | 338 // Local address of socket that was created in CreateSession. |
317 IPEndPoint local_address_; | 339 IPEndPoint local_address_; |
318 bool check_persisted_supports_quic_; | 340 bool check_persisted_supports_quic_; |
319 std::set<HostPortPair> quic_supported_servers_at_startup_; | 341 std::set<HostPortPair> quic_supported_servers_at_startup_; |
320 | 342 |
321 base::TaskRunner* task_runner_; | 343 base::TaskRunner* task_runner_; |
322 | 344 |
323 base::WeakPtrFactory<QuicStreamFactory> weak_factory_; | 345 base::WeakPtrFactory<QuicStreamFactory> weak_factory_; |
324 | 346 |
325 DISALLOW_COPY_AND_ASSIGN(QuicStreamFactory); | 347 DISALLOW_COPY_AND_ASSIGN(QuicStreamFactory); |
326 }; | 348 }; |
327 | 349 |
328 } // namespace net | 350 } // namespace net |
329 | 351 |
330 #endif // NET_QUIC_QUIC_STREAM_FACTORY_H_ | 352 #endif // NET_QUIC_QUIC_STREAM_FACTORY_H_ |
OLD | NEW |