| 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/tools/quic/quic_dispatcher.h" | 5 #include "net/tools/quic/quic_dispatcher.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "net/quic/crypto/crypto_handshake.h" | 13 #include "net/quic/crypto/crypto_handshake.h" |
| 14 #include "net/quic/crypto/quic_crypto_server_config.h" | 14 #include "net/quic/crypto/quic_crypto_server_config.h" |
| 15 #include "net/quic/crypto/quic_random.h" | 15 #include "net/quic/crypto/quic_random.h" |
| 16 #include "net/quic/quic_chromium_connection_helper.h" | 16 #include "net/quic/quic_chromium_connection_helper.h" |
| 17 #include "net/quic/quic_crypto_stream.h" | 17 #include "net/quic/quic_crypto_stream.h" |
| 18 #include "net/quic/quic_flags.h" | 18 #include "net/quic/quic_flags.h" |
| 19 #include "net/quic/quic_utils.h" | 19 #include "net/quic/quic_utils.h" |
| 20 #include "net/quic/test_tools/crypto_test_utils.h" | 20 #include "net/quic/test_tools/crypto_test_utils.h" |
| 21 #include "net/quic/test_tools/quic_test_utils.h" | 21 #include "net/quic/test_tools/quic_test_utils.h" |
| 22 #include "net/tools/epoll_server/epoll_server.h" | 22 #include "net/tools/epoll_server/epoll_server.h" |
| 23 #include "net/tools/quic/quic_epoll_alarm_factory.h" |
| 23 #include "net/tools/quic/quic_epoll_connection_helper.h" | 24 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 24 #include "net/tools/quic/quic_packet_writer_wrapper.h" | 25 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
| 25 #include "net/tools/quic/quic_time_wait_list_manager.h" | 26 #include "net/tools/quic/quic_time_wait_list_manager.h" |
| 26 #include "net/tools/quic/test_tools/mock_quic_time_wait_list_manager.h" | 27 #include "net/tools/quic/test_tools/mock_quic_time_wait_list_manager.h" |
| 27 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" | 28 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 31 |
| 31 using base::StringPiece; | 32 using base::StringPiece; |
| 32 using net::EpollServer; | 33 using net::EpollServer; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 class TestDispatcher : public QuicDispatcher { | 95 class TestDispatcher : public QuicDispatcher { |
| 95 public: | 96 public: |
| 96 TestDispatcher(const QuicConfig& config, | 97 TestDispatcher(const QuicConfig& config, |
| 97 const QuicCryptoServerConfig* crypto_config, | 98 const QuicCryptoServerConfig* crypto_config, |
| 98 EpollServer* eps) | 99 EpollServer* eps) |
| 99 : QuicDispatcher( | 100 : QuicDispatcher( |
| 100 config, | 101 config, |
| 101 crypto_config, | 102 crypto_config, |
| 102 QuicSupportedVersions(), | 103 QuicSupportedVersions(), |
| 103 std::unique_ptr<QuicEpollConnectionHelper>( | 104 std::unique_ptr<QuicEpollConnectionHelper>( |
| 104 new QuicEpollConnectionHelper(eps, | 105 new QuicEpollConnectionHelper(eps, QuicAllocator::BUFFER_POOL)), |
| 105 QuicAllocator::BUFFER_POOL))) {} | 106 std::unique_ptr<QuicEpollAlarmFactory>( |
| 107 new QuicEpollAlarmFactory(eps))) {} |
| 106 | 108 |
| 107 MOCK_METHOD2(CreateQuicSession, | 109 MOCK_METHOD2(CreateQuicSession, |
| 108 QuicServerSessionBase*(QuicConnectionId connection_id, | 110 QuicServerSessionBase*(QuicConnectionId connection_id, |
| 109 const IPEndPoint& client_address)); | 111 const IPEndPoint& client_address)); |
| 110 | 112 |
| 111 using QuicDispatcher::current_server_address; | 113 using QuicDispatcher::current_server_address; |
| 112 using QuicDispatcher::current_client_address; | 114 using QuicDispatcher::current_client_address; |
| 113 }; | 115 }; |
| 114 | 116 |
| 115 // A Connection class which unregisters the session from the dispatcher when | 117 // A Connection class which unregisters the session from the dispatcher when |
| 116 // sending connection close. | 118 // sending connection close. |
| 117 // It'd be slightly more realistic to do this from the Session but it would | 119 // It'd be slightly more realistic to do this from the Session but it would |
| 118 // involve a lot more mocking. | 120 // involve a lot more mocking. |
| 119 class MockServerConnection : public MockConnection { | 121 class MockServerConnection : public MockConnection { |
| 120 public: | 122 public: |
| 121 MockServerConnection(QuicConnectionId connection_id, | 123 MockServerConnection(QuicConnectionId connection_id, |
| 122 MockConnectionHelper* helper, | 124 MockConnectionHelper* helper, |
| 125 MockAlarmFactory* alarm_factory, |
| 123 QuicDispatcher* dispatcher) | 126 QuicDispatcher* dispatcher) |
| 124 : MockConnection(connection_id, helper, Perspective::IS_SERVER), | 127 : MockConnection(connection_id, |
| 128 helper, |
| 129 alarm_factory, |
| 130 Perspective::IS_SERVER), |
| 125 dispatcher_(dispatcher) {} | 131 dispatcher_(dispatcher) {} |
| 126 | 132 |
| 127 void UnregisterOnConnectionClosed() { | 133 void UnregisterOnConnectionClosed() { |
| 128 LOG(ERROR) << "Unregistering " << connection_id(); | 134 LOG(ERROR) << "Unregistering " << connection_id(); |
| 129 dispatcher_->OnConnectionClosed(connection_id(), QUIC_NO_ERROR, | 135 dispatcher_->OnConnectionClosed(connection_id(), QUIC_NO_ERROR, |
| 130 "Unregistering."); | 136 "Unregistering."); |
| 131 } | 137 } |
| 132 | 138 |
| 133 private: | 139 private: |
| 134 QuicDispatcher* dispatcher_; | 140 QuicDispatcher* dispatcher_; |
| 135 }; | 141 }; |
| 136 | 142 |
| 137 QuicServerSessionBase* CreateSession( | 143 QuicServerSessionBase* CreateSession( |
| 138 QuicDispatcher* dispatcher, | 144 QuicDispatcher* dispatcher, |
| 139 const QuicConfig& config, | 145 const QuicConfig& config, |
| 140 QuicConnectionId connection_id, | 146 QuicConnectionId connection_id, |
| 141 const IPEndPoint& client_address, | 147 const IPEndPoint& client_address, |
| 142 MockConnectionHelper* helper, | 148 MockConnectionHelper* helper, |
| 149 MockAlarmFactory* alarm_factory, |
| 143 const QuicCryptoServerConfig* crypto_config, | 150 const QuicCryptoServerConfig* crypto_config, |
| 144 QuicCompressedCertsCache* compressed_certs_cache, | 151 QuicCompressedCertsCache* compressed_certs_cache, |
| 145 TestQuicSpdyServerSession** session) { | 152 TestQuicSpdyServerSession** session) { |
| 146 MockServerConnection* connection = | 153 MockServerConnection* connection = new MockServerConnection( |
| 147 new MockServerConnection(connection_id, helper, dispatcher); | 154 connection_id, helper, alarm_factory, dispatcher); |
| 148 *session = new TestQuicSpdyServerSession(config, connection, crypto_config, | 155 *session = new TestQuicSpdyServerSession(config, connection, crypto_config, |
| 149 compressed_certs_cache); | 156 compressed_certs_cache); |
| 150 connection->set_visitor(*session); | 157 connection->set_visitor(*session); |
| 151 ON_CALL(*connection, CloseConnection(_, _, _)) | 158 ON_CALL(*connection, CloseConnection(_, _, _)) |
| 152 .WillByDefault(WithoutArgs(Invoke( | 159 .WillByDefault(WithoutArgs(Invoke( |
| 153 connection, &MockServerConnection::UnregisterOnConnectionClosed))); | 160 connection, &MockServerConnection::UnregisterOnConnectionClosed))); |
| 154 EXPECT_CALL(*reinterpret_cast<MockConnection*>((*session)->connection()), | 161 EXPECT_CALL(*reinterpret_cast<MockConnection*>((*session)->connection()), |
| 155 ProcessUdpPacket(_, client_address, _)); | 162 ProcessUdpPacket(_, client_address, _)); |
| 156 | 163 |
| 157 return *session; | 164 return *session; |
| 158 } | 165 } |
| 159 | 166 |
| 160 class QuicDispatcherTest : public ::testing::Test { | 167 class QuicDispatcherTest : public ::testing::Test { |
| 161 public: | 168 public: |
| 162 QuicDispatcherTest() | 169 QuicDispatcherTest() |
| 163 : helper_(&eps_, QuicAllocator::BUFFER_POOL), | 170 : helper_(&eps_, QuicAllocator::BUFFER_POOL), |
| 171 alarm_factory_(&eps_), |
| 164 crypto_config_(QuicCryptoServerConfig::TESTING, | 172 crypto_config_(QuicCryptoServerConfig::TESTING, |
| 165 QuicRandom::GetInstance(), | 173 QuicRandom::GetInstance(), |
| 166 CryptoTestUtils::ProofSourceForTesting()), | 174 CryptoTestUtils::ProofSourceForTesting()), |
| 167 dispatcher_(config_, &crypto_config_, &eps_), | 175 dispatcher_(config_, &crypto_config_, &eps_), |
| 168 time_wait_list_manager_(nullptr), | 176 time_wait_list_manager_(nullptr), |
| 169 session1_(nullptr), | 177 session1_(nullptr), |
| 170 session2_(nullptr) { | 178 session2_(nullptr) { |
| 171 dispatcher_.InitializeWithWriter(new QuicDefaultPacketWriter(1)); | 179 dispatcher_.InitializeWithWriter(new QuicDefaultPacketWriter(1)); |
| 172 } | 180 } |
| 173 | 181 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 dispatcher_.ProcessPacket(server_address_, client_address, | 251 dispatcher_.ProcessPacket(server_address_, client_address, |
| 244 *received_packet); | 252 *received_packet); |
| 245 } | 253 } |
| 246 | 254 |
| 247 void ValidatePacket(const QuicEncryptedPacket& packet) { | 255 void ValidatePacket(const QuicEncryptedPacket& packet) { |
| 248 EXPECT_EQ(data_.length(), packet.AsStringPiece().length()); | 256 EXPECT_EQ(data_.length(), packet.AsStringPiece().length()); |
| 249 EXPECT_EQ(data_, packet.AsStringPiece()); | 257 EXPECT_EQ(data_, packet.AsStringPiece()); |
| 250 } | 258 } |
| 251 | 259 |
| 252 void CreateTimeWaitListManager() { | 260 void CreateTimeWaitListManager() { |
| 253 time_wait_list_manager_ = new MockTimeWaitListManager( | 261 time_wait_list_manager_ = |
| 254 QuicDispatcherPeer::GetWriter(&dispatcher_), &dispatcher_, &helper_); | 262 new MockTimeWaitListManager(QuicDispatcherPeer::GetWriter(&dispatcher_), |
| 263 &dispatcher_, &helper_, &alarm_factory_); |
| 255 // dispatcher_ takes the ownership of time_wait_list_manager_. | 264 // dispatcher_ takes the ownership of time_wait_list_manager_. |
| 256 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, | 265 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, |
| 257 time_wait_list_manager_); | 266 time_wait_list_manager_); |
| 258 } | 267 } |
| 259 | 268 |
| 260 EpollServer eps_; | 269 EpollServer eps_; |
| 261 QuicEpollConnectionHelper helper_; | 270 QuicEpollConnectionHelper helper_; |
| 262 MockConnectionHelper mock_helper_; | 271 MockConnectionHelper mock_helper_; |
| 272 QuicEpollAlarmFactory alarm_factory_; |
| 273 MockAlarmFactory mock_alarm_factory_; |
| 263 QuicConfig config_; | 274 QuicConfig config_; |
| 264 QuicCryptoServerConfig crypto_config_; | 275 QuicCryptoServerConfig crypto_config_; |
| 265 IPEndPoint server_address_; | 276 IPEndPoint server_address_; |
| 266 TestDispatcher dispatcher_; | 277 TestDispatcher dispatcher_; |
| 267 MockTimeWaitListManager* time_wait_list_manager_; | 278 MockTimeWaitListManager* time_wait_list_manager_; |
| 268 TestQuicSpdyServerSession* session1_; | 279 TestQuicSpdyServerSession* session1_; |
| 269 TestQuicSpdyServerSession* session2_; | 280 TestQuicSpdyServerSession* session2_; |
| 270 string data_; | 281 string data_; |
| 271 }; | 282 }; |
| 272 | 283 |
| 273 TEST_F(QuicDispatcherTest, ProcessPackets) { | 284 TEST_F(QuicDispatcherTest, ProcessPackets) { |
| 274 IPEndPoint client_address(net::test::Loopback4(), 1); | 285 IPEndPoint client_address(net::test::Loopback4(), 1); |
| 275 server_address_ = IPEndPoint(net::test::Any4(), 5); | 286 server_address_ = IPEndPoint(net::test::Any4(), 5); |
| 276 | 287 |
| 277 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) | 288 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) |
| 278 .WillOnce(testing::Return(CreateSession( | 289 .WillOnce(testing::Return(CreateSession( |
| 279 &dispatcher_, config_, 1, client_address, &mock_helper_, | 290 &dispatcher_, config_, 1, client_address, &mock_helper_, |
| 280 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), | 291 &mock_alarm_factory_, &crypto_config_, |
| 281 &session1_))); | 292 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); |
| 282 ProcessPacket(client_address, 1, true, false, "foo"); | 293 ProcessPacket(client_address, 1, true, false, "foo"); |
| 283 EXPECT_EQ(client_address, dispatcher_.current_client_address()); | 294 EXPECT_EQ(client_address, dispatcher_.current_client_address()); |
| 284 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); | 295 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); |
| 285 | 296 |
| 286 EXPECT_CALL(dispatcher_, CreateQuicSession(2, client_address)) | 297 EXPECT_CALL(dispatcher_, CreateQuicSession(2, client_address)) |
| 287 .WillOnce(testing::Return(CreateSession( | 298 .WillOnce(testing::Return(CreateSession( |
| 288 &dispatcher_, config_, 2, client_address, &mock_helper_, | 299 &dispatcher_, config_, 2, client_address, &mock_helper_, |
| 289 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), | 300 &mock_alarm_factory_, &crypto_config_, |
| 290 &session2_))); | 301 QuicDispatcherPeer::GetCache(&dispatcher_), &session2_))); |
| 291 ProcessPacket(client_address, 2, true, false, "bar"); | 302 ProcessPacket(client_address, 2, true, false, "bar"); |
| 292 | 303 |
| 293 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), | 304 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), |
| 294 ProcessUdpPacket(_, _, _)) | 305 ProcessUdpPacket(_, _, _)) |
| 295 .Times(1) | 306 .Times(1) |
| 296 .WillOnce(testing::WithArgs<2>( | 307 .WillOnce(testing::WithArgs<2>( |
| 297 Invoke(this, &QuicDispatcherTest::ValidatePacket))); | 308 Invoke(this, &QuicDispatcherTest::ValidatePacket))); |
| 298 ProcessPacket(client_address, 1, false, false, "eep"); | 309 ProcessPacket(client_address, 1, false, false, "eep"); |
| 299 } | 310 } |
| 300 | 311 |
| 301 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) { | 312 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) { |
| 302 ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, true); | 313 ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, true); |
| 303 IPEndPoint client_address(net::test::Loopback4(), 1); | 314 IPEndPoint client_address(net::test::Loopback4(), 1); |
| 304 server_address_ = IPEndPoint(net::test::Any4(), 5); | 315 server_address_ = IPEndPoint(net::test::Any4(), 5); |
| 305 | 316 |
| 306 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0); | 317 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0); |
| 307 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); | 318 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); |
| 308 ProcessPacket(client_address, 1, true, version, "foo", | 319 ProcessPacket(client_address, 1, true, version, "foo", |
| 309 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); | 320 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); |
| 310 } | 321 } |
| 311 | 322 |
| 312 TEST_F(QuicDispatcherTest, StatefulVersionNegotiation) { | 323 TEST_F(QuicDispatcherTest, StatefulVersionNegotiation) { |
| 313 ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, false); | 324 ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, false); |
| 314 IPEndPoint client_address(net::test::Loopback4(), 1); | 325 IPEndPoint client_address(net::test::Loopback4(), 1); |
| 315 server_address_ = IPEndPoint(net::test::Any4(), 5); | 326 server_address_ = IPEndPoint(net::test::Any4(), 5); |
| 316 | 327 |
| 317 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) | 328 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) |
| 318 .WillOnce(testing::Return(CreateSession( | 329 .WillOnce(testing::Return(CreateSession( |
| 319 &dispatcher_, config_, 1, client_address, &mock_helper_, | 330 &dispatcher_, config_, 1, client_address, &mock_helper_, |
| 320 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), | 331 &mock_alarm_factory_, &crypto_config_, |
| 321 &session1_))); | 332 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); |
| 322 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); | 333 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); |
| 323 ProcessPacket(client_address, 1, true, version, "foo", | 334 ProcessPacket(client_address, 1, true, version, "foo", |
| 324 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); | 335 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); |
| 325 } | 336 } |
| 326 | 337 |
| 327 TEST_F(QuicDispatcherTest, Shutdown) { | 338 TEST_F(QuicDispatcherTest, Shutdown) { |
| 328 IPEndPoint client_address(net::test::Loopback4(), 1); | 339 IPEndPoint client_address(net::test::Loopback4(), 1); |
| 329 | 340 |
| 330 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) | 341 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) |
| 331 .WillOnce(testing::Return(CreateSession( | 342 .WillOnce(testing::Return(CreateSession( |
| 332 &dispatcher_, config_, 1, client_address, &mock_helper_, | 343 &dispatcher_, config_, 1, client_address, &mock_helper_, |
| 333 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), | 344 &mock_alarm_factory_, &crypto_config_, |
| 334 &session1_))); | 345 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); |
| 335 | 346 |
| 336 ProcessPacket(client_address, 1, true, false, "foo"); | 347 ProcessPacket(client_address, 1, true, false, "foo"); |
| 337 | 348 |
| 338 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), | 349 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), |
| 339 CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); | 350 CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); |
| 340 | 351 |
| 341 dispatcher_.Shutdown(); | 352 dispatcher_.Shutdown(); |
| 342 } | 353 } |
| 343 | 354 |
| 344 TEST_F(QuicDispatcherTest, TimeWaitListManager) { | 355 TEST_F(QuicDispatcherTest, TimeWaitListManager) { |
| 345 CreateTimeWaitListManager(); | 356 CreateTimeWaitListManager(); |
| 346 | 357 |
| 347 // Create a new session. | 358 // Create a new session. |
| 348 IPEndPoint client_address(net::test::Loopback4(), 1); | 359 IPEndPoint client_address(net::test::Loopback4(), 1); |
| 349 QuicConnectionId connection_id = 1; | 360 QuicConnectionId connection_id = 1; |
| 350 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) | 361 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) |
| 351 .WillOnce(testing::Return(CreateSession( | 362 .WillOnce(testing::Return(CreateSession( |
| 352 &dispatcher_, config_, connection_id, client_address, &mock_helper_, | 363 &dispatcher_, config_, connection_id, client_address, &mock_helper_, |
| 353 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), | 364 &mock_alarm_factory_, &crypto_config_, |
| 354 &session1_))); | 365 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); |
| 355 ProcessPacket(client_address, connection_id, true, false, "foo"); | 366 ProcessPacket(client_address, connection_id, true, false, "foo"); |
| 356 | 367 |
| 357 // Close the connection by sending public reset packet. | 368 // Close the connection by sending public reset packet. |
| 358 QuicPublicResetPacket packet; | 369 QuicPublicResetPacket packet; |
| 359 packet.public_header.connection_id = connection_id; | 370 packet.public_header.connection_id = connection_id; |
| 360 packet.public_header.reset_flag = true; | 371 packet.public_header.reset_flag = true; |
| 361 packet.public_header.version_flag = false; | 372 packet.public_header.version_flag = false; |
| 362 packet.rejected_packet_number = 19191; | 373 packet.rejected_packet_number = 19191; |
| 363 packet.nonce_proof = 132232; | 374 packet.nonce_proof = 132232; |
| 364 std::unique_ptr<QuicEncryptedPacket> encrypted( | 375 std::unique_ptr<QuicEncryptedPacket> encrypted( |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 !GetParam().crypto_handshake_successful && | 503 !GetParam().crypto_handshake_successful && |
| 493 GetParam().client_supports_statelesss_rejects; | 504 GetParam().client_supports_statelesss_rejects; |
| 494 } | 505 } |
| 495 | 506 |
| 496 // Sets up dispatcher_, sesession1_, and crypto_stream1_ based on | 507 // Sets up dispatcher_, sesession1_, and crypto_stream1_ based on |
| 497 // the test parameters. | 508 // the test parameters. |
| 498 QuicServerSessionBase* CreateSessionBasedOnTestParams( | 509 QuicServerSessionBase* CreateSessionBasedOnTestParams( |
| 499 QuicConnectionId connection_id, | 510 QuicConnectionId connection_id, |
| 500 const IPEndPoint& client_address) { | 511 const IPEndPoint& client_address) { |
| 501 CreateSession(&dispatcher_, config_, connection_id, client_address, | 512 CreateSession(&dispatcher_, config_, connection_id, client_address, |
| 502 &mock_helper_, &crypto_config_, | 513 &mock_helper_, &mock_alarm_factory_, &crypto_config_, |
| 503 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_); | 514 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_); |
| 504 | 515 |
| 505 crypto_stream1_ = new MockQuicCryptoServerStream( | 516 crypto_stream1_ = new MockQuicCryptoServerStream( |
| 506 crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), session1_); | 517 crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), session1_); |
| 507 session1_->SetCryptoStream(crypto_stream1_); | 518 session1_->SetCryptoStream(crypto_stream1_); |
| 508 crypto_stream1_->set_handshake_confirmed_for_testing( | 519 crypto_stream1_->set_handshake_confirmed_for_testing( |
| 509 GetParam().crypto_handshake_successful); | 520 GetParam().crypto_handshake_successful); |
| 510 crypto_stream1_->SetPeerSupportsStatelessRejects( | 521 crypto_stream1_->SetPeerSupportsStatelessRejects( |
| 511 GetParam().client_supports_statelesss_rejects); | 522 GetParam().client_supports_statelesss_rejects); |
| 512 return session1_; | 523 return session1_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 530 } | 541 } |
| 531 | 542 |
| 532 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) { | 543 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) { |
| 533 IPEndPoint client_address(net::test::Loopback4(), 1); | 544 IPEndPoint client_address(net::test::Loopback4(), 1); |
| 534 QuicConnectionId connection_id = 1; | 545 QuicConnectionId connection_id = 1; |
| 535 server_address_ = IPEndPoint(net::test::Any4(), 5); | 546 server_address_ = IPEndPoint(net::test::Any4(), 5); |
| 536 | 547 |
| 537 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) | 548 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) |
| 538 .WillOnce(testing::Return(CreateSession( | 549 .WillOnce(testing::Return(CreateSession( |
| 539 &dispatcher_, config_, 1, client_address, &mock_helper_, | 550 &dispatcher_, config_, 1, client_address, &mock_helper_, |
| 540 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), | 551 &mock_alarm_factory_, &crypto_config_, |
| 541 &session1_))); | 552 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); |
| 542 // A packet whose packet number is the largest that is allowed to start a | 553 // A packet whose packet number is the largest that is allowed to start a |
| 543 // connection. | 554 // connection. |
| 544 ProcessPacket(client_address, connection_id, true, false, "data", | 555 ProcessPacket(client_address, connection_id, true, false, "data", |
| 545 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, | 556 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, |
| 546 kDefaultPathId, | 557 kDefaultPathId, |
| 547 QuicDispatcher::kMaxReasonableInitialPacketNumber); | 558 QuicDispatcher::kMaxReasonableInitialPacketNumber); |
| 548 EXPECT_EQ(client_address, dispatcher_.current_client_address()); | 559 EXPECT_EQ(client_address, dispatcher_.current_client_address()); |
| 549 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); | 560 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); |
| 550 } | 561 } |
| 551 | 562 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest { | 684 class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest { |
| 674 public: | 685 public: |
| 675 void SetUp() override { | 686 void SetUp() override { |
| 676 writer_ = new BlockingWriter; | 687 writer_ = new BlockingWriter; |
| 677 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_); | 688 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_); |
| 678 | 689 |
| 679 IPEndPoint client_address(net::test::Loopback4(), 1); | 690 IPEndPoint client_address(net::test::Loopback4(), 1); |
| 680 | 691 |
| 681 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) | 692 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) |
| 682 .WillOnce(testing::Return(CreateSession( | 693 .WillOnce(testing::Return(CreateSession( |
| 683 &dispatcher_, config_, 1, client_address, &helper_, &crypto_config_, | 694 &dispatcher_, config_, 1, client_address, &helper_, &alarm_factory_, |
| 684 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); | 695 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), |
| 696 &session1_))); |
| 685 ProcessPacket(client_address, 1, true, false, "foo"); | 697 ProcessPacket(client_address, 1, true, false, "foo"); |
| 686 | 698 |
| 687 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) | 699 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) |
| 688 .WillOnce(testing::Return(CreateSession( | 700 .WillOnce(testing::Return(CreateSession( |
| 689 &dispatcher_, config_, 2, client_address, &helper_, &crypto_config_, | 701 &dispatcher_, config_, 2, client_address, &helper_, &alarm_factory_, |
| 690 QuicDispatcherPeer::GetCache(&dispatcher_), &session2_))); | 702 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), |
| 703 &session2_))); |
| 691 ProcessPacket(client_address, 2, true, false, "bar"); | 704 ProcessPacket(client_address, 2, true, false, "bar"); |
| 692 | 705 |
| 693 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_); | 706 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_); |
| 694 } | 707 } |
| 695 | 708 |
| 696 void TearDown() override { | 709 void TearDown() override { |
| 697 EXPECT_CALL(*connection1(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); | 710 EXPECT_CALL(*connection1(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); |
| 698 EXPECT_CALL(*connection2(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); | 711 EXPECT_CALL(*connection2(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); |
| 699 dispatcher_.Shutdown(); | 712 dispatcher_.Shutdown(); |
| 700 } | 713 } |
| 701 | 714 |
| 702 void SetBlocked() { writer_->write_blocked_ = true; } | 715 void SetBlocked() { writer_->write_blocked_ = true; } |
| 703 | 716 |
| 704 void BlockConnection2() { | 717 void BlockConnection2() { |
| 705 writer_->write_blocked_ = true; | 718 writer_->write_blocked_ = true; |
| 706 dispatcher_.OnWriteBlocked(connection2()); | 719 dispatcher_.OnWriteBlocked(connection2()); |
| 707 } | 720 } |
| 708 | 721 |
| 709 protected: | 722 protected: |
| 710 MockConnectionHelper helper_; | 723 MockConnectionHelper helper_; |
| 724 MockAlarmFactory alarm_factory_; |
| 711 BlockingWriter* writer_; | 725 BlockingWriter* writer_; |
| 712 QuicDispatcher::WriteBlockedList* blocked_list_; | 726 QuicDispatcher::WriteBlockedList* blocked_list_; |
| 713 }; | 727 }; |
| 714 | 728 |
| 715 TEST_F(QuicDispatcherWriteBlockedListTest, BasicOnCanWrite) { | 729 TEST_F(QuicDispatcherWriteBlockedListTest, BasicOnCanWrite) { |
| 716 // No OnCanWrite calls because no connections are blocked. | 730 // No OnCanWrite calls because no connections are blocked. |
| 717 dispatcher_.OnCanWrite(); | 731 dispatcher_.OnCanWrite(); |
| 718 | 732 |
| 719 // Register connection 1 for events, and make sure it's notified. | 733 // Register connection 1 for events, and make sure it's notified. |
| 720 SetBlocked(); | 734 SetBlocked(); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 | 853 |
| 840 // And we'll resume where we left off when we get another call. | 854 // And we'll resume where we left off when we get another call. |
| 841 EXPECT_CALL(*connection2(), OnCanWrite()); | 855 EXPECT_CALL(*connection2(), OnCanWrite()); |
| 842 dispatcher_.OnCanWrite(); | 856 dispatcher_.OnCanWrite(); |
| 843 EXPECT_FALSE(dispatcher_.HasPendingWrites()); | 857 EXPECT_FALSE(dispatcher_.HasPendingWrites()); |
| 844 } | 858 } |
| 845 | 859 |
| 846 } // namespace | 860 } // namespace |
| 847 } // namespace test | 861 } // namespace test |
| 848 } // namespace net | 862 } // namespace net |
| OLD | NEW |