| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 bool enable_port_selection, | 563 bool enable_port_selection, |
| 564 bool always_require_handshake_confirmation, | 564 bool always_require_handshake_confirmation, |
| 565 bool disable_connection_pooling, | 565 bool disable_connection_pooling, |
| 566 float load_server_info_timeout_srtt_multiplier, | 566 float load_server_info_timeout_srtt_multiplier, |
| 567 bool enable_connection_racing, | 567 bool enable_connection_racing, |
| 568 bool enable_non_blocking_io, | 568 bool enable_non_blocking_io, |
| 569 bool disable_disk_cache, | 569 bool disable_disk_cache, |
| 570 bool prefer_aes, | 570 bool prefer_aes, |
| 571 int max_number_of_lossy_connections, | 571 int max_number_of_lossy_connections, |
| 572 float packet_loss_threshold, | 572 float packet_loss_threshold, |
| 573 int max_disabled_reasons, |
| 574 int threshold_public_resets_post_handshake, |
| 575 int threshold_timeouts_with_open_streams, |
| 573 int socket_receive_buffer_size, | 576 int socket_receive_buffer_size, |
| 574 const QuicTagVector& connection_options) | 577 const QuicTagVector& connection_options) |
| 575 : require_confirmation_(true), | 578 : require_confirmation_(true), |
| 576 host_resolver_(host_resolver), | 579 host_resolver_(host_resolver), |
| 577 client_socket_factory_(client_socket_factory), | 580 client_socket_factory_(client_socket_factory), |
| 578 http_server_properties_(http_server_properties), | 581 http_server_properties_(http_server_properties), |
| 579 transport_security_state_(transport_security_state), | 582 transport_security_state_(transport_security_state), |
| 580 quic_server_info_factory_(nullptr), | 583 quic_server_info_factory_(nullptr), |
| 581 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), | 584 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), |
| 582 random_generator_(random_generator), | 585 random_generator_(random_generator), |
| 583 clock_(clock), | 586 clock_(clock), |
| 584 max_packet_length_(max_packet_length), | 587 max_packet_length_(max_packet_length), |
| 585 config_(InitializeQuicConfig(connection_options)), | 588 config_(InitializeQuicConfig(connection_options)), |
| 586 supported_versions_(supported_versions), | 589 supported_versions_(supported_versions), |
| 587 enable_port_selection_(enable_port_selection), | 590 enable_port_selection_(enable_port_selection), |
| 588 always_require_handshake_confirmation_( | 591 always_require_handshake_confirmation_( |
| 589 always_require_handshake_confirmation), | 592 always_require_handshake_confirmation), |
| 590 disable_connection_pooling_(disable_connection_pooling), | 593 disable_connection_pooling_(disable_connection_pooling), |
| 591 load_server_info_timeout_srtt_multiplier_( | 594 load_server_info_timeout_srtt_multiplier_( |
| 592 load_server_info_timeout_srtt_multiplier), | 595 load_server_info_timeout_srtt_multiplier), |
| 593 enable_connection_racing_(enable_connection_racing), | 596 enable_connection_racing_(enable_connection_racing), |
| 594 enable_non_blocking_io_(enable_non_blocking_io), | 597 enable_non_blocking_io_(enable_non_blocking_io), |
| 595 disable_disk_cache_(disable_disk_cache), | 598 disable_disk_cache_(disable_disk_cache), |
| 596 prefer_aes_(prefer_aes), | 599 prefer_aes_(prefer_aes), |
| 597 max_number_of_lossy_connections_(max_number_of_lossy_connections), | 600 max_number_of_lossy_connections_(max_number_of_lossy_connections), |
| 598 packet_loss_threshold_(packet_loss_threshold), | 601 packet_loss_threshold_(packet_loss_threshold), |
| 602 max_disabled_reasons_(max_disabled_reasons), |
| 603 num_public_resets_post_handshake_(0), |
| 604 num_timeouts_with_open_streams_(0), |
| 605 max_public_resets_post_handshake_(0), |
| 606 max_timeouts_with_open_streams_(0), |
| 607 threshold_timeouts_with_open_streams_( |
| 608 threshold_timeouts_with_open_streams), |
| 609 threshold_public_resets_post_handshake_( |
| 610 threshold_public_resets_post_handshake), |
| 599 socket_receive_buffer_size_(socket_receive_buffer_size), | 611 socket_receive_buffer_size_(socket_receive_buffer_size), |
| 600 port_seed_(random_generator_->RandUint64()), | 612 port_seed_(random_generator_->RandUint64()), |
| 601 check_persisted_supports_quic_(true), | 613 check_persisted_supports_quic_(true), |
| 602 task_runner_(nullptr), | 614 task_runner_(nullptr), |
| 603 weak_factory_(this) { | 615 weak_factory_(this) { |
| 604 DCHECK(transport_security_state_); | 616 DCHECK(transport_security_state_); |
| 605 crypto_config_.set_user_agent_id(user_agent_id); | 617 crypto_config_.set_user_agent_id(user_agent_id); |
| 606 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); | 618 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); |
| 607 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); | 619 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); |
| 608 crypto_config_.AddCanonicalSuffix(".googleusercontent.com"); | 620 crypto_config_.AddCanonicalSuffix(".googleusercontent.com"); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 STLDeleteElements(&(active_jobs_[server_id])); | 835 STLDeleteElements(&(active_jobs_[server_id])); |
| 824 active_jobs_.erase(server_id); | 836 active_jobs_.erase(server_id); |
| 825 job_requests_map_.erase(server_id); | 837 job_requests_map_.erase(server_id); |
| 826 } | 838 } |
| 827 | 839 |
| 828 scoped_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( | 840 scoped_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( |
| 829 QuicClientSession* session) { | 841 QuicClientSession* session) { |
| 830 return scoped_ptr<QuicHttpStream>(new QuicHttpStream(session->GetWeakPtr())); | 842 return scoped_ptr<QuicHttpStream>(new QuicHttpStream(session->GetWeakPtr())); |
| 831 } | 843 } |
| 832 | 844 |
| 845 QuicClientSession::QuicDisabledReason QuicStreamFactory::QuicDisabledReason( |
| 846 uint16 port) const { |
| 847 if (max_number_of_lossy_connections_ > 0 && |
| 848 number_of_lossy_connections_.find(port) != |
| 849 number_of_lossy_connections_.end() && |
| 850 number_of_lossy_connections_.at(port) >= |
| 851 max_number_of_lossy_connections_) { |
| 852 return QuicClientSession::QUIC_DISABLED_BAD_PACKET_LOSS_RATE; |
| 853 } |
| 854 if (threshold_public_resets_post_handshake_ > 0 && |
| 855 num_public_resets_post_handshake_ >= |
| 856 threshold_public_resets_post_handshake_) { |
| 857 return QuicClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE; |
| 858 } |
| 859 if (threshold_timeouts_with_open_streams_ > 0 && |
| 860 num_timeouts_with_open_streams_ >= |
| 861 threshold_timeouts_with_open_streams_) { |
| 862 return QuicClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS; |
| 863 } |
| 864 return QuicClientSession::QUIC_DISABLED_NOT; |
| 865 } |
| 866 |
| 867 const char* QuicStreamFactory::QuicDisabledReasonString() const { |
| 868 // TODO(ckrasic) - better solution for port/lossy connections? |
| 869 const uint16 port = 443; |
| 870 switch (QuicDisabledReason(port)) { |
| 871 case QuicClientSession::QUIC_DISABLED_BAD_PACKET_LOSS_RATE: |
| 872 return "Bad packet loss rate."; |
| 873 case QuicClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE: |
| 874 return "Public resets after successful handshakes."; |
| 875 case QuicClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS: |
| 876 return "Connection timeouts with streams open."; |
| 877 default: |
| 878 return ""; |
| 879 } |
| 880 } |
| 881 |
| 833 bool QuicStreamFactory::IsQuicDisabled(uint16 port) { | 882 bool QuicStreamFactory::IsQuicDisabled(uint16 port) { |
| 834 return max_number_of_lossy_connections_ > 0 && | 883 return QuicDisabledReason(port) != QuicClientSession::QUIC_DISABLED_NOT; |
| 835 number_of_lossy_connections_[port] >= max_number_of_lossy_connections_; | |
| 836 } | 884 } |
| 837 | 885 |
| 838 bool QuicStreamFactory::OnHandshakeConfirmed(QuicClientSession* session, | 886 bool QuicStreamFactory::OnHandshakeConfirmed(QuicClientSession* session, |
| 839 float packet_loss_rate) { | 887 float packet_loss_rate) { |
| 840 DCHECK(session); | 888 DCHECK(session); |
| 841 uint16 port = session->server_id().port(); | 889 uint16 port = session->server_id().port(); |
| 842 if (packet_loss_rate < packet_loss_threshold_) { | 890 if (packet_loss_rate < packet_loss_threshold_) { |
| 843 number_of_lossy_connections_[port] = 0; | 891 number_of_lossy_connections_[port] = 0; |
| 844 return false; | 892 return false; |
| 845 } | 893 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 const IpAliasKey ip_alias_key(session->connection()->peer_address(), | 947 const IpAliasKey ip_alias_key(session->connection()->peer_address(), |
| 900 aliases.begin()->is_https()); | 948 aliases.begin()->is_https()); |
| 901 ip_aliases_[ip_alias_key].erase(session); | 949 ip_aliases_[ip_alias_key].erase(session); |
| 902 if (ip_aliases_[ip_alias_key].empty()) { | 950 if (ip_aliases_[ip_alias_key].empty()) { |
| 903 ip_aliases_.erase(ip_alias_key); | 951 ip_aliases_.erase(ip_alias_key); |
| 904 } | 952 } |
| 905 } | 953 } |
| 906 session_aliases_.erase(session); | 954 session_aliases_.erase(session); |
| 907 } | 955 } |
| 908 | 956 |
| 957 void QuicStreamFactory::MaybeDisableQuic(QuicClientSession* session) { |
| 958 DCHECK(session); |
| 959 uint16 port = session->server_id().port(); |
| 960 if (IsQuicDisabled(port)) |
| 961 return; |
| 962 |
| 963 // Expire the oldest disabled_reason if appropriate. This enforces that we |
| 964 // only consider the max_disabled_reasons_ most recent sessions. |
| 965 QuicClientSession::QuicDisabledReason disabled_reason; |
| 966 if (static_cast<int>(disabled_reasons_.size()) == max_disabled_reasons_) { |
| 967 disabled_reason = disabled_reasons_.front(); |
| 968 disabled_reasons_.pop_front(); |
| 969 if (disabled_reason == |
| 970 QuicClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE) { |
| 971 --num_public_resets_post_handshake_; |
| 972 } else if (disabled_reason == |
| 973 QuicClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS) { |
| 974 --num_timeouts_with_open_streams_; |
| 975 } |
| 976 } |
| 977 disabled_reason = session->disabled_reason(); |
| 978 disabled_reasons_.push_back(disabled_reason); |
| 979 if (disabled_reason == |
| 980 QuicClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE) { |
| 981 ++num_public_resets_post_handshake_; |
| 982 } else if (disabled_reason == |
| 983 QuicClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS) { |
| 984 ++num_timeouts_with_open_streams_; |
| 985 } |
| 986 if (num_timeouts_with_open_streams_ > max_timeouts_with_open_streams_) { |
| 987 max_timeouts_with_open_streams_ = num_timeouts_with_open_streams_; |
| 988 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicStreamFactory.TimeoutsWithOpenStreams", |
| 989 num_timeouts_with_open_streams_, 0, 20, 10); |
| 990 } |
| 991 |
| 992 if (num_public_resets_post_handshake_ > max_public_resets_post_handshake_) { |
| 993 max_public_resets_post_handshake_ = num_public_resets_post_handshake_; |
| 994 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 995 "Net.QuicStreamFactory.PublicResetsPostHandshake", |
| 996 num_public_resets_post_handshake_, 0, 20, 10); |
| 997 } |
| 998 |
| 999 if (IsQuicDisabled(port)) { |
| 1000 if (disabled_reason == |
| 1001 QuicClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE) { |
| 1002 session->CloseSessionOnErrorAndNotifyFactoryLater( |
| 1003 ERR_ABORTED, QUIC_PUBLIC_RESETS_POST_HANDSHAKE); |
| 1004 } else if (disabled_reason == |
| 1005 QuicClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS) { |
| 1006 session->CloseSessionOnErrorAndNotifyFactoryLater( |
| 1007 ERR_ABORTED, QUIC_TIMEOUTS_WITH_OPEN_STREAMS); |
| 1008 } |
| 1009 UMA_HISTOGRAM_ENUMERATION("Net.QuicStreamFactory.DisabledReasons", |
| 1010 disabled_reason, |
| 1011 QuicClientSession::QUIC_DISABLED_MAX); |
| 1012 } |
| 1013 } |
| 1014 |
| 909 void QuicStreamFactory::OnSessionClosed(QuicClientSession* session) { | 1015 void QuicStreamFactory::OnSessionClosed(QuicClientSession* session) { |
| 910 DCHECK_EQ(0u, session->GetNumOpenStreams()); | 1016 DCHECK_EQ(0u, session->GetNumOpenStreams()); |
| 1017 MaybeDisableQuic(session); |
| 911 OnSessionGoingAway(session); | 1018 OnSessionGoingAway(session); |
| 912 delete session; | 1019 delete session; |
| 913 all_sessions_.erase(session); | 1020 all_sessions_.erase(session); |
| 914 } | 1021 } |
| 915 | 1022 |
| 916 void QuicStreamFactory::OnSessionConnectTimeout( | 1023 void QuicStreamFactory::OnSessionConnectTimeout( |
| 917 QuicClientSession* session) { | 1024 QuicClientSession* session) { |
| 918 const AliasSet& aliases = session_aliases_[session]; | 1025 const AliasSet& aliases = session_aliases_[session]; |
| 919 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); | 1026 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); |
| 920 ++it) { | 1027 ++it) { |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 // Since the session was active, there's no longer an | 1387 // Since the session was active, there's no longer an |
| 1281 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1388 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
| 1282 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1389 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
| 1283 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1390 // it as recently broken, which means that 0-RTT will be disabled but we'll |
| 1284 // still race. | 1391 // still race. |
| 1285 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1392 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
| 1286 alternative_service); | 1393 alternative_service); |
| 1287 } | 1394 } |
| 1288 | 1395 |
| 1289 } // namespace net | 1396 } // namespace net |
| OLD | NEW |