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