diff options
author | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-01 09:15:37 +0000 |
---|---|---|
committer | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-01 09:15:37 +0000 |
commit | 257f24fb9b8d3a232406f11b0f7a137659d11565 (patch) | |
tree | 5b9e726302dd618a785f64577b2e76feef2bbde3 /net | |
parent | 275e485af3ba80248267aefab70a14e277768678 (diff) | |
download | chromium_src-257f24fb9b8d3a232406f11b0f7a137659d11565.zip chromium_src-257f24fb9b8d3a232406f11b0f7a137659d11565.tar.gz chromium_src-257f24fb9b8d3a232406f11b0f7a137659d11565.tar.bz2 |
Land Recent QUIC Changes.
Refactor hybrid slow start in QUIC to create a simpler interface between
it an TCPCubicSender.
In preparation for BBR.
Merge internal change: 64031462
https://codereview.chromium.org/218993002/
Don't log decryption errors in AeadBaseDecrypter::Decrypt.
Instead, have QuicFramer::DecryptPayload log a warning message if both
trial decryptions fail.
Merge internal change: 63977728
https://codereview.chromium.org/218983002/
QUIC refactor to remove a return value which was always true.
Merge internal change: 63977684
https://codereview.chromium.org/218913003/
Simplify the bytes_consumed computation
in QuicPacketCreator::CreateStreamFrame. Does not change behavior.
Merge internal change: 63900899
https://codereview.chromium.org/218873003/
Fixing a broken test for quic. cr/63542972 added the proxy flag on
outbound packets. Unfortunately, this broke our tests using the magic
header. This CL provides hooks for clearing that bit of data.
Adding a virtual function to quic client so we can fix a test.
Merge internal change: 63898585
https://codereview.chromium.org/218963003/
+ Use QuicServerKey tuple (host, port, is_https) instead of
server_hostname, while creating QuicClientSession,
QuicCryptoClientStream, QuicCryptoClientConfig, QuicClient,
QuicTestClient, etc objects.
+ QuicServerKey is used as the key to access QUIC server
config information from all caches.
+ Added couple of new unit tests for HostPortPair class.
+ Added unit tests for QuicServerId for privacy mode
combination with host, port, is_https.
Merge internal change: 63891842
https://codereview.chromium.org/218923002/
R=rch@chromium.org
Review URL: https://codereview.chromium.org/216713003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260810 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
57 files changed, 891 insertions, 486 deletions
diff --git a/net/base/host_port_pair.cc b/net/base/host_port_pair.cc index bc23a9a..a862098 100644 --- a/net/base/host_port_pair.cc +++ b/net/base/host_port_pair.cc @@ -4,6 +4,7 @@ #include "net/base/host_port_pair.h" +#include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" @@ -47,6 +48,9 @@ std::string HostPortPair::ToString() const { } std::string HostPortPair::HostForURL() const { + // TODO(rtenneti): Add support for |host| to have '\0'. + LOG_IF(DFATAL, host_.find('\0') != std::string::npos) + << "Host has a null char: " << host_; // Check to see if the host is an IPv6 address. If so, added brackets. if (host_.find(':') != std::string::npos) { DCHECK_NE(host_[0], '['); diff --git a/net/base/host_port_pair_unittest.cc b/net/base/host_port_pair_unittest.cc index d654622..fa73875 100644 --- a/net/base/host_port_pair_unittest.cc +++ b/net/base/host_port_pair_unittest.cc @@ -4,15 +4,33 @@ #include "net/base/host_port_pair.h" +#include "base/logging.h" +#include "net/test/gtest_util.h" #include "testing/gtest/include/gtest/gtest.h" +using std::string; + namespace net { namespace { +struct TestData { + string host; + uint16 port; + string to_string; + string host_for_url; +} tests[] = { + { "www.google.com", 80, "www.google.com:80", "www.google.com" }, + { "www.google.com", 443, "www.google.com:443", "www.google.com" }, + { "127.0.0.1", 80, "127.0.0.1:80", "127.0.0.1" }, + { "192.168.1.1", 80, "192.168.1.1:80", "192.168.1.1" }, + { "::1", 80, "[::1]:80", "[::1]" }, + { "2001:db8::42", 80, "[2001:db8::42]:80", "[2001:db8::42]" }, +}; + TEST(HostPortPairTest, Parsing) { HostPortPair foo("foo.com", 10); - std::string foo_str = foo.ToString(); + string foo_str = foo.ToString(); EXPECT_EQ("foo.com:10", foo_str); HostPortPair bar = HostPortPair::FromString(foo_str); EXPECT_TRUE(foo.Equals(bar)); @@ -35,6 +53,64 @@ TEST(HostPortPairTest, Emptiness) { EXPECT_FALSE(foo.IsEmpty()); } +TEST(HostPortPairTest, ToString) { + for (size_t index = 0; index < arraysize(tests); ++index) { + HostPortPair foo(tests[index].host, tests[index].port); + EXPECT_EQ(tests[index].to_string, foo.ToString()); + } + + // Test empty hostname. + HostPortPair foo(string(), 10); +} + +TEST(HostPortPairTest, HostForURL) { + for (size_t index = 0; index < arraysize(tests); ++index) { + HostPortPair foo(tests[index].host, tests[index].port); + EXPECT_EQ(tests[index].host_for_url, foo.HostForURL()); + } + + // Test hostname with null character. + string bar_hostname("a\0.com", 6); + HostPortPair bar(bar_hostname, 80); + string expected_error("Host has a null char: "); + expected_error.append(bar_hostname); + EXPECT_DFATAL(bar.HostForURL(), expected_error); +} + +TEST(HostPortPairTest, LessThan) { + HostPortPair a_10("a.com", 10); + HostPortPair a_11("a.com", 11); + HostPortPair b_10("b.com", 10); + HostPortPair b_11("b.com", 11); + + EXPECT_FALSE(a_10 < a_10); + EXPECT_TRUE(a_10 < a_11); + EXPECT_TRUE(a_10 < b_10); + EXPECT_TRUE(a_10 < b_11); + + EXPECT_FALSE(a_11 < a_10); + EXPECT_FALSE(a_11 < b_10); + + EXPECT_FALSE(b_10 < a_10); + EXPECT_TRUE(b_10 < a_11); + + EXPECT_FALSE(b_11 < a_10); +} + +TEST(HostPortPairTest, Equals) { + HostPortPair a_10("a.com", 10); + HostPortPair a_11("a.com", 11); + HostPortPair b_10("b.com", 10); + HostPortPair b_11("b.com", 11); + + HostPortPair new_a_10("a.com", 10); + + EXPECT_TRUE(new_a_10.Equals(a_10)); + EXPECT_FALSE(new_a_10.Equals(a_11)); + EXPECT_FALSE(new_a_10.Equals(b_10)); + EXPECT_FALSE(new_a_10.Equals(b_11)); +} + } // namespace } // namespace net diff --git a/net/http/disk_cache_based_quic_server_info.cc b/net/http/disk_cache_based_quic_server_info.cc index 1c7147d..4cf036d 100644 --- a/net/http/disk_cache_based_quic_server_info.cc +++ b/net/http/disk_cache_based_quic_server_info.cc @@ -12,7 +12,7 @@ #include "net/base/net_errors.h" #include "net/http/http_cache.h" #include "net/http/http_network_session.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" namespace net { @@ -44,9 +44,9 @@ struct DiskCacheBasedQuicServerInfo::CacheOperationDataShim { }; DiskCacheBasedQuicServerInfo::DiskCacheBasedQuicServerInfo( - const QuicSessionKey& server_key, + const QuicServerId& server_id, HttpCache* http_cache) - : QuicServerInfo(server_key), + : QuicServerInfo(server_id), weak_factory_(this), data_shim_(new CacheOperationDataShim()), io_callback_( @@ -56,7 +56,7 @@ DiskCacheBasedQuicServerInfo::DiskCacheBasedQuicServerInfo( state_(GET_BACKEND), ready_(false), found_entry_(false), - server_key_(server_key), + server_id_(server_id), http_cache_(http_cache), backend_(NULL), entry_(NULL) { @@ -120,7 +120,7 @@ DiskCacheBasedQuicServerInfo::~DiskCacheBasedQuicServerInfo() { } std::string DiskCacheBasedQuicServerInfo::key() const { - return "quicserverinfo:" + server_key_.ToString(); + return "quicserverinfo:" + server_id_.ToString(); } void DiskCacheBasedQuicServerInfo::OnIOComplete(CacheOperationDataShim* unused, diff --git a/net/http/disk_cache_based_quic_server_info.h b/net/http/disk_cache_based_quic_server_info.h index 3c384cc..2a18ef5 100644 --- a/net/http/disk_cache_based_quic_server_info.h +++ b/net/http/disk_cache_based_quic_server_info.h @@ -18,7 +18,7 @@ namespace net { class HttpCache; class IOBuffer; -class QuicSessionKey; +class QuicServerId; // DiskCacheBasedQuicServerInfo fetches information about a QUIC server from // our standard disk cache. Since the information is defined to be @@ -27,7 +27,7 @@ class NET_EXPORT_PRIVATE DiskCacheBasedQuicServerInfo : public QuicServerInfo, public NON_EXPORTED_BASE(base::NonThreadSafe) { public: - DiskCacheBasedQuicServerInfo(const QuicSessionKey& server_key, + DiskCacheBasedQuicServerInfo(const QuicServerId& server_id, HttpCache* http_cache); // QuicServerInfo implementation. @@ -91,7 +91,7 @@ class NET_EXPORT_PRIVATE DiskCacheBasedQuicServerInfo bool ready_; bool found_entry_; // Controls the behavior of DoCreateOrOpen. std::string new_data_; - const QuicSessionKey server_key_; + const QuicServerId server_id_; HttpCache* const http_cache_; disk_cache::Backend* backend_; disk_cache::Entry* entry_; diff --git a/net/http/disk_cache_based_quic_server_info_unittest.cc b/net/http/disk_cache_based_quic_server_info_unittest.cc index 3fb9ba5..52b832d 100644 --- a/net/http/disk_cache_based_quic_server_info_unittest.cc +++ b/net/http/disk_cache_based_quic_server_info_unittest.cc @@ -11,7 +11,7 @@ #include "net/base/net_errors.h" #include "net/http/mock_http_cache.h" #include "net/quic/crypto/quic_server_info.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "testing/gtest/include/gtest/gtest.h" namespace net { @@ -57,10 +57,9 @@ TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) { // of quic_server_info->WaitForDataReady(), so that the callback will run. MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); MockHttpCache cache(factory); - QuicSessionKey server_key("www.verisign.com", 443, true, - PRIVACY_MODE_DISABLED); + QuicServerId server_id("www.verisign.com", 443, true, PRIVACY_MODE_DISABLED); scoped_ptr<QuicServerInfo> quic_server_info( - new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); + new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); quic_server_info->Start(); TestCompletionCallback callback; int rv = quic_server_info->WaitForDataReady(callback.callback()); @@ -76,9 +75,9 @@ TEST(DiskCacheBasedQuicServerInfo, Update) { AddMockTransaction(&kHostInfoTransaction1); TestCompletionCallback callback; - QuicSessionKey server_key("www.google.com", 443, true, PRIVACY_MODE_DISABLED); + QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); scoped_ptr<QuicServerInfo> quic_server_info( - new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); + new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); quic_server_info->Start(); int rv = quic_server_info->WaitForDataReady(callback.callback()); EXPECT_EQ(OK, callback.GetResult(rv)); @@ -102,7 +101,7 @@ TEST(DiskCacheBasedQuicServerInfo, Update) { // Open the stored QuicServerInfo. quic_server_info.reset( - new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); + new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); quic_server_info->Start(); rv = quic_server_info->WaitForDataReady(callback.callback()); EXPECT_EQ(OK, callback.GetResult(rv)); @@ -118,7 +117,7 @@ TEST(DiskCacheBasedQuicServerInfo, Update) { // Verify that the state was updated. quic_server_info.reset( - new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); + new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); quic_server_info->Start(); rv = quic_server_info->WaitForDataReady(callback.callback()); EXPECT_EQ(OK, callback.GetResult(rv)); @@ -143,10 +142,9 @@ TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) { TestCompletionCallback callback; // Persist data for port 443. - QuicSessionKey server_key1("www.google.com", 443, true, - PRIVACY_MODE_DISABLED); + QuicServerId server_id1("www.google.com", 443, true, PRIVACY_MODE_DISABLED); scoped_ptr<QuicServerInfo> quic_server_info1( - new DiskCacheBasedQuicServerInfo(server_key1, cache.http_cache())); + new DiskCacheBasedQuicServerInfo(server_id1, cache.http_cache())); quic_server_info1->Start(); int rv = quic_server_info1->WaitForDataReady(callback.callback()); EXPECT_EQ(OK, callback.GetResult(rv)); @@ -168,10 +166,9 @@ TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) { base::MessageLoop::current()->RunUntilIdle(); // Persist data for port 80. - QuicSessionKey server_key2("www.google.com", 80, false, - PRIVACY_MODE_DISABLED); + QuicServerId server_id2("www.google.com", 80, false, PRIVACY_MODE_DISABLED); scoped_ptr<QuicServerInfo> quic_server_info2( - new DiskCacheBasedQuicServerInfo(server_key2, cache.http_cache())); + new DiskCacheBasedQuicServerInfo(server_id2, cache.http_cache())); quic_server_info2->Start(); rv = quic_server_info2->WaitForDataReady(callback.callback()); EXPECT_EQ(OK, callback.GetResult(rv)); @@ -194,7 +191,7 @@ TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) { // Verify the stored QuicServerInfo for port 443. scoped_ptr<QuicServerInfo> quic_server_info( - new DiskCacheBasedQuicServerInfo(server_key1, cache.http_cache())); + new DiskCacheBasedQuicServerInfo(server_id1, cache.http_cache())); quic_server_info->Start(); rv = quic_server_info->WaitForDataReady(callback.callback()); EXPECT_EQ(OK, callback.GetResult(rv)); @@ -209,7 +206,7 @@ TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) { // Verify the stored QuicServerInfo for port 80. quic_server_info.reset( - new DiskCacheBasedQuicServerInfo(server_key2, cache.http_cache())); + new DiskCacheBasedQuicServerInfo(server_id2, cache.http_cache())); quic_server_info->Start(); rv = quic_server_info->WaitForDataReady(callback.callback()); EXPECT_EQ(OK, callback.GetResult(rv)); @@ -232,9 +229,9 @@ TEST(DiskCacheBasedQuicServerInfo, IsReadyToPersist) { AddMockTransaction(&kHostInfoTransaction1); TestCompletionCallback callback; - QuicSessionKey server_key("www.google.com", 443, true, PRIVACY_MODE_DISABLED); + QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); scoped_ptr<QuicServerInfo> quic_server_info( - new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); + new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); EXPECT_FALSE(quic_server_info->IsDataReady()); quic_server_info->Start(); int rv = quic_server_info->WaitForDataReady(callback.callback()); @@ -266,7 +263,7 @@ TEST(DiskCacheBasedQuicServerInfo, IsReadyToPersist) { // Verify that the state was updated. quic_server_info.reset( - new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); + new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); quic_server_info->Start(); rv = quic_server_info->WaitForDataReady(callback.callback()); EXPECT_EQ(OK, callback.GetResult(rv)); diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index c040aa9..8c7dc1e 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -276,8 +276,8 @@ class HttpCache::QuicServerInfoFactoryAdaptor : public QuicServerInfoFactory { } virtual QuicServerInfo* GetForServer( - const QuicSessionKey& server_key) OVERRIDE { - return new DiskCacheBasedQuicServerInfo(server_key, http_cache_); + const QuicServerId& server_id) OVERRIDE { + return new DiskCacheBasedQuicServerInfo(server_id, http_cache_); } private: diff --git a/net/net.gyp b/net/net.gyp index 4d7a780..167935e 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -936,10 +936,10 @@ 'quic/quic_sent_entropy_manager.h', 'quic/quic_sent_packet_manager.cc', 'quic/quic_sent_packet_manager.h', + 'quic/quic_server_id.cc', + 'quic/quic_server_id.h', 'quic/quic_session.cc', 'quic/quic_session.h', - 'quic/quic_session_key.cc', - 'quic/quic_session_key.h', 'quic/quic_socket_address_coder.cc', 'quic/quic_socket_address_coder.h', 'quic/quic_stream_factory.cc', @@ -1988,7 +1988,7 @@ 'quic/quic_reliable_client_stream_test.cc', 'quic/quic_sent_entropy_manager_test.cc', 'quic/quic_sent_packet_manager_test.cc', - 'quic/quic_session_key_test.cc', + 'quic/quic_server_id_test.cc', 'quic/quic_session_test.cc', 'quic/quic_socket_address_coder_test.cc', 'quic/quic_stream_factory_test.cc', diff --git a/net/quic/congestion_control/hybrid_slow_start.cc b/net/quic/congestion_control/hybrid_slow_start.cc index 3a6b0ec..9325ca4 100644 --- a/net/quic/congestion_control/hybrid_slow_start.cc +++ b/net/quic/congestion_control/hybrid_slow_start.cc @@ -6,6 +6,8 @@ #include <algorithm> +#include "net/quic/congestion_control/rtt_stats.h" + using std::max; using std::min; @@ -13,6 +15,7 @@ namespace net { // Note(pwestin): the magic clamping numbers come from the original code in // tcp_cubic.c. +const int64 kHybridStartLowWindow = 16; // Number of delay samples for detecting the increase of delay. const int kHybridStartMinSamples = 8; const int kHybridStartDelayFactorExp = 4; // 2^4 = 16 @@ -25,12 +28,52 @@ HybridSlowStart::HybridSlowStart(const QuicClock* clock) found_ack_train_(false), found_delay_(false), round_start_(QuicTime::Zero()), + update_end_sequence_number_(true), + sender_end_sequence_number_(0), end_sequence_number_(0), last_time_(QuicTime::Zero()), sample_count_(0), current_rtt_(QuicTime::Delta::Zero()) { } +void HybridSlowStart::OnPacketAcked( + QuicPacketSequenceNumber acked_sequence_number, bool in_slow_start) { + if (in_slow_start) { + if (IsEndOfRound(acked_sequence_number)) { + Reset(sender_end_sequence_number_); + } + } + + if (sender_end_sequence_number_ == acked_sequence_number) { + DVLOG(1) << "Start update end sequence number @" << acked_sequence_number; + update_end_sequence_number_ = true; + } +} + +void HybridSlowStart::OnPacketSent(QuicPacketSequenceNumber sequence_number, + QuicByteCount available_send_window) { + if (update_end_sequence_number_) { + sender_end_sequence_number_ = sequence_number; + if (available_send_window == 0) { + update_end_sequence_number_ = false; + DVLOG(1) << "Stop update end sequence number @" << sequence_number; + } + } +} + +bool HybridSlowStart::ShouldExitSlowStart(const RttStats* rtt_stats, + int64 congestion_window) { + if (congestion_window < kHybridStartLowWindow) { + return false; + } + if (!started()) { + // Time to start the hybrid slow start. + Reset(sender_end_sequence_number_); + } + Update(rtt_stats->latest_rtt(), rtt_stats->min_rtt()); + return Exit(); +} + void HybridSlowStart::Restart() { found_ack_train_ = false; found_delay_ = false; @@ -45,7 +88,7 @@ void HybridSlowStart::Reset(QuicPacketSequenceNumber end_sequence_number) { started_ = true; } -bool HybridSlowStart::EndOfRound(QuicPacketSequenceNumber ack) { +bool HybridSlowStart::IsEndOfRound(QuicPacketSequenceNumber ack) const { return end_sequence_number_ <= ack; } diff --git a/net/quic/congestion_control/hybrid_slow_start.h b/net/quic/congestion_control/hybrid_slow_start.h index cee9c73..e41eba9 100644 --- a/net/quic/congestion_control/hybrid_slow_start.h +++ b/net/quic/congestion_control/hybrid_slow_start.h @@ -22,17 +22,30 @@ namespace net { +class RttStats; + class NET_EXPORT_PRIVATE HybridSlowStart { public: explicit HybridSlowStart(const QuicClock* clock); + void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number, + bool in_slow_start); + + void OnPacketSent(QuicPacketSequenceNumber sequence_number, + QuicByteCount available_send_window); + + bool ShouldExitSlowStart(const RttStats* rtt_stats, + int64 congestion_window); + + // TODO(ianswett): The following methods should be private, but that requires + // a follow up CL to update the unit test. // Start a new slow start phase. void Restart(); // Returns true if this ack the last sequence number of our current slow start // round. // Call Reset if this returns true. - bool EndOfRound(QuicPacketSequenceNumber ack); + bool IsEndOfRound(QuicPacketSequenceNumber ack) const; // Call for each round (burst) in the slow start phase. void Reset(QuicPacketSequenceNumber end_sequence_number); @@ -44,7 +57,7 @@ class NET_EXPORT_PRIVATE HybridSlowStart { // Returns true when we should exit slow start. bool Exit(); - bool started() { return started_; } + bool started() const { return started_; } private: const QuicClock* clock_; @@ -52,6 +65,9 @@ class NET_EXPORT_PRIVATE HybridSlowStart { bool found_ack_train_; bool found_delay_; QuicTime round_start_; // Beginning of each slow start round. + // We need to keep track of the end sequence number of each RTT "burst". + bool update_end_sequence_number_; + QuicPacketSequenceNumber sender_end_sequence_number_; QuicPacketSequenceNumber end_sequence_number_; // End of slow start round. QuicTime last_time_; // Last time when the ACK spacing was close. uint8 sample_count_; // Number of samples to decide current RTT. diff --git a/net/quic/congestion_control/hybrid_slow_start_test.cc b/net/quic/congestion_control/hybrid_slow_start_test.cc index 0a9f91f..ee572bd 100644 --- a/net/quic/congestion_control/hybrid_slow_start_test.cc +++ b/net/quic/congestion_control/hybrid_slow_start_test.cc @@ -31,23 +31,23 @@ TEST_F(HybridSlowStartTest, Simple) { QuicPacketSequenceNumber end_sequence_number = 3; slowStart_->Reset(end_sequence_number); - EXPECT_FALSE(slowStart_->EndOfRound(sequence_number++)); + EXPECT_FALSE(slowStart_->IsEndOfRound(sequence_number++)); // Test duplicates. - EXPECT_FALSE(slowStart_->EndOfRound(sequence_number)); + EXPECT_FALSE(slowStart_->IsEndOfRound(sequence_number)); - EXPECT_FALSE(slowStart_->EndOfRound(sequence_number++)); - EXPECT_TRUE(slowStart_->EndOfRound(sequence_number++)); + EXPECT_FALSE(slowStart_->IsEndOfRound(sequence_number++)); + EXPECT_TRUE(slowStart_->IsEndOfRound(sequence_number++)); // Test without a new registered end_sequence_number; - EXPECT_TRUE(slowStart_->EndOfRound(sequence_number++)); + EXPECT_TRUE(slowStart_->IsEndOfRound(sequence_number++)); end_sequence_number = 20; slowStart_->Reset(end_sequence_number); while (sequence_number < end_sequence_number) { - EXPECT_FALSE(slowStart_->EndOfRound(sequence_number++)); + EXPECT_FALSE(slowStart_->IsEndOfRound(sequence_number++)); } - EXPECT_TRUE(slowStart_->EndOfRound(sequence_number++)); + EXPECT_TRUE(slowStart_->IsEndOfRound(sequence_number++)); } TEST_F(HybridSlowStartTest, AckTrain) { @@ -63,12 +63,12 @@ TEST_F(HybridSlowStartTest, AckTrain) { clock_.AdvanceTime(one_ms_); slowStart_->Update(rtt_, rtt_); EXPECT_FALSE(slowStart_->Exit()); - } while (!slowStart_->EndOfRound(sequence_number++)); + } while (!slowStart_->IsEndOfRound(sequence_number++)); end_sequence_number *= 2; // Exponential growth. } slowStart_->Reset(end_sequence_number); - for (int n = 0; n < 29 && !slowStart_->EndOfRound(sequence_number++); ++n) { + for (int n = 0; n < 29 && !slowStart_->IsEndOfRound(sequence_number++); ++n) { clock_.AdvanceTime(one_ms_); slowStart_->Update(rtt_, rtt_); EXPECT_FALSE(slowStart_->Exit()); diff --git a/net/quic/congestion_control/tcp_cubic_sender.cc b/net/quic/congestion_control/tcp_cubic_sender.cc index 835be60..b08e3c6 100644 --- a/net/quic/congestion_control/tcp_cubic_sender.cc +++ b/net/quic/congestion_control/tcp_cubic_sender.cc @@ -19,7 +19,6 @@ namespace { // The minimum cwnd based on RFC 3782 (TCP NewReno) for cwnd reductions on a // fast retransmission. The cwnd after a timeout is still 1. const QuicTcpCongestionWindow kMinimumCongestionWindow = 2; -const int64 kHybridStartLowWindow = 16; const QuicByteCount kMaxSegmentSize = kDefaultTCPMSS; const QuicByteCount kDefaultReceiveWindow = 64000; const int64 kInitialCongestionWindow = 10; @@ -43,8 +42,6 @@ TcpCubicSender::TcpCubicSender( prr_delivered_(0), ack_count_since_loss_(0), bytes_in_flight_before_loss_(0), - update_end_sequence_number_(true), - end_sequence_number_(0), largest_sent_sequence_number_(0), largest_acked_sequence_number_(0), largest_sent_at_last_cutback_(0), @@ -57,6 +54,10 @@ TcpCubicSender::~TcpCubicSender() { UMA_HISTOGRAM_COUNTS("Net.QuicSession.FinalTcpCwnd", congestion_window_); } +bool TcpCubicSender::InSlowStart() const { + return congestion_window_ < slowstart_threshold_; +} + void TcpCubicSender::SetFromConfig(const QuicConfig& config, bool is_server) { if (is_server) { // Set the initial window size. @@ -79,10 +80,8 @@ void TcpCubicSender::OnPacketAcked( largest_acked_sequence_number_ = max(acked_sequence_number, largest_acked_sequence_number_); MaybeIncreaseCwnd(acked_sequence_number); - if (end_sequence_number_ == acked_sequence_number) { - DVLOG(1) << "Start update end sequence number @" << acked_sequence_number; - update_end_sequence_number_ = true; - } + // TODO(ianswett): Should this even be called when not in slow start? + hybrid_slow_start_.OnPacketAcked(acked_sequence_number, InSlowStart()); } void TcpCubicSender::OnPacketLost(QuicPacketSequenceNumber sequence_number, @@ -145,13 +144,7 @@ bool TcpCubicSender::OnPacketSent(QuicTime /*sent_time*/, // DCHECK_LT(largest_sent_sequence_number_, sequence_number); largest_sent_sequence_number_ = sequence_number; } - if (update_end_sequence_number_) { - end_sequence_number_ = sequence_number; - if (AvailableSendWindow() == 0) { - update_end_sequence_number_ = false; - DVLOG(1) << "Stop update end sequence number @" << sequence_number; - } - } + hybrid_slow_start_.OnPacketSent(sequence_number, AvailableSendWindow()); return true; } @@ -252,11 +245,7 @@ void TcpCubicSender::MaybeIncreaseCwnd( // We don't increase the congestion window during recovery. return; } - if (congestion_window_ < slowstart_threshold_) { - // Slow start. - if (hybrid_slow_start_.EndOfRound(acked_sequence_number)) { - hybrid_slow_start_.Reset(end_sequence_number_); - } + if (InSlowStart()) { // congestion_window_cnt is the number of acks since last change of snd_cwnd if (congestion_window_ < max_tcp_congestion_window_) { // TCP slow start, exponential growth, increase by one for each ACK. @@ -302,16 +291,9 @@ void TcpCubicSender::OnRetransmissionTimeout(bool packets_retransmitted) { void TcpCubicSender::UpdateRtt(QuicTime::Delta rtt) { // Hybrid start triggers when cwnd is larger than some threshold. - if (congestion_window_ <= slowstart_threshold_ && - congestion_window_ >= kHybridStartLowWindow) { - if (!hybrid_slow_start_.started()) { - // Time to start the hybrid slow start. - hybrid_slow_start_.Reset(end_sequence_number_); - } - hybrid_slow_start_.Update(rtt, rtt_stats_->min_rtt()); - if (hybrid_slow_start_.Exit()) { - slowstart_threshold_ = congestion_window_; - } + if (InSlowStart() && + hybrid_slow_start_.ShouldExitSlowStart(rtt_stats_, congestion_window_)) { + slowstart_threshold_ = congestion_window_; } } diff --git a/net/quic/congestion_control/tcp_cubic_sender.h b/net/quic/congestion_control/tcp_cubic_sender.h index 93204d4..f70511e 100644 --- a/net/quic/congestion_control/tcp_cubic_sender.h +++ b/net/quic/congestion_control/tcp_cubic_sender.h @@ -40,6 +40,8 @@ class NET_EXPORT_PRIVATE TcpCubicSender : public SendAlgorithmInterface { QuicConnectionStats* stats); virtual ~TcpCubicSender(); + bool InSlowStart() const; + // Start implementation of SendAlgorithmInterface. virtual void SetFromConfig(const QuicConfig& config, bool is_server) OVERRIDE; virtual void OnIncomingQuicCongestionFeedbackFrame( @@ -98,10 +100,6 @@ class NET_EXPORT_PRIVATE TcpCubicSender : public SendAlgorithmInterface { // The congestion window before the last loss event. QuicByteCount bytes_in_flight_before_loss_; - // We need to keep track of the end sequence number of each RTT "burst". - bool update_end_sequence_number_; - QuicPacketSequenceNumber end_sequence_number_; - // Track the largest packet that has been sent. QuicPacketSequenceNumber largest_sent_sequence_number_; diff --git a/net/quic/crypto/aead_base_decrypter_openssl.cc b/net/quic/crypto/aead_base_decrypter_openssl.cc index 4916c6d..2190bf6 100644 --- a/net/quic/crypto/aead_base_decrypter_openssl.cc +++ b/net/quic/crypto/aead_base_decrypter_openssl.cc @@ -17,8 +17,14 @@ namespace { // Clear OpenSSL error stack. void ClearOpenSslErrors() { -#ifdef NDEBUG while (ERR_get_error()) {} +} + +// In debug builds only, log OpenSSL error stack. Then clear OpenSSL error +// stack. +void DLogOpenSslErrors() { +#ifdef NDEBUG + ClearOpenSslErrors(); #else while (unsigned long error = ERR_get_error()) { char buf[120]; @@ -54,7 +60,7 @@ bool AeadBaseDecrypter::SetKey(StringPiece key) { EVP_AEAD_CTX_cleanup(ctx_.get()); if (!EVP_AEAD_CTX_init(ctx_.get(), aead_alg_, key_, key_size_, auth_tag_size_, NULL)) { - ClearOpenSslErrors(); + DLogOpenSslErrors(); return false; } @@ -88,6 +94,8 @@ bool AeadBaseDecrypter::Decrypt(StringPiece nonce, associated_data.size()); if (len < 0) { + // Because QuicFramer does trial decryption, decryption errors are expected + // when encryption level changes. So we don't log decryption errors. ClearOpenSslErrors(); return false; } diff --git a/net/quic/crypto/aead_base_encrypter_openssl.cc b/net/quic/crypto/aead_base_encrypter_openssl.cc index 8ab3902..9f053ab 100644 --- a/net/quic/crypto/aead_base_encrypter_openssl.cc +++ b/net/quic/crypto/aead_base_encrypter_openssl.cc @@ -16,8 +16,9 @@ namespace net { namespace { -// Clear OpenSSL error stack. -void ClearOpenSslErrors() { +// In debug builds only, log OpenSSL error stack. Then clear OpenSSL error +// stack. +void DLogOpenSslErrors() { #ifdef NDEBUG while (ERR_get_error()) {} #else @@ -56,7 +57,7 @@ bool AeadBaseEncrypter::SetKey(StringPiece key) { if (!EVP_AEAD_CTX_init(ctx_.get(), aead_alg_, key_, key_size_, auth_tag_size_, NULL)) { - ClearOpenSslErrors(); + DLogOpenSslErrors(); return false; } @@ -88,7 +89,7 @@ bool AeadBaseEncrypter::Encrypt(StringPiece nonce, associated_data.size()); if (len < 0) { - ClearOpenSslErrors(); + DLogOpenSslErrors(); return false; } diff --git a/net/quic/crypto/quic_crypto_client_config.cc b/net/quic/crypto/quic_crypto_client_config.cc index b802005..e58e4d1 100644 --- a/net/quic/crypto/quic_crypto_client_config.cc +++ b/net/quic/crypto/quic_crypto_client_config.cc @@ -17,7 +17,7 @@ #include "net/quic/crypto/p256_key_exchange.h" #include "net/quic/crypto/proof_verifier.h" #include "net/quic/crypto/quic_encrypter.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "net/quic/quic_utils.h" using base::StringPiece; @@ -260,20 +260,20 @@ void QuicCryptoClientConfig::SetDefaults() { } QuicCryptoClientConfig::CachedState* QuicCryptoClientConfig::LookupOrCreate( - const QuicSessionKey& server_key) { - CachedStateMap::const_iterator it = cached_states_.find(server_key); + const QuicServerId& server_id) { + CachedStateMap::const_iterator it = cached_states_.find(server_id); if (it != cached_states_.end()) { return it->second; } CachedState* cached = new CachedState; - cached_states_.insert(make_pair(server_key, cached)); - PopulateFromCanonicalConfig(server_key, cached); + cached_states_.insert(make_pair(server_id, cached)); + PopulateFromCanonicalConfig(server_id, cached); return cached; } void QuicCryptoClientConfig::FillInchoateClientHello( - const QuicSessionKey& server_key, + const QuicServerId& server_id, const QuicVersion preferred_version, const CachedState* cached, QuicCryptoNegotiatedParameters* out_params, @@ -283,8 +283,8 @@ void QuicCryptoClientConfig::FillInchoateClientHello( // Server name indication. We only send SNI if it's a valid domain name, as // per the spec. - if (CryptoUtils::IsValidSNI(server_key.host())) { - out->SetStringPiece(kSNI, server_key.host()); + if (CryptoUtils::IsValidSNI(server_id.host())) { + out->SetStringPiece(kSNI, server_id.host()); } out->SetValue(kVER, QuicVersionToQuicTag(preferred_version)); @@ -292,7 +292,7 @@ void QuicCryptoClientConfig::FillInchoateClientHello( out->SetStringPiece(kSourceAddressTokenTag, cached->source_address_token()); } - if (server_key.is_https()) { + if (server_id.is_https()) { if (disable_ecdsa_) { out->SetTaglist(kPDMD, kX59R, 0); } else { @@ -322,7 +322,7 @@ void QuicCryptoClientConfig::FillInchoateClientHello( } QuicErrorCode QuicCryptoClientConfig::FillClientHello( - const QuicSessionKey& server_key, + const QuicServerId& server_id, QuicConnectionId connection_id, const QuicVersion preferred_version, uint32 initial_flow_control_window_bytes, @@ -334,7 +334,7 @@ QuicErrorCode QuicCryptoClientConfig::FillClientHello( string* error_details) const { DCHECK(error_details != NULL); - FillInchoateClientHello(server_key, preferred_version, cached, + FillInchoateClientHello(server_id, preferred_version, cached, out_params, out); // Set initial receive window for flow control. @@ -462,7 +462,7 @@ QuicErrorCode QuicCryptoClientConfig::FillClientHello( hkdf_input.append(cached->server_config()); string key, signature; - if (!channel_id_signer_->Sign(server_key.host(), hkdf_input, + if (!channel_id_signer_->Sign(server_id.host(), hkdf_input, &key, &signature)) { *error_details = "Channel ID signature failed"; return QUIC_INVALID_CHANNEL_ID_SIGNATURE; @@ -675,15 +675,15 @@ void QuicCryptoClientConfig::SetChannelIDSigner(ChannelIDSigner* signer) { } void QuicCryptoClientConfig::InitializeFrom( - const QuicSessionKey& server_key, - const QuicSessionKey& canonical_server_key, + const QuicServerId& server_id, + const QuicServerId& canonical_server_id, QuicCryptoClientConfig* canonical_crypto_config) { CachedState* canonical_cached = - canonical_crypto_config->LookupOrCreate(canonical_server_key); + canonical_crypto_config->LookupOrCreate(canonical_server_id); if (!canonical_cached->proof_valid()) { return; } - CachedState* cached = LookupOrCreate(server_key); + CachedState* cached = LookupOrCreate(server_id); cached->InitializeFrom(*canonical_cached); } @@ -708,37 +708,37 @@ void QuicCryptoClientConfig::DisableEcdsa() { } void QuicCryptoClientConfig::PopulateFromCanonicalConfig( - const QuicSessionKey& server_key, + const QuicServerId& server_id, CachedState* server_state) { DCHECK(server_state->IsEmpty()); unsigned i = 0; for (; i < canoncial_suffixes_.size(); ++i) { - if (EndsWith(server_key.host(), canoncial_suffixes_[i], false)) { + if (EndsWith(server_id.host(), canoncial_suffixes_[i], false)) { break; } } if (i == canoncial_suffixes_.size()) return; - QuicSessionKey suffix_server_key(canoncial_suffixes_[i], server_key.port(), - server_key.is_https(), - server_key.privacy_mode()); - if (!ContainsKey(canonical_server_map_, suffix_server_key)) { + QuicServerId suffix_server_id(canoncial_suffixes_[i], server_id.port(), + server_id.is_https(), + server_id.privacy_mode()); + if (!ContainsKey(canonical_server_map_, suffix_server_id)) { // This is the first host we've seen which matches the suffix, so make it // canonical. - canonical_server_map_[suffix_server_key] = server_key; + canonical_server_map_[suffix_server_id] = server_id; return; } - const QuicSessionKey& canonical_server_key = - canonical_server_map_[suffix_server_key]; - CachedState* canonical_state = cached_states_[canonical_server_key]; + const QuicServerId& canonical_server_id = + canonical_server_map_[suffix_server_id]; + CachedState* canonical_state = cached_states_[canonical_server_id]; if (!canonical_state->proof_valid()) { return; } // Update canonical version to point at the "most recent" entry. - canonical_server_map_[suffix_server_key] = server_key; + canonical_server_map_[suffix_server_id] = server_id; server_state->InitializeFrom(*canonical_state); } diff --git a/net/quic/crypto/quic_crypto_client_config.h b/net/quic/crypto/quic_crypto_client_config.h index b18e503..f88dcdf 100644 --- a/net/quic/crypto/quic_crypto_client_config.h +++ b/net/quic/crypto/quic_crypto_client_config.h @@ -14,6 +14,7 @@ #include "net/base/net_export.h" #include "net/quic/crypto/crypto_handshake.h" #include "net/quic/quic_protocol.h" +#include "net/quic/quic_server_id.h" namespace net { @@ -22,7 +23,6 @@ class CryptoHandshakeMessage; class ProofVerifier; class ProofVerifyDetails; class QuicRandom; -class QuicSessionKey; // QuicCryptoClientConfig contains crypto-related configuration settings for a // client. Note that this object isn't thread-safe. It's designed to be used on @@ -132,9 +132,9 @@ class NET_EXPORT_PRIVATE QuicCryptoClientConfig : public QuicCryptoConfig { // Sets the members to reasonable, default values. void SetDefaults(); - // LookupOrCreate returns a CachedState for the given |server_key|. If no such + // LookupOrCreate returns a CachedState for the given |server_id|. If no such // CachedState currently exists, it will be created and cached. - CachedState* LookupOrCreate(const QuicSessionKey& server_key); + CachedState* LookupOrCreate(const QuicServerId& server_id); // FillInchoateClientHello sets |out| to be a CHLO message that elicits a // source-address token or SCFG from a server. If |cached| is non-NULL, the @@ -143,7 +143,7 @@ class NET_EXPORT_PRIVATE QuicCryptoClientConfig : public QuicCryptoConfig { // |out_params->cached_certs|. |preferred_version| is the version of the // QUIC protocol that this client chose to use initially. This allows the // server to detect downgrade attacks. - void FillInchoateClientHello(const QuicSessionKey& server_key, + void FillInchoateClientHello(const QuicServerId& server_id, const QuicVersion preferred_version, const CachedState* cached, QuicCryptoNegotiatedParameters* out_params, @@ -162,7 +162,7 @@ class NET_EXPORT_PRIVATE QuicCryptoClientConfig : public QuicCryptoConfig { // accept. |preferred_version| is the version of the QUIC protocol that this // client chose to use initially. This allows the server to detect downgrade // attacks. - QuicErrorCode FillClientHello(const QuicSessionKey& server_key, + QuicErrorCode FillClientHello(const QuicServerId& server_id, QuicConnectionId connection_id, const QuicVersion preferred_version, uint32 initial_flow_control_window_bytes, @@ -216,10 +216,10 @@ class NET_EXPORT_PRIVATE QuicCryptoClientConfig : public QuicCryptoConfig { void SetChannelIDSigner(ChannelIDSigner* signer); // Initialize the CachedState from |canonical_crypto_config| for the - // |canonical_server_key| as the initial CachedState for |server_key|. We will + // |canonical_server_id| as the initial CachedState for |server_id|. We will // copy config data only if |canonical_crypto_config| has valid proof. - void InitializeFrom(const QuicSessionKey& server_key, - const QuicSessionKey& canonical_server_key, + void InitializeFrom(const QuicServerId& server_id, + const QuicServerId& canonical_server_id, QuicCryptoClientConfig* canonical_crypto_config); // Adds |suffix| as a domain suffix for which the server's crypto config @@ -239,15 +239,15 @@ class NET_EXPORT_PRIVATE QuicCryptoClientConfig : public QuicCryptoConfig { void DisableEcdsa(); private: - typedef std::map<QuicSessionKey, CachedState*> CachedStateMap; + typedef std::map<QuicServerId, CachedState*> CachedStateMap; - // If the suffix of the hostname in |server_key| is in |canoncial_suffixes_|, + // If the suffix of the hostname in |server_id| is in |canoncial_suffixes_|, // then populate |cached| with the canonical cached state from // |canonical_server_map_| for that suffix. - void PopulateFromCanonicalConfig(const QuicSessionKey& server_key, + void PopulateFromCanonicalConfig(const QuicServerId& server_id, CachedState* cached); - // cached_states_ maps from the server_key to the cached information about + // cached_states_ maps from the server_id to the cached information about // that server. CachedStateMap cached_states_; @@ -255,7 +255,7 @@ class NET_EXPORT_PRIVATE QuicCryptoClientConfig : public QuicCryptoConfig { // from a canonical host suffix/port/scheme to a representative server with // the canonical suffix, which has a plausible set of initial certificates // (or at least server public key). - std::map<QuicSessionKey, QuicSessionKey> canonical_server_map_; + std::map<QuicServerId, QuicServerId> canonical_server_map_; // Contains list of suffixes (for exmaple ".c.youtube.com", // ".googlevideo.com") of canoncial hostnames. diff --git a/net/quic/crypto/quic_crypto_client_config_test.cc b/net/quic/crypto/quic_crypto_client_config_test.cc index 3680b77..a085d16 100644 --- a/net/quic/crypto/quic_crypto_client_config_test.cc +++ b/net/quic/crypto/quic_crypto_client_config_test.cc @@ -5,7 +5,7 @@ #include "net/quic/crypto/quic_crypto_client_config.h" #include "net/quic/crypto/proof_verifier.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "net/quic/test_tools/mock_random.h" #include "net/quic/test_tools/quic_test_utils.h" #include "testing/gtest/include/gtest/gtest.h" @@ -57,8 +57,8 @@ TEST(QuicCryptoClientConfigTest, InchoateChlo) { QuicCryptoClientConfig config; QuicCryptoNegotiatedParameters params; CryptoHandshakeMessage msg; - QuicSessionKey server_key("www.google.com", 80, false, PRIVACY_MODE_DISABLED); - config.FillInchoateClientHello(server_key, QuicVersionMax(), &state, + QuicServerId server_id("www.google.com", 80, false, PRIVACY_MODE_DISABLED); + config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, ¶ms, &msg); QuicTag cver; @@ -75,8 +75,8 @@ TEST(QuicCryptoClientConfigTest, FillClientHello) { string error_details; MockRandom rand; CryptoHandshakeMessage chlo; - QuicSessionKey server_key("www.google.com", 80, false, PRIVACY_MODE_DISABLED); - config.FillClientHello(server_key, + QuicServerId server_id("www.google.com", 80, false, PRIVACY_MODE_DISABLED); + config.FillClientHello(server_id, kConnectionId, QuicVersionMax(), kInitialFlowControlWindow, @@ -102,8 +102,8 @@ TEST(QuicCryptoClientConfigTest, InchoateChloSecure) { QuicCryptoClientConfig config; QuicCryptoNegotiatedParameters params; CryptoHandshakeMessage msg; - QuicSessionKey server_key("www.google.com", 443, true, PRIVACY_MODE_DISABLED); - config.FillInchoateClientHello(server_key, QuicVersionMax(), &state, + QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); + config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, ¶ms, &msg); QuicTag pdmd; @@ -117,8 +117,8 @@ TEST(QuicCryptoClientConfigTest, InchoateChloSecureNoEcdsa) { config.DisableEcdsa(); QuicCryptoNegotiatedParameters params; CryptoHandshakeMessage msg; - QuicSessionKey server_key("www.google.com", 443, true, PRIVACY_MODE_DISABLED); - config.FillInchoateClientHello(server_key, QuicVersionMax(), &state, + QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); + config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, ¶ms, &msg); QuicTag pdmd; @@ -153,17 +153,19 @@ TEST(QuicCryptoClientConfigTest, ProcessServerDowngradeAttack) { TEST(QuicCryptoClientConfigTest, InitializeFrom) { QuicCryptoClientConfig config; - QuicSessionKey canonical_key1("www.google.com", 80, false, - PRIVACY_MODE_DISABLED); + QuicServerId canonical_server_id("www.google.com", 80, false, + PRIVACY_MODE_DISABLED); QuicCryptoClientConfig::CachedState* state = - config.LookupOrCreate(canonical_key1); + config.LookupOrCreate(canonical_server_id); // TODO(rch): Populate other fields of |state|. state->set_source_address_token("TOKEN"); state->SetProofValid(); - QuicSessionKey other_key("mail.google.com", 80, false, PRIVACY_MODE_DISABLED); - config.InitializeFrom(other_key, canonical_key1, &config); - QuicCryptoClientConfig::CachedState* other = config.LookupOrCreate(other_key); + QuicServerId other_server_id("mail.google.com", 80, false, + PRIVACY_MODE_DISABLED); + config.InitializeFrom(other_server_id, canonical_server_id, &config); + QuicCryptoClientConfig::CachedState* other = + config.LookupOrCreate(other_server_id); EXPECT_EQ(state->server_config(), other->server_config()); EXPECT_EQ(state->source_address_token(), other->source_address_token()); diff --git a/net/quic/crypto/quic_server_info.cc b/net/quic/crypto/quic_server_info.cc index ab2a062..519d7b5 100644 --- a/net/quic/crypto/quic_server_info.cc +++ b/net/quic/crypto/quic_server_info.cc @@ -29,8 +29,8 @@ void QuicServerInfo::State::Clear() { certs.clear(); } -QuicServerInfo::QuicServerInfo(const QuicSessionKey& server_key) - : server_key_(server_key) { +QuicServerInfo::QuicServerInfo(const QuicServerId& server_id) + : server_id_(server_id) { } QuicServerInfo::~QuicServerInfo() { diff --git a/net/quic/crypto/quic_server_info.h b/net/quic/crypto/quic_server_info.h index 0f09f3b..8b3db5f 100644 --- a/net/quic/crypto/quic_server_info.h +++ b/net/quic/crypto/quic_server_info.h @@ -13,7 +13,7 @@ #include "base/time/time.h" #include "net/base/completion_callback.h" #include "net/base/net_export.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" namespace net { @@ -25,7 +25,7 @@ class X509Certificate; // crypto config. class NET_EXPORT_PRIVATE QuicServerInfo { public: - QuicServerInfo(const QuicSessionKey& server_key); + QuicServerInfo(const QuicServerId& server_id); virtual ~QuicServerInfo(); // Start will commence the lookup. This must be called before any other @@ -97,9 +97,9 @@ class NET_EXPORT_PRIVATE QuicServerInfo { // SerializeInner is a helper function for Serialize. std::string SerializeInner() const; - // This is the QUIC server (hostname, port, is_https) tuple for which we - // restore the crypto_config. - const QuicSessionKey server_key_; + // This is the QUIC server (hostname, port, is_https, privacy_mode) tuple for + // which we restore the crypto_config. + const QuicServerId server_id_; }; class QuicServerInfoFactory { @@ -107,8 +107,8 @@ class QuicServerInfoFactory { virtual ~QuicServerInfoFactory(); // GetForServer returns a fresh, allocated QuicServerInfo for the given - // |server_key| or NULL on failure. - virtual QuicServerInfo* GetForServer(const QuicSessionKey& server_key) = 0; + // |server_id| or NULL on failure. + virtual QuicServerInfo* GetForServer(const QuicServerId& server_id) = 0; }; } // namespace net diff --git a/net/quic/quic_client_session.cc b/net/quic/quic_client_session.cc index 5b14c7d..f511474 100644 --- a/net/quic/quic_client_session.cc +++ b/net/quic/quic_client_session.cc @@ -18,7 +18,7 @@ #include "net/quic/quic_connection_helper.h" #include "net/quic/quic_crypto_client_stream_factory.h" #include "net/quic/quic_default_packet_writer.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "net/quic/quic_stream_factory.h" #include "net/ssl/ssl_connection_status_flags.h" #include "net/ssl/ssl_info.h" @@ -119,7 +119,7 @@ QuicClientSession::QuicClientSession( QuicStreamFactory* stream_factory, QuicCryptoClientStreamFactory* crypto_client_stream_factory, scoped_ptr<QuicServerInfo> server_info, - const QuicSessionKey& server_key, + const QuicServerId& server_id, const QuicConfig& config, QuicCryptoClientConfig* crypto_config, NetLog* net_log) @@ -140,8 +140,8 @@ QuicClientSession::QuicClientSession( crypto_stream_.reset( crypto_client_stream_factory ? crypto_client_stream_factory->CreateQuicCryptoClientStream( - server_key, this, crypto_config) : - new QuicCryptoClientStream(server_key, this, + server_id, this, crypto_config) : + new QuicCryptoClientStream(server_id, this, new ProofVerifyContextChromium(net_log_), crypto_config)); @@ -149,7 +149,7 @@ QuicClientSession::QuicClientSession( // TODO(rch): pass in full host port proxy pair net_log_.BeginEvent( NetLog::TYPE_QUIC_SESSION, - NetLog::StringCallback("host", &server_key.host())); + NetLog::StringCallback("host", &server_id.host())); } QuicClientSession::~QuicClientSession() { diff --git a/net/quic/quic_client_session.h b/net/quic/quic_client_session.h index 801ad07..9ad12ed 100644 --- a/net/quic/quic_client_session.h +++ b/net/quic/quic_client_session.h @@ -30,7 +30,7 @@ class DatagramClientSocket; class QuicConnectionHelper; class QuicCryptoClientStreamFactory; class QuicDefaultPacketWriter; -class QuicSessionKey; +class QuicServerId; class QuicServerInfo; class QuicStreamFactory; class SSLInfo; @@ -95,7 +95,7 @@ class NET_EXPORT_PRIVATE QuicClientSession : public QuicClientSessionBase { QuicStreamFactory* stream_factory, QuicCryptoClientStreamFactory* crypto_client_stream_factory, scoped_ptr<QuicServerInfo> server_info, - const QuicSessionKey& server_key, + const QuicServerId& server_id, const QuicConfig& config, QuicCryptoClientConfig* crypto_config, NetLog* net_log); diff --git a/net/quic/quic_client_session_test.cc b/net/quic/quic_client_session_test.cc index 99fbaf3..58ef26c 100644 --- a/net/quic/quic_client_session_test.cc +++ b/net/quic/quic_client_session_test.cc @@ -70,8 +70,8 @@ class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { new PacketSavingConnection(false, SupportedVersions(GetParam()))), session_(connection_, GetSocket().Pass(), writer_.Pass(), NULL, NULL, make_scoped_ptr((QuicServerInfo*)NULL), - QuicSessionKey(kServerHostname, kServerPort, false, - PRIVACY_MODE_DISABLED), + QuicServerId(kServerHostname, kServerPort, false, + PRIVACY_MODE_DISABLED), DefaultQuicConfig(), &crypto_config_, &net_log_) { session_.config()->SetDefaults(); crypto_config_.SetDefaults(); diff --git a/net/quic/quic_connection.cc b/net/quic/quic_connection.cc index 95771e2..4f409a0 100644 --- a/net/quic/quic_connection.cc +++ b/net/quic/quic_connection.cc @@ -519,20 +519,19 @@ void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) { sent_entropy_manager_.ClearEntropyBefore( received_packet_manager_.least_packet_awaited_by_peer() - 1); - bool reset_retransmission_alarm = - sent_packet_manager_.OnIncomingAck(incoming_ack.received_info, - time_of_last_received_packet_); + sent_packet_manager_.OnIncomingAck(incoming_ack.received_info, + time_of_last_received_packet_); if (sent_packet_manager_.HasPendingRetransmissions()) { WriteIfNotBlocked(); } - if (reset_retransmission_alarm) { - retransmission_alarm_->Cancel(); - QuicTime retransmission_time = - sent_packet_manager_.GetRetransmissionTime(); - if (retransmission_time != QuicTime::Zero()) { - retransmission_alarm_->Set(retransmission_time); - } + // Always reset the retransmission alarm when an ack comes in, since we now + // have a better estimate of the current rtt than when it was set. + retransmission_alarm_->Cancel(); + QuicTime retransmission_time = + sent_packet_manager_.GetRetransmissionTime(); + if (retransmission_time != QuicTime::Zero()) { + retransmission_alarm_->Set(retransmission_time); } } diff --git a/net/quic/quic_crypto_client_stream.cc b/net/quic/quic_crypto_client_stream.cc index c7d99ca..0ae7247 100644 --- a/net/quic/quic_crypto_client_stream.cc +++ b/net/quic/quic_crypto_client_stream.cc @@ -43,7 +43,7 @@ void QuicCryptoClientStream::ProofVerifierCallbackImpl::Cancel() { } QuicCryptoClientStream::QuicCryptoClientStream( - const QuicSessionKey& server_key, + const QuicServerId& server_id, QuicClientSessionBase* session, ProofVerifyContext* verify_context, QuicCryptoClientConfig* crypto_config) @@ -51,7 +51,7 @@ QuicCryptoClientStream::QuicCryptoClientStream( next_state_(STATE_IDLE), num_client_hellos_(0), crypto_config_(crypto_config), - server_key_(server_key), + server_id_(server_id), generation_counter_(0), proof_verify_callback_(NULL), verify_context_(verify_context) { @@ -93,7 +93,7 @@ void QuicCryptoClientStream::DoHandshakeLoop( QuicErrorCode error; string error_details; QuicCryptoClientConfig::CachedState* cached = - crypto_config_->LookupOrCreate(server_key_); + crypto_config_->LookupOrCreate(server_id_); if (in != NULL) { DVLOG(1) << "Client: Received " << in->DebugString(); @@ -105,7 +105,7 @@ void QuicCryptoClientStream::DoHandshakeLoop( switch (state) { case STATE_INITIALIZE: { if (!cached->IsEmpty() && !cached->signature().empty() && - server_key_.is_https()) { + server_id_.is_https()) { DCHECK(crypto_config_->proof_verifier()); // If the cached state needs to be verified, do it now. next_state_ = STATE_VERIFY_PROOF; @@ -125,9 +125,11 @@ void QuicCryptoClientStream::DoHandshakeLoop( if (!cached->IsComplete(session()->connection()->clock()->WallNow())) { crypto_config_->FillInchoateClientHello( - server_key_, + server_id_, session()->connection()->supported_versions().front(), - cached, &crypto_negotiated_params_, &out); + cached, + &crypto_negotiated_params_, + &out); // Pad the inchoate client hello to fill up a packet. const size_t kFramingOverhead = 50; // A rough estimate. const size_t max_packet_size = @@ -151,7 +153,7 @@ void QuicCryptoClientStream::DoHandshakeLoop( } session()->config()->ToHandshakeMessage(&out); error = crypto_config_->FillClientHello( - server_key_, + server_id_, session()->connection()->connection_id(), session()->connection()->supported_versions().front(), session()->connection()->max_flow_control_receive_window_bytes(), @@ -214,7 +216,7 @@ void QuicCryptoClientStream::DoHandshakeLoop( return; } if (!cached->proof_valid()) { - if (!server_key_.is_https()) { + if (!server_id_.is_https()) { // We don't check the certificates for insecure QUIC connections. SetCachedProofValid(cached); } else if (!cached->signature().empty()) { @@ -236,7 +238,7 @@ void QuicCryptoClientStream::DoHandshakeLoop( verify_ok_ = false; ProofVerifier::Status status = verifier->VerifyProof( - server_key_.host(), + server_id_.host(), cached->server_config(), cached->certs(), cached->signature(), diff --git a/net/quic/quic_crypto_client_stream.h b/net/quic/quic_crypto_client_stream.h index aef96cc..5bb50ef 100644 --- a/net/quic/quic_crypto_client_stream.h +++ b/net/quic/quic_crypto_client_stream.h @@ -11,7 +11,7 @@ #include "net/quic/crypto/quic_crypto_client_config.h" #include "net/quic/quic_config.h" #include "net/quic/quic_crypto_stream.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" namespace net { @@ -23,7 +23,7 @@ class CryptoTestUtils; class NET_EXPORT_PRIVATE QuicCryptoClientStream : public QuicCryptoStream { public: - QuicCryptoClientStream(const QuicSessionKey& server_key, + QuicCryptoClientStream(const QuicServerId& server_id, QuicClientSessionBase* session, ProofVerifyContext* verify_context, QuicCryptoClientConfig* crypto_config); @@ -97,8 +97,8 @@ class NET_EXPORT_PRIVATE QuicCryptoClientStream : public QuicCryptoStream { // Client's connection nonce (4-byte timestamp + 28 random bytes) std::string nonce_; - // Server's (hostname, port, is_https) tuple. - const QuicSessionKey server_key_; + // Server's (hostname, port, is_https, privacy_mode) tuple. + const QuicServerId server_id_; // Generation counter from QuicCryptoClientConfig's CachedState. uint64 generation_counter_; diff --git a/net/quic/quic_crypto_client_stream_factory.h b/net/quic/quic_crypto_client_stream_factory.h index 5f160b0..293fa82 100644 --- a/net/quic/quic_crypto_client_stream_factory.h +++ b/net/quic/quic_crypto_client_stream_factory.h @@ -13,7 +13,7 @@ namespace net { class QuicClientSession; class QuicCryptoClientStream; -class QuicSessionKey; +class QuicServerId; // An interface used to instantiate QuicCryptoClientStream objects. Used to // facilitate testing code with mock implementations. @@ -22,7 +22,7 @@ class NET_EXPORT QuicCryptoClientStreamFactory { virtual ~QuicCryptoClientStreamFactory() {} virtual QuicCryptoClientStream* CreateQuicCryptoClientStream( - const QuicSessionKey& server_key, + const QuicServerId& server_id, QuicClientSession* session, QuicCryptoClientConfig* crypto_config) = 0; }; diff --git a/net/quic/quic_crypto_client_stream_test.cc b/net/quic/quic_crypto_client_stream_test.cc index ea11677..14ff3fd 100644 --- a/net/quic/quic_crypto_client_stream_test.cc +++ b/net/quic/quic_crypto_client_stream_test.cc @@ -10,7 +10,7 @@ #include "net/quic/crypto/quic_encrypter.h" #include "net/quic/quic_flags.h" #include "net/quic/quic_protocol.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "net/quic/test_tools/crypto_test_utils.h" #include "net/quic/test_tools/quic_test_utils.h" #include "net/quic/test_tools/simple_quic_framer.h" @@ -29,9 +29,9 @@ class QuicCryptoClientStreamTest : public ::testing::Test { QuicCryptoClientStreamTest() : connection_(new PacketSavingConnection(false)), session_(new TestClientSession(connection_, DefaultQuicConfig())), - server_key_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED), + server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED), stream_(new QuicCryptoClientStream( - server_key_, session_.get(), NULL, &crypto_config_)) { + server_id_, session_.get(), NULL, &crypto_config_)) { session_->SetCryptoStream(stream_.get()); session_->config()->SetDefaults(); crypto_config_.SetDefaults(); @@ -49,7 +49,7 @@ class QuicCryptoClientStreamTest : public ::testing::Test { PacketSavingConnection* connection_; scoped_ptr<TestClientSession> session_; - QuicSessionKey server_key_; + QuicServerId server_id_; scoped_ptr<QuicCryptoClientStream> stream_; CryptoHandshakeMessage message_; scoped_ptr<QuicData> message_data_; @@ -107,8 +107,8 @@ TEST_F(QuicCryptoClientStreamTest, NegotiatedParameters) { } TEST_F(QuicCryptoClientStreamTest, InvalidHostname) { - QuicSessionKey server_key("invalid", 80, false, PRIVACY_MODE_DISABLED); - stream_.reset(new QuicCryptoClientStream(server_key, session_.get(), NULL, + QuicServerId server_id("invalid", 80, false, PRIVACY_MODE_DISABLED); + stream_.reset(new QuicCryptoClientStream(server_id, session_.get(), NULL, &crypto_config_)); session_->SetCryptoStream(stream_.get()); @@ -123,7 +123,7 @@ TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { connection_ = new PacketSavingConnection(true); session_.reset(new TestClientSession(connection_, DefaultQuicConfig())); - stream_.reset(new QuicCryptoClientStream(server_key_, session_.get(), NULL, + stream_.reset(new QuicCryptoClientStream(server_id_, session_.get(), NULL, &crypto_config_)); session_->SetCryptoStream(stream_.get()); diff --git a/net/quic/quic_crypto_server_stream_test.cc b/net/quic/quic_crypto_server_stream_test.cc index 49adea8..bbc0525 100644 --- a/net/quic/quic_crypto_server_stream_test.cc +++ b/net/quic/quic_crypto_server_stream_test.cc @@ -145,10 +145,10 @@ TEST_P(QuicCryptoServerStreamTest, ZeroRTT) { QuicCryptoClientConfig client_crypto_config; client_crypto_config.SetDefaults(); - QuicSessionKey server_key(kServerHostname, kServerPort, false, - PRIVACY_MODE_DISABLED); + QuicServerId server_id(kServerHostname, kServerPort, false, + PRIVACY_MODE_DISABLED); scoped_ptr<QuicCryptoClientStream> client(new QuicCryptoClientStream( - server_key, client_session.get(), NULL, &client_crypto_config)); + server_id, client_session.get(), NULL, &client_crypto_config)); client_session->SetCryptoStream(client.get()); // Do a first handshake in order to prime the client config with the server's @@ -182,7 +182,7 @@ TEST_P(QuicCryptoServerStreamTest, ZeroRTT) { client_session.reset(new TestClientSession(client_conn, client_config)); server_session.reset(new TestClientSession(server_conn, config_)); client.reset(new QuicCryptoClientStream( - server_key, client_session.get(), NULL, &client_crypto_config)); + server_id, client_session.get(), NULL, &client_crypto_config)); client_session->SetCryptoStream(client.get()); server.reset(new QuicCryptoServerStream(crypto_config_, diff --git a/net/quic/quic_framer.cc b/net/quic/quic_framer.cc index 26bdc02..674000b 100644 --- a/net/quic/quic_framer.cc +++ b/net/quic/quic_framer.cc @@ -1829,6 +1829,7 @@ bool QuicFramer::DecryptPayload(const QuicPacketHeader& header, } if (decrypted_.get() == NULL) { + DLOG(WARNING) << "DecryptPacket failed"; return false; } diff --git a/net/quic/quic_http_stream_test.cc b/net/quic/quic_http_stream_test.cc index 39e48c3..46bfa57 100644 --- a/net/quic/quic_http_stream_test.cc +++ b/net/quic/quic_http_stream_test.cc @@ -208,8 +208,8 @@ class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> { writer_.Pass(), NULL, &crypto_client_stream_factory_, make_scoped_ptr((QuicServerInfo*)NULL), - QuicSessionKey(kServerHostname, kServerPort, - false, PRIVACY_MODE_DISABLED), + QuicServerId(kServerHostname, kServerPort, + false, PRIVACY_MODE_DISABLED), DefaultQuicConfig(), &crypto_config_, NULL)); session_->GetCryptoStream()->CryptoConnect(); EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed()); diff --git a/net/quic/quic_packet_creator.cc b/net/quic/quic_packet_creator.cc index 97c4c18..aa52c7d 100644 --- a/net/quic/quic_packet_creator.cc +++ b/net/quic/quic_packet_creator.cc @@ -170,31 +170,11 @@ size_t QuicPacketCreator::CreateStreamFrame(QuicStreamId id, return 0; } - const size_t free_bytes = BytesFree(); - size_t bytes_consumed = 0; const size_t data_size = data.TotalBufferSize(); - - // When a STREAM frame is the last frame in a packet, it consumes two fewer - // bytes of framing overhead. - // Anytime more data is available than fits in with the extra two bytes, - // the frame will be the last, and up to two extra bytes are consumed. - // TODO(ianswett): If QUIC pads, the 1 byte PADDING frame does not fit when - // 1 byte is available, because then the STREAM frame isn't the last. - - // The minimum frame size(0 bytes of data) if it's not the last frame. - size_t min_frame_size = QuicFramer::GetMinStreamFrameSize( - framer_->version(), id, offset, false); - // Check if it's the last frame in the packet. - if (data_size + min_frame_size > free_bytes) { - // The minimum frame size(0 bytes of data) if it is the last frame. - size_t min_last_frame_size = QuicFramer::GetMinStreamFrameSize( - framer_->version(), id, offset, true); - bytes_consumed = - min<size_t>(free_bytes - min_last_frame_size, data_size); - } else { - DCHECK_LT(data_size, BytesFree()); - bytes_consumed = data_size; - } + size_t min_last_frame_size = QuicFramer::GetMinStreamFrameSize( + framer_->version(), id, offset, /*last_frame_in_packet=*/ true); + size_t bytes_consumed = + min<size_t>(BytesFree() - min_last_frame_size, data_size); bool set_fin = fin && bytes_consumed == data_size; // Last frame. IOVector frame_data; diff --git a/net/quic/quic_sent_packet_manager.cc b/net/quic/quic_sent_packet_manager.cc index 3509ae7..eccffbf 100644 --- a/net/quic/quic_sent_packet_manager.cc +++ b/net/quic/quic_sent_packet_manager.cc @@ -117,7 +117,7 @@ void QuicSentPacketManager::OnRetransmittedPacket( new_sequence_number); } -bool QuicSentPacketManager::OnIncomingAck( +void QuicSentPacketManager::OnIncomingAck( const ReceivedPacketInfo& received_info, QuicTime ack_receive_time) { // We rely on delta_time_largest_observed to compute an RTT estimate, so // we only update rtt when the largest observed gets acked. @@ -136,10 +136,6 @@ bool QuicSentPacketManager::OnIncomingAck( consecutive_tlp_count_ = 0; consecutive_crypto_retransmission_count_ = 0; } - - // Always reset the retransmission alarm when an ack comes in, since we now - // have a better estimate of the current rtt than when it was set. - return true; } void QuicSentPacketManager::DiscardUnackedPacket( diff --git a/net/quic/quic_sent_packet_manager.h b/net/quic/quic_sent_packet_manager.h index 0f7266c..d2fe0b8 100644 --- a/net/quic/quic_sent_packet_manager.h +++ b/net/quic/quic_sent_packet_manager.h @@ -78,9 +78,8 @@ class NET_EXPORT_PRIVATE QuicSentPacketManager { void OnRetransmittedPacket(QuicPacketSequenceNumber old_sequence_number, QuicPacketSequenceNumber new_sequence_number); - // Processes the incoming ack and returns true if the retransmission or ack - // alarm should be reset. - bool OnIncomingAck(const ReceivedPacketInfo& received_info, + // Processes the incoming ack. + void OnIncomingAck(const ReceivedPacketInfo& received_info, QuicTime ack_receive_time); // Discards any information for the packet corresponding to |sequence_number|. diff --git a/net/quic/quic_sent_packet_manager_test.cc b/net/quic/quic_sent_packet_manager_test.cc index c6a1e29..b186cc0 100644 --- a/net/quic/quic_sent_packet_manager_test.cc +++ b/net/quic/quic_sent_packet_manager_test.cc @@ -262,7 +262,7 @@ TEST_F(QuicSentPacketManagerTest, RetransmitThenAckPrevious) { EXPECT_CALL(*send_algorithm_, OnPacketAcked(1, _)); ReceivedPacketInfo received_info; received_info.largest_observed = 1; - EXPECT_TRUE(manager_.OnIncomingAck(received_info, clock_.ApproximateNow())); + manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); // No packets should be unacked. VerifyUnackedPackets(NULL, 0); @@ -286,7 +286,7 @@ TEST_F(QuicSentPacketManagerTest, RetransmitAndSendThenAckPrevious) { EXPECT_CALL(*send_algorithm_, OnPacketAcked(1, _)); ReceivedPacketInfo received_info; received_info.largest_observed = 1; - EXPECT_TRUE(manager_.OnIncomingAck(received_info, clock_.ApproximateNow())); + manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); // 2 remains unacked, but no packets have retransmittable data. QuicPacketSequenceNumber unacked[] = { 2 }; @@ -312,7 +312,7 @@ TEST_F(QuicSentPacketManagerTest, RetransmitThenAckPreviousThenNackRetransmit) { EXPECT_CALL(*send_algorithm_, OnPacketAcked(1, _)); ReceivedPacketInfo received_info; received_info.largest_observed = 1; - EXPECT_TRUE(manager_.OnIncomingAck(received_info, clock_.ApproximateNow())); + manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); SendDataPacket(3); SendDataPacket(4); @@ -324,19 +324,19 @@ TEST_F(QuicSentPacketManagerTest, RetransmitThenAckPreviousThenNackRetransmit) { received_info.missing_packets.insert(2); EXPECT_CALL(*send_algorithm_, UpdateRtt(rtt)); EXPECT_CALL(*send_algorithm_, OnPacketAcked(3, _)); - EXPECT_TRUE(manager_.OnIncomingAck(received_info, clock_.ApproximateNow())); + manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); received_info.largest_observed = 4; EXPECT_CALL(*send_algorithm_, UpdateRtt(rtt)); EXPECT_CALL(*send_algorithm_, OnPacketAcked(4, _)); - EXPECT_TRUE(manager_.OnIncomingAck(received_info, clock_.ApproximateNow())); + manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); received_info.largest_observed = 5; EXPECT_CALL(*send_algorithm_, UpdateRtt(rtt)); EXPECT_CALL(*send_algorithm_, OnPacketAcked(5, _)); EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)); EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _)); - EXPECT_TRUE(manager_.OnIncomingAck(received_info, clock_.ApproximateNow())); + manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); // No packets remain unacked. VerifyUnackedPackets(NULL, 0); @@ -363,7 +363,7 @@ TEST_F(QuicSentPacketManagerTest, RetransmitTwiceThenAckPreviousBeforeSend) { ReceivedPacketInfo received_info; received_info.largest_observed = 1; EXPECT_CALL(*send_algorithm_, UpdateRtt(QuicTime::Delta::Zero())); - EXPECT_TRUE(manager_.OnIncomingAck(received_info, clock_.ApproximateNow())); + manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); // Since 2 was marked for retransmit, when 1 is acked, 2 is discarded. VerifyUnackedPackets(NULL, 0); diff --git a/net/quic/quic_session_key.cc b/net/quic/quic_server_id.cc index 2dc4165..152fbe1 100644 --- a/net/quic/quic_session_key.cc +++ b/net/quic/quic_server_id.cc @@ -2,32 +2,32 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" using std::string; namespace net { -QuicSessionKey::QuicSessionKey() {} +QuicServerId::QuicServerId() {} -QuicSessionKey::QuicSessionKey(const HostPortPair& host_port_pair, - bool is_https, - PrivacyMode privacy_mode) +QuicServerId::QuicServerId(const HostPortPair& host_port_pair, + bool is_https, + PrivacyMode privacy_mode) : host_port_pair_(host_port_pair), is_https_(is_https), privacy_mode_(privacy_mode) {} -QuicSessionKey::QuicSessionKey(const string& host, - uint16 port, - bool is_https, - PrivacyMode privacy_mode) +QuicServerId::QuicServerId(const string& host, + uint16 port, + bool is_https, + PrivacyMode privacy_mode) : host_port_pair_(host, port), is_https_(is_https), privacy_mode_(privacy_mode) {} -QuicSessionKey::~QuicSessionKey() {} +QuicServerId::~QuicServerId() {} -bool QuicSessionKey::operator<(const QuicSessionKey& other) const { +bool QuicServerId::operator<(const QuicServerId& other) const { if (!host_port_pair_.Equals(other.host_port_pair_)) { return host_port_pair_ < other.host_port_pair_; } @@ -37,13 +37,13 @@ bool QuicSessionKey::operator<(const QuicSessionKey& other) const { return privacy_mode_ < other.privacy_mode_; } -bool QuicSessionKey::operator==(const QuicSessionKey& other) const { +bool QuicServerId::operator==(const QuicServerId& other) const { return is_https_ == other.is_https_ && privacy_mode_ == other.privacy_mode_ && host_port_pair_.Equals(other.host_port_pair_); } -string QuicSessionKey::ToString() const { +string QuicServerId::ToString() const { return (is_https_ ? "https://" : "http://") + host_port_pair_.ToString() + (privacy_mode_ == PRIVACY_MODE_ENABLED ? "/private" : ""); } diff --git a/net/quic/quic_session_key.h b/net/quic/quic_server_id.h index 6cd43e7..1973ccc 100644 --- a/net/quic/quic_session_key.h +++ b/net/quic/quic_server_id.h @@ -13,30 +13,30 @@ namespace net { -// The key used to identify sessions. Includes the hostname, port, and scheme. -class NET_EXPORT_PRIVATE QuicSessionKey { +// The id used to identify sessions. Includes the hostname, port, scheme and +// privacy_mode. +class NET_EXPORT_PRIVATE QuicServerId { public: - QuicSessionKey(); - QuicSessionKey(const HostPortPair& host_port_pair, - bool is_https, - PrivacyMode privacy_mode); - QuicSessionKey(const std::string& host, - uint16 port, - bool is_https, - PrivacyMode privacy_mode); - ~QuicSessionKey(); + QuicServerId(); + QuicServerId(const HostPortPair& host_port_pair, + bool is_https, + PrivacyMode privacy_mode); + QuicServerId(const std::string& host, + uint16 port, + bool is_https, + PrivacyMode privacy_mode); + ~QuicServerId(); // Needed to be an element of std::set. - bool operator<(const QuicSessionKey& other) const; - bool operator==(const QuicSessionKey& other) const; + bool operator<(const QuicServerId& other) const; + bool operator==(const QuicServerId& other) const; - // ToString() will convert the QuicSessionKey to "scheme:hostname:port". - // "scheme" would either be "http" or "https" based on |is_https|. + // ToString() will convert the QuicServerId to "scheme:hostname:port" or + // "scheme:hostname:port/private". "scheme" would either be "http" or "https" + // based on |is_https|. std::string ToString() const; - const HostPortPair& host_port_pair() const { - return host_port_pair_; - } + const HostPortPair& host_port_pair() const { return host_port_pair_; } const std::string& host() const { return host_port_pair_.host(); } diff --git a/net/quic/quic_server_id_test.cc b/net/quic/quic_server_id_test.cc new file mode 100644 index 0000000..4a9c0f3 --- /dev/null +++ b/net/quic/quic_server_id_test.cc @@ -0,0 +1,319 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/quic/quic_server_id.h" + +#include "testing/gtest/include/gtest/gtest.h" + +using std::string; + +namespace net { + +namespace { + +TEST(QuicServerIdTest, ToString) { + HostPortPair google_host_port_pair("google.com", 10); + + QuicServerId google_http_server_id(google_host_port_pair, false, + PRIVACY_MODE_DISABLED); + string google_http_server_id_str = google_http_server_id.ToString(); + EXPECT_EQ("http://google.com:10", google_http_server_id_str); + + QuicServerId google_https_server_id(google_host_port_pair, true, + PRIVACY_MODE_DISABLED); + string google_https_server_id_str = google_https_server_id.ToString(); + EXPECT_EQ("https://google.com:10", google_https_server_id_str); + + QuicServerId private_http_server_id(google_host_port_pair, false, + PRIVACY_MODE_ENABLED); + string private_http_server_id_str = private_http_server_id.ToString(); + EXPECT_EQ("http://google.com:10/private", private_http_server_id_str); + + QuicServerId private_https_server_id(google_host_port_pair, true, + PRIVACY_MODE_ENABLED); + string private_https_server_id_str = private_https_server_id.ToString(); + EXPECT_EQ("https://google.com:10/private", private_https_server_id_str); +} + +TEST(QuicServerIdTest, LessThan) { + QuicServerId a_10_http(HostPortPair("a.com", 10), false, + PRIVACY_MODE_DISABLED); + QuicServerId a_10_https(HostPortPair("a.com", 10), true, + PRIVACY_MODE_DISABLED); + QuicServerId a_11_http(HostPortPair("a.com", 11), false, + PRIVACY_MODE_DISABLED); + QuicServerId a_11_https(HostPortPair("a.com", 11), true, + PRIVACY_MODE_DISABLED); + QuicServerId b_10_http(HostPortPair("b.com", 10), false, + PRIVACY_MODE_DISABLED); + QuicServerId b_10_https(HostPortPair("b.com", 10), true, + PRIVACY_MODE_DISABLED); + QuicServerId b_11_http(HostPortPair("b.com", 11), false, + PRIVACY_MODE_DISABLED); + QuicServerId b_11_https(HostPortPair("b.com", 11), true, + PRIVACY_MODE_DISABLED); + + QuicServerId a_10_http_private(HostPortPair("a.com", 10), false, + PRIVACY_MODE_ENABLED); + QuicServerId a_10_https_private(HostPortPair("a.com", 10), true, + PRIVACY_MODE_ENABLED); + QuicServerId a_11_http_private(HostPortPair("a.com", 11), false, + PRIVACY_MODE_ENABLED); + QuicServerId a_11_https_private(HostPortPair("a.com", 11), true, + PRIVACY_MODE_ENABLED); + QuicServerId b_10_http_private(HostPortPair("b.com", 10), false, + PRIVACY_MODE_ENABLED); + QuicServerId b_10_https_private(HostPortPair("b.com", 10), true, + PRIVACY_MODE_ENABLED); + QuicServerId b_11_http_private(HostPortPair("b.com", 11), false, + PRIVACY_MODE_ENABLED); + QuicServerId b_11_https_private(HostPortPair("b.com", 11), true, + PRIVACY_MODE_ENABLED); + + // Test combinations of host, port, https and privacy being same on left and + // right side of less than. + EXPECT_FALSE(a_10_http < a_10_http); + EXPECT_TRUE(a_10_http < a_10_https); + EXPECT_FALSE(a_10_https < a_10_http); + EXPECT_FALSE(a_10_https < a_10_https); + + EXPECT_TRUE(a_10_http < a_10_http_private); + EXPECT_TRUE(a_10_http < a_10_https_private); + EXPECT_FALSE(a_10_https < a_10_http_private); + EXPECT_TRUE(a_10_https < a_10_https_private); + + EXPECT_FALSE(a_10_http_private < a_10_http); + EXPECT_TRUE(a_10_http_private < a_10_https); + EXPECT_FALSE(a_10_https_private < a_10_http); + EXPECT_FALSE(a_10_https_private < a_10_https); + + EXPECT_FALSE(a_10_http_private < a_10_http_private); + EXPECT_TRUE(a_10_http_private < a_10_https_private); + EXPECT_FALSE(a_10_https_private < a_10_http_private); + EXPECT_FALSE(a_10_https_private < a_10_https_private); + + // Test with either host, port or https being different on left and right side + // of less than. + PrivacyMode left_privacy; + PrivacyMode right_privacy; + for (int i = 0; i < 4; i++) { + switch (i) { + case 0: + left_privacy = PRIVACY_MODE_DISABLED; + right_privacy = PRIVACY_MODE_DISABLED; + break; + case 1: + left_privacy = PRIVACY_MODE_DISABLED; + right_privacy = PRIVACY_MODE_ENABLED; + break; + case 2: + left_privacy = PRIVACY_MODE_ENABLED; + right_privacy = PRIVACY_MODE_DISABLED; + break; + case 3: + left_privacy = PRIVACY_MODE_ENABLED; + right_privacy = PRIVACY_MODE_ENABLED; + break; + } + QuicServerId a_10_http_left_private(HostPortPair("a.com", 10), false, + left_privacy); + QuicServerId a_10_http_right_private(HostPortPair("a.com", 10), false, + right_privacy); + QuicServerId a_10_https_left_private(HostPortPair("a.com", 10), true, + left_privacy); + QuicServerId a_10_https_right_private(HostPortPair("a.com", 10), true, + right_privacy); + QuicServerId a_11_http_left_private(HostPortPair("a.com", 11), false, + left_privacy); + QuicServerId a_11_http_right_private(HostPortPair("a.com", 11), false, + right_privacy); + QuicServerId a_11_https_left_private(HostPortPair("a.com", 11), true, + left_privacy); + QuicServerId a_11_https_right_private(HostPortPair("a.com", 11), true, + right_privacy); + + QuicServerId b_10_http_left_private(HostPortPair("b.com", 10), false, + left_privacy); + QuicServerId b_10_http_right_private(HostPortPair("b.com", 10), false, + right_privacy); + QuicServerId b_10_https_left_private(HostPortPair("b.com", 10), true, + left_privacy); + QuicServerId b_10_https_right_private(HostPortPair("b.com", 10), true, + right_privacy); + QuicServerId b_11_http_left_private(HostPortPair("b.com", 11), false, + left_privacy); + QuicServerId b_11_http_right_private(HostPortPair("b.com", 11), false, + right_privacy); + QuicServerId b_11_https_left_private(HostPortPair("b.com", 11), true, + left_privacy); + QuicServerId b_11_https_right_private(HostPortPair("b.com", 11), true, + right_privacy); + + EXPECT_TRUE(a_10_http_left_private < a_11_http_right_private); + EXPECT_TRUE(a_10_http_left_private < a_11_https_right_private); + EXPECT_TRUE(a_10_https_left_private < a_11_http_right_private); + EXPECT_TRUE(a_10_https_left_private < a_11_https_right_private); + + EXPECT_TRUE(a_10_http_left_private < b_10_http_right_private); + EXPECT_TRUE(a_10_http_left_private < b_10_https_right_private); + EXPECT_TRUE(a_10_https_left_private < b_10_http_right_private); + EXPECT_TRUE(a_10_https_left_private < b_10_https_right_private); + + EXPECT_TRUE(a_10_http_left_private < b_11_http_right_private); + EXPECT_TRUE(a_10_http_left_private < b_11_https_right_private); + EXPECT_TRUE(a_10_https_left_private < b_11_http_right_private); + EXPECT_TRUE(a_10_https_left_private < b_11_https_right_private); + + EXPECT_FALSE(a_11_http_left_private < a_10_http_right_private); + EXPECT_FALSE(a_11_http_left_private < a_10_https_right_private); + EXPECT_FALSE(a_11_https_left_private < a_10_http_right_private); + EXPECT_FALSE(a_11_https_left_private < a_10_https_right_private); + + EXPECT_FALSE(a_11_http_left_private < b_10_http_right_private); + EXPECT_FALSE(a_11_http_left_private < b_10_https_right_private); + EXPECT_FALSE(a_11_https_left_private < b_10_http_right_private); + EXPECT_FALSE(a_11_https_left_private < b_10_https_right_private); + + EXPECT_TRUE(a_11_http_left_private < b_11_http_right_private); + EXPECT_TRUE(a_11_http_left_private < b_11_https_right_private); + EXPECT_TRUE(a_11_https_left_private < b_11_http_right_private); + EXPECT_TRUE(a_11_https_left_private < b_11_https_right_private); + + EXPECT_FALSE(b_10_http_left_private < a_10_http_right_private); + EXPECT_FALSE(b_10_http_left_private < a_10_https_right_private); + EXPECT_FALSE(b_10_https_left_private < a_10_http_right_private); + EXPECT_FALSE(b_10_https_left_private < a_10_https_right_private); + + EXPECT_TRUE(b_10_http_left_private < a_11_http_right_private); + EXPECT_TRUE(b_10_http_left_private < a_11_https_right_private); + EXPECT_TRUE(b_10_https_left_private < a_11_http_right_private); + EXPECT_TRUE(b_10_https_left_private < a_11_https_right_private); + + EXPECT_TRUE(b_10_http_left_private < b_11_http_right_private); + EXPECT_TRUE(b_10_http_left_private < b_11_https_right_private); + EXPECT_TRUE(b_10_https_left_private < b_11_http_right_private); + EXPECT_TRUE(b_10_https_left_private < b_11_https_right_private); + + EXPECT_FALSE(b_11_http_left_private < a_10_http_right_private); + EXPECT_FALSE(b_11_http_left_private < a_10_https_right_private); + EXPECT_FALSE(b_11_https_left_private < a_10_http_right_private); + EXPECT_FALSE(b_11_https_left_private < a_10_https_right_private); + + EXPECT_FALSE(b_11_http_left_private < a_11_http_right_private); + EXPECT_FALSE(b_11_http_left_private < a_11_https_right_private); + EXPECT_FALSE(b_11_https_left_private < a_11_http_right_private); + EXPECT_FALSE(b_11_https_left_private < a_11_https_right_private); + + EXPECT_FALSE(b_11_http_left_private < b_10_http_right_private); + EXPECT_FALSE(b_11_http_left_private < b_10_https_right_private); + EXPECT_FALSE(b_11_https_left_private < b_10_http_right_private); + EXPECT_FALSE(b_11_https_left_private < b_10_https_right_private); + } +} + +TEST(QuicServerIdTest, Equals) { + PrivacyMode left_privacy; + PrivacyMode right_privacy; + for (int i = 0; i < 2; i++) { + switch (i) { + case 0: + left_privacy = PRIVACY_MODE_DISABLED; + right_privacy = PRIVACY_MODE_DISABLED; + break; + case 1: + left_privacy = PRIVACY_MODE_ENABLED; + right_privacy = PRIVACY_MODE_ENABLED; + break; + } + QuicServerId a_10_http_right_private(HostPortPair("a.com", 10), false, + right_privacy); + QuicServerId a_10_https_right_private(HostPortPair("a.com", 10), true, + right_privacy); + QuicServerId a_11_http_right_private(HostPortPair("a.com", 11), false, + right_privacy); + QuicServerId a_11_https_right_private(HostPortPair("a.com", 11), true, + right_privacy); + QuicServerId b_10_http_right_private(HostPortPair("b.com", 10), false, + right_privacy); + QuicServerId b_10_https_right_private(HostPortPair("b.com", 10), true, + right_privacy); + QuicServerId b_11_http_right_private(HostPortPair("b.com", 11), false, + right_privacy); + QuicServerId b_11_https_right_private(HostPortPair("b.com", 11), true, + right_privacy); + + QuicServerId new_a_10_http_left_private(HostPortPair("a.com", 10), false, + left_privacy); + QuicServerId new_a_10_https_left_private(HostPortPair("a.com", 10), true, + left_privacy); + QuicServerId new_a_11_http_left_private(HostPortPair("a.com", 11), false, + left_privacy); + QuicServerId new_a_11_https_left_private(HostPortPair("a.com", 11), true, + left_privacy); + QuicServerId new_b_10_http_left_private(HostPortPair("b.com", 10), false, + left_privacy); + QuicServerId new_b_10_https_left_private(HostPortPair("b.com", 10), true, + left_privacy); + QuicServerId new_b_11_http_left_private(HostPortPair("b.com", 11), false, + left_privacy); + QuicServerId new_b_11_https_left_private(HostPortPair("b.com", 11), true, + left_privacy); + + EXPECT_EQ(new_a_10_http_left_private, a_10_http_right_private); + EXPECT_EQ(new_a_10_https_left_private, a_10_https_right_private); + EXPECT_EQ(new_a_11_http_left_private, a_11_http_right_private); + EXPECT_EQ(new_a_11_https_left_private, a_11_https_right_private); + EXPECT_EQ(new_b_10_http_left_private, b_10_http_right_private); + EXPECT_EQ(new_b_10_https_left_private, b_10_https_right_private); + EXPECT_EQ(new_b_11_http_left_private, b_11_http_right_private); + EXPECT_EQ(new_b_11_https_left_private, b_11_https_right_private); + } + + for (int i = 0; i < 2; i++) { + switch (i) { + case 0: + right_privacy = PRIVACY_MODE_DISABLED; + break; + case 1: + right_privacy = PRIVACY_MODE_ENABLED; + break; + } + QuicServerId a_10_http_right_private(HostPortPair("a.com", 10), false, + right_privacy); + QuicServerId a_10_https_right_private(HostPortPair("a.com", 10), true, + right_privacy); + QuicServerId a_11_http_right_private(HostPortPair("a.com", 11), false, + right_privacy); + QuicServerId a_11_https_right_private(HostPortPair("a.com", 11), true, + right_privacy); + QuicServerId b_10_http_right_private(HostPortPair("b.com", 10), false, + right_privacy); + QuicServerId b_10_https_right_private(HostPortPair("b.com", 10), true, + right_privacy); + QuicServerId b_11_http_right_private(HostPortPair("b.com", 11), false, + right_privacy); + QuicServerId b_11_https_right_private(HostPortPair("b.com", 11), true, + right_privacy); + + QuicServerId new_a_10_http_left_private(HostPortPair("a.com", 10), false, + PRIVACY_MODE_DISABLED); + + EXPECT_FALSE(new_a_10_http_left_private == a_10_https_right_private); + EXPECT_FALSE(new_a_10_http_left_private == a_11_http_right_private); + EXPECT_FALSE(new_a_10_http_left_private == b_10_http_right_private); + EXPECT_FALSE(new_a_10_http_left_private == a_11_https_right_private); + EXPECT_FALSE(new_a_10_http_left_private == b_10_https_right_private); + EXPECT_FALSE(new_a_10_http_left_private == b_11_http_right_private); + EXPECT_FALSE(new_a_10_http_left_private == b_11_https_right_private); + } + QuicServerId a_10_http_private(HostPortPair("a.com", 10), false, + PRIVACY_MODE_ENABLED); + QuicServerId new_a_10_http_no_private(HostPortPair("a.com", 10), false, + PRIVACY_MODE_DISABLED); + EXPECT_FALSE(new_a_10_http_no_private == a_10_http_private); +} + +} // namespace + +} // namespace net diff --git a/net/quic/quic_session_key_test.cc b/net/quic/quic_session_key_test.cc deleted file mode 100644 index db03097..0000000 --- a/net/quic/quic_session_key_test.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "net/quic/quic_session_key.h" - -#include "testing/gtest/include/gtest/gtest.h" - -using std::string; - -namespace net { - -namespace { - -TEST(QuicSessionKeyTest, ToString) { - HostPortPair google_host_port_pair("google.com", 10); - - QuicSessionKey google_http_key(google_host_port_pair, false, - PRIVACY_MODE_DISABLED); - string google_http_key_str = google_http_key.ToString(); - EXPECT_EQ("http://google.com:10", google_http_key_str); - - QuicSessionKey google_https_key(google_host_port_pair, true, - PRIVACY_MODE_DISABLED); - string google_https_key_str = google_https_key.ToString(); - EXPECT_EQ("https://google.com:10", google_https_key_str); - - QuicSessionKey private_http_key(google_host_port_pair, false, - PRIVACY_MODE_ENABLED); - string private_http_key_str = private_http_key.ToString(); - EXPECT_EQ("http://google.com:10/private", private_http_key_str); - - QuicSessionKey private_https_key(google_host_port_pair, true, - PRIVACY_MODE_ENABLED); - string private_https_key_str = private_https_key.ToString(); - EXPECT_EQ("https://google.com:10/private", private_https_key_str); -} - -} // namespace - -} // namespace net diff --git a/net/quic/quic_stream_factory.cc b/net/quic/quic_stream_factory.cc index a822856..0127d581 100644 --- a/net/quic/quic_stream_factory.cc +++ b/net/quic/quic_stream_factory.cc @@ -32,7 +32,7 @@ #include "net/quic/quic_default_packet_writer.h" #include "net/quic/quic_http_stream.h" #include "net/quic/quic_protocol.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "net/socket/client_socket_factory.h" #if defined(OS_WIN) @@ -128,8 +128,8 @@ class QuicStreamFactory::Job { return callback_; } - const QuicSessionKey session_key() const { - return session_key_; + const QuicServerId server_id() const { + return server_id_; } private: @@ -146,7 +146,7 @@ class QuicStreamFactory::Job { QuicStreamFactory* factory_; SingleRequestHostResolver host_resolver_; - QuicSessionKey session_key_; + QuicServerId server_id_; bool is_post_; scoped_ptr<QuicServerInfo> server_info_; const BoundNetLog net_log_; @@ -168,7 +168,7 @@ QuicStreamFactory::Job::Job(QuicStreamFactory* factory, const BoundNetLog& net_log) : factory_(factory), host_resolver_(host_resolver), - session_key_(host_port_pair, is_https, privacy_mode), + server_id_(host_port_pair, is_https, privacy_mode), is_post_(method == "POST"), server_info_(server_info), net_log_(net_log), @@ -238,7 +238,7 @@ int QuicStreamFactory::Job::DoResolveHost() { io_state_ = STATE_RESOLVE_HOST_COMPLETE; return host_resolver_.Resolve( - HostResolver::RequestInfo(session_key_.host_port_pair()), + HostResolver::RequestInfo(server_id_.host_port_pair()), DEFAULT_PRIORITY, &address_list_, base::Bind(&QuicStreamFactory::Job::OnIOComplete, @@ -250,11 +250,11 @@ int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { if (rv != OK) return rv; - DCHECK(!factory_->HasActiveSession(session_key_)); + DCHECK(!factory_->HasActiveSession(server_id_)); // Inform the factory of this resolution, which will set up // a session alias, if possible. - if (factory_->OnResolution(session_key_, address_list_)) { + if (factory_->OnResolution(server_id_, address_list_)) { return OK; } @@ -290,7 +290,7 @@ int QuicStreamFactory::Job::DoLoadServerInfoComplete(int rv) { int QuicStreamFactory::Job::DoConnect() { io_state_ = STATE_CONNECT_COMPLETE; - int rv = factory_->CreateSession(session_key_, server_info_.Pass(), + int rv = factory_->CreateSession(server_id_, server_info_.Pass(), address_list_, net_log_, &session_); if (rv != OK) { DCHECK(rv != ERR_IO_PENDING); @@ -303,7 +303,7 @@ int QuicStreamFactory::Job::DoConnect() { return ERR_QUIC_PROTOCOL_ERROR; } rv = session_->CryptoConnect( - factory_->require_confirmation() || session_key_.is_https() || is_post_, + factory_->require_confirmation() || server_id_.is_https() || is_post_, base::Bind(&QuicStreamFactory::Job::OnIOComplete, base::Unretained(this))); return rv; @@ -313,17 +313,17 @@ int QuicStreamFactory::Job::DoConnectComplete(int rv) { if (rv != OK) return rv; - DCHECK(!factory_->HasActiveSession(session_key_)); + DCHECK(!factory_->HasActiveSession(server_id_)); // There may well now be an active session for this IP. If so, use the // existing session instead. AddressList address(session_->connection()->peer_address()); - if (factory_->OnResolution(session_key_, address)) { + if (factory_->OnResolution(server_id_, address)) { session_->connection()->SendConnectionClose(QUIC_NO_ERROR); session_ = NULL; return OK; } - factory_->ActivateSession(session_key_, session_); + factory_->ActivateSession(server_id_, session_); return OK; } @@ -431,14 +431,14 @@ int QuicStreamFactory::Create(const HostPortPair& host_port_pair, base::StringPiece method, const BoundNetLog& net_log, QuicStreamRequest* request) { - QuicSessionKey session_key(host_port_pair, is_https, privacy_mode); - if (HasActiveSession(session_key)) { - request->set_stream(CreateIfSessionExists(session_key, net_log)); + QuicServerId server_id(host_port_pair, is_https, privacy_mode); + if (HasActiveSession(server_id)) { + request->set_stream(CreateIfSessionExists(server_id, net_log)); return OK; } - if (HasActiveJob(session_key)) { - Job* job = active_jobs_[session_key]; + if (HasActiveJob(server_id)) { + Job* job = active_jobs_[server_id]; active_requests_[request] = job; job_requests_map_[job].insert(request); return ERR_IO_PENDING; @@ -447,10 +447,10 @@ int QuicStreamFactory::Create(const HostPortPair& host_port_pair, QuicServerInfo* quic_server_info = NULL; if (quic_server_info_factory_) { QuicCryptoClientConfig::CachedState* cached = - crypto_config_.LookupOrCreate(session_key); + crypto_config_.LookupOrCreate(server_id); DCHECK(cached); if (cached->IsEmpty()) { - quic_server_info = quic_server_info_factory_->GetForServer(session_key); + quic_server_info = quic_server_info_factory_->GetForServer(server_id); } } scoped_ptr<Job> job(new Job(this, host_resolver_, host_port_pair, is_https, @@ -461,22 +461,22 @@ int QuicStreamFactory::Create(const HostPortPair& host_port_pair, if (rv == ERR_IO_PENDING) { active_requests_[request] = job.get(); job_requests_map_[job.get()].insert(request); - active_jobs_[session_key] = job.release(); + active_jobs_[server_id] = job.release(); } if (rv == OK) { - DCHECK(HasActiveSession(session_key)); - request->set_stream(CreateIfSessionExists(session_key, net_log)); + DCHECK(HasActiveSession(server_id)); + request->set_stream(CreateIfSessionExists(server_id, net_log)); } return rv; } bool QuicStreamFactory::OnResolution( - const QuicSessionKey& session_key, + const QuicServerId& server_id, const AddressList& address_list) { - DCHECK(!HasActiveSession(session_key)); + DCHECK(!HasActiveSession(server_id)); for (size_t i = 0; i < address_list.size(); ++i) { const IPEndPoint& address = address_list[i]; - const IpAliasKey ip_alias_key(address, session_key.is_https()); + const IpAliasKey ip_alias_key(address, server_id.is_https()); if (!ContainsKey(ip_aliases_, ip_alias_key)) continue; @@ -484,10 +484,10 @@ bool QuicStreamFactory::OnResolution( for (SessionSet::const_iterator i = sessions.begin(); i != sessions.end(); ++i) { QuicClientSession* session = *i; - if (!session->CanPool(session_key.host())) + if (!session->CanPool(server_id.host())) continue; - active_sessions_[session_key] = session; - session_aliases_[session].insert(session_key); + active_sessions_[server_id] = session; + session_aliases_[session].insert(server_id); return true; } } @@ -501,8 +501,8 @@ void QuicStreamFactory::OnJobComplete(Job* job, int rv) { // Create all the streams, but do not notify them yet. for (RequestSet::iterator it = job_requests_map_[job].begin(); it != job_requests_map_[job].end() ; ++it) { - DCHECK(HasActiveSession(job->session_key())); - (*it)->set_stream(CreateIfSessionExists(job->session_key(), + DCHECK(HasActiveSession(job->server_id())); + (*it)->set_stream(CreateIfSessionExists(job->server_id(), (*it)->net_log())); } } @@ -516,7 +516,7 @@ void QuicStreamFactory::OnJobComplete(Job* job, int rv) { // profile which can not be deleted via callbacks. request->OnRequestComplete(rv); } - active_jobs_.erase(job->session_key()); + active_jobs_.erase(job->server_id()); job_requests_map_.erase(job); delete job; return; @@ -525,14 +525,14 @@ void QuicStreamFactory::OnJobComplete(Job* job, int rv) { // Returns a newly created QuicHttpStream owned by the caller, if a // matching session already exists. Returns NULL otherwise. scoped_ptr<QuicHttpStream> QuicStreamFactory::CreateIfSessionExists( - const QuicSessionKey& session_key, + const QuicServerId& server_id, const BoundNetLog& net_log) { - if (!HasActiveSession(session_key)) { + if (!HasActiveSession(server_id)) { DVLOG(1) << "No active session"; return scoped_ptr<QuicHttpStream>(); } - QuicClientSession* session = active_sessions_[session_key]; + QuicClientSession* session = active_sessions_[server_id]; DCHECK(session); return scoped_ptr<QuicHttpStream>( new QuicHttpStream(session->GetWeakPtr())); @@ -633,11 +633,11 @@ base::Value* QuicStreamFactory::QuicStreamFactoryInfoToValue() const { for (SessionMap::const_iterator it = active_sessions_.begin(); it != active_sessions_.end(); ++it) { - const QuicSessionKey& session_key = it->first; + const QuicServerId& server_id = it->first; QuicClientSession* session = it->second; const AliasSet& aliases = session_aliases_.find(session)->second; // Only add a session to the list once. - if (session_key == *aliases.begin()) { + if (server_id == *aliases.begin()) { std::set<HostPortPair> hosts; for (AliasSet::const_iterator alias_it = aliases.begin(); alias_it != aliases.end(); ++alias_it) { @@ -672,30 +672,30 @@ void QuicStreamFactory::OnCACertChanged(const X509Certificate* cert) { } bool QuicStreamFactory::HasActiveSession( - const QuicSessionKey& session_key) const { - return ContainsKey(active_sessions_, session_key); + const QuicServerId& server_id) const { + return ContainsKey(active_sessions_, server_id); } int QuicStreamFactory::CreateSession( - const QuicSessionKey& session_key, + const QuicServerId& server_id, scoped_ptr<QuicServerInfo> server_info, const AddressList& address_list, const BoundNetLog& net_log, QuicClientSession** session) { bool enable_port_selection = enable_port_selection_; if (enable_port_selection && - ContainsKey(gone_away_aliases_, session_key)) { + ContainsKey(gone_away_aliases_, server_id)) { // Disable port selection when the server is going away. // There is no point in trying to return to the same server, if // that server is no longer handling requests. enable_port_selection = false; - gone_away_aliases_.erase(session_key); + gone_away_aliases_.erase(server_id); } QuicConnectionId connection_id = random_generator_->RandUint64(); IPEndPoint addr = *address_list.begin(); scoped_refptr<PortSuggester> port_suggester = - new PortSuggester(session_key.host_port_pair(), port_seed_); + new PortSuggester(server_id.host_port_pair(), port_seed_); DatagramSocket::BindType bind_type = enable_port_selection ? DatagramSocket::RANDOM_BIND : // Use our callback. DatagramSocket::DEFAULT_BIND; // Use OS to randomize. @@ -749,13 +749,13 @@ int QuicStreamFactory::CreateSession( writer->SetConnection(connection); connection->options()->max_packet_length = max_packet_length_; - InitializeCachedState(session_key, server_info); + InitializeCachedState(server_id, server_info); QuicConfig config = config_; if (http_server_properties_) { const HttpServerProperties::NetworkStats* stats = http_server_properties_->GetServerNetworkStats( - session_key.host_port_pair()); + server_id.host_port_pair()); if (stats != NULL) { config.set_initial_round_trip_time_us(stats->rtt.InMicroseconds(), stats->rtt.InMicroseconds()); @@ -764,36 +764,36 @@ int QuicStreamFactory::CreateSession( *session = new QuicClientSession( connection, socket.Pass(), writer.Pass(), this, - quic_crypto_client_stream_factory_, server_info.Pass(), session_key, + quic_crypto_client_stream_factory_, server_info.Pass(), server_id, config, &crypto_config_, net_log.net_log()); all_sessions_.insert(*session); // owning pointer return OK; } -bool QuicStreamFactory::HasActiveJob(const QuicSessionKey& key) const { +bool QuicStreamFactory::HasActiveJob(const QuicServerId& key) const { return ContainsKey(active_jobs_, key); } void QuicStreamFactory::ActivateSession( - const QuicSessionKey& session_key, + const QuicServerId& server_id, QuicClientSession* session) { - DCHECK(!HasActiveSession(session_key)); - active_sessions_[session_key] = session; - session_aliases_[session].insert(session_key); + DCHECK(!HasActiveSession(server_id)); + active_sessions_[server_id] = session; + session_aliases_[session].insert(server_id); const IpAliasKey ip_alias_key(session->connection()->peer_address(), - session_key.is_https()); + server_id.is_https()); DCHECK(!ContainsKey(ip_aliases_[ip_alias_key], session)); ip_aliases_[ip_alias_key].insert(session); } void QuicStreamFactory::InitializeCachedState( - const QuicSessionKey& session_key, + const QuicServerId& server_id, const scoped_ptr<QuicServerInfo>& server_info) { if (!server_info) return; QuicCryptoClientConfig::CachedState* cached = - crypto_config_.LookupOrCreate(session_key); + crypto_config_.LookupOrCreate(server_id); if (!cached->IsEmpty()) return; @@ -804,7 +804,7 @@ void QuicStreamFactory::InitializeCachedState( clock_->WallNow())) return; - if (!session_key.is_https()) { + if (!server_id.is_https()) { // Don't check the certificates for insecure QUIC. cached->SetProofValid(); } diff --git a/net/quic/quic_stream_factory.h b/net/quic/quic_stream_factory.h index 1e22cdb..dd8b3ac 100644 --- a/net/quic/quic_stream_factory.h +++ b/net/quic/quic_stream_factory.h @@ -36,7 +36,7 @@ class QuicConnectionHelper; class QuicCryptoClientStreamFactory; class QuicRandom; class QuicServerInfoFactory; -class QuicSessionKey; +class QuicServerId; class QuicStreamFactory; namespace test { @@ -181,38 +181,38 @@ class NET_EXPORT_PRIVATE QuicStreamFactory bool operator==(const IpAliasKey &other) const; }; - typedef std::map<QuicSessionKey, QuicClientSession*> SessionMap; - typedef std::set<QuicSessionKey> AliasSet; + typedef std::map<QuicServerId, QuicClientSession*> SessionMap; + typedef std::set<QuicServerId> AliasSet; typedef std::map<QuicClientSession*, AliasSet> SessionAliasMap; typedef std::set<QuicClientSession*> SessionSet; typedef std::map<IpAliasKey, SessionSet> IPAliasMap; - typedef std::map<QuicSessionKey, QuicCryptoClientConfig*> CryptoConfigMap; - typedef std::map<QuicSessionKey, Job*> JobMap; + typedef std::map<QuicServerId, QuicCryptoClientConfig*> CryptoConfigMap; + typedef std::map<QuicServerId, Job*> JobMap; typedef std::map<QuicStreamRequest*, Job*> RequestMap; typedef std::set<QuicStreamRequest*> RequestSet; typedef std::map<Job*, RequestSet> JobRequestsMap; // Returns a newly created QuicHttpStream owned by the caller, if a // matching session already exists. Returns NULL otherwise. - scoped_ptr<QuicHttpStream> CreateIfSessionExists(const QuicSessionKey& key, + scoped_ptr<QuicHttpStream> CreateIfSessionExists(const QuicServerId& key, const BoundNetLog& net_log); - bool OnResolution(const QuicSessionKey& session_key, + bool OnResolution(const QuicServerId& server_id, const AddressList& address_list); void OnJobComplete(Job* job, int rv); - bool HasActiveSession(const QuicSessionKey& session_key) const; - bool HasActiveJob(const QuicSessionKey& session_key) const; - int CreateSession(const QuicSessionKey& session_key, + bool HasActiveSession(const QuicServerId& server_id) const; + bool HasActiveJob(const QuicServerId& server_id) const; + int CreateSession(const QuicServerId& server_id, scoped_ptr<QuicServerInfo> quic_server_info, const AddressList& address_list, const BoundNetLog& net_log, QuicClientSession** session); - void ActivateSession(const QuicSessionKey& key, + void ActivateSession(const QuicServerId& key, QuicClientSession* session); - // Initializes the cached state associated with |session_key| in + // Initializes the cached state associated with |server_id| in // |crypto_config_| with the information in |server_info|. - void InitializeCachedState(const QuicSessionKey& session_key, + void InitializeCachedState(const QuicServerId& server_id, const scoped_ptr<QuicServerInfo>& server_info); void ExpireBrokenAlternateProtocolMappings(); diff --git a/net/quic/quic_stream_factory_test.cc b/net/quic/quic_stream_factory_test.cc index 75b6e98..b5c2817 100644 --- a/net/quic/quic_stream_factory_test.cc +++ b/net/quic/quic_stream_factory_test.cc @@ -17,7 +17,7 @@ #include "net/quic/crypto/quic_decrypter.h" #include "net/quic/crypto/quic_encrypter.h" #include "net/quic/quic_http_stream.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "net/quic/test_tools/mock_clock.h" #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" #include "net/quic/test_tools/mock_random.h" @@ -48,17 +48,17 @@ class QuicStreamFactoryPeer { static bool HasActiveSession(QuicStreamFactory* factory, const HostPortPair& host_port_pair, bool is_https) { - QuicSessionKey server_key(host_port_pair, is_https, PRIVACY_MODE_DISABLED); - return factory->HasActiveSession(server_key); + QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED); + return factory->HasActiveSession(server_id); } static QuicClientSession* GetActiveSession( QuicStreamFactory* factory, const HostPortPair& host_port_pair, bool is_https) { - QuicSessionKey server_key(host_port_pair, is_https, PRIVACY_MODE_DISABLED); - DCHECK(factory->HasActiveSession(server_key)); - return factory->active_sessions_[server_key]; + QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED); + DCHECK(factory->HasActiveSession(server_id)); + return factory->active_sessions_[server_id]; } static scoped_ptr<QuicHttpStream> CreateIfSessionExists( @@ -66,8 +66,8 @@ class QuicStreamFactoryPeer { const HostPortPair& host_port_pair, bool is_https, const BoundNetLog& net_log) { - QuicSessionKey server_key(host_port_pair, is_https, PRIVACY_MODE_DISABLED); - return factory->CreateIfSessionExists(server_key, net_log); + QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED); + return factory->CreateIfSessionExists(server_id, net_log); } static bool IsLiveSession(QuicStreamFactory* factory, @@ -1092,9 +1092,9 @@ TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { HostPortPair host_port_pair1(r1_host_name, 80); QuicCryptoClientConfig* crypto_config = QuicStreamFactoryPeer::GetCryptoConfig(&factory_); - QuicSessionKey server_key1(host_port_pair1, is_https_, privacy_mode_); + QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_); QuicCryptoClientConfig::CachedState* cached1 = - crypto_config->LookupOrCreate(server_key1); + crypto_config->LookupOrCreate(server_id1); EXPECT_FALSE(cached1->proof_valid()); EXPECT_TRUE(cached1->source_address_token().empty()); @@ -1104,9 +1104,9 @@ TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { cached1->SetProofValid(); HostPortPair host_port_pair2(r2_host_name, 80); - QuicSessionKey server_key2(host_port_pair2, is_https_, privacy_mode_); + QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_); QuicCryptoClientConfig::CachedState* cached2 = - crypto_config->LookupOrCreate(server_key2); + crypto_config->LookupOrCreate(server_id2); EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); EXPECT_TRUE(cached2->proof_valid()); } @@ -1126,9 +1126,9 @@ TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { HostPortPair host_port_pair1(r3_host_name, 80); QuicCryptoClientConfig* crypto_config = QuicStreamFactoryPeer::GetCryptoConfig(&factory_); - QuicSessionKey server_key1(host_port_pair1, is_https_, privacy_mode_); + QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_); QuicCryptoClientConfig::CachedState* cached1 = - crypto_config->LookupOrCreate(server_key1); + crypto_config->LookupOrCreate(server_id1); EXPECT_FALSE(cached1->proof_valid()); EXPECT_TRUE(cached1->source_address_token().empty()); @@ -1138,9 +1138,9 @@ TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { cached1->SetProofInvalid(); HostPortPair host_port_pair2(r4_host_name, 80); - QuicSessionKey server_key2(host_port_pair2, is_https_, privacy_mode_); + QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_); QuicCryptoClientConfig::CachedState* cached2 = - crypto_config->LookupOrCreate(server_key2); + crypto_config->LookupOrCreate(server_id2); EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); EXPECT_TRUE(cached2->source_address_token().empty()); EXPECT_FALSE(cached2->proof_valid()); diff --git a/net/quic/test_tools/crypto_test_utils.cc b/net/quic/test_tools/crypto_test_utils.cc index 6989fff..ef27df0 100644 --- a/net/quic/test_tools/crypto_test_utils.cc +++ b/net/quic/test_tools/crypto_test_utils.cc @@ -15,7 +15,7 @@ #include "net/quic/quic_crypto_client_stream.h" #include "net/quic/quic_crypto_server_stream.h" #include "net/quic/quic_crypto_stream.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "net/quic/test_tools/quic_connection_peer.h" #include "net/quic/test_tools/quic_test_utils.h" #include "net/quic/test_tools/simple_quic_framer.h" @@ -41,9 +41,7 @@ class CryptoFramerVisitor : public CryptoFramerVisitorInterface { : error_(false) { } - virtual void OnError(CryptoFramer* framer) OVERRIDE { - error_ = true; - } + virtual void OnError(CryptoFramer* framer) OVERRIDE { error_ = true; } virtual void OnHandshakeMessage( const CryptoHandshakeMessage& message) OVERRIDE { @@ -179,9 +177,9 @@ int CryptoTestUtils::HandshakeWithFakeClient( if (options.channel_id_enabled) { crypto_config.SetChannelIDSigner(ChannelIDSignerForTesting()); } - QuicSessionKey server_key(kServerHostname, kServerPort, false, - PRIVACY_MODE_DISABLED); - QuicCryptoClientStream client(server_key, &client_session, NULL, + QuicServerId server_id(kServerHostname, kServerPort, false, + PRIVACY_MODE_DISABLED); + QuicCryptoClientStream client(server_id, &client_session, NULL, &crypto_config); client_session.SetCryptoStream(&client); @@ -193,9 +191,9 @@ int CryptoTestUtils::HandshakeWithFakeClient( CompareClientAndServerKeys(&client, server); if (options.channel_id_enabled) { - EXPECT_EQ(crypto_config.channel_id_signer()->GetKeyForHostname( - kServerHostname), - server->crypto_negotiated_params().channel_id); + EXPECT_EQ( + crypto_config.channel_id_signer()->GetKeyForHostname(kServerHostname), + server->crypto_negotiated_params().channel_id); } return client.num_sent_client_hellos(); @@ -494,7 +492,7 @@ CryptoHandshakeMessage CryptoTestUtils::BuildMessage(const char* message_tag, valuestr++; len--; - CHECK(len % 2 == 0); + CHECK_EQ(0u, len % 2); scoped_ptr<uint8[]> buf(new uint8[len/2]); for (size_t i = 0; i < len/2; i++) { diff --git a/net/quic/test_tools/mock_crypto_client_stream.cc b/net/quic/test_tools/mock_crypto_client_stream.cc index a5ff173..24e2843 100644 --- a/net/quic/test_tools/mock_crypto_client_stream.cc +++ b/net/quic/test_tools/mock_crypto_client_stream.cc @@ -5,19 +5,19 @@ #include "net/quic/test_tools/mock_crypto_client_stream.h" #include "net/quic/quic_client_session_base.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "testing/gtest/include/gtest/gtest.h" namespace net { MockCryptoClientStream::MockCryptoClientStream( - const QuicSessionKey& server_key, + const QuicServerId& server_id, QuicClientSessionBase* session, ProofVerifyContext* verify_context, QuicCryptoClientConfig* crypto_config, HandshakeMode handshake_mode, const ProofVerifyDetails* proof_verify_details) - : QuicCryptoClientStream(server_key, session, verify_context, + : QuicCryptoClientStream(server_id, session, verify_context, crypto_config), handshake_mode_(handshake_mode), proof_verify_details_(proof_verify_details) { diff --git a/net/quic/test_tools/mock_crypto_client_stream.h b/net/quic/test_tools/mock_crypto_client_stream.h index 8567945..e1205e1 100644 --- a/net/quic/test_tools/mock_crypto_client_stream.h +++ b/net/quic/test_tools/mock_crypto_client_stream.h @@ -14,7 +14,7 @@ namespace net { -class QuicSessionKey; +class QuicServerId; class MockCryptoClientStream : public QuicCryptoClientStream { public: @@ -36,7 +36,7 @@ class MockCryptoClientStream : public QuicCryptoClientStream { }; MockCryptoClientStream( - const QuicSessionKey& server_key, + const QuicServerId& server_id, QuicClientSessionBase* session, ProofVerifyContext* verify_context, QuicCryptoClientConfig* crypto_config, diff --git a/net/quic/test_tools/mock_crypto_client_stream_factory.cc b/net/quic/test_tools/mock_crypto_client_stream_factory.cc index 83dac36..302ed07 100644 --- a/net/quic/test_tools/mock_crypto_client_stream_factory.cc +++ b/net/quic/test_tools/mock_crypto_client_stream_factory.cc @@ -7,7 +7,7 @@ #include "base/lazy_instance.h" #include "net/quic/quic_client_session.h" #include "net/quic/quic_crypto_client_stream.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" using std::string; @@ -21,11 +21,11 @@ MockCryptoClientStreamFactory::MockCryptoClientStreamFactory() QuicCryptoClientStream* MockCryptoClientStreamFactory::CreateQuicCryptoClientStream( - const QuicSessionKey& server_key, + const QuicServerId& server_id, QuicClientSession* session, QuicCryptoClientConfig* crypto_config) { last_stream_ = new MockCryptoClientStream( - server_key, session, NULL, crypto_config, handshake_mode_, + server_id, session, NULL, crypto_config, handshake_mode_, proof_verify_details_); return last_stream_; } diff --git a/net/quic/test_tools/mock_crypto_client_stream_factory.h b/net/quic/test_tools/mock_crypto_client_stream_factory.h index ac1184f..a6626b9 100644 --- a/net/quic/test_tools/mock_crypto_client_stream_factory.h +++ b/net/quic/test_tools/mock_crypto_client_stream_factory.h @@ -13,7 +13,7 @@ namespace net { -class QuicSessionKey; +class QuicServerId; class MockCryptoClientStreamFactory : public QuicCryptoClientStreamFactory { public: @@ -21,7 +21,7 @@ class MockCryptoClientStreamFactory : public QuicCryptoClientStreamFactory { virtual ~MockCryptoClientStreamFactory() {} virtual QuicCryptoClientStream* CreateQuicCryptoClientStream( - const QuicSessionKey& server_key, + const QuicServerId& server_id, QuicClientSession* session, QuicCryptoClientConfig* crypto_config) OVERRIDE; diff --git a/net/tools/quic/end_to_end_test.cc b/net/tools/quic/end_to_end_test.cc index 7e50cab..ad0dfe8 100644 --- a/net/tools/quic/end_to_end_test.cc +++ b/net/tools/quic/end_to_end_test.cc @@ -21,7 +21,7 @@ #include "net/quic/quic_packet_creator.h" #include "net/quic/quic_protocol.h" #include "net/quic/quic_sent_packet_manager.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "net/quic/test_tools/quic_connection_peer.h" #include "net/quic/test_tools/quic_session_peer.h" #include "net/quic/test_tools/quic_test_utils.h" @@ -144,14 +144,12 @@ class ClientDelegate : public PacketDroppingTestWriter::Delegate { class EndToEndTest : public ::testing::TestWithParam<TestParams> { protected: EndToEndTest() - : server_started_(false), + : server_hostname_("example.com"), + server_started_(false), strike_register_no_startup_period_(false) { net::IPAddressNumber ip; CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &ip)); - uint port = 0; - server_address_ = IPEndPoint(ip, port); - server_key_ = QuicSessionKey("example.com", port, false, - PRIVACY_MODE_DISABLED); + server_address_ = IPEndPoint(ip, 0); client_supported_versions_ = GetParam().client_supported_versions; server_supported_versions_ = GetParam().server_supported_versions; @@ -190,7 +188,7 @@ class EndToEndTest : public ::testing::TestWithParam<TestParams> { QuicTestClient* CreateQuicClient(QuicPacketWriterWrapper* writer) { QuicTestClient* client = new QuicTestClient( server_address_, - server_key_, + server_hostname_, false, // not secure client_config_, client_supported_versions_, @@ -247,9 +245,6 @@ class EndToEndTest : public ::testing::TestWithParam<TestParams> { server_thread_->Initialize(); server_address_ = IPEndPoint(server_address_.address(), server_thread_->GetPort()); - server_key_ = QuicSessionKey(server_key_.host(), server_thread_->GetPort(), - false, PRIVACY_MODE_DISABLED); - QuicDispatcher* dispatcher = QuicServerPeer::GetDispatcher(server_thread_->server()); QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); @@ -303,7 +298,7 @@ class EndToEndTest : public ::testing::TestWithParam<TestParams> { } IPEndPoint server_address_; - QuicSessionKey server_key_; + string server_hostname_; scoped_ptr<ServerThread> server_thread_; scoped_ptr<QuicTestClient> client_; PacketDroppingTestWriter* client_writer_; diff --git a/net/tools/quic/quic_client.cc b/net/tools/quic/quic_client.cc index f0cca3b..8407bd9 100644 --- a/net/tools/quic/quic_client.cc +++ b/net/tools/quic/quic_client.cc @@ -16,7 +16,7 @@ #include "net/quic/quic_connection.h" #include "net/quic/quic_data_reader.h" #include "net/quic/quic_protocol.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "net/tools/balsa/balsa_headers.h" #include "net/tools/quic/quic_epoll_connection_helper.h" #include "net/tools/quic/quic_socket_utils.h" @@ -32,12 +32,12 @@ namespace tools { const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET; QuicClient::QuicClient(IPEndPoint server_address, - const QuicSessionKey& server_key, + const QuicServerId& server_id, const QuicVersionVector& supported_versions, bool print_response, uint32 initial_flow_control_window) : server_address_(server_address), - server_key_(server_key), + server_id_(server_id), local_port_(0), fd_(-1), helper_(CreateQuicConnectionHelper()), @@ -51,12 +51,12 @@ QuicClient::QuicClient(IPEndPoint server_address, } QuicClient::QuicClient(IPEndPoint server_address, - const QuicSessionKey& server_key, + const QuicServerId& server_id, const QuicConfig& config, const QuicVersionVector& supported_versions, uint32 initial_flow_control_window) : server_address_(server_address), - server_key_(server_key), + server_id_(server_id), config_(config), local_port_(0), fd_(-1), @@ -167,7 +167,7 @@ bool QuicClient::StartConnect() { } session_.reset(new QuicClientSession( - server_key_, + server_id_, config_, new QuicConnection(GenerateConnectionId(), server_address_, helper_.get(), writer_.get(), false, supported_versions_, @@ -300,6 +300,15 @@ QuicPacketWriter* QuicClient::CreateQuicPacketWriter() { return new QuicDefaultPacketWriter(fd_); } +int QuicClient::ReadPacket(char* buffer, + int buffer_len, + IPEndPoint* server_address, + IPAddressNumber* client_ip) { + return QuicSocketUtils::ReadPacket( + fd_, buffer, buffer_len, overflow_supported_ ? &packets_dropped_ : NULL, + client_ip, server_address); +} + bool QuicClient::ReadAndProcessPacket() { // Allocate some extra space so we can send an error if the server goes over // the limit. @@ -308,9 +317,7 @@ bool QuicClient::ReadAndProcessPacket() { IPEndPoint server_address; IPAddressNumber client_ip; - int bytes_read = QuicSocketUtils::ReadPacket( - fd_, buf, arraysize(buf), overflow_supported_ ? &packets_dropped_ : NULL, - &client_ip, &server_address); + int bytes_read = ReadPacket(buf, arraysize(buf), &server_address, &client_ip); if (bytes_read < 0) { return false; diff --git a/net/tools/quic/quic_client.h b/net/tools/quic/quic_client.h index a439d28..183158a 100644 --- a/net/tools/quic/quic_client.h +++ b/net/tools/quic/quic_client.h @@ -25,7 +25,7 @@ namespace net { class ProofVerifier; -class QuicSessionKey; +class QuicServerId; namespace tools { @@ -48,12 +48,12 @@ class QuicClient : public EpollCallbackInterface, }; QuicClient(IPEndPoint server_address, - const QuicSessionKey& server_key, + const QuicServerId& server_id, const QuicVersionVector& supported_versions, bool print_response, uint32 initial_flow_control_window); QuicClient(IPEndPoint server_address, - const QuicSessionKey& server_key, + const QuicServerId& server_id, const QuicConfig& config, const QuicVersionVector& supported_versions, uint32 initial_flow_control_window); @@ -138,11 +138,11 @@ class QuicClient : public EpollCallbackInterface, int fd() { return fd_; } - const QuicSessionKey& server_key() const { return server_key_; } + const QuicServerId& server_id() const { return server_id_; } // This should only be set before the initial Connect() - void set_server_key(const QuicSessionKey& server_key) { - server_key_ = server_key; + void set_server_id(const QuicServerId& server_id) { + server_id_ = server_id; } // SetProofVerifier sets the ProofVerifier that will be used to verify the @@ -174,6 +174,11 @@ class QuicClient : public EpollCallbackInterface, virtual QuicEpollConnectionHelper* CreateQuicConnectionHelper(); virtual QuicPacketWriter* CreateQuicPacketWriter(); + virtual int ReadPacket(char* buffer, + int buffer_len, + IPEndPoint* server_address, + IPAddressNumber* client_ip); + private: friend class net::tools::test::QuicClientPeer; @@ -183,8 +188,8 @@ class QuicClient : public EpollCallbackInterface, // Address of the server. const IPEndPoint server_address_; - // |server_key_| is a tuple (hostname, port, is_https) of the server. - QuicSessionKey server_key_; + // |server_id_| is a tuple (hostname, port, is_https) of the server. + QuicServerId server_id_; // config_ and crypto_config_ contain configuration and cached state about // servers. diff --git a/net/tools/quic/quic_client_bin.cc b/net/tools/quic/quic_client_bin.cc index 0e33fa8..7e2ea98 100644 --- a/net/tools/quic/quic_client_bin.cc +++ b/net/tools/quic/quic_client_bin.cc @@ -81,8 +81,8 @@ int main(int argc, char *argv[]) { // TODO(rjshade): Set version on command line. net::tools::QuicClient client( net::IPEndPoint(addr, FLAGS_port), - net::QuicSessionKey(FLAGS_hostname, FLAGS_port, FLAGS_secure, - net::PRIVACY_MODE_DISABLED), + net::QuicServerId(FLAGS_hostname, FLAGS_port, FLAGS_secure, + net::PRIVACY_MODE_DISABLED), net::QuicSupportedVersions(), true, FLAGS_initial_flow_control_window); client.Initialize(); diff --git a/net/tools/quic/quic_client_session.cc b/net/tools/quic/quic_client_session.cc index 29b178a..aca5418 100644 --- a/net/tools/quic/quic_client_session.cc +++ b/net/tools/quic/quic_client_session.cc @@ -6,7 +6,7 @@ #include "base/logging.h" #include "net/quic/crypto/crypto_protocol.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "net/tools/quic/quic_spdy_client_stream.h" using std::string; @@ -15,12 +15,12 @@ namespace net { namespace tools { QuicClientSession::QuicClientSession( - const QuicSessionKey& server_key, + const QuicServerId& server_id, const QuicConfig& config, QuicConnection* connection, QuicCryptoClientConfig* crypto_config) : QuicClientSessionBase(connection, config), - crypto_stream_(server_key, this, NULL, crypto_config) { + crypto_stream_(server_id, this, NULL, crypto_config) { } QuicClientSession::~QuicClientSession() { diff --git a/net/tools/quic/quic_client_session.h b/net/tools/quic/quic_client_session.h index 6f7a1ba..3aad445 100644 --- a/net/tools/quic/quic_client_session.h +++ b/net/tools/quic/quic_client_session.h @@ -18,14 +18,14 @@ namespace net { class QuicConnection; -class QuicSessionKey; +class QuicServerId; class ReliableQuicStream; namespace tools { class QuicClientSession : public QuicClientSessionBase { public: - QuicClientSession(const QuicSessionKey& server_key, + QuicClientSession(const QuicServerId& server_id, const QuicConfig& config, QuicConnection* connection, QuicCryptoClientConfig* crypto_config); diff --git a/net/tools/quic/quic_client_session_test.cc b/net/tools/quic/quic_client_session_test.cc index 286de4c..7b50f42 100644 --- a/net/tools/quic/quic_client_session_test.cc +++ b/net/tools/quic/quic_client_session_test.cc @@ -35,8 +35,10 @@ class ToolsQuicClientSessionTest SupportedVersions(GetParam()))) { crypto_config_.SetDefaults(); session_.reset(new QuicClientSession( - QuicSessionKey(kServerHostname, kPort, false, PRIVACY_MODE_DISABLED), - DefaultQuicConfig(), connection_, &crypto_config_)); + QuicServerId(kServerHostname, kPort, false, PRIVACY_MODE_DISABLED), + DefaultQuicConfig(), + connection_, + &crypto_config_)); session_->config()->SetDefaults(); } diff --git a/net/tools/quic/quic_socket_utils.h b/net/tools/quic/quic_socket_utils.h index 38b7e51..988c746 100644 --- a/net/tools/quic/quic_socket_utils.h +++ b/net/tools/quic/quic_socket_utils.h @@ -42,7 +42,9 @@ class QuicSocketUtils { // // If self_address is non-null, it will be set to the address the peer sent // packets to, assuming a packet was read. - static int ReadPacket(int fd, char* buffer, size_t buf_len, + static int ReadPacket(int fd, + char* buffer, + size_t buf_len, uint32* dropped_packets, IPAddressNumber* self_address, IPEndPoint* peer_address); diff --git a/net/tools/quic/quic_spdy_client_stream_test.cc b/net/tools/quic/quic_spdy_client_stream_test.cc index 37b5086..d3d5667 100644 --- a/net/tools/quic/quic_spdy_client_stream_test.cc +++ b/net/tools/quic/quic_spdy_client_stream_test.cc @@ -30,10 +30,10 @@ class QuicSpdyClientStreamTest : public TestWithParam<QuicVersion> { QuicSpdyClientStreamTest() : connection_(new StrictMock<MockConnection>( false, SupportedVersions(GetParam()))), - session_(QuicSessionKey("example.com", 80, false, - PRIVACY_MODE_DISABLED), + session_(QuicServerId("example.com", 80, false, PRIVACY_MODE_DISABLED), DefaultQuicConfig(), - connection_, &crypto_config_), + connection_, + &crypto_config_), body_("hello world") { crypto_config_.SetDefaults(); diff --git a/net/tools/quic/test_tools/quic_test_client.cc b/net/tools/quic/test_tools/quic_test_client.cc index eea3a50..37bfb74 100644 --- a/net/tools/quic/test_tools/quic_test_client.cc +++ b/net/tools/quic/test_tools/quic_test_client.cc @@ -10,7 +10,7 @@ #include "net/cert/cert_verify_result.h" #include "net/cert/x509_certificate.h" #include "net/quic/crypto/proof_verifier.h" -#include "net/quic/quic_session_key.h" +#include "net/quic/quic_server_id.h" #include "net/quic/test_tools/quic_connection_peer.h" #include "net/quic/test_tools/quic_test_utils.h" #include "net/tools/balsa/balsa_headers.h" @@ -22,6 +22,7 @@ #include "url/gurl.h" using base::StringPiece; +using net::QuicServerId; using net::test::kInitialFlowControlWindowForTest; using net::test::QuicConnectionPeer; using std::string; @@ -101,11 +102,11 @@ BalsaHeaders* MungeHeaders(const BalsaHeaders* const_headers, class MockableQuicClient : public QuicClient { public: MockableQuicClient(IPEndPoint server_address, - const QuicSessionKey& server_key, + const QuicServerId& server_id, const QuicVersionVector& supported_versions, uint32 initial_flow_control_window) : QuicClient(server_address, - server_key, + server_id, supported_versions, false, initial_flow_control_window), @@ -113,12 +114,12 @@ class MockableQuicClient : public QuicClient { test_writer_(NULL) {} MockableQuicClient(IPEndPoint server_address, - const QuicSessionKey& server_key, + const QuicServerId& server_id, const QuicConfig& config, const QuicVersionVector& supported_versions, uint32 initial_flow_control_window) : QuicClient(server_address, - server_key, + server_id, config, supported_versions, initial_flow_control_window), @@ -155,53 +156,69 @@ class MockableQuicClient : public QuicClient { override_connection_id_ = connection_id; } + virtual int ReadPacket(char* buffer, + int buffer_len, + IPEndPoint* server_address, + IPAddressNumber* client_ip) OVERRIDE { + return QuicClient::ReadPacket( + buffer, buffer_len, server_address, client_ip); + } + private: QuicConnectionId override_connection_id_; // ConnectionId to use, if nonzero QuicPacketWriterWrapper* test_writer_; }; -QuicTestClient::QuicTestClient(IPEndPoint address, - const QuicSessionKey& server_key, +QuicTestClient::QuicTestClient(IPEndPoint server_address, + const string& server_hostname, const QuicVersionVector& supported_versions) - : client_(new MockableQuicClient(address, - server_key, + : client_(new MockableQuicClient(server_address, + QuicServerId(server_hostname, + server_address.port(), + false, + PRIVACY_MODE_DISABLED), supported_versions, kInitialFlowControlWindowForTest)) { - Initialize(address, server_key, true); + Initialize(server_address, server_hostname, true); } -QuicTestClient::QuicTestClient(IPEndPoint address, - const QuicSessionKey& server_key, +QuicTestClient::QuicTestClient(IPEndPoint server_address, + const string& server_hostname, bool secure, const QuicVersionVector& supported_versions) - : client_(new MockableQuicClient(address, - server_key, + : client_(new MockableQuicClient(server_address, + QuicServerId(server_hostname, + server_address.port(), + secure, + PRIVACY_MODE_DISABLED), supported_versions, kInitialFlowControlWindowForTest)) { - Initialize(address, server_key, secure); + Initialize(server_address, server_hostname, secure); } QuicTestClient::QuicTestClient( - IPEndPoint address, - const QuicSessionKey& server_key, + IPEndPoint server_address, + const string& server_hostname, bool secure, const QuicConfig& config, const QuicVersionVector& supported_versions, uint32 client_initial_flow_control_receive_window) : client_( - new MockableQuicClient(address, - server_key, + new MockableQuicClient(server_address, + QuicServerId(server_hostname, + server_address.port(), + secure, + PRIVACY_MODE_DISABLED), config, supported_versions, client_initial_flow_control_receive_window)) { - Initialize(address, server_key, secure); + Initialize(server_address, server_hostname, secure); } void QuicTestClient::Initialize(IPEndPoint address, - const QuicSessionKey& server_key, + const string& hostname, bool secure) { server_address_ = address; - server_key_ = server_key; priority_ = 3; connect_attempted_ = false; secure_ = secure; @@ -240,9 +257,9 @@ ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) { if (!connected()) { GURL url(message.headers()->request_uri().as_string()); if (!url.host().empty()) { - client_->set_server_key( - QuicSessionKey(url.host(), url.EffectiveIntPort(), - url.SchemeIs("https"), PRIVACY_MODE_DISABLED)); + client_->set_server_id( + QuicServerId(url.host(), url.EffectiveIntPort(), + url.SchemeIs("https"), PRIVACY_MODE_DISABLED)); } } @@ -323,7 +340,7 @@ QuicTagValueMap QuicTestClient::GetServerConfig() const { net::QuicCryptoClientConfig* config = QuicClientPeer::GetCryptoConfig(client_.get()); net::QuicCryptoClientConfig::CachedState* state = - config->LookupOrCreate(client_->server_key()); + config->LookupOrCreate(client_->server_id()); const net::CryptoHandshakeMessage* handshake_msg = state->GetServerConfig(); if (handshake_msg != NULL) { return handshake_msg->tag_value_map(); diff --git a/net/tools/quic/test_tools/quic_test_client.h b/net/tools/quic/test_tools/quic_test_client.h index 114c520..311d0a7 100644 --- a/net/tools/quic/test_tools/quic_test_client.h +++ b/net/tools/quic/test_tools/quic_test_client.h @@ -17,7 +17,7 @@ namespace net { class ProofVerifier; -class QuicSessionKey; +class QuicServerId; namespace tools { @@ -32,14 +32,14 @@ class MockableQuicClient; class QuicTestClient : public QuicDataStream::Visitor { public: QuicTestClient(IPEndPoint server_address, - const QuicSessionKey& server_key, + const string& server_hostname, const QuicVersionVector& supported_versions); QuicTestClient(IPEndPoint server_address, - const QuicSessionKey& server_key, + const string& server_hostname, bool secure, const QuicVersionVector& supported_versions); QuicTestClient(IPEndPoint server_address, - const QuicSessionKey& server_key, + const string& server_hostname, bool secure, const QuicConfig& config, const QuicVersionVector& supported_versions, @@ -121,13 +121,10 @@ class QuicTestClient : public QuicDataStream::Visitor { void WaitForWriteToFlush(); private: - void Initialize(IPEndPoint address, - const QuicSessionKey& server_key, - bool secure); + void Initialize(IPEndPoint address, const std::string& hostname, bool secure); IPEndPoint server_address_; IPEndPoint client_address_; - QuicSessionKey server_key_; scoped_ptr<MockableQuicClient> client_; // The actual client QuicSpdyClientStream* stream_; |