| 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/chromium/quic_stream_factory.h" | 5 #include "net/quic/chromium/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "net/cert/cert_verifier.h" | 28 #include "net/cert/cert_verifier.h" |
| 29 #include "net/cert/ct_verifier.h" | 29 #include "net/cert/ct_verifier.h" |
| 30 #include "net/dns/host_resolver.h" | 30 #include "net/dns/host_resolver.h" |
| 31 #include "net/http/bidirectional_stream_impl.h" | 31 #include "net/http/bidirectional_stream_impl.h" |
| 32 #include "net/log/net_log_capture_mode.h" | 32 #include "net/log/net_log_capture_mode.h" |
| 33 #include "net/log/net_log_event_type.h" | 33 #include "net/log/net_log_event_type.h" |
| 34 #include "net/log/net_log_source_type.h" | 34 #include "net/log/net_log_source_type.h" |
| 35 #include "net/quic/chromium/bidirectional_stream_quic_impl.h" | 35 #include "net/quic/chromium/bidirectional_stream_quic_impl.h" |
| 36 #include "net/quic/chromium/crypto/channel_id_chromium.h" | 36 #include "net/quic/chromium/crypto/channel_id_chromium.h" |
| 37 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" | 37 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" |
| 38 #include "net/quic/chromium/port_suggester.h" | |
| 39 #include "net/quic/chromium/quic_chromium_alarm_factory.h" | 38 #include "net/quic/chromium/quic_chromium_alarm_factory.h" |
| 40 #include "net/quic/chromium/quic_chromium_connection_helper.h" | 39 #include "net/quic/chromium/quic_chromium_connection_helper.h" |
| 41 #include "net/quic/chromium/quic_chromium_packet_reader.h" | 40 #include "net/quic/chromium/quic_chromium_packet_reader.h" |
| 42 #include "net/quic/chromium/quic_chromium_packet_writer.h" | 41 #include "net/quic/chromium/quic_chromium_packet_writer.h" |
| 43 #include "net/quic/core/crypto/proof_verifier.h" | 42 #include "net/quic/core/crypto/proof_verifier.h" |
| 44 #include "net/quic/core/crypto/properties_based_quic_server_info.h" | 43 #include "net/quic/core/crypto/properties_based_quic_server_info.h" |
| 45 #include "net/quic/core/crypto/quic_random.h" | 44 #include "net/quic/core/crypto/quic_random.h" |
| 46 #include "net/quic/core/crypto/quic_server_info.h" | 45 #include "net/quic/core/crypto/quic_server_info.h" |
| 47 #include "net/quic/core/quic_client_promised_info.h" | 46 #include "net/quic/core/quic_client_promised_info.h" |
| 48 #include "net/quic/core/quic_clock.h" | 47 #include "net/quic/core/quic_clock.h" |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 ChannelIDService* channel_id_service, | 711 ChannelIDService* channel_id_service, |
| 713 TransportSecurityState* transport_security_state, | 712 TransportSecurityState* transport_security_state, |
| 714 CTVerifier* cert_transparency_verifier, | 713 CTVerifier* cert_transparency_verifier, |
| 715 SocketPerformanceWatcherFactory* socket_performance_watcher_factory, | 714 SocketPerformanceWatcherFactory* socket_performance_watcher_factory, |
| 716 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory, | 715 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory, |
| 717 QuicRandom* random_generator, | 716 QuicRandom* random_generator, |
| 718 QuicClock* clock, | 717 QuicClock* clock, |
| 719 size_t max_packet_length, | 718 size_t max_packet_length, |
| 720 const std::string& user_agent_id, | 719 const std::string& user_agent_id, |
| 721 const QuicVersionVector& supported_versions, | 720 const QuicVersionVector& supported_versions, |
| 722 bool enable_port_selection, | |
| 723 bool always_require_handshake_confirmation, | 721 bool always_require_handshake_confirmation, |
| 724 bool disable_connection_pooling, | 722 bool disable_connection_pooling, |
| 725 float load_server_info_timeout_srtt_multiplier, | 723 float load_server_info_timeout_srtt_multiplier, |
| 726 bool enable_connection_racing, | 724 bool enable_connection_racing, |
| 727 bool enable_non_blocking_io, | 725 bool enable_non_blocking_io, |
| 728 bool disable_disk_cache, | 726 bool disable_disk_cache, |
| 729 bool prefer_aes, | 727 bool prefer_aes, |
| 730 int socket_receive_buffer_size, | 728 int socket_receive_buffer_size, |
| 731 bool delay_tcp_race, | 729 bool delay_tcp_race, |
| 732 int max_server_configs_stored_in_properties, | 730 int max_server_configs_stored_in_properties, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 758 clock_skew_detector_(base::TimeTicks::Now(), base::Time::Now()), | 756 clock_skew_detector_(base::TimeTicks::Now(), base::Time::Now()), |
| 759 socket_performance_watcher_factory_(socket_performance_watcher_factory), | 757 socket_performance_watcher_factory_(socket_performance_watcher_factory), |
| 760 config_(InitializeQuicConfig(connection_options, | 758 config_(InitializeQuicConfig(connection_options, |
| 761 idle_connection_timeout_seconds)), | 759 idle_connection_timeout_seconds)), |
| 762 crypto_config_(base::WrapUnique( | 760 crypto_config_(base::WrapUnique( |
| 763 new ProofVerifierChromium(cert_verifier, | 761 new ProofVerifierChromium(cert_verifier, |
| 764 ct_policy_enforcer, | 762 ct_policy_enforcer, |
| 765 transport_security_state, | 763 transport_security_state, |
| 766 cert_transparency_verifier))), | 764 cert_transparency_verifier))), |
| 767 supported_versions_(supported_versions), | 765 supported_versions_(supported_versions), |
| 768 enable_port_selection_(enable_port_selection), | |
| 769 always_require_handshake_confirmation_( | 766 always_require_handshake_confirmation_( |
| 770 always_require_handshake_confirmation), | 767 always_require_handshake_confirmation), |
| 771 disable_connection_pooling_(disable_connection_pooling), | 768 disable_connection_pooling_(disable_connection_pooling), |
| 772 load_server_info_timeout_srtt_multiplier_( | 769 load_server_info_timeout_srtt_multiplier_( |
| 773 load_server_info_timeout_srtt_multiplier), | 770 load_server_info_timeout_srtt_multiplier), |
| 774 enable_connection_racing_(enable_connection_racing), | 771 enable_connection_racing_(enable_connection_racing), |
| 775 enable_non_blocking_io_(enable_non_blocking_io), | 772 enable_non_blocking_io_(enable_non_blocking_io), |
| 776 disable_disk_cache_(disable_disk_cache), | 773 disable_disk_cache_(disable_disk_cache), |
| 777 prefer_aes_(prefer_aes), | 774 prefer_aes_(prefer_aes), |
| 778 disable_quic_on_timeout_with_open_streams_( | 775 disable_quic_on_timeout_with_open_streams_( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 790 close_sessions_on_ip_change_(close_sessions_on_ip_change), | 787 close_sessions_on_ip_change_(close_sessions_on_ip_change), |
| 791 migrate_sessions_on_network_change_( | 788 migrate_sessions_on_network_change_( |
| 792 migrate_sessions_on_network_change && | 789 migrate_sessions_on_network_change && |
| 793 NetworkChangeNotifier::AreNetworkHandlesSupported()), | 790 NetworkChangeNotifier::AreNetworkHandlesSupported()), |
| 794 migrate_sessions_early_(migrate_sessions_early && | 791 migrate_sessions_early_(migrate_sessions_early && |
| 795 migrate_sessions_on_network_change_), | 792 migrate_sessions_on_network_change_), |
| 796 allow_server_migration_(allow_server_migration), | 793 allow_server_migration_(allow_server_migration), |
| 797 force_hol_blocking_(force_hol_blocking), | 794 force_hol_blocking_(force_hol_blocking), |
| 798 race_cert_verification_(race_cert_verification), | 795 race_cert_verification_(race_cert_verification), |
| 799 quic_do_not_fragment_(quic_do_not_fragment), | 796 quic_do_not_fragment_(quic_do_not_fragment), |
| 800 port_seed_(random_generator_->RandUint64()), | |
| 801 check_persisted_supports_quic_(true), | 797 check_persisted_supports_quic_(true), |
| 802 has_initialized_data_(false), | 798 has_initialized_data_(false), |
| 803 num_push_streams_created_(0), | 799 num_push_streams_created_(0), |
| 804 status_(OPEN), | 800 status_(OPEN), |
| 805 task_runner_(nullptr), | 801 task_runner_(nullptr), |
| 806 ssl_config_service_(ssl_config_service), | 802 ssl_config_service_(ssl_config_service), |
| 807 weak_factory_(this) { | 803 weak_factory_(this) { |
| 808 if (ssl_config_service_.get()) | 804 if (ssl_config_service_.get()) |
| 809 ssl_config_service_->AddObserver(this); | 805 ssl_config_service_->AddObserver(this); |
| 810 DCHECK(transport_security_state_); | 806 DCHECK(transport_security_state_); |
| (...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 task_runner_->PostDelayedTask( | 1608 task_runner_->PostDelayedTask( |
| 1613 FROM_HERE, | 1609 FROM_HERE, |
| 1614 base::Bind(&QuicStreamFactory::MaybeClearConsecutiveDisabledCount, | 1610 base::Bind(&QuicStreamFactory::MaybeClearConsecutiveDisabledCount, |
| 1615 weak_factory_.GetWeakPtr()), | 1611 weak_factory_.GetWeakPtr()), |
| 1616 base::TimeDelta::FromSeconds(kDisableQuicTimeoutSecs)); | 1612 base::TimeDelta::FromSeconds(kDisableQuicTimeoutSecs)); |
| 1617 | 1613 |
| 1618 need_to_evaluate_consecutive_disabled_count_ = false; | 1614 need_to_evaluate_consecutive_disabled_count_ = false; |
| 1619 } | 1615 } |
| 1620 TRACE_EVENT0("net", "QuicStreamFactory::CreateSession"); | 1616 TRACE_EVENT0("net", "QuicStreamFactory::CreateSession"); |
| 1621 IPEndPoint addr = *address_list.begin(); | 1617 IPEndPoint addr = *address_list.begin(); |
| 1622 bool enable_port_selection = enable_port_selection_; | |
| 1623 if (enable_port_selection && base::ContainsKey(gone_away_aliases_, key)) { | |
| 1624 // Disable port selection when the server is going away. | |
| 1625 // There is no point in trying to return to the same server, if | |
| 1626 // that server is no longer handling requests. | |
| 1627 enable_port_selection = false; | |
| 1628 gone_away_aliases_.erase(key); | |
| 1629 } | |
| 1630 const QuicServerId& server_id = key.server_id(); | 1618 const QuicServerId& server_id = key.server_id(); |
| 1631 scoped_refptr<PortSuggester> port_suggester = | 1619 DatagramSocket::BindType bind_type = DatagramSocket::DEFAULT_BIND; |
| 1632 new PortSuggester(server_id.host_port_pair(), port_seed_); | |
| 1633 DatagramSocket::BindType bind_type = | |
| 1634 enable_port_selection ? DatagramSocket::RANDOM_BIND | |
| 1635 : // Use our callback. | |
| 1636 DatagramSocket::DEFAULT_BIND; // Use OS to randomize. | |
| 1637 | |
| 1638 std::unique_ptr<DatagramClientSocket> socket( | 1620 std::unique_ptr<DatagramClientSocket> socket( |
| 1639 client_socket_factory_->CreateDatagramClientSocket( | 1621 client_socket_factory_->CreateDatagramClientSocket( |
| 1640 bind_type, base::Bind(&PortSuggester::SuggestPort, port_suggester), | 1622 bind_type, RandIntCallback(), net_log.net_log(), net_log.source())); |
| 1641 net_log.net_log(), net_log.source())); | |
| 1642 | 1623 |
| 1643 // Passing in kInvalidNetworkHandle binds socket to default network. | 1624 // Passing in kInvalidNetworkHandle binds socket to default network. |
| 1644 int rv = ConfigureSocket(socket.get(), addr, | 1625 int rv = ConfigureSocket(socket.get(), addr, |
| 1645 NetworkChangeNotifier::kInvalidNetworkHandle); | 1626 NetworkChangeNotifier::kInvalidNetworkHandle); |
| 1646 if (rv != OK) | 1627 if (rv != OK) |
| 1647 return rv; | 1628 return rv; |
| 1648 | 1629 |
| 1649 if (enable_port_selection) | |
| 1650 DCHECK_LE(1u, port_suggester->call_count()); | |
| 1651 else | |
| 1652 DCHECK_EQ(0u, port_suggester->call_count()); | |
| 1653 | |
| 1654 if (!helper_.get()) { | 1630 if (!helper_.get()) { |
| 1655 helper_.reset( | 1631 helper_.reset( |
| 1656 new QuicChromiumConnectionHelper(clock_.get(), random_generator_)); | 1632 new QuicChromiumConnectionHelper(clock_.get(), random_generator_)); |
| 1657 } | 1633 } |
| 1658 | 1634 |
| 1659 if (!alarm_factory_.get()) { | 1635 if (!alarm_factory_.get()) { |
| 1660 alarm_factory_.reset(new QuicChromiumAlarmFactory( | 1636 alarm_factory_.reset(new QuicChromiumAlarmFactory( |
| 1661 base::ThreadTaskRunnerHandle::Get().get(), clock_.get())); | 1637 base::ThreadTaskRunnerHandle::Get().get(), clock_.get())); |
| 1662 } | 1638 } |
| 1663 QuicConnectionId connection_id = random_generator_->RandUint64(); | 1639 QuicConnectionId connection_id = random_generator_->RandUint64(); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1924 void QuicStreamFactory::OpenFactory() { | 1900 void QuicStreamFactory::OpenFactory() { |
| 1925 status_ = OPEN; | 1901 status_ = OPEN; |
| 1926 } | 1902 } |
| 1927 | 1903 |
| 1928 void QuicStreamFactory::MaybeClearConsecutiveDisabledCount() { | 1904 void QuicStreamFactory::MaybeClearConsecutiveDisabledCount() { |
| 1929 if (status_ == OPEN) | 1905 if (status_ == OPEN) |
| 1930 consecutive_disabled_count_ = 0; | 1906 consecutive_disabled_count_ = 0; |
| 1931 } | 1907 } |
| 1932 | 1908 |
| 1933 } // namespace net | 1909 } // namespace net |
| OLD | NEW |