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