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 2401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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. | 2419 // SetFromConfig is always called after construction from InitializeSession. |
2420 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 2420 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
2421 QuicConfig config; | 2421 QuicConfig config; |
2422 config.SetDefaults(); | |
2423 connection_.SetFromConfig(config); | 2422 connection_.SetFromConfig(config); |
2424 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2423 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2425 use_tagging_decrypter(); | 2424 use_tagging_decrypter(); |
2426 | 2425 |
2427 const uint8 tag = 0x07; | 2426 const uint8 tag = 0x07; |
2428 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2427 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
2429 | 2428 |
2430 // Process an encrypted packet which can not yet be decrypted which should | 2429 // Process an encrypted packet which can not yet be decrypted which should |
2431 // result in the packet being buffered. | 2430 // result in the packet being buffered. |
2432 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 2431 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL); |
(...skipping 10 matching lines...) Expand all Loading... |
2443 // Finally, process a third packet and note that we do not reprocess the | 2442 // Finally, process a third packet and note that we do not reprocess the |
2444 // buffered packet. | 2443 // buffered packet. |
2445 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); | 2444 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); |
2446 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 2445 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL); |
2447 } | 2446 } |
2448 | 2447 |
2449 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { | 2448 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { |
2450 // SetFromConfig is always called after construction from InitializeSession. | 2449 // SetFromConfig is always called after construction from InitializeSession. |
2451 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 2450 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
2452 QuicConfig config; | 2451 QuicConfig config; |
2453 config.SetDefaults(); | |
2454 config.set_max_undecryptable_packets(100); | 2452 config.set_max_undecryptable_packets(100); |
2455 connection_.SetFromConfig(config); | 2453 connection_.SetFromConfig(config); |
2456 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2454 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2457 use_tagging_decrypter(); | 2455 use_tagging_decrypter(); |
2458 | 2456 |
2459 const uint8 tag = 0x07; | 2457 const uint8 tag = 0x07; |
2460 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2458 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
2461 | 2459 |
2462 // Process an encrypted packet which can not yet be decrypted which should | 2460 // Process an encrypted packet which can not yet be decrypted which should |
2463 // result in the packet being buffered. | 2461 // result in the packet being buffered. |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2712 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); | 2710 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); |
2713 return; | 2711 return; |
2714 } | 2712 } |
2715 EXPECT_TRUE(connection_.connected()); | 2713 EXPECT_TRUE(connection_.connected()); |
2716 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); | 2714 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); |
2717 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 2715 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
2718 | 2716 |
2719 // SetFromConfig sets the initial timeouts before negotiation. | 2717 // SetFromConfig sets the initial timeouts before negotiation. |
2720 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 2718 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
2721 QuicConfig config; | 2719 QuicConfig config; |
2722 config.SetDefaults(); | |
2723 connection_.SetFromConfig(config); | 2720 connection_.SetFromConfig(config); |
2724 // Subtract a second from the idle timeout on the client side. | 2721 // Subtract a second from the idle timeout on the client side. |
2725 QuicTime default_timeout = clock_.ApproximateNow().Add( | 2722 QuicTime default_timeout = clock_.ApproximateNow().Add( |
2726 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); | 2723 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); |
2727 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); | 2724 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); |
2728 | 2725 |
2729 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); | 2726 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); |
2730 // Simulate the timeout alarm firing. | 2727 // Simulate the timeout alarm firing. |
2731 clock_.AdvanceTime( | 2728 clock_.AdvanceTime( |
2732 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); | 2729 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2865 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), | 2862 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), |
2866 clock_.ApproximateNow()); | 2863 clock_.ApproximateNow()); |
2867 connection_.GetTimeoutAlarm()->Fire(); | 2864 connection_.GetTimeoutAlarm()->Fire(); |
2868 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 2865 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
2869 EXPECT_FALSE(connection_.connected()); | 2866 EXPECT_FALSE(connection_.connected()); |
2870 return; | 2867 return; |
2871 } | 2868 } |
2872 EXPECT_TRUE(connection_.connected()); | 2869 EXPECT_TRUE(connection_.connected()); |
2873 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 2870 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
2874 QuicConfig config; | 2871 QuicConfig config; |
2875 config.SetDefaults(); | |
2876 connection_.SetFromConfig(config); | 2872 connection_.SetFromConfig(config); |
2877 | 2873 |
2878 const QuicTime::Delta initial_idle_timeout = | 2874 const QuicTime::Delta initial_idle_timeout = |
2879 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); | 2875 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); |
2880 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); | 2876 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); |
2881 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout); | 2877 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout); |
2882 | 2878 |
2883 // When we send a packet, the timeout will change to 5ms + | 2879 // When we send a packet, the timeout will change to 5ms + |
2884 // kInitialIdleTimeoutSecs. | 2880 // kInitialIdleTimeoutSecs. |
2885 clock_.AdvanceTime(five_ms); | 2881 clock_.AdvanceTime(five_ms); |
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4045 QuicBlockedFrame blocked; | 4041 QuicBlockedFrame blocked; |
4046 blocked.stream_id = 3; | 4042 blocked.stream_id = 3; |
4047 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 4043 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
4048 ProcessFramePacket(QuicFrame(&blocked)); | 4044 ProcessFramePacket(QuicFrame(&blocked)); |
4049 EXPECT_TRUE(ack_alarm->IsSet()); | 4045 EXPECT_TRUE(ack_alarm->IsSet()); |
4050 } | 4046 } |
4051 | 4047 |
4052 } // namespace | 4048 } // namespace |
4053 } // namespace test | 4049 } // namespace test |
4054 } // namespace net | 4050 } // namespace net |
OLD | NEW |