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