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" |
11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/metrics/sparse_histogram.h" | |
14 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
19 #include "net/cert/cert_verifier.h" | 20 #include "net/cert/cert_verifier.h" |
20 #include "net/dns/host_resolver.h" | 21 #include "net/dns/host_resolver.h" |
21 #include "net/dns/single_request_host_resolver.h" | 22 #include "net/dns/single_request_host_resolver.h" |
22 #include "net/http/http_server_properties.h" | 23 #include "net/http/http_server_properties.h" |
23 #include "net/quic/crypto/channel_id_chromium.h" | 24 #include "net/quic/crypto/channel_id_chromium.h" |
(...skipping 508 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 max_number_of_lossy_connections, | |
544 float 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 max_number_of_lossy_connections_(max_number_of_lossy_connections), | |
569 packet_loss_threshold_(packet_loss_threshold), | |
565 socket_receive_buffer_size_(socket_receive_buffer_size), | 570 socket_receive_buffer_size_(socket_receive_buffer_size), |
566 port_seed_(random_generator_->RandUint64()), | 571 port_seed_(random_generator_->RandUint64()), |
567 check_persisted_supports_quic_(true), | 572 check_persisted_supports_quic_(true), |
568 task_runner_(nullptr), | 573 task_runner_(nullptr), |
569 weak_factory_(this) { | 574 weak_factory_(this) { |
570 DCHECK(transport_security_state_); | 575 DCHECK(transport_security_state_); |
571 crypto_config_.set_user_agent_id(user_agent_id); | 576 crypto_config_.set_user_agent_id(user_agent_id); |
572 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); | 577 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); |
573 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); | 578 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); |
574 crypto_config_.SetProofVerifier( | 579 crypto_config_.SetProofVerifier( |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 DVLOG(1) << "No active session"; | 760 DVLOG(1) << "No active session"; |
756 return scoped_ptr<QuicHttpStream>(); | 761 return scoped_ptr<QuicHttpStream>(); |
757 } | 762 } |
758 | 763 |
759 QuicClientSession* session = active_sessions_[server_id]; | 764 QuicClientSession* session = active_sessions_[server_id]; |
760 DCHECK(session); | 765 DCHECK(session); |
761 return scoped_ptr<QuicHttpStream>( | 766 return scoped_ptr<QuicHttpStream>( |
762 new QuicHttpStream(session->GetWeakPtr())); | 767 new QuicHttpStream(session->GetWeakPtr())); |
763 } | 768 } |
764 | 769 |
770 bool QuicStreamFactory::IsQuicDisabled(uint16 port) { | |
771 return number_of_lossy_connections_[port] > max_number_of_lossy_connections_; | |
772 } | |
773 | |
774 bool QuicStreamFactory::OnBadPacketLoss(QuicClientSession* session, | |
775 const QuicServerId& server_id, | |
776 float packet_loss_rate) { | |
777 if (packet_loss_rate < packet_loss_threshold_) | |
778 return false; | |
779 | |
780 uint16 port = server_id.port(); | |
781 | |
782 if (http_server_properties_) { | |
783 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | |
Ryan Hamilton
2015/03/24 03:43:00
Can you add a comment which explains that this dis
ramant (doing other things)
2015/03/24 17:19:23
Done.
| |
784 AlternativeService(QUIC, server_id.host(), port)); | |
785 } | |
786 | |
787 // We abandon the connection if packet loss rate is too bad. | |
788 DCHECK(session); | |
789 session->CloseSessionOnError(ERR_ABORTED, QUIC_BAD_PACKET_LOSS_RATE); | |
790 | |
791 if (IsQuicDisabled(port)) | |
792 return true; // Exit if Quic is already disabled for this port. | |
793 | |
794 if (++number_of_lossy_connections_[port] > max_number_of_lossy_connections_) { | |
795 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicStreamFactory.QuicIsDisabled", port, 0, | |
796 1024, 1025); | |
797 } | |
798 | |
799 return true; | |
800 } | |
801 | |
765 void QuicStreamFactory::OnIdleSession(QuicClientSession* session) { | 802 void QuicStreamFactory::OnIdleSession(QuicClientSession* session) { |
766 } | 803 } |
767 | 804 |
768 void QuicStreamFactory::OnSessionGoingAway(QuicClientSession* session) { | 805 void QuicStreamFactory::OnSessionGoingAway(QuicClientSession* session) { |
769 const AliasSet& aliases = session_aliases_[session]; | 806 const AliasSet& aliases = session_aliases_[session]; |
770 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); | 807 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); |
771 ++it) { | 808 ++it) { |
772 DCHECK(active_sessions_.count(*it)); | 809 DCHECK(active_sessions_.count(*it)); |
773 DCHECK_EQ(session, active_sessions_[*it]); | 810 DCHECK_EQ(session, active_sessions_[*it]); |
774 // Track sessions which have recently gone away so that we can disable | 811 // Track sessions which have recently gone away so that we can disable |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
831 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { | 868 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { |
832 DCHECK(ContainsKey(active_requests_, request)); | 869 DCHECK(ContainsKey(active_requests_, request)); |
833 QuicServerId server_id = active_requests_[request]; | 870 QuicServerId server_id = active_requests_[request]; |
834 job_requests_map_[server_id].erase(request); | 871 job_requests_map_[server_id].erase(request); |
835 active_requests_.erase(request); | 872 active_requests_.erase(request); |
836 } | 873 } |
837 | 874 |
838 void QuicStreamFactory::CloseAllSessions(int error) { | 875 void QuicStreamFactory::CloseAllSessions(int error) { |
839 while (!active_sessions_.empty()) { | 876 while (!active_sessions_.empty()) { |
840 size_t initial_size = active_sessions_.size(); | 877 size_t initial_size = active_sessions_.size(); |
841 active_sessions_.begin()->second->CloseSessionOnError(error); | 878 active_sessions_.begin()->second->CloseSessionOnError(error, |
879 QUIC_INTERNAL_ERROR); | |
842 DCHECK_NE(initial_size, active_sessions_.size()); | 880 DCHECK_NE(initial_size, active_sessions_.size()); |
843 } | 881 } |
844 while (!all_sessions_.empty()) { | 882 while (!all_sessions_.empty()) { |
845 size_t initial_size = all_sessions_.size(); | 883 size_t initial_size = all_sessions_.size(); |
846 all_sessions_.begin()->first->CloseSessionOnError(error); | 884 all_sessions_.begin()->first->CloseSessionOnError(error, |
885 QUIC_INTERNAL_ERROR); | |
847 DCHECK_NE(initial_size, all_sessions_.size()); | 886 DCHECK_NE(initial_size, all_sessions_.size()); |
848 } | 887 } |
849 DCHECK(all_sessions_.empty()); | 888 DCHECK(all_sessions_.empty()); |
850 } | 889 } |
851 | 890 |
852 base::Value* QuicStreamFactory::QuicStreamFactoryInfoToValue() const { | 891 base::Value* QuicStreamFactory::QuicStreamFactoryInfoToValue() const { |
853 base::ListValue* list = new base::ListValue(); | 892 base::ListValue* list = new base::ListValue(); |
854 | 893 |
855 for (SessionMap::const_iterator it = active_sessions_.begin(); | 894 for (SessionMap::const_iterator it = active_sessions_.begin(); |
856 it != active_sessions_.end(); ++it) { | 895 it != active_sessions_.end(); ++it) { |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1160 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1199 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
1161 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1200 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
1162 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1201 // it as recently broken, which means that 0-RTT will be disabled but we'll |
1163 // still race. | 1202 // still race. |
1164 const HostPortPair& server = server_id.host_port_pair(); | 1203 const HostPortPair& server = server_id.host_port_pair(); |
1165 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1204 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
1166 AlternativeService(QUIC, server.host(), server.port())); | 1205 AlternativeService(QUIC, server.host(), server.port())); |
1167 } | 1206 } |
1168 | 1207 |
1169 } // namespace net | 1208 } // namespace net |
OLD | NEW |