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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 QuicCryptoClientConfig* crypto_config, | 176 QuicCryptoClientConfig* crypto_config, |
172 const char* const connection_description, | 177 const char* const connection_description, |
173 base::TimeTicks dns_resolution_end_time, | 178 base::TimeTicks dns_resolution_end_time, |
174 base::TaskRunner* task_runner, | 179 base::TaskRunner* task_runner, |
175 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher, | 180 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
176 NetLog* net_log) | 181 NetLog* net_log) |
177 : QuicClientSessionBase(connection, config), | 182 : QuicClientSessionBase(connection, config), |
178 server_id_(server_id), | 183 server_id_(server_id), |
179 require_confirmation_(false), | 184 require_confirmation_(false), |
180 stream_factory_(stream_factory), | 185 stream_factory_(stream_factory), |
181 socket_(socket.Pass()), | |
182 transport_security_state_(transport_security_state), | 186 transport_security_state_(transport_security_state), |
183 server_info_(server_info.Pass()), | 187 server_info_(server_info.Pass()), |
184 num_total_streams_(0), | 188 num_total_streams_(0), |
185 task_runner_(task_runner), | 189 task_runner_(task_runner), |
186 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), | 190 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), |
187 packet_reader_(socket_.get(), | |
188 clock, | |
189 this, | |
190 yield_after_packets, | |
191 yield_after_duration, | |
192 net_log_), | |
193 dns_resolution_end_time_(dns_resolution_end_time), | 191 dns_resolution_end_time_(dns_resolution_end_time), |
194 logger_(new QuicConnectionLogger(this, | 192 logger_(new QuicConnectionLogger(this, |
195 connection_description, | 193 connection_description, |
196 socket_performance_watcher.Pass(), | 194 socket_performance_watcher.Pass(), |
197 net_log_)), | 195 net_log_)), |
198 going_away_(false), | 196 going_away_(false), |
199 disabled_reason_(QUIC_DISABLED_NOT), | 197 disabled_reason_(QUIC_DISABLED_NOT), |
200 weak_factory_(this) { | 198 weak_factory_(this) { |
| 199 sockets_.push_back(socket.Pass()); |
| 200 packet_readers_.push_back(make_scoped_ptr(new QuicPacketReader( |
| 201 sockets_.back().get(), clock, this, yield_after_packets, |
| 202 yield_after_duration, net_log_))); |
201 crypto_stream_.reset( | 203 crypto_stream_.reset( |
202 crypto_client_stream_factory | 204 crypto_client_stream_factory |
203 ? crypto_client_stream_factory->CreateQuicCryptoClientStream( | 205 ? crypto_client_stream_factory->CreateQuicCryptoClientStream( |
204 server_id, this, crypto_config) | 206 server_id, this, crypto_config) |
205 : new QuicCryptoClientStream( | 207 : new QuicCryptoClientStream( |
206 server_id, this, | 208 server_id, this, |
207 new ProofVerifyContextChromium(cert_verify_flags, net_log_), | 209 new ProofVerifyContextChromium(cert_verify_flags, net_log_), |
208 crypto_config)); | 210 crypto_config)); |
209 connection->set_debug_visitor(logger_.get()); | 211 connection->set_debug_visitor(logger_.get()); |
210 net_log_.BeginEvent(NetLog::TYPE_QUIC_SESSION, | 212 net_log_.BeginEvent(NetLog::TYPE_QUIC_SESSION, |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 } else if (error == QUIC_PUBLIC_RESET) { | 755 } else if (error == QUIC_PUBLIC_RESET) { |
754 disabled_reason_ = QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE; | 756 disabled_reason_ = QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE; |
755 } | 757 } |
756 | 758 |
757 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.QuicVersion", | 759 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.QuicVersion", |
758 connection()->version()); | 760 connection()->version()); |
759 NotifyFactoryOfSessionGoingAway(); | 761 NotifyFactoryOfSessionGoingAway(); |
760 if (!callback_.is_null()) { | 762 if (!callback_.is_null()) { |
761 base::ResetAndReturn(&callback_).Run(ERR_QUIC_PROTOCOL_ERROR); | 763 base::ResetAndReturn(&callback_).Run(ERR_QUIC_PROTOCOL_ERROR); |
762 } | 764 } |
763 socket_->Close(); | 765 |
| 766 for (auto& socket : sockets_) { |
| 767 socket->Close(); |
| 768 } |
764 QuicSession::OnConnectionClosed(error, from_peer); | 769 QuicSession::OnConnectionClosed(error, from_peer); |
765 DCHECK(dynamic_streams().empty()); | 770 DCHECK(dynamic_streams().empty()); |
766 CloseAllStreams(ERR_UNEXPECTED); | 771 CloseAllStreams(ERR_UNEXPECTED); |
767 CloseAllObservers(ERR_UNEXPECTED); | 772 CloseAllObservers(ERR_UNEXPECTED); |
768 NotifyFactoryOfSessionClosedLater(); | 773 NotifyFactoryOfSessionClosedLater(); |
769 } | 774 } |
770 | 775 |
771 void QuicChromiumClientSession::OnSuccessfulVersionNegotiation( | 776 void QuicChromiumClientSession::OnSuccessfulVersionNegotiation( |
772 const QuicVersion& version) { | 777 const QuicVersion& version) { |
773 logger_->OnSuccessfulVersionNegotiation(version); | 778 logger_->OnSuccessfulVersionNegotiation(version); |
(...skipping 23 matching lines...) Expand all Loading... |
797 const ProofVerifyDetailsChromium* verify_details_chromium = | 802 const ProofVerifyDetailsChromium* verify_details_chromium = |
798 reinterpret_cast<const ProofVerifyDetailsChromium*>(&verify_details); | 803 reinterpret_cast<const ProofVerifyDetailsChromium*>(&verify_details); |
799 CertVerifyResult* result_copy = new CertVerifyResult; | 804 CertVerifyResult* result_copy = new CertVerifyResult; |
800 result_copy->CopyFrom(verify_details_chromium->cert_verify_result); | 805 result_copy->CopyFrom(verify_details_chromium->cert_verify_result); |
801 cert_verify_result_.reset(result_copy); | 806 cert_verify_result_.reset(result_copy); |
802 pinning_failure_log_ = verify_details_chromium->pinning_failure_log; | 807 pinning_failure_log_ = verify_details_chromium->pinning_failure_log; |
803 logger_->OnCertificateVerified(*cert_verify_result_); | 808 logger_->OnCertificateVerified(*cert_verify_result_); |
804 } | 809 } |
805 | 810 |
806 void QuicChromiumClientSession::StartReading() { | 811 void QuicChromiumClientSession::StartReading() { |
807 packet_reader_.StartReading(); | 812 for (auto& packet_reader : packet_readers_) { |
| 813 packet_reader->StartReading(); |
| 814 } |
808 } | 815 } |
809 | 816 |
810 void QuicChromiumClientSession::CloseSessionOnError(int error, | 817 void QuicChromiumClientSession::CloseSessionOnError(int error, |
811 QuicErrorCode quic_error) { | 818 QuicErrorCode quic_error) { |
812 RecordAndCloseSessionOnError(error, quic_error); | 819 RecordAndCloseSessionOnError(error, quic_error); |
813 NotifyFactoryOfSessionClosed(); | 820 NotifyFactoryOfSessionClosed(); |
814 } | 821 } |
815 | 822 |
816 void QuicChromiumClientSession::CloseSessionOnErrorAndNotifyFactoryLater( | 823 void QuicChromiumClientSession::CloseSessionOnErrorAndNotifyFactoryLater( |
817 int error, | 824 int error, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 if (IsCryptoHandshakeConfirmed()) | 969 if (IsCryptoHandshakeConfirmed()) |
963 return; | 970 return; |
964 | 971 |
965 // TODO(rch): re-enable this code once beta is cut. | 972 // TODO(rch): re-enable this code once beta is cut. |
966 // if (stream_factory_) | 973 // if (stream_factory_) |
967 // stream_factory_->OnSessionConnectTimeout(this); | 974 // stream_factory_->OnSessionConnectTimeout(this); |
968 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); | 975 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); |
969 // DCHECK_EQ(0u, GetNumOpenStreams()); | 976 // DCHECK_EQ(0u, GetNumOpenStreams()); |
970 } | 977 } |
971 | 978 |
| 979 bool QuicChromiumClientSession::MigrateToSocket( |
| 980 scoped_ptr<DatagramClientSocket> socket, |
| 981 QuicPacketReader* reader, |
| 982 QuicPacketWriter* writer) { |
| 983 DCHECK_EQ(sockets_.size(), packet_readers_.size()); |
| 984 if (sockets_.size() >= kMaxReadersPerQuicSession) { |
| 985 return false; |
| 986 } |
| 987 connection()->SetQuicPacketWriter(writer, /*owns_writer=*/true); |
| 988 packet_readers_.push_back(make_scoped_ptr(reader)); |
| 989 sockets_.push_back(socket.Pass()); |
| 990 |
| 991 StartReading(); |
| 992 return true; |
| 993 } |
| 994 |
972 } // namespace net | 995 } // namespace net |
OLD | NEW |