Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: net/quic/core/quic_connection_test.cc

Issue 2334363002: Landing Recent QUIC changes until Sat Sep 10 00:32:41 (Closed)
Patch Set: Revase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_connection.cc ('k') | net/quic/core/quic_crypto_server_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/core/quic_connection.h" 5 #include "net/quic/core/quic_connection.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <memory> 8 #include <memory>
9 #include <ostream> 9 #include <ostream>
10 #include <utility> 10 #include <utility>
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // QuicDecrypter interface 144 // QuicDecrypter interface
145 bool SetKey(StringPiece key) override { return true; } 145 bool SetKey(StringPiece key) override { return true; }
146 146
147 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } 147 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; }
148 148
149 bool SetPreliminaryKey(StringPiece key) override { 149 bool SetPreliminaryKey(StringPiece key) override {
150 QUIC_BUG << "should not be called"; 150 QUIC_BUG << "should not be called";
151 return false; 151 return false;
152 } 152 }
153 153
154 bool SetDiversificationNonce(DiversificationNonce key) override { 154 bool SetDiversificationNonce(const DiversificationNonce& key) override {
155 return true; 155 return true;
156 } 156 }
157 157
158 bool DecryptPacket(QuicPathId path_id, 158 bool DecryptPacket(QuicPathId path_id,
159 QuicPacketNumber packet_number, 159 QuicPacketNumber packet_number,
160 StringPiece associated_data, 160 StringPiece associated_data,
161 StringPiece ciphertext, 161 StringPiece ciphertext,
162 char* output, 162 char* output,
163 size_t* output_length, 163 size_t* output_length,
164 size_t max_output_length) override { 164 size_t max_output_length) override {
(...skipping 2472 matching lines...) Expand 10 before | Expand all | Expand 10 after
2637 2637
2638 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2638 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2639 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2639 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2640 2640
2641 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr); 2641 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr);
2642 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2642 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2643 2643
2644 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); 2644 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION);
2645 } 2645 }
2646 2646
2647 TEST_P(QuicConnectionTest, DelayForwardSecureEncryptionUntilClientIsReady) {
2648 FLAGS_quic_remove_obsolete_forward_secure = false;
2649 // A TaggingEncrypter puts kTagSize copies of the given byte (0x02 here) at
2650 // the end of the packet. We can test this to check which encrypter was used.
2651 use_tagging_decrypter();
2652 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2653 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2654 SendAckPacketToPeer();
2655 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2656
2657 // Set a forward-secure encrypter but do not make it the default, and verify
2658 // that it is not yet used.
2659 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2660 new TaggingEncrypter(0x03));
2661 SendAckPacketToPeer();
2662 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2663
2664 // Now simulate receipt of a forward-secure packet and verify that the
2665 // forward-secure encrypter is now used.
2666 connection_.OnDecryptedPacket(ENCRYPTION_FORWARD_SECURE);
2667 SendAckPacketToPeer();
2668 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet());
2669 }
2670
2671 TEST_P(QuicConnectionTest, DelayForwardSecureEncryptionUntilManyPacketSent) {
2672 FLAGS_quic_remove_obsolete_forward_secure = false;
2673 // Set a congestion window of 10 packets.
2674 QuicPacketCount congestion_window = 10;
2675 EXPECT_CALL(*send_algorithm_, GetCongestionWindow())
2676 .WillRepeatedly(Return(congestion_window * kDefaultMaxPacketSize));
2677
2678 // A TaggingEncrypter puts kTagSize copies of the given byte (0x02 here) at
2679 // the end of the packet. We can test this to check which encrypter was used.
2680 use_tagging_decrypter();
2681 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2682 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2683 SendAckPacketToPeer();
2684 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2685
2686 // Set a forward-secure encrypter but do not make it the default, and
2687 // verify that it is not yet used.
2688 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2689 new TaggingEncrypter(0x03));
2690 SendAckPacketToPeer();
2691 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2692
2693 // Now send a packet "Far enough" after the encrypter was set and verify that
2694 // the forward-secure encrypter is now used.
2695 for (uint64_t i = 0; i < 3 * congestion_window - 1; ++i) {
2696 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2697 SendAckPacketToPeer();
2698 }
2699 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet());
2700 }
2701
2702 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { 2647 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) {
2703 // SetFromConfig is always called after construction from InitializeSession. 2648 // SetFromConfig is always called after construction from InitializeSession.
2704 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2649 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2705 QuicConfig config; 2650 QuicConfig config;
2706 connection_.SetFromConfig(config); 2651 connection_.SetFromConfig(config);
2707 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2652 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2708 use_tagging_decrypter(); 2653 use_tagging_decrypter();
2709 2654
2710 const uint8_t tag = 0x07; 2655 const uint8_t tag = 0x07;
2711 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2656 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
(...skipping 2510 matching lines...) Expand 10 before | Expand all | Expand 10 after
5222 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 5167 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
5223 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _, 5168 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _,
5224 ConnectionCloseSource::FROM_SELF)) 5169 ConnectionCloseSource::FROM_SELF))
5225 .Times(1); 5170 .Times(1);
5226 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 5171 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
5227 } 5172 }
5228 5173
5229 // Verify that if connection has no outstanding data, it notifies the send 5174 // Verify that if connection has no outstanding data, it notifies the send
5230 // algorithm after the write. 5175 // algorithm after the write.
5231 TEST_P(QuicConnectionTest, SendDataAndBecomeApplicationLimited) { 5176 TEST_P(QuicConnectionTest, SendDataAndBecomeApplicationLimited) {
5232 FLAGS_quic_enable_app_limited_check = true;
5233
5234 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(1); 5177 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(1);
5235 { 5178 {
5236 InSequence seq; 5179 InSequence seq;
5237 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); 5180 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true));
5238 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 5181 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
5239 .WillOnce(Return(true)); 5182 .WillOnce(Return(true));
5240 EXPECT_CALL(visitor_, WillingAndAbleToWrite()) 5183 EXPECT_CALL(visitor_, WillingAndAbleToWrite())
5241 .WillRepeatedly(Return(false)); 5184 .WillRepeatedly(Return(false));
5242 } 5185 }
5243 5186
5244 connection_.SendStreamData3(); 5187 connection_.SendStreamData3();
5245 } 5188 }
5246 5189
5247 // Verify that the connection does not become app-limited if there is 5190 // Verify that the connection does not become app-limited if there is
5248 // outstanding data to send after the write. 5191 // outstanding data to send after the write.
5249 TEST_P(QuicConnectionTest, NotBecomeApplicationLimitedIfMoreDataAvailable) { 5192 TEST_P(QuicConnectionTest, NotBecomeApplicationLimitedIfMoreDataAvailable) {
5250 FLAGS_quic_enable_app_limited_check = true;
5251
5252 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(0); 5193 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(0);
5253 { 5194 {
5254 InSequence seq; 5195 InSequence seq;
5255 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 5196 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
5256 .WillOnce(Return(true)); 5197 .WillOnce(Return(true));
5257 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); 5198 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true));
5258 } 5199 }
5259 5200
5260 connection_.SendStreamData3(); 5201 connection_.SendStreamData3();
5261 } 5202 }
5262 5203
5263 // Verify that the connection does not become app-limited after blocked write 5204 // Verify that the connection does not become app-limited after blocked write
5264 // even if there is outstanding data to send after the write. 5205 // even if there is outstanding data to send after the write.
5265 TEST_P(QuicConnectionTest, NotBecomeApplicationLimitedDueToWriteBlock) { 5206 TEST_P(QuicConnectionTest, NotBecomeApplicationLimitedDueToWriteBlock) {
5266 FLAGS_quic_enable_app_limited_check = true;
5267
5268 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(0); 5207 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(0);
5269 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); 5208 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true));
5270 BlockOnNextWrite(); 5209 BlockOnNextWrite();
5271 5210
5272 connection_.SendStreamData3(); 5211 connection_.SendStreamData3();
5273 } 5212 }
5274 5213
5275 TEST_P(QuicConnectionTest, ForceSendingAckOnPacketTooLarge) { 5214 TEST_P(QuicConnectionTest, ForceSendingAckOnPacketTooLarge) {
5276 FLAGS_quic_do_not_send_ack_on_emsgsize = false; 5215 FLAGS_quic_do_not_send_ack_on_emsgsize = false;
5277 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 5216 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
(...skipping 26 matching lines...) Expand all
5304 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 5243 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
5305 EXPECT_EQ(1u, writer_->frame_count()); 5244 EXPECT_EQ(1u, writer_->frame_count());
5306 EXPECT_FALSE(writer_->connection_close_frames().empty()); 5245 EXPECT_FALSE(writer_->connection_close_frames().empty());
5307 // Ack frame is not bundled in connection close packet. 5246 // Ack frame is not bundled in connection close packet.
5308 EXPECT_TRUE(writer_->ack_frames().empty()); 5247 EXPECT_TRUE(writer_->ack_frames().empty());
5309 } 5248 }
5310 5249
5311 } // namespace 5250 } // namespace
5312 } // namespace test 5251 } // namespace test
5313 } // namespace net 5252 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_connection.cc ('k') | net/quic/core/quic_crypto_server_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698