| 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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 QuicFrame(new QuicStreamFrame())); | 509 QuicFrame(new QuicStreamFrame())); |
| 510 } | 510 } |
| 511 OnSerializedPacket(&serialized_packet); | 511 OnSerializedPacket(&serialized_packet); |
| 512 } | 512 } |
| 513 | 513 |
| 514 QuicConsumedData SendStreamDataWithString( | 514 QuicConsumedData SendStreamDataWithString( |
| 515 QuicStreamId id, | 515 QuicStreamId id, |
| 516 StringPiece data, | 516 StringPiece data, |
| 517 QuicStreamOffset offset, | 517 QuicStreamOffset offset, |
| 518 bool fin, | 518 bool fin, |
| 519 scoped_refptr<QuicAckListenerInterface> listener) { | 519 QuicReferenceCountedPointer<QuicAckListenerInterface> listener) { |
| 520 if (id != kCryptoStreamId && this->encryption_level() == ENCRYPTION_NONE) { | 520 if (id != kCryptoStreamId && this->encryption_level() == ENCRYPTION_NONE) { |
| 521 this->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); | 521 this->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); |
| 522 } | 522 } |
| 523 struct iovec iov; | 523 struct iovec iov; |
| 524 QuicIOVector data_iov(MakeIOVector(data, &iov)); | 524 QuicIOVector data_iov(MakeIOVector(data, &iov)); |
| 525 return QuicConnection::SendStreamData(id, data_iov, offset, fin, | 525 return QuicConnection::SendStreamData(id, data_iov, offset, fin, |
| 526 std::move(listener)); | 526 std::move(listener)); |
| 527 } | 527 } |
| 528 | 528 |
| 529 QuicConsumedData SendStreamData3() { | 529 QuicConsumedData SendStreamData3() { |
| (...skipping 4076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4606 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 4606 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 4607 EXPECT_TRUE(writer_->IsWriteBlocked()); | 4607 EXPECT_TRUE(writer_->IsWriteBlocked()); |
| 4608 TriggerConnectionClose(); | 4608 TriggerConnectionClose(); |
| 4609 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 4609 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 4610 } | 4610 } |
| 4611 | 4611 |
| 4612 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { | 4612 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { |
| 4613 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4613 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 4614 | 4614 |
| 4615 // Create a listener which we expect to be called. | 4615 // Create a listener which we expect to be called. |
| 4616 scoped_refptr<MockAckListener> listener(new MockAckListener); | 4616 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener); |
| 4617 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(1); | 4617 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(1); |
| 4618 | 4618 |
| 4619 // Send some data, which will register the listener to be notified. | 4619 // Send some data, which will register the listener to be notified. |
| 4620 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener); | 4620 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener); |
| 4621 | 4621 |
| 4622 // Process an ACK from the server which should trigger the callback. | 4622 // Process an ACK from the server which should trigger the callback. |
| 4623 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); | 4623 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); |
| 4624 QuicAckFrame frame = InitAckFrame(1); | 4624 QuicAckFrame frame = InitAckFrame(1); |
| 4625 ProcessAckPacket(&frame); | 4625 ProcessAckPacket(&frame); |
| 4626 } | 4626 } |
| 4627 | 4627 |
| 4628 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { | 4628 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { |
| 4629 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4629 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 4630 | 4630 |
| 4631 // Create a listener which we don't expect to be called. | 4631 // Create a listener which we don't expect to be called. |
| 4632 scoped_refptr<MockAckListener> listener(new MockAckListener); | 4632 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener); |
| 4633 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(0); | 4633 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(0); |
| 4634 | 4634 |
| 4635 // Send some data, which will register the listener to be notified. This will | 4635 // Send some data, which will register the listener to be notified. This will |
| 4636 // not be ACKed and so the listener should never be called. | 4636 // not be ACKed and so the listener should never be called. |
| 4637 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener); | 4637 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener); |
| 4638 | 4638 |
| 4639 // Send some other data which we will ACK. | 4639 // Send some other data which we will ACK. |
| 4640 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); | 4640 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); |
| 4641 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, nullptr); | 4641 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, nullptr); |
| 4642 | 4642 |
| 4643 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 | 4643 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 |
| 4644 // which we registered to be notified about. | 4644 // which we registered to be notified about. |
| 4645 QuicAckFrame frame = InitAckFrame(3); | 4645 QuicAckFrame frame = InitAckFrame(3); |
| 4646 NackPacket(1, &frame); | 4646 NackPacket(1, &frame); |
| 4647 SendAlgorithmInterface::CongestionVector lost_packets; | 4647 SendAlgorithmInterface::CongestionVector lost_packets; |
| 4648 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); | 4648 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); |
| 4649 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) | 4649 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) |
| 4650 .WillOnce(SetArgPointee<4>(lost_packets)); | 4650 .WillOnce(SetArgPointee<4>(lost_packets)); |
| 4651 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); | 4651 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); |
| 4652 ProcessAckPacket(&frame); | 4652 ProcessAckPacket(&frame); |
| 4653 } | 4653 } |
| 4654 | 4654 |
| 4655 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { | 4655 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { |
| 4656 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4656 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 4657 | 4657 |
| 4658 // Create a listener which we expect to be called. | 4658 // Create a listener which we expect to be called. |
| 4659 scoped_refptr<MockAckListener> listener(new MockAckListener); | 4659 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener); |
| 4660 EXPECT_CALL(*listener, OnPacketRetransmitted(3)).Times(1); | 4660 EXPECT_CALL(*listener, OnPacketRetransmitted(3)).Times(1); |
| 4661 EXPECT_CALL(*listener, OnPacketAcked(3, _)).Times(1); | 4661 EXPECT_CALL(*listener, OnPacketAcked(3, _)).Times(1); |
| 4662 | 4662 |
| 4663 // Send four packets, and register to be notified on ACK of packet 2. | 4663 // Send four packets, and register to be notified on ACK of packet 2. |
| 4664 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); | 4664 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); |
| 4665 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, listener); | 4665 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, listener); |
| 4666 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); | 4666 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); |
| 4667 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); | 4667 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); |
| 4668 | 4668 |
| 4669 // Now we receive ACK for packets 1, 3, and 4 and lose 2. | 4669 // Now we receive ACK for packets 1, 3, and 4 and lose 2. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4685 ProcessAckPacket(&second_ack_frame); | 4685 ProcessAckPacket(&second_ack_frame); |
| 4686 } | 4686 } |
| 4687 | 4687 |
| 4688 // AckNotifierCallback is triggered by the ack of a packet that timed | 4688 // AckNotifierCallback is triggered by the ack of a packet that timed |
| 4689 // out and was retransmitted, even though the retransmission has a | 4689 // out and was retransmitted, even though the retransmission has a |
| 4690 // different packet number. | 4690 // different packet number. |
| 4691 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { | 4691 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { |
| 4692 connection_.SetMaxTailLossProbes(kDefaultPathId, 0); | 4692 connection_.SetMaxTailLossProbes(kDefaultPathId, 0); |
| 4693 | 4693 |
| 4694 // Create a listener which we expect to be called. | 4694 // Create a listener which we expect to be called. |
| 4695 scoped_refptr<MockAckListener> listener(new StrictMock<MockAckListener>); | 4695 QuicReferenceCountedPointer<MockAckListener> listener( |
| 4696 new StrictMock<MockAckListener>); |
| 4696 | 4697 |
| 4697 QuicTime default_retransmission_time = | 4698 QuicTime default_retransmission_time = |
| 4698 clock_.ApproximateNow() + DefaultRetransmissionTime(); | 4699 clock_.ApproximateNow() + DefaultRetransmissionTime(); |
| 4699 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, listener); | 4700 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, listener); |
| 4700 EXPECT_EQ(1u, stop_waiting()->least_unacked); | 4701 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
| 4701 | 4702 |
| 4702 EXPECT_EQ(1u, writer_->header().packet_number); | 4703 EXPECT_EQ(1u, writer_->header().packet_number); |
| 4703 EXPECT_EQ(default_retransmission_time, | 4704 EXPECT_EQ(default_retransmission_time, |
| 4704 connection_.GetRetransmissionAlarm()->deadline()); | 4705 connection_.GetRetransmissionAlarm()->deadline()); |
| 4705 // Simulate the retransmission alarm firing. | 4706 // Simulate the retransmission alarm firing. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4722 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); | 4723 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); |
| 4723 QuicAckFrame second_ack_frame = InitAckFrame(2); | 4724 QuicAckFrame second_ack_frame = InitAckFrame(2); |
| 4724 ProcessAckPacket(&second_ack_frame); | 4725 ProcessAckPacket(&second_ack_frame); |
| 4725 } | 4726 } |
| 4726 | 4727 |
| 4727 // AckNotifierCallback is triggered by the ack of a packet that was | 4728 // AckNotifierCallback is triggered by the ack of a packet that was |
| 4728 // previously nacked, even though the retransmission has a different | 4729 // previously nacked, even though the retransmission has a different |
| 4729 // packet number. | 4730 // packet number. |
| 4730 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckOfNackedPacket) { | 4731 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckOfNackedPacket) { |
| 4731 // Create a listener which we expect to be called. | 4732 // Create a listener which we expect to be called. |
| 4732 scoped_refptr<MockAckListener> listener(new StrictMock<MockAckListener>); | 4733 QuicReferenceCountedPointer<MockAckListener> listener( |
| 4734 new StrictMock<MockAckListener>()); |
| 4733 | 4735 |
| 4734 // Send four packets, and register to be notified on ACK of packet 2. | 4736 // Send four packets, and register to be notified on ACK of packet 2. |
| 4735 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); | 4737 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); |
| 4736 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, listener); | 4738 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, listener); |
| 4737 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); | 4739 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); |
| 4738 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); | 4740 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); |
| 4739 | 4741 |
| 4740 // Now we receive ACK for packets 1, 3, and 4 and lose 2. | 4742 // Now we receive ACK for packets 1, 3, and 4 and lose 2. |
| 4741 QuicAckFrame frame = InitAckFrame(4); | 4743 QuicAckFrame frame = InitAckFrame(4); |
| 4742 NackPacket(2, &frame); | 4744 NackPacket(2, &frame); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4819 | 4821 |
| 4820 // Ensure that this has caused the ACK alarm to be set. | 4822 // Ensure that this has caused the ACK alarm to be set. |
| 4821 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_); | 4823 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_); |
| 4822 EXPECT_TRUE(ack_alarm->IsSet()); | 4824 EXPECT_TRUE(ack_alarm->IsSet()); |
| 4823 } | 4825 } |
| 4824 | 4826 |
| 4825 TEST_P(QuicConnectionTest, NoDataNoFin) { | 4827 TEST_P(QuicConnectionTest, NoDataNoFin) { |
| 4826 // Make sure that a call to SendStreamWithData, with no data and no FIN, does | 4828 // Make sure that a call to SendStreamWithData, with no data and no FIN, does |
| 4827 // not result in a QuicAckNotifier being used-after-free (fail under ASAN). | 4829 // not result in a QuicAckNotifier being used-after-free (fail under ASAN). |
| 4828 // Regression test for b/18594622 | 4830 // Regression test for b/18594622 |
| 4829 scoped_refptr<MockAckListener> listener(new MockAckListener); | 4831 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener); |
| 4830 EXPECT_QUIC_BUG( | 4832 EXPECT_QUIC_BUG( |
| 4831 connection_.SendStreamDataWithString(3, "", 0, !kFin, listener), | 4833 connection_.SendStreamDataWithString(3, "", 0, !kFin, listener), |
| 4832 "Attempt to send empty stream frame"); | 4834 "Attempt to send empty stream frame"); |
| 4833 } | 4835 } |
| 4834 | 4836 |
| 4835 TEST_P(QuicConnectionTest, DoNotSendGoAwayTwice) { | 4837 TEST_P(QuicConnectionTest, DoNotSendGoAwayTwice) { |
| 4836 EXPECT_FALSE(connection_.goaway_sent()); | 4838 EXPECT_FALSE(connection_.goaway_sent()); |
| 4837 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 4839 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 4838 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 4840 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
| 4839 EXPECT_TRUE(connection_.goaway_sent()); | 4841 EXPECT_TRUE(connection_.goaway_sent()); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5114 error_details, ConnectionCloseSource::FROM_PEER)); | 5116 error_details, ConnectionCloseSource::FROM_PEER)); |
| 5115 connection_.set_perspective(Perspective::IS_CLIENT); | 5117 connection_.set_perspective(Perspective::IS_CLIENT); |
| 5116 connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, | 5118 connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, |
| 5117 error_details, | 5119 error_details, |
| 5118 ConnectionCloseBehavior::SILENT_CLOSE); | 5120 ConnectionCloseBehavior::SILENT_CLOSE); |
| 5119 } | 5121 } |
| 5120 | 5122 |
| 5121 } // namespace | 5123 } // namespace |
| 5122 } // namespace test | 5124 } // namespace test |
| 5123 } // namespace net | 5125 } // namespace net |
| OLD | NEW |