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_chromium_client_session.h" | 5 #include "net/quic/quic_chromium_client_session.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 // The length of time to wait for a 0-RTT handshake to complete | 36 // The length of time to wait for a 0-RTT handshake to complete |
37 // before allowing the requests to possibly proceed over TCP. | 37 // before allowing the requests to possibly proceed over TCP. |
38 const int k0RttHandshakeTimeoutMs = 300; | 38 const int k0RttHandshakeTimeoutMs = 300; |
39 | 39 |
40 // IPv6 packets have an additional 20 bytes of overhead than IPv4 packets. | 40 // IPv6 packets have an additional 20 bytes of overhead than IPv4 packets. |
41 const size_t kAdditionalOverheadForIPv6 = 20; | 41 const size_t kAdditionalOverheadForIPv6 = 20; |
42 | 42 |
| 43 // Maximum number of Readers that are created for any session due to |
| 44 // connection migration. A new Reader is created every time this endpoint's |
| 45 // IP address changes. |
| 46 const size_t kMaxReadersPerQuicSession = 5; |
| 47 |
43 // Histograms for tracking down the crashes from http://crbug.com/354669 | 48 // Histograms for tracking down the crashes from http://crbug.com/354669 |
44 // Note: these values must be kept in sync with the corresponding values in: | 49 // Note: these values must be kept in sync with the corresponding values in: |
45 // tools/metrics/histograms/histograms.xml | 50 // tools/metrics/histograms/histograms.xml |
46 enum Location { | 51 enum Location { |
47 DESTRUCTOR = 0, | 52 DESTRUCTOR = 0, |
48 ADD_OBSERVER = 1, | 53 ADD_OBSERVER = 1, |
49 TRY_CREATE_STREAM = 2, | 54 TRY_CREATE_STREAM = 2, |
50 CREATE_OUTGOING_RELIABLE_STREAM = 3, | 55 CREATE_OUTGOING_RELIABLE_STREAM = 3, |
51 NOTIFY_FACTORY_OF_SESSION_CLOSED_LATER = 4, | 56 NOTIFY_FACTORY_OF_SESSION_CLOSED_LATER = 4, |
52 NOTIFY_FACTORY_OF_SESSION_CLOSED = 5, | 57 NOTIFY_FACTORY_OF_SESSION_CLOSED = 5, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 QuicCryptoClientConfig* crypto_config, | 177 QuicCryptoClientConfig* crypto_config, |
173 const char* const connection_description, | 178 const char* const connection_description, |
174 base::TimeTicks dns_resolution_end_time, | 179 base::TimeTicks dns_resolution_end_time, |
175 base::TaskRunner* task_runner, | 180 base::TaskRunner* task_runner, |
176 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher, | 181 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
177 NetLog* net_log) | 182 NetLog* net_log) |
178 : QuicClientSessionBase(connection, config), | 183 : QuicClientSessionBase(connection, config), |
179 server_id_(server_id), | 184 server_id_(server_id), |
180 require_confirmation_(false), | 185 require_confirmation_(false), |
181 stream_factory_(stream_factory), | 186 stream_factory_(stream_factory), |
182 socket_(socket.Pass()), | |
183 transport_security_state_(transport_security_state), | 187 transport_security_state_(transport_security_state), |
184 server_info_(server_info.Pass()), | 188 server_info_(server_info.Pass()), |
185 num_total_streams_(0), | 189 num_total_streams_(0), |
186 task_runner_(task_runner), | 190 task_runner_(task_runner), |
187 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), | 191 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), |
188 packet_reader_(socket_.get(), | |
189 clock, | |
190 this, | |
191 yield_after_packets, | |
192 yield_after_duration, | |
193 net_log_), | |
194 dns_resolution_end_time_(dns_resolution_end_time), | 192 dns_resolution_end_time_(dns_resolution_end_time), |
195 logger_(new QuicConnectionLogger(this, | 193 logger_(new QuicConnectionLogger(this, |
196 connection_description, | 194 connection_description, |
197 socket_performance_watcher.Pass(), | 195 socket_performance_watcher.Pass(), |
198 net_log_)), | 196 net_log_)), |
199 going_away_(false), | 197 going_away_(false), |
200 disabled_reason_(QUIC_DISABLED_NOT), | 198 disabled_reason_(QUIC_DISABLED_NOT), |
201 weak_factory_(this) { | 199 weak_factory_(this) { |
| 200 sockets_[0] = socket.Pass(); |
| 201 packet_readers_[0].reset(new QuicPacketReader(sockets_[0].get(), |
| 202 clock, |
| 203 this, |
| 204 yield_after_packets, |
| 205 yield_after_duration, |
| 206 net_log_)); |
202 crypto_stream_.reset( | 207 crypto_stream_.reset( |
203 crypto_client_stream_factory | 208 crypto_client_stream_factory |
204 ? crypto_client_stream_factory->CreateQuicCryptoClientStream( | 209 ? crypto_client_stream_factory->CreateQuicCryptoClientStream( |
205 server_id, this, crypto_config) | 210 server_id, this, crypto_config) |
206 : new QuicCryptoClientStream( | 211 : new QuicCryptoClientStream( |
207 server_id, this, | 212 server_id, this, |
208 new ProofVerifyContextChromium(cert_verify_flags, net_log_), | 213 new ProofVerifyContextChromium(cert_verify_flags, net_log_), |
209 crypto_config)); | 214 crypto_config)); |
210 connection->set_debug_visitor(logger_.get()); | 215 connection->set_debug_visitor(logger_.get()); |
211 net_log_.BeginEvent(NetLog::TYPE_QUIC_SESSION, | 216 net_log_.BeginEvent(NetLog::TYPE_QUIC_SESSION, |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 } else if (error == QUIC_PUBLIC_RESET) { | 759 } else if (error == QUIC_PUBLIC_RESET) { |
755 disabled_reason_ = QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE; | 760 disabled_reason_ = QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE; |
756 } | 761 } |
757 | 762 |
758 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.QuicVersion", | 763 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.QuicVersion", |
759 connection()->version()); | 764 connection()->version()); |
760 NotifyFactoryOfSessionGoingAway(); | 765 NotifyFactoryOfSessionGoingAway(); |
761 if (!callback_.is_null()) { | 766 if (!callback_.is_null()) { |
762 base::ResetAndReturn(&callback_).Run(ERR_QUIC_PROTOCOL_ERROR); | 767 base::ResetAndReturn(&callback_).Run(ERR_QUIC_PROTOCOL_ERROR); |
763 } | 768 } |
764 socket_->Close(); | 769 |
| 770 for (size_t i = 0; i < sockets_.size(); ++i) { |
| 771 sockets_[i]->Close(); |
| 772 } |
765 QuicSession::OnConnectionClosed(error, from_peer); | 773 QuicSession::OnConnectionClosed(error, from_peer); |
766 DCHECK(dynamic_streams().empty()); | 774 DCHECK(dynamic_streams().empty()); |
767 CloseAllStreams(ERR_UNEXPECTED); | 775 CloseAllStreams(ERR_UNEXPECTED); |
768 CloseAllObservers(ERR_UNEXPECTED); | 776 CloseAllObservers(ERR_UNEXPECTED); |
769 NotifyFactoryOfSessionClosedLater(); | 777 NotifyFactoryOfSessionClosedLater(); |
770 } | 778 } |
771 | 779 |
772 void QuicChromiumClientSession::OnSuccessfulVersionNegotiation( | 780 void QuicChromiumClientSession::OnSuccessfulVersionNegotiation( |
773 const QuicVersion& version) { | 781 const QuicVersion& version) { |
774 logger_->OnSuccessfulVersionNegotiation(version); | 782 logger_->OnSuccessfulVersionNegotiation(version); |
(...skipping 23 matching lines...) Expand all Loading... |
798 const ProofVerifyDetailsChromium* verify_details_chromium = | 806 const ProofVerifyDetailsChromium* verify_details_chromium = |
799 reinterpret_cast<const ProofVerifyDetailsChromium*>(&verify_details); | 807 reinterpret_cast<const ProofVerifyDetailsChromium*>(&verify_details); |
800 CertVerifyResult* result_copy = new CertVerifyResult; | 808 CertVerifyResult* result_copy = new CertVerifyResult; |
801 result_copy->CopyFrom(verify_details_chromium->cert_verify_result); | 809 result_copy->CopyFrom(verify_details_chromium->cert_verify_result); |
802 cert_verify_result_.reset(result_copy); | 810 cert_verify_result_.reset(result_copy); |
803 pinning_failure_log_ = verify_details_chromium->pinning_failure_log; | 811 pinning_failure_log_ = verify_details_chromium->pinning_failure_log; |
804 logger_->OnCertificateVerified(*cert_verify_result_); | 812 logger_->OnCertificateVerified(*cert_verify_result_); |
805 } | 813 } |
806 | 814 |
807 void QuicChromiumClientSession::StartReading() { | 815 void QuicChromiumClientSession::StartReading() { |
808 packet_reader_.StartReading(); | 816 for (size_t i = 0; i < packet_readers_.size(); ++i) { |
| 817 packet_readers_[i]->StartReading(); |
| 818 } |
809 } | 819 } |
810 | 820 |
811 void QuicChromiumClientSession::CloseSessionOnError(int error, | 821 void QuicChromiumClientSession::CloseSessionOnError(int error, |
812 QuicErrorCode quic_error) { | 822 QuicErrorCode quic_error) { |
813 RecordAndCloseSessionOnError(error, quic_error); | 823 RecordAndCloseSessionOnError(error, quic_error); |
814 NotifyFactoryOfSessionClosed(); | 824 NotifyFactoryOfSessionClosed(); |
815 } | 825 } |
816 | 826 |
817 void QuicChromiumClientSession::CloseSessionOnErrorAndNotifyFactoryLater( | 827 void QuicChromiumClientSession::CloseSessionOnErrorAndNotifyFactoryLater( |
818 int error, | 828 int error, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 if (IsCryptoHandshakeConfirmed()) | 973 if (IsCryptoHandshakeConfirmed()) |
964 return; | 974 return; |
965 | 975 |
966 // TODO(rch): re-enable this code once beta is cut. | 976 // TODO(rch): re-enable this code once beta is cut. |
967 // if (stream_factory_) | 977 // if (stream_factory_) |
968 // stream_factory_->OnSessionConnectTimeout(this); | 978 // stream_factory_->OnSessionConnectTimeout(this); |
969 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); | 979 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); |
970 // DCHECK_EQ(0u, GetNumOpenStreams()); | 980 // DCHECK_EQ(0u, GetNumOpenStreams()); |
971 } | 981 } |
972 | 982 |
| 983 void QuicChromiumClientSession::AddSocket( |
| 984 scoped_ptr<DatagramClientSocket> socket) { |
| 985 size_t num_sockets = sockets_.size(); |
| 986 sockets_.resize(num_sockets + 1); |
| 987 sockets_[num_sockets - 1] = socket.Pass(); |
| 988 } |
| 989 |
| 990 bool QuicChromiumClientSession::AddPacketReader(QuicPacketReader* reader) { |
| 991 size_t num_readers = packet_readers_.size(); |
| 992 if (num_readers >= kMaxReadersPerQuicSession) { |
| 993 return false; |
| 994 } |
| 995 packet_readers_.resize(num_readers + 1); |
| 996 packet_readers_[num_readers - 1].reset(reader); |
| 997 return true; |
| 998 } |
| 999 |
973 } // namespace net | 1000 } // namespace net |
OLD | NEW |