| 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 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 } | 897 } |
| 898 return frame; | 898 return frame; |
| 899 } | 899 } |
| 900 | 900 |
| 901 const QuicStopWaitingFrame InitStopWaitingFrame( | 901 const QuicStopWaitingFrame InitStopWaitingFrame( |
| 902 QuicPacketSequenceNumber least_unacked) { | 902 QuicPacketSequenceNumber least_unacked) { |
| 903 QuicStopWaitingFrame frame; | 903 QuicStopWaitingFrame frame; |
| 904 frame.least_unacked = least_unacked; | 904 frame.least_unacked = least_unacked; |
| 905 return frame; | 905 return frame; |
| 906 } | 906 } |
| 907 |
| 907 // Explicitly nack a packet. | 908 // Explicitly nack a packet. |
| 908 void NackPacket(QuicPacketSequenceNumber missing, QuicAckFrame* frame) { | 909 void NackPacket(QuicPacketSequenceNumber missing, QuicAckFrame* frame) { |
| 909 frame->missing_packets.insert(missing); | 910 frame->missing_packets.insert(missing); |
| 910 frame->entropy_hash ^= | 911 frame->entropy_hash ^= |
| 911 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing); | 912 QuicConnectionPeer::PacketEntropy(&connection_, missing); |
| 912 if (missing > 1) { | |
| 913 frame->entropy_hash ^= | |
| 914 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing - 1); | |
| 915 } | |
| 916 } | 913 } |
| 917 | 914 |
| 918 // Undo nacking a packet within the frame. | 915 // Undo nacking a packet within the frame. |
| 919 void AckPacket(QuicPacketSequenceNumber arrived, QuicAckFrame* frame) { | 916 void AckPacket(QuicPacketSequenceNumber arrived, QuicAckFrame* frame) { |
| 920 EXPECT_THAT(frame->missing_packets, Contains(arrived)); | 917 EXPECT_THAT(frame->missing_packets, Contains(arrived)); |
| 921 frame->missing_packets.erase(arrived); | 918 frame->missing_packets.erase(arrived); |
| 922 frame->entropy_hash ^= | 919 frame->entropy_hash ^= |
| 923 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived); | 920 QuicConnectionPeer::PacketEntropy(&connection_, arrived); |
| 924 if (arrived > 1) { | |
| 925 frame->entropy_hash ^= | |
| 926 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived - 1); | |
| 927 } | |
| 928 } | 921 } |
| 929 | 922 |
| 930 void TriggerConnectionClose() { | 923 void TriggerConnectionClose() { |
| 931 // Send an erroneous packet to close the connection. | 924 // Send an erroneous packet to close the connection. |
| 932 EXPECT_CALL(visitor_, | 925 EXPECT_CALL(visitor_, |
| 933 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); | 926 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); |
| 934 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a | 927 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
| 935 // packet call to the visitor. | 928 // packet call to the visitor. |
| 936 ProcessDataPacket(6000, 0, !kEntropyFlag); | 929 ProcessDataPacket(6000, 0, !kEntropyFlag); |
| 937 EXPECT_FALSE( | 930 EXPECT_FALSE( |
| (...skipping 1694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2632 connection_.GetPingAlarm()->deadline()); | 2625 connection_.GetPingAlarm()->deadline()); |
| 2633 | 2626 |
| 2634 // Now recevie and ACK of the previous packet, which will move the | 2627 // Now recevie and ACK of the previous packet, which will move the |
| 2635 // ping alarm forward. | 2628 // ping alarm forward. |
| 2636 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 2629 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 2637 QuicAckFrame frame = InitAckFrame(1); | 2630 QuicAckFrame frame = InitAckFrame(1); |
| 2638 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2631 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2639 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2632 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2640 ProcessAckPacket(&frame); | 2633 ProcessAckPacket(&frame); |
| 2641 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); | 2634 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); |
| 2642 EXPECT_EQ(clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(15)), | 2635 // The ping timer is set slightly less than 15 seconds in the future, because |
| 2636 // of the 1s ping timer alarm granularity. |
| 2637 EXPECT_EQ(clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(15)) |
| 2638 .Subtract(QuicTime::Delta::FromMilliseconds(5)), |
| 2643 connection_.GetPingAlarm()->deadline()); | 2639 connection_.GetPingAlarm()->deadline()); |
| 2644 | 2640 |
| 2645 writer_->Reset(); | 2641 writer_->Reset(); |
| 2646 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(15)); | 2642 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(15)); |
| 2647 connection_.GetPingAlarm()->Fire(); | 2643 connection_.GetPingAlarm()->Fire(); |
| 2648 EXPECT_EQ(1u, writer_->frame_count()); | 2644 EXPECT_EQ(1u, writer_->frame_count()); |
| 2649 if (version() >= QUIC_VERSION_18) { | 2645 if (version() >= QUIC_VERSION_18) { |
| 2650 ASSERT_EQ(1u, writer_->ping_frames().size()); | 2646 ASSERT_EQ(1u, writer_->ping_frames().size()); |
| 2651 } else { | 2647 } else { |
| 2652 ASSERT_EQ(1u, writer_->stream_frames().size()); | 2648 ASSERT_EQ(1u, writer_->stream_frames().size()); |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3239 entropy[i] = entropy[i - 1]; | 3235 entropy[i] = entropy[i - 1]; |
| 3240 } | 3236 } |
| 3241 ProcessDataPacket(i, 1, entropy_flag); | 3237 ProcessDataPacket(i, 1, entropy_flag); |
| 3242 } | 3238 } |
| 3243 for (int i = 1; i < 50; ++i) { | 3239 for (int i = 1; i < 50; ++i) { |
| 3244 EXPECT_EQ(entropy[i], QuicConnectionPeer::ReceivedEntropyHash( | 3240 EXPECT_EQ(entropy[i], QuicConnectionPeer::ReceivedEntropyHash( |
| 3245 &connection_, i)); | 3241 &connection_, i)); |
| 3246 } | 3242 } |
| 3247 } | 3243 } |
| 3248 | 3244 |
| 3249 TEST_P(QuicConnectionTest, CheckSentEntropyHash) { | |
| 3250 peer_creator_.set_sequence_number(1); | |
| 3251 SequenceNumberSet missing_packets; | |
| 3252 QuicPacketEntropyHash entropy_hash = 0; | |
| 3253 QuicPacketSequenceNumber max_sequence_number = 51; | |
| 3254 for (QuicPacketSequenceNumber i = 1; i <= max_sequence_number; ++i) { | |
| 3255 bool is_missing = i % 10 != 0; | |
| 3256 bool entropy_flag = (i & (i - 1)) != 0; | |
| 3257 QuicPacketEntropyHash packet_entropy_hash = 0; | |
| 3258 if (entropy_flag) { | |
| 3259 packet_entropy_hash = 1 << (i % 8); | |
| 3260 } | |
| 3261 QuicPacket* packet = ConstructDataPacket(i, 0, entropy_flag); | |
| 3262 connection_.SendPacket( | |
| 3263 ENCRYPTION_NONE, i, packet, packet_entropy_hash, | |
| 3264 HAS_RETRANSMITTABLE_DATA); | |
| 3265 | |
| 3266 if (is_missing) { | |
| 3267 missing_packets.insert(i); | |
| 3268 continue; | |
| 3269 } | |
| 3270 | |
| 3271 entropy_hash ^= packet_entropy_hash; | |
| 3272 } | |
| 3273 EXPECT_TRUE(QuicConnectionPeer::IsValidEntropy( | |
| 3274 &connection_, max_sequence_number, missing_packets, entropy_hash)) | |
| 3275 << ""; | |
| 3276 } | |
| 3277 | |
| 3278 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacket) { | 3245 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacket) { |
| 3279 connection_.SetSupportedVersions(QuicSupportedVersions()); | 3246 connection_.SetSupportedVersions(QuicSupportedVersions()); |
| 3280 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 3247 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
| 3281 | 3248 |
| 3282 QuicPacketHeader header; | 3249 QuicPacketHeader header; |
| 3283 header.public_header.connection_id = connection_id_; | 3250 header.public_header.connection_id = connection_id_; |
| 3284 header.public_header.reset_flag = false; | 3251 header.public_header.reset_flag = false; |
| 3285 header.public_header.version_flag = true; | 3252 header.public_header.version_flag = true; |
| 3286 header.entropy_flag = false; | 3253 header.entropy_flag = false; |
| 3287 header.fec_flag = false; | 3254 header.fec_flag = false; |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3984 QuicBlockedFrame blocked; | 3951 QuicBlockedFrame blocked; |
| 3985 blocked.stream_id = 3; | 3952 blocked.stream_id = 3; |
| 3986 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 3953 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
| 3987 ProcessFramePacket(QuicFrame(&blocked)); | 3954 ProcessFramePacket(QuicFrame(&blocked)); |
| 3988 EXPECT_TRUE(ack_alarm->IsSet()); | 3955 EXPECT_TRUE(ack_alarm->IsSet()); |
| 3989 } | 3956 } |
| 3990 | 3957 |
| 3991 } // namespace | 3958 } // namespace |
| 3992 } // namespace test | 3959 } // namespace test |
| 3993 } // namespace net | 3960 } // namespace net |
| OLD | NEW |