| 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 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 TestStream* CreateOutgoingDynamicStream(SpdyPriority priority) override { | 134 TestStream* CreateOutgoingDynamicStream(SpdyPriority priority) override { |
| 135 TestStream* stream = new TestStream(GetNextOutgoingStreamId(), this); | 135 TestStream* stream = new TestStream(GetNextOutgoingStreamId(), this); |
| 136 stream->SetPriority(priority); | 136 stream->SetPriority(priority); |
| 137 ActivateStream(stream); | 137 ActivateStream(stream); |
| 138 return stream; | 138 return stream; |
| 139 } | 139 } |
| 140 | 140 |
| 141 TestStream* CreateIncomingDynamicStream(QuicStreamId id) override { | 141 TestStream* CreateIncomingDynamicStream(QuicStreamId id) override { |
| 142 // Enforce the limit on the number of open streams. | 142 // Enforce the limit on the number of open streams. |
| 143 if (GetNumOpenIncomingStreams() + 1 > get_max_open_streams()) { | 143 if (GetNumOpenIncomingStreams() + 1 > get_max_open_streams()) { |
| 144 connection()->SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS); | 144 connection()->SendConnectionCloseWithDetails(QUIC_TOO_MANY_OPEN_STREAMS, |
| 145 "Too many streams!"); |
| 145 return nullptr; | 146 return nullptr; |
| 146 } else { | 147 } else { |
| 147 return new TestStream(id, this); | 148 return new TestStream(id, this); |
| 148 } | 149 } |
| 149 } | 150 } |
| 150 | 151 |
| 151 bool IsClosedStream(QuicStreamId id) { | 152 bool IsClosedStream(QuicStreamId id) { |
| 152 return QuicSession::IsClosedStream(id); | 153 return QuicSession::IsClosedStream(id); |
| 153 } | 154 } |
| 154 | 155 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 session_.GetOrCreateDynamicStream(stream_id2 + 4); | 335 session_.GetOrCreateDynamicStream(stream_id2 + 4); |
| 335 CheckClosedStreams(); | 336 CheckClosedStreams(); |
| 336 // Close one, but make sure the other is still not closed | 337 // Close one, but make sure the other is still not closed |
| 337 CloseStream(stream3->id()); | 338 CloseStream(stream3->id()); |
| 338 CheckClosedStreams(); | 339 CheckClosedStreams(); |
| 339 } | 340 } |
| 340 | 341 |
| 341 TEST_P(QuicSessionTestServer, MaximumAvailableOpenedStreams) { | 342 TEST_P(QuicSessionTestServer, MaximumAvailableOpenedStreams) { |
| 342 QuicStreamId stream_id = kClientDataStreamId1; | 343 QuicStreamId stream_id = kClientDataStreamId1; |
| 343 session_.GetOrCreateDynamicStream(stream_id); | 344 session_.GetOrCreateDynamicStream(stream_id); |
| 344 EXPECT_CALL(*connection_, SendConnectionClose(_)).Times(0); | 345 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0); |
| 345 EXPECT_NE(nullptr, | 346 EXPECT_NE(nullptr, |
| 346 session_.GetOrCreateDynamicStream( | 347 session_.GetOrCreateDynamicStream( |
| 347 stream_id + 2 * (session_.get_max_open_streams() - 1))); | 348 stream_id + 2 * (session_.get_max_open_streams() - 1))); |
| 348 } | 349 } |
| 349 | 350 |
| 350 TEST_P(QuicSessionTestServer, TooManyAvailableStreams) { | 351 TEST_P(QuicSessionTestServer, TooManyAvailableStreams) { |
| 351 QuicStreamId stream_id1 = kClientDataStreamId1; | 352 QuicStreamId stream_id1 = kClientDataStreamId1; |
| 352 QuicStreamId stream_id2; | 353 QuicStreamId stream_id2; |
| 353 EXPECT_NE(nullptr, session_.GetOrCreateDynamicStream(stream_id1)); | 354 EXPECT_NE(nullptr, session_.GetOrCreateDynamicStream(stream_id1)); |
| 354 // A stream ID which is too large to create. | 355 // A stream ID which is too large to create. |
| 355 stream_id2 = stream_id1 + 2 * session_.get_max_available_streams() + 4; | 356 stream_id2 = stream_id1 + 2 * session_.get_max_available_streams() + 4; |
| 356 EXPECT_CALL(*connection_, | 357 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
| 357 SendConnectionClose(QUIC_TOO_MANY_AVAILABLE_STREAMS)); | 358 QUIC_TOO_MANY_AVAILABLE_STREAMS, _)); |
| 358 EXPECT_EQ(nullptr, session_.GetOrCreateDynamicStream(stream_id2)); | 359 EXPECT_EQ(nullptr, session_.GetOrCreateDynamicStream(stream_id2)); |
| 359 } | 360 } |
| 360 | 361 |
| 361 TEST_P(QuicSessionTestServer, ManyAvailableStreams) { | 362 TEST_P(QuicSessionTestServer, ManyAvailableStreams) { |
| 362 // When max_open_streams_ is 200, should be able to create 200 streams | 363 // When max_open_streams_ is 200, should be able to create 200 streams |
| 363 // out-of-order, that is, creating the one with the largest stream ID first. | 364 // out-of-order, that is, creating the one with the largest stream ID first. |
| 364 QuicSessionPeer::SetMaxOpenStreams(&session_, 200); | 365 QuicSessionPeer::SetMaxOpenStreams(&session_, 200); |
| 365 QuicStreamId stream_id = kClientDataStreamId1; | 366 QuicStreamId stream_id = kClientDataStreamId1; |
| 366 // Create one stream. | 367 // Create one stream. |
| 367 session_.GetOrCreateDynamicStream(stream_id); | 368 session_.GetOrCreateDynamicStream(stream_id); |
| 368 EXPECT_CALL(*connection_, SendConnectionClose(_)).Times(0); | 369 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0); |
| 369 // Create the largest stream ID of a threatened total of 200 streams. | 370 // Create the largest stream ID of a threatened total of 200 streams. |
| 370 session_.GetOrCreateDynamicStream(stream_id + 2 * (200 - 1)); | 371 session_.GetOrCreateDynamicStream(stream_id + 2 * (200 - 1)); |
| 371 } | 372 } |
| 372 | 373 |
| 373 TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) { | 374 TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) { |
| 374 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 375 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority); |
| 375 QuicStreamId closed_stream_id = stream2->id(); | 376 QuicStreamId closed_stream_id = stream2->id(); |
| 376 // Close the stream. | 377 // Close the stream. |
| 377 EXPECT_CALL(*connection_, SendRstStream(closed_stream_id, _, _)); | 378 EXPECT_CALL(*connection_, SendRstStream(closed_stream_id, _, _)); |
| 378 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD); | 379 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD); |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 // should trigger a connection close. However there is no need to send | 731 // should trigger a connection close. However there is no need to send |
| 731 // multiple connection close frames. | 732 // multiple connection close frames. |
| 732 | 733 |
| 733 // Create valid stream. | 734 // Create valid stream. |
| 734 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); | 735 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); |
| 735 session_.OnStreamFrame(data1); | 736 session_.OnStreamFrame(data1); |
| 736 EXPECT_EQ(1u, session_.GetNumOpenIncomingStreams()); | 737 EXPECT_EQ(1u, session_.GetNumOpenIncomingStreams()); |
| 737 | 738 |
| 738 // Process first invalid stream reset, resulting in the connection being | 739 // Process first invalid stream reset, resulting in the connection being |
| 739 // closed. | 740 // closed. |
| 740 EXPECT_CALL(*connection_, | 741 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
| 741 SendConnectionClose(QUIC_TOO_MANY_AVAILABLE_STREAMS)); | 742 QUIC_TOO_MANY_AVAILABLE_STREAMS, _)); |
| 742 | 743 |
| 743 const QuicStreamId kLargeInvalidStreamId = 99999999; | 744 const QuicStreamId kLargeInvalidStreamId = 99999999; |
| 744 QuicRstStreamFrame rst1(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); | 745 QuicRstStreamFrame rst1(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); |
| 745 session_.OnRstStream(rst1); | 746 session_.OnRstStream(rst1); |
| 746 QuicConnectionPeer::CloseConnection(connection_); | 747 QuicConnectionPeer::CloseConnection(connection_); |
| 747 | 748 |
| 748 // Processing of second invalid stream reset should not result in the | 749 // Processing of second invalid stream reset should not result in the |
| 749 // connection being closed for a second time. | 750 // connection being closed for a second time. |
| 750 QuicRstStreamFrame rst2(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); | 751 QuicRstStreamFrame rst2(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); |
| 751 session_.OnRstStream(rst2); | 752 session_.OnRstStream(rst2); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 session_.flow_controller()->highest_received_byte_offset()); | 1011 session_.flow_controller()->highest_received_byte_offset()); |
| 1011 } | 1012 } |
| 1012 | 1013 |
| 1013 TEST_P(QuicSessionTestServer, InvalidStreamFlowControlWindowInHandshake) { | 1014 TEST_P(QuicSessionTestServer, InvalidStreamFlowControlWindowInHandshake) { |
| 1014 // Test that receipt of an invalid (< default) stream flow control window from | 1015 // Test that receipt of an invalid (< default) stream flow control window from |
| 1015 // the peer results in the connection being torn down. | 1016 // the peer results in the connection being torn down. |
| 1016 const uint32 kInvalidWindow = kMinimumFlowControlSendWindow - 1; | 1017 const uint32 kInvalidWindow = kMinimumFlowControlSendWindow - 1; |
| 1017 QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_.config(), | 1018 QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_.config(), |
| 1018 kInvalidWindow); | 1019 kInvalidWindow); |
| 1019 | 1020 |
| 1020 EXPECT_CALL(*connection_, | 1021 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
| 1021 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); | 1022 QUIC_FLOW_CONTROL_INVALID_WINDOW, _)); |
| 1022 session_.OnConfigNegotiated(); | 1023 session_.OnConfigNegotiated(); |
| 1023 } | 1024 } |
| 1024 | 1025 |
| 1025 TEST_P(QuicSessionTestServer, InvalidSessionFlowControlWindowInHandshake) { | 1026 TEST_P(QuicSessionTestServer, InvalidSessionFlowControlWindowInHandshake) { |
| 1026 // Test that receipt of an invalid (< default) session flow control window | 1027 // Test that receipt of an invalid (< default) session flow control window |
| 1027 // from the peer results in the connection being torn down. | 1028 // from the peer results in the connection being torn down. |
| 1028 const uint32 kInvalidWindow = kMinimumFlowControlSendWindow - 1; | 1029 const uint32 kInvalidWindow = kMinimumFlowControlSendWindow - 1; |
| 1029 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow(session_.config(), | 1030 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow(session_.config(), |
| 1030 kInvalidWindow); | 1031 kInvalidWindow); |
| 1031 | 1032 |
| 1032 EXPECT_CALL(*connection_, | 1033 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
| 1033 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); | 1034 QUIC_FLOW_CONTROL_INVALID_WINDOW, _)); |
| 1034 session_.OnConfigNegotiated(); | 1035 session_.OnConfigNegotiated(); |
| 1035 } | 1036 } |
| 1036 | 1037 |
| 1037 TEST_P(QuicSessionTestServer, FlowControlWithInvalidFinalOffset) { | 1038 TEST_P(QuicSessionTestServer, FlowControlWithInvalidFinalOffset) { |
| 1038 // Test that if we receive a stream RST with a highest byte offset that | 1039 // Test that if we receive a stream RST with a highest byte offset that |
| 1039 // violates flow control, that we close the connection. | 1040 // violates flow control, that we close the connection. |
| 1040 const uint64 kLargeOffset = kInitialSessionFlowControlWindowForTest + 1; | 1041 const uint64 kLargeOffset = kInitialSessionFlowControlWindowForTest + 1; |
| 1041 EXPECT_CALL(*connection_, | 1042 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
| 1042 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) | 1043 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _)) |
| 1043 .Times(2); | 1044 .Times(2); |
| 1044 | 1045 |
| 1045 // Check that stream frame + FIN results in connection close. | 1046 // Check that stream frame + FIN results in connection close. |
| 1046 TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 1047 TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); |
| 1047 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); | 1048 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); |
| 1048 stream->Reset(QUIC_STREAM_CANCELLED); | 1049 stream->Reset(QUIC_STREAM_CANCELLED); |
| 1049 QuicStreamFrame frame(stream->id(), true, kLargeOffset, StringPiece()); | 1050 QuicStreamFrame frame(stream->id(), true, kLargeOffset, StringPiece()); |
| 1050 session_.OnStreamFrame(frame); | 1051 session_.OnStreamFrame(frame); |
| 1051 | 1052 |
| 1052 // Check that RST results in connection close. | 1053 // Check that RST results in connection close. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 // FIN or a RST_STREAM from the client. | 1091 // FIN or a RST_STREAM from the client. |
| 1091 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { | 1092 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { |
| 1092 QuicStreamFrame data1(i, false, 0, StringPiece("HT")); | 1093 QuicStreamFrame data1(i, false, 0, StringPiece("HT")); |
| 1093 session_.OnStreamFrame(data1); | 1094 session_.OnStreamFrame(data1); |
| 1094 // EXPECT_EQ(1u, session_.GetNumOpenStreams()); | 1095 // EXPECT_EQ(1u, session_.GetNumOpenStreams()); |
| 1095 EXPECT_CALL(*connection_, SendRstStream(i, _, _)); | 1096 EXPECT_CALL(*connection_, SendRstStream(i, _, _)); |
| 1096 session_.CloseStream(i); | 1097 session_.CloseStream(i); |
| 1097 } | 1098 } |
| 1098 | 1099 |
| 1099 if (GetParam() <= QUIC_VERSION_27) { | 1100 if (GetParam() <= QUIC_VERSION_27) { |
| 1100 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)); | 1101 EXPECT_CALL(*connection_, |
| 1102 SendConnectionCloseWithDetails(QUIC_TOO_MANY_OPEN_STREAMS, _)); |
| 1101 EXPECT_CALL(*connection_, SendRstStream(kFinalStreamId, _, _)).Times(0); | 1103 EXPECT_CALL(*connection_, SendRstStream(kFinalStreamId, _, _)).Times(0); |
| 1102 } else { | 1104 } else { |
| 1103 EXPECT_CALL(*connection_, | 1105 EXPECT_CALL(*connection_, |
| 1104 SendRstStream(kFinalStreamId, QUIC_REFUSED_STREAM, _)) | 1106 SendRstStream(kFinalStreamId, QUIC_REFUSED_STREAM, _)) |
| 1105 .Times(1); | 1107 .Times(1); |
| 1106 } | 1108 } |
| 1107 // Create one more data streams to exceed limit of open stream. | 1109 // Create one more data streams to exceed limit of open stream. |
| 1108 QuicStreamFrame data1(kFinalStreamId, false, 0, StringPiece("HT")); | 1110 QuicStreamFrame data1(kFinalStreamId, false, 0, StringPiece("HT")); |
| 1109 session_.OnStreamFrame(data1); | 1111 session_.OnStreamFrame(data1); |
| 1110 | 1112 |
| 1111 // Called after any new data is received by the session, and triggers the | 1113 // Called after any new data is received by the session, and triggers the |
| 1112 // call to close the connection. | 1114 // call to close the connection. |
| 1113 session_.PostProcessAfterData(); | 1115 session_.PostProcessAfterData(); |
| 1114 } | 1116 } |
| 1115 | 1117 |
| 1116 TEST_P(QuicSessionTestServer, DrainingStreamsDoNotCountAsOpened) { | 1118 TEST_P(QuicSessionTestServer, DrainingStreamsDoNotCountAsOpened) { |
| 1117 // Verify that a draining stream (which has received a FIN but not consumed | 1119 // Verify that a draining stream (which has received a FIN but not consumed |
| 1118 // it) does not count against the open quota (because it is closed from the | 1120 // it) does not count against the open quota (because it is closed from the |
| 1119 // protocol point of view). | 1121 // protocol point of view). |
| 1120 if (GetParam() <= QUIC_VERSION_27) { | 1122 if (GetParam() <= QUIC_VERSION_27) { |
| 1121 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)) | 1123 EXPECT_CALL(*connection_, |
| 1124 SendConnectionCloseWithDetails(QUIC_TOO_MANY_OPEN_STREAMS, _)) |
| 1122 .Times(0); | 1125 .Times(0); |
| 1123 } else { | 1126 } else { |
| 1124 EXPECT_CALL(*connection_, SendRstStream(_, QUIC_REFUSED_STREAM, _)) | 1127 EXPECT_CALL(*connection_, SendRstStream(_, QUIC_REFUSED_STREAM, _)) |
| 1125 .Times(0); | 1128 .Times(0); |
| 1126 } | 1129 } |
| 1127 const QuicStreamId kMaxStreams = 5; | 1130 const QuicStreamId kMaxStreams = 5; |
| 1128 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams); | 1131 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams); |
| 1129 | 1132 |
| 1130 // Create kMaxStreams + 1 data streams, and mark them draining. | 1133 // Create kMaxStreams + 1 data streams, and mark them draining. |
| 1131 const QuicStreamId kFirstStreamId = kClientDataStreamId1; | 1134 const QuicStreamId kFirstStreamId = kClientDataStreamId1; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 | 1195 |
| 1193 // The stream is not waiting for the arrival of the peer's final offset as it | 1196 // The stream is not waiting for the arrival of the peer's final offset as it |
| 1194 // was received with the FIN earlier. | 1197 // was received with the FIN earlier. |
| 1195 EXPECT_EQ(0u, QuicSessionPeer::GetLocallyClosedStreamsHighestOffset(&session_) | 1198 EXPECT_EQ(0u, QuicSessionPeer::GetLocallyClosedStreamsHighestOffset(&session_) |
| 1196 .size()); | 1199 .size()); |
| 1197 } | 1200 } |
| 1198 | 1201 |
| 1199 } // namespace | 1202 } // namespace |
| 1200 } // namespace test | 1203 } // namespace test |
| 1201 } // namespace net | 1204 } // namespace net |
| OLD | NEW |