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