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 #include "net/quic/quic_client_session.h" | 5 #include "net/quic/quic_client_session.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "net/quic/quic_server_id.h" | 21 #include "net/quic/quic_server_id.h" |
22 #include "net/quic/quic_stream_factory.h" | 22 #include "net/quic/quic_stream_factory.h" |
23 #include "net/ssl/ssl_connection_status_flags.h" | 23 #include "net/ssl/ssl_connection_status_flags.h" |
24 #include "net/ssl/ssl_info.h" | 24 #include "net/ssl/ssl_info.h" |
25 #include "net/udp/datagram_client_socket.h" | 25 #include "net/udp/datagram_client_socket.h" |
26 | 26 |
27 namespace net { | 27 namespace net { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
| 31 // The length of time to wait for a 0-RTT handshake to complete |
| 32 // before allowing the requests to possibly proceed over TCP. |
| 33 const int k0RttHandshakeTimeoutMs = 300; |
| 34 |
31 // Histograms for tracking down the crashes from http://crbug.com/354669 | 35 // Histograms for tracking down the crashes from http://crbug.com/354669 |
32 // Note: these values must be kept in sync with the corresponding values in: | 36 // Note: these values must be kept in sync with the corresponding values in: |
33 // tools/metrics/histograms/histograms.xml | 37 // tools/metrics/histograms/histograms.xml |
34 enum Location { | 38 enum Location { |
35 DESTRUCTOR = 0, | 39 DESTRUCTOR = 0, |
36 ADD_OBSERVER = 1, | 40 ADD_OBSERVER = 1, |
37 TRY_CREATE_STREAM = 2, | 41 TRY_CREATE_STREAM = 2, |
38 CREATE_OUTGOING_RELIABLE_STREAM = 3, | 42 CREATE_OUTGOING_RELIABLE_STREAM = 3, |
39 NOTIFY_FACTORY_OF_SESSION_CLOSED_LATER = 4, | 43 NOTIFY_FACTORY_OF_SESSION_CLOSED_LATER = 4, |
40 NOTIFY_FACTORY_OF_SESSION_CLOSED = 5, | 44 NOTIFY_FACTORY_OF_SESSION_CLOSED = 5, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 QuicConnection* connection, | 135 QuicConnection* connection, |
132 scoped_ptr<DatagramClientSocket> socket, | 136 scoped_ptr<DatagramClientSocket> socket, |
133 scoped_ptr<QuicDefaultPacketWriter> writer, | 137 scoped_ptr<QuicDefaultPacketWriter> writer, |
134 QuicStreamFactory* stream_factory, | 138 QuicStreamFactory* stream_factory, |
135 QuicCryptoClientStreamFactory* crypto_client_stream_factory, | 139 QuicCryptoClientStreamFactory* crypto_client_stream_factory, |
136 scoped_ptr<QuicServerInfo> server_info, | 140 scoped_ptr<QuicServerInfo> server_info, |
137 const QuicServerId& server_id, | 141 const QuicServerId& server_id, |
138 const QuicConfig& config, | 142 const QuicConfig& config, |
139 uint32 max_flow_control_receive_window_bytes, | 143 uint32 max_flow_control_receive_window_bytes, |
140 QuicCryptoClientConfig* crypto_config, | 144 QuicCryptoClientConfig* crypto_config, |
| 145 base::TaskRunner* task_runner, |
141 NetLog* net_log) | 146 NetLog* net_log) |
142 : QuicClientSessionBase(connection, | 147 : QuicClientSessionBase(connection, |
143 max_flow_control_receive_window_bytes, | 148 max_flow_control_receive_window_bytes, |
144 config), | 149 config), |
145 require_confirmation_(false), | 150 require_confirmation_(false), |
146 stream_factory_(stream_factory), | 151 stream_factory_(stream_factory), |
147 socket_(socket.Pass()), | 152 socket_(socket.Pass()), |
148 writer_(writer.Pass()), | 153 writer_(writer.Pass()), |
149 read_buffer_(new IOBufferWithSize(kMaxPacketSize)), | 154 read_buffer_(new IOBufferWithSize(kMaxPacketSize)), |
150 server_info_(server_info.Pass()), | 155 server_info_(server_info.Pass()), |
151 read_pending_(false), | 156 read_pending_(false), |
152 num_total_streams_(0), | 157 num_total_streams_(0), |
| 158 task_runner_(task_runner), |
153 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), | 159 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), |
154 logger_(net_log_), | 160 logger_(net_log_), |
155 num_packets_read_(0), | 161 num_packets_read_(0), |
156 going_away_(false), | 162 going_away_(false), |
157 weak_factory_(this) { | 163 weak_factory_(this) { |
158 crypto_stream_.reset( | 164 crypto_stream_.reset( |
159 crypto_client_stream_factory ? | 165 crypto_client_stream_factory ? |
160 crypto_client_stream_factory->CreateQuicCryptoClientStream( | 166 crypto_client_stream_factory->CreateQuicCryptoClientStream( |
161 server_id, this, crypto_config) : | 167 server_id, this, crypto_config) : |
162 new QuicCryptoClientStream(server_id, this, | 168 new QuicCryptoClientStream(server_id, this, |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 int QuicClientSession::CryptoConnect(bool require_confirmation, | 435 int QuicClientSession::CryptoConnect(bool require_confirmation, |
430 const CompletionCallback& callback) { | 436 const CompletionCallback& callback) { |
431 require_confirmation_ = require_confirmation; | 437 require_confirmation_ = require_confirmation; |
432 RecordHandshakeState(STATE_STARTED); | 438 RecordHandshakeState(STATE_STARTED); |
433 if (!crypto_stream_->CryptoConnect()) { | 439 if (!crypto_stream_->CryptoConnect()) { |
434 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a | 440 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a |
435 // QuicErrorCode and map it to a net error code. | 441 // QuicErrorCode and map it to a net error code. |
436 return ERR_CONNECTION_FAILED; | 442 return ERR_CONNECTION_FAILED; |
437 } | 443 } |
438 | 444 |
439 bool can_notify = require_confirmation_ ? | 445 if (IsCryptoHandshakeConfirmed()) |
440 IsCryptoHandshakeConfirmed() : IsEncryptionEstablished(); | |
441 if (can_notify) { | |
442 return OK; | 446 return OK; |
| 447 |
| 448 // Unless we require handshake confirmation, activate the session if |
| 449 // we have established initial encryption. |
| 450 if (!require_confirmation_ && IsEncryptionEstablished()) { |
| 451 // To mitigate the effects of hanging 0-RTT connections, set up a timer to |
| 452 // cancel any requests, if the handshake takes too long. |
| 453 task_runner_->PostDelayedTask( |
| 454 FROM_HERE, |
| 455 base::Bind(&QuicClientSession::OnConnectTimeout, |
| 456 weak_factory_.GetWeakPtr()), |
| 457 base::TimeDelta::FromMilliseconds(k0RttHandshakeTimeoutMs)); |
| 458 return OK; |
| 459 |
443 } | 460 } |
444 | 461 |
445 callback_ = callback; | 462 callback_ = callback; |
446 return ERR_IO_PENDING; | 463 return ERR_IO_PENDING; |
447 } | 464 } |
448 | 465 |
| 466 int QuicClientSession::ResumeCryptoConnect(const CompletionCallback& callback) { |
| 467 |
| 468 if (IsCryptoHandshakeConfirmed()) |
| 469 return OK; |
| 470 |
| 471 if (!connection()->connected()) |
| 472 return ERR_QUIC_HANDSHAKE_FAILED; |
| 473 |
| 474 callback_ = callback; |
| 475 return ERR_IO_PENDING; |
| 476 } |
| 477 |
449 int QuicClientSession::GetNumSentClientHellos() const { | 478 int QuicClientSession::GetNumSentClientHellos() const { |
450 return crypto_stream_->num_sent_client_hellos(); | 479 return crypto_stream_->num_sent_client_hellos(); |
451 } | 480 } |
452 | 481 |
453 bool QuicClientSession::CanPool(const std::string& hostname) const { | 482 bool QuicClientSession::CanPool(const std::string& hostname) const { |
454 // TODO(rch): When QUIC supports channel ID or client certificates, this | 483 // TODO(rch): When QUIC supports channel ID or client certificates, this |
455 // logic will need to be revised. | 484 // logic will need to be revised. |
456 DCHECK(connection()->connected()); | 485 DCHECK(connection()->connected()); |
457 SSLInfo ssl_info; | 486 SSLInfo ssl_info; |
458 bool unused = false; | 487 bool unused = false; |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 if (!going_away_) | 822 if (!going_away_) |
794 RecordUnexpectedNotGoingAway(NOTIFY_FACTORY_OF_SESSION_CLOSED); | 823 RecordUnexpectedNotGoingAway(NOTIFY_FACTORY_OF_SESSION_CLOSED); |
795 | 824 |
796 going_away_ = true; | 825 going_away_ = true; |
797 DCHECK_EQ(0u, GetNumOpenStreams()); | 826 DCHECK_EQ(0u, GetNumOpenStreams()); |
798 // Will delete |this|. | 827 // Will delete |this|. |
799 if (stream_factory_) | 828 if (stream_factory_) |
800 stream_factory_->OnSessionClosed(this); | 829 stream_factory_->OnSessionClosed(this); |
801 } | 830 } |
802 | 831 |
| 832 void QuicClientSession::OnConnectTimeout() { |
| 833 DCHECK(callback_.is_null()); |
| 834 DCHECK(IsEncryptionEstablished()); |
| 835 |
| 836 if (IsCryptoHandshakeConfirmed()) |
| 837 return; |
| 838 |
| 839 if (stream_factory_) |
| 840 stream_factory_->OnSessionConnectTimeout(this); |
| 841 CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); |
| 842 } |
| 843 |
803 } // namespace net | 844 } // namespace net |
OLD | NEW |