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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 TestCryptoStream* GetCryptoStream() override { return &crypto_stream_; } | 128 TestCryptoStream* GetCryptoStream() override { return &crypto_stream_; } |
129 | 129 |
130 TestStream* CreateOutgoingDynamicStream() override { | 130 TestStream* CreateOutgoingDynamicStream() override { |
131 TestStream* stream = new TestStream(GetNextStreamId(), this); | 131 TestStream* stream = new TestStream(GetNextStreamId(), this); |
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 return new TestStream(id, this); | 137 // Enforce the limit on the number of open streams. |
| 138 if (GetNumOpenStreams() + 1 > get_max_open_streams()) { |
| 139 connection()->SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS); |
| 140 return nullptr; |
| 141 } else { |
| 142 return new TestStream(id, this); |
| 143 } |
138 } | 144 } |
139 | 145 |
140 bool IsClosedStream(QuicStreamId id) { | 146 bool IsClosedStream(QuicStreamId id) { |
141 return QuicSession::IsClosedStream(id); | 147 return QuicSession::IsClosedStream(id); |
142 } | 148 } |
143 | 149 |
144 ReliableQuicStream* GetIncomingDynamicStream(QuicStreamId stream_id) { | 150 ReliableQuicStream* GetIncomingDynamicStream(QuicStreamId stream_id) { |
145 return QuicSpdySession::GetIncomingDynamicStream(stream_id); | 151 return QuicSpdySession::GetIncomingDynamicStream(stream_id); |
146 } | 152 } |
147 | 153 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 CloseStream(stream_id2); | 311 CloseStream(stream_id2); |
306 // Create a stream explicitly, and another implicitly. | 312 // Create a stream explicitly, and another implicitly. |
307 ReliableQuicStream* stream3 = | 313 ReliableQuicStream* stream3 = |
308 session_.GetIncomingDynamicStream(stream_id2 + 4); | 314 session_.GetIncomingDynamicStream(stream_id2 + 4); |
309 CheckClosedStreams(); | 315 CheckClosedStreams(); |
310 // Close one, but make sure the other is still not closed | 316 // Close one, but make sure the other is still not closed |
311 CloseStream(stream3->id()); | 317 CloseStream(stream3->id()); |
312 CheckClosedStreams(); | 318 CheckClosedStreams(); |
313 } | 319 } |
314 | 320 |
315 TEST_P(QuicSessionTestServer, StreamIdTooLarge) { | 321 TEST_P(QuicSessionTestServer, MaximumImplicitlyOpenedStreams) { |
316 QuicStreamId stream_id = kClientDataStreamId1; | 322 QuicStreamId stream_id = kClientDataStreamId1; |
317 session_.GetIncomingDynamicStream(stream_id); | 323 session_.GetIncomingDynamicStream(stream_id); |
318 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)); | 324 EXPECT_CALL(*connection_, SendConnectionClose(_)).Times(0); |
319 session_.GetIncomingDynamicStream(stream_id + kMaxStreamIdDelta + 2); | 325 EXPECT_NE(nullptr, |
| 326 session_.GetIncomingDynamicStream( |
| 327 stream_id + 2 * (session_.get_max_open_streams() - 1))); |
| 328 } |
| 329 |
| 330 TEST_P(QuicSessionTestServer, TooManyImplicitlyOpenedStreams) { |
| 331 QuicStreamId stream_id1 = kClientDataStreamId1; |
| 332 // A stream ID which is too large to create. |
| 333 const QuicStreamId kMaxStreamIdDelta = 200; |
| 334 QuicStreamId stream_id2 = |
| 335 FLAGS_exact_stream_id_delta |
| 336 ? stream_id1 + 2 * session_.get_max_open_streams() |
| 337 : stream_id1 + kMaxStreamIdDelta + 2; |
| 338 EXPECT_NE(nullptr, session_.GetIncomingDynamicStream(stream_id1)); |
| 339 EXPECT_CALL(*connection_, SendConnectionClose(FLAGS_exact_stream_id_delta |
| 340 ? QUIC_TOO_MANY_OPEN_STREAMS |
| 341 : QUIC_INVALID_STREAM_ID)); |
| 342 EXPECT_EQ(nullptr, session_.GetIncomingDynamicStream(stream_id2)); |
| 343 } |
| 344 |
| 345 TEST_P(QuicSessionTestServer, ManyImplicitlyOpenedStreams) { |
| 346 // When max_open_streams_ is 200, should be able to create 200 streams |
| 347 // out-of-order, that is, creating the one with the largest stream ID first. |
| 348 QuicSessionPeer::SetMaxOpenStreams(&session_, 200); |
| 349 QuicStreamId stream_id = kClientDataStreamId1; |
| 350 // Create one stream. |
| 351 session_.GetIncomingDynamicStream(stream_id); |
| 352 EXPECT_CALL(*connection_, SendConnectionClose(_)) |
| 353 .Times(FLAGS_exact_stream_id_delta ? 0 : 1); |
| 354 // Create the largest stream ID of a threatened total of 200 streams. |
| 355 session_.GetIncomingDynamicStream(stream_id + 2 * (200 - 1)); |
320 } | 356 } |
321 | 357 |
322 TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) { | 358 TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) { |
323 TestStream* stream2 = session_.CreateOutgoingDynamicStream(); | 359 TestStream* stream2 = session_.CreateOutgoingDynamicStream(); |
324 QuicStreamId kClosedStreamId = stream2->id(); | 360 QuicStreamId kClosedStreamId = stream2->id(); |
325 // Close the stream. | 361 // Close the stream. |
326 EXPECT_CALL(*connection_, SendRstStream(kClosedStreamId, _, _)); | 362 EXPECT_CALL(*connection_, SendRstStream(kClosedStreamId, _, _)); |
327 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD); | 363 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD); |
328 EXPECT_DEBUG_DFATAL(session_.MarkConnectionLevelWriteBlocked( | 364 EXPECT_DEBUG_DFATAL(session_.MarkConnectionLevelWriteBlocked( |
329 kClosedStreamId, kSomeMiddlePriority), | 365 kClosedStreamId, kSomeMiddlePriority), |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 // should trigger a connection close. However there is no need to send | 626 // should trigger a connection close. However there is no need to send |
591 // multiple connection close frames. | 627 // multiple connection close frames. |
592 | 628 |
593 // Create valid stream. | 629 // Create valid stream. |
594 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); | 630 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); |
595 session_.OnStreamFrame(data1); | 631 session_.OnStreamFrame(data1); |
596 EXPECT_EQ(1u, session_.GetNumOpenStreams()); | 632 EXPECT_EQ(1u, session_.GetNumOpenStreams()); |
597 | 633 |
598 // Process first invalid stream reset, resulting in the connection being | 634 // Process first invalid stream reset, resulting in the connection being |
599 // closed. | 635 // closed. |
600 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)) | 636 EXPECT_CALL(*connection_, SendConnectionClose(FLAGS_exact_stream_id_delta |
| 637 ? QUIC_TOO_MANY_OPEN_STREAMS |
| 638 : QUIC_INVALID_STREAM_ID)) |
601 .Times(1); | 639 .Times(1); |
602 const QuicStreamId kLargeInvalidStreamId = 99999999; | 640 const QuicStreamId kLargeInvalidStreamId = 99999999; |
603 QuicRstStreamFrame rst1(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); | 641 QuicRstStreamFrame rst1(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); |
604 session_.OnRstStream(rst1); | 642 session_.OnRstStream(rst1); |
605 QuicConnectionPeer::CloseConnection(connection_); | 643 QuicConnectionPeer::CloseConnection(connection_); |
606 | 644 |
607 // Processing of second invalid stream reset should not result in the | 645 // Processing of second invalid stream reset should not result in the |
608 // connection being closed for a second time. | 646 // connection being closed for a second time. |
609 QuicRstStreamFrame rst2(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); | 647 QuicRstStreamFrame rst2(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); |
610 session_.OnRstStream(rst2); | 648 session_.OnRstStream(rst2); |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 4)); | 1036 EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 4)); |
999 ASSERT_TRUE(session_.GetIncomingDynamicStream(2) != nullptr); | 1037 ASSERT_TRUE(session_.GetIncomingDynamicStream(2) != nullptr); |
1000 ASSERT_TRUE(session_.GetIncomingDynamicStream(4) != nullptr); | 1038 ASSERT_TRUE(session_.GetIncomingDynamicStream(4) != nullptr); |
1001 // And 5 should be not implicitly created. | 1039 // And 5 should be not implicitly created. |
1002 EXPECT_FALSE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 5)); | 1040 EXPECT_FALSE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 5)); |
1003 } | 1041 } |
1004 | 1042 |
1005 } // namespace | 1043 } // namespace |
1006 } // namespace test | 1044 } // namespace test |
1007 } // namespace net | 1045 } // namespace net |
OLD | NEW |