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 <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 QuicPacket* packet, | 448 QuicPacket* packet, |
449 QuicPacketEntropyHash entropy_hash, | 449 QuicPacketEntropyHash entropy_hash, |
450 HasRetransmittableData retransmittable, | 450 HasRetransmittableData retransmittable, |
451 bool has_ack, | 451 bool has_ack, |
452 bool has_pending_frames) { | 452 bool has_pending_frames) { |
453 RetransmittableFrames* retransmittable_frames = | 453 RetransmittableFrames* retransmittable_frames = |
454 retransmittable == HAS_RETRANSMITTABLE_DATA | 454 retransmittable == HAS_RETRANSMITTABLE_DATA |
455 ? new RetransmittableFrames(ENCRYPTION_NONE) | 455 ? new RetransmittableFrames(ENCRYPTION_NONE) |
456 : nullptr; | 456 : nullptr; |
457 char buffer[kMaxPacketSize]; | 457 char buffer[kMaxPacketSize]; |
458 QuicEncryptedPacket* encrypted = | 458 size_t encrypted_length = |
459 QuicConnectionPeer::GetFramer(this)->EncryptPayload( | 459 QuicConnectionPeer::GetFramer(this)->EncryptPayload( |
460 ENCRYPTION_NONE, packet_number, *packet, buffer, kMaxPacketSize); | 460 ENCRYPTION_NONE, packet_number, *packet, buffer, kMaxPacketSize); |
461 delete packet; | 461 delete packet; |
462 OnSerializedPacket(SerializedPacket( | 462 OnSerializedPacket( |
463 packet_number, PACKET_6BYTE_PACKET_NUMBER, encrypted, entropy_hash, | 463 SerializedPacket(packet_number, PACKET_6BYTE_PACKET_NUMBER, buffer, |
464 retransmittable_frames, has_ack, has_pending_frames)); | 464 encrypted_length, false, entropy_hash, |
| 465 retransmittable_frames, has_ack, has_pending_frames)); |
465 } | 466 } |
466 | 467 |
467 QuicConsumedData SendStreamDataWithString( | 468 QuicConsumedData SendStreamDataWithString( |
468 QuicStreamId id, | 469 QuicStreamId id, |
469 StringPiece data, | 470 StringPiece data, |
470 QuicStreamOffset offset, | 471 QuicStreamOffset offset, |
471 bool fin, | 472 bool fin, |
472 QuicAckListenerInterface* listener) { | 473 QuicAckListenerInterface* listener) { |
473 return SendStreamDataWithStringHelper(id, data, offset, fin, | 474 return SendStreamDataWithStringHelper(id, data, offset, fin, |
474 MAY_FEC_PROTECT, listener); | 475 MAY_FEC_PROTECT, listener); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 ENCRYPTION_NONE); | 781 ENCRYPTION_NONE); |
781 } | 782 } |
782 | 783 |
783 size_t ProcessDataPacketAtLevel(QuicPacketNumber number, | 784 size_t ProcessDataPacketAtLevel(QuicPacketNumber number, |
784 QuicFecGroupNumber fec_group, | 785 QuicFecGroupNumber fec_group, |
785 bool entropy_flag, | 786 bool entropy_flag, |
786 EncryptionLevel level) { | 787 EncryptionLevel level) { |
787 scoped_ptr<QuicPacket> packet(ConstructDataPacket(number, fec_group, | 788 scoped_ptr<QuicPacket> packet(ConstructDataPacket(number, fec_group, |
788 entropy_flag)); | 789 entropy_flag)); |
789 char buffer[kMaxPacketSize]; | 790 char buffer[kMaxPacketSize]; |
790 scoped_ptr<QuicEncryptedPacket> encrypted( | 791 size_t encrypted_length = |
791 framer_.EncryptPayload(level, number, *packet, buffer, kMaxPacketSize)); | 792 framer_.EncryptPayload(level, number, *packet, buffer, kMaxPacketSize); |
792 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 793 connection_.ProcessUdpPacket( |
793 return encrypted->length(); | 794 kSelfAddress, kPeerAddress, |
| 795 QuicEncryptedPacket(buffer, encrypted_length, false)); |
| 796 return encrypted_length; |
794 } | 797 } |
795 | 798 |
796 void ProcessClosePacket(QuicPacketNumber number, | 799 void ProcessClosePacket(QuicPacketNumber number, |
797 QuicFecGroupNumber fec_group) { | 800 QuicFecGroupNumber fec_group) { |
798 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); | 801 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); |
799 char buffer[kMaxPacketSize]; | 802 char buffer[kMaxPacketSize]; |
800 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 803 size_t encrypted_length = framer_.EncryptPayload( |
801 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize)); | 804 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize); |
802 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 805 connection_.ProcessUdpPacket( |
| 806 kSelfAddress, kPeerAddress, |
| 807 QuicEncryptedPacket(buffer, encrypted_length, false)); |
803 } | 808 } |
804 | 809 |
805 size_t ProcessFecProtectedPacket(QuicPacketNumber number, | 810 size_t ProcessFecProtectedPacket(QuicPacketNumber number, |
806 bool expect_revival, | 811 bool expect_revival, |
807 bool entropy_flag) { | 812 bool entropy_flag) { |
808 if (expect_revival) { | 813 if (expect_revival) { |
809 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 814 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
810 } | 815 } |
811 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1).RetiresOnSaturation(); | 816 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1).RetiresOnSaturation(); |
812 return ProcessDataPacket(number, 1, entropy_flag); | 817 return ProcessDataPacket(number, 1, entropy_flag); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 header.public_header.version_flag, | 857 header.public_header.version_flag, |
853 header.public_header.packet_number_length); | 858 header.public_header.packet_number_length); |
854 i < data_packet->length(); ++i) { | 859 i < data_packet->length(); ++i) { |
855 data_packet->mutable_data()[i] ^= data_packet->data()[i]; | 860 data_packet->mutable_data()[i] ^= data_packet->data()[i]; |
856 } | 861 } |
857 } | 862 } |
858 | 863 |
859 scoped_ptr<QuicPacket> fec_packet( | 864 scoped_ptr<QuicPacket> fec_packet( |
860 framer_.BuildFecPacket(header, data_packet->FecProtectedData())); | 865 framer_.BuildFecPacket(header, data_packet->FecProtectedData())); |
861 char buffer[kMaxPacketSize]; | 866 char buffer[kMaxPacketSize]; |
862 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 867 size_t encrypted_length = framer_.EncryptPayload( |
863 ENCRYPTION_NONE, number, *fec_packet, buffer, kMaxPacketSize)); | 868 ENCRYPTION_NONE, number, *fec_packet, buffer, kMaxPacketSize); |
864 | 869 |
865 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 870 connection_.ProcessUdpPacket( |
866 return encrypted->length(); | 871 kSelfAddress, kPeerAddress, |
| 872 QuicEncryptedPacket(buffer, encrypted_length, false)); |
| 873 return encrypted_length; |
867 } | 874 } |
868 | 875 |
869 QuicByteCount SendStreamDataToPeer(QuicStreamId id, | 876 QuicByteCount SendStreamDataToPeer(QuicStreamId id, |
870 StringPiece data, | 877 StringPiece data, |
871 QuicStreamOffset offset, | 878 QuicStreamOffset offset, |
872 bool fin, | 879 bool fin, |
873 QuicPacketNumber* last_packet) { | 880 QuicPacketNumber* last_packet) { |
874 QuicByteCount packet_size; | 881 QuicByteCount packet_size; |
875 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 882 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
876 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); | 883 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 header.public_header.connection_id = connection_id_; | 1087 header.public_header.connection_id = connection_id_; |
1081 header.public_header.version_flag = true; | 1088 header.public_header.version_flag = true; |
1082 header.packet_number = 1; | 1089 header.packet_number = 1; |
1083 | 1090 |
1084 QuicFrames frames; | 1091 QuicFrames frames; |
1085 QuicPaddingFrame padding; | 1092 QuicPaddingFrame padding; |
1086 frames.push_back(QuicFrame(&frame1_)); | 1093 frames.push_back(QuicFrame(&frame1_)); |
1087 frames.push_back(QuicFrame(padding)); | 1094 frames.push_back(QuicFrame(padding)); |
1088 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 1095 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
1089 char buffer[kMaxPacketSize]; | 1096 char buffer[kMaxPacketSize]; |
1090 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 1097 size_t encrypted_length = framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, |
1091 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); | 1098 buffer, kMaxPacketSize); |
1092 EXPECT_EQ(kMaxPacketSize, encrypted->length()); | 1099 EXPECT_EQ(kMaxPacketSize, encrypted_length); |
1093 | 1100 |
1094 framer_.set_version(version()); | 1101 framer_.set_version(version()); |
1095 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 1102 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
1096 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 1103 connection_.ProcessUdpPacket( |
| 1104 kSelfAddress, kPeerAddress, |
| 1105 QuicEncryptedPacket(buffer, encrypted_length, false)); |
1097 | 1106 |
1098 EXPECT_EQ(kMaxPacketSize, connection_.max_packet_length()); | 1107 EXPECT_EQ(kMaxPacketSize, connection_.max_packet_length()); |
1099 } | 1108 } |
1100 | 1109 |
1101 TEST_P(QuicConnectionTest, IncreaseServerMaxPacketSizeWhileWriterLimited) { | 1110 TEST_P(QuicConnectionTest, IncreaseServerMaxPacketSizeWhileWriterLimited) { |
1102 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1111 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1103 | 1112 |
1104 const QuicByteCount lower_max_packet_size = 1240; | 1113 const QuicByteCount lower_max_packet_size = 1240; |
1105 writer_->set_max_packet_size(lower_max_packet_size); | 1114 writer_->set_max_packet_size(lower_max_packet_size); |
1106 connection_.set_perspective(Perspective::IS_SERVER); | 1115 connection_.set_perspective(Perspective::IS_SERVER); |
1107 connection_.SetMaxPacketLength(1000); | 1116 connection_.SetMaxPacketLength(1000); |
1108 EXPECT_EQ(1000u, connection_.max_packet_length()); | 1117 EXPECT_EQ(1000u, connection_.max_packet_length()); |
1109 | 1118 |
1110 QuicPacketHeader header; | 1119 QuicPacketHeader header; |
1111 header.public_header.connection_id = connection_id_; | 1120 header.public_header.connection_id = connection_id_; |
1112 header.public_header.version_flag = true; | 1121 header.public_header.version_flag = true; |
1113 header.packet_number = 1; | 1122 header.packet_number = 1; |
1114 | 1123 |
1115 QuicFrames frames; | 1124 QuicFrames frames; |
1116 QuicPaddingFrame padding; | 1125 QuicPaddingFrame padding; |
1117 frames.push_back(QuicFrame(&frame1_)); | 1126 frames.push_back(QuicFrame(&frame1_)); |
1118 frames.push_back(QuicFrame(padding)); | 1127 frames.push_back(QuicFrame(padding)); |
1119 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 1128 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
1120 char buffer[kMaxPacketSize]; | 1129 char buffer[kMaxPacketSize]; |
1121 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 1130 size_t encrypted_length = framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, |
1122 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); | 1131 buffer, kMaxPacketSize); |
1123 EXPECT_EQ(kMaxPacketSize, encrypted->length()); | 1132 EXPECT_EQ(kMaxPacketSize, encrypted_length); |
1124 | 1133 |
1125 framer_.set_version(version()); | 1134 framer_.set_version(version()); |
1126 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 1135 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
1127 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 1136 connection_.ProcessUdpPacket( |
| 1137 kSelfAddress, kPeerAddress, |
| 1138 QuicEncryptedPacket(buffer, encrypted_length, false)); |
1128 | 1139 |
1129 // Here, the limit imposed by the writer is lower than the size of the packet | 1140 // Here, the limit imposed by the writer is lower than the size of the packet |
1130 // received, so the writer max packet size is used. | 1141 // received, so the writer max packet size is used. |
1131 EXPECT_EQ(lower_max_packet_size, connection_.max_packet_length()); | 1142 EXPECT_EQ(lower_max_packet_size, connection_.max_packet_length()); |
1132 } | 1143 } |
1133 | 1144 |
1134 TEST_P(QuicConnectionTest, LimitMaxPacketSizeByWriter) { | 1145 TEST_P(QuicConnectionTest, LimitMaxPacketSizeByWriter) { |
1135 const QuicByteCount lower_max_packet_size = 1240; | 1146 const QuicByteCount lower_max_packet_size = 1240; |
1136 writer_->set_max_packet_size(lower_max_packet_size); | 1147 writer_->set_max_packet_size(lower_max_packet_size); |
1137 | 1148 |
(...skipping 2996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4134 | 4145 |
4135 QuicPacketHeader header; | 4146 QuicPacketHeader header; |
4136 header.public_header.connection_id = connection_id_; | 4147 header.public_header.connection_id = connection_id_; |
4137 header.public_header.version_flag = true; | 4148 header.public_header.version_flag = true; |
4138 header.packet_number = 12; | 4149 header.packet_number = 12; |
4139 | 4150 |
4140 QuicFrames frames; | 4151 QuicFrames frames; |
4141 frames.push_back(QuicFrame(&frame1_)); | 4152 frames.push_back(QuicFrame(&frame1_)); |
4142 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 4153 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
4143 char buffer[kMaxPacketSize]; | 4154 char buffer[kMaxPacketSize]; |
4144 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 4155 size_t encrypted_length = framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, |
4145 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); | 4156 buffer, kMaxPacketSize); |
4146 | 4157 |
4147 framer_.set_version(version()); | 4158 framer_.set_version(version()); |
4148 connection_.set_perspective(Perspective::IS_SERVER); | 4159 connection_.set_perspective(Perspective::IS_SERVER); |
4149 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 4160 connection_.ProcessUdpPacket( |
| 4161 kSelfAddress, kPeerAddress, |
| 4162 QuicEncryptedPacket(buffer, encrypted_length, false)); |
4150 EXPECT_TRUE(writer_->version_negotiation_packet() != nullptr); | 4163 EXPECT_TRUE(writer_->version_negotiation_packet() != nullptr); |
4151 | 4164 |
4152 size_t num_versions = arraysize(kSupportedQuicVersions); | 4165 size_t num_versions = arraysize(kSupportedQuicVersions); |
4153 ASSERT_EQ(num_versions, | 4166 ASSERT_EQ(num_versions, |
4154 writer_->version_negotiation_packet()->versions.size()); | 4167 writer_->version_negotiation_packet()->versions.size()); |
4155 | 4168 |
4156 // We expect all versions in kSupportedQuicVersions to be | 4169 // We expect all versions in kSupportedQuicVersions to be |
4157 // included in the packet. | 4170 // included in the packet. |
4158 for (size_t i = 0; i < num_versions; ++i) { | 4171 for (size_t i = 0; i < num_versions; ++i) { |
4159 EXPECT_EQ(kSupportedQuicVersions[i], | 4172 EXPECT_EQ(kSupportedQuicVersions[i], |
4160 writer_->version_negotiation_packet()->versions[i]); | 4173 writer_->version_negotiation_packet()->versions[i]); |
4161 } | 4174 } |
4162 } | 4175 } |
4163 | 4176 |
4164 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacketSocketBlocked) { | 4177 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacketSocketBlocked) { |
4165 connection_.SetSupportedVersions(QuicSupportedVersions()); | 4178 connection_.SetSupportedVersions(QuicSupportedVersions()); |
4166 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 4179 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
4167 | 4180 |
4168 QuicPacketHeader header; | 4181 QuicPacketHeader header; |
4169 header.public_header.connection_id = connection_id_; | 4182 header.public_header.connection_id = connection_id_; |
4170 header.public_header.version_flag = true; | 4183 header.public_header.version_flag = true; |
4171 header.packet_number = 12; | 4184 header.packet_number = 12; |
4172 | 4185 |
4173 QuicFrames frames; | 4186 QuicFrames frames; |
4174 frames.push_back(QuicFrame(&frame1_)); | 4187 frames.push_back(QuicFrame(&frame1_)); |
4175 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 4188 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
4176 char buffer[kMaxPacketSize]; | 4189 char buffer[kMaxPacketSize]; |
4177 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 4190 size_t encrypted_length = framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, |
4178 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); | 4191 buffer, kMaxPacketSize); |
4179 | 4192 |
4180 framer_.set_version(version()); | 4193 framer_.set_version(version()); |
4181 connection_.set_perspective(Perspective::IS_SERVER); | 4194 connection_.set_perspective(Perspective::IS_SERVER); |
4182 BlockOnNextWrite(); | 4195 BlockOnNextWrite(); |
4183 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 4196 connection_.ProcessUdpPacket( |
| 4197 kSelfAddress, kPeerAddress, |
| 4198 QuicEncryptedPacket(buffer, encrypted_length, false)); |
4184 EXPECT_EQ(0u, writer_->last_packet_size()); | 4199 EXPECT_EQ(0u, writer_->last_packet_size()); |
4185 EXPECT_TRUE(connection_.HasQueuedData()); | 4200 EXPECT_TRUE(connection_.HasQueuedData()); |
4186 | 4201 |
4187 writer_->SetWritable(); | 4202 writer_->SetWritable(); |
4188 connection_.OnCanWrite(); | 4203 connection_.OnCanWrite(); |
4189 EXPECT_TRUE(writer_->version_negotiation_packet() != nullptr); | 4204 EXPECT_TRUE(writer_->version_negotiation_packet() != nullptr); |
4190 | 4205 |
4191 size_t num_versions = arraysize(kSupportedQuicVersions); | 4206 size_t num_versions = arraysize(kSupportedQuicVersions); |
4192 ASSERT_EQ(num_versions, | 4207 ASSERT_EQ(num_versions, |
4193 writer_->version_negotiation_packet()->versions.size()); | 4208 writer_->version_negotiation_packet()->versions.size()); |
(...skipping 13 matching lines...) Expand all Loading... |
4207 | 4222 |
4208 QuicPacketHeader header; | 4223 QuicPacketHeader header; |
4209 header.public_header.connection_id = connection_id_; | 4224 header.public_header.connection_id = connection_id_; |
4210 header.public_header.version_flag = true; | 4225 header.public_header.version_flag = true; |
4211 header.packet_number = 12; | 4226 header.packet_number = 12; |
4212 | 4227 |
4213 QuicFrames frames; | 4228 QuicFrames frames; |
4214 frames.push_back(QuicFrame(&frame1_)); | 4229 frames.push_back(QuicFrame(&frame1_)); |
4215 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 4230 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
4216 char buffer[kMaxPacketSize]; | 4231 char buffer[kMaxPacketSize]; |
4217 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 4232 size_t encryped_length = framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, |
4218 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); | 4233 buffer, kMaxPacketSize); |
4219 | 4234 |
4220 framer_.set_version(version()); | 4235 framer_.set_version(version()); |
4221 connection_.set_perspective(Perspective::IS_SERVER); | 4236 connection_.set_perspective(Perspective::IS_SERVER); |
4222 BlockOnNextWrite(); | 4237 BlockOnNextWrite(); |
4223 writer_->set_is_write_blocked_data_buffered(true); | 4238 writer_->set_is_write_blocked_data_buffered(true); |
4224 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 4239 connection_.ProcessUdpPacket( |
| 4240 kSelfAddress, kPeerAddress, |
| 4241 QuicEncryptedPacket(buffer, encryped_length, false)); |
4225 EXPECT_EQ(0u, writer_->last_packet_size()); | 4242 EXPECT_EQ(0u, writer_->last_packet_size()); |
4226 EXPECT_FALSE(connection_.HasQueuedData()); | 4243 EXPECT_FALSE(connection_.HasQueuedData()); |
4227 } | 4244 } |
4228 | 4245 |
4229 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { | 4246 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { |
4230 // Start out with some unsupported version. | 4247 // Start out with some unsupported version. |
4231 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( | 4248 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( |
4232 QUIC_VERSION_UNSUPPORTED); | 4249 QUIC_VERSION_UNSUPPORTED); |
4233 | 4250 |
4234 QuicPacketHeader header; | 4251 QuicPacketHeader header; |
(...skipping 12 matching lines...) Expand all Loading... |
4247 header.public_header, supported_versions)); | 4264 header.public_header, supported_versions)); |
4248 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 4265 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
4249 | 4266 |
4250 // Now force another packet. The connection should transition into | 4267 // Now force another packet. The connection should transition into |
4251 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. | 4268 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. |
4252 header.public_header.version_flag = false; | 4269 header.public_header.version_flag = false; |
4253 QuicFrames frames; | 4270 QuicFrames frames; |
4254 frames.push_back(QuicFrame(&frame1_)); | 4271 frames.push_back(QuicFrame(&frame1_)); |
4255 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 4272 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
4256 char buffer[kMaxPacketSize]; | 4273 char buffer[kMaxPacketSize]; |
4257 encrypted.reset(framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, buffer, | 4274 size_t encrypted_length = framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, |
4258 kMaxPacketSize)); | 4275 buffer, kMaxPacketSize); |
| 4276 ASSERT_NE(0u, encrypted_length); |
4259 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4277 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4260 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4278 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4261 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 4279 connection_.ProcessUdpPacket( |
| 4280 kSelfAddress, kPeerAddress, |
| 4281 QuicEncryptedPacket(buffer, encrypted_length, false)); |
4262 | 4282 |
4263 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(creator_)); | 4283 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(creator_)); |
4264 } | 4284 } |
4265 | 4285 |
4266 TEST_P(QuicConnectionTest, BadVersionNegotiation) { | 4286 TEST_P(QuicConnectionTest, BadVersionNegotiation) { |
4267 QuicPacketHeader header; | 4287 QuicPacketHeader header; |
4268 header.public_header.connection_id = connection_id_; | 4288 header.public_header.connection_id = connection_id_; |
4269 header.public_header.version_flag = true; | 4289 header.public_header.version_flag = true; |
4270 header.packet_number = 12; | 4290 header.packet_number = 12; |
4271 | 4291 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4382 | 4402 |
4383 QuicConnectionCloseFrame qccf; | 4403 QuicConnectionCloseFrame qccf; |
4384 qccf.error_code = QUIC_PEER_GOING_AWAY; | 4404 qccf.error_code = QUIC_PEER_GOING_AWAY; |
4385 | 4405 |
4386 QuicFrames frames; | 4406 QuicFrames frames; |
4387 frames.push_back(QuicFrame(&frame1_)); | 4407 frames.push_back(QuicFrame(&frame1_)); |
4388 frames.push_back(QuicFrame(&qccf)); | 4408 frames.push_back(QuicFrame(&qccf)); |
4389 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 4409 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
4390 EXPECT_TRUE(nullptr != packet.get()); | 4410 EXPECT_TRUE(nullptr != packet.get()); |
4391 char buffer[kMaxPacketSize]; | 4411 char buffer[kMaxPacketSize]; |
4392 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 4412 size_t encrypted_length = framer_.EncryptPayload(ENCRYPTION_NONE, 1, *packet, |
4393 ENCRYPTION_NONE, 1, *packet, buffer, kMaxPacketSize)); | 4413 buffer, kMaxPacketSize); |
4394 | 4414 |
4395 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); | 4415 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); |
4396 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4416 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4397 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4417 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4398 | 4418 |
4399 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 4419 connection_.ProcessUdpPacket( |
| 4420 kSelfAddress, kPeerAddress, |
| 4421 QuicEncryptedPacket(buffer, encrypted_length, false)); |
4400 } | 4422 } |
4401 | 4423 |
4402 TEST_P(QuicConnectionTest, SelectMutualVersion) { | 4424 TEST_P(QuicConnectionTest, SelectMutualVersion) { |
4403 connection_.SetSupportedVersions(QuicSupportedVersions()); | 4425 connection_.SetSupportedVersions(QuicSupportedVersions()); |
4404 // Set the connection to speak the lowest quic version. | 4426 // Set the connection to speak the lowest quic version. |
4405 connection_.set_version(QuicVersionMin()); | 4427 connection_.set_version(QuicVersionMin()); |
4406 EXPECT_EQ(QuicVersionMin(), connection_.version()); | 4428 EXPECT_EQ(QuicVersionMin(), connection_.version()); |
4407 | 4429 |
4408 // Pass in available versions which includes a higher mutually supported | 4430 // Pass in available versions which includes a higher mutually supported |
4409 // version. The higher mutually supported version should be selected. | 4431 // version. The higher mutually supported version should be selected. |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4623 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(1); | 4645 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(1); |
4624 // Send some data, which will register the listener to be notified. | 4646 // Send some data, which will register the listener to be notified. |
4625 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener.get()); | 4647 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener.get()); |
4626 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, nullptr); | 4648 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, nullptr); |
4627 | 4649 |
4628 // Process an ACK from the server with a revived packet, which should trigger | 4650 // Process an ACK from the server with a revived packet, which should trigger |
4629 // the callback. | 4651 // the callback. |
4630 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 4652 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
4631 QuicAckFrame frame = InitAckFrame(2); | 4653 QuicAckFrame frame = InitAckFrame(2); |
4632 NackPacket(1, &frame); | 4654 NackPacket(1, &frame); |
4633 frame.revived_packets.insert(1); | 4655 frame.latest_revived_packet = 1; |
4634 ProcessAckPacket(&frame); | 4656 ProcessAckPacket(&frame); |
4635 // If the ack is processed again, the notifier should not be called again. | 4657 // If the ack is processed again, the notifier should not be called again. |
4636 ProcessAckPacket(&frame); | 4658 ProcessAckPacket(&frame); |
4637 } | 4659 } |
4638 | 4660 |
4639 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { | 4661 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { |
4640 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4662 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4641 EXPECT_CALL(visitor_, OnCanWrite()); | 4663 EXPECT_CALL(visitor_, OnCanWrite()); |
4642 | 4664 |
4643 // Create a listener which we expect to be called. | 4665 // Create a listener which we expect to be called. |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4819 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 4841 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
4820 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 4842 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
4821 EXPECT_TRUE(connection_.goaway_sent()); | 4843 EXPECT_TRUE(connection_.goaway_sent()); |
4822 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 4844 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
4823 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 4845 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
4824 } | 4846 } |
4825 | 4847 |
4826 } // namespace | 4848 } // namespace |
4827 } // namespace test | 4849 } // namespace test |
4828 } // namespace net | 4850 } // namespace net |
OLD | NEW |