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_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/cpu.h" | 9 #include "base/cpu.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 | 429 |
430 if (!session_->connection()->connected()) { | 430 if (!session_->connection()->connected()) { |
431 return ERR_CONNECTION_CLOSED; | 431 return ERR_CONNECTION_CLOSED; |
432 } | 432 } |
433 | 433 |
434 session_->StartReading(); | 434 session_->StartReading(); |
435 if (!session_->connection()->connected()) { | 435 if (!session_->connection()->connected()) { |
436 return ERR_QUIC_PROTOCOL_ERROR; | 436 return ERR_QUIC_PROTOCOL_ERROR; |
437 } | 437 } |
438 bool require_confirmation = | 438 bool require_confirmation = |
439 factory_->require_confirmation() || is_post_ || | 439 factory_->require_confirmation() || |
| 440 is_post_ || |
440 was_alternate_protocol_recently_broken_; | 441 was_alternate_protocol_recently_broken_; |
441 | 442 |
442 rv = session_->CryptoConnect( | 443 rv = session_->CryptoConnect( |
443 require_confirmation, | 444 require_confirmation, |
444 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); | 445 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); |
445 return rv; | 446 return rv; |
446 } | 447 } |
447 | 448 |
448 int QuicStreamFactory::Job::DoResumeConnect() { | 449 int QuicStreamFactory::Job::DoResumeConnect() { |
449 io_state_ = STATE_CONNECT_COMPLETE; | 450 io_state_ = STATE_CONNECT_COMPLETE; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 size_t max_packet_length, | 533 size_t max_packet_length, |
533 const std::string& user_agent_id, | 534 const std::string& user_agent_id, |
534 const QuicVersionVector& supported_versions, | 535 const QuicVersionVector& supported_versions, |
535 bool enable_port_selection, | 536 bool enable_port_selection, |
536 bool always_require_handshake_confirmation, | 537 bool always_require_handshake_confirmation, |
537 bool disable_connection_pooling, | 538 bool disable_connection_pooling, |
538 float load_server_info_timeout_srtt_multiplier, | 539 float load_server_info_timeout_srtt_multiplier, |
539 bool enable_connection_racing, | 540 bool enable_connection_racing, |
540 bool enable_non_blocking_io, | 541 bool enable_non_blocking_io, |
541 bool disable_disk_cache, | 542 bool disable_disk_cache, |
| 543 int number_of_lossy_handshakes, |
| 544 int packet_loss_threshold, |
542 int socket_receive_buffer_size, | 545 int socket_receive_buffer_size, |
543 const QuicTagVector& connection_options) | 546 const QuicTagVector& connection_options) |
544 : require_confirmation_(true), | 547 : require_confirmation_(true), |
545 host_resolver_(host_resolver), | 548 host_resolver_(host_resolver), |
546 client_socket_factory_(client_socket_factory), | 549 client_socket_factory_(client_socket_factory), |
547 http_server_properties_(http_server_properties), | 550 http_server_properties_(http_server_properties), |
548 transport_security_state_(transport_security_state), | 551 transport_security_state_(transport_security_state), |
549 quic_server_info_factory_(nullptr), | 552 quic_server_info_factory_(nullptr), |
550 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), | 553 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), |
551 random_generator_(random_generator), | 554 random_generator_(random_generator), |
552 clock_(clock), | 555 clock_(clock), |
553 max_packet_length_(max_packet_length), | 556 max_packet_length_(max_packet_length), |
554 config_(InitializeQuicConfig(connection_options)), | 557 config_(InitializeQuicConfig(connection_options)), |
555 supported_versions_(supported_versions), | 558 supported_versions_(supported_versions), |
556 enable_port_selection_(enable_port_selection), | 559 enable_port_selection_(enable_port_selection), |
557 always_require_handshake_confirmation_( | 560 always_require_handshake_confirmation_( |
558 always_require_handshake_confirmation), | 561 always_require_handshake_confirmation), |
559 disable_connection_pooling_(disable_connection_pooling), | 562 disable_connection_pooling_(disable_connection_pooling), |
560 load_server_info_timeout_srtt_multiplier_( | 563 load_server_info_timeout_srtt_multiplier_( |
561 load_server_info_timeout_srtt_multiplier), | 564 load_server_info_timeout_srtt_multiplier), |
562 enable_connection_racing_(enable_connection_racing), | 565 enable_connection_racing_(enable_connection_racing), |
563 enable_non_blocking_io_(enable_non_blocking_io), | 566 enable_non_blocking_io_(enable_non_blocking_io), |
564 disable_disk_cache_(disable_disk_cache), | 567 disable_disk_cache_(disable_disk_cache), |
| 568 number_of_lossy_handshakes_(number_of_lossy_handshakes), |
| 569 packet_loss_threshold_(packet_loss_threshold), |
| 570 disable_zero_rtt_(number_of_lossy_handshakes_ > 0 && |
| 571 packet_loss_threshold_ > 0), |
565 socket_receive_buffer_size_(socket_receive_buffer_size), | 572 socket_receive_buffer_size_(socket_receive_buffer_size), |
566 port_seed_(random_generator_->RandUint64()), | 573 port_seed_(random_generator_->RandUint64()), |
567 check_persisted_supports_quic_(true), | 574 check_persisted_supports_quic_(true), |
568 task_runner_(nullptr), | 575 task_runner_(nullptr), |
569 weak_factory_(this) { | 576 weak_factory_(this) { |
570 DCHECK(transport_security_state_); | 577 DCHECK(transport_security_state_); |
571 crypto_config_.set_user_agent_id(user_agent_id); | 578 crypto_config_.set_user_agent_id(user_agent_id); |
572 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); | 579 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); |
573 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); | 580 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); |
574 crypto_config_.SetProofVerifier( | 581 crypto_config_.SetProofVerifier( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 return ERR_IO_PENDING; | 628 return ERR_IO_PENDING; |
622 } | 629 } |
623 | 630 |
624 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_ | 631 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_ |
625 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed. | 632 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed. |
626 if (!task_runner_) | 633 if (!task_runner_) |
627 task_runner_ = base::MessageLoop::current()->message_loop_proxy().get(); | 634 task_runner_ = base::MessageLoop::current()->message_loop_proxy().get(); |
628 | 635 |
629 QuicServerInfo* quic_server_info = nullptr; | 636 QuicServerInfo* quic_server_info = nullptr; |
630 if (quic_server_info_factory_) { | 637 if (quic_server_info_factory_) { |
631 bool load_from_disk_cache = !disable_disk_cache_; | 638 bool load_from_disk_cache = !disable_disk_cache_ || !disable_zero_rtt_; |
632 if (http_server_properties_) { | 639 if (http_server_properties_) { |
633 const AlternateProtocolMap& alternate_protocol_map = | 640 const AlternateProtocolMap& alternate_protocol_map = |
634 http_server_properties_->alternate_protocol_map(); | 641 http_server_properties_->alternate_protocol_map(); |
635 AlternateProtocolMap::const_iterator it = | 642 AlternateProtocolMap::const_iterator it = |
636 alternate_protocol_map.Peek(server_id.host_port_pair()); | 643 alternate_protocol_map.Peek(server_id.host_port_pair()); |
637 if (it == alternate_protocol_map.end() || it->second.protocol != QUIC) { | 644 if (it == alternate_protocol_map.end() || it->second.protocol != QUIC) { |
638 // If there is no entry for QUIC, consider that as a new server and | 645 // If there is no entry for QUIC, consider that as a new server and |
639 // don't wait for Cache thread to load the data for that server. | 646 // don't wait for Cache thread to load the data for that server. |
640 load_from_disk_cache = false; | 647 load_from_disk_cache = false; |
641 } | 648 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 DVLOG(1) << "No active session"; | 763 DVLOG(1) << "No active session"; |
757 return scoped_ptr<QuicHttpStream>(); | 764 return scoped_ptr<QuicHttpStream>(); |
758 } | 765 } |
759 | 766 |
760 QuicClientSession* session = active_sessions_[server_id]; | 767 QuicClientSession* session = active_sessions_[server_id]; |
761 DCHECK(session); | 768 DCHECK(session); |
762 return scoped_ptr<QuicHttpStream>( | 769 return scoped_ptr<QuicHttpStream>( |
763 new QuicHttpStream(session->GetWeakPtr())); | 770 new QuicHttpStream(session->GetWeakPtr())); |
764 } | 771 } |
765 | 772 |
| 773 QuicErrorCode QuicStreamFactory::OnCryptoHandshakeCompleted( |
| 774 QuicClientSession* session, |
| 775 const QuicServerId& server_id, |
| 776 int number_of_handshakes) { |
| 777 DCHECK_LT(0, number_of_handshakes); |
| 778 if (number_of_handshakes != number_of_lossy_handshakes_) |
| 779 return QUIC_NO_ERROR; |
| 780 |
| 781 bool bad_packet_loss_rate = |
| 782 (session->PacketLossRate() / 10) > packet_loss_threshold_; |
| 783 |
| 784 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.HasBadPacketLossRate", |
| 785 bad_packet_loss_rate); |
| 786 |
| 787 // It is not bad packet loss rate, enable 0-RTT. |
| 788 if (!bad_packet_loss_rate) { |
| 789 disable_zero_rtt_ = false; |
| 790 return QUIC_NO_ERROR; |
| 791 } |
| 792 |
| 793 HistogramBrokenAlternateProtocolLocation( |
| 794 BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY); |
| 795 |
| 796 const HostPortPair& server = server_id.host_port_pair(); |
| 797 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
| 798 AlternativeService(QUIC, server.host(), server.port())); |
| 799 // TODO(rtenneti): Should we close the connection? |
| 800 return QUIC_BAD_PACKET_LOSS_RATE; |
| 801 } |
| 802 |
766 void QuicStreamFactory::OnIdleSession(QuicClientSession* session) { | 803 void QuicStreamFactory::OnIdleSession(QuicClientSession* session) { |
767 } | 804 } |
768 | 805 |
769 void QuicStreamFactory::OnSessionGoingAway(QuicClientSession* session) { | 806 void QuicStreamFactory::OnSessionGoingAway(QuicClientSession* session) { |
770 const AliasSet& aliases = session_aliases_[session]; | 807 const AliasSet& aliases = session_aliases_[session]; |
771 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); | 808 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); |
772 ++it) { | 809 ++it) { |
773 DCHECK(active_sessions_.count(*it)); | 810 DCHECK(active_sessions_.count(*it)); |
774 DCHECK_EQ(session, active_sessions_[*it]); | 811 DCHECK_EQ(session, active_sessions_[*it]); |
775 // Track sessions which have recently gone away so that we can disable | 812 // Track sessions which have recently gone away so that we can disable |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1195 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
1159 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1196 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
1160 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1197 // it as recently broken, which means that 0-RTT will be disabled but we'll |
1161 // still race. | 1198 // still race. |
1162 const HostPortPair& server = server_id.host_port_pair(); | 1199 const HostPortPair& server = server_id.host_port_pair(); |
1163 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1200 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
1164 AlternativeService(QUIC, server.host(), server.port())); | 1201 AlternativeService(QUIC, server.host(), server.port())); |
1165 } | 1202 } |
1166 | 1203 |
1167 } // namespace net | 1204 } // namespace net |
OLD | NEW |