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 max_number_of_lossy_connections_ > 0 && | |
772 number_of_lossy_connections_[port] >= max_number_of_lossy_connections_; | |
773 } | |
774 | |
775 bool QuicStreamFactory::OnHandshakeConfirmed(QuicClientSession* session, | |
776 float packet_loss_rate) { | |
777 DCHECK(session); | |
778 uint16 port = session->server_id().port(); | |
779 if (packet_loss_rate < packet_loss_threshold_) { | |
780 number_of_lossy_connections_[port] = 0; | |
781 return false; | |
782 } | |
783 | |
784 if (http_server_properties_) { | |
785 // We mark it as recently broken, which means that 0-RTT will be disabled | |
786 // but we'll still race. | |
787 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | |
788 AlternativeService(QUIC, session->server_id().host(), port)); | |
789 } | |
790 | |
791 // We abandon the connection if packet loss rate is too bad. | |
792 session->CloseSessionOnError(ERR_ABORTED, QUIC_BAD_PACKET_LOSS_RATE); | |
793 | |
794 if (IsQuicDisabled(port)) | |
795 return true; // Exit if Quic is already disabled for this port. | |
796 | |
797 if (++number_of_lossy_connections_[port] >= | |
798 max_number_of_lossy_connections_) { | |
799 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicStreamFactory.QuicIsDisabled", port, 0, | |
Mark P
2015/03/26 20:25:00
Also, is there any way to get the information you
ramant (doing other things)
2015/03/26 21:03:35
Good point. Changed it to UMA_HISTOGRAM_SPARSE_SLO
| |
800 1024, 1025); | |
801 } | |
802 | |
803 return true; | |
804 } | |
805 | |
765 void QuicStreamFactory::OnIdleSession(QuicClientSession* session) { | 806 void QuicStreamFactory::OnIdleSession(QuicClientSession* session) { |
766 } | 807 } |
767 | 808 |
768 void QuicStreamFactory::OnSessionGoingAway(QuicClientSession* session) { | 809 void QuicStreamFactory::OnSessionGoingAway(QuicClientSession* session) { |
769 const AliasSet& aliases = session_aliases_[session]; | 810 const AliasSet& aliases = session_aliases_[session]; |
770 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); | 811 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); |
771 ++it) { | 812 ++it) { |
772 DCHECK(active_sessions_.count(*it)); | 813 DCHECK(active_sessions_.count(*it)); |
773 DCHECK_EQ(session, active_sessions_[*it]); | 814 DCHECK_EQ(session, active_sessions_[*it]); |
774 // Track sessions which have recently gone away so that we can disable | 815 // 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) { | 872 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { |
832 DCHECK(ContainsKey(active_requests_, request)); | 873 DCHECK(ContainsKey(active_requests_, request)); |
833 QuicServerId server_id = active_requests_[request]; | 874 QuicServerId server_id = active_requests_[request]; |
834 job_requests_map_[server_id].erase(request); | 875 job_requests_map_[server_id].erase(request); |
835 active_requests_.erase(request); | 876 active_requests_.erase(request); |
836 } | 877 } |
837 | 878 |
838 void QuicStreamFactory::CloseAllSessions(int error) { | 879 void QuicStreamFactory::CloseAllSessions(int error) { |
839 while (!active_sessions_.empty()) { | 880 while (!active_sessions_.empty()) { |
840 size_t initial_size = active_sessions_.size(); | 881 size_t initial_size = active_sessions_.size(); |
841 active_sessions_.begin()->second->CloseSessionOnError(error); | 882 active_sessions_.begin()->second->CloseSessionOnError(error, |
883 QUIC_INTERNAL_ERROR); | |
842 DCHECK_NE(initial_size, active_sessions_.size()); | 884 DCHECK_NE(initial_size, active_sessions_.size()); |
843 } | 885 } |
844 while (!all_sessions_.empty()) { | 886 while (!all_sessions_.empty()) { |
845 size_t initial_size = all_sessions_.size(); | 887 size_t initial_size = all_sessions_.size(); |
846 all_sessions_.begin()->first->CloseSessionOnError(error); | 888 all_sessions_.begin()->first->CloseSessionOnError(error, |
889 QUIC_INTERNAL_ERROR); | |
847 DCHECK_NE(initial_size, all_sessions_.size()); | 890 DCHECK_NE(initial_size, all_sessions_.size()); |
848 } | 891 } |
849 DCHECK(all_sessions_.empty()); | 892 DCHECK(all_sessions_.empty()); |
850 } | 893 } |
851 | 894 |
852 base::Value* QuicStreamFactory::QuicStreamFactoryInfoToValue() const { | 895 base::Value* QuicStreamFactory::QuicStreamFactoryInfoToValue() const { |
853 base::ListValue* list = new base::ListValue(); | 896 base::ListValue* list = new base::ListValue(); |
854 | 897 |
855 for (SessionMap::const_iterator it = active_sessions_.begin(); | 898 for (SessionMap::const_iterator it = active_sessions_.begin(); |
856 it != active_sessions_.end(); ++it) { | 899 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 | 1203 // 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 | 1204 // 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 | 1205 // it as recently broken, which means that 0-RTT will be disabled but we'll |
1163 // still race. | 1206 // still race. |
1164 const HostPortPair& server = server_id.host_port_pair(); | 1207 const HostPortPair& server = server_id.host_port_pair(); |
1165 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1208 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
1166 AlternativeService(QUIC, server.host(), server.port())); | 1209 AlternativeService(QUIC, server.host(), server.port())); |
1167 } | 1210 } |
1168 | 1211 |
1169 } // namespace net | 1212 } // namespace net |
OLD | NEW |