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 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 | 962 |
963 // Unblock the headers stream by supplying a WINDOW_UPDATE. | 963 // Unblock the headers stream by supplying a WINDOW_UPDATE. |
964 QuicWindowUpdateFrame window_update_frame(headers_stream->id(), | 964 QuicWindowUpdateFrame window_update_frame(headers_stream->id(), |
965 2 * kMinimumFlowControlSendWindow); | 965 2 * kMinimumFlowControlSendWindow); |
966 session_.OnWindowUpdateFrame(window_update_frame); | 966 session_.OnWindowUpdateFrame(window_update_frame); |
967 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked()); | 967 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked()); |
968 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); | 968 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); |
969 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); | 969 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); |
970 } | 970 } |
971 | 971 |
972 TEST_P(QuicSessionTestServer, TooManyUnfinishedStreamsCauseConnectionClose) { | 972 TEST_P(QuicSessionTestServer, |
973 FLAGS_quic_count_unfinished_as_open_streams = false; | 973 TooManyUnfinishedStreamsCauseServerRejectStream) { |
974 // If a buggy/malicious peer creates too many streams that are not ended | |
975 // with a FIN or RST then we send a connection close. | |
976 EXPECT_CALL(*connection_, | |
977 SendConnectionClose(QUIC_TOO_MANY_UNFINISHED_STREAMS)); | |
978 | |
979 const QuicStreamId kMaxStreams = 5; | |
980 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams); | |
981 | |
982 // Create kMaxStreams + 1 data streams, and close them all without receiving | |
983 // a FIN or a RST_STREAM from the client. | |
984 const QuicStreamId kFirstStreamId = kClientDataStreamId1; | |
985 const QuicStreamId kFinalStreamId = | |
986 kClientDataStreamId1 + 2 * kMaxStreams + 1; | |
987 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { | |
988 QuicStreamFrame data1(i, false, 0, StringPiece("HT")); | |
989 session_.OnStreamFrame(data1); | |
990 EXPECT_EQ(1u, session_.GetNumOpenStreams()); | |
991 EXPECT_CALL(*connection_, SendRstStream(i, _, _)); | |
992 session_.CloseStream(i); | |
993 } | |
994 | |
995 // Called after any new data is received by the session, and triggers the | |
996 // call to close the connection. | |
997 session_.PostProcessAfterData(); | |
998 } | |
999 | |
1000 TEST_P(QuicSessionTestServer, TooManyUnfinishedStreamsCauseServerRejectStream) { | |
1001 FLAGS_quic_count_unfinished_as_open_streams = true; | |
1002 // If a buggy/malicious peer creates too many streams that are not ended | 974 // If a buggy/malicious peer creates too many streams that are not ended |
1003 // with a FIN or RST then we send a connection close or an RST to | 975 // with a FIN or RST then we send a connection close or an RST to |
1004 // refuse streams. | 976 // refuse streams. |
1005 const QuicStreamId kMaxStreams = 5; | 977 const QuicStreamId kMaxStreams = 5; |
1006 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams); | 978 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams); |
1007 const QuicStreamId kFirstStreamId = kClientDataStreamId1; | 979 const QuicStreamId kFirstStreamId = kClientDataStreamId1; |
1008 const QuicStreamId kFinalStreamId = kClientDataStreamId1 + 2 * kMaxStreams; | 980 const QuicStreamId kFinalStreamId = kClientDataStreamId1 + 2 * kMaxStreams; |
1009 | 981 |
1010 // Create kMaxStreams data streams, and close them all without receiving a | 982 // Create kMaxStreams data streams, and close them all without receiving a |
1011 // FIN or a RST_STREAM from the client. | 983 // FIN or a RST_STREAM from the client. |
(...skipping 19 matching lines...) Expand all Loading... |
1031 | 1003 |
1032 // Called after any new data is received by the session, and triggers the | 1004 // Called after any new data is received by the session, and triggers the |
1033 // call to close the connection. | 1005 // call to close the connection. |
1034 session_.PostProcessAfterData(); | 1006 session_.PostProcessAfterData(); |
1035 } | 1007 } |
1036 | 1008 |
1037 TEST_P(QuicSessionTestServer, DrainingStreamsDoNotCountAsOpened) { | 1009 TEST_P(QuicSessionTestServer, DrainingStreamsDoNotCountAsOpened) { |
1038 // Verify that a draining stream (which has received a FIN but not consumed | 1010 // Verify that a draining stream (which has received a FIN but not consumed |
1039 // it) does not count against the open quota (because it is closed from the | 1011 // it) does not count against the open quota (because it is closed from the |
1040 // protocol point of view). | 1012 // protocol point of view). |
1041 if (FLAGS_quic_count_unfinished_as_open_streams) { | 1013 if (GetParam() <= QUIC_VERSION_27) { |
1042 if (GetParam() <= QUIC_VERSION_27) { | 1014 EXPECT_CALL(*connection_, |
1043 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)) | 1015 SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)).Times(0); |
1044 .Times(0); | |
1045 } else { | |
1046 EXPECT_CALL(*connection_, SendRstStream(_, QUIC_REFUSED_STREAM, _)) | |
1047 .Times(0); | |
1048 } | |
1049 } else { | 1016 } else { |
1050 EXPECT_CALL(*connection_, | 1017 EXPECT_CALL(*connection_, |
1051 SendConnectionClose(QUIC_TOO_MANY_UNFINISHED_STREAMS)) | 1018 SendRstStream(_, QUIC_REFUSED_STREAM, _)).Times(0); |
1052 .Times(0); | |
1053 } | 1019 } |
1054 | |
1055 const QuicStreamId kMaxStreams = 5; | 1020 const QuicStreamId kMaxStreams = 5; |
1056 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams); | 1021 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams); |
1057 | 1022 |
1058 // Create kMaxStreams + 1 data streams, and mark them draining. | 1023 // Create kMaxStreams + 1 data streams, and mark them draining. |
1059 const QuicStreamId kFirstStreamId = kClientDataStreamId1; | 1024 const QuicStreamId kFirstStreamId = kClientDataStreamId1; |
1060 const QuicStreamId kFinalStreamId = | 1025 const QuicStreamId kFinalStreamId = |
1061 kClientDataStreamId1 + 2 * kMaxStreams + 1; | 1026 kClientDataStreamId1 + 2 * kMaxStreams + 1; |
1062 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { | 1027 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { |
1063 QuicStreamFrame data1(i, true, 0, StringPiece("HT")); | 1028 QuicStreamFrame data1(i, true, 0, StringPiece("HT")); |
1064 session_.OnStreamFrame(data1); | 1029 session_.OnStreamFrame(data1); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 // Verify that there is no entry for the stream in | 1088 // Verify that there is no entry for the stream in |
1124 // locally_closed_streams_highest_offset_. | 1089 // locally_closed_streams_highest_offset_. |
1125 EXPECT_EQ( | 1090 EXPECT_EQ( |
1126 FLAGS_quic_fix_fin_accounting ? 0u : 1u, | 1091 FLAGS_quic_fix_fin_accounting ? 0u : 1u, |
1127 QuicSessionPeer::GetLocallyClosedStreamsHighestOffset(&session_).size()); | 1092 QuicSessionPeer::GetLocallyClosedStreamsHighestOffset(&session_).size()); |
1128 } | 1093 } |
1129 | 1094 |
1130 } // namespace | 1095 } // namespace |
1131 } // namespace test | 1096 } // namespace test |
1132 } // namespace net | 1097 } // namespace net |
OLD | NEW |