OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 2398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2409 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); | 2409 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); |
2410 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2410 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
2411 | 2411 |
2412 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr); | 2412 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr); |
2413 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2413 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
2414 | 2414 |
2415 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); | 2415 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); |
2416 } | 2416 } |
2417 | 2417 |
2418 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { | 2418 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { |
| 2419 // SetFromConfig is always called after construction from InitializeSession. |
| 2420 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2421 QuicConfig config; |
| 2422 config.SetDefaults(); |
| 2423 connection_.SetFromConfig(config); |
2419 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2424 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2420 use_tagging_decrypter(); | 2425 use_tagging_decrypter(); |
2421 | 2426 |
2422 const uint8 tag = 0x07; | 2427 const uint8 tag = 0x07; |
2423 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2428 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
2424 | 2429 |
2425 // Process an encrypted packet which can not yet be decrypted | 2430 // Process an encrypted packet which can not yet be decrypted which should |
2426 // which should result in the packet being buffered. | 2431 // result in the packet being buffered. |
2427 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 2432 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL); |
2428 | 2433 |
2429 // Transition to the new encryption state and process another | 2434 // Transition to the new encryption state and process another encrypted packet |
2430 // encrypted packet which should result in the original packet being | 2435 // which should result in the original packet being processed. |
2431 // processed. | |
2432 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), | 2436 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), |
2433 ENCRYPTION_INITIAL); | 2437 ENCRYPTION_INITIAL); |
2434 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2438 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
2435 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2439 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
2436 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2); | 2440 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2); |
2437 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 2441 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL); |
2438 | 2442 |
2439 // Finally, process a third packet and note that we do not | 2443 // Finally, process a third packet and note that we do not reprocess the |
2440 // reprocess the buffered packet. | 2444 // buffered packet. |
2441 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); | 2445 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); |
2442 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 2446 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL); |
2443 } | 2447 } |
2444 | 2448 |
| 2449 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { |
| 2450 // SetFromConfig is always called after construction from InitializeSession. |
| 2451 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2452 QuicConfig config; |
| 2453 config.SetDefaults(); |
| 2454 config.set_max_undecryptable_packets(100); |
| 2455 connection_.SetFromConfig(config); |
| 2456 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2457 use_tagging_decrypter(); |
| 2458 |
| 2459 const uint8 tag = 0x07; |
| 2460 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 2461 |
| 2462 // Process an encrypted packet which can not yet be decrypted which should |
| 2463 // result in the packet being buffered. |
| 2464 for (QuicPacketSequenceNumber i = 1; i <= 100; ++i) { |
| 2465 ProcessDataPacketAtLevel(i, 0, kEntropyFlag, ENCRYPTION_INITIAL); |
| 2466 } |
| 2467 |
| 2468 // Transition to the new encryption state and process another encrypted packet |
| 2469 // which should result in the original packets being processed. |
| 2470 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), ENCRYPTION_INITIAL); |
| 2471 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 2472 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 2473 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(101); |
| 2474 ProcessDataPacketAtLevel(101, 0, kEntropyFlag, ENCRYPTION_INITIAL); |
| 2475 |
| 2476 // Finally, process a third packet and note that we do not reprocess the |
| 2477 // buffered packet. |
| 2478 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); |
| 2479 ProcessDataPacketAtLevel(102, 0, kEntropyFlag, ENCRYPTION_INITIAL); |
| 2480 } |
| 2481 |
2445 TEST_P(QuicConnectionTest, TestRetransmitOrder) { | 2482 TEST_P(QuicConnectionTest, TestRetransmitOrder) { |
2446 QuicByteCount first_packet_size; | 2483 QuicByteCount first_packet_size; |
2447 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( | 2484 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( |
2448 DoAll(SaveArg<3>(&first_packet_size), Return(true))); | 2485 DoAll(SaveArg<3>(&first_packet_size), Return(true))); |
2449 | 2486 |
2450 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); | 2487 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); |
2451 QuicByteCount second_packet_size; | 2488 QuicByteCount second_packet_size; |
2452 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( | 2489 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( |
2453 DoAll(SaveArg<3>(&second_packet_size), Return(true))); | 2490 DoAll(SaveArg<3>(&second_packet_size), Return(true))); |
2454 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr); | 2491 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr); |
(...skipping 1553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4008 QuicBlockedFrame blocked; | 4045 QuicBlockedFrame blocked; |
4009 blocked.stream_id = 3; | 4046 blocked.stream_id = 3; |
4010 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 4047 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
4011 ProcessFramePacket(QuicFrame(&blocked)); | 4048 ProcessFramePacket(QuicFrame(&blocked)); |
4012 EXPECT_TRUE(ack_alarm->IsSet()); | 4049 EXPECT_TRUE(ack_alarm->IsSet()); |
4013 } | 4050 } |
4014 | 4051 |
4015 } // namespace | 4052 } // namespace |
4016 } // namespace test | 4053 } // namespace test |
4017 } // namespace net | 4054 } // namespace net |
OLD | NEW |