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