| 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" |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "net/quic/crypto/crypto_protocol.h" | 14 #include "net/quic/crypto/crypto_protocol.h" |
| 15 #include "net/quic/quic_crypto_stream.h" | 15 #include "net/quic/quic_crypto_stream.h" |
| 16 #include "net/quic/quic_flags.h" | |
| 17 #include "net/quic/quic_protocol.h" | 16 #include "net/quic/quic_protocol.h" |
| 18 #include "net/quic/quic_utils.h" | 17 #include "net/quic/quic_utils.h" |
| 19 #include "net/quic/reliable_quic_stream.h" | 18 #include "net/quic/reliable_quic_stream.h" |
| 20 #include "net/quic/test_tools/quic_config_peer.h" | 19 #include "net/quic/test_tools/quic_config_peer.h" |
| 21 #include "net/quic/test_tools/quic_connection_peer.h" | 20 #include "net/quic/test_tools/quic_connection_peer.h" |
| 22 #include "net/quic/test_tools/quic_data_stream_peer.h" | 21 #include "net/quic/test_tools/quic_data_stream_peer.h" |
| 23 #include "net/quic/test_tools/quic_flow_controller_peer.h" | 22 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
| 24 #include "net/quic/test_tools/quic_session_peer.h" | 23 #include "net/quic/test_tools/quic_session_peer.h" |
| 25 #include "net/quic/test_tools/quic_spdy_session_peer.h" | 24 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
| 26 #include "net/quic/test_tools/quic_test_utils.h" | 25 #include "net/quic/test_tools/quic_test_utils.h" |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 session_.GetIncomingDynamicStream(stream_id); | 322 session_.GetIncomingDynamicStream(stream_id); |
| 324 EXPECT_CALL(*connection_, SendConnectionClose(_)).Times(0); | 323 EXPECT_CALL(*connection_, SendConnectionClose(_)).Times(0); |
| 325 EXPECT_NE(nullptr, | 324 EXPECT_NE(nullptr, |
| 326 session_.GetIncomingDynamicStream( | 325 session_.GetIncomingDynamicStream( |
| 327 stream_id + 2 * (session_.get_max_open_streams() - 1))); | 326 stream_id + 2 * (session_.get_max_open_streams() - 1))); |
| 328 } | 327 } |
| 329 | 328 |
| 330 TEST_P(QuicSessionTestServer, TooManyImplicitlyOpenedStreams) { | 329 TEST_P(QuicSessionTestServer, TooManyImplicitlyOpenedStreams) { |
| 331 QuicStreamId stream_id1 = kClientDataStreamId1; | 330 QuicStreamId stream_id1 = kClientDataStreamId1; |
| 332 // A stream ID which is too large to create. | 331 // A stream ID which is too large to create. |
| 333 const QuicStreamId kMaxStreamIdDelta = 200; | 332 QuicStreamId stream_id2 = stream_id1 + 2 * session_.get_max_open_streams(); |
| 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)); | 333 EXPECT_NE(nullptr, session_.GetIncomingDynamicStream(stream_id1)); |
| 339 EXPECT_CALL(*connection_, SendConnectionClose(FLAGS_exact_stream_id_delta | 334 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)); |
| 340 ? QUIC_TOO_MANY_OPEN_STREAMS | |
| 341 : QUIC_INVALID_STREAM_ID)); | |
| 342 EXPECT_EQ(nullptr, session_.GetIncomingDynamicStream(stream_id2)); | 335 EXPECT_EQ(nullptr, session_.GetIncomingDynamicStream(stream_id2)); |
| 343 } | 336 } |
| 344 | 337 |
| 345 TEST_P(QuicSessionTestServer, ManyImplicitlyOpenedStreams) { | 338 TEST_P(QuicSessionTestServer, ManyImplicitlyOpenedStreams) { |
| 346 // When max_open_streams_ is 200, should be able to create 200 streams | 339 // 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. | 340 // out-of-order, that is, creating the one with the largest stream ID first. |
| 348 QuicSessionPeer::SetMaxOpenStreams(&session_, 200); | 341 QuicSessionPeer::SetMaxOpenStreams(&session_, 200); |
| 349 QuicStreamId stream_id = kClientDataStreamId1; | 342 QuicStreamId stream_id = kClientDataStreamId1; |
| 350 // Create one stream. | 343 // Create one stream. |
| 351 session_.GetIncomingDynamicStream(stream_id); | 344 session_.GetIncomingDynamicStream(stream_id); |
| 352 EXPECT_CALL(*connection_, SendConnectionClose(_)) | 345 EXPECT_CALL(*connection_, SendConnectionClose(_)).Times(0); |
| 353 .Times(FLAGS_exact_stream_id_delta ? 0 : 1); | |
| 354 // Create the largest stream ID of a threatened total of 200 streams. | 346 // Create the largest stream ID of a threatened total of 200 streams. |
| 355 session_.GetIncomingDynamicStream(stream_id + 2 * (200 - 1)); | 347 session_.GetIncomingDynamicStream(stream_id + 2 * (200 - 1)); |
| 356 } | 348 } |
| 357 | 349 |
| 358 TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) { | 350 TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) { |
| 359 TestStream* stream2 = session_.CreateOutgoingDynamicStream(); | 351 TestStream* stream2 = session_.CreateOutgoingDynamicStream(); |
| 360 QuicStreamId closed_stream_id = stream2->id(); | 352 QuicStreamId closed_stream_id = stream2->id(); |
| 361 // Close the stream. | 353 // Close the stream. |
| 362 EXPECT_CALL(*connection_, SendRstStream(closed_stream_id, _, _)); | 354 EXPECT_CALL(*connection_, SendRstStream(closed_stream_id, _, _)); |
| 363 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD); | 355 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 // should trigger a connection close. However there is no need to send | 614 // should trigger a connection close. However there is no need to send |
| 623 // multiple connection close frames. | 615 // multiple connection close frames. |
| 624 | 616 |
| 625 // Create valid stream. | 617 // Create valid stream. |
| 626 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); | 618 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); |
| 627 session_.OnStreamFrame(data1); | 619 session_.OnStreamFrame(data1); |
| 628 EXPECT_EQ(1u, session_.GetNumOpenStreams()); | 620 EXPECT_EQ(1u, session_.GetNumOpenStreams()); |
| 629 | 621 |
| 630 // Process first invalid stream reset, resulting in the connection being | 622 // Process first invalid stream reset, resulting in the connection being |
| 631 // closed. | 623 // closed. |
| 632 EXPECT_CALL(*connection_, SendConnectionClose(FLAGS_exact_stream_id_delta | 624 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)) |
| 633 ? QUIC_TOO_MANY_OPEN_STREAMS | |
| 634 : QUIC_INVALID_STREAM_ID)) | |
| 635 .Times(1); | 625 .Times(1); |
| 636 const QuicStreamId kLargeInvalidStreamId = 99999999; | 626 const QuicStreamId kLargeInvalidStreamId = 99999999; |
| 637 QuicRstStreamFrame rst1(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); | 627 QuicRstStreamFrame rst1(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); |
| 638 session_.OnRstStream(rst1); | 628 session_.OnRstStream(rst1); |
| 639 QuicConnectionPeer::CloseConnection(connection_); | 629 QuicConnectionPeer::CloseConnection(connection_); |
| 640 | 630 |
| 641 // Processing of second invalid stream reset should not result in the | 631 // Processing of second invalid stream reset should not result in the |
| 642 // connection being closed for a second time. | 632 // connection being closed for a second time. |
| 643 QuicRstStreamFrame rst2(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); | 633 QuicRstStreamFrame rst2(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); |
| 644 session_.OnRstStream(rst2); | 634 session_.OnRstStream(rst2); |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 4)); | 1022 EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 4)); |
| 1033 ASSERT_TRUE(session_.GetIncomingDynamicStream(2) != nullptr); | 1023 ASSERT_TRUE(session_.GetIncomingDynamicStream(2) != nullptr); |
| 1034 ASSERT_TRUE(session_.GetIncomingDynamicStream(4) != nullptr); | 1024 ASSERT_TRUE(session_.GetIncomingDynamicStream(4) != nullptr); |
| 1035 // And 5 should be not implicitly created. | 1025 // And 5 should be not implicitly created. |
| 1036 EXPECT_FALSE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 5)); | 1026 EXPECT_FALSE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 5)); |
| 1037 } | 1027 } |
| 1038 | 1028 |
| 1039 } // namespace | 1029 } // namespace |
| 1040 } // namespace test | 1030 } // namespace test |
| 1041 } // namespace net | 1031 } // namespace net |
| OLD | NEW |