Rename QuicChaosProtector cl/696443185 introduced QuicChaosProtectorNew and only uses it when --gfe2_reloadable_flag_quic_enable_new_chaos_protector is true, and did not change QuicChaosProtector. This change renames QuicChaosProtector to QuicChaosProtectorOld and QuicChaosProtectorNew to QuicChaosProtector. This will simplify deprecating the flag later, and working on it in the meantime PiperOrigin-RevId: 696453573
diff --git a/quiche/quic/core/quic_chaos_protector.cc b/quiche/quic/core/quic_chaos_protector.cc index f69c4ef..7b55586 100644 --- a/quiche/quic/core/quic_chaos_protector.cc +++ b/quiche/quic/core/quic_chaos_protector.cc
@@ -29,10 +29,9 @@ namespace quic { -QuicChaosProtector::QuicChaosProtector(const QuicCryptoFrame& crypto_frame, - int num_padding_bytes, - size_t packet_size, QuicFramer* framer, - QuicRandom* random) +QuicChaosProtectorOld::QuicChaosProtectorOld( + const QuicCryptoFrame& crypto_frame, int num_padding_bytes, + size_t packet_size, QuicFramer* framer, QuicRandom* random) : packet_size_(packet_size), crypto_data_length_(crypto_frame.data_length), crypto_buffer_offset_(crypto_frame.offset), @@ -45,9 +44,9 @@ QUICHE_DCHECK_NE(random_, nullptr); } -QuicChaosProtector::~QuicChaosProtector() { DeleteFrames(&frames_); } +QuicChaosProtectorOld::~QuicChaosProtectorOld() { DeleteFrames(&frames_); } -std::optional<size_t> QuicChaosProtector::BuildDataPacket( +std::optional<size_t> QuicChaosProtectorOld::BuildDataPacket( const QuicPacketHeader& header, char* buffer) { if (!CopyCryptoDataToLocalBuffer()) { return std::nullopt; @@ -59,7 +58,7 @@ return BuildPacket(header, buffer); } -WriteStreamDataResult QuicChaosProtector::WriteStreamData( +WriteStreamDataResult QuicChaosProtectorOld::WriteStreamData( QuicStreamId id, QuicStreamOffset offset, QuicByteCount data_length, QuicDataWriter* /*writer*/) { QUIC_BUG(chaos stream) << "This should never be called; id " << id @@ -68,10 +67,10 @@ return STREAM_MISSING; } -bool QuicChaosProtector::WriteCryptoData(EncryptionLevel level, - QuicStreamOffset offset, - QuicByteCount data_length, - QuicDataWriter* writer) { +bool QuicChaosProtectorOld::WriteCryptoData(EncryptionLevel level, + QuicStreamOffset offset, + QuicByteCount data_length, + QuicDataWriter* writer) { if (level != level_) { QUIC_BUG(chaos bad level) << "Unexpected " << level << " != " << level_; return false; @@ -91,7 +90,7 @@ return true; } -bool QuicChaosProtector::CopyCryptoDataToLocalBuffer() { +bool QuicChaosProtectorOld::CopyCryptoDataToLocalBuffer() { crypto_frame_buffer_ = std::make_unique<char[]>(packet_size_); frames_.push_back(QuicFrame( new QuicCryptoFrame(level_, crypto_buffer_offset_, crypto_data_length_))); @@ -122,7 +121,7 @@ return true; } -void QuicChaosProtector::SplitCryptoFrame() { +void QuicChaosProtectorOld::SplitCryptoFrame() { const int max_overhead_of_adding_a_crypto_frame = static_cast<int>(QuicFramer::GetMinCryptoFrameSize( crypto_buffer_offset_ + crypto_data_length_, crypto_data_length_)); @@ -170,7 +169,7 @@ } } -void QuicChaosProtector::AddPingFrames() { +void QuicChaosProtectorOld::AddPingFrames() { if (remaining_padding_bytes_ == 0) { return; } @@ -184,14 +183,14 @@ remaining_padding_bytes_ -= static_cast<int>(num_ping_frames); } -void QuicChaosProtector::ReorderFrames() { +void QuicChaosProtectorOld::ReorderFrames() { // Walk the array backwards and swap each frame with a random earlier one. for (size_t i = frames_.size() - 1; i > 0; i--) { std::swap(frames_[i], frames_[random_->InsecureRandUint64() % (i + 1)]); } } -void QuicChaosProtector::SpreadPadding() { +void QuicChaosProtectorOld::SpreadPadding() { for (auto it = frames_.begin(); it != frames_.end(); ++it) { const int padding_bytes_in_this_frame = random_->InsecureRandUint64() % (remaining_padding_bytes_ + 1); @@ -208,7 +207,7 @@ } } -std::optional<size_t> QuicChaosProtector::BuildPacket( +std::optional<size_t> QuicChaosProtectorOld::BuildPacket( const QuicPacketHeader& header, char* buffer) { QuicStreamFrameDataProducer* original_data_producer = framer_->data_producer(); @@ -226,10 +225,9 @@ // End of old code, start of new code. -QuicChaosProtectorNew::QuicChaosProtectorNew(size_t packet_size, - EncryptionLevel level, - QuicFramer* framer, - QuicRandom* random) +QuicChaosProtector::QuicChaosProtector(size_t packet_size, + EncryptionLevel level, + QuicFramer* framer, QuicRandom* random) : packet_size_(packet_size), level_(level), framer_(framer), @@ -239,7 +237,7 @@ QUICHE_DCHECK_NE(random_, nullptr); } -bool QuicChaosProtectorNew::IngestFrames(const QuicFrames& frames) { +bool QuicChaosProtector::IngestFrames(const QuicFrames& frames) { bool has_crypto_frame = false; bool has_padding_frame = false; QuicByteCount max_crypto_data; @@ -295,9 +293,9 @@ return has_crypto_frame && has_padding_frame; } -QuicChaosProtectorNew::~QuicChaosProtectorNew() { DeleteFrames(&frames_); } +QuicChaosProtector::~QuicChaosProtector() { DeleteFrames(&frames_); } -std::optional<size_t> QuicChaosProtectorNew::BuildDataPacket( +std::optional<size_t> QuicChaosProtector::BuildDataPacket( const QuicPacketHeader& header, const QuicFrames& frames, char* buffer) { if (!IngestFrames(frames)) { QUIC_DVLOG(1) << "Failed to ingest frames"; @@ -314,7 +312,7 @@ return BuildPacket(header, buffer); } -WriteStreamDataResult QuicChaosProtectorNew::WriteStreamData( +WriteStreamDataResult QuicChaosProtector::WriteStreamData( QuicStreamId id, QuicStreamOffset offset, QuicByteCount data_length, QuicDataWriter* /*writer*/) { QUIC_BUG(chaos stream) << "This should never be called; id " << id @@ -323,10 +321,10 @@ return STREAM_MISSING; } -bool QuicChaosProtectorNew::WriteCryptoData(EncryptionLevel level, - QuicStreamOffset offset, - QuicByteCount data_length, - QuicDataWriter* writer) { +bool QuicChaosProtector::WriteCryptoData(EncryptionLevel level, + QuicStreamOffset offset, + QuicByteCount data_length, + QuicDataWriter* writer) { if (level != level_) { QUIC_BUG(chaos bad level) << "Unexpected " << level << " != " << level_; return false; @@ -346,7 +344,7 @@ return true; } -bool QuicChaosProtectorNew::CopyCryptoDataToLocalBuffer() { +bool QuicChaosProtector::CopyCryptoDataToLocalBuffer() { size_t frame_size = QuicDataWriter::GetVarInt62Len(crypto_buffer_offset_) + QuicDataWriter::GetVarInt62Len(crypto_data_length_) + crypto_data_length_; @@ -380,7 +378,7 @@ return true; } -void QuicChaosProtectorNew::SplitCryptoFrame() { +void QuicChaosProtector::SplitCryptoFrame() { const int max_overhead_of_adding_a_crypto_frame = static_cast<int>(QuicFramer::GetMinCryptoFrameSize( crypto_buffer_offset_ + crypto_data_length_, crypto_data_length_)); @@ -432,7 +430,7 @@ } } -void QuicChaosProtectorNew::AddPingFrames() { +void QuicChaosProtector::AddPingFrames() { if (remaining_padding_bytes_ == 0) { return; } @@ -446,7 +444,7 @@ remaining_padding_bytes_ -= static_cast<int>(num_ping_frames); } -void QuicChaosProtectorNew::ReorderFrames() { +void QuicChaosProtector::ReorderFrames() { // Walk the array backwards and swap each frame with a random earlier one. for (size_t i = frames_.size() - 1; i > 0; i--) { quic::QuicFrame& lhs = frames_[i]; @@ -458,7 +456,7 @@ } } -void QuicChaosProtectorNew::SpreadPadding() { +void QuicChaosProtector::SpreadPadding() { for (auto it = frames_.begin(); it != frames_.end(); ++it) { const int padding_bytes_in_this_frame = random_->InsecureRandUint64() % (remaining_padding_bytes_ + 1); @@ -479,7 +477,7 @@ } } -std::optional<size_t> QuicChaosProtectorNew::BuildPacket( +std::optional<size_t> QuicChaosProtector::BuildPacket( const QuicPacketHeader& header, char* buffer) { QuicStreamFrameDataProducer* original_data_producer = framer_->data_producer();
diff --git a/quiche/quic/core/quic_chaos_protector.h b/quiche/quic/core/quic_chaos_protector.h index 2456b42..5dbb3ad 100644 --- a/quiche/quic/core/quic_chaos_protector.h +++ b/quiche/quic/core/quic_chaos_protector.h
@@ -21,24 +21,25 @@ namespace quic { namespace test { -class QuicChaosProtectorTest; +class QuicChaosProtectorOldTest; } -// QuicChaosProtector will take a crypto frame and an amount of padding and +// QuicChaosProtectorOld will take a crypto frame and an amount of padding and // build a data packet that will parse to something equivalent. -class QUICHE_EXPORT QuicChaosProtector : public QuicStreamFrameDataProducer { +class QUICHE_EXPORT QuicChaosProtectorOld : public QuicStreamFrameDataProducer { public: - // |framer| and |random| must be valid for the lifetime of QuicChaosProtector. - explicit QuicChaosProtector(const QuicCryptoFrame& crypto_frame, - int num_padding_bytes, size_t packet_size, - QuicFramer* framer, QuicRandom* random); + // |framer| and |random| must be valid for the lifetime of + // QuicChaosProtectorOld. + explicit QuicChaosProtectorOld(const QuicCryptoFrame& crypto_frame, + int num_padding_bytes, size_t packet_size, + QuicFramer* framer, QuicRandom* random); - ~QuicChaosProtector() override; + ~QuicChaosProtectorOld() override; - QuicChaosProtector(const QuicChaosProtector&) = delete; - QuicChaosProtector(QuicChaosProtector&&) = delete; - QuicChaosProtector& operator=(const QuicChaosProtector&) = delete; - QuicChaosProtector& operator=(QuicChaosProtector&&) = delete; + QuicChaosProtectorOld(const QuicChaosProtectorOld&) = delete; + QuicChaosProtectorOld(QuicChaosProtectorOld&&) = delete; + QuicChaosProtectorOld& operator=(const QuicChaosProtectorOld&) = delete; + QuicChaosProtectorOld& operator=(QuicChaosProtectorOld&&) = delete; // Attempts to build a data packet with chaos protection. If an error occurs, // then std::nullopt is returned. Otherwise returns the serialized length. @@ -55,7 +56,7 @@ QuicDataWriter* writer) override; private: - friend class test::QuicChaosProtectorTest; + friend class test::QuicChaosProtectorOldTest; // Allocate the crypto data buffer, create the CRYPTO frame and write the // crypto data to our buffer. @@ -93,24 +94,24 @@ // End of old code, start of new code. namespace test { -class QuicChaosProtectorNewTest; +class QuicChaosProtectorTest; } -// QuicChaosProtectorNew will take a crypto frame and an amount of padding and +// QuicChaosProtector will take a crypto frame and an amount of padding and // build a data packet that will parse to something equivalent. -class QUICHE_EXPORT QuicChaosProtectorNew : public QuicStreamFrameDataProducer { +class QUICHE_EXPORT QuicChaosProtector : public QuicStreamFrameDataProducer { public: // |framer| and |random| must be valid for the lifetime of - // QuicChaosProtectorNew. - explicit QuicChaosProtectorNew(size_t packet_size, EncryptionLevel level, - QuicFramer* framer, QuicRandom* random); + // QuicChaosProtector. + explicit QuicChaosProtector(size_t packet_size, EncryptionLevel level, + QuicFramer* framer, QuicRandom* random); - ~QuicChaosProtectorNew() override; + ~QuicChaosProtector() override; - QuicChaosProtectorNew(const QuicChaosProtectorNew&) = delete; - QuicChaosProtectorNew(QuicChaosProtectorNew&&) = delete; - QuicChaosProtectorNew& operator=(const QuicChaosProtectorNew&) = delete; - QuicChaosProtectorNew& operator=(QuicChaosProtectorNew&&) = delete; + QuicChaosProtector(const QuicChaosProtector&) = delete; + QuicChaosProtector(QuicChaosProtector&&) = delete; + QuicChaosProtector& operator=(const QuicChaosProtector&) = delete; + QuicChaosProtector& operator=(QuicChaosProtector&&) = delete; // Attempts to build a data packet with chaos protection. If an error occurs, // then std::nullopt is returned. Otherwise returns the serialized length. @@ -127,7 +128,7 @@ QuicDataWriter* writer) override; private: - friend class test::QuicChaosProtectorNewTest; + friend class test::QuicChaosProtectorTest; // Ingest the frames to be chaos protected. bool IngestFrames(const QuicFrames& frames);
diff --git a/quiche/quic/core/quic_chaos_protector_test.cc b/quiche/quic/core/quic_chaos_protector_test.cc index fe82c47..fb87aa1 100644 --- a/quiche/quic/core/quic_chaos_protector_test.cc +++ b/quiche/quic/core/quic_chaos_protector_test.cc
@@ -27,10 +27,10 @@ namespace quic { namespace test { -class QuicChaosProtectorTest : public QuicTestWithParam<ParsedQuicVersion>, - public QuicStreamFrameDataProducer { +class QuicChaosProtectorOldTest : public QuicTestWithParam<ParsedQuicVersion>, + public QuicStreamFrameDataProducer { public: - QuicChaosProtectorTest() + QuicChaosProtectorOldTest() : version_(GetParam()), framer_({version_}, QuicTime::Zero(), Perspective::IS_CLIENT, kQuicDefaultConnectionIdLength), @@ -47,7 +47,7 @@ } void ReCreateChaosProtector() { - chaos_protector_ = std::make_unique<QuicChaosProtector>( + chaos_protector_ = std::make_unique<QuicChaosProtectorOld>( crypto_frame_, num_padding_bytes_, packet_size_, SetupHeaderAndFramers(), &random_); } @@ -139,12 +139,12 @@ int num_padding_bytes_; size_t packet_size_; std::unique_ptr<char[]> packet_buffer_; - std::unique_ptr<QuicChaosProtector> chaos_protector_; + std::unique_ptr<QuicChaosProtectorOld> chaos_protector_; }; namespace { -ParsedQuicVersionVector TestVersions() { +ParsedQuicVersionVector TestVersionsOld() { ParsedQuicVersionVector versions; for (const ParsedQuicVersion& version : AllSupportedVersions()) { if (version.UsesCryptoFrames()) { @@ -154,11 +154,11 @@ return versions; } -INSTANTIATE_TEST_SUITE_P(QuicChaosProtectorTests, QuicChaosProtectorTest, - ::testing::ValuesIn(TestVersions()), +INSTANTIATE_TEST_SUITE_P(QuicChaosProtectorOldTests, QuicChaosProtectorOldTest, + ::testing::ValuesIn(TestVersionsOld()), ::testing::PrintToStringParamName()); -TEST_P(QuicChaosProtectorTest, Main) { +TEST_P(QuicChaosProtectorOldTest, Main) { BuildEncryptAndParse(); ASSERT_EQ(validation_framer_.crypto_frames().size(), 4u); EXPECT_EQ(validation_framer_.crypto_frames()[0]->offset, 0u); @@ -168,7 +168,7 @@ EXPECT_EQ(validation_framer_.padding_frames()[0].num_padding_bytes, 3); } -TEST_P(QuicChaosProtectorTest, DifferentRandom) { +TEST_P(QuicChaosProtectorOldTest, DifferentRandom) { random_.ResetBase(4); BuildEncryptAndParse(); ASSERT_EQ(validation_framer_.crypto_frames().size(), 4u); @@ -176,7 +176,7 @@ ASSERT_EQ(validation_framer_.padding_frames().size(), 8u); } -TEST_P(QuicChaosProtectorTest, RandomnessZero) { +TEST_P(QuicChaosProtectorOldTest, RandomnessZero) { random_.ResetBase(0); BuildEncryptAndParse(); ASSERT_EQ(validation_framer_.crypto_frames().size(), 1u); @@ -187,7 +187,7 @@ ASSERT_EQ(validation_framer_.padding_frames().size(), 1u); } -TEST_P(QuicChaosProtectorTest, Offset) { +TEST_P(QuicChaosProtectorOldTest, Offset) { ResetOffset(123); BuildEncryptAndParse(); ASSERT_EQ(validation_framer_.crypto_frames().size(), 4u); @@ -198,7 +198,7 @@ EXPECT_EQ(validation_framer_.padding_frames()[0].num_padding_bytes, 3); } -TEST_P(QuicChaosProtectorTest, OffsetAndRandomnessZero) { +TEST_P(QuicChaosProtectorOldTest, OffsetAndRandomnessZero) { ResetOffset(123); random_.ResetBase(0); BuildEncryptAndParse(); @@ -210,7 +210,7 @@ ASSERT_EQ(validation_framer_.padding_frames().size(), 1u); } -TEST_P(QuicChaosProtectorTest, ZeroRemainingBytesAfterSplit) { +TEST_P(QuicChaosProtectorOldTest, ZeroRemainingBytesAfterSplit) { QuicPacketLength new_length = 63; num_padding_bytes_ = QuicFramer::GetMinCryptoFrameSize( crypto_frame_.offset + new_length, new_length); @@ -238,10 +238,10 @@ kAckCryptoAndPadding, }; -class QuicChaosProtectorNewTest : public QuicTestWithParam<ParsedQuicVersion>, - public QuicStreamFrameDataProducer { +class QuicChaosProtectorTest : public QuicTestWithParam<ParsedQuicVersion>, + public QuicStreamFrameDataProducer { public: - QuicChaosProtectorNewTest() + QuicChaosProtectorTest() : version_(GetParam()), framer_({version_}, QuicTime::Zero(), Perspective::IS_CLIENT, kQuicDefaultConnectionIdLength), @@ -281,7 +281,7 @@ } void ReCreateChaosProtector() { - chaos_protector_ = std::make_unique<QuicChaosProtectorNew>( + chaos_protector_ = std::make_unique<QuicChaosProtector>( packet_size_, level_, SetupHeaderAndFramers(), &random_); } @@ -413,12 +413,12 @@ int num_padding_bytes_; size_t packet_size_; std::unique_ptr<char[]> packet_buffer_; - std::unique_ptr<QuicChaosProtectorNew> chaos_protector_; + std::unique_ptr<QuicChaosProtector> chaos_protector_; }; namespace { -ParsedQuicVersionVector TestVersionsNew() { +ParsedQuicVersionVector TestVersions() { ParsedQuicVersionVector versions; for (const ParsedQuicVersion& version : AllSupportedVersions()) { if (version.UsesCryptoFrames()) { @@ -428,11 +428,11 @@ return versions; } -INSTANTIATE_TEST_SUITE_P(QuicChaosProtectorNewTests, QuicChaosProtectorNewTest, - ::testing::ValuesIn(TestVersionsNew()), +INSTANTIATE_TEST_SUITE_P(QuicChaosProtectorTests, QuicChaosProtectorTest, + ::testing::ValuesIn(TestVersions()), ::testing::PrintToStringParamName()); -TEST_P(QuicChaosProtectorNewTest, Main) { +TEST_P(QuicChaosProtectorTest, Main) { BuildEncryptAndParse(); ASSERT_EQ(validation_framer_.crypto_frames().size(), 4u); EXPECT_EQ(validation_framer_.crypto_frames()[0]->offset, 0u); @@ -442,7 +442,7 @@ EXPECT_EQ(validation_framer_.padding_frames()[0].num_padding_bytes, 3); } -TEST_P(QuicChaosProtectorNewTest, DifferentRandom) { +TEST_P(QuicChaosProtectorTest, DifferentRandom) { random_.ResetBase(4); BuildEncryptAndParse(); ASSERT_EQ(validation_framer_.crypto_frames().size(), 4u); @@ -450,7 +450,7 @@ ASSERT_EQ(validation_framer_.padding_frames().size(), 8u); } -TEST_P(QuicChaosProtectorNewTest, RandomnessZero) { +TEST_P(QuicChaosProtectorTest, RandomnessZero) { random_.ResetBase(0); BuildEncryptAndParse(); ASSERT_EQ(validation_framer_.crypto_frames().size(), 1u); @@ -461,7 +461,7 @@ ASSERT_EQ(validation_framer_.padding_frames().size(), 1u); } -TEST_P(QuicChaosProtectorNewTest, Offset) { +TEST_P(QuicChaosProtectorTest, Offset) { ResetOffset(123); BuildEncryptAndParse(); ASSERT_EQ(validation_framer_.crypto_frames().size(), 4u); @@ -472,7 +472,7 @@ EXPECT_EQ(validation_framer_.padding_frames()[0].num_padding_bytes, 3); } -TEST_P(QuicChaosProtectorNewTest, OffsetAndRandomnessZero) { +TEST_P(QuicChaosProtectorTest, OffsetAndRandomnessZero) { ResetOffset(123); random_.ResetBase(0); BuildEncryptAndParse(); @@ -484,7 +484,7 @@ ASSERT_EQ(validation_framer_.padding_frames().size(), 1u); } -TEST_P(QuicChaosProtectorNewTest, ZeroRemainingBytesAfterSplit) { +TEST_P(QuicChaosProtectorTest, ZeroRemainingBytesAfterSplit) { QuicPacketLength new_length = 63; num_padding_bytes_ = QuicFramer::GetMinCryptoFrameSize( crypto_offset_ + new_length, new_length); @@ -500,7 +500,7 @@ EXPECT_EQ(validation_framer_.ping_frames().size(), 0u); } -TEST_P(QuicChaosProtectorNewTest, CryptoCryptoAndPadding) { +TEST_P(QuicChaosProtectorTest, CryptoCryptoAndPadding) { input_frames_pattern_ = InputFramesPattern::kCryptoCryptoAndPadding; random_.ResetBase(38); BuildEncryptAndParse(); @@ -509,7 +509,7 @@ EXPECT_EQ(validation_framer_.padding_frames().size(), 3u); } -TEST_P(QuicChaosProtectorNewTest, ReorderedCryptoCryptoAndPadding) { +TEST_P(QuicChaosProtectorTest, ReorderedCryptoCryptoAndPadding) { input_frames_pattern_ = InputFramesPattern::kReorderedCryptoCryptoAndPadding; random_.ResetBase(38); BuildEncryptAndParse(); @@ -518,7 +518,7 @@ EXPECT_EQ(validation_framer_.padding_frames().size(), 3u); } -TEST_P(QuicChaosProtectorNewTest, AckCryptoAndPadding) { +TEST_P(QuicChaosProtectorTest, AckCryptoAndPadding) { input_frames_pattern_ = InputFramesPattern::kAckCryptoAndPadding; random_.ResetBase(37); BuildEncryptAndParse();
diff --git a/quiche/quic/core/quic_packet_creator.cc b/quiche/quic/core/quic_packet_creator.cc index 6f7187e..426d709 100644 --- a/quiche/quic/core/quic_packet_creator.cc +++ b/quiche/quic/core/quic_packet_creator.cc
@@ -790,14 +790,14 @@ << " != " << crypto_frame.level; return std::nullopt; } - QuicChaosProtector chaos_protector( + QuicChaosProtectorOld chaos_protector( crypto_frame, queued_frames_[1].padding_frame.num_padding_bytes, packet_size_, framer_, random_); return chaos_protector.BuildDataPacket(header, buffer); } QUIC_RELOADABLE_FLAG_COUNT(quic_enable_new_chaos_protector); - QuicChaosProtectorNew chaos_protector(packet_size_, packet_.encryption_level, - framer_, random_); + QuicChaosProtector chaos_protector(packet_size_, packet_.encryption_level, + framer_, random_); return chaos_protector.BuildDataPacket(header, queued_frames_, buffer); }