| 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 "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "net/base/test_data_directory.h" | 10 #include "net/base/test_data_directory.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } // namespace anonymous | 80 } // namespace anonymous |
| 81 | 81 |
| 82 class QuicStreamFactoryPeer { | 82 class QuicStreamFactoryPeer { |
| 83 public: | 83 public: |
| 84 static QuicCryptoClientConfig* GetCryptoConfig(QuicStreamFactory* factory) { | 84 static QuicCryptoClientConfig* GetCryptoConfig(QuicStreamFactory* factory) { |
| 85 return &factory->crypto_config_; | 85 return &factory->crypto_config_; |
| 86 } | 86 } |
| 87 | 87 |
| 88 static bool HasActiveSession(QuicStreamFactory* factory, | 88 static bool HasActiveSession(QuicStreamFactory* factory, |
| 89 const HostPortPair& host_port_pair) { | 89 const HostPortPair& host_port_pair) { |
| 90 QuicServerId server_id(host_port_pair, /*is_https=*/true, | 90 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
| 91 PRIVACY_MODE_DISABLED); | |
| 92 return factory->HasActiveSession(server_id); | 91 return factory->HasActiveSession(server_id); |
| 93 } | 92 } |
| 94 | 93 |
| 95 static QuicChromiumClientSession* GetActiveSession( | 94 static QuicChromiumClientSession* GetActiveSession( |
| 96 QuicStreamFactory* factory, | 95 QuicStreamFactory* factory, |
| 97 const HostPortPair& host_port_pair) { | 96 const HostPortPair& host_port_pair) { |
| 98 QuicServerId server_id(host_port_pair, /*is_https=*/true, | 97 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
| 99 PRIVACY_MODE_DISABLED); | |
| 100 DCHECK(factory->HasActiveSession(server_id)); | 98 DCHECK(factory->HasActiveSession(server_id)); |
| 101 return factory->active_sessions_[server_id]; | 99 return factory->active_sessions_[server_id]; |
| 102 } | 100 } |
| 103 | 101 |
| 104 static scoped_ptr<QuicHttpStream> CreateFromSession( | 102 static scoped_ptr<QuicHttpStream> CreateFromSession( |
| 105 QuicStreamFactory* factory, | 103 QuicStreamFactory* factory, |
| 106 QuicChromiumClientSession* session) { | 104 QuicChromiumClientSession* session) { |
| 107 return factory->CreateFromSession(session); | 105 return factory->CreateFromSession(session); |
| 108 } | 106 } |
| 109 | 107 |
| (...skipping 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 | 1546 |
| 1549 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { | 1547 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 1550 string r1_host_name("r1"); | 1548 string r1_host_name("r1"); |
| 1551 string r2_host_name("r2"); | 1549 string r2_host_name("r2"); |
| 1552 r1_host_name.append(cannoncial_suffixes[i]); | 1550 r1_host_name.append(cannoncial_suffixes[i]); |
| 1553 r2_host_name.append(cannoncial_suffixes[i]); | 1551 r2_host_name.append(cannoncial_suffixes[i]); |
| 1554 | 1552 |
| 1555 HostPortPair host_port_pair1(r1_host_name, 80); | 1553 HostPortPair host_port_pair1(r1_host_name, 80); |
| 1556 QuicCryptoClientConfig* crypto_config = | 1554 QuicCryptoClientConfig* crypto_config = |
| 1557 QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); | 1555 QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
| 1558 QuicServerId server_id1(host_port_pair1, /*is_https=*/true, privacy_mode_); | 1556 QuicServerId server_id1(host_port_pair1, privacy_mode_); |
| 1559 QuicCryptoClientConfig::CachedState* cached1 = | 1557 QuicCryptoClientConfig::CachedState* cached1 = |
| 1560 crypto_config->LookupOrCreate(server_id1); | 1558 crypto_config->LookupOrCreate(server_id1); |
| 1561 EXPECT_FALSE(cached1->proof_valid()); | 1559 EXPECT_FALSE(cached1->proof_valid()); |
| 1562 EXPECT_TRUE(cached1->source_address_token().empty()); | 1560 EXPECT_TRUE(cached1->source_address_token().empty()); |
| 1563 | 1561 |
| 1564 // Mutate the cached1 to have different data. | 1562 // Mutate the cached1 to have different data. |
| 1565 // TODO(rtenneti): mutate other members of CachedState. | 1563 // TODO(rtenneti): mutate other members of CachedState. |
| 1566 cached1->set_source_address_token(r1_host_name); | 1564 cached1->set_source_address_token(r1_host_name); |
| 1567 cached1->SetProofValid(); | 1565 cached1->SetProofValid(); |
| 1568 | 1566 |
| 1569 HostPortPair host_port_pair2(r2_host_name, 80); | 1567 HostPortPair host_port_pair2(r2_host_name, 80); |
| 1570 QuicServerId server_id2(host_port_pair2, /*is_https=*/true, privacy_mode_); | 1568 QuicServerId server_id2(host_port_pair2, privacy_mode_); |
| 1571 QuicCryptoClientConfig::CachedState* cached2 = | 1569 QuicCryptoClientConfig::CachedState* cached2 = |
| 1572 crypto_config->LookupOrCreate(server_id2); | 1570 crypto_config->LookupOrCreate(server_id2); |
| 1573 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); | 1571 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
| 1574 EXPECT_TRUE(cached2->proof_valid()); | 1572 EXPECT_TRUE(cached2->proof_valid()); |
| 1575 } | 1573 } |
| 1576 } | 1574 } |
| 1577 | 1575 |
| 1578 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { | 1576 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
| 1579 Initialize(); | 1577 Initialize(); |
| 1580 vector<string> cannoncial_suffixes; | 1578 vector<string> cannoncial_suffixes; |
| 1581 cannoncial_suffixes.push_back(string(".c.youtube.com")); | 1579 cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 1582 cannoncial_suffixes.push_back(string(".googlevideo.com")); | 1580 cannoncial_suffixes.push_back(string(".googlevideo.com")); |
| 1583 | 1581 |
| 1584 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { | 1582 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 1585 string r3_host_name("r3"); | 1583 string r3_host_name("r3"); |
| 1586 string r4_host_name("r4"); | 1584 string r4_host_name("r4"); |
| 1587 r3_host_name.append(cannoncial_suffixes[i]); | 1585 r3_host_name.append(cannoncial_suffixes[i]); |
| 1588 r4_host_name.append(cannoncial_suffixes[i]); | 1586 r4_host_name.append(cannoncial_suffixes[i]); |
| 1589 | 1587 |
| 1590 HostPortPair host_port_pair1(r3_host_name, 80); | 1588 HostPortPair host_port_pair1(r3_host_name, 80); |
| 1591 QuicCryptoClientConfig* crypto_config = | 1589 QuicCryptoClientConfig* crypto_config = |
| 1592 QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); | 1590 QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
| 1593 QuicServerId server_id1(host_port_pair1, /*is_https=*/true, privacy_mode_); | 1591 QuicServerId server_id1(host_port_pair1, privacy_mode_); |
| 1594 QuicCryptoClientConfig::CachedState* cached1 = | 1592 QuicCryptoClientConfig::CachedState* cached1 = |
| 1595 crypto_config->LookupOrCreate(server_id1); | 1593 crypto_config->LookupOrCreate(server_id1); |
| 1596 EXPECT_FALSE(cached1->proof_valid()); | 1594 EXPECT_FALSE(cached1->proof_valid()); |
| 1597 EXPECT_TRUE(cached1->source_address_token().empty()); | 1595 EXPECT_TRUE(cached1->source_address_token().empty()); |
| 1598 | 1596 |
| 1599 // Mutate the cached1 to have different data. | 1597 // Mutate the cached1 to have different data. |
| 1600 // TODO(rtenneti): mutate other members of CachedState. | 1598 // TODO(rtenneti): mutate other members of CachedState. |
| 1601 cached1->set_source_address_token(r3_host_name); | 1599 cached1->set_source_address_token(r3_host_name); |
| 1602 cached1->SetProofInvalid(); | 1600 cached1->SetProofInvalid(); |
| 1603 | 1601 |
| 1604 HostPortPair host_port_pair2(r4_host_name, 80); | 1602 HostPortPair host_port_pair2(r4_host_name, 80); |
| 1605 QuicServerId server_id2(host_port_pair2, /*is_https=*/true, privacy_mode_); | 1603 QuicServerId server_id2(host_port_pair2, privacy_mode_); |
| 1606 QuicCryptoClientConfig::CachedState* cached2 = | 1604 QuicCryptoClientConfig::CachedState* cached2 = |
| 1607 crypto_config->LookupOrCreate(server_id2); | 1605 crypto_config->LookupOrCreate(server_id2); |
| 1608 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); | 1606 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 1609 EXPECT_TRUE(cached2->source_address_token().empty()); | 1607 EXPECT_TRUE(cached2->source_address_token().empty()); |
| 1610 EXPECT_FALSE(cached2->proof_valid()); | 1608 EXPECT_FALSE(cached2->proof_valid()); |
| 1611 } | 1609 } |
| 1612 } | 1610 } |
| 1613 | 1611 |
| 1614 TEST_P(QuicStreamFactoryTest, RacingConnections) { | 1612 TEST_P(QuicStreamFactoryTest, RacingConnections) { |
| 1615 disable_disk_cache_ = false; | 1613 disable_disk_cache_ = false; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1644 http_server_properties_.SetAlternativeServices( | 1642 http_server_properties_.SetAlternativeServices( |
| 1645 host_port_pair_, alternative_service_info_vector); | 1643 host_port_pair_, alternative_service_info_vector); |
| 1646 | 1644 |
| 1647 crypto_client_stream_factory_.set_handshake_mode( | 1645 crypto_client_stream_factory_.set_handshake_mode( |
| 1648 MockCryptoClientStream::ZERO_RTT); | 1646 MockCryptoClientStream::ZERO_RTT); |
| 1649 host_resolver_.set_synchronous_mode(true); | 1647 host_resolver_.set_synchronous_mode(true); |
| 1650 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), | 1648 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1651 "192.168.0.1", ""); | 1649 "192.168.0.1", ""); |
| 1652 | 1650 |
| 1653 QuicStreamRequest request(factory_.get()); | 1651 QuicStreamRequest request(factory_.get()); |
| 1654 QuicServerId server_id(host_port_pair_, /*is_https=*/true, privacy_mode_); | 1652 QuicServerId server_id(host_port_pair_, privacy_mode_); |
| 1655 EXPECT_EQ(ERR_IO_PENDING, | 1653 EXPECT_EQ(ERR_IO_PENDING, |
| 1656 request.Request(host_port_pair_, privacy_mode_, | 1654 request.Request(host_port_pair_, privacy_mode_, |
| 1657 /*cert_verify_flags=*/0, host_port_pair_.host(), | 1655 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1658 "GET", net_log_, callback_.callback())); | 1656 "GET", net_log_, callback_.callback())); |
| 1659 EXPECT_EQ(2u, QuicStreamFactoryPeer::GetNumberOfActiveJobs(factory_.get(), | 1657 EXPECT_EQ(2u, QuicStreamFactoryPeer::GetNumberOfActiveJobs(factory_.get(), |
| 1660 server_id)); | 1658 server_id)); |
| 1661 | 1659 |
| 1662 runner_->RunNextTask(); | 1660 runner_->RunNextTask(); |
| 1663 | 1661 |
| 1664 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 1662 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| (...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2634 const AlternativeService alternative_service1(QUIC, host_port_pair_.host(), | 2632 const AlternativeService alternative_service1(QUIC, host_port_pair_.host(), |
| 2635 host_port_pair_.port()); | 2633 host_port_pair_.port()); |
| 2636 AlternativeServiceInfoVector alternative_service_info_vector; | 2634 AlternativeServiceInfoVector alternative_service_info_vector; |
| 2637 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 2635 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 2638 alternative_service_info_vector.push_back( | 2636 alternative_service_info_vector.push_back( |
| 2639 AlternativeServiceInfo(alternative_service1, 1.0, expiration)); | 2637 AlternativeServiceInfo(alternative_service1, 1.0, expiration)); |
| 2640 | 2638 |
| 2641 http_server_properties_.SetAlternativeServices( | 2639 http_server_properties_.SetAlternativeServices( |
| 2642 host_port_pair_, alternative_service_info_vector); | 2640 host_port_pair_, alternative_service_info_vector); |
| 2643 | 2641 |
| 2644 QuicServerId quic_server_id("www.google.com", 80, false, | 2642 QuicServerId quic_server_id("www.google.com", 80, PRIVACY_MODE_DISABLED); |
| 2645 PRIVACY_MODE_DISABLED); | |
| 2646 QuicServerInfoFactory* quic_server_info_factory = | 2643 QuicServerInfoFactory* quic_server_info_factory = |
| 2647 new PropertiesBasedQuicServerInfoFactory( | 2644 new PropertiesBasedQuicServerInfoFactory( |
| 2648 http_server_properties_.GetWeakPtr()); | 2645 http_server_properties_.GetWeakPtr()); |
| 2649 factory_->set_quic_server_info_factory(quic_server_info_factory); | 2646 factory_->set_quic_server_info_factory(quic_server_info_factory); |
| 2650 | 2647 |
| 2651 scoped_ptr<QuicServerInfo> quic_server_info( | 2648 scoped_ptr<QuicServerInfo> quic_server_info( |
| 2652 quic_server_info_factory->GetForServer(quic_server_id)); | 2649 quic_server_info_factory->GetForServer(quic_server_id)); |
| 2653 | 2650 |
| 2654 // Update quic_server_info's server_config and persist it. | 2651 // Update quic_server_info's server_config and persist it. |
| 2655 QuicServerInfo::State* state = quic_server_info->mutable_state(); | 2652 QuicServerInfo::State* state = quic_server_info->mutable_state(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2786 EXPECT_EQ(1u, observer.executed_count()); | 2783 EXPECT_EQ(1u, observer.executed_count()); |
| 2787 | 2784 |
| 2788 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 2785 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 2789 EXPECT_TRUE(stream.get()); | 2786 EXPECT_TRUE(stream.get()); |
| 2790 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 2787 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2791 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 2788 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2792 } | 2789 } |
| 2793 | 2790 |
| 2794 } // namespace test | 2791 } // namespace test |
| 2795 } // namespace net | 2792 } // namespace net |
| OLD | NEW |