Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: net/quic/quic_chromium_client_session.cc

Issue 1327923002: Migrates QUIC sessions to a new network when old network is (about to be) disconnected. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@home
Patch Set: Fixed StartReading method Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 const QuicConfig& config, 173 const QuicConfig& config,
169 QuicCryptoClientConfig* crypto_config, 174 QuicCryptoClientConfig* crypto_config,
170 const char* const connection_description, 175 const char* const connection_description,
171 base::TimeTicks dns_resolution_end_time, 176 base::TimeTicks dns_resolution_end_time,
172 base::TaskRunner* task_runner, 177 base::TaskRunner* task_runner,
173 NetLog* net_log) 178 NetLog* net_log)
174 : QuicClientSessionBase(connection, config), 179 : QuicClientSessionBase(connection, config),
175 server_id_(server_id), 180 server_id_(server_id),
176 require_confirmation_(false), 181 require_confirmation_(false),
177 stream_factory_(stream_factory), 182 stream_factory_(stream_factory),
178 socket_(socket.Pass()),
179 transport_security_state_(transport_security_state), 183 transport_security_state_(transport_security_state),
180 server_info_(server_info.Pass()), 184 server_info_(server_info.Pass()),
181 num_total_streams_(0), 185 num_total_streams_(0),
182 task_runner_(task_runner), 186 task_runner_(task_runner),
183 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), 187 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)),
184 packet_reader_(socket_.get(), this, net_log_),
185 dns_resolution_end_time_(dns_resolution_end_time), 188 dns_resolution_end_time_(dns_resolution_end_time),
186 logger_(new QuicConnectionLogger(this, connection_description, net_log_)), 189 logger_(new QuicConnectionLogger(this, connection_description, net_log_)),
187 going_away_(false), 190 going_away_(false),
188 disabled_reason_(QUIC_DISABLED_NOT), 191 disabled_reason_(QUIC_DISABLED_NOT),
189 weak_factory_(this) { 192 weak_factory_(this) {
193 sockets_[0] = socket.Pass();
Ryan Hamilton 2015/09/08 04:09:37 nit: sockets_.push_back(socket.Pass())
Jana 2015/11/17 01:50:08 Done.
194 packet_readers_[0].reset(
195 new QuicPacketReader(sockets_[0].get(), this, net_log_));
Ryan Hamilton 2015/09/08 04:09:37 ditto
Jana 2015/11/17 01:50:08 Done.
190 crypto_stream_.reset( 196 crypto_stream_.reset(
191 crypto_client_stream_factory 197 crypto_client_stream_factory
192 ? crypto_client_stream_factory->CreateQuicCryptoClientStream( 198 ? crypto_client_stream_factory->CreateQuicCryptoClientStream(
193 server_id, this, crypto_config) 199 server_id, this, crypto_config)
194 : new QuicCryptoClientStream( 200 : new QuicCryptoClientStream(
195 server_id, this, 201 server_id, this,
196 new ProofVerifyContextChromium(cert_verify_flags, net_log_), 202 new ProofVerifyContextChromium(cert_verify_flags, net_log_),
197 crypto_config)); 203 crypto_config));
198 connection->set_debug_visitor(logger_.get()); 204 connection->set_debug_visitor(logger_.get());
199 net_log_.BeginEvent(NetLog::TYPE_QUIC_SESSION, 205 net_log_.BeginEvent(NetLog::TYPE_QUIC_SESSION,
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 } else if (error == QUIC_PUBLIC_RESET) { 743 } else if (error == QUIC_PUBLIC_RESET) {
738 disabled_reason_ = QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE; 744 disabled_reason_ = QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE;
739 } 745 }
740 746
741 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.QuicVersion", 747 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.QuicVersion",
742 connection()->version()); 748 connection()->version());
743 NotifyFactoryOfSessionGoingAway(); 749 NotifyFactoryOfSessionGoingAway();
744 if (!callback_.is_null()) { 750 if (!callback_.is_null()) {
745 base::ResetAndReturn(&callback_).Run(ERR_QUIC_PROTOCOL_ERROR); 751 base::ResetAndReturn(&callback_).Run(ERR_QUIC_PROTOCOL_ERROR);
746 } 752 }
747 socket_->Close(); 753
754 for (size_t i = 0; i < sockets_.size(); ++i) {
Ryan Hamilton 2015/09/08 04:09:37 nit: for (Socket socket : sockets) { ... }
Jana 2015/11/17 01:50:08 Done.
755 sockets_[i]->Close();
756 }
748 QuicSession::OnConnectionClosed(error, from_peer); 757 QuicSession::OnConnectionClosed(error, from_peer);
749 DCHECK(dynamic_streams().empty()); 758 DCHECK(dynamic_streams().empty());
750 CloseAllStreams(ERR_UNEXPECTED); 759 CloseAllStreams(ERR_UNEXPECTED);
751 CloseAllObservers(ERR_UNEXPECTED); 760 CloseAllObservers(ERR_UNEXPECTED);
752 NotifyFactoryOfSessionClosedLater(); 761 NotifyFactoryOfSessionClosedLater();
753 } 762 }
754 763
755 void QuicChromiumClientSession::OnSuccessfulVersionNegotiation( 764 void QuicChromiumClientSession::OnSuccessfulVersionNegotiation(
756 const QuicVersion& version) { 765 const QuicVersion& version) {
757 logger_->OnSuccessfulVersionNegotiation(version); 766 logger_->OnSuccessfulVersionNegotiation(version);
(...skipping 23 matching lines...) Expand all
781 const ProofVerifyDetailsChromium* verify_details_chromium = 790 const ProofVerifyDetailsChromium* verify_details_chromium =
782 reinterpret_cast<const ProofVerifyDetailsChromium*>(&verify_details); 791 reinterpret_cast<const ProofVerifyDetailsChromium*>(&verify_details);
783 CertVerifyResult* result_copy = new CertVerifyResult; 792 CertVerifyResult* result_copy = new CertVerifyResult;
784 result_copy->CopyFrom(verify_details_chromium->cert_verify_result); 793 result_copy->CopyFrom(verify_details_chromium->cert_verify_result);
785 cert_verify_result_.reset(result_copy); 794 cert_verify_result_.reset(result_copy);
786 pinning_failure_log_ = verify_details_chromium->pinning_failure_log; 795 pinning_failure_log_ = verify_details_chromium->pinning_failure_log;
787 logger_->OnCertificateVerified(*cert_verify_result_); 796 logger_->OnCertificateVerified(*cert_verify_result_);
788 } 797 }
789 798
790 void QuicChromiumClientSession::StartReading() { 799 void QuicChromiumClientSession::StartReading() {
791 packet_reader_.StartReading(); 800 for (size_t i = 0; i < packet_readers_.size(); ++i) {
Ryan Hamilton 2015/09/08 04:09:37 nit: c++11 foreach loop
Jana 2015/11/17 01:50:08 Done.
801 packet_readers_[i]->StartReading();
802 }
792 } 803 }
793 804
794 void QuicChromiumClientSession::CloseSessionOnError(int error, 805 void QuicChromiumClientSession::CloseSessionOnError(int error,
795 QuicErrorCode quic_error) { 806 QuicErrorCode quic_error) {
796 RecordAndCloseSessionOnError(error, quic_error); 807 RecordAndCloseSessionOnError(error, quic_error);
797 NotifyFactoryOfSessionClosed(); 808 NotifyFactoryOfSessionClosed();
798 } 809 }
799 810
800 void QuicChromiumClientSession::CloseSessionOnErrorAndNotifyFactoryLater( 811 void QuicChromiumClientSession::CloseSessionOnErrorAndNotifyFactoryLater(
801 int error, 812 int error,
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 if (IsCryptoHandshakeConfirmed()) 957 if (IsCryptoHandshakeConfirmed())
947 return; 958 return;
948 959
949 // TODO(rch): re-enable this code once beta is cut. 960 // TODO(rch): re-enable this code once beta is cut.
950 // if (stream_factory_) 961 // if (stream_factory_)
951 // stream_factory_->OnSessionConnectTimeout(this); 962 // stream_factory_->OnSessionConnectTimeout(this);
952 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); 963 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED);
953 // DCHECK_EQ(0u, GetNumOpenStreams()); 964 // DCHECK_EQ(0u, GetNumOpenStreams());
954 } 965 }
955 966
967 void QuicChromiumClientSession::AddSocket(
968 scoped_ptr<DatagramClientSocket> socket) {
969 size_t num_sockets = sockets_.size();
970 sockets_.resize(num_sockets + 1);
971 sockets_[num_sockets - 1] = socket.Pass();
Ryan Hamilton 2015/09/08 04:09:37 I think you can just do sockets_.push_back(socket.
Jana 2015/11/17 01:50:08 Done.
972 }
973
974 bool QuicChromiumClientSession::AddPacketReader(QuicPacketReader* reader) {
975 size_t num_readers = packet_readers_.size();
976 if (num_readers >= kMaxReadersPerQuicSession) {
977 return false;
978 }
979 packet_readers_.resize(num_readers + 1);
980 packet_readers_[num_readers - 1].reset(reader);
981 return true;
982 }
Ryan Hamilton 2015/09/08 04:09:37 It's a bit surprising that the AddSocket method re
Jana 2015/11/17 01:50:08 Yeah, this wasn't great, so I cleaned it up now, P
983
956 } // namespace net 984 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698