| 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 383   } | 383   } | 
| 384 | 384 | 
| 385   const std::vector<std::unique_ptr<QuicStreamFrame>>& stream_frames() const { | 385   const std::vector<std::unique_ptr<QuicStreamFrame>>& stream_frames() const { | 
| 386     return framer_.stream_frames(); | 386     return framer_.stream_frames(); | 
| 387   } | 387   } | 
| 388 | 388 | 
| 389   const std::vector<QuicPingFrame>& ping_frames() const { | 389   const std::vector<QuicPingFrame>& ping_frames() const { | 
| 390     return framer_.ping_frames(); | 390     return framer_.ping_frames(); | 
| 391   } | 391   } | 
| 392 | 392 | 
|  | 393   const std::vector<QuicPaddingFrame>& padding_frames() const { | 
|  | 394     return framer_.padding_frames(); | 
|  | 395   } | 
|  | 396 | 
| 393   size_t last_packet_size() { return last_packet_size_; } | 397   size_t last_packet_size() { return last_packet_size_; } | 
| 394 | 398 | 
| 395   const QuicVersionNegotiationPacket* version_negotiation_packet() { | 399   const QuicVersionNegotiationPacket* version_negotiation_packet() { | 
| 396     return framer_.version_negotiation_packet(); | 400     return framer_.version_negotiation_packet(); | 
| 397   } | 401   } | 
| 398 | 402 | 
| 399   void set_is_write_blocked_data_buffered(bool buffered) { | 403   void set_is_write_blocked_data_buffered(bool buffered) { | 
| 400     is_write_blocked_data_buffered_ = buffered; | 404     is_write_blocked_data_buffered_ = buffered; | 
| 401   } | 405   } | 
| 402 | 406 | 
| (...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1769     EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 1773     EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 
| 1770     QuicConnection::ScopedPacketBundler bundler(&connection_, | 1774     QuicConnection::ScopedPacketBundler bundler(&connection_, | 
| 1771                                                 QuicConnection::SEND_ACK); | 1775                                                 QuicConnection::SEND_ACK); | 
| 1772     connection_.SendStreamData3(); | 1776     connection_.SendStreamData3(); | 
| 1773     connection_.SendCryptoStreamData(); | 1777     connection_.SendCryptoStreamData(); | 
| 1774   } | 1778   } | 
| 1775   EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1779   EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 
| 1776   EXPECT_FALSE(connection_.HasQueuedData()); | 1780   EXPECT_FALSE(connection_.HasQueuedData()); | 
| 1777 | 1781 | 
| 1778   // Parse the last packet and ensure it's the crypto stream frame. | 1782   // Parse the last packet and ensure it's the crypto stream frame. | 
| 1779   EXPECT_EQ(1u, writer_->frame_count()); | 1783   EXPECT_EQ(2u, writer_->frame_count()); | 
| 1780   ASSERT_EQ(1u, writer_->stream_frames().size()); | 1784   ASSERT_EQ(1u, writer_->stream_frames().size()); | 
|  | 1785   ASSERT_EQ(1u, writer_->padding_frames().size()); | 
| 1781   EXPECT_EQ(kCryptoStreamId, writer_->stream_frames()[0]->stream_id); | 1786   EXPECT_EQ(kCryptoStreamId, writer_->stream_frames()[0]->stream_id); | 
| 1782 } | 1787 } | 
| 1783 | 1788 | 
| 1784 TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) { | 1789 TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) { | 
| 1785   // Send an ack and two stream frames (one crypto, then one non-crypto) in 2 | 1790   // Send an ack and two stream frames (one crypto, then one non-crypto) in 2 | 
| 1786   // packets by queueing them. | 1791   // packets by queueing them. | 
| 1787   { | 1792   { | 
| 1788     EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 1793     EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 
| 1789     QuicConnection::ScopedPacketBundler bundler(&connection_, | 1794     QuicConnection::ScopedPacketBundler bundler(&connection_, | 
| 1790                                                 QuicConnection::SEND_ACK); | 1795                                                 QuicConnection::SEND_ACK); | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1847   iov[0].iov_len = 2; | 1852   iov[0].iov_len = 2; | 
| 1848   iov[1].iov_base = data + 2; | 1853   iov[1].iov_base = data + 2; | 
| 1849   iov[1].iov_len = 2; | 1854   iov[1].iov_len = 2; | 
| 1850   connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, !kFin, nullptr); | 1855   connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, !kFin, nullptr); | 
| 1851 | 1856 | 
| 1852   EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1857   EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 
| 1853   EXPECT_FALSE(connection_.HasQueuedData()); | 1858   EXPECT_FALSE(connection_.HasQueuedData()); | 
| 1854 | 1859 | 
| 1855   // Parse the last packet and ensure multiple iovector blocks have | 1860   // Parse the last packet and ensure multiple iovector blocks have | 
| 1856   // been packed into a single stream frame from one stream. | 1861   // been packed into a single stream frame from one stream. | 
| 1857   EXPECT_EQ(1u, writer_->frame_count()); | 1862   EXPECT_EQ(2u, writer_->frame_count()); | 
| 1858   EXPECT_EQ(1u, writer_->stream_frames().size()); | 1863   EXPECT_EQ(1u, writer_->stream_frames().size()); | 
|  | 1864   EXPECT_EQ(1u, writer_->padding_frames().size()); | 
| 1859   QuicStreamFrame* frame = writer_->stream_frames()[0].get(); | 1865   QuicStreamFrame* frame = writer_->stream_frames()[0].get(); | 
| 1860   EXPECT_EQ(1u, frame->stream_id); | 1866   EXPECT_EQ(1u, frame->stream_id); | 
| 1861   EXPECT_EQ("ABCD", QuicStringPiece(frame->data_buffer, frame->data_length)); | 1867   EXPECT_EQ("ABCD", QuicStringPiece(frame->data_buffer, frame->data_length)); | 
| 1862 } | 1868 } | 
| 1863 | 1869 | 
| 1864 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { | 1870 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { | 
| 1865   // Try to send two stream frames in 1 packet by using writev. | 1871   // Try to send two stream frames in 1 packet by using writev. | 
| 1866   EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1872   EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 
| 1867 | 1873 | 
| 1868   BlockOnNextWrite(); | 1874   BlockOnNextWrite(); | 
| 1869   char data[] = "ABCD"; | 1875   char data[] = "ABCD"; | 
| 1870   struct iovec iov[2]; | 1876   struct iovec iov[2]; | 
| 1871   iov[0].iov_base = data; | 1877   iov[0].iov_base = data; | 
| 1872   iov[0].iov_len = 2; | 1878   iov[0].iov_len = 2; | 
| 1873   iov[1].iov_base = data + 2; | 1879   iov[1].iov_base = data + 2; | 
| 1874   iov[1].iov_len = 2; | 1880   iov[1].iov_len = 2; | 
| 1875   connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, !kFin, nullptr); | 1881   connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, !kFin, nullptr); | 
| 1876 | 1882 | 
| 1877   EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1883   EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 
| 1878   EXPECT_TRUE(connection_.HasQueuedData()); | 1884   EXPECT_TRUE(connection_.HasQueuedData()); | 
| 1879 | 1885 | 
| 1880   // Unblock the writes and actually send. | 1886   // Unblock the writes and actually send. | 
| 1881   writer_->SetWritable(); | 1887   writer_->SetWritable(); | 
| 1882   connection_.OnCanWrite(); | 1888   connection_.OnCanWrite(); | 
| 1883   EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1889   EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 
| 1884 | 1890 | 
| 1885   // Parse the last packet and ensure it's one stream frame from one stream. | 1891   // Parse the last packet and ensure it's one stream frame from one stream. | 
| 1886   EXPECT_EQ(1u, writer_->frame_count()); | 1892   EXPECT_EQ(2u, writer_->frame_count()); | 
| 1887   EXPECT_EQ(1u, writer_->stream_frames().size()); | 1893   EXPECT_EQ(1u, writer_->stream_frames().size()); | 
|  | 1894   EXPECT_EQ(1u, writer_->padding_frames().size()); | 
| 1888   EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id); | 1895   EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id); | 
| 1889 } | 1896 } | 
| 1890 | 1897 | 
| 1891 TEST_P(QuicConnectionTest, SendingZeroBytes) { | 1898 TEST_P(QuicConnectionTest, SendingZeroBytes) { | 
| 1892   connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); | 1899   connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); | 
| 1893   // Send a zero byte write with a fin using writev. | 1900   // Send a zero byte write with a fin using writev. | 
| 1894   EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1901   EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 
| 1895   QuicIOVector empty_iov(nullptr, 0, 0); | 1902   QuicIOVector empty_iov(nullptr, 0, 0); | 
| 1896   connection_.SendStreamData(kHeadersStreamId, empty_iov, 0, kFin, nullptr); | 1903   connection_.SendStreamData(kHeadersStreamId, empty_iov, 0, kFin, nullptr); | 
| 1897 | 1904 | 
| (...skipping 2270 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4168   EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4175   EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 
| 4169 } | 4176 } | 
| 4170 | 4177 | 
| 4171 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingCryptoPacket) { | 4178 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingCryptoPacket) { | 
| 4172   EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4179   EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 
| 4173   ProcessPacket(1); | 4180   ProcessPacket(1); | 
| 4174   connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, | 4181   connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, | 
| 4175                                        nullptr); | 4182                                        nullptr); | 
| 4176   // Check that ack is bundled with outgoing crypto data. | 4183   // Check that ack is bundled with outgoing crypto data. | 
| 4177   if (GetParam().no_stop_waiting) { | 4184   if (GetParam().no_stop_waiting) { | 
| 4178     EXPECT_EQ(2u, writer_->frame_count()); | 4185     EXPECT_EQ(3u, writer_->frame_count()); | 
| 4179     EXPECT_TRUE(writer_->stop_waiting_frames().empty()); | 4186     EXPECT_TRUE(writer_->stop_waiting_frames().empty()); | 
| 4180   } else { | 4187   } else { | 
| 4181     EXPECT_EQ(3u, writer_->frame_count()); | 4188     EXPECT_EQ(4u, writer_->frame_count()); | 
| 4182     EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 4189     EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 
| 4183   } | 4190   } | 
| 4184   EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4191   EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 
| 4185 } | 4192 } | 
| 4186 | 4193 | 
| 4187 TEST_P(QuicConnectionTest, BlockAndBufferOnFirstCHLOPacketOfTwo) { | 4194 TEST_P(QuicConnectionTest, BlockAndBufferOnFirstCHLOPacketOfTwo) { | 
| 4188   EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4195   EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 
| 4189   ProcessPacket(1); | 4196   ProcessPacket(1); | 
| 4190   BlockOnNextWrite(); | 4197   BlockOnNextWrite(); | 
| 4191   writer_->set_is_write_blocked_data_buffered(true); | 4198   writer_->set_is_write_blocked_data_buffered(true); | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 4204   EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4211   EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 
| 4205   EXPECT_CALL(visitor_, OnCanWrite()) | 4212   EXPECT_CALL(visitor_, OnCanWrite()) | 
| 4206       .WillOnce(IgnoreResult(InvokeWithoutArgs( | 4213       .WillOnce(IgnoreResult(InvokeWithoutArgs( | 
| 4207           &connection_, &TestConnection::SendCryptoStreamData))); | 4214           &connection_, &TestConnection::SendCryptoStreamData))); | 
| 4208   // Process a packet from the crypto stream, which is frame1_'s default. | 4215   // Process a packet from the crypto stream, which is frame1_'s default. | 
| 4209   // Receiving the CHLO as packet 2 first will cause the connection to | 4216   // Receiving the CHLO as packet 2 first will cause the connection to | 
| 4210   // immediately send an ack, due to the packet gap. | 4217   // immediately send an ack, due to the packet gap. | 
| 4211   ProcessPacket(2); | 4218   ProcessPacket(2); | 
| 4212   // Check that ack is sent and that delayed ack alarm is reset. | 4219   // Check that ack is sent and that delayed ack alarm is reset. | 
| 4213   if (GetParam().no_stop_waiting) { | 4220   if (GetParam().no_stop_waiting) { | 
| 4214     EXPECT_EQ(2u, writer_->frame_count()); | 4221     EXPECT_EQ(3u, writer_->frame_count()); | 
| 4215     EXPECT_TRUE(writer_->stop_waiting_frames().empty()); | 4222     EXPECT_TRUE(writer_->stop_waiting_frames().empty()); | 
| 4216   } else { | 4223   } else { | 
| 4217     EXPECT_EQ(3u, writer_->frame_count()); | 4224     EXPECT_EQ(4u, writer_->frame_count()); | 
| 4218     EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 4225     EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 
| 4219   } | 4226   } | 
| 4220   EXPECT_EQ(1u, writer_->stream_frames().size()); | 4227   EXPECT_EQ(1u, writer_->stream_frames().size()); | 
|  | 4228   EXPECT_EQ(1u, writer_->padding_frames().size()); | 
| 4221   EXPECT_FALSE(writer_->ack_frames().empty()); | 4229   EXPECT_FALSE(writer_->ack_frames().empty()); | 
| 4222   EXPECT_EQ(2u, writer_->ack_frames().front().largest_observed); | 4230   EXPECT_EQ(2u, writer_->ack_frames().front().largest_observed); | 
| 4223   EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4231   EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 
| 4224 } | 4232 } | 
| 4225 | 4233 | 
| 4226 TEST_P(QuicConnectionTest, BundleAckForSecondCHLOTwoPacketReject) { | 4234 TEST_P(QuicConnectionTest, BundleAckForSecondCHLOTwoPacketReject) { | 
| 4227   EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4235   EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 
| 4228   EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4236   EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 
| 4229 | 4237 | 
| 4230   // Process two packets from the crypto stream, which is frame1_'s default, | 4238   // Process two packets from the crypto stream, which is frame1_'s default, | 
| 4231   // simulating a 2 packet reject. | 4239   // simulating a 2 packet reject. | 
| 4232   { | 4240   { | 
| 4233     ProcessPacket(1); | 4241     ProcessPacket(1); | 
| 4234     // Send the new CHLO when the REJ is processed. | 4242     // Send the new CHLO when the REJ is processed. | 
| 4235     EXPECT_CALL(visitor_, OnStreamFrame(_)) | 4243     EXPECT_CALL(visitor_, OnStreamFrame(_)) | 
| 4236         .WillOnce(IgnoreResult(InvokeWithoutArgs( | 4244         .WillOnce(IgnoreResult(InvokeWithoutArgs( | 
| 4237             &connection_, &TestConnection::SendCryptoStreamData))); | 4245             &connection_, &TestConnection::SendCryptoStreamData))); | 
| 4238     ProcessDataPacket(2); | 4246     ProcessDataPacket(2); | 
| 4239   } | 4247   } | 
| 4240   // Check that ack is sent and that delayed ack alarm is reset. | 4248   // Check that ack is sent and that delayed ack alarm is reset. | 
| 4241   if (GetParam().no_stop_waiting) { | 4249   if (GetParam().no_stop_waiting) { | 
| 4242     EXPECT_EQ(2u, writer_->frame_count()); | 4250     EXPECT_EQ(3u, writer_->frame_count()); | 
| 4243     EXPECT_TRUE(writer_->stop_waiting_frames().empty()); | 4251     EXPECT_TRUE(writer_->stop_waiting_frames().empty()); | 
| 4244   } else { | 4252   } else { | 
| 4245     EXPECT_EQ(3u, writer_->frame_count()); | 4253     EXPECT_EQ(4u, writer_->frame_count()); | 
| 4246     EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 4254     EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 
| 4247   } | 4255   } | 
| 4248   EXPECT_EQ(1u, writer_->stream_frames().size()); | 4256   EXPECT_EQ(1u, writer_->stream_frames().size()); | 
|  | 4257   EXPECT_EQ(1u, writer_->padding_frames().size()); | 
| 4249   EXPECT_FALSE(writer_->ack_frames().empty()); | 4258   EXPECT_FALSE(writer_->ack_frames().empty()); | 
| 4250   EXPECT_EQ(2u, writer_->ack_frames().front().largest_observed); | 4259   EXPECT_EQ(2u, writer_->ack_frames().front().largest_observed); | 
| 4251   EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4260   EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 
| 4252 } | 4261 } | 
| 4253 | 4262 | 
| 4254 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { | 4263 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { | 
| 4255   EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4264   EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 
| 4256   connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, | 4265   connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, | 
| 4257                                        nullptr); | 4266                                        nullptr); | 
| 4258   connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin, | 4267   connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin, | 
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 5148                             error_details, ConnectionCloseSource::FROM_PEER)); | 5157                             error_details, ConnectionCloseSource::FROM_PEER)); | 
| 5149   connection_.set_perspective(Perspective::IS_CLIENT); | 5158   connection_.set_perspective(Perspective::IS_CLIENT); | 
| 5150   connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, | 5159   connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, | 
| 5151                               error_details, | 5160                               error_details, | 
| 5152                               ConnectionCloseBehavior::SILENT_CLOSE); | 5161                               ConnectionCloseBehavior::SILENT_CLOSE); | 
| 5153 } | 5162 } | 
| 5154 | 5163 | 
| 5155 }  // namespace | 5164 }  // namespace | 
| 5156 }  // namespace test | 5165 }  // namespace test | 
| 5157 }  // namespace net | 5166 }  // namespace net | 
| OLD | NEW | 
|---|