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