diff options
45 files changed, 263 insertions, 351 deletions
diff --git a/net/net.gypi b/net/net.gypi index a31edc2..5a8087d 100644 --- a/net/net.gypi +++ b/net/net.gypi @@ -760,8 +760,6 @@ 'proxy/proxy_server_mac.cc', 'proxy/proxy_service.cc', 'proxy/proxy_service.h', - 'quic/congestion_control/cube_root.cc', - 'quic/congestion_control/cube_root.h', 'quic/congestion_control/cubic.cc', 'quic/congestion_control/cubic.h', 'quic/congestion_control/hybrid_slow_start.cc', @@ -1453,7 +1451,6 @@ 'proxy/proxy_script_fetcher_impl_unittest.cc', 'proxy/proxy_server_unittest.cc', 'proxy/proxy_service_unittest.cc', - 'quic/congestion_control/cube_root_test.cc', 'quic/congestion_control/cubic_test.cc', 'quic/congestion_control/hybrid_slow_start_test.cc', 'quic/congestion_control/pacing_sender_test.cc', diff --git a/net/quic/congestion_control/cube_root.cc b/net/quic/congestion_control/cube_root.cc deleted file mode 100644 index 191cccc..0000000 --- a/net/quic/congestion_control/cube_root.cc +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2013 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/congestion_control/cube_root.h" - -#include "base/logging.h" - -namespace { - -// Find last bit in a 64-bit word. -int FindMostSignificantBit(uint64 x) { - if (!x) { - return 0; - } - int r = 0; - if (x & 0xffffffff00000000ull) { - x >>= 32; - r += 32; - } - if (x & 0xffff0000u) { - x >>= 16; - r += 16; - } - if (x & 0xff00u) { - x >>= 8; - r += 8; - } - if (x & 0xf0u) { - x >>= 4; - r += 4; - } - if (x & 0xcu) { - x >>= 2; - r += 2; - } - if (x & 0x02u) { - x >>= 1; - r++; - } - if (x & 0x01u) { - r++; - } - return r; -} - -// 6 bits table [0..63] -const uint32 cube_root_table[] = { - 0, 54, 54, 54, 118, 118, 118, 118, 123, 129, 134, 138, 143, 147, 151, - 156, 157, 161, 164, 168, 170, 173, 176, 179, 181, 185, 187, 190, 192, 194, - 197, 199, 200, 202, 204, 206, 209, 211, 213, 215, 217, 219, 221, 222, 224, - 225, 227, 229, 231, 232, 234, 236, 237, 239, 240, 242, 244, 245, 246, 248, - 250, 251, 252, 254 -}; -} // namespace - -namespace net { - -// Calculate the cube root using a table lookup followed by one Newton-Raphson -// iteration. -uint32 CubeRoot::Root(uint64 a) { - uint32 msb = FindMostSignificantBit(a); - DCHECK_LE(msb, 64u); - - if (msb < 7) { - // MSB in our table. - return ((cube_root_table[a]) + 31) >> 6; - } - // MSB 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, ... - // cubic_shift 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, ... - uint32 cubic_shift = (msb - 4); - cubic_shift = ((cubic_shift * 342) >> 10); // Div by 3, biased high. - - // 4 to 6 bits accuracy depending on MSB. - uint64 root = - ((cube_root_table[a >> (cubic_shift * 3)] + 10) << cubic_shift) >> 6; - - // Make one Newton-Raphson iteration. - // Since x has an error (inaccuracy due to the use of fix point) we get a - // more accurate result by doing x * (x - 1) instead of x * x. - root = 2 * root + (a / (root * (root - 1))); - root = ((root * 341) >> 10); // Div by 3, biased low. - return static_cast<uint32>(root); -} - -} // namespace net diff --git a/net/quic/congestion_control/cube_root.h b/net/quic/congestion_control/cube_root.h deleted file mode 100644 index 293a719..0000000 --- a/net/quic/congestion_control/cube_root.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2013 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. - -#ifndef NET_QUIC_CONGESTION_CONTROL_CUBE_ROOT_H_ -#define NET_QUIC_CONGESTION_CONTROL_CUBE_ROOT_H_ - -#include "base/basictypes.h" -#include "net/base/net_export.h" - -namespace net { - -class NET_EXPORT_PRIVATE CubeRoot { - public: - // Calculates the cube root using a table lookup followed by one Newton- - // Raphson iteration. - static uint32 Root(uint64 a); - - private: - DISALLOW_COPY_AND_ASSIGN(CubeRoot); -}; - -} // namespace net -#endif // NET_QUIC_CONGESTION_CONTROL_CUBE_ROOT_H_ diff --git a/net/quic/congestion_control/cube_root_test.cc b/net/quic/congestion_control/cube_root_test.cc deleted file mode 100644 index 8f4729c..0000000 --- a/net/quic/congestion_control/cube_root_test.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2013 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 "base/basictypes.h" -#include "net/quic/congestion_control/cube_root.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace net { -namespace test { - -class CubeRootTest : public ::testing::Test { - protected: - CubeRootTest() { - } -}; - -TEST_F(CubeRootTest, LowRoot) { - for (uint32 i = 1; i < 256; ++i) { - uint64 cube = i * i * i; - uint8 cube_root = CubeRoot::Root(cube); - EXPECT_EQ(i, cube_root); - } -} - -TEST_F(CubeRootTest, HighRoot) { - // Test the range we will opperate in, 1300 to 130 000. - // We expect some loss in accuracy, accepting +-0.2%. - for (uint64 i = 1300; i < 20000; i += 100) { - uint64 cube = i * i * i; - uint32 cube_root = CubeRoot::Root(cube); - uint32 margin = cube_root >> 9; // Calculate 0.2% roughly by - // dividing by 512. - EXPECT_LE(i - margin, cube_root); - EXPECT_GE(i + margin, cube_root); - } - for (uint64 i = 20000; i < 130000; i *= 2) { - uint64 cube = i * i * i; - uint32 cube_root = CubeRoot::Root(cube); - uint32 margin = cube_root >> 9; - EXPECT_LE(i - margin, cube_root); - EXPECT_GE(i + margin, cube_root); - } -} - -} // namespace test -} // namespace net diff --git a/net/quic/congestion_control/cubic.cc b/net/quic/congestion_control/cubic.cc index 7b99057..dc6b89b 100644 --- a/net/quic/congestion_control/cubic.cc +++ b/net/quic/congestion_control/cubic.cc @@ -10,7 +10,6 @@ #include "base/basictypes.h" #include "base/logging.h" #include "base/time/time.h" -#include "net/quic/congestion_control/cube_root.h" #include "net/quic/quic_flags.h" #include "net/quic/quic_protocol.h" @@ -136,17 +135,9 @@ QuicPacketCount Cubic::CongestionWindowAfterAck( time_to_origin_point_ = 0; origin_point_congestion_window_ = current_congestion_window; } else { - if (FLAGS_quic_use_std_cbrt) { - time_to_origin_point_ = static_cast<uint32>( - cbrt(kCubeFactor * - (last_max_congestion_window_ - current_congestion_window))); - } else { - // TODO(rjshade): Remove CubeRoot source when removing - // FLAGS_quic_use_std_cbrt. - time_to_origin_point_ = - CubeRoot::Root(kCubeFactor * (last_max_congestion_window_ - - current_congestion_window)); - } + time_to_origin_point_ = + static_cast<uint32>(cbrt(kCubeFactor * (last_max_congestion_window_ - + current_congestion_window))); origin_point_congestion_window_ = last_max_congestion_window_; } diff --git a/net/quic/congestion_control/send_algorithm_simulator.cc b/net/quic/congestion_control/send_algorithm_simulator.cc index eedebe53..3d6d456 100644 --- a/net/quic/congestion_control/send_algorithm_simulator.cc +++ b/net/quic/congestion_control/send_algorithm_simulator.cc @@ -11,7 +11,6 @@ #include "net/quic/crypto/quic_random.h" using std::list; -using std::make_pair; using std::max; using std::min; using std::string; @@ -290,13 +289,13 @@ void SendAlgorithmSimulator::HandlePendingAck(Transfer* transfer) { if (it->sequence_number > sender->last_acked) { DVLOG(1) << "Lost packet:" << sender->last_acked << " dropped by buffer overflow."; - lost_packets.push_back(make_pair(sender->last_acked, info)); + lost_packets.push_back(std::make_pair(sender->last_acked, info)); continue; } if (it->lost) { - lost_packets.push_back(make_pair(sender->last_acked, info)); + lost_packets.push_back(std::make_pair(sender->last_acked, info)); } else { - acked_packets.push_back(make_pair(sender->last_acked, info)); + acked_packets.push_back(std::make_pair(sender->last_acked, info)); } // This packet has been acked or lost, remove it from sent_packets_. largest_observed = *it; diff --git a/net/quic/congestion_control/tcp_cubic_sender_test.cc b/net/quic/congestion_control/tcp_cubic_sender_test.cc index 17ca8bf..6cfa6c1 100644 --- a/net/quic/congestion_control/tcp_cubic_sender_test.cc +++ b/net/quic/congestion_control/tcp_cubic_sender_test.cc @@ -15,7 +15,6 @@ #include "net/quic/test_tools/quic_config_peer.h" #include "testing/gtest/include/gtest/gtest.h" -using std::make_pair; using std::min; namespace net { @@ -97,7 +96,7 @@ class TcpCubicSenderTest : public ::testing::Test { for (int i = 0; i < n; ++i) { ++acked_sequence_number_; acked_packets.push_back( - make_pair(acked_sequence_number_, standard_packet_)); + std::make_pair(acked_sequence_number_, standard_packet_)); } sender_->OnCongestionEvent( true, bytes_in_flight_, acked_packets, lost_packets); @@ -111,7 +110,7 @@ class TcpCubicSenderTest : public ::testing::Test { for (int i = 0; i < n; ++i) { ++acked_sequence_number_; lost_packets.push_back( - make_pair(acked_sequence_number_, standard_packet_)); + std::make_pair(acked_sequence_number_, standard_packet_)); } sender_->OnCongestionEvent( false, bytes_in_flight_, acked_packets, lost_packets); @@ -122,8 +121,7 @@ class TcpCubicSenderTest : public ::testing::Test { void LosePacket(QuicPacketSequenceNumber sequence_number) { SendAlgorithmInterface::CongestionVector acked_packets; SendAlgorithmInterface::CongestionVector lost_packets; - lost_packets.push_back( - make_pair(sequence_number, standard_packet_)); + lost_packets.push_back(std::make_pair(sequence_number, standard_packet_)); sender_->OnCongestionEvent( false, bytes_in_flight_, acked_packets, lost_packets); bytes_in_flight_ -= kDefaultTCPMSS; diff --git a/net/quic/crypto/crypto_framer.cc b/net/quic/crypto/crypto_framer.cc index 79e17ed..7f81f36 100644 --- a/net/quic/crypto/crypto_framer.cc +++ b/net/quic/crypto/crypto_framer.cc @@ -9,7 +9,6 @@ #include "net/quic/quic_data_writer.h" using base::StringPiece; -using std::make_pair; using std::pair; using std::vector; @@ -106,8 +105,8 @@ QuicData* CryptoFramer::ConstructHandshakeMessage( return nullptr; } - - QuicDataWriter writer(len); + scoped_ptr<char[]> buffer(new char[len]); + QuicDataWriter writer(len, buffer.get()); if (!writer.WriteUInt32(message.tag())) { DCHECK(false) << "Failed to write message tag."; return nullptr; @@ -181,7 +180,7 @@ QuicData* CryptoFramer::ConstructHandshakeMessage( } } - return new QuicData(writer.take(), len, true); + return new QuicData(buffer.release(), len, true); } void CryptoFramer::Clear() { @@ -242,8 +241,8 @@ QuicErrorCode CryptoFramer::Process(StringPiece input) { if (end_offset < last_end_offset) { return QUIC_CRYPTO_TAGS_OUT_OF_ORDER; } - tags_and_lengths_.push_back( - make_pair(tag, static_cast<size_t>(end_offset - last_end_offset))); + tags_and_lengths_.push_back(std::make_pair( + tag, static_cast<size_t>(end_offset - last_end_offset))); last_end_offset = end_offset; } values_len_ = last_end_offset; diff --git a/net/quic/crypto/quic_crypto_client_config.cc b/net/quic/crypto/quic_crypto_client_config.cc index 18e9e60..9ec19fd 100644 --- a/net/quic/crypto/quic_crypto_client_config.cc +++ b/net/quic/crypto/quic_crypto_client_config.cc @@ -23,8 +23,6 @@ #include "net/quic/quic_utils.h" using base::StringPiece; -using std::find; -using std::make_pair; using std::map; using std::string; using std::vector; @@ -324,7 +322,7 @@ QuicCryptoClientConfig::CachedState* QuicCryptoClientConfig::LookupOrCreate( } CachedState* cached = new CachedState; - cached_states_.insert(make_pair(server_id, cached)); + cached_states_.insert(std::make_pair(server_id, cached)); bool cache_populated = PopulateFromCanonicalConfig(server_id, cached); UMA_HISTOGRAM_BOOLEAN( "Net.QuicCryptoClientConfig.PopulatedFromCanonicalConfig", @@ -840,7 +838,7 @@ void QuicCryptoClientConfig::PreferAesGcm() { if (aead.size() <= 1) { return; } - QuicTagVector::iterator pos = find(aead.begin(), aead.end(), kAESG); + QuicTagVector::iterator pos = std::find(aead.begin(), aead.end(), kAESG); if (pos != aead.end()) { aead.erase(pos); aead.insert(aead.begin(), kAESG); diff --git a/net/quic/crypto/quic_crypto_server_config.cc b/net/quic/crypto/quic_crypto_server_config.cc index 091caed..7c76ba85 100644 --- a/net/quic/crypto/quic_crypto_server_config.cc +++ b/net/quic/crypto/quic_crypto_server_config.cc @@ -452,7 +452,7 @@ bool QuicCryptoServerConfig::SetConfigs( reinterpret_cast<const char *>(config->orbit), kOrbitSize) << " primary_time " << config->primary_time.ToUNIXSeconds() << " priority " << config->priority; - new_configs.insert(make_pair(config->id, config)); + new_configs.insert(std::make_pair(config->id, config)); } } @@ -836,7 +836,7 @@ void QuicCryptoServerConfig::SelectNewPrimaryConfig( return; } - sort(configs.begin(), configs.end(), ConfigPrimaryTimeLessThan); + std::sort(configs.begin(), configs.end(), ConfigPrimaryTimeLessThan); Config* best_candidate = configs[0].get(); diff --git a/net/quic/crypto/quic_crypto_server_config_test.cc b/net/quic/crypto/quic_crypto_server_config_test.cc index ac7f3e0..5134f50 100644 --- a/net/quic/crypto/quic_crypto_server_config_test.cc +++ b/net/quic/crypto/quic_crypto_server_config_test.cc @@ -21,7 +21,6 @@ #include "testing/gtest/include/gtest/gtest.h" using base::StringPiece; -using std::make_pair; using std::map; using std::pair; using std::string; @@ -152,7 +151,7 @@ class QuicCryptoServerConfigPeer { // varargs will promote the value to an int so we have to read that from // the stack and cast down. const bool is_primary = static_cast<bool>(va_arg(ap, int)); - expected.push_back(make_pair(server_config_id, is_primary)); + expected.push_back(std::make_pair(server_config_id, is_primary)); } va_end(ap); diff --git a/net/quic/crypto/strike_register.cc b/net/quic/crypto/strike_register.cc index fd5dc4f..c36d370 100644 --- a/net/quic/crypto/strike_register.cc +++ b/net/quic/crypto/strike_register.cc @@ -8,7 +8,6 @@ #include "base/logging.h" -using std::make_pair; using std::max; using std::min; using std::pair; @@ -324,7 +323,7 @@ pair<uint32, uint32> StrikeRegister::GetValidRange( uint32 current_time_internal) const { if (current_time_internal < horizon_) { // Empty valid range. - return make_pair(std::numeric_limits<uint32>::max(), 0); + return std::make_pair(std::numeric_limits<uint32>::max(), 0); } uint32 lower_bound; @@ -344,7 +343,7 @@ pair<uint32, uint32> StrikeRegister::GetValidRange( current_time_internal + min(current_time_internal - horizon_, window_secs_); - return make_pair(lower_bound, upper_bound); + return std::make_pair(lower_bound, upper_bound); } uint32 StrikeRegister::ExternalTimeToInternal(uint32 external_time) const { diff --git a/net/quic/crypto/strike_register_test.cc b/net/quic/crypto/strike_register_test.cc index df72357..73a6b2f 100644 --- a/net/quic/crypto/strike_register_test.cc +++ b/net/quic/crypto/strike_register_test.cc @@ -15,7 +15,6 @@ namespace { using net::InsertStatus; using net::StrikeRegister; -using std::make_pair; using std::min; using std::pair; using std::set; @@ -232,9 +231,8 @@ class SlowStrikeRegister { return net::NONCE_INVALID_TIME_FAILURE; } - pair<uint32, string> nonce = make_pair( - nonce_time, - string(reinterpret_cast<const char*>(nonce_bytes), 32)); + pair<uint32, string> nonce = std::make_pair( + nonce_time, string(reinterpret_cast<const char*>(nonce_bytes), 32)); set<pair<uint32, string> >::const_iterator it = nonces_.find(nonce); if (it != nonces_.end()) { diff --git a/net/quic/quic_connection.cc b/net/quic/quic_connection.cc index 2a59644..a441c1b 100644 --- a/net/quic/quic_connection.cc +++ b/net/quic/quic_connection.cc @@ -272,6 +272,9 @@ QuicConnection::QuicConnection(QuicConnectionId connection_id, framer_.set_received_entropy_calculator(&received_packet_manager_); stats_.connection_creation_time = clock_->ApproximateNow(); sent_packet_manager_.set_network_change_visitor(this); + if (FLAGS_quic_small_default_packet_size && is_server_) { + set_max_packet_length(kDefaultServerMaxPacketSize); + } } QuicConnection::~QuicConnection() { @@ -1584,9 +1587,7 @@ void QuicConnection::OnSerializedPacket( serialized_packet.retransmittable_frames-> set_encryption_level(encryption_level_); - if (FLAGS_quic_ack_notifier_informed_on_serialized) { - sent_packet_manager_.OnSerializedPacket(serialized_packet); - } + sent_packet_manager_.OnSerializedPacket(serialized_packet); } if (serialized_packet.is_fec_packet && fec_alarm_->IsSet()) { // If an FEC packet is serialized with the FEC alarm set, cancel the alarm. diff --git a/net/quic/quic_connection_test.cc b/net/quic/quic_connection_test.cc index a25065e..0dc817c 100644 --- a/net/quic/quic_connection_test.cc +++ b/net/quic/quic_connection_test.cc @@ -1004,6 +1004,64 @@ INSTANTIATE_TEST_CASE_P(SupportedVersion, QuicConnectionTest, ::testing::ValuesIn(QuicSupportedVersions())); +TEST_P(QuicConnectionTest, MaxPacketSize) { + EXPECT_FALSE(connection_.is_server()); + EXPECT_EQ(1350u, connection_.max_packet_length()); +} + +TEST_P(QuicConnectionTest, SmallerServerMaxPacketSize) { + ValueRestore<bool> old_flag(&FLAGS_quic_small_default_packet_size, true); + QuicConnectionId connection_id = 42; + bool kIsServer = true; + TestConnection connection(connection_id, IPEndPoint(), helper_.get(), + factory_, kIsServer, version()); + EXPECT_TRUE(connection.is_server()); + EXPECT_EQ(1000u, connection.max_packet_length()); +} + +TEST_P(QuicConnectionTest, ServerMaxPacketSize) { + ValueRestore<bool> old_flag(&FLAGS_quic_small_default_packet_size, false); + QuicConnectionId connection_id = 42; + bool kIsServer = true; + TestConnection connection(connection_id, IPEndPoint(), helper_.get(), + factory_, kIsServer, version()); + EXPECT_TRUE(connection.is_server()); + EXPECT_EQ(1350u, connection.max_packet_length()); +} + +TEST_P(QuicConnectionTest, IncreaseServerMaxPacketSize) { + EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); + + connection_.set_is_server(true); + connection_.set_max_packet_length(1000); + + QuicPacketHeader header; + header.public_header.connection_id = connection_id_; + header.public_header.reset_flag = false; + header.public_header.version_flag = true; + header.entropy_flag = false; + header.fec_flag = false; + header.packet_sequence_number = 1; + header.fec_group = 0; + + QuicFrames frames; + QuicPaddingFrame padding; + frames.push_back(QuicFrame(&frame1_)); + frames.push_back(QuicFrame(&padding)); + + scoped_ptr<QuicPacket> packet( + BuildUnsizedDataPacket(&framer_, header, frames)); + scoped_ptr<QuicEncryptedPacket> encrypted( + framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); + EXPECT_EQ(kMaxPacketSize, encrypted->length()); + + framer_.set_version(version()); + EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); + connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); + + EXPECT_EQ(kMaxPacketSize, connection_.max_packet_length()); +} + TEST_P(QuicConnectionTest, PacketsInOrder) { EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); diff --git a/net/quic/quic_crypto_client_stream.cc b/net/quic/quic_crypto_client_stream.cc index bcf0456..c7c0291 100644 --- a/net/quic/quic_crypto_client_stream.cc +++ b/net/quic/quic_crypto_client_stream.cc @@ -87,7 +87,9 @@ QuicCryptoClientStream::QuicCryptoClientStream( channel_id_source_callback_run_(false), channel_id_source_callback_(nullptr), verify_context_(verify_context), - proof_verify_callback_(nullptr) {} + proof_verify_callback_(nullptr) { + DCHECK(!session->connection()->is_server()); +} QuicCryptoClientStream::~QuicCryptoClientStream() { if (channel_id_source_callback_) { diff --git a/net/quic/quic_crypto_client_stream_test.cc b/net/quic/quic_crypto_client_stream_test.cc index 74fcc30..454d930 100644 --- a/net/quic/quic_crypto_client_stream_test.cc +++ b/net/quic/quic_crypto_client_stream_test.cc @@ -30,10 +30,12 @@ const uint16 kServerPort = 80; class QuicCryptoClientStreamTest : public ::testing::Test { public: QuicCryptoClientStreamTest() - : connection_(new PacketSavingConnection(false)), + : connection_(new PacketSavingConnection(/*is_server=*/false)), session_(new TestClientSession(connection_, DefaultQuicConfig())), server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED), - stream_(new QuicCryptoClientStream(server_id_, session_.get(), nullptr, + stream_(new QuicCryptoClientStream(server_id_, + session_.get(), + nullptr, &crypto_config_)) { session_->SetCryptoStream(stream_.get()); // Advance the time, because timers do not like uninitialized times. @@ -121,7 +123,7 @@ TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { // Seed the config with a cached server config. CompleteCryptoHandshake(); - connection_ = new PacketSavingConnection(true); + connection_ = new PacketSavingConnection(/*is_server=*/false); session_.reset(new TestClientSession(connection_, DefaultQuicConfig())); stream_.reset(new QuicCryptoClientStream(server_id_, session_.get(), nullptr, &crypto_config_)); diff --git a/net/quic/quic_crypto_server_stream.cc b/net/quic/quic_crypto_server_stream.cc index 3ec65b0..8e04298 100644 --- a/net/quic/quic_crypto_server_stream.cc +++ b/net/quic/quic_crypto_server_stream.cc @@ -32,7 +32,9 @@ QuicCryptoServerStream::QuicCryptoServerStream( crypto_config_(crypto_config), validate_client_hello_cb_(nullptr), num_handshake_messages_(0), - num_server_config_update_messages_sent_(0) {} + num_server_config_update_messages_sent_(0) { + DCHECK(session->connection()->is_server()); +} QuicCryptoServerStream::~QuicCryptoServerStream() { CancelOutstandingCallbacks(); diff --git a/net/quic/quic_crypto_server_stream_test.cc b/net/quic/quic_crypto_server_stream_test.cc index 847ed16..2b885fa 100644 --- a/net/quic/quic_crypto_server_stream_test.cc +++ b/net/quic/quic_crypto_server_stream_test.cc @@ -56,7 +56,7 @@ const uint16 kServerPort = 80; class QuicCryptoServerStreamTest : public ::testing::TestWithParam<bool> { public: QuicCryptoServerStreamTest() - : connection_(new PacketSavingConnection(true)), + : connection_(new PacketSavingConnection(/*is_server=*/true)), session_(connection_, DefaultQuicConfig()), crypto_config_(QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance()), @@ -133,8 +133,10 @@ TEST_P(QuicCryptoServerStreamTest, ConnectedAfterCHLO) { } TEST_P(QuicCryptoServerStreamTest, ZeroRTT) { - PacketSavingConnection* client_conn = new PacketSavingConnection(false); - PacketSavingConnection* server_conn = new PacketSavingConnection(false); + PacketSavingConnection* client_conn = + new PacketSavingConnection(/*is_server=*/false); + PacketSavingConnection* server_conn = + new PacketSavingConnection(/*is_server=*/true); client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(100000)); server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(100000)); @@ -166,8 +168,8 @@ TEST_P(QuicCryptoServerStreamTest, ZeroRTT) { // Now do another handshake, hopefully in 0-RTT. LOG(INFO) << "Resetting for 0-RTT handshake attempt"; - client_conn = new PacketSavingConnection(false); - server_conn = new PacketSavingConnection(false); + client_conn = new PacketSavingConnection(/*is_server=*/false); + server_conn = new PacketSavingConnection(/*is_server=*/true); // We need to advance time past the strike-server window so that it's // authoritative in this time span. client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000)); diff --git a/net/quic/quic_data_writer.cc b/net/quic/quic_data_writer.cc index be8b357..1c6e47f 100644 --- a/net/quic/quic_data_writer.cc +++ b/net/quic/quic_data_writer.cc @@ -16,22 +16,15 @@ using std::numeric_limits; namespace net { -QuicDataWriter::QuicDataWriter(size_t size) - : buffer_(new char[size]), - capacity_(size), - length_(0) { +QuicDataWriter::QuicDataWriter(size_t size, char* buffer) + : buffer_(buffer), capacity_(size), length_(0) { } QuicDataWriter::~QuicDataWriter() { - delete[] buffer_; } -char* QuicDataWriter::take() { - char* rv = buffer_; - buffer_ = nullptr; - capacity_ = 0; - length_ = 0; - return rv; +char* QuicDataWriter::data() { + return buffer_; } bool QuicDataWriter::WriteUInt8(uint8 value) { diff --git a/net/quic/quic_data_writer.h b/net/quic/quic_data_writer.h index 8204c3a..4b5958e 100644 --- a/net/quic/quic_data_writer.h +++ b/net/quic/quic_data_writer.h @@ -20,20 +20,20 @@ namespace net { // This class provides facilities for packing QUIC data. // // The QuicDataWriter supports appending primitive values (int, string, etc) -// to a frame instance. The QuicDataWriter grows its internal memory buffer -// dynamically to hold the sequence of primitive values. The internal memory -// buffer is exposed as the "data" of the QuicDataWriter. +// to a frame instance. The internal memory buffer is exposed as the "data" +// of the QuicDataWriter. class NET_EXPORT_PRIVATE QuicDataWriter { public: - explicit QuicDataWriter(size_t length); + // Creates a QuicDataWriter where |buffer| is not owned. + QuicDataWriter(size_t size, char* buffer); ~QuicDataWriter(); // Returns the size of the QuicDataWriter's data. size_t length() const { return length_; } - // Takes the buffer from the QuicDataWriter. - char* take(); + // Retrieves the buffer from the QuicDataWriter without changing ownership. + char* data(); // Methods for adding to the payload. These values are appended to the end // of the QuicDataWriter payload. Note - binary integers are written in diff --git a/net/quic/quic_data_writer_test.cc b/net/quic/quic_data_writer_test.cc index 07346c7..01b3c6d 100644 --- a/net/quic/quic_data_writer_test.cc +++ b/net/quic/quic_data_writer_test.cc @@ -14,7 +14,8 @@ namespace test { namespace { TEST(QuicDataWriterTest, WriteUInt8ToOffset) { - QuicDataWriter writer(4); + char buffer[4]; + QuicDataWriter writer(4, buffer); writer.WriteUInt32(0xfefdfcfb); EXPECT_TRUE(writer.WriteUInt8ToOffset(1, 0)); @@ -22,16 +23,15 @@ TEST(QuicDataWriterTest, WriteUInt8ToOffset) { EXPECT_TRUE(writer.WriteUInt8ToOffset(3, 2)); EXPECT_TRUE(writer.WriteUInt8ToOffset(4, 3)); - scoped_ptr<char[]> data(writer.take()); - - EXPECT_EQ(1, data[0]); - EXPECT_EQ(2, data[1]); - EXPECT_EQ(3, data[2]); - EXPECT_EQ(4, data[3]); + EXPECT_EQ(1, writer.data()[0]); + EXPECT_EQ(2, writer.data()[1]); + EXPECT_EQ(3, writer.data()[2]); + EXPECT_EQ(4, writer.data()[3]); } TEST(QuicDataWriterDeathTest, WriteUInt8ToOffset) { - QuicDataWriter writer(4); + char buffer[4]; + QuicDataWriter writer(4, buffer); EXPECT_DFATAL(EXPECT_FALSE(writer.WriteUInt8ToOffset(5, 4)), "offset: 4 >= capacity: 4"); @@ -80,10 +80,10 @@ TEST(QuicDataWriterTest, WriteUFloat16) { int num_test_cases = sizeof(test_cases) / sizeof(test_cases[0]); for (int i = 0; i < num_test_cases; ++i) { - QuicDataWriter writer(2); + char buffer[2]; + QuicDataWriter writer(2, buffer); EXPECT_TRUE(writer.WriteUFloat16(test_cases[i].decoded)); - scoped_ptr<char[]> data(writer.take()); - EXPECT_EQ(test_cases[i].encoded, *reinterpret_cast<uint16*>(data.get())); + EXPECT_EQ(test_cases[i].encoded, *reinterpret_cast<uint16*>(writer.data())); } } @@ -144,17 +144,18 @@ TEST(QuicDataWriterTest, RoundTripUFloat16) { // Check we're always within the promised range. EXPECT_LT(value, GG_UINT64_C(0x3FFC0000000)); previous_value = value; - QuicDataWriter writer(6); + char buffer[6]; + QuicDataWriter writer(6, buffer); EXPECT_TRUE(writer.WriteUFloat16(value - 1)); EXPECT_TRUE(writer.WriteUFloat16(value)); EXPECT_TRUE(writer.WriteUFloat16(value + 1)); - scoped_ptr<char[]> data(writer.take()); // Check minimal decoding (previous decoding has previous encoding). - EXPECT_EQ(i-1, *reinterpret_cast<uint16*>(data.get())); + EXPECT_EQ(i - 1, *reinterpret_cast<uint16*>(writer.data())); // Check roundtrip. - EXPECT_EQ(i, *reinterpret_cast<uint16*>(data.get() + 2)); + EXPECT_EQ(i, *reinterpret_cast<uint16*>(writer.data() + 2)); // Check next decoding. - EXPECT_EQ(i < 4096? i+1 : i, *reinterpret_cast<uint16*>(data.get() + 4)); + EXPECT_EQ(i < 4096 ? i + 1 : i, + *reinterpret_cast<uint16*>(writer.data() + 4)); } } diff --git a/net/quic/quic_dispatcher.cc b/net/quic/quic_dispatcher.cc index f1ae736..f750bfa 100644 --- a/net/quic/quic_dispatcher.cc +++ b/net/quic/quic_dispatcher.cc @@ -249,7 +249,7 @@ bool QuicDispatcher::OnUnauthenticatedPublicHeader( return HandlePacketForTimeWait(header); } DVLOG(1) << "Created new session for " << connection_id; - session_map_.insert(make_pair(connection_id, session)); + session_map_.insert(std::make_pair(connection_id, session)); } else { session = it->second; } @@ -344,7 +344,7 @@ void QuicDispatcher::OnWriteBlocked( // infinite loops in OnCanWrite. return; } - write_blocked_list_.insert(make_pair(blocked_writer, true)); + write_blocked_list_.insert(std::make_pair(blocked_writer, true)); } void QuicDispatcher::OnConnectionAddedToTimeWaitList( diff --git a/net/quic/quic_flags.cc b/net/quic/quic_flags.cc index 5997e90..e4514cb 100644 --- a/net/quic/quic_flags.cc +++ b/net/quic/quic_flags.cc @@ -39,10 +39,7 @@ bool FLAGS_quic_enable_bandwidth_resumption_experiment = true; // If true, QUIC congestion control will be paced. If false, pacing may be // controlled by QUIC connection options in the config or by enabling BBR // congestion control. -bool FLAGS_quic_enable_pacing = false; - -// If true, use std::cbrt instead of custom cube root. -bool FLAGS_quic_use_std_cbrt = true; +bool FLAGS_quic_enable_pacing = true; // If true, then the source address tokens generated for QUIC connects will // store multiple addresses. @@ -55,10 +52,6 @@ bool FLAGS_quic_rto_uses_last_sent = true; // frames. bool FLAGS_quic_attach_ack_notifiers_to_packets = true; -// If true, the AckNotifierManager is informed about new packets as soon as they -// are serialized. -bool FLAGS_quic_ack_notifier_informed_on_serialized = true; - // If true, QUIC will use the new RTO that waits until an ack arrives to adjust // the congestion window. bool FLAGS_quic_use_new_rto = true; @@ -80,3 +73,6 @@ int64 FLAGS_quic_time_wait_list_max_connections = 50000; // If true, limit the number of connections on the quic time-wait list using a // flag. bool FLAGS_quic_limit_time_wait_list_size = true; + +// Use small QUIC packet sizes by default. +bool FLAGS_quic_small_default_packet_size = true; diff --git a/net/quic/quic_flags.h b/net/quic/quic_flags.h index 5ad6062..decdcb1 100644 --- a/net/quic/quic_flags.h +++ b/net/quic/quic_flags.h @@ -19,14 +19,13 @@ NET_EXPORT_PRIVATE extern bool FLAGS_quic_record_send_time_before_write; NET_EXPORT_PRIVATE extern bool FLAGS_quic_enable_bandwidth_resumption_experiment; NET_EXPORT_PRIVATE extern bool FLAGS_quic_enable_pacing; -NET_EXPORT_PRIVATE extern bool FLAGS_quic_use_std_cbrt; NET_EXPORT_PRIVATE extern bool FLAGS_quic_use_multiple_address_in_source_tokens; NET_EXPORT_PRIVATE extern bool FLAGS_quic_rto_uses_last_sent; NET_EXPORT_PRIVATE extern bool FLAGS_quic_attach_ack_notifiers_to_packets; -NET_EXPORT_PRIVATE extern bool FLAGS_quic_ack_notifier_informed_on_serialized; NET_EXPORT_PRIVATE extern bool FLAGS_quic_use_new_rto; NET_EXPORT_PRIVATE extern int64 FLAGS_quic_time_wait_list_seconds; NET_EXPORT_PRIVATE extern int64 FLAGS_quic_time_wait_list_max_connections; NET_EXPORT_PRIVATE extern bool FLAGS_quic_limit_time_wait_list_size; +NET_EXPORT_PRIVATE extern bool FLAGS_quic_small_default_packet_size; #endif // NET_QUIC_QUIC_FLAGS_H_ diff --git a/net/quic/quic_framer.cc b/net/quic/quic_framer.cc index 3eda6b3..4ff23a4 100644 --- a/net/quic/quic_framer.cc +++ b/net/quic/quic_framer.cc @@ -17,7 +17,6 @@ #include "net/quic/quic_socket_address_coder.h" using base::StringPiece; -using std::make_pair; using std::map; using std::max; using std::min; @@ -318,8 +317,9 @@ QuicPacketEntropyHash QuicFramer::GetPacketEntropyHash( QuicPacket* QuicFramer::BuildDataPacket(const QuicPacketHeader& header, const QuicFrames& frames, - size_t packet_size) { - QuicDataWriter writer(packet_size); + char* buffer, + size_t packet_length) { + QuicDataWriter writer(packet_length, buffer); if (!AppendPacketHeader(header, &writer)) { LOG(DFATAL) << "AppendPacketHeader failed"; return nullptr; @@ -403,15 +403,11 @@ QuicPacket* QuicFramer::BuildDataPacket(const QuicPacketHeader& header, ++i; } - // Save the length before writing, because take clears it. - const size_t len = writer.length(); - // Less than or equal because truncated acks end up with max_plaintex_size - // length, even though they're typically slightly shorter. - DCHECK_LE(len, packet_size); - QuicPacket* packet = new QuicPacket( - writer.take(), len, true, header.public_header.connection_id_length, - header.public_header.version_flag, - header.public_header.sequence_number_length); + QuicPacket* packet = + new QuicPacket(writer.data(), writer.length(), false, + header.public_header.connection_id_length, + header.public_header.version_flag, + header.public_header.sequence_number_length); if (fec_builder_) { fec_builder_->OnBuiltFecProtectedPayload(header, @@ -428,7 +424,8 @@ QuicPacket* QuicFramer::BuildFecPacket(const QuicPacketHeader& header, size_t len = GetPacketHeaderSize(header); len += fec.redundancy.length(); - QuicDataWriter writer(len); + scoped_ptr<char[]> buffer(new char[len]); + QuicDataWriter writer(len, buffer.get()); if (!AppendPacketHeader(header, &writer)) { LOG(DFATAL) << "AppendPacketHeader failed"; return nullptr; @@ -439,7 +436,7 @@ QuicPacket* QuicFramer::BuildFecPacket(const QuicPacketHeader& header, return nullptr; } - return new QuicPacket(writer.take(), len, true, + return new QuicPacket(buffer.release(), len, true, header.public_header.connection_id_length, header.public_header.version_flag, header.public_header.sequence_number_length); @@ -467,7 +464,8 @@ QuicEncryptedPacket* QuicFramer::BuildPublicResetPacket( size_t len = kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID + reset_serialized.length(); - QuicDataWriter writer(len); + scoped_ptr<char[]> buffer(new char[len]); + QuicDataWriter writer(len, buffer.get()); uint8 flags = static_cast<uint8>(PACKET_PUBLIC_FLAGS_RST | PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID); @@ -483,7 +481,7 @@ QuicEncryptedPacket* QuicFramer::BuildPublicResetPacket( return nullptr; } - return new QuicEncryptedPacket(writer.take(), len, true); + return new QuicEncryptedPacket(buffer.release(), len, true); } QuicEncryptedPacket* QuicFramer::BuildVersionNegotiationPacket( @@ -491,7 +489,8 @@ QuicEncryptedPacket* QuicFramer::BuildVersionNegotiationPacket( const QuicVersionVector& supported_versions) { DCHECK(header.version_flag); size_t len = GetVersionNegotiationPacketSize(supported_versions.size()); - QuicDataWriter writer(len); + scoped_ptr<char[]> buffer(new char[len]); + QuicDataWriter writer(len, buffer.get()); uint8 flags = static_cast<uint8>(PACKET_PUBLIC_FLAGS_VERSION | PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID); @@ -509,7 +508,7 @@ QuicEncryptedPacket* QuicFramer::BuildVersionNegotiationPacket( } } - return new QuicEncryptedPacket(writer.take(), len, true); + return new QuicEncryptedPacket(buffer.release(), len, true); } bool QuicFramer::ProcessPacket(const QuicEncryptedPacket& packet) { @@ -545,18 +544,16 @@ bool QuicFramer::ProcessPacket(const QuicEncryptedPacket& packet) { rv = ProcessVersionNegotiationPacket(&public_header); } else if (public_header.reset_flag) { rv = ProcessPublicResetPacket(public_header); + } else if (packet.length() <= kMaxPacketSize) { + char buffer[kMaxPacketSize]; + rv = ProcessDataPacket(public_header, packet, buffer, kMaxPacketSize); } else { - if (packet.length() <= kMaxPacketSize) { - char buffer[kMaxPacketSize]; - rv = ProcessDataPacket(public_header, packet, buffer, kMaxPacketSize); - } else { - scoped_ptr<char[]> buffer(new char[packet.length()]); - rv = ProcessDataPacket(public_header, packet, buffer.get(), - packet.length()); - LOG_IF(DFATAL, rv) << "QUIC should never successfully process packets " - << "larger than kMaxPacketSize. packet size:" - << packet.length(); - } + scoped_ptr<char[]> large_buffer(new char[packet.length()]); + rv = ProcessDataPacket(public_header, packet, large_buffer.get(), + packet.length()); + LOG_IF(DFATAL, rv) << "QUIC should never successfully process packets " + << "larger than kMaxPacketSize. packet size:" + << packet.length(); } reader_.reset(nullptr); @@ -1409,7 +1406,7 @@ bool QuicFramer::ProcessTimestampsInAckFrame(QuicAckFrame* ack_frame) { last_timestamp_ = CalculateTimestampFromWire(time_delta_us); ack_frame->received_packet_times.push_back( - make_pair(seq_num, creation_time_.Add(last_timestamp_))); + std::make_pair(seq_num, creation_time_.Add(last_timestamp_))); for (uint8 i = 1; i < num_received_packets; ++i) { if (!reader_->ReadBytes(&delta_from_largest_observed, @@ -1431,7 +1428,7 @@ bool QuicFramer::ProcessTimestampsInAckFrame(QuicAckFrame* ack_frame) { last_timestamp_ = last_timestamp_.Add( QuicTime::Delta::FromMicroseconds(incremental_time_delta_us)); ack_frame->received_packet_times.push_back( - make_pair(seq_num, creation_time_.Add(last_timestamp_))); + std::make_pair(seq_num, creation_time_.Add(last_timestamp_))); } } } diff --git a/net/quic/quic_framer.h b/net/quic/quic_framer.h index abd2e31..3cfaa88 100644 --- a/net/quic/quic_framer.h +++ b/net/quic/quic_framer.h @@ -306,7 +306,8 @@ class NET_EXPORT_PRIVATE QuicFramer { // The packet must be of size |packet_size|. QuicPacket* BuildDataPacket(const QuicPacketHeader& header, const QuicFrames& frames, - size_t packet_size); + char* buffer, + size_t packet_length); // Returns a QuicPacket* that is owned by the caller, and is populated with // the fields in |header| and |fec|. Returns nullptr if the packet could diff --git a/net/quic/quic_framer_test.cc b/net/quic/quic_framer_test.cc index 07a3510..69373e0 100644 --- a/net/quic/quic_framer_test.cc +++ b/net/quic/quic_framer_test.cc @@ -479,6 +479,12 @@ class QuicFramerTest : public ::testing::TestWithParam<QuicVersion> { return BuildUnsizedDataPacket(&framer_, header, frames); } + QuicPacket* BuildDataPacket(const QuicPacketHeader& header, + const QuicFrames& frames, + size_t packet_size) { + return BuildUnsizedDataPacket(&framer_, header, frames, packet_size); + } + test::TestEncrypter* encrypter_; test::TestDecrypter* decrypter_; QuicVersion version_; @@ -3393,8 +3399,7 @@ TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacket) { 0x00, }; - scoped_ptr<QuicPacket> data( - framer_.BuildDataPacket(header, frames, kMaxPacketSize)); + scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); ASSERT_TRUE(data != nullptr); test::CompareCharArraysWithHexError("constructed packet", @@ -3456,7 +3461,7 @@ TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacket) { 0x00, }; - scoped_ptr<QuicPacket> data(framer_.BuildDataPacket(header, frames, 37u)); + scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames, 37u)); ASSERT_TRUE(data != nullptr); // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks. EXPECT_EQ(36u, data->length()); @@ -4024,8 +4029,7 @@ TEST_P(QuicFramerTest, AckTruncationLargePacket) { frames.push_back(frame); // Build an ack packet with truncation due to limit in number of nack ranges. - scoped_ptr<QuicPacket> raw_ack_packet( - framer_.BuildDataPacket(header, frames, kMaxPacketSize)); + scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); ASSERT_TRUE(raw_ack_packet != nullptr); scoped_ptr<QuicEncryptedPacket> ack_packet( framer_.EncryptPacket(ENCRYPTION_NONE, header.packet_sequence_number, @@ -4064,8 +4068,7 @@ TEST_P(QuicFramerTest, AckTruncationSmallPacket) { frames.push_back(frame); // Build an ack packet with truncation due to limit in number of nack ranges. - scoped_ptr<QuicPacket> raw_ack_packet( - framer_.BuildDataPacket(header, frames, 500)); + scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames, 500)); ASSERT_TRUE(raw_ack_packet != nullptr); scoped_ptr<QuicEncryptedPacket> ack_packet( framer_.EncryptPacket(ENCRYPTION_NONE, header.packet_sequence_number, diff --git a/net/quic/quic_packet_creator.cc b/net/quic/quic_packet_creator.cc index bd4541e..e91efa2 100644 --- a/net/quic/quic_packet_creator.cc +++ b/net/quic/quic_packet_creator.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "net/quic/crypto/quic_random.h" #include "net/quic/quic_ack_notifier.h" +#include "net/quic/quic_data_writer.h" #include "net/quic/quic_fec_group.h" #include "net/quic/quic_utils.h" @@ -297,8 +298,8 @@ SerializedPacket QuicPacketCreator::SerializeAllFrames( DCHECK_EQ(0u, queued_frames_.size()); LOG_IF(DFATAL, frames.empty()) << "Attempt to serialize empty packet"; - for (size_t i = 0; i < frames.size(); ++i) { - bool success = AddFrame(frames[i], false); + for (const QuicFrame& frame : frames) { + bool success = AddFrame(frame, false); DCHECK(success); } SerializedPacket packet = SerializePacket(); @@ -372,8 +373,19 @@ SerializedPacket QuicPacketCreator::SerializePacket() { bool possibly_truncated_by_length = packet_size_ == max_plaintext_size && queued_frames_.size() == 1 && queued_frames_.back().type == ACK_FRAME; - scoped_ptr<QuicPacket> packet( - framer_->BuildDataPacket(header, queued_frames_, packet_size_)); + char buffer[kMaxPacketSize]; + scoped_ptr<QuicPacket> packet; + // Use the packet_size_ instead of the buffer size to ensure smaller + // packet sizes are properly used. + scoped_ptr<char[]> large_buffer; + if (packet_size_ <= kMaxPacketSize) { + packet.reset( + framer_->BuildDataPacket(header, queued_frames_, buffer, packet_size_)); + } else { + large_buffer.reset(new char[packet_size_]); + packet.reset(framer_->BuildDataPacket(header, queued_frames_, + large_buffer.get(), packet_size_)); + } LOG_IF(DFATAL, packet == nullptr) << "Failed to serialize " << queued_frames_.size() << " frames."; // Because of possible truncation, we can't be confident that our diff --git a/net/quic/quic_protocol.h b/net/quic/quic_protocol.h index 19ff84a..058e548 100644 --- a/net/quic/quic_protocol.h +++ b/net/quic/quic_protocol.h @@ -48,9 +48,10 @@ typedef std::map<QuicTag, std::string> QuicTagValueMap; // QuicPriority is uint32. Use SpdyPriority when we change the QUIC_VERSION. typedef uint32 QuicPriority; -// TODO(rch): Consider Quic specific names for these constants. // Default and initial maximum size in bytes of a QUIC packet. const QuicByteCount kDefaultMaxPacketSize = 1350; +// Default initial maximum size in bytes of a QUIC packet for servers. +const QuicByteCount kDefaultServerMaxPacketSize = 1000; // The maximum packet size of any QUIC packet, based on ethernet's max size, // minus the IP and UDP headers. IPv6 has a 40 byte header, UPD adds an // additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's diff --git a/net/quic/quic_received_packet_manager.cc b/net/quic/quic_received_packet_manager.cc index f5e2c36..dcc7823 100644 --- a/net/quic/quic_received_packet_manager.cc +++ b/net/quic/quic_received_packet_manager.cc @@ -13,7 +13,6 @@ #include "net/quic/crypto/crypto_protocol.h" #include "net/quic/quic_connection_stats.h" -using std::make_pair; using std::max; using std::min; using std::numeric_limits; @@ -81,13 +80,13 @@ void QuicReceivedPacketManager::EntropyTracker::RecordPacketEntropyHash( if (sequence_number > largest_observed_) { for (QuicPacketSequenceNumber i = 0; i < (sequence_number - largest_observed_ - 1); ++i) { - packets_entropy_.push_back(make_pair(0, false)); + packets_entropy_.push_back(std::make_pair(0, false)); } - packets_entropy_.push_back(make_pair(entropy_hash, true)); + packets_entropy_.push_back(std::make_pair(entropy_hash, true)); largest_observed_ = sequence_number; } else { packets_entropy_[sequence_number - first_gap_] = - make_pair(entropy_hash, true); + std::make_pair(entropy_hash, true); AdvanceFirstGapAndGarbageCollectEntropyMap(); } diff --git a/net/quic/quic_received_packet_manager_test.cc b/net/quic/quic_received_packet_manager_test.cc index b64025b..d91e4e0 100644 --- a/net/quic/quic_received_packet_manager_test.cc +++ b/net/quic/quic_received_packet_manager_test.cc @@ -12,7 +12,6 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -using std::make_pair; using std::pair; using std::vector; @@ -214,17 +213,17 @@ class QuicReceivedPacketManagerTest : public ::testing::Test { TEST_F(QuicReceivedPacketManagerTest, ReceivedPacketEntropyHash) { vector<pair<QuicPacketSequenceNumber, QuicPacketEntropyHash> > entropies; - entropies.push_back(make_pair(1, 12)); - entropies.push_back(make_pair(7, 1)); - entropies.push_back(make_pair(2, 33)); - entropies.push_back(make_pair(5, 3)); - entropies.push_back(make_pair(8, 34)); + entropies.push_back(std::make_pair(1, 12)); + entropies.push_back(std::make_pair(7, 1)); + entropies.push_back(std::make_pair(2, 33)); + entropies.push_back(std::make_pair(5, 3)); + entropies.push_back(std::make_pair(8, 34)); for (size_t i = 0; i < entropies.size(); ++i) { RecordPacketReceipt(entropies[i].first, entropies[i].second); } - sort(entropies.begin(), entropies.end()); + std::sort(entropies.begin(), entropies.end()); QuicPacketEntropyHash hash = 0; size_t index = 0; @@ -256,12 +255,12 @@ TEST_F(QuicReceivedPacketManagerTest, EntropyHashAboveLargestObserved) { TEST_F(QuicReceivedPacketManagerTest, SetCumulativeEntropyUpTo) { vector<pair<QuicPacketSequenceNumber, QuicPacketEntropyHash> > entropies; - entropies.push_back(make_pair(1, 12)); - entropies.push_back(make_pair(2, 1)); - entropies.push_back(make_pair(3, 33)); - entropies.push_back(make_pair(4, 3)); - entropies.push_back(make_pair(6, 34)); - entropies.push_back(make_pair(7, 29)); + entropies.push_back(std::make_pair(1, 12)); + entropies.push_back(std::make_pair(2, 1)); + entropies.push_back(std::make_pair(3, 33)); + entropies.push_back(std::make_pair(4, 3)); + entropies.push_back(std::make_pair(6, 34)); + entropies.push_back(std::make_pair(7, 29)); QuicPacketEntropyHash entropy_hash = 0; for (size_t i = 0; i < entropies.size(); ++i) { diff --git a/net/quic/quic_sent_packet_manager.cc b/net/quic/quic_sent_packet_manager.cc index c1811cf..60fd0f5 100644 --- a/net/quic/quic_sent_packet_manager.cc +++ b/net/quic/quic_sent_packet_manager.cc @@ -15,7 +15,6 @@ #include "net/quic/quic_flags.h" #include "net/quic/quic_utils_chromium.h" -using std::make_pair; using std::max; using std::min; @@ -329,7 +328,7 @@ void QuicSentPacketManager::HandleAckForSentPackets( // If data is associated with the most recent transmission of this // packet, then inform the caller. if (it->in_flight) { - packets_acked_.push_back(make_pair(sequence_number, *it)); + packets_acked_.push_back(std::make_pair(sequence_number, *it)); } MarkPacketHandled(sequence_number, *it, delta_largest_observed); } @@ -561,12 +560,7 @@ bool QuicSentPacketManager::OnPacketSent( DCHECK(!unacked_packets_.IsUnacked(sequence_number)); LOG_IF(DFATAL, bytes == 0) << "Cannot send empty packets."; - if (original_sequence_number == 0) { - if (!FLAGS_quic_ack_notifier_informed_on_serialized && - serialized_packet->retransmittable_frames) { - ack_notifier_manager_.OnSerializedPacket(*serialized_packet); - } - } else { + if (original_sequence_number != 0) { PendingRetransmissionMap::iterator it = pending_retransmissions_.find(original_sequence_number); if (it != pending_retransmissions_.end()) { @@ -793,7 +787,7 @@ void QuicSentPacketManager::InvokeLossDetection(QuicTime time) { // should be recorded as a loss to the send algorithm, but not retransmitted // until it's known whether the FEC packet arrived. ++stats_->packets_lost; - packets_lost_.push_back(make_pair(sequence_number, transmission_info)); + packets_lost_.push_back(std::make_pair(sequence_number, transmission_info)); DVLOG(1) << ENDPOINT << "Lost packet " << sequence_number; if (transmission_info.retransmittable_frames != nullptr) { diff --git a/net/quic/quic_sent_packet_manager_test.cc b/net/quic/quic_sent_packet_manager_test.cc index 6615036..82d45d6 100644 --- a/net/quic/quic_sent_packet_manager_test.cc +++ b/net/quic/quic_sent_packet_manager_test.cc @@ -1154,6 +1154,8 @@ TEST_F(QuicSentPacketManagerTest, NewRetransmissionTimeout) { EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); EXPECT_CALL(*network_change_visitor_, OnRttChange()); EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); + EXPECT_CALL(*send_algorithm_, PacingRate()) + .WillRepeatedly(Return(QuicBandwidth::Zero())); manager_.SetFromConfig(client_config); EXPECT_TRUE(QuicSentPacketManagerPeer::GetUseNewRto(&manager_)); @@ -1721,6 +1723,8 @@ TEST_F(QuicSentPacketManagerTest, NegotiateReceiveWindowFromOptions) { QuicConfig client_config; QuicConfigPeer::SetReceivedSocketReceiveBuffer(&client_config, 1024); EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); + EXPECT_CALL(*send_algorithm_, PacingRate()) + .WillRepeatedly(Return(QuicBandwidth::Zero())); EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); EXPECT_CALL(*network_change_visitor_, OnRttChange()); manager_.SetFromConfig(client_config); diff --git a/net/quic/quic_stream_sequencer.cc b/net/quic/quic_stream_sequencer.cc index 7a9ae0d..7f06ec4 100644 --- a/net/quic/quic_stream_sequencer.cc +++ b/net/quic/quic_stream_sequencer.cc @@ -11,7 +11,6 @@ #include "base/metrics/sparse_histogram.h" #include "net/quic/reliable_quic_stream.h" -using std::make_pair; using std::min; using std::numeric_limits; using std::string; @@ -103,7 +102,7 @@ void QuicStreamSequencer::OnStreamFrame(const QuicStreamFrame& frame) { for (size_t i = 0; i < data.Size(); ++i) { DVLOG(1) << "Buffering stream data at offset " << byte_offset; const iovec& iov = data.iovec()[i]; - buffered_frames_.insert(make_pair( + buffered_frames_.insert(std::make_pair( byte_offset, string(static_cast<char*>(iov.iov_base), iov.iov_len))); byte_offset += iov.iov_len; num_bytes_buffered_ += iov.iov_len; @@ -195,8 +194,8 @@ int QuicStreamSequencer::Readv(const struct iovec* iov, size_t iov_len) { } // We've finished copying. If we have a partial frame, update it. if (frame_offset != 0) { - buffered_frames_.insert( - make_pair(it->first + frame_offset, it->second.substr(frame_offset))); + buffered_frames_.insert(std::make_pair(it->first + frame_offset, + it->second.substr(frame_offset))); buffered_frames_.erase(buffered_frames_.begin()); RecordBytesConsumed(frame_offset); } @@ -283,7 +282,7 @@ void QuicStreamSequencer::FlushBufferedFrames() { } else { string new_data = it->second.substr(bytes_consumed); buffered_frames_.erase(it); - buffered_frames_.insert(make_pair(num_bytes_consumed_, new_data)); + buffered_frames_.insert(std::make_pair(num_bytes_consumed_, new_data)); return; } } diff --git a/net/quic/quic_stream_sequencer_test.cc b/net/quic/quic_stream_sequencer_test.cc index 9db0234..6e3d57d 100644 --- a/net/quic/quic_stream_sequencer_test.cc +++ b/net/quic/quic_stream_sequencer_test.cc @@ -338,7 +338,7 @@ class QuicSequencerRandomTest : public QuicStreamSequencerTest { while (remaining_payload != 0) { int size = min(OneToN(6), remaining_payload); int index = payload_size - remaining_payload; - list_.push_back(make_pair(index, string(kPayload + index, size))); + list_.push_back(std::make_pair(index, string(kPayload + index, size))); remaining_payload -= size; } } @@ -402,7 +402,7 @@ TEST_F(QuicStreamSequencerTest, FrameOverlapsBufferedData) { // Add a buffered frame. buffered_frames->insert( - make_pair(kBufferedOffset, string(kBufferedDataLength, '.'))); + std::make_pair(kBufferedOffset, string(kBufferedDataLength, '.'))); // New byte range partially overlaps with buffered frame, start offset // preceeding buffered frame. diff --git a/net/quic/quic_time_wait_list_manager.cc b/net/quic/quic_time_wait_list_manager.cc index 52ee2da..2e3e16d 100644 --- a/net/quic/quic_time_wait_list_manager.cc +++ b/net/quic/quic_time_wait_list_manager.cc @@ -22,7 +22,6 @@ #include "net/quic/quic_utils.h" using base::StringPiece; -using std::make_pair; namespace net { @@ -122,7 +121,7 @@ void QuicTimeWaitListManager::AddConnectionIdToTimeWait( version, helper_->GetClock()->ApproximateNow(), close_packet); - connection_id_map_.insert(make_pair(connection_id, data)); + connection_id_map_.insert(std::make_pair(connection_id, data)); if (new_connection_id) { visitor_->OnConnectionAddedToTimeWaitList(connection_id); } diff --git a/net/quic/test_tools/crypto_test_utils.cc b/net/quic/test_tools/crypto_test_utils.cc index d8ee1f8..d6238bd 100644 --- a/net/quic/test_tools/crypto_test_utils.cc +++ b/net/quic/test_tools/crypto_test_utils.cc @@ -332,7 +332,7 @@ pair<size_t, size_t> CryptoTestUtils::AdvanceHandshake( } MovePackets(b_conn, &b_i, a, a_conn); - return make_pair(a_i, b_i); + return std::make_pair(a_i, b_i); } // static diff --git a/net/quic/test_tools/quic_test_utils.cc b/net/quic/test_tools/quic_test_utils.cc index fc45106..b504b75 100644 --- a/net/quic/test_tools/quic_test_utils.cc +++ b/net/quic/test_tools/quic_test_utils.cc @@ -13,6 +13,7 @@ #include "net/quic/crypto/null_encrypter.h" #include "net/quic/crypto/quic_decrypter.h" #include "net/quic/crypto/quic_encrypter.h" +#include "net/quic/quic_data_writer.h" #include "net/quic/quic_framer.h" #include "net/quic/quic_packet_creator.h" #include "net/quic/quic_utils.h" @@ -76,7 +77,22 @@ QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, DCHECK(frame_size); packet_size += frame_size; } - return framer->BuildDataPacket(header, frames, packet_size); + return BuildUnsizedDataPacket(framer, header, frames, packet_size); +} + +QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, + const QuicPacketHeader& header, + const QuicFrames& frames, + size_t packet_size) { + char* buffer = new char[packet_size]; + scoped_ptr<QuicPacket> packet( + framer->BuildDataPacket(header, frames, buffer, packet_size)); + DCHECK(packet.get() != nullptr); + // Now I have to re-construct the data packet with data ownership. + return new QuicPacket(buffer, packet->length(), true, + header.public_header.connection_id_length, + header.public_header.version_flag, + header.public_header.sequence_number_length); } uint64 SimpleRandom::RandUint64() { diff --git a/net/quic/test_tools/quic_test_utils.h b/net/quic/test_tools/quic_test_utils.h index 107617b..5282d62 100644 --- a/net/quic/test_tools/quic_test_utils.h +++ b/net/quic/test_tools/quic_test_utils.h @@ -103,12 +103,17 @@ QuicAckFrame MakeAckFrame(QuicPacketSequenceNumber largest_observed); QuicAckFrame MakeAckFrameWithNackRanges(size_t num_nack_ranges, QuicPacketSequenceNumber least_unacked); -// Returns a QuicPacket whose that is owned by the caller, and +// Returns a QuicPacket that is owned by the caller, and // is populated with the fields in |header| and |frames|, or is nullptr if the // packet could not be created. QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, const QuicPacketHeader& header, const QuicFrames& frames); +// Returns a QuicPacket that is owned by the caller, and of size |packet_size|. +QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, + const QuicPacketHeader& header, + const QuicFrames& frames, + size_t packet_size); template<typename SaveType> class ValueRestore { diff --git a/net/tools/quic/end_to_end_test.cc b/net/tools/quic/end_to_end_test.cc index fa9a8e7..9e7605f 100644 --- a/net/tools/quic/end_to_end_test.cc +++ b/net/tools/quic/end_to_end_test.cc @@ -319,6 +319,8 @@ class EndToEndTest : public ::testing::TestWithParam<TestParams> { // and TestWriterFactory when Initialize() is executed. client_writer_ = new PacketDroppingTestWriter(); server_writer_ = new PacketDroppingTestWriter(); + // TODO(ianswett): Remove this once it's fully rolled out. + FLAGS_quic_enable_pacing = false; } void TearDown() override { StopServer(); } @@ -1406,8 +1408,6 @@ TEST_P(EndToEndTest, AckNotifierWithPacketLossAndBlockedSocket) { // demonstrates that retransmissions do not break this functionality. ValueRestore<bool> old_flag(&FLAGS_quic_attach_ack_notifiers_to_packets, true); - ValueRestore<bool> old_flag2(&FLAGS_quic_ack_notifier_informed_on_serialized, - true); SetPacketLossPercentage(5); ASSERT_TRUE(Initialize()); diff --git a/net/tools/quic/quic_client_session.cc b/net/tools/quic/quic_client_session.cc index 815fdfd..92eec04 100644 --- a/net/tools/quic/quic_client_session.cc +++ b/net/tools/quic/quic_client_session.cc @@ -16,7 +16,7 @@ namespace tools { QuicClientSession::QuicClientSession(const QuicConfig& config, QuicConnection* connection) - : QuicClientSessionBase(connection, config) { + : QuicClientSessionBase(connection, config), respect_goaway_(true) { } QuicClientSession::~QuicClientSession() { @@ -46,7 +46,7 @@ QuicSpdyClientStream* QuicClientSession::CreateOutgoingDataStream() { << "Already " << GetNumOpenStreams() << " open."; return nullptr; } - if (goaway_received()) { + if (goaway_received() && respect_goaway_) { DVLOG(1) << "Failed to create a new outgoing stream. " << "Already received goaway."; return nullptr; diff --git a/net/tools/quic/quic_client_session.h b/net/tools/quic/quic_client_session.h index 7532552..3438a23 100644 --- a/net/tools/quic/quic_client_session.h +++ b/net/tools/quic/quic_client_session.h @@ -48,6 +48,10 @@ class QuicClientSession : public QuicClientSessionBase { // than the number of round-trips needed for the handshake. int GetNumSentClientHellos() const; + void set_respect_goaway(bool respect_goaway) { + respect_goaway_ = respect_goaway; + } + protected: // QuicSession methods: QuicDataStream* CreateIncomingDataStream(QuicStreamId id) override; @@ -55,6 +59,10 @@ class QuicClientSession : public QuicClientSessionBase { private: scoped_ptr<QuicCryptoClientStream> crypto_stream_; + // If this is set to false, the client will ignore server GOAWAYs and allow + // the creation of streams regardless of the high chance they will fail. + bool respect_goaway_; + DISALLOW_COPY_AND_ASSIGN(QuicClientSession); }; diff --git a/net/tools/quic/quic_dispatcher.cc b/net/tools/quic/quic_dispatcher.cc index 46f672ea..8f19cf4 100644 --- a/net/tools/quic/quic_dispatcher.cc +++ b/net/tools/quic/quic_dispatcher.cc @@ -24,7 +24,6 @@ namespace net { namespace tools { using base::StringPiece; -using std::make_pair; class DeleteSessionsAlarm : public EpollAlarm { public: @@ -254,7 +253,7 @@ bool QuicDispatcher::OnUnauthenticatedPublicHeader( return HandlePacketForTimeWait(header); } DVLOG(1) << "Created new session for " << connection_id; - session_map_.insert(make_pair(connection_id, session)); + session_map_.insert(std::make_pair(connection_id, session)); } else { session = it->second; } @@ -352,7 +351,7 @@ void QuicDispatcher::OnWriteBlocked( // infinite loops in OnCanWrite. return; } - write_blocked_list_.insert(make_pair(blocked_writer, true)); + write_blocked_list_.insert(std::make_pair(blocked_writer, true)); } void QuicDispatcher::OnConnectionAddedToTimeWaitList( diff --git a/net/tools/quic/quic_time_wait_list_manager.cc b/net/tools/quic/quic_time_wait_list_manager.cc index 1cb86a5..c9e589c 100644 --- a/net/tools/quic/quic_time_wait_list_manager.cc +++ b/net/tools/quic/quic_time_wait_list_manager.cc @@ -22,7 +22,6 @@ #include "net/tools/quic/quic_server_session.h" using base::StringPiece; -using std::make_pair; namespace net { namespace tools { @@ -127,7 +126,7 @@ void QuicTimeWaitListManager::AddConnectionIdToTimeWait( version, clock_.ApproximateNow(), close_packet); - connection_id_map_.insert(make_pair(connection_id, data)); + connection_id_map_.insert(std::make_pair(connection_id, data)); if (new_connection_id) { visitor_->OnConnectionAddedToTimeWaitList(connection_id); } |