| 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/chromium/quic_chromium_client_session.h" | 5 #include "net/quic/chromium/quic_chromium_client_session.h" |
| 6 | 6 |
| 7 #include <openssl/ssl.h> | 7 #include <openssl/ssl.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 QuicClock* clock, | 212 QuicClock* clock, |
| 213 TransportSecurityState* transport_security_state, | 213 TransportSecurityState* transport_security_state, |
| 214 std::unique_ptr<QuicServerInfo> server_info, | 214 std::unique_ptr<QuicServerInfo> server_info, |
| 215 const QuicServerId& server_id, | 215 const QuicServerId& server_id, |
| 216 int yield_after_packets, | 216 int yield_after_packets, |
| 217 QuicTime::Delta yield_after_duration, | 217 QuicTime::Delta yield_after_duration, |
| 218 int cert_verify_flags, | 218 int cert_verify_flags, |
| 219 const QuicConfig& config, | 219 const QuicConfig& config, |
| 220 QuicCryptoClientConfig* crypto_config, | 220 QuicCryptoClientConfig* crypto_config, |
| 221 const char* const connection_description, | 221 const char* const connection_description, |
| 222 base::TimeTicks dns_resolution_start_time, |
| 222 base::TimeTicks dns_resolution_end_time, | 223 base::TimeTicks dns_resolution_end_time, |
| 223 QuicClientPushPromiseIndex* push_promise_index, | 224 QuicClientPushPromiseIndex* push_promise_index, |
| 224 base::TaskRunner* task_runner, | 225 base::TaskRunner* task_runner, |
| 225 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, | 226 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
| 226 NetLog* net_log) | 227 NetLog* net_log) |
| 227 : QuicClientSessionBase(connection, push_promise_index, config), | 228 : QuicClientSessionBase(connection, push_promise_index, config), |
| 228 server_id_(server_id), | 229 server_id_(server_id), |
| 229 require_confirmation_(false), | 230 require_confirmation_(false), |
| 230 stream_factory_(stream_factory), | 231 stream_factory_(stream_factory), |
| 231 transport_security_state_(transport_security_state), | 232 transport_security_state_(transport_security_state), |
| 232 server_info_(std::move(server_info)), | 233 server_info_(std::move(server_info)), |
| 233 pkp_bypassed_(false), | 234 pkp_bypassed_(false), |
| 234 num_total_streams_(0), | 235 num_total_streams_(0), |
| 235 task_runner_(task_runner), | 236 task_runner_(task_runner), |
| 236 net_log_(BoundNetLog::Make(net_log, NetLogSourceType::QUIC_SESSION)), | 237 net_log_(BoundNetLog::Make(net_log, NetLogSourceType::QUIC_SESSION)), |
| 237 dns_resolution_end_time_(dns_resolution_end_time), | |
| 238 logger_(new QuicConnectionLogger(this, | 238 logger_(new QuicConnectionLogger(this, |
| 239 connection_description, | 239 connection_description, |
| 240 std::move(socket_performance_watcher), | 240 std::move(socket_performance_watcher), |
| 241 net_log_)), | 241 net_log_)), |
| 242 going_away_(false), | 242 going_away_(false), |
| 243 port_migration_detected_(false), | 243 port_migration_detected_(false), |
| 244 token_binding_signatures_(kTokenBindingSignatureMapSize), | 244 token_binding_signatures_(kTokenBindingSignatureMapSize), |
| 245 streams_pushed_count_(0), | 245 streams_pushed_count_(0), |
| 246 streams_pushed_and_claimed_count_(0), | 246 streams_pushed_and_claimed_count_(0), |
| 247 migration_pending_(false), | 247 migration_pending_(false), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 259 connection->set_creator_debug_delegate(logger_.get()); | 259 connection->set_creator_debug_delegate(logger_.get()); |
| 260 net_log_.BeginEvent(NetLogEventType::QUIC_SESSION, | 260 net_log_.BeginEvent(NetLogEventType::QUIC_SESSION, |
| 261 base::Bind(NetLogQuicClientSessionCallback, &server_id, | 261 base::Bind(NetLogQuicClientSessionCallback, &server_id, |
| 262 cert_verify_flags, require_confirmation_)); | 262 cert_verify_flags, require_confirmation_)); |
| 263 IPEndPoint address; | 263 IPEndPoint address; |
| 264 if (socket && socket->GetLocalAddress(&address) == OK && | 264 if (socket && socket->GetLocalAddress(&address) == OK && |
| 265 address.GetFamily() == ADDRESS_FAMILY_IPV6) { | 265 address.GetFamily() == ADDRESS_FAMILY_IPV6) { |
| 266 connection->SetMaxPacketLength(connection->max_packet_length() - | 266 connection->SetMaxPacketLength(connection->max_packet_length() - |
| 267 kAdditionalOverheadForIPv6); | 267 kAdditionalOverheadForIPv6); |
| 268 } | 268 } |
| 269 connect_timing_.dns_start = dns_resolution_start_time; |
| 270 connect_timing_.dns_end = dns_resolution_end_time; |
| 269 } | 271 } |
| 270 | 272 |
| 271 QuicChromiumClientSession::~QuicChromiumClientSession() { | 273 QuicChromiumClientSession::~QuicChromiumClientSession() { |
| 272 if (!dynamic_streams().empty()) | 274 if (!dynamic_streams().empty()) |
| 273 RecordUnexpectedOpenStreams(DESTRUCTOR); | 275 RecordUnexpectedOpenStreams(DESTRUCTOR); |
| 274 if (!observers_.empty()) | 276 if (!observers_.empty()) |
| 275 RecordUnexpectedObservers(DESTRUCTOR); | 277 RecordUnexpectedObservers(DESTRUCTOR); |
| 276 if (!going_away_) | 278 if (!going_away_) |
| 277 RecordUnexpectedNotGoingAway(DESTRUCTOR); | 279 RecordUnexpectedNotGoingAway(DESTRUCTOR); |
| 278 | 280 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 if (!SignTokenBindingEkm(key_material, key, out)) | 615 if (!SignTokenBindingEkm(key_material, key, out)) |
| 614 return ERR_FAILED; | 616 return ERR_FAILED; |
| 615 token_binding_signatures_.Put(raw_public_key, *out); | 617 token_binding_signatures_.Put(raw_public_key, *out); |
| 616 return OK; | 618 return OK; |
| 617 } | 619 } |
| 618 | 620 |
| 619 int QuicChromiumClientSession::CryptoConnect( | 621 int QuicChromiumClientSession::CryptoConnect( |
| 620 bool require_confirmation, | 622 bool require_confirmation, |
| 621 const CompletionCallback& callback) { | 623 const CompletionCallback& callback) { |
| 622 require_confirmation_ = require_confirmation; | 624 require_confirmation_ = require_confirmation; |
| 623 handshake_start_ = base::TimeTicks::Now(); | 625 connect_timing_.connect_start = base::TimeTicks::Now(); |
| 624 RecordHandshakeState(STATE_STARTED); | 626 RecordHandshakeState(STATE_STARTED); |
| 625 DCHECK(flow_controller()); | 627 DCHECK(flow_controller()); |
| 626 crypto_stream_->CryptoConnect(); | 628 crypto_stream_->CryptoConnect(); |
| 627 | 629 |
| 628 if (IsCryptoHandshakeConfirmed()) | 630 if (IsCryptoHandshakeConfirmed()) { |
| 631 connect_timing_.connect_end = base::TimeTicks::Now(); |
| 629 return OK; | 632 return OK; |
| 633 } |
| 630 | 634 |
| 631 // Unless we require handshake confirmation, activate the session if | 635 // Unless we require handshake confirmation, activate the session if |
| 632 // we have established initial encryption. | 636 // we have established initial encryption. |
| 633 if (!require_confirmation_ && IsEncryptionEstablished()) | 637 if (!require_confirmation_ && IsEncryptionEstablished()) |
| 634 return OK; | 638 return OK; |
| 635 | 639 |
| 636 callback_ = callback; | 640 callback_ = callback; |
| 637 return ERR_IO_PENDING; | 641 return ERR_IO_PENDING; |
| 638 } | 642 } |
| 639 | 643 |
| 640 int QuicChromiumClientSession::ResumeCryptoConnect( | 644 int QuicChromiumClientSession::ResumeCryptoConnect( |
| 641 const CompletionCallback& callback) { | 645 const CompletionCallback& callback) { |
| 642 if (IsCryptoHandshakeConfirmed()) | 646 if (IsCryptoHandshakeConfirmed()) { |
| 647 connect_timing_.connect_end = base::TimeTicks::Now(); |
| 643 return OK; | 648 return OK; |
| 649 } |
| 644 | 650 |
| 645 if (!connection()->connected()) | 651 if (!connection()->connected()) |
| 646 return ERR_QUIC_HANDSHAKE_FAILED; | 652 return ERR_QUIC_HANDSHAKE_FAILED; |
| 647 | 653 |
| 648 callback_ = callback; | 654 callback_ = callback; |
| 649 return ERR_IO_PENDING; | 655 return ERR_IO_PENDING; |
| 650 } | 656 } |
| 651 | 657 |
| 652 int QuicChromiumClientSession::GetNumSentClientHellos() const { | 658 int QuicChromiumClientSession::GetNumSentClientHellos() const { |
| 653 return crypto_stream_->num_sent_client_hellos(); | 659 return crypto_stream_->num_sent_client_hellos(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 if (!callback_.is_null() && | 789 if (!callback_.is_null() && |
| 784 (!require_confirmation_ || event == HANDSHAKE_CONFIRMED || | 790 (!require_confirmation_ || event == HANDSHAKE_CONFIRMED || |
| 785 event == ENCRYPTION_REESTABLISHED)) { | 791 event == ENCRYPTION_REESTABLISHED)) { |
| 786 // TODO(rtenneti): Currently for all CryptoHandshakeEvent events, callback_ | 792 // TODO(rtenneti): Currently for all CryptoHandshakeEvent events, callback_ |
| 787 // could be called because there are no error events in CryptoHandshakeEvent | 793 // could be called because there are no error events in CryptoHandshakeEvent |
| 788 // enum. If error events are added to CryptoHandshakeEvent, then the | 794 // enum. If error events are added to CryptoHandshakeEvent, then the |
| 789 // following code needs to changed. | 795 // following code needs to changed. |
| 790 base::ResetAndReturn(&callback_).Run(OK); | 796 base::ResetAndReturn(&callback_).Run(OK); |
| 791 } | 797 } |
| 792 if (event == HANDSHAKE_CONFIRMED) { | 798 if (event == HANDSHAKE_CONFIRMED) { |
| 793 UMA_HISTOGRAM_TIMES("Net.QuicSession.HandshakeConfirmedTime", | 799 // Update |connect_end| only when handshake is confirmed. This should also |
| 794 base::TimeTicks::Now() - handshake_start_); | 800 // take care of any failed 0-RTT request. |
| 801 connect_timing_.connect_end = base::TimeTicks::Now(); |
| 802 DCHECK(connect_timing_.connect_start < connect_timing_.connect_end); |
| 803 UMA_HISTOGRAM_TIMES( |
| 804 "Net.QuicSession.HandshakeConfirmedTime", |
| 805 connect_timing_.connect_end - connect_timing_.connect_start); |
| 806 |
| 795 if (server_info_) { | 807 if (server_info_) { |
| 796 // TODO(rtenneti): Should we delete this histogram? | 808 // TODO(rtenneti): Should we delete this histogram? |
| 797 // Track how long it has taken to finish handshake once we start waiting | 809 // Track how long it has taken to finish handshake once we start waiting |
| 798 // for reading of QUIC server information from disk cache. We could use | 810 // for reading of QUIC server information from disk cache. We could use |
| 799 // this data to compare total time taken if we were to cancel the disk | 811 // this data to compare total time taken if we were to cancel the disk |
| 800 // cache read vs waiting for the read to complete. | 812 // cache read vs waiting for the read to complete. |
| 801 base::TimeTicks wait_for_data_start_time = | 813 base::TimeTicks wait_for_data_start_time = |
| 802 server_info_->wait_for_data_start_time(); | 814 server_info_->wait_for_data_start_time(); |
| 803 if (!wait_for_data_start_time.is_null()) { | 815 if (!wait_for_data_start_time.is_null()) { |
| 804 UMA_HISTOGRAM_TIMES( | 816 UMA_HISTOGRAM_TIMES( |
| 805 "Net.QuicServerInfo.WaitForDataReady.HandshakeConfirmedTime", | 817 "Net.QuicServerInfo.WaitForDataReady.HandshakeConfirmedTime", |
| 806 base::TimeTicks::Now() - wait_for_data_start_time); | 818 base::TimeTicks::Now() - wait_for_data_start_time); |
| 807 } | 819 } |
| 808 } | 820 } |
| 809 // Track how long it has taken to finish handshake after we have finished | 821 // Track how long it has taken to finish handshake after we have finished |
| 810 // DNS host resolution. | 822 // DNS host resolution. |
| 811 if (!dns_resolution_end_time_.is_null()) { | 823 if (!connect_timing_.dns_end.is_null()) { |
| 812 UMA_HISTOGRAM_TIMES( | 824 UMA_HISTOGRAM_TIMES( |
| 813 "Net.QuicSession.HostResolution.HandshakeConfirmedTime", | 825 "Net.QuicSession.HostResolution.HandshakeConfirmedTime", |
| 814 base::TimeTicks::Now() - dns_resolution_end_time_); | 826 base::TimeTicks::Now() - connect_timing_.dns_end); |
| 815 } | 827 } |
| 816 | 828 |
| 817 ObserverSet::iterator it = observers_.begin(); | 829 ObserverSet::iterator it = observers_.begin(); |
| 818 while (it != observers_.end()) { | 830 while (it != observers_.end()) { |
| 819 Observer* observer = *it; | 831 Observer* observer = *it; |
| 820 ++it; | 832 ++it; |
| 821 observer->OnCryptoHandshakeConfirmed(); | 833 observer->OnCryptoHandshakeConfirmed(); |
| 822 } | 834 } |
| 823 if (server_info_) | 835 if (server_info_) |
| 824 server_info_->OnExternalCacheHit(); | 836 server_info_->OnExternalCacheHit(); |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 id, promised_id)); | 1385 id, promised_id)); |
| 1374 } | 1386 } |
| 1375 | 1387 |
| 1376 void QuicChromiumClientSession::DeletePromised( | 1388 void QuicChromiumClientSession::DeletePromised( |
| 1377 QuicClientPromisedInfo* promised) { | 1389 QuicClientPromisedInfo* promised) { |
| 1378 if (IsOpenStream(promised->id())) | 1390 if (IsOpenStream(promised->id())) |
| 1379 streams_pushed_and_claimed_count_++; | 1391 streams_pushed_and_claimed_count_++; |
| 1380 QuicClientSessionBase::DeletePromised(promised); | 1392 QuicClientSessionBase::DeletePromised(promised); |
| 1381 } | 1393 } |
| 1382 | 1394 |
| 1395 const LoadTimingInfo::ConnectTiming& |
| 1396 QuicChromiumClientSession::GetConnectTiming() { |
| 1397 connect_timing_.ssl_start = connect_timing_.connect_start; |
| 1398 connect_timing_.ssl_end = connect_timing_.connect_end; |
| 1399 return connect_timing_; |
| 1400 } |
| 1401 |
| 1383 } // namespace net | 1402 } // namespace net |
| OLD | NEW |