| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/core/quic_server_session_base.h" | 5 #include "net/quic/core/quic_server_session_base.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 11 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
| 12 #include "net/quic/core/crypto/quic_random.h" | 12 #include "net/quic/core/crypto/quic_random.h" |
| 13 #include "net/quic/core/proto/cached_network_parameters.pb.h" | 13 #include "net/quic/core/proto/cached_network_parameters.pb.h" |
| 14 #include "net/quic/core/quic_connection.h" | 14 #include "net/quic/core/quic_connection.h" |
| 15 #include "net/quic/core/quic_crypto_server_stream.h" | 15 #include "net/quic/core/quic_crypto_server_stream.h" |
| 16 #include "net/quic/core/quic_utils.h" | 16 #include "net/quic/core/quic_utils.h" |
| 17 #include "net/quic/platform/api/quic_flags.h" |
| 17 #include "net/quic/platform/api/quic_ptr_util.h" | 18 #include "net/quic/platform/api/quic_ptr_util.h" |
| 18 #include "net/quic/platform/api/quic_socket_address.h" | 19 #include "net/quic/platform/api/quic_socket_address.h" |
| 19 #include "net/quic/test_tools/crypto_test_utils.h" | 20 #include "net/quic/test_tools/crypto_test_utils.h" |
| 20 #include "net/quic/test_tools/fake_proof_source.h" | 21 #include "net/quic/test_tools/fake_proof_source.h" |
| 21 #include "net/quic/test_tools/quic_config_peer.h" | 22 #include "net/quic/test_tools/quic_config_peer.h" |
| 22 #include "net/quic/test_tools/quic_connection_peer.h" | 23 #include "net/quic/test_tools/quic_connection_peer.h" |
| 23 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" | 24 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" |
| 24 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 25 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
| 25 #include "net/quic/test_tools/quic_session_peer.h" | 26 #include "net/quic/test_tools/quic_session_peer.h" |
| 26 #include "net/quic/test_tools/quic_spdy_session_peer.h" | 27 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 QuicServerSessionBaseTest, | 187 QuicServerSessionBaseTest, |
| 187 ::testing::ValuesIn(AllSupportedVersions())); | 188 ::testing::ValuesIn(AllSupportedVersions())); |
| 188 TEST_P(QuicServerSessionBaseTest, ServerPushDisabledByDefault) { | 189 TEST_P(QuicServerSessionBaseTest, ServerPushDisabledByDefault) { |
| 189 FLAGS_quic_reloadable_flag_quic_enable_server_push_by_default = true; | 190 FLAGS_quic_reloadable_flag_quic_enable_server_push_by_default = true; |
| 190 // Without the client explicitly sending kSPSH, server push will be disabled | 191 // Without the client explicitly sending kSPSH, server push will be disabled |
| 191 // at the server, until version 35 when it is enabled by default. | 192 // at the server, until version 35 when it is enabled by default. |
| 192 EXPECT_FALSE( | 193 EXPECT_FALSE( |
| 193 session_->config()->HasReceivedConnectionOptions() && | 194 session_->config()->HasReceivedConnectionOptions() && |
| 194 ContainsQuicTag(session_->config()->ReceivedConnectionOptions(), kSPSH)); | 195 ContainsQuicTag(session_->config()->ReceivedConnectionOptions(), kSPSH)); |
| 195 session_->OnConfigNegotiated(); | 196 session_->OnConfigNegotiated(); |
| 196 if (GetParam() <= QUIC_VERSION_34) { | 197 EXPECT_TRUE(session_->server_push_enabled()); |
| 197 EXPECT_FALSE(session_->server_push_enabled()); | |
| 198 } else { | |
| 199 EXPECT_TRUE(session_->server_push_enabled()); | |
| 200 } | |
| 201 } | 198 } |
| 202 | 199 |
| 203 TEST_P(QuicServerSessionBaseTest, CloseStreamDueToReset) { | 200 TEST_P(QuicServerSessionBaseTest, CloseStreamDueToReset) { |
| 204 // Open a stream, then reset it. | 201 // Open a stream, then reset it. |
| 205 // Send two bytes of payload to open it. | 202 // Send two bytes of payload to open it. |
| 206 QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT")); | 203 QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT")); |
| 207 session_->OnStreamFrame(data1); | 204 session_->OnStreamFrame(data1); |
| 208 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 205 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
| 209 | 206 |
| 210 // Send a reset (and expect the peer to send a RST in response). | 207 // Send a reset (and expect the peer to send a RST in response). |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 // The stream should never be opened, now that the reset is received. | 267 // The stream should never be opened, now that the reset is received. |
| 271 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 268 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
| 272 EXPECT_TRUE(connection_->connected()); | 269 EXPECT_TRUE(connection_->connected()); |
| 273 } | 270 } |
| 274 | 271 |
| 275 TEST_P(QuicServerSessionBaseTest, MaxOpenStreams) { | 272 TEST_P(QuicServerSessionBaseTest, MaxOpenStreams) { |
| 276 // Test that the server refuses if a client attempts to open too many data | 273 // Test that the server refuses if a client attempts to open too many data |
| 277 // streams. The server accepts slightly more than the negotiated stream limit | 274 // streams. The server accepts slightly more than the negotiated stream limit |
| 278 // to deal with rare cases where a client FIN/RST is lost. | 275 // to deal with rare cases where a client FIN/RST is lost. |
| 279 | 276 |
| 280 if (GetParam() <= QUIC_VERSION_34) { | |
| 281 EXPECT_EQ(kMaxStreamsForTest, session_->max_open_incoming_streams()); | |
| 282 } | |
| 283 | |
| 284 // The slightly increased stream limit is set during config negotiation. It | 277 // The slightly increased stream limit is set during config negotiation. It |
| 285 // is either an increase of 10 over negotiated limit, or a fixed percentage | 278 // is either an increase of 10 over negotiated limit, or a fixed percentage |
| 286 // scaling, whichever is larger. Test both before continuing. | 279 // scaling, whichever is larger. Test both before continuing. |
| 287 session_->OnConfigNegotiated(); | 280 session_->OnConfigNegotiated(); |
| 288 EXPECT_LT(kMaxStreamsMultiplier * kMaxStreamsForTest, | 281 EXPECT_LT(kMaxStreamsMultiplier * kMaxStreamsForTest, |
| 289 kMaxStreamsForTest + kMaxStreamsMinimumIncrement); | 282 kMaxStreamsForTest + kMaxStreamsMinimumIncrement); |
| 290 EXPECT_EQ(kMaxStreamsForTest + kMaxStreamsMinimumIncrement, | 283 EXPECT_EQ(kMaxStreamsForTest + kMaxStreamsMinimumIncrement, |
| 291 session_->max_open_incoming_streams()); | 284 session_->max_open_incoming_streams()); |
| 292 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 285 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
| 293 QuicStreamId stream_id = kClientDataStreamId1; | 286 QuicStreamId stream_id = kClientDataStreamId1; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 312 // Even if the connection remains open, the stream creation should fail. | 305 // Even if the connection remains open, the stream creation should fail. |
| 313 EXPECT_FALSE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( | 306 EXPECT_FALSE(QuicServerSessionBasePeer::GetOrCreateDynamicStream( |
| 314 session_.get(), stream_id)); | 307 session_.get(), stream_id)); |
| 315 } | 308 } |
| 316 | 309 |
| 317 TEST_P(QuicServerSessionBaseTest, MaxAvailableStreams) { | 310 TEST_P(QuicServerSessionBaseTest, MaxAvailableStreams) { |
| 318 // Test that the server closes the connection if a client makes too many data | 311 // Test that the server closes the connection if a client makes too many data |
| 319 // streams available. The server accepts slightly more than the negotiated | 312 // streams available. The server accepts slightly more than the negotiated |
| 320 // stream limit to deal with rare cases where a client FIN/RST is lost. | 313 // stream limit to deal with rare cases where a client FIN/RST is lost. |
| 321 | 314 |
| 322 if (GetParam() <= QUIC_VERSION_34) { | |
| 323 // The slightly increased stream limit is set during config negotiation. | |
| 324 EXPECT_EQ(kMaxStreamsForTest, session_->max_open_incoming_streams()); | |
| 325 } | |
| 326 session_->OnConfigNegotiated(); | 315 session_->OnConfigNegotiated(); |
| 327 const size_t kAvailableStreamLimit = session_->MaxAvailableStreams(); | 316 const size_t kAvailableStreamLimit = session_->MaxAvailableStreams(); |
| 328 EXPECT_EQ( | 317 EXPECT_EQ( |
| 329 session_->max_open_incoming_streams() * kMaxAvailableStreamsMultiplier, | 318 session_->max_open_incoming_streams() * kMaxAvailableStreamsMultiplier, |
| 330 session_->MaxAvailableStreams()); | 319 session_->MaxAvailableStreams()); |
| 331 // The protocol specification requires that there can be at least 10 times | 320 // The protocol specification requires that there can be at least 10 times |
| 332 // as many available streams as the connection's maximum open streams. | 321 // as many available streams as the connection's maximum open streams. |
| 333 EXPECT_LE(10 * kMaxStreamsForTest, kAvailableStreamLimit); | 322 EXPECT_LE(10 * kMaxStreamsForTest, kAvailableStreamLimit); |
| 334 | 323 |
| 335 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 324 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 QuicConfigPeer::SetReceivedConnectionOptions(session_->config(), copt); | 507 QuicConfigPeer::SetReceivedConnectionOptions(session_->config(), copt); |
| 519 | 508 |
| 520 const string kTestServingRegion = "a serving region"; | 509 const string kTestServingRegion = "a serving region"; |
| 521 session_->set_serving_region(kTestServingRegion); | 510 session_->set_serving_region(kTestServingRegion); |
| 522 | 511 |
| 523 // Set the time to be one hour + one second from the 0 baseline. | 512 // Set the time to be one hour + one second from the 0 baseline. |
| 524 connection_->AdvanceTime( | 513 connection_->AdvanceTime( |
| 525 QuicTime::Delta::FromSeconds(kNumSecondsPerHour + 1)); | 514 QuicTime::Delta::FromSeconds(kNumSecondsPerHour + 1)); |
| 526 | 515 |
| 527 QuicCryptoServerStream* crypto_stream = static_cast<QuicCryptoServerStream*>( | 516 QuicCryptoServerStream* crypto_stream = static_cast<QuicCryptoServerStream*>( |
| 528 QuicSessionPeer::GetCryptoStream(session_.get())); | 517 QuicSessionPeer::GetMutableCryptoStream(session_.get())); |
| 529 | 518 |
| 530 // No effect if no CachedNetworkParameters provided. | 519 // No effect if no CachedNetworkParameters provided. |
| 531 EXPECT_CALL(*connection_, ResumeConnectionState(_, _)).Times(0); | 520 EXPECT_CALL(*connection_, ResumeConnectionState(_, _)).Times(0); |
| 532 session_->OnConfigNegotiated(); | 521 session_->OnConfigNegotiated(); |
| 533 | 522 |
| 534 // No effect if CachedNetworkParameters provided, but different serving | 523 // No effect if CachedNetworkParameters provided, but different serving |
| 535 // regions. | 524 // regions. |
| 536 CachedNetworkParameters cached_network_params; | 525 CachedNetworkParameters cached_network_params; |
| 537 cached_network_params.set_bandwidth_estimate_bytes_per_second(1); | 526 cached_network_params.set_bandwidth_estimate_bytes_per_second(1); |
| 538 cached_network_params.set_serving_region("different serving region"); | 527 cached_network_params.set_serving_region("different serving region"); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 | 634 |
| 646 // Allow the async ProofSource::GetProof call to complete. Verify (under | 635 // Allow the async ProofSource::GetProof call to complete. Verify (under |
| 647 // asan) that this does not result in accesses to any freed memory from the | 636 // asan) that this does not result in accesses to any freed memory from the |
| 648 // session or its subobjects. | 637 // session or its subobjects. |
| 649 GetFakeProofSource()->InvokePendingCallback(0); | 638 GetFakeProofSource()->InvokePendingCallback(0); |
| 650 } | 639 } |
| 651 | 640 |
| 652 } // namespace | 641 } // namespace |
| 653 } // namespace test | 642 } // namespace test |
| 654 } // namespace net | 643 } // namespace net |
| OLD | NEW |