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 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 } else if (error == QUIC_PUBLIC_RESET) { | 765 } else if (error == QUIC_PUBLIC_RESET) { |
764 disabled_reason_ = QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE; | 766 disabled_reason_ = QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE; |
765 } | 767 } |
766 | 768 |
767 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.QuicVersion", | 769 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.QuicVersion", |
768 connection()->version()); | 770 connection()->version()); |
769 NotifyFactoryOfSessionGoingAway(); | 771 NotifyFactoryOfSessionGoingAway(); |
770 if (!callback_.is_null()) { | 772 if (!callback_.is_null()) { |
771 base::ResetAndReturn(&callback_).Run(ERR_QUIC_PROTOCOL_ERROR); | 773 base::ResetAndReturn(&callback_).Run(ERR_QUIC_PROTOCOL_ERROR); |
772 } | 774 } |
773 socket_->Close(); | 775 |
776 for (auto& socket : sockets_) { | |
Ryan Hamilton
2015/12/18 22:00:18
nit: I'd use the full type here. (no need for {}s)
| |
777 socket->Close(); | |
778 } | |
774 QuicSession::OnConnectionClosed(error, from_peer); | 779 QuicSession::OnConnectionClosed(error, from_peer); |
775 DCHECK(dynamic_streams().empty()); | 780 DCHECK(dynamic_streams().empty()); |
776 CloseAllStreams(ERR_UNEXPECTED); | 781 CloseAllStreams(ERR_UNEXPECTED); |
777 CloseAllObservers(ERR_UNEXPECTED); | 782 CloseAllObservers(ERR_UNEXPECTED); |
778 NotifyFactoryOfSessionClosedLater(); | 783 NotifyFactoryOfSessionClosedLater(); |
779 } | 784 } |
780 | 785 |
781 void QuicChromiumClientSession::OnSuccessfulVersionNegotiation( | 786 void QuicChromiumClientSession::OnSuccessfulVersionNegotiation( |
782 const QuicVersion& version) { | 787 const QuicVersion& version) { |
783 logger_->OnSuccessfulVersionNegotiation(version); | 788 logger_->OnSuccessfulVersionNegotiation(version); |
(...skipping 25 matching lines...) Expand all Loading... | |
809 cert_verify_result_.reset(new CertVerifyResult); | 814 cert_verify_result_.reset(new CertVerifyResult); |
810 cert_verify_result_->CopyFrom(verify_details_chromium->cert_verify_result); | 815 cert_verify_result_->CopyFrom(verify_details_chromium->cert_verify_result); |
811 pinning_failure_log_ = verify_details_chromium->pinning_failure_log; | 816 pinning_failure_log_ = verify_details_chromium->pinning_failure_log; |
812 scoped_ptr<ct::CTVerifyResult> ct_verify_result_copy( | 817 scoped_ptr<ct::CTVerifyResult> ct_verify_result_copy( |
813 new ct::CTVerifyResult(verify_details_chromium->ct_verify_result)); | 818 new ct::CTVerifyResult(verify_details_chromium->ct_verify_result)); |
814 ct_verify_result_ = ct_verify_result_copy.Pass(); | 819 ct_verify_result_ = ct_verify_result_copy.Pass(); |
815 logger_->OnCertificateVerified(*cert_verify_result_); | 820 logger_->OnCertificateVerified(*cert_verify_result_); |
816 } | 821 } |
817 | 822 |
818 void QuicChromiumClientSession::StartReading() { | 823 void QuicChromiumClientSession::StartReading() { |
819 packet_reader_.StartReading(); | 824 for (auto& packet_reader : packet_readers_) { |
825 packet_reader->StartReading(); | |
826 } | |
Ryan Hamilton
2015/12/18 22:00:18
nit: no need for {}s
| |
820 } | 827 } |
821 | 828 |
822 void QuicChromiumClientSession::CloseSessionOnError(int error, | 829 void QuicChromiumClientSession::CloseSessionOnError(int error, |
823 QuicErrorCode quic_error) { | 830 QuicErrorCode quic_error) { |
824 RecordAndCloseSessionOnError(error, quic_error); | 831 RecordAndCloseSessionOnError(error, quic_error); |
825 NotifyFactoryOfSessionClosed(); | 832 NotifyFactoryOfSessionClosed(); |
826 } | 833 } |
827 | 834 |
828 void QuicChromiumClientSession::CloseSessionOnErrorAndNotifyFactoryLater( | 835 void QuicChromiumClientSession::CloseSessionOnErrorAndNotifyFactoryLater( |
829 int error, | 836 int error, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
905 dict->Set("aliases", alias_list.Pass()); | 912 dict->Set("aliases", alias_list.Pass()); |
906 | 913 |
907 return dict.Pass(); | 914 return dict.Pass(); |
908 } | 915 } |
909 | 916 |
910 base::WeakPtr<QuicChromiumClientSession> | 917 base::WeakPtr<QuicChromiumClientSession> |
911 QuicChromiumClientSession::GetWeakPtr() { | 918 QuicChromiumClientSession::GetWeakPtr() { |
912 return weak_factory_.GetWeakPtr(); | 919 return weak_factory_.GetWeakPtr(); |
913 } | 920 } |
914 | 921 |
915 void QuicChromiumClientSession::OnReadError(int result) { | 922 void QuicChromiumClientSession::OnReadError( |
923 int result, | |
924 const DatagramClientSocket* socket) { | |
925 DCHECK(socket != nullptr); | |
926 if (socket != GetDefaultSocket()) { | |
927 // Ignore read errors from old sockets that are no longer active. | |
928 // TODO(jri): Maybe clean up old sockets on error. | |
Ryan Hamilton
2015/12/18 22:00:18
Do we stop reading on the socket in this case?
| |
929 return; | |
930 } | |
916 DVLOG(1) << "Closing session on read error: " << result; | 931 DVLOG(1) << "Closing session on read error: " << result; |
917 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.ReadError", -result); | 932 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.ReadError", -result); |
918 NotifyFactoryOfSessionGoingAway(); | 933 NotifyFactoryOfSessionGoingAway(); |
919 CloseSessionOnErrorInner(result, QUIC_PACKET_READ_ERROR); | 934 CloseSessionOnErrorInner(result, QUIC_PACKET_READ_ERROR); |
920 NotifyFactoryOfSessionClosedLater(); | 935 NotifyFactoryOfSessionClosedLater(); |
921 } | 936 } |
922 | 937 |
923 bool QuicChromiumClientSession::OnPacket(const QuicEncryptedPacket& packet, | 938 bool QuicChromiumClientSession::OnPacket(const QuicEncryptedPacket& packet, |
924 IPEndPoint local_address, | 939 IPEndPoint local_address, |
925 IPEndPoint peer_address) { | 940 IPEndPoint peer_address) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
974 if (IsCryptoHandshakeConfirmed()) | 989 if (IsCryptoHandshakeConfirmed()) |
975 return; | 990 return; |
976 | 991 |
977 // TODO(rch): re-enable this code once beta is cut. | 992 // TODO(rch): re-enable this code once beta is cut. |
978 // if (stream_factory_) | 993 // if (stream_factory_) |
979 // stream_factory_->OnSessionConnectTimeout(this); | 994 // stream_factory_->OnSessionConnectTimeout(this); |
980 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); | 995 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); |
981 // DCHECK_EQ(0u, GetNumOpenOutgoingStreams()); | 996 // DCHECK_EQ(0u, GetNumOpenOutgoingStreams()); |
982 } | 997 } |
983 | 998 |
999 bool QuicChromiumClientSession::MigrateToSocket( | |
Ryan Hamilton
2015/12/18 22:00:19
I think we should probably have tests for this new
| |
1000 scoped_ptr<DatagramClientSocket> socket, | |
1001 scoped_ptr<QuicPacketReader> reader, | |
1002 scoped_ptr<QuicPacketWriter> writer) { | |
1003 DCHECK_EQ(sockets_.size(), packet_readers_.size()); | |
1004 if (sockets_.size() >= kMaxReadersPerQuicSession) { | |
1005 return false; | |
1006 } | |
1007 // TODO(jri): Make SetQuicPacketWriter take a scoped_ptr. | |
Ryan Hamilton
2015/12/18 22:00:19
I don't think that's possible because the connecti
| |
1008 connection()->SetQuicPacketWriter(writer.release(), /*owns_writer=*/true); | |
Ryan Hamilton
2015/12/18 22:00:19
So all new data will go out over this new writer,
| |
1009 packet_readers_.push_back(reader.Pass()); | |
1010 sockets_.push_back(socket.Pass()); | |
1011 StartReading(); | |
1012 connection()->SendPing(); | |
1013 return true; | |
1014 } | |
1015 | |
1016 const DatagramClientSocket* QuicChromiumClientSession::GetDefaultSocket() | |
1017 const { | |
1018 DCHECK(sockets_.back().get() != nullptr); | |
1019 // The most recently added socket is the currently active one. | |
1020 return sockets_.back().get(); | |
1021 } | |
1022 | |
984 } // namespace net | 1023 } // namespace net |
OLD | NEW |