| 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_SPARSE_SLOWLY("Net.QuicStreamFactory.QuicIsDisabled", port); |
| 800 } |
| 801 |
| 802 return true; |
| 803 } |
| 804 |
| 765 void QuicStreamFactory::OnIdleSession(QuicClientSession* session) { | 805 void QuicStreamFactory::OnIdleSession(QuicClientSession* session) { |
| 766 } | 806 } |
| 767 | 807 |
| 768 void QuicStreamFactory::OnSessionGoingAway(QuicClientSession* session) { | 808 void QuicStreamFactory::OnSessionGoingAway(QuicClientSession* session) { |
| 769 const AliasSet& aliases = session_aliases_[session]; | 809 const AliasSet& aliases = session_aliases_[session]; |
| 770 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); | 810 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); |
| 771 ++it) { | 811 ++it) { |
| 772 DCHECK(active_sessions_.count(*it)); | 812 DCHECK(active_sessions_.count(*it)); |
| 773 DCHECK_EQ(session, active_sessions_[*it]); | 813 DCHECK_EQ(session, active_sessions_[*it]); |
| 774 // Track sessions which have recently gone away so that we can disable | 814 // 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) { | 871 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { |
| 832 DCHECK(ContainsKey(active_requests_, request)); | 872 DCHECK(ContainsKey(active_requests_, request)); |
| 833 QuicServerId server_id = active_requests_[request]; | 873 QuicServerId server_id = active_requests_[request]; |
| 834 job_requests_map_[server_id].erase(request); | 874 job_requests_map_[server_id].erase(request); |
| 835 active_requests_.erase(request); | 875 active_requests_.erase(request); |
| 836 } | 876 } |
| 837 | 877 |
| 838 void QuicStreamFactory::CloseAllSessions(int error) { | 878 void QuicStreamFactory::CloseAllSessions(int error) { |
| 839 while (!active_sessions_.empty()) { | 879 while (!active_sessions_.empty()) { |
| 840 size_t initial_size = active_sessions_.size(); | 880 size_t initial_size = active_sessions_.size(); |
| 841 active_sessions_.begin()->second->CloseSessionOnError(error); | 881 active_sessions_.begin()->second->CloseSessionOnError(error, |
| 882 QUIC_INTERNAL_ERROR); |
| 842 DCHECK_NE(initial_size, active_sessions_.size()); | 883 DCHECK_NE(initial_size, active_sessions_.size()); |
| 843 } | 884 } |
| 844 while (!all_sessions_.empty()) { | 885 while (!all_sessions_.empty()) { |
| 845 size_t initial_size = all_sessions_.size(); | 886 size_t initial_size = all_sessions_.size(); |
| 846 all_sessions_.begin()->first->CloseSessionOnError(error); | 887 all_sessions_.begin()->first->CloseSessionOnError(error, |
| 888 QUIC_INTERNAL_ERROR); |
| 847 DCHECK_NE(initial_size, all_sessions_.size()); | 889 DCHECK_NE(initial_size, all_sessions_.size()); |
| 848 } | 890 } |
| 849 DCHECK(all_sessions_.empty()); | 891 DCHECK(all_sessions_.empty()); |
| 850 } | 892 } |
| 851 | 893 |
| 852 base::Value* QuicStreamFactory::QuicStreamFactoryInfoToValue() const { | 894 base::Value* QuicStreamFactory::QuicStreamFactoryInfoToValue() const { |
| 853 base::ListValue* list = new base::ListValue(); | 895 base::ListValue* list = new base::ListValue(); |
| 854 | 896 |
| 855 for (SessionMap::const_iterator it = active_sessions_.begin(); | 897 for (SessionMap::const_iterator it = active_sessions_.begin(); |
| 856 it != active_sessions_.end(); ++it) { | 898 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 | 1202 // 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 | 1203 // 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 | 1204 // it as recently broken, which means that 0-RTT will be disabled but we'll |
| 1163 // still race. | 1205 // still race. |
| 1164 const HostPortPair& server = server_id.host_port_pair(); | 1206 const HostPortPair& server = server_id.host_port_pair(); |
| 1165 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1207 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
| 1166 AlternativeService(QUIC, server.host(), server.port())); | 1208 AlternativeService(QUIC, server.host(), server.port())); |
| 1167 } | 1209 } |
| 1168 | 1210 |
| 1169 } // namespace net | 1211 } // namespace net |
| OLD | NEW |