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" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "net/quic/crypto/crypto_protocol.h" | 12 #include "net/quic/crypto/crypto_protocol.h" |
13 #include "net/quic/quic_crypto_stream.h" | 13 #include "net/quic/quic_crypto_stream.h" |
| 14 #include "net/quic/quic_flags.h" |
14 #include "net/quic/quic_protocol.h" | 15 #include "net/quic/quic_protocol.h" |
15 #include "net/quic/quic_utils.h" | 16 #include "net/quic/quic_utils.h" |
16 #include "net/quic/reliable_quic_stream.h" | 17 #include "net/quic/reliable_quic_stream.h" |
17 #include "net/quic/test_tools/quic_config_peer.h" | 18 #include "net/quic/test_tools/quic_config_peer.h" |
18 #include "net/quic/test_tools/quic_connection_peer.h" | 19 #include "net/quic/test_tools/quic_connection_peer.h" |
19 #include "net/quic/test_tools/quic_data_stream_peer.h" | 20 #include "net/quic/test_tools/quic_data_stream_peer.h" |
20 #include "net/quic/test_tools/quic_flow_controller_peer.h" | 21 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
21 #include "net/quic/test_tools/quic_session_peer.h" | 22 #include "net/quic/test_tools/quic_session_peer.h" |
22 #include "net/quic/test_tools/quic_test_utils.h" | 23 #include "net/quic/test_tools/quic_test_utils.h" |
23 #include "net/quic/test_tools/reliable_quic_stream_peer.h" | 24 #include "net/quic/test_tools/reliable_quic_stream_peer.h" |
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_18); | 897 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_18); |
897 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); | 898 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); |
898 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); | 899 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); |
899 | 900 |
900 // Version 16 means all flow control is disabled. | 901 // Version 16 means all flow control is disabled. |
901 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); | 902 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); |
902 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); | 903 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); |
903 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); | 904 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); |
904 } | 905 } |
905 | 906 |
| 907 TEST_P(QuicSessionTest, TooManyUnfinishedStreamsCauseConnectionClose) { |
| 908 if (version() < QUIC_VERSION_18) { |
| 909 return; |
| 910 } |
| 911 // If a buggy/malicious peer creates too many streams that are not ended with |
| 912 // a FIN or RST then we send a connection close. |
| 913 ValueRestore<bool> old_flag(&FLAGS_close_quic_connection_unfinished_streams, |
| 914 true); |
| 915 |
| 916 EXPECT_CALL(*connection_, |
| 917 SendConnectionClose(QUIC_TOO_MANY_UNFINISHED_STREAMS)).Times(1); |
| 918 |
| 919 const int kMaxStreams = 5; |
| 920 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams); |
| 921 |
| 922 // Create kMaxStreams + 1 data streams, and close them all without receiving a |
| 923 // FIN or a RST from the client. |
| 924 const int kFirstStreamId = kClientDataStreamId1; |
| 925 const int kFinalStreamId = kClientDataStreamId1 + 2 * kMaxStreams + 1; |
| 926 for (int i = kFirstStreamId; i < kFinalStreamId; i += 2) { |
| 927 QuicStreamFrame data1(i, false, 0, MakeIOVector("HT")); |
| 928 vector<QuicStreamFrame> frames; |
| 929 frames.push_back(data1); |
| 930 session_.OnStreamFrames(frames); |
| 931 EXPECT_EQ(1u, session_.GetNumOpenStreams()); |
| 932 session_.CloseStream(i); |
| 933 } |
| 934 } |
| 935 |
906 } // namespace | 936 } // namespace |
907 } // namespace test | 937 } // namespace test |
908 } // namespace net | 938 } // namespace net |
OLD | NEW |