| 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_session.h" | 5 #include "net/quic/quic_session.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 143 |
| 144 QuicDataStream* GetIncomingDataStream(QuicStreamId stream_id) { | 144 QuicDataStream* GetIncomingDataStream(QuicStreamId stream_id) { |
| 145 return QuicSession::GetIncomingDataStream(stream_id); | 145 return QuicSession::GetIncomingDataStream(stream_id); |
| 146 } | 146 } |
| 147 | 147 |
| 148 virtual QuicConsumedData WritevData( | 148 virtual QuicConsumedData WritevData( |
| 149 QuicStreamId id, | 149 QuicStreamId id, |
| 150 const IOVector& data, | 150 const IOVector& data, |
| 151 QuicStreamOffset offset, | 151 QuicStreamOffset offset, |
| 152 bool fin, | 152 bool fin, |
| 153 FecProtection fec_protection, |
| 153 QuicAckNotifier::DelegateInterface* ack_notifier_delegate) OVERRIDE { | 154 QuicAckNotifier::DelegateInterface* ack_notifier_delegate) OVERRIDE { |
| 154 // Always consumes everything. | 155 // Always consumes everything. |
| 155 if (writev_consumes_all_data_) { | 156 if (writev_consumes_all_data_) { |
| 156 return QuicConsumedData(data.TotalBufferSize(), fin); | 157 return QuicConsumedData(data.TotalBufferSize(), fin); |
| 157 } else { | 158 } else { |
| 158 return QuicSession::WritevData(id, data, offset, fin, | 159 return QuicSession::WritevData(id, data, offset, fin, fec_protection, |
| 159 ack_notifier_delegate); | 160 ack_notifier_delegate); |
| 160 } | 161 } |
| 161 } | 162 } |
| 162 | 163 |
| 163 void set_writev_consumes_all_data(bool val) { | 164 void set_writev_consumes_all_data(bool val) { |
| 164 writev_consumes_all_data_ = val; | 165 writev_consumes_all_data_ = val; |
| 165 } | 166 } |
| 166 | 167 |
| 167 QuicConsumedData SendStreamData(QuicStreamId id) { | 168 QuicConsumedData SendStreamData(QuicStreamId id) { |
| 168 return WritevData(id, IOVector(), 0, true, NULL); | 169 return WritevData(id, IOVector(), 0, true, MAY_FEC_PROTECT, NULL); |
| 169 } | 170 } |
| 170 | 171 |
| 171 using QuicSession::PostProcessAfterData; | 172 using QuicSession::PostProcessAfterData; |
| 172 | 173 |
| 173 private: | 174 private: |
| 174 StrictMock<TestCryptoStream> crypto_stream_; | 175 StrictMock<TestCryptoStream> crypto_stream_; |
| 175 | 176 |
| 176 bool writev_consumes_all_data_; | 177 bool writev_consumes_all_data_; |
| 177 }; | 178 }; |
| 178 | 179 |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 TEST_P(QuicSessionTest, IncreasedTimeoutAfterCryptoHandshake) { | 569 TEST_P(QuicSessionTest, IncreasedTimeoutAfterCryptoHandshake) { |
| 569 EXPECT_EQ(kDefaultInitialTimeoutSecs, | 570 EXPECT_EQ(kDefaultInitialTimeoutSecs, |
| 570 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); | 571 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); |
| 571 CryptoHandshakeMessage msg; | 572 CryptoHandshakeMessage msg; |
| 572 session_.GetCryptoStream()->OnHandshakeMessage(msg); | 573 session_.GetCryptoStream()->OnHandshakeMessage(msg); |
| 573 EXPECT_EQ(kDefaultTimeoutSecs, | 574 EXPECT_EQ(kDefaultTimeoutSecs, |
| 574 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); | 575 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); |
| 575 } | 576 } |
| 576 | 577 |
| 577 TEST_P(QuicSessionTest, RstStreamBeforeHeadersDecompressed) { | 578 TEST_P(QuicSessionTest, RstStreamBeforeHeadersDecompressed) { |
| 578 QuicStreamId stream_id1 = kClientDataStreamId1; | |
| 579 // Send two bytes of payload. | 579 // Send two bytes of payload. |
| 580 QuicStreamFrame data1(stream_id1, false, 0, MakeIOVector("HT")); | 580 QuicStreamFrame data1(kClientDataStreamId1, false, 0, MakeIOVector("HT")); |
| 581 vector<QuicStreamFrame> frames; | 581 vector<QuicStreamFrame> frames; |
| 582 frames.push_back(data1); | 582 frames.push_back(data1); |
| 583 session_.OnStreamFrames(frames); | 583 session_.OnStreamFrames(frames); |
| 584 EXPECT_EQ(1u, session_.GetNumOpenStreams()); | 584 EXPECT_EQ(1u, session_.GetNumOpenStreams()); |
| 585 | 585 |
| 586 QuicRstStreamFrame rst1(stream_id1, QUIC_STREAM_NO_ERROR, 0); | 586 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0); |
| 587 session_.OnRstStream(rst1); | 587 session_.OnRstStream(rst1); |
| 588 EXPECT_EQ(0u, session_.GetNumOpenStreams()); | 588 EXPECT_EQ(0u, session_.GetNumOpenStreams()); |
| 589 // Connection should remain alive. | 589 // Connection should remain alive. |
| 590 EXPECT_TRUE(connection_->connected()); | 590 EXPECT_TRUE(connection_->connected()); |
| 591 } | 591 } |
| 592 | 592 |
| 593 TEST_P(QuicSessionTest, MultipleRstStreamsCauseSingleConnectionClose) { | 593 TEST_P(QuicSessionTest, MultipleRstStreamsCauseSingleConnectionClose) { |
| 594 // If multiple invalid reset stream frames arrive in a single packet, this | 594 // If multiple invalid reset stream frames arrive in a single packet, this |
| 595 // should trigger a connection close. However there is no need to send | 595 // should trigger a connection close. However there is no need to send |
| 596 // multiple connection close frames. | 596 // multiple connection close frames. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 session_.config()->ToHandshakeMessage(&msg); | 661 session_.config()->ToHandshakeMessage(&msg); |
| 662 const QuicErrorCode error = | 662 const QuicErrorCode error = |
| 663 session_.config()->ProcessPeerHello(msg, CLIENT, &error_details); | 663 session_.config()->ProcessPeerHello(msg, CLIENT, &error_details); |
| 664 EXPECT_EQ(QUIC_NO_ERROR, error); | 664 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 665 | 665 |
| 666 EXPECT_CALL(*connection_, | 666 EXPECT_CALL(*connection_, |
| 667 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); | 667 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); |
| 668 session_.OnConfigNegotiated(); | 668 session_.OnConfigNegotiated(); |
| 669 } | 669 } |
| 670 | 670 |
| 671 |
| 671 TEST_P(QuicSessionTest, InvalidFlowControlWindow) { | 672 TEST_P(QuicSessionTest, InvalidFlowControlWindow) { |
| 673 // Test that an attempt to create a QuicSession with an invalid (< default) |
| 674 // flow control window results in a QuicSession using the default. |
| 672 QuicConnection* connection = | 675 QuicConnection* connection = |
| 673 new MockConnection(true, SupportedVersions(GetParam())); | 676 new MockConnection(true, SupportedVersions(GetParam())); |
| 674 | 677 |
| 675 const uint32 kSmallerFlowControlWindow = kDefaultFlowControlSendWindow - 1; | 678 const uint32 kSmallerFlowControlWindow = kDefaultFlowControlSendWindow - 1; |
| 676 TestSession session(connection, kSmallerFlowControlWindow); | 679 TestSession session(connection, kSmallerFlowControlWindow); |
| 677 | 680 |
| 678 EXPECT_EQ(kDefaultFlowControlSendWindow, | 681 EXPECT_EQ(kDefaultFlowControlSendWindow, |
| 679 session.max_flow_control_receive_window_bytes()); | 682 session.max_flow_control_receive_window_bytes()); |
| 680 } | 683 } |
| 681 | 684 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 821 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
| 819 kByteOffset); | 822 kByteOffset); |
| 820 session_.OnRstStream(rst_frame); | 823 session_.OnRstStream(rst_frame); |
| 821 | 824 |
| 822 EXPECT_EQ(kInitialConnectionBytesConsumed + kByteOffset, | 825 EXPECT_EQ(kInitialConnectionBytesConsumed + kByteOffset, |
| 823 session_.flow_controller()->bytes_consumed()); | 826 session_.flow_controller()->bytes_consumed()); |
| 824 EXPECT_EQ(kInitialConnectionHighestReceivedOffset + kByteOffset, | 827 EXPECT_EQ(kInitialConnectionHighestReceivedOffset + kByteOffset, |
| 825 session_.flow_controller()->highest_received_byte_offset()); | 828 session_.flow_controller()->highest_received_byte_offset()); |
| 826 } | 829 } |
| 827 | 830 |
| 831 TEST_P(QuicSessionTest, FlowControlWithInvalidFinalOffset) { |
| 832 // Test that if we receive a stream RST with a highest byte offset that |
| 833 // violates flow control, that we close the connection. |
| 834 if (version() < QUIC_VERSION_17) { |
| 835 return; |
| 836 } |
| 837 FLAGS_enable_quic_stream_flow_control_2 = true; |
| 838 FLAGS_enable_quic_connection_flow_control = true; |
| 839 |
| 840 const uint64 kLargeOffset = kInitialFlowControlWindowForTest + 1; |
| 841 EXPECT_CALL(*connection_, |
| 842 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) |
| 843 .Times(2); |
| 844 |
| 845 // Check that stream frame + FIN results in connection close. |
| 846 TestStream* stream = session_.CreateOutgoingDataStream(); |
| 847 stream->Reset(QUIC_STREAM_CANCELLED); |
| 848 QuicStreamFrame frame(stream->id(), true, kLargeOffset, IOVector()); |
| 849 vector<QuicStreamFrame> frames; |
| 850 frames.push_back(frame); |
| 851 session_.OnStreamFrames(frames); |
| 852 |
| 853 // Check that RST results in connection close. |
| 854 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
| 855 kLargeOffset); |
| 856 session_.OnRstStream(rst_frame); |
| 857 } |
| 858 |
| 828 TEST_P(QuicSessionTest, VersionNegotiationDisablesFlowControl) { | 859 TEST_P(QuicSessionTest, VersionNegotiationDisablesFlowControl) { |
| 829 ValueRestore<bool> old_stream_flag( | 860 ValueRestore<bool> old_stream_flag( |
| 830 &FLAGS_enable_quic_stream_flow_control_2, true); | 861 &FLAGS_enable_quic_stream_flow_control_2, true); |
| 831 ValueRestore<bool> old_connection_flag( | 862 ValueRestore<bool> old_connection_flag( |
| 832 &FLAGS_enable_quic_connection_flow_control, true); | 863 &FLAGS_enable_quic_connection_flow_control, true); |
| 833 if (version() < QUIC_VERSION_19) { | 864 if (version() < QUIC_VERSION_19) { |
| 834 return; | 865 return; |
| 835 } | 866 } |
| 836 | 867 |
| 837 // Test that after successful version negotiation, flow control is disabled | 868 // Test that after successful version negotiation, flow control is disabled |
| (...skipping 12 matching lines...) Expand all Loading... |
| 850 | 881 |
| 851 // Version 16 means all flow control is disabled. | 882 // Version 16 means all flow control is disabled. |
| 852 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); | 883 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); |
| 853 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); | 884 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); |
| 854 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); | 885 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); |
| 855 } | 886 } |
| 856 | 887 |
| 857 } // namespace | 888 } // namespace |
| 858 } // namespace test | 889 } // namespace test |
| 859 } // namespace net | 890 } // namespace net |
| OLD | NEW |