| 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/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 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 bool entropy_flag, | 844 bool entropy_flag, |
| 845 bool has_stop_waiting, | 845 bool has_stop_waiting, |
| 846 EncryptionLevel level) { | 846 EncryptionLevel level) { |
| 847 std::unique_ptr<QuicPacket> packet( | 847 std::unique_ptr<QuicPacket> packet( |
| 848 ConstructDataPacket(path_id, number, entropy_flag, has_stop_waiting)); | 848 ConstructDataPacket(path_id, number, entropy_flag, has_stop_waiting)); |
| 849 char buffer[kMaxPacketSize]; | 849 char buffer[kMaxPacketSize]; |
| 850 size_t encrypted_length = framer_.EncryptPayload( | 850 size_t encrypted_length = framer_.EncryptPayload( |
| 851 level, path_id, number, *packet, buffer, kMaxPacketSize); | 851 level, path_id, number, *packet, buffer, kMaxPacketSize); |
| 852 connection_.ProcessUdpPacket( | 852 connection_.ProcessUdpPacket( |
| 853 kSelfAddress, kPeerAddress, | 853 kSelfAddress, kPeerAddress, |
| 854 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); | 854 QuicReceivedPacket(buffer, encrypted_length, clock_.Now(), false)); |
| 855 if (connection_.GetSendAlarm()->IsSet()) { | 855 if (connection_.GetSendAlarm()->IsSet()) { |
| 856 connection_.GetSendAlarm()->Fire(); | 856 connection_.GetSendAlarm()->Fire(); |
| 857 } | 857 } |
| 858 return encrypted_length; | 858 return encrypted_length; |
| 859 } | 859 } |
| 860 | 860 |
| 861 void ProcessClosePacket(QuicPathId path_id, QuicPacketNumber number) { | 861 void ProcessClosePacket(QuicPathId path_id, QuicPacketNumber number) { |
| 862 std::unique_ptr<QuicPacket> packet(ConstructClosePacket(number)); | 862 std::unique_ptr<QuicPacket> packet(ConstructClosePacket(number)); |
| 863 char buffer[kMaxPacketSize]; | 863 char buffer[kMaxPacketSize]; |
| 864 size_t encrypted_length = framer_.EncryptPayload( | 864 size_t encrypted_length = framer_.EncryptPayload( |
| (...skipping 2323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3188 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); | 3188 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); |
| 3189 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); | 3189 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); |
| 3190 | 3190 |
| 3191 // The original alarm will fire. We should not time out because we had a | 3191 // The original alarm will fire. We should not time out because we had a |
| 3192 // network event at t=5ms. The alarm will reregister. | 3192 // network event at t=5ms. The alarm will reregister. |
| 3193 clock_.AdvanceTime(initial_idle_timeout - five_ms - five_ms); | 3193 clock_.AdvanceTime(initial_idle_timeout - five_ms - five_ms); |
| 3194 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); | 3194 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); |
| 3195 connection_.GetTimeoutAlarm()->Fire(); | 3195 connection_.GetTimeoutAlarm()->Fire(); |
| 3196 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); | 3196 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3197 EXPECT_TRUE(connection_.connected()); | 3197 EXPECT_TRUE(connection_.connected()); |
| 3198 EXPECT_EQ(default_timeout + five_ms + five_ms, | 3198 if (FLAGS_quic_better_last_send_for_timeout) { |
| 3199 connection_.GetTimeoutAlarm()->deadline()); | 3199 EXPECT_EQ(default_timeout + five_ms, |
| 3200 connection_.GetTimeoutAlarm()->deadline()); |
| 3201 } else { |
| 3202 EXPECT_EQ(default_timeout + five_ms + five_ms, |
| 3203 connection_.GetTimeoutAlarm()->deadline()); |
| 3204 } |
| 3200 | 3205 |
| 3201 // This time, we should time out. | 3206 // This time, we should time out. |
| 3202 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, | 3207 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, |
| 3203 ConnectionCloseSource::FROM_SELF)); | 3208 ConnectionCloseSource::FROM_SELF)); |
| 3204 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3209 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3205 clock_.AdvanceTime(five_ms); | 3210 clock_.AdvanceTime(five_ms); |
| 3206 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); | 3211 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); |
| 3207 connection_.GetTimeoutAlarm()->Fire(); | 3212 connection_.GetTimeoutAlarm()->Fire(); |
| 3208 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3213 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3209 EXPECT_FALSE(connection_.connected()); | 3214 EXPECT_FALSE(connection_.connected()); |
| 3210 } | 3215 } |
| 3211 | 3216 |
| 3217 TEST_P(QuicConnectionTest, TimeoutAfterRetransmission) { |
| 3218 FLAGS_quic_better_last_send_for_timeout = true; |
| 3219 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3220 EXPECT_TRUE(connection_.connected()); |
| 3221 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3222 QuicConfig config; |
| 3223 connection_.SetFromConfig(config); |
| 3224 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); |
| 3225 |
| 3226 const QuicTime start_time = clock_.Now(); |
| 3227 const QuicTime::Delta initial_idle_timeout = |
| 3228 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); |
| 3229 QuicTime default_timeout = clock_.Now() + initial_idle_timeout; |
| 3230 |
| 3231 connection_.SetMaxTailLossProbes(kDefaultPathId, 0); |
| 3232 const QuicTime default_retransmission_time = |
| 3233 start_time + DefaultRetransmissionTime(); |
| 3234 |
| 3235 ASSERT_LT(default_retransmission_time, default_timeout); |
| 3236 |
| 3237 // When we send a packet, the timeout will change to 5 ms + |
| 3238 // kInitialIdleTimeoutSecs (but it will not reschedule the alarm). |
| 3239 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); |
| 3240 const QuicTime send_time = start_time + five_ms; |
| 3241 clock_.AdvanceTime(five_ms); |
| 3242 ASSERT_EQ(send_time, clock_.Now()); |
| 3243 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); |
| 3244 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); |
| 3245 |
| 3246 // Move forward 5 ms and receive a packet, which will move the timeout |
| 3247 // forward 5 ms more (but will not reschedule the alarm). |
| 3248 const QuicTime receive_time = send_time + five_ms; |
| 3249 clock_.AdvanceTime(receive_time - clock_.Now()); |
| 3250 ASSERT_EQ(receive_time, clock_.Now()); |
| 3251 ProcessPacket(kDefaultPathId, 1); |
| 3252 |
| 3253 // Now move forward to the retransmission time and retransmit the |
| 3254 // packet, which should move the timeout forward again (but will not |
| 3255 // reschedule the alarm). |
| 3256 EXPECT_EQ(default_retransmission_time + five_ms, |
| 3257 connection_.GetRetransmissionAlarm()->deadline()); |
| 3258 // Simulate the retransmission alarm firing. |
| 3259 const QuicTime rto_time = send_time + DefaultRetransmissionTime(); |
| 3260 const QuicTime final_timeout = rto_time + initial_idle_timeout; |
| 3261 clock_.AdvanceTime(rto_time - clock_.Now()); |
| 3262 ASSERT_EQ(rto_time, clock_.Now()); |
| 3263 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); |
| 3264 connection_.GetRetransmissionAlarm()->Fire(); |
| 3265 |
| 3266 // Advance to the original timeout and fire the alarm. The connection should |
| 3267 // timeout, and the alarm should be registered based on the time of the |
| 3268 // retransmission. |
| 3269 clock_.AdvanceTime(default_timeout - clock_.Now()); |
| 3270 ASSERT_EQ(default_timeout.ToDebuggingValue(), |
| 3271 clock_.Now().ToDebuggingValue()); |
| 3272 EXPECT_EQ(default_timeout, clock_.Now()); |
| 3273 connection_.GetTimeoutAlarm()->Fire(); |
| 3274 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3275 EXPECT_TRUE(connection_.connected()); |
| 3276 ASSERT_EQ(final_timeout.ToDebuggingValue(), |
| 3277 connection_.GetTimeoutAlarm()->deadline().ToDebuggingValue()); |
| 3278 |
| 3279 // This time, we should time out. |
| 3280 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, |
| 3281 ConnectionCloseSource::FROM_SELF)); |
| 3282 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3283 clock_.AdvanceTime(final_timeout - clock_.Now()); |
| 3284 EXPECT_EQ(connection_.GetTimeoutAlarm()->deadline(), clock_.Now()); |
| 3285 EXPECT_EQ(final_timeout, clock_.Now()); |
| 3286 connection_.GetTimeoutAlarm()->Fire(); |
| 3287 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3288 EXPECT_FALSE(connection_.connected()); |
| 3289 } |
| 3290 |
| 3212 TEST_P(QuicConnectionTest, NewTimeoutAfterSendSilentClose) { | 3291 TEST_P(QuicConnectionTest, NewTimeoutAfterSendSilentClose) { |
| 3213 // Same test as above, but complete a handshake which enables silent close, | 3292 // Same test as above, but complete a handshake which enables silent close, |
| 3214 // causing no connection close packet to be sent. | 3293 // causing no connection close packet to be sent. |
| 3215 EXPECT_TRUE(connection_.connected()); | 3294 EXPECT_TRUE(connection_.connected()); |
| 3216 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3295 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3217 QuicConfig config; | 3296 QuicConfig config; |
| 3218 | 3297 |
| 3219 // Create a handshake message that also enables silent close. | 3298 // Create a handshake message that also enables silent close. |
| 3220 CryptoHandshakeMessage msg; | 3299 CryptoHandshakeMessage msg; |
| 3221 string error_details; | 3300 string error_details; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3252 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); | 3331 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); |
| 3253 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); | 3332 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); |
| 3254 | 3333 |
| 3255 // The original alarm will fire. We should not time out because we had a | 3334 // The original alarm will fire. We should not time out because we had a |
| 3256 // network event at t=5ms. The alarm will reregister. | 3335 // network event at t=5ms. The alarm will reregister. |
| 3257 clock_.AdvanceTime(default_idle_timeout - five_ms - five_ms); | 3336 clock_.AdvanceTime(default_idle_timeout - five_ms - five_ms); |
| 3258 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); | 3337 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); |
| 3259 connection_.GetTimeoutAlarm()->Fire(); | 3338 connection_.GetTimeoutAlarm()->Fire(); |
| 3260 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); | 3339 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3261 EXPECT_TRUE(connection_.connected()); | 3340 EXPECT_TRUE(connection_.connected()); |
| 3262 EXPECT_EQ(default_timeout + five_ms + five_ms, | 3341 if (FLAGS_quic_better_last_send_for_timeout) { |
| 3263 connection_.GetTimeoutAlarm()->deadline()); | 3342 EXPECT_EQ(default_timeout + five_ms, |
| 3343 connection_.GetTimeoutAlarm()->deadline()); |
| 3344 } else { |
| 3345 EXPECT_EQ(default_timeout + five_ms + five_ms, |
| 3346 connection_.GetTimeoutAlarm()->deadline()); |
| 3347 } |
| 3264 | 3348 |
| 3265 // This time, we should time out. | 3349 // This time, we should time out. |
| 3266 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, | 3350 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, |
| 3267 ConnectionCloseSource::FROM_SELF)); | 3351 ConnectionCloseSource::FROM_SELF)); |
| 3268 clock_.AdvanceTime(five_ms); | 3352 clock_.AdvanceTime(five_ms); |
| 3269 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); | 3353 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); |
| 3270 connection_.GetTimeoutAlarm()->Fire(); | 3354 connection_.GetTimeoutAlarm()->Fire(); |
| 3271 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3355 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3272 EXPECT_FALSE(connection_.connected()); | 3356 EXPECT_FALSE(connection_.connected()); |
| 3273 } | 3357 } |
| (...skipping 1759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5033 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(0); | 5117 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(0); |
| 5034 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); | 5118 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); |
| 5035 BlockOnNextWrite(); | 5119 BlockOnNextWrite(); |
| 5036 | 5120 |
| 5037 connection_.SendStreamData3(); | 5121 connection_.SendStreamData3(); |
| 5038 } | 5122 } |
| 5039 | 5123 |
| 5040 } // namespace | 5124 } // namespace |
| 5041 } // namespace test | 5125 } // namespace test |
| 5042 } // namespace net | 5126 } // namespace net |
| OLD | NEW |