| 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 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 MockQuicConnection* connection2() { | 201 MockQuicConnection* connection2() { |
| 202 return reinterpret_cast<MockQuicConnection*>(session2_->connection()); | 202 return reinterpret_cast<MockQuicConnection*>(session2_->connection()); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // Process a packet with an 8 byte connection id, | 205 // Process a packet with an 8 byte connection id, |
| 206 // 6 byte packet number, default path id, and packet number 1, | 206 // 6 byte packet number, default path id, and packet number 1, |
| 207 // using the first supported version. | 207 // using the first supported version. |
| 208 void ProcessPacket(QuicSocketAddress client_address, | 208 void ProcessPacket(QuicSocketAddress client_address, |
| 209 QuicConnectionId connection_id, | 209 QuicConnectionId connection_id, |
| 210 bool has_version_flag, | 210 bool has_version_flag, |
| 211 bool has_multipath_flag, | |
| 212 const string& data) { | 211 const string& data) { |
| 213 ProcessPacket(client_address, connection_id, has_version_flag, | 212 ProcessPacket(client_address, connection_id, has_version_flag, data, |
| 214 has_multipath_flag, data, PACKET_8BYTE_CONNECTION_ID, | 213 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER); |
| 215 PACKET_6BYTE_PACKET_NUMBER); | |
| 216 } | 214 } |
| 217 | 215 |
| 218 // Process a packet with a default path id, and packet number 1, | 216 // Process a packet with a default path id, and packet number 1, |
| 219 // using the first supported version. | 217 // using the first supported version. |
| 220 void ProcessPacket(QuicSocketAddress client_address, | 218 void ProcessPacket(QuicSocketAddress client_address, |
| 221 QuicConnectionId connection_id, | 219 QuicConnectionId connection_id, |
| 222 bool has_version_flag, | 220 bool has_version_flag, |
| 223 bool has_multipath_flag, | |
| 224 const string& data, | 221 const string& data, |
| 225 QuicConnectionIdLength connection_id_length, | 222 QuicConnectionIdLength connection_id_length, |
| 226 QuicPacketNumberLength packet_number_length) { | 223 QuicPacketNumberLength packet_number_length) { |
| 227 ProcessPacket(client_address, connection_id, has_version_flag, | 224 ProcessPacket(client_address, connection_id, has_version_flag, data, |
| 228 has_multipath_flag, data, connection_id_length, | 225 connection_id_length, packet_number_length, 1); |
| 229 packet_number_length, 1); | |
| 230 } | 226 } |
| 231 | 227 |
| 232 // Process a packet using the first supported version. | 228 // Process a packet using the first supported version. |
| 233 void ProcessPacket(QuicSocketAddress client_address, | 229 void ProcessPacket(QuicSocketAddress client_address, |
| 234 QuicConnectionId connection_id, | 230 QuicConnectionId connection_id, |
| 235 bool has_version_flag, | 231 bool has_version_flag, |
| 236 bool has_multipath_flag, | |
| 237 const string& data, | 232 const string& data, |
| 238 QuicConnectionIdLength connection_id_length, | 233 QuicConnectionIdLength connection_id_length, |
| 239 QuicPacketNumberLength packet_number_length, | 234 QuicPacketNumberLength packet_number_length, |
| 240 QuicPacketNumber packet_number) { | 235 QuicPacketNumber packet_number) { |
| 241 ProcessPacket(client_address, connection_id, has_version_flag, | 236 ProcessPacket(client_address, connection_id, has_version_flag, |
| 242 CurrentSupportedVersions().front(), data, | 237 CurrentSupportedVersions().front(), data, |
| 243 connection_id_length, packet_number_length, packet_number); | 238 connection_id_length, packet_number_length, packet_number); |
| 244 } | 239 } |
| 245 | 240 |
| 246 // Processes a packet. | 241 // Processes a packet. |
| 247 void ProcessPacket(QuicSocketAddress client_address, | 242 void ProcessPacket(QuicSocketAddress client_address, |
| 248 QuicConnectionId connection_id, | 243 QuicConnectionId connection_id, |
| 249 bool has_version_flag, | 244 bool has_version_flag, |
| 250 QuicVersion version, | 245 QuicVersion version, |
| 251 const string& data, | 246 const string& data, |
| 252 QuicConnectionIdLength connection_id_length, | 247 QuicConnectionIdLength connection_id_length, |
| 253 QuicPacketNumberLength packet_number_length, | 248 QuicPacketNumberLength packet_number_length, |
| 254 QuicPacketNumber packet_number) { | 249 QuicPacketNumber packet_number) { |
| 255 QuicVersionVector versions(SupportedVersions(version)); | 250 QuicVersionVector versions(SupportedVersions(version)); |
| 256 std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( | 251 std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
| 257 connection_id, has_version_flag, false, false, packet_number, data, | 252 connection_id, has_version_flag, false, packet_number, data, |
| 258 connection_id_length, packet_number_length, &versions)); | 253 connection_id_length, packet_number_length, &versions)); |
| 259 std::unique_ptr<QuicReceivedPacket> received_packet( | 254 std::unique_ptr<QuicReceivedPacket> received_packet( |
| 260 ConstructReceivedPacket(*packet, helper_.GetClock()->Now())); | 255 ConstructReceivedPacket(*packet, helper_.GetClock()->Now())); |
| 261 | 256 |
| 262 if (ChloExtractor::Extract(*packet, versions, nullptr)) { | 257 if (ChloExtractor::Extract(*packet, versions, nullptr)) { |
| 263 // Add CHLO packet to the beginning to be verified first, because it is | 258 // Add CHLO packet to the beginning to be verified first, because it is |
| 264 // also processed first by new session. | 259 // also processed first by new session. |
| 265 data_connection_map_[connection_id].push_front( | 260 data_connection_map_[connection_id].push_front( |
| 266 string(packet->data(), packet->length())); | 261 string(packet->data(), packet->length())); |
| 267 } else { | 262 } else { |
| 268 // For non-CHLO, always append to last. | 263 // For non-CHLO, always append to last. |
| 269 data_connection_map_[connection_id].push_back( | 264 data_connection_map_[connection_id].push_back( |
| 270 string(packet->data(), packet->length())); | 265 string(packet->data(), packet->length())); |
| 271 } | 266 } |
| 272 dispatcher_->ProcessPacket(server_address_, client_address, | 267 dispatcher_->ProcessPacket(server_address_, client_address, |
| 273 *received_packet); | 268 *received_packet); |
| 274 } | 269 } |
| 275 | 270 |
| 276 void ValidatePacket(QuicConnectionId conn_id, | 271 void ValidatePacket(QuicConnectionId conn_id, |
| 277 const QuicEncryptedPacket& packet) { | 272 const QuicEncryptedPacket& packet) { |
| 278 EXPECT_EQ(data_connection_map_[conn_id].front().length(), | 273 EXPECT_EQ(data_connection_map_[conn_id].front().length(), |
| 279 packet.AsStringPiece().length()); | 274 packet.AsStringPiece().length()); |
| 280 EXPECT_EQ(data_connection_map_[conn_id].front(), packet.AsStringPiece()); | 275 EXPECT_EQ(data_connection_map_[conn_id].front(), |
| 276 packet.AsStringPiece().as_string()); |
| 281 data_connection_map_[conn_id].pop_front(); | 277 data_connection_map_[conn_id].pop_front(); |
| 282 } | 278 } |
| 283 | 279 |
| 284 QuicServerSessionBase* CreateSession( | 280 QuicServerSessionBase* CreateSession( |
| 285 QuicDispatcher* dispatcher, | 281 QuicDispatcher* dispatcher, |
| 286 const QuicConfig& config, | 282 const QuicConfig& config, |
| 287 QuicConnectionId connection_id, | 283 QuicConnectionId connection_id, |
| 288 const QuicSocketAddress& client_address, | 284 const QuicSocketAddress& client_address, |
| 289 MockQuicConnectionHelper* helper, | 285 MockQuicConnectionHelper* helper, |
| 290 MockAlarmFactory* alarm_factory, | 286 MockAlarmFactory* alarm_factory, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 337 |
| 342 EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address)) | 338 EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address)) |
| 343 .WillOnce(testing::Return(CreateSession( | 339 .WillOnce(testing::Return(CreateSession( |
| 344 dispatcher_.get(), config_, 1, client_address, &mock_helper_, | 340 dispatcher_.get(), config_, 1, client_address, &mock_helper_, |
| 345 &mock_alarm_factory_, &crypto_config_, | 341 &mock_alarm_factory_, &crypto_config_, |
| 346 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 342 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 347 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 343 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 348 ProcessUdpPacket(_, _, _)) | 344 ProcessUdpPacket(_, _, _)) |
| 349 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( | 345 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( |
| 350 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1)))); | 346 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1)))); |
| 351 ProcessPacket(client_address, 1, true, false, SerializeCHLO()); | 347 ProcessPacket(client_address, 1, true, SerializeCHLO()); |
| 352 EXPECT_EQ(client_address, dispatcher_->current_client_address()); | 348 EXPECT_EQ(client_address, dispatcher_->current_client_address()); |
| 353 EXPECT_EQ(server_address_, dispatcher_->current_server_address()); | 349 EXPECT_EQ(server_address_, dispatcher_->current_server_address()); |
| 354 | 350 |
| 355 EXPECT_CALL(*dispatcher_, CreateQuicSession(2, client_address)) | 351 EXPECT_CALL(*dispatcher_, CreateQuicSession(2, client_address)) |
| 356 .WillOnce(testing::Return(CreateSession( | 352 .WillOnce(testing::Return(CreateSession( |
| 357 dispatcher_.get(), config_, 2, client_address, &mock_helper_, | 353 dispatcher_.get(), config_, 2, client_address, &mock_helper_, |
| 358 &mock_alarm_factory_, &crypto_config_, | 354 &mock_alarm_factory_, &crypto_config_, |
| 359 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session2_))); | 355 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session2_))); |
| 360 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session2_->connection()), | 356 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session2_->connection()), |
| 361 ProcessUdpPacket(_, _, _)) | 357 ProcessUdpPacket(_, _, _)) |
| 362 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( | 358 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( |
| 363 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 2)))); | 359 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 2)))); |
| 364 ProcessPacket(client_address, 2, true, false, SerializeCHLO()); | 360 ProcessPacket(client_address, 2, true, SerializeCHLO()); |
| 365 | 361 |
| 366 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 362 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 367 ProcessUdpPacket(_, _, _)) | 363 ProcessUdpPacket(_, _, _)) |
| 368 .Times(1) | 364 .Times(1) |
| 369 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( | 365 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( |
| 370 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1)))); | 366 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1)))); |
| 371 ProcessPacket(client_address, 1, false, false, "data"); | 367 ProcessPacket(client_address, 1, false, "data"); |
| 372 } | 368 } |
| 373 | 369 |
| 374 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) { | 370 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) { |
| 375 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 371 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 376 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); | 372 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); |
| 377 | 373 |
| 378 EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address)).Times(0); | 374 EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address)).Times(0); |
| 379 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); | 375 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); |
| 380 ProcessPacket(client_address, 1, true, version, SerializeCHLO(), | 376 ProcessPacket(client_address, 1, true, version, SerializeCHLO(), |
| 381 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); | 377 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); |
| 382 } | 378 } |
| 383 | 379 |
| 384 TEST_F(QuicDispatcherTest, Shutdown) { | 380 TEST_F(QuicDispatcherTest, Shutdown) { |
| 385 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 381 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 386 | 382 |
| 387 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address)) | 383 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address)) |
| 388 .WillOnce(testing::Return(CreateSession( | 384 .WillOnce(testing::Return(CreateSession( |
| 389 dispatcher_.get(), config_, 1, client_address, &mock_helper_, | 385 dispatcher_.get(), config_, 1, client_address, &mock_helper_, |
| 390 &mock_alarm_factory_, &crypto_config_, | 386 &mock_alarm_factory_, &crypto_config_, |
| 391 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 387 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 392 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 388 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 393 ProcessUdpPacket(_, _, _)) | 389 ProcessUdpPacket(_, _, _)) |
| 394 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( | 390 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( |
| 395 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1)))); | 391 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1)))); |
| 396 | 392 |
| 397 ProcessPacket(client_address, 1, true, false, SerializeCHLO()); | 393 ProcessPacket(client_address, 1, true, SerializeCHLO()); |
| 398 | 394 |
| 399 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 395 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 400 CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); | 396 CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); |
| 401 | 397 |
| 402 dispatcher_->Shutdown(); | 398 dispatcher_->Shutdown(); |
| 403 } | 399 } |
| 404 | 400 |
| 405 TEST_F(QuicDispatcherTest, TimeWaitListManager) { | 401 TEST_F(QuicDispatcherTest, TimeWaitListManager) { |
| 406 CreateTimeWaitListManager(); | 402 CreateTimeWaitListManager(); |
| 407 | 403 |
| 408 // Create a new session. | 404 // Create a new session. |
| 409 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 405 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 410 QuicConnectionId connection_id = 1; | 406 QuicConnectionId connection_id = 1; |
| 411 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address)) | 407 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address)) |
| 412 .WillOnce(testing::Return(CreateSession( | 408 .WillOnce(testing::Return(CreateSession( |
| 413 dispatcher_.get(), config_, connection_id, client_address, | 409 dispatcher_.get(), config_, connection_id, client_address, |
| 414 &mock_helper_, &mock_alarm_factory_, &crypto_config_, | 410 &mock_helper_, &mock_alarm_factory_, &crypto_config_, |
| 415 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 411 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 416 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 412 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 417 ProcessUdpPacket(_, _, _)) | 413 ProcessUdpPacket(_, _, _)) |
| 418 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( | 414 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( |
| 419 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1)))); | 415 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1)))); |
| 420 | 416 |
| 421 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO()); | 417 ProcessPacket(client_address, connection_id, true, SerializeCHLO()); |
| 422 | 418 |
| 423 // Close the connection by sending public reset packet. | 419 // Close the connection by sending public reset packet. |
| 424 QuicPublicResetPacket packet; | 420 QuicPublicResetPacket packet; |
| 425 packet.public_header.connection_id = connection_id; | 421 packet.public_header.connection_id = connection_id; |
| 426 packet.public_header.reset_flag = true; | 422 packet.public_header.reset_flag = true; |
| 427 packet.public_header.version_flag = false; | 423 packet.public_header.version_flag = false; |
| 428 packet.rejected_packet_number = 19191; | 424 packet.rejected_packet_number = 19191; |
| 429 packet.nonce_proof = 132232; | 425 packet.nonce_proof = 132232; |
| 430 std::unique_ptr<QuicEncryptedPacket> encrypted( | 426 std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 431 QuicFramer::BuildPublicResetPacket(packet)); | 427 QuicFramer::BuildPublicResetPacket(packet)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 445 dispatcher_->ProcessPacket(QuicSocketAddress(), client_address, *received); | 441 dispatcher_->ProcessPacket(QuicSocketAddress(), client_address, *received); |
| 446 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); | 442 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); |
| 447 | 443 |
| 448 // Dispatcher forwards subsequent packets for this connection_id to the time | 444 // Dispatcher forwards subsequent packets for this connection_id to the time |
| 449 // wait list manager. | 445 // wait list manager. |
| 450 EXPECT_CALL(*time_wait_list_manager_, | 446 EXPECT_CALL(*time_wait_list_manager_, |
| 451 ProcessPacket(_, _, connection_id, _, _)) | 447 ProcessPacket(_, _, connection_id, _, _)) |
| 452 .Times(1); | 448 .Times(1); |
| 453 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) | 449 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) |
| 454 .Times(0); | 450 .Times(0); |
| 455 ProcessPacket(client_address, connection_id, true, false, "data"); | 451 ProcessPacket(client_address, connection_id, true, "data"); |
| 456 } | 452 } |
| 457 | 453 |
| 458 TEST_F(QuicDispatcherTest, NoVersionPacketToTimeWaitListManager) { | 454 TEST_F(QuicDispatcherTest, NoVersionPacketToTimeWaitListManager) { |
| 459 CreateTimeWaitListManager(); | 455 CreateTimeWaitListManager(); |
| 460 | 456 |
| 461 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 457 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 462 QuicConnectionId connection_id = 1; | 458 QuicConnectionId connection_id = 1; |
| 463 // Dispatcher forwards all packets for this connection_id to the time wait | 459 // Dispatcher forwards all packets for this connection_id to the time wait |
| 464 // list manager. | 460 // list manager. |
| 465 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0); | 461 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0); |
| 466 EXPECT_CALL(*time_wait_list_manager_, | 462 EXPECT_CALL(*time_wait_list_manager_, |
| 467 ProcessPacket(_, _, connection_id, _, _)) | 463 ProcessPacket(_, _, connection_id, _, _)) |
| 468 .Times(1); | 464 .Times(1); |
| 469 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) | 465 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) |
| 470 .Times(1); | 466 .Times(1); |
| 471 ProcessPacket(client_address, connection_id, false, false, SerializeCHLO()); | 467 ProcessPacket(client_address, connection_id, false, SerializeCHLO()); |
| 472 } | 468 } |
| 473 | 469 |
| 474 TEST_F(QuicDispatcherTest, ProcessPacketWithZeroPort) { | 470 TEST_F(QuicDispatcherTest, ProcessPacketWithZeroPort) { |
| 475 CreateTimeWaitListManager(); | 471 CreateTimeWaitListManager(); |
| 476 | 472 |
| 477 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 0); | 473 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 0); |
| 478 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); | 474 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); |
| 479 | 475 |
| 480 // dispatcher_ should drop this packet. | 476 // dispatcher_ should drop this packet. |
| 481 EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address)).Times(0); | 477 EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address)).Times(0); |
| 482 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0); | 478 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0); |
| 483 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) | 479 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) |
| 484 .Times(0); | 480 .Times(0); |
| 485 ProcessPacket(client_address, 1, true, false, SerializeCHLO()); | 481 ProcessPacket(client_address, 1, true, SerializeCHLO()); |
| 486 } | 482 } |
| 487 | 483 |
| 488 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) { | 484 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) { |
| 489 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 485 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 490 QuicConnectionId connection_id = 1; | 486 QuicConnectionId connection_id = 1; |
| 491 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); | 487 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); |
| 492 | 488 |
| 493 EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address)) | 489 EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address)) |
| 494 .WillOnce(testing::Return(CreateSession( | 490 .WillOnce(testing::Return(CreateSession( |
| 495 dispatcher_.get(), config_, 1, client_address, &mock_helper_, | 491 dispatcher_.get(), config_, 1, client_address, &mock_helper_, |
| 496 &mock_alarm_factory_, &crypto_config_, | 492 &mock_alarm_factory_, &crypto_config_, |
| 497 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 493 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 498 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 494 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 499 ProcessUdpPacket(_, _, _)) | 495 ProcessUdpPacket(_, _, _)) |
| 500 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( | 496 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( |
| 501 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1)))); | 497 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1)))); |
| 502 // A packet whose packet number is the largest that is allowed to start a | 498 // A packet whose packet number is the largest that is allowed to start a |
| 503 // connection. | 499 // connection. |
| 504 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO(), | 500 ProcessPacket(client_address, connection_id, true, SerializeCHLO(), |
| 505 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, | 501 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, |
| 506 QuicDispatcher::kMaxReasonableInitialPacketNumber); | 502 QuicDispatcher::kMaxReasonableInitialPacketNumber); |
| 507 EXPECT_EQ(client_address, dispatcher_->current_client_address()); | 503 EXPECT_EQ(client_address, dispatcher_->current_client_address()); |
| 508 EXPECT_EQ(server_address_, dispatcher_->current_server_address()); | 504 EXPECT_EQ(server_address_, dispatcher_->current_server_address()); |
| 509 } | 505 } |
| 510 | 506 |
| 511 TEST_F(QuicDispatcherTest, TooBigSeqNoPacketToTimeWaitListManager) { | 507 TEST_F(QuicDispatcherTest, TooBigSeqNoPacketToTimeWaitListManager) { |
| 512 CreateTimeWaitListManager(); | 508 CreateTimeWaitListManager(); |
| 513 | 509 |
| 514 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 510 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 515 QuicConnectionId connection_id = 1; | 511 QuicConnectionId connection_id = 1; |
| 516 // Dispatcher forwards this packet for this connection_id to the time wait | 512 // Dispatcher forwards this packet for this connection_id to the time wait |
| 517 // list manager. | 513 // list manager. |
| 518 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0); | 514 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0); |
| 519 EXPECT_CALL(*time_wait_list_manager_, | 515 EXPECT_CALL(*time_wait_list_manager_, |
| 520 ProcessPacket(_, _, connection_id, _, _)) | 516 ProcessPacket(_, _, connection_id, _, _)) |
| 521 .Times(1); | 517 .Times(1); |
| 522 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) | 518 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) |
| 523 .Times(1); | 519 .Times(1); |
| 524 // A packet whose packet number is one to large to be allowed to start a | 520 // A packet whose packet number is one to large to be allowed to start a |
| 525 // connection. | 521 // connection. |
| 526 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO(), | 522 ProcessPacket(client_address, connection_id, true, SerializeCHLO(), |
| 527 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, | 523 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, |
| 528 QuicDispatcher::kMaxReasonableInitialPacketNumber + 1); | 524 QuicDispatcher::kMaxReasonableInitialPacketNumber + 1); |
| 529 } | 525 } |
| 530 | 526 |
| 531 TEST_F(QuicDispatcherTest, SupportedVersionsChangeInFlight) { | 527 TEST_F(QuicDispatcherTest, SupportedVersionsChangeInFlight) { |
| 532 static_assert(arraysize(kSupportedQuicVersions) == 5u, | 528 static_assert(arraysize(kSupportedQuicVersions) == 5u, |
| 533 "Supported versions out of sync"); | 529 "Supported versions out of sync"); |
| 534 FLAGS_quic_reloadable_flag_quic_disable_version_34 = false; | 530 FLAGS_quic_reloadable_flag_quic_disable_version_34 = false; |
| 535 FLAGS_quic_reloadable_flag_quic_enable_version_36_v3 = true; | 531 FLAGS_quic_reloadable_flag_quic_enable_version_36_v3 = true; |
| 536 FLAGS_quic_reloadable_flag_quic_enable_version_37 = true; | 532 FLAGS_quic_reloadable_flag_quic_enable_version_37 = true; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 QuicConnectionId connection_id = 1; | 751 QuicConnectionId connection_id = 1; |
| 756 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address)) | 752 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address)) |
| 757 .WillOnce(testing::Return( | 753 .WillOnce(testing::Return( |
| 758 CreateSessionBasedOnTestParams(connection_id, client_address))); | 754 CreateSessionBasedOnTestParams(connection_id, client_address))); |
| 759 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 755 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 760 ProcessUdpPacket(_, _, _)) | 756 ProcessUdpPacket(_, _, _)) |
| 761 .WillOnce(testing::WithArgs<2>( | 757 .WillOnce(testing::WithArgs<2>( |
| 762 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 758 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 763 base::Unretained(this), connection_id)))); | 759 base::Unretained(this), connection_id)))); |
| 764 // Process the first packet for the connection. | 760 // Process the first packet for the connection. |
| 765 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO()); | 761 ProcessPacket(client_address, connection_id, true, SerializeCHLO()); |
| 766 if (ExpectStatelessReject()) { | 762 if (ExpectStatelessReject()) { |
| 767 // If this is a stateless reject, the crypto stream will close the | 763 // If this is a stateless reject, the crypto stream will close the |
| 768 // connection. | 764 // connection. |
| 769 session1_->connection()->CloseConnection( | 765 session1_->connection()->CloseConnection( |
| 770 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, "stateless reject", | 766 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, "stateless reject", |
| 771 ConnectionCloseBehavior::SILENT_CLOSE); | 767 ConnectionCloseBehavior::SILENT_CLOSE); |
| 772 } | 768 } |
| 773 | 769 |
| 774 // Send a second packet and check the results. If this is a stateless reject, | 770 // Send a second packet and check the results. If this is a stateless reject, |
| 775 // the existing connection_id will go on the time-wait list. | 771 // the existing connection_id will go on the time-wait list. |
| 776 EXPECT_EQ(ExpectStatelessReject(), | 772 EXPECT_EQ(ExpectStatelessReject(), |
| 777 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); | 773 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); |
| 778 if (ExpectStatelessReject()) { | 774 if (ExpectStatelessReject()) { |
| 779 // The second packet will be processed on the time-wait list. | 775 // The second packet will be processed on the time-wait list. |
| 780 EXPECT_CALL(*time_wait_list_manager_, | 776 EXPECT_CALL(*time_wait_list_manager_, |
| 781 ProcessPacket(_, _, connection_id, _, _)) | 777 ProcessPacket(_, _, connection_id, _, _)) |
| 782 .Times(1); | 778 .Times(1); |
| 783 } else { | 779 } else { |
| 784 // The second packet will trigger a packet-validation | 780 // The second packet will trigger a packet-validation |
| 785 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 781 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 786 ProcessUdpPacket(_, _, _)) | 782 ProcessUdpPacket(_, _, _)) |
| 787 .Times(1) | 783 .Times(1) |
| 788 .WillOnce(testing::WithArgs<2>( | 784 .WillOnce(testing::WithArgs<2>( |
| 789 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 785 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 790 base::Unretained(this), connection_id)))); | 786 base::Unretained(this), connection_id)))); |
| 791 } | 787 } |
| 792 ProcessPacket(client_address, connection_id, true, false, "data"); | 788 ProcessPacket(client_address, connection_id, true, "data"); |
| 793 } | 789 } |
| 794 | 790 |
| 795 TEST_P(QuicDispatcherStatelessRejectTest, CheapRejects) { | 791 TEST_P(QuicDispatcherStatelessRejectTest, CheapRejects) { |
| 796 FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects = true; | 792 FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects = true; |
| 797 CreateTimeWaitListManager(); | 793 CreateTimeWaitListManager(); |
| 798 | 794 |
| 799 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 795 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 800 QuicConnectionId connection_id = 1; | 796 QuicConnectionId connection_id = 1; |
| 801 if (GetParam().enable_stateless_rejects_via_flag) { | 797 if (GetParam().enable_stateless_rejects_via_flag) { |
| 802 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address)) | 798 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address)) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 815 QUIC_LOG(INFO) << "Params: " << GetParam(); | 811 QUIC_LOG(INFO) << "Params: " << GetParam(); |
| 816 // Process the first packet for the connection. | 812 // Process the first packet for the connection. |
| 817 CryptoHandshakeMessage client_hello = | 813 CryptoHandshakeMessage client_hello = |
| 818 crypto_test_utils::CreateCHLO({{"AEAD", "AESG"}, | 814 crypto_test_utils::CreateCHLO({{"AEAD", "AESG"}, |
| 819 {"KEXS", "C255"}, | 815 {"KEXS", "C255"}, |
| 820 {"COPT", "SREJ"}, | 816 {"COPT", "SREJ"}, |
| 821 {"NONC", "1234567890123456789012"}, | 817 {"NONC", "1234567890123456789012"}, |
| 822 {"VER\0", "Q025"}}, | 818 {"VER\0", "Q025"}}, |
| 823 kClientHelloMinimumSize); | 819 kClientHelloMinimumSize); |
| 824 | 820 |
| 825 ProcessPacket(client_address, connection_id, true, false, | 821 ProcessPacket(client_address, connection_id, true, |
| 826 client_hello.GetSerialized().AsStringPiece().as_string()); | 822 client_hello.GetSerialized().AsStringPiece().as_string()); |
| 827 | 823 |
| 828 if (GetParam().enable_stateless_rejects_via_flag) { | 824 if (GetParam().enable_stateless_rejects_via_flag) { |
| 829 EXPECT_EQ(true, | 825 EXPECT_EQ(true, |
| 830 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); | 826 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); |
| 831 } | 827 } |
| 832 } | 828 } |
| 833 | 829 |
| 834 TEST_P(QuicDispatcherStatelessRejectTest, BufferNonChlo) { | 830 TEST_P(QuicDispatcherStatelessRejectTest, BufferNonChlo) { |
| 835 FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects = true; | 831 FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects = true; |
| 836 CreateTimeWaitListManager(); | 832 CreateTimeWaitListManager(); |
| 837 | 833 |
| 838 const QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 834 const QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 839 const QuicConnectionId connection_id = 1; | 835 const QuicConnectionId connection_id = 1; |
| 840 | 836 |
| 841 ProcessPacket(client_address, connection_id, true, false, | 837 ProcessPacket(client_address, connection_id, true, "NOT DATA FOR A CHLO"); |
| 842 "NOT DATA FOR A CHLO"); | |
| 843 | 838 |
| 844 // Process the first packet for the connection. | 839 // Process the first packet for the connection. |
| 845 CryptoHandshakeMessage client_hello = | 840 CryptoHandshakeMessage client_hello = |
| 846 crypto_test_utils::CreateCHLO({{"AEAD", "AESG"}, | 841 crypto_test_utils::CreateCHLO({{"AEAD", "AESG"}, |
| 847 {"KEXS", "C255"}, | 842 {"KEXS", "C255"}, |
| 848 {"NONC", "1234567890123456789012"}, | 843 {"NONC", "1234567890123456789012"}, |
| 849 {"VER\0", "Q025"}}, | 844 {"VER\0", "Q025"}}, |
| 850 kClientHelloMinimumSize); | 845 kClientHelloMinimumSize); |
| 851 | 846 |
| 852 // If stateless rejects are enabled then a connection will be created now | 847 // If stateless rejects are enabled then a connection will be created now |
| 853 // and the buffered packet will be processed | 848 // and the buffered packet will be processed |
| 854 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address)) | 849 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address)) |
| 855 .WillOnce(testing::Return( | 850 .WillOnce(testing::Return( |
| 856 CreateSessionBasedOnTestParams(connection_id, client_address))); | 851 CreateSessionBasedOnTestParams(connection_id, client_address))); |
| 857 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 852 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 858 ProcessUdpPacket(_, client_address, _)) | 853 ProcessUdpPacket(_, client_address, _)) |
| 859 .WillOnce(testing::WithArg<2>( | 854 .WillOnce(testing::WithArg<2>( |
| 860 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 855 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 861 base::Unretained(this), connection_id)))); | 856 base::Unretained(this), connection_id)))); |
| 862 // Expect both packets to be passed to ProcessUdpPacket(). And one of them | 857 // Expect both packets to be passed to ProcessUdpPacket(). And one of them |
| 863 // is already expected in CreateSessionBasedOnTestParams(). | 858 // is already expected in CreateSessionBasedOnTestParams(). |
| 864 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 859 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 865 ProcessUdpPacket(_, client_address, _)) | 860 ProcessUdpPacket(_, client_address, _)) |
| 866 .WillOnce(testing::WithArg<2>( | 861 .WillOnce(testing::WithArg<2>( |
| 867 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 862 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 868 base::Unretained(this), connection_id)))) | 863 base::Unretained(this), connection_id)))) |
| 869 .RetiresOnSaturation(); | 864 .RetiresOnSaturation(); |
| 870 ProcessPacket(client_address, connection_id, true, false, | 865 ProcessPacket(client_address, connection_id, true, |
| 871 client_hello.GetSerialized().AsStringPiece().as_string()); | 866 client_hello.GetSerialized().AsStringPiece().as_string()); |
| 872 EXPECT_FALSE( | 867 EXPECT_FALSE( |
| 873 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); | 868 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); |
| 874 } | 869 } |
| 875 | 870 |
| 876 // Verify the stopgap test: Packets with truncated connection IDs should be | 871 // Verify the stopgap test: Packets with truncated connection IDs should be |
| 877 // dropped. | 872 // dropped. |
| 878 class QuicDispatcherTestStrayPacketConnectionId : public QuicDispatcherTest {}; | 873 class QuicDispatcherTestStrayPacketConnectionId : public QuicDispatcherTest {}; |
| 879 | 874 |
| 880 // Packets with truncated connection IDs should be dropped. | 875 // Packets with truncated connection IDs should be dropped. |
| 881 TEST_F(QuicDispatcherTestStrayPacketConnectionId, | 876 TEST_F(QuicDispatcherTestStrayPacketConnectionId, |
| 882 StrayPacketTruncatedConnectionId) { | 877 StrayPacketTruncatedConnectionId) { |
| 883 CreateTimeWaitListManager(); | 878 CreateTimeWaitListManager(); |
| 884 | 879 |
| 885 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 880 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 886 QuicConnectionId connection_id = 1; | 881 QuicConnectionId connection_id = 1; |
| 887 // Dispatcher drops this packet. | 882 // Dispatcher drops this packet. |
| 888 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0); | 883 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0); |
| 889 EXPECT_CALL(*time_wait_list_manager_, | 884 EXPECT_CALL(*time_wait_list_manager_, |
| 890 ProcessPacket(_, _, connection_id, _, _)) | 885 ProcessPacket(_, _, connection_id, _, _)) |
| 891 .Times(0); | 886 .Times(0); |
| 892 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) | 887 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) |
| 893 .Times(0); | 888 .Times(0); |
| 894 ProcessPacket(client_address, connection_id, true, false, "data", | 889 ProcessPacket(client_address, connection_id, true, "data", |
| 895 PACKET_0BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER); | 890 PACKET_0BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER); |
| 896 } | 891 } |
| 897 | 892 |
| 898 class BlockingWriter : public QuicPacketWriterWrapper { | 893 class BlockingWriter : public QuicPacketWriterWrapper { |
| 899 public: | 894 public: |
| 900 BlockingWriter() : write_blocked_(false) {} | 895 BlockingWriter() : write_blocked_(false) {} |
| 901 | 896 |
| 902 bool IsWriteBlocked() const override { return write_blocked_; } | 897 bool IsWriteBlocked() const override { return write_blocked_; } |
| 903 void SetWritable() override { write_blocked_ = false; } | 898 void SetWritable() override { write_blocked_ = false; } |
| 904 | 899 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 928 | 923 |
| 929 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address)) | 924 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address)) |
| 930 .WillOnce(testing::Return(CreateSession( | 925 .WillOnce(testing::Return(CreateSession( |
| 931 dispatcher_.get(), config_, 1, client_address, &helper_, | 926 dispatcher_.get(), config_, 1, client_address, &helper_, |
| 932 &alarm_factory_, &crypto_config_, | 927 &alarm_factory_, &crypto_config_, |
| 933 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 928 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 934 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 929 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 935 ProcessUdpPacket(_, _, _)) | 930 ProcessUdpPacket(_, _, _)) |
| 936 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( | 931 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( |
| 937 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1)))); | 932 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1)))); |
| 938 ProcessPacket(client_address, 1, true, false, SerializeCHLO()); | 933 ProcessPacket(client_address, 1, true, SerializeCHLO()); |
| 939 | 934 |
| 940 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address)) | 935 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address)) |
| 941 .WillOnce(testing::Return(CreateSession( | 936 .WillOnce(testing::Return(CreateSession( |
| 942 dispatcher_.get(), config_, 2, client_address, &helper_, | 937 dispatcher_.get(), config_, 2, client_address, &helper_, |
| 943 &alarm_factory_, &crypto_config_, | 938 &alarm_factory_, &crypto_config_, |
| 944 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session2_))); | 939 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session2_))); |
| 945 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session2_->connection()), | 940 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session2_->connection()), |
| 946 ProcessUdpPacket(_, _, _)) | 941 ProcessUdpPacket(_, _, _)) |
| 947 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( | 942 .WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor( |
| 948 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 2)))); | 943 &QuicDispatcherTest::ValidatePacket, base::Unretained(this), 2)))); |
| 949 ProcessPacket(client_address, 2, true, false, SerializeCHLO()); | 944 ProcessPacket(client_address, 2, true, SerializeCHLO()); |
| 950 | 945 |
| 951 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(dispatcher_.get()); | 946 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(dispatcher_.get()); |
| 952 } | 947 } |
| 953 | 948 |
| 954 void TearDown() override { | 949 void TearDown() override { |
| 955 EXPECT_CALL(*connection1(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); | 950 EXPECT_CALL(*connection1(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); |
| 956 EXPECT_CALL(*connection2(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); | 951 EXPECT_CALL(*connection2(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); |
| 957 dispatcher_->Shutdown(); | 952 dispatcher_->Shutdown(); |
| 958 } | 953 } |
| 959 | 954 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 TEST_P(BufferedPacketStoreTest, ProcessNonChloPacketsUptoLimitAndProcessChlo) { | 1183 TEST_P(BufferedPacketStoreTest, ProcessNonChloPacketsUptoLimitAndProcessChlo) { |
| 1189 InSequence s; | 1184 InSequence s; |
| 1190 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 1185 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 1191 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); | 1186 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); |
| 1192 QuicConnectionId conn_id = 1; | 1187 QuicConnectionId conn_id = 1; |
| 1193 // A bunch of non-CHLO should be buffered upon arrival, and the first one | 1188 // A bunch of non-CHLO should be buffered upon arrival, and the first one |
| 1194 // should trigger ShouldCreateOrBufferPacketForConnection(). | 1189 // should trigger ShouldCreateOrBufferPacketForConnection(). |
| 1195 EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id)) | 1190 EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id)) |
| 1196 .Times(1); | 1191 .Times(1); |
| 1197 for (size_t i = 1; i <= kDefaultMaxUndecryptablePackets + 1; ++i) { | 1192 for (size_t i = 1; i <= kDefaultMaxUndecryptablePackets + 1; ++i) { |
| 1198 ProcessPacket(client_address, conn_id, true, false, | 1193 ProcessPacket(client_address, conn_id, true, |
| 1199 QuicStrCat("data packet ", i + 1), PACKET_8BYTE_CONNECTION_ID, | 1194 QuicStrCat("data packet ", i + 1), PACKET_8BYTE_CONNECTION_ID, |
| 1200 PACKET_6BYTE_PACKET_NUMBER, /*packet_number=*/i + 1); | 1195 PACKET_6BYTE_PACKET_NUMBER, /*packet_number=*/i + 1); |
| 1201 } | 1196 } |
| 1202 EXPECT_EQ(0u, dispatcher_->session_map().size()) | 1197 EXPECT_EQ(0u, dispatcher_->session_map().size()) |
| 1203 << "No session should be created before CHLO arrives."; | 1198 << "No session should be created before CHLO arrives."; |
| 1204 | 1199 |
| 1205 // Pop out the last packet as it is also be dropped by the store. | 1200 // Pop out the last packet as it is also be dropped by the store. |
| 1206 data_connection_map_[conn_id].pop_back(); | 1201 data_connection_map_[conn_id].pop_back(); |
| 1207 // When CHLO arrives, a new session should be created, and all packets | 1202 // When CHLO arrives, a new session should be created, and all packets |
| 1208 // buffered should be delivered to the session. | 1203 // buffered should be delivered to the session. |
| 1209 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address)) | 1204 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address)) |
| 1210 .WillOnce(testing::Return(CreateSession( | 1205 .WillOnce(testing::Return(CreateSession( |
| 1211 dispatcher_.get(), config_, conn_id, client_address, &mock_helper_, | 1206 dispatcher_.get(), config_, conn_id, client_address, &mock_helper_, |
| 1212 &mock_alarm_factory_, &crypto_config_, | 1207 &mock_alarm_factory_, &crypto_config_, |
| 1213 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 1208 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 1214 | 1209 |
| 1215 // Only |kDefaultMaxUndecryptablePackets| packets were buffered, and they | 1210 // Only |kDefaultMaxUndecryptablePackets| packets were buffered, and they |
| 1216 // should be delivered in arrival order. | 1211 // should be delivered in arrival order. |
| 1217 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 1212 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 1218 ProcessUdpPacket(_, _, _)) | 1213 ProcessUdpPacket(_, _, _)) |
| 1219 .Times(kDefaultMaxUndecryptablePackets + 1) // + 1 for CHLO. | 1214 .Times(kDefaultMaxUndecryptablePackets + 1) // + 1 for CHLO. |
| 1220 .WillRepeatedly(testing::WithArg<2>( | 1215 .WillRepeatedly(testing::WithArg<2>( |
| 1221 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 1216 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 1222 base::Unretained(this), conn_id)))); | 1217 base::Unretained(this), conn_id)))); |
| 1223 ProcessPacket(client_address, conn_id, true, false, SerializeFullCHLO()); | 1218 ProcessPacket(client_address, conn_id, true, SerializeFullCHLO()); |
| 1224 } | 1219 } |
| 1225 | 1220 |
| 1226 TEST_P(BufferedPacketStoreTest, | 1221 TEST_P(BufferedPacketStoreTest, |
| 1227 ProcessNonChloPacketsForDifferentConnectionsUptoLimit) { | 1222 ProcessNonChloPacketsForDifferentConnectionsUptoLimit) { |
| 1228 InSequence s; | 1223 InSequence s; |
| 1229 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); | 1224 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); |
| 1230 // A bunch of non-CHLO should be buffered upon arrival. | 1225 // A bunch of non-CHLO should be buffered upon arrival. |
| 1231 size_t kNumConnections = | 1226 size_t kNumConnections = |
| 1232 (FLAGS_quic_reloadable_flag_quic_limit_num_new_sessions_per_epoll_loop | 1227 (FLAGS_quic_reloadable_flag_quic_limit_num_new_sessions_per_epoll_loop |
| 1233 ? kMaxConnectionsWithoutCHLO | 1228 ? kMaxConnectionsWithoutCHLO |
| 1234 : kDefaultMaxConnectionsInStore) + | 1229 : kDefaultMaxConnectionsInStore) + |
| 1235 1; | 1230 1; |
| 1236 for (size_t i = 1; i <= kNumConnections; ++i) { | 1231 for (size_t i = 1; i <= kNumConnections; ++i) { |
| 1237 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), i); | 1232 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), i); |
| 1238 QuicConnectionId conn_id = i; | 1233 QuicConnectionId conn_id = i; |
| 1239 if (FLAGS_quic_reloadable_flag_quic_create_session_after_insertion) { | 1234 if (FLAGS_quic_reloadable_flag_quic_create_session_after_insertion) { |
| 1240 EXPECT_CALL(*dispatcher_, | 1235 EXPECT_CALL(*dispatcher_, |
| 1241 ShouldCreateOrBufferPacketForConnection(conn_id)); | 1236 ShouldCreateOrBufferPacketForConnection(conn_id)); |
| 1242 } else { | 1237 } else { |
| 1243 if (i <= kNumConnections - 1) { | 1238 if (i <= kNumConnections - 1) { |
| 1244 // As they are on different connection, they should trigger | 1239 // As they are on different connection, they should trigger |
| 1245 // ShouldCreateOrBufferPacketForConnection(). The last packet should be | 1240 // ShouldCreateOrBufferPacketForConnection(). The last packet should be |
| 1246 // dropped. | 1241 // dropped. |
| 1247 EXPECT_CALL(*dispatcher_, | 1242 EXPECT_CALL(*dispatcher_, |
| 1248 ShouldCreateOrBufferPacketForConnection(conn_id)); | 1243 ShouldCreateOrBufferPacketForConnection(conn_id)); |
| 1249 } | 1244 } |
| 1250 } | 1245 } |
| 1251 ProcessPacket(client_address, conn_id, true, false, | 1246 ProcessPacket(client_address, conn_id, true, |
| 1252 QuicStrCat("data packet on connection ", i), | 1247 QuicStrCat("data packet on connection ", i), |
| 1253 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, | 1248 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, |
| 1254 /*packet_number=*/2); | 1249 /*packet_number=*/2); |
| 1255 } | 1250 } |
| 1256 | 1251 |
| 1257 // Pop out the packet on last connection as it shouldn't be enqueued in store | 1252 // Pop out the packet on last connection as it shouldn't be enqueued in store |
| 1258 // as well. | 1253 // as well. |
| 1259 data_connection_map_[kNumConnections].pop_front(); | 1254 data_connection_map_[kNumConnections].pop_front(); |
| 1260 | 1255 |
| 1261 // Reset session creation counter to ensure processing CHLO can always | 1256 // Reset session creation counter to ensure processing CHLO can always |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1292 FLAGS_quic_reloadable_flag_quic_limit_num_new_sessions_per_epoll_loop | 1287 FLAGS_quic_reloadable_flag_quic_limit_num_new_sessions_per_epoll_loop |
| 1293 ? kMaxConnectionsWithoutCHLO | 1288 ? kMaxConnectionsWithoutCHLO |
| 1294 : kDefaultMaxConnectionsInStore; | 1289 : kDefaultMaxConnectionsInStore; |
| 1295 size_t num_packet_to_process = i <= upper_limit ? 2u : 1u; | 1290 size_t num_packet_to_process = i <= upper_limit ? 2u : 1u; |
| 1296 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 1291 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 1297 ProcessUdpPacket(_, client_address, _)) | 1292 ProcessUdpPacket(_, client_address, _)) |
| 1298 .Times(num_packet_to_process) | 1293 .Times(num_packet_to_process) |
| 1299 .WillRepeatedly(testing::WithArg<2>( | 1294 .WillRepeatedly(testing::WithArg<2>( |
| 1300 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 1295 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 1301 base::Unretained(this), conn_id)))); | 1296 base::Unretained(this), conn_id)))); |
| 1302 ProcessPacket(client_address, conn_id, true, false, SerializeFullCHLO()); | 1297 ProcessPacket(client_address, conn_id, true, SerializeFullCHLO()); |
| 1303 } | 1298 } |
| 1304 } | 1299 } |
| 1305 | 1300 |
| 1306 // Tests that store delivers empty packet list if CHLO arrives firstly. | 1301 // Tests that store delivers empty packet list if CHLO arrives firstly. |
| 1307 TEST_P(BufferedPacketStoreTest, DeliverEmptyPackets) { | 1302 TEST_P(BufferedPacketStoreTest, DeliverEmptyPackets) { |
| 1308 QuicConnectionId conn_id = 1; | 1303 QuicConnectionId conn_id = 1; |
| 1309 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 1304 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 1310 EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id)); | 1305 EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id)); |
| 1311 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address)) | 1306 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address)) |
| 1312 .WillOnce(testing::Return(CreateSession( | 1307 .WillOnce(testing::Return(CreateSession( |
| 1313 dispatcher_.get(), config_, conn_id, client_address, &mock_helper_, | 1308 dispatcher_.get(), config_, conn_id, client_address, &mock_helper_, |
| 1314 &mock_alarm_factory_, &crypto_config_, | 1309 &mock_alarm_factory_, &crypto_config_, |
| 1315 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 1310 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 1316 ProcessPacket(client_address, conn_id, true, false, SerializeFullCHLO()); | 1311 ProcessPacket(client_address, conn_id, true, SerializeFullCHLO()); |
| 1317 } | 1312 } |
| 1318 | 1313 |
| 1319 // Tests that a retransmitted CHLO arrives after a connection for the | 1314 // Tests that a retransmitted CHLO arrives after a connection for the |
| 1320 // CHLO has been created. | 1315 // CHLO has been created. |
| 1321 TEST_P(BufferedPacketStoreTest, ReceiveRetransmittedCHLO) { | 1316 TEST_P(BufferedPacketStoreTest, ReceiveRetransmittedCHLO) { |
| 1322 InSequence s; | 1317 InSequence s; |
| 1323 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 1318 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 1324 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); | 1319 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); |
| 1325 QuicConnectionId conn_id = 1; | 1320 QuicConnectionId conn_id = 1; |
| 1326 ProcessPacket(client_address, conn_id, true, false, | 1321 ProcessPacket(client_address, conn_id, true, QuicStrCat("data packet ", 2), |
| 1327 QuicStrCat("data packet ", 2), PACKET_8BYTE_CONNECTION_ID, | 1322 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, |
| 1328 PACKET_6BYTE_PACKET_NUMBER, /*packet_number=*/2); | 1323 /*packet_number=*/2); |
| 1329 | 1324 |
| 1330 // When CHLO arrives, a new session should be created, and all packets | 1325 // When CHLO arrives, a new session should be created, and all packets |
| 1331 // buffered should be delivered to the session. | 1326 // buffered should be delivered to the session. |
| 1332 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address)) | 1327 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address)) |
| 1333 .Times(1) // Only triggered by 1st CHLO. | 1328 .Times(1) // Only triggered by 1st CHLO. |
| 1334 .WillOnce(testing::Return(CreateSession( | 1329 .WillOnce(testing::Return(CreateSession( |
| 1335 dispatcher_.get(), config_, conn_id, client_address, &mock_helper_, | 1330 dispatcher_.get(), config_, conn_id, client_address, &mock_helper_, |
| 1336 &mock_alarm_factory_, &crypto_config_, | 1331 &mock_alarm_factory_, &crypto_config_, |
| 1337 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 1332 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 1338 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 1333 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 1339 ProcessUdpPacket(_, _, _)) | 1334 ProcessUdpPacket(_, _, _)) |
| 1340 .Times(3) // Triggered by 1 data packet and 2 CHLOs. | 1335 .Times(3) // Triggered by 1 data packet and 2 CHLOs. |
| 1341 .WillRepeatedly(testing::WithArg<2>( | 1336 .WillRepeatedly(testing::WithArg<2>( |
| 1342 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 1337 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 1343 base::Unretained(this), conn_id)))); | 1338 base::Unretained(this), conn_id)))); |
| 1344 ProcessPacket(client_address, conn_id, true, false, SerializeFullCHLO()); | 1339 ProcessPacket(client_address, conn_id, true, SerializeFullCHLO()); |
| 1345 | 1340 |
| 1346 ProcessPacket(client_address, conn_id, true, false, SerializeFullCHLO()); | 1341 ProcessPacket(client_address, conn_id, true, SerializeFullCHLO()); |
| 1347 } | 1342 } |
| 1348 | 1343 |
| 1349 // Tests that expiration of a connection add connection id to time wait list. | 1344 // Tests that expiration of a connection add connection id to time wait list. |
| 1350 TEST_P(BufferedPacketStoreTest, ReceiveCHLOAfterExpiration) { | 1345 TEST_P(BufferedPacketStoreTest, ReceiveCHLOAfterExpiration) { |
| 1351 InSequence s; | 1346 InSequence s; |
| 1352 CreateTimeWaitListManager(); | 1347 CreateTimeWaitListManager(); |
| 1353 QuicBufferedPacketStore* store = | 1348 QuicBufferedPacketStore* store = |
| 1354 QuicDispatcherPeer::GetBufferedPackets(dispatcher_.get()); | 1349 QuicDispatcherPeer::GetBufferedPackets(dispatcher_.get()); |
| 1355 QuicBufferedPacketStorePeer::set_clock(store, mock_helper_.GetClock()); | 1350 QuicBufferedPacketStorePeer::set_clock(store, mock_helper_.GetClock()); |
| 1356 | 1351 |
| 1357 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 1352 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 1358 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); | 1353 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); |
| 1359 QuicConnectionId conn_id = 1; | 1354 QuicConnectionId conn_id = 1; |
| 1360 ProcessPacket(client_address, conn_id, true, false, | 1355 ProcessPacket(client_address, conn_id, true, QuicStrCat("data packet ", 2), |
| 1361 QuicStrCat("data packet ", 2), PACKET_8BYTE_CONNECTION_ID, | 1356 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, |
| 1362 PACKET_6BYTE_PACKET_NUMBER, /*packet_number=*/2); | 1357 /*packet_number=*/2); |
| 1363 | 1358 |
| 1364 mock_helper_.AdvanceTime( | 1359 mock_helper_.AdvanceTime( |
| 1365 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs)); | 1360 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs)); |
| 1366 QuicAlarm* alarm = QuicBufferedPacketStorePeer::expiration_alarm(store); | 1361 QuicAlarm* alarm = QuicBufferedPacketStorePeer::expiration_alarm(store); |
| 1367 // Cancel alarm as if it had been fired. | 1362 // Cancel alarm as if it had been fired. |
| 1368 alarm->Cancel(); | 1363 alarm->Cancel(); |
| 1369 store->OnExpirationTimeout(); | 1364 store->OnExpirationTimeout(); |
| 1370 // New arrived CHLO will be dropped because this connection is in time wait | 1365 // New arrived CHLO will be dropped because this connection is in time wait |
| 1371 // list. | 1366 // list. |
| 1372 ASSERT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); | 1367 ASSERT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); |
| 1373 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, conn_id, _, _)); | 1368 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, conn_id, _, _)); |
| 1374 ProcessPacket(client_address, conn_id, true, false, SerializeFullCHLO()); | 1369 ProcessPacket(client_address, conn_id, true, SerializeFullCHLO()); |
| 1375 } | 1370 } |
| 1376 | 1371 |
| 1377 TEST_P(BufferedPacketStoreTest, ProcessCHLOsUptoLimitAndBufferTheRest) { | 1372 TEST_P(BufferedPacketStoreTest, ProcessCHLOsUptoLimitAndBufferTheRest) { |
| 1378 FLAGS_quic_reloadable_flag_quic_limit_num_new_sessions_per_epoll_loop = true; | 1373 FLAGS_quic_reloadable_flag_quic_limit_num_new_sessions_per_epoll_loop = true; |
| 1379 // Process more than (|kMaxNumSessionsToCreate| + | 1374 // Process more than (|kMaxNumSessionsToCreate| + |
| 1380 // |kDefaultMaxConnectionsInStore|) CHLOs, | 1375 // |kDefaultMaxConnectionsInStore|) CHLOs, |
| 1381 // the first |kMaxNumSessionsToCreate| should create connections immediately, | 1376 // the first |kMaxNumSessionsToCreate| should create connections immediately, |
| 1382 // the next |kDefaultMaxConnectionsInStore| should be buffered, | 1377 // the next |kDefaultMaxConnectionsInStore| should be buffered, |
| 1383 // the rest should be dropped. | 1378 // the rest should be dropped. |
| 1384 QuicBufferedPacketStore* store = | 1379 QuicBufferedPacketStore* store = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1403 dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_, | 1398 dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_, |
| 1404 &mock_alarm_factory_, &crypto_config_, | 1399 &mock_alarm_factory_, &crypto_config_, |
| 1405 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 1400 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 1406 EXPECT_CALL( | 1401 EXPECT_CALL( |
| 1407 *reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 1402 *reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 1408 ProcessUdpPacket(_, _, _)) | 1403 ProcessUdpPacket(_, _, _)) |
| 1409 .WillOnce(testing::WithArg<2>( | 1404 .WillOnce(testing::WithArg<2>( |
| 1410 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 1405 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 1411 base::Unretained(this), conn_id)))); | 1406 base::Unretained(this), conn_id)))); |
| 1412 } | 1407 } |
| 1413 ProcessPacket(client_addr_, conn_id, true, false, SerializeFullCHLO()); | 1408 ProcessPacket(client_addr_, conn_id, true, SerializeFullCHLO()); |
| 1414 if (conn_id <= kMaxNumSessionsToCreate + kDefaultMaxConnectionsInStore && | 1409 if (conn_id <= kMaxNumSessionsToCreate + kDefaultMaxConnectionsInStore && |
| 1415 conn_id > kMaxNumSessionsToCreate) { | 1410 conn_id > kMaxNumSessionsToCreate) { |
| 1416 EXPECT_TRUE(store->HasChloForConnection(conn_id)); | 1411 EXPECT_TRUE(store->HasChloForConnection(conn_id)); |
| 1417 } else { | 1412 } else { |
| 1418 // First |kMaxNumSessionsToCreate| CHLOs should be passed to new | 1413 // First |kMaxNumSessionsToCreate| CHLOs should be passed to new |
| 1419 // connections immediately, and the last CHLO should be dropped as the | 1414 // connections immediately, and the last CHLO should be dropped as the |
| 1420 // store is full. | 1415 // store is full. |
| 1421 EXPECT_FALSE(store->HasChloForConnection(conn_id)); | 1416 EXPECT_FALSE(store->HasChloForConnection(conn_id)); |
| 1422 } | 1417 } |
| 1423 } | 1418 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_, | 1457 dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_, |
| 1463 &mock_alarm_factory_, &crypto_config_, | 1458 &mock_alarm_factory_, &crypto_config_, |
| 1464 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 1459 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 1465 EXPECT_CALL( | 1460 EXPECT_CALL( |
| 1466 *reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 1461 *reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 1467 ProcessUdpPacket(_, _, _)) | 1462 ProcessUdpPacket(_, _, _)) |
| 1468 .WillOnce(testing::WithArg<2>( | 1463 .WillOnce(testing::WithArg<2>( |
| 1469 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 1464 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 1470 base::Unretained(this), conn_id)))); | 1465 base::Unretained(this), conn_id)))); |
| 1471 } | 1466 } |
| 1472 ProcessPacket(client_addr_, conn_id, true, false, SerializeFullCHLO()); | 1467 ProcessPacket(client_addr_, conn_id, true, SerializeFullCHLO()); |
| 1473 } | 1468 } |
| 1474 // Retransmit CHLO on last connection should be dropped. | 1469 // Retransmit CHLO on last connection should be dropped. |
| 1475 QuicConnectionId last_connection = kMaxNumSessionsToCreate + 1; | 1470 QuicConnectionId last_connection = kMaxNumSessionsToCreate + 1; |
| 1476 ProcessPacket(client_addr_, last_connection, true, false, | 1471 ProcessPacket(client_addr_, last_connection, true, SerializeFullCHLO()); |
| 1477 SerializeFullCHLO()); | |
| 1478 | 1472 |
| 1479 size_t packets_buffered = 2; | 1473 size_t packets_buffered = 2; |
| 1480 if (!FLAGS_quic_reloadable_flag_quic_buffer_packets_after_chlo) { | 1474 if (!FLAGS_quic_reloadable_flag_quic_buffer_packets_after_chlo) { |
| 1481 // The packet sent above is dropped when flag is off. | 1475 // The packet sent above is dropped when flag is off. |
| 1482 packets_buffered = 1; | 1476 packets_buffered = 1; |
| 1483 } | 1477 } |
| 1484 | 1478 |
| 1485 // Reset counter and process buffered CHLO. | 1479 // Reset counter and process buffered CHLO. |
| 1486 EXPECT_CALL(*dispatcher_, CreateQuicSession(last_connection, client_addr_)) | 1480 EXPECT_CALL(*dispatcher_, CreateQuicSession(last_connection, client_addr_)) |
| 1487 .WillOnce(testing::Return(CreateSession( | 1481 .WillOnce(testing::Return(CreateSession( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1509 dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_, | 1503 dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_, |
| 1510 &mock_alarm_factory_, &crypto_config_, | 1504 &mock_alarm_factory_, &crypto_config_, |
| 1511 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 1505 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 1512 EXPECT_CALL( | 1506 EXPECT_CALL( |
| 1513 *reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 1507 *reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 1514 ProcessUdpPacket(_, _, _)) | 1508 ProcessUdpPacket(_, _, _)) |
| 1515 .WillOnce(testing::WithArg<2>( | 1509 .WillOnce(testing::WithArg<2>( |
| 1516 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 1510 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 1517 base::Unretained(this), conn_id)))); | 1511 base::Unretained(this), conn_id)))); |
| 1518 } | 1512 } |
| 1519 ProcessPacket(client_addr_, conn_id, true, false, SerializeFullCHLO()); | 1513 ProcessPacket(client_addr_, conn_id, true, SerializeFullCHLO()); |
| 1520 } | 1514 } |
| 1521 | 1515 |
| 1522 // Process another |kDefaultMaxUndecryptablePackets| + 1 data packets. The | 1516 // Process another |kDefaultMaxUndecryptablePackets| + 1 data packets. The |
| 1523 // last one should be dropped. | 1517 // last one should be dropped. |
| 1524 for (QuicPacketNumber packet_number = 2; | 1518 for (QuicPacketNumber packet_number = 2; |
| 1525 packet_number <= kDefaultMaxUndecryptablePackets + 2; ++packet_number) { | 1519 packet_number <= kDefaultMaxUndecryptablePackets + 2; ++packet_number) { |
| 1526 ProcessPacket(client_addr_, last_connection_id, true, false, "data packet"); | 1520 ProcessPacket(client_addr_, last_connection_id, true, "data packet"); |
| 1527 } | 1521 } |
| 1528 | 1522 |
| 1529 // Reset counter and process buffered CHLO. | 1523 // Reset counter and process buffered CHLO. |
| 1530 EXPECT_CALL(*dispatcher_, CreateQuicSession(last_connection_id, client_addr_)) | 1524 EXPECT_CALL(*dispatcher_, CreateQuicSession(last_connection_id, client_addr_)) |
| 1531 .WillOnce(testing::Return(CreateSession( | 1525 .WillOnce(testing::Return(CreateSession( |
| 1532 dispatcher_.get(), config_, last_connection_id, client_addr_, | 1526 dispatcher_.get(), config_, last_connection_id, client_addr_, |
| 1533 &mock_helper_, &mock_alarm_factory_, &crypto_config_, | 1527 &mock_helper_, &mock_alarm_factory_, &crypto_config_, |
| 1534 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 1528 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 1535 // Only CHLO and following |kDefaultMaxUndecryptablePackets| data packets | 1529 // Only CHLO and following |kDefaultMaxUndecryptablePackets| data packets |
| 1536 // should be process. | 1530 // should be process. |
| 1537 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 1531 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 1538 ProcessUdpPacket(_, _, _)) | 1532 ProcessUdpPacket(_, _, _)) |
| 1539 .Times(kDefaultMaxUndecryptablePackets + 1) | 1533 .Times(kDefaultMaxUndecryptablePackets + 1) |
| 1540 .WillRepeatedly(testing::WithArg<2>( | 1534 .WillRepeatedly(testing::WithArg<2>( |
| 1541 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 1535 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 1542 base::Unretained(this), last_connection_id)))); | 1536 base::Unretained(this), last_connection_id)))); |
| 1543 dispatcher_->ProcessBufferedChlos(kMaxNumSessionsToCreate); | 1537 dispatcher_->ProcessBufferedChlos(kMaxNumSessionsToCreate); |
| 1544 } | 1538 } |
| 1545 | 1539 |
| 1546 // Tests that when dispatcher's packet buffer is full, a CHLO on connection | 1540 // Tests that when dispatcher's packet buffer is full, a CHLO on connection |
| 1547 // which doesn't have buffered CHLO should be buffered. | 1541 // which doesn't have buffered CHLO should be buffered. |
| 1548 TEST_P(BufferedPacketStoreTest, ReceiveCHLOForBufferedConnection) { | 1542 TEST_P(BufferedPacketStoreTest, ReceiveCHLOForBufferedConnection) { |
| 1549 FLAGS_quic_reloadable_flag_quic_limit_num_new_sessions_per_epoll_loop = true; | 1543 FLAGS_quic_reloadable_flag_quic_limit_num_new_sessions_per_epoll_loop = true; |
| 1550 QuicBufferedPacketStore* store = | 1544 QuicBufferedPacketStore* store = |
| 1551 QuicDispatcherPeer::GetBufferedPackets(dispatcher_.get()); | 1545 QuicDispatcherPeer::GetBufferedPackets(dispatcher_.get()); |
| 1552 | 1546 |
| 1553 QuicConnectionId conn_id = 1; | 1547 QuicConnectionId conn_id = 1; |
| 1554 ProcessPacket(client_addr_, conn_id, true, false, "data packet", | 1548 ProcessPacket(client_addr_, conn_id, true, "data packet", |
| 1555 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, | 1549 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, |
| 1556 /*packet_number=*/1); | 1550 /*packet_number=*/1); |
| 1557 // Fill packet buffer to full with CHLOs on other connections. Need to feed | 1551 // Fill packet buffer to full with CHLOs on other connections. Need to feed |
| 1558 // extra CHLOs because the first |kMaxNumSessionsToCreate| are going to create | 1552 // extra CHLOs because the first |kMaxNumSessionsToCreate| are going to create |
| 1559 // session directly. | 1553 // session directly. |
| 1560 for (conn_id = 2; | 1554 for (conn_id = 2; |
| 1561 conn_id <= kDefaultMaxConnectionsInStore + kMaxNumSessionsToCreate; | 1555 conn_id <= kDefaultMaxConnectionsInStore + kMaxNumSessionsToCreate; |
| 1562 ++conn_id) { | 1556 ++conn_id) { |
| 1563 if (conn_id <= kMaxNumSessionsToCreate + 1) { | 1557 if (conn_id <= kMaxNumSessionsToCreate + 1) { |
| 1564 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_)) | 1558 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_)) |
| 1565 .WillOnce(testing::Return(CreateSession( | 1559 .WillOnce(testing::Return(CreateSession( |
| 1566 dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_, | 1560 dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_, |
| 1567 &mock_alarm_factory_, &crypto_config_, | 1561 &mock_alarm_factory_, &crypto_config_, |
| 1568 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); | 1562 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); |
| 1569 EXPECT_CALL( | 1563 EXPECT_CALL( |
| 1570 *reinterpret_cast<MockQuicConnection*>(session1_->connection()), | 1564 *reinterpret_cast<MockQuicConnection*>(session1_->connection()), |
| 1571 ProcessUdpPacket(_, _, _)) | 1565 ProcessUdpPacket(_, _, _)) |
| 1572 .WillOnce(testing::WithArg<2>( | 1566 .WillOnce(testing::WithArg<2>( |
| 1573 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 1567 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 1574 base::Unretained(this), conn_id)))); | 1568 base::Unretained(this), conn_id)))); |
| 1575 } | 1569 } |
| 1576 ProcessPacket(client_addr_, conn_id, true, false, SerializeFullCHLO()); | 1570 ProcessPacket(client_addr_, conn_id, true, SerializeFullCHLO()); |
| 1577 } | 1571 } |
| 1578 EXPECT_FALSE(store->HasChloForConnection(/*connection_id=*/1)); | 1572 EXPECT_FALSE(store->HasChloForConnection(/*connection_id=*/1)); |
| 1579 | 1573 |
| 1580 // CHLO on connection 1 should still be buffered. | 1574 // CHLO on connection 1 should still be buffered. |
| 1581 ProcessPacket(client_addr_, /*connection_id=*/1, true, false, | 1575 ProcessPacket(client_addr_, /*connection_id=*/1, true, SerializeFullCHLO()); |
| 1582 SerializeFullCHLO()); | |
| 1583 EXPECT_TRUE(store->HasChloForConnection(/*connection_id=*/1)); | 1576 EXPECT_TRUE(store->HasChloForConnection(/*connection_id=*/1)); |
| 1584 } | 1577 } |
| 1585 | 1578 |
| 1586 // Test which exercises the async GetProof codepaths, especially in the context | 1579 // Test which exercises the async GetProof codepaths, especially in the context |
| 1587 // of stateless rejection. | 1580 // of stateless rejection. |
| 1588 class AsyncGetProofTest : public QuicDispatcherTest { | 1581 class AsyncGetProofTest : public QuicDispatcherTest { |
| 1589 public: | 1582 public: |
| 1590 AsyncGetProofTest() | 1583 AsyncGetProofTest() |
| 1591 : QuicDispatcherTest( | 1584 : QuicDispatcherTest( |
| 1592 std::unique_ptr<FakeProofSource>(new FakeProofSource())), | 1585 std::unique_ptr<FakeProofSource>(new FakeProofSource())), |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 EXPECT_CALL(check, Call(2)); | 1688 EXPECT_CALL(check, Call(2)); |
| 1696 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>( | 1689 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>( |
| 1697 GetSession(conn_id)->connection()), | 1690 GetSession(conn_id)->connection()), |
| 1698 ProcessUdpPacket(_, _, _)) | 1691 ProcessUdpPacket(_, _, _)) |
| 1699 .WillOnce(testing::WithArg<2>( | 1692 .WillOnce(testing::WithArg<2>( |
| 1700 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 1693 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 1701 base::Unretained(this), conn_id)))); | 1694 base::Unretained(this), conn_id)))); |
| 1702 } | 1695 } |
| 1703 | 1696 |
| 1704 // Send a CHLO that the StatelessRejector will accept. | 1697 // Send a CHLO that the StatelessRejector will accept. |
| 1705 ProcessPacket(client_addr_, conn_id, true, false, SerializeFullCHLO()); | 1698 ProcessPacket(client_addr_, conn_id, true, SerializeFullCHLO()); |
| 1706 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); | 1699 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); |
| 1707 | 1700 |
| 1708 check.Call(1); | 1701 check.Call(1); |
| 1709 // Complete the ProofSource::GetProof call and verify that a session is | 1702 // Complete the ProofSource::GetProof call and verify that a session is |
| 1710 // created. | 1703 // created. |
| 1711 GetFakeProofSource()->InvokePendingCallback(0); | 1704 GetFakeProofSource()->InvokePendingCallback(0); |
| 1712 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); | 1705 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); |
| 1713 | 1706 |
| 1714 check.Call(2); | 1707 check.Call(2); |
| 1715 // Verify that a data packet gets processed immediately. | 1708 // Verify that a data packet gets processed immediately. |
| 1716 ProcessPacket(client_addr_, conn_id, true, false, "My name is Data"); | 1709 ProcessPacket(client_addr_, conn_id, true, "My name is Data"); |
| 1717 } | 1710 } |
| 1718 | 1711 |
| 1719 // Test a simple situation of connections which the StatelessRejector will | 1712 // Test a simple situation of connections which the StatelessRejector will |
| 1720 // reject. | 1713 // reject. |
| 1721 TEST_F(AsyncGetProofTest, BasicReject) { | 1714 TEST_F(AsyncGetProofTest, BasicReject) { |
| 1722 CreateTimeWaitListManager(); | 1715 CreateTimeWaitListManager(); |
| 1723 | 1716 |
| 1724 QuicConnectionId conn_id = 1; | 1717 QuicConnectionId conn_id = 1; |
| 1725 | 1718 |
| 1726 testing::MockFunction<void(int check_point)> check; | 1719 testing::MockFunction<void(int check_point)> check; |
| 1727 { | 1720 { |
| 1728 InSequence s; | 1721 InSequence s; |
| 1729 EXPECT_CALL(check, Call(1)); | 1722 EXPECT_CALL(check, Call(1)); |
| 1730 EXPECT_CALL(*time_wait_list_manager_, | 1723 EXPECT_CALL(*time_wait_list_manager_, |
| 1731 AddConnectionIdToTimeWait(conn_id, _, true, _)); | 1724 AddConnectionIdToTimeWait(conn_id, _, true, _)); |
| 1732 EXPECT_CALL(*time_wait_list_manager_, | 1725 EXPECT_CALL(*time_wait_list_manager_, |
| 1733 ProcessPacket(_, client_addr_, conn_id, _, _)); | 1726 ProcessPacket(_, client_addr_, conn_id, _, _)); |
| 1734 | 1727 |
| 1735 EXPECT_CALL(check, Call(2)); | 1728 EXPECT_CALL(check, Call(2)); |
| 1736 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_)) | 1729 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_)) |
| 1737 .Times(0); | 1730 .Times(0); |
| 1738 EXPECT_CALL(*time_wait_list_manager_, | 1731 EXPECT_CALL(*time_wait_list_manager_, |
| 1739 ProcessPacket(_, client_addr_, conn_id, _, _)); | 1732 ProcessPacket(_, client_addr_, conn_id, _, _)); |
| 1740 } | 1733 } |
| 1741 | 1734 |
| 1742 // Send a CHLO that the StatelessRejector will reject. | 1735 // Send a CHLO that the StatelessRejector will reject. |
| 1743 ProcessPacket(client_addr_, conn_id, true, false, SerializeCHLO()); | 1736 ProcessPacket(client_addr_, conn_id, true, SerializeCHLO()); |
| 1744 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); | 1737 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); |
| 1745 | 1738 |
| 1746 // Complete the ProofSource::GetProof call and verify that the connection and | 1739 // Complete the ProofSource::GetProof call and verify that the connection and |
| 1747 // packet are processed by the time wait list manager. | 1740 // packet are processed by the time wait list manager. |
| 1748 check.Call(1); | 1741 check.Call(1); |
| 1749 GetFakeProofSource()->InvokePendingCallback(0); | 1742 GetFakeProofSource()->InvokePendingCallback(0); |
| 1750 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); | 1743 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); |
| 1751 | 1744 |
| 1752 // Verify that a data packet is passed to the time wait list manager. | 1745 // Verify that a data packet is passed to the time wait list manager. |
| 1753 check.Call(2); | 1746 check.Call(2); |
| 1754 ProcessPacket(client_addr_, conn_id, true, false, "My name is Data"); | 1747 ProcessPacket(client_addr_, conn_id, true, "My name is Data"); |
| 1755 } | 1748 } |
| 1756 | 1749 |
| 1757 // Test a situation with multiple interleaved connections which the | 1750 // Test a situation with multiple interleaved connections which the |
| 1758 // StatelessRejector will accept. | 1751 // StatelessRejector will accept. |
| 1759 TEST_F(AsyncGetProofTest, MultipleAccept) { | 1752 TEST_F(AsyncGetProofTest, MultipleAccept) { |
| 1760 QuicConnectionId conn_id_1 = 1; | 1753 QuicConnectionId conn_id_1 = 1; |
| 1761 QuicConnectionId conn_id_2 = 2; | 1754 QuicConnectionId conn_id_2 = 2; |
| 1762 QuicBufferedPacketStore* store = | 1755 QuicBufferedPacketStore* store = |
| 1763 QuicDispatcherPeer::GetBufferedPackets(dispatcher_.get()); | 1756 QuicDispatcherPeer::GetBufferedPackets(dispatcher_.get()); |
| 1764 | 1757 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1794 .WillOnce(testing::Return(GetSession(conn_id_1))); | 1787 .WillOnce(testing::Return(GetSession(conn_id_1))); |
| 1795 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>( | 1788 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>( |
| 1796 GetSession(conn_id_1)->connection()), | 1789 GetSession(conn_id_1)->connection()), |
| 1797 ProcessUdpPacket(_, _, _)) | 1790 ProcessUdpPacket(_, _, _)) |
| 1798 .WillRepeatedly(testing::WithArg<2>( | 1791 .WillRepeatedly(testing::WithArg<2>( |
| 1799 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 1792 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 1800 base::Unretained(this), conn_id_1)))); | 1793 base::Unretained(this), conn_id_1)))); |
| 1801 } | 1794 } |
| 1802 | 1795 |
| 1803 // Send a CHLO that the StatelessRejector will accept. | 1796 // Send a CHLO that the StatelessRejector will accept. |
| 1804 ProcessPacket(client_addr_, conn_id_1, true, false, SerializeFullCHLO()); | 1797 ProcessPacket(client_addr_, conn_id_1, true, SerializeFullCHLO()); |
| 1805 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); | 1798 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); |
| 1806 | 1799 |
| 1807 // Send another CHLO that the StatelessRejector will accept. | 1800 // Send another CHLO that the StatelessRejector will accept. |
| 1808 ProcessPacket(client_addr_, conn_id_2, true, false, SerializeFullCHLO()); | 1801 ProcessPacket(client_addr_, conn_id_2, true, SerializeFullCHLO()); |
| 1809 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 2); | 1802 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 2); |
| 1810 | 1803 |
| 1811 // Complete the second ProofSource::GetProof call and verify that a session is | 1804 // Complete the second ProofSource::GetProof call and verify that a session is |
| 1812 // created. | 1805 // created. |
| 1813 check.Call(1); | 1806 check.Call(1); |
| 1814 GetFakeProofSource()->InvokePendingCallback(1); | 1807 GetFakeProofSource()->InvokePendingCallback(1); |
| 1815 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); | 1808 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); |
| 1816 | 1809 |
| 1817 // Verify that a data packet on that connection gets processed immediately. | 1810 // Verify that a data packet on that connection gets processed immediately. |
| 1818 check.Call(2); | 1811 check.Call(2); |
| 1819 ProcessPacket(client_addr_, conn_id_2, true, false, "My name is Data"); | 1812 ProcessPacket(client_addr_, conn_id_2, true, "My name is Data"); |
| 1820 | 1813 |
| 1821 // Verify that a data packet on the other connection does not get processed | 1814 // Verify that a data packet on the other connection does not get processed |
| 1822 // yet. | 1815 // yet. |
| 1823 check.Call(3); | 1816 check.Call(3); |
| 1824 ProcessPacket(client_addr_, conn_id_1, true, false, "My name is Data"); | 1817 ProcessPacket(client_addr_, conn_id_1, true, "My name is Data"); |
| 1825 EXPECT_TRUE(store->HasBufferedPackets(conn_id_1)); | 1818 EXPECT_TRUE(store->HasBufferedPackets(conn_id_1)); |
| 1826 EXPECT_FALSE(store->HasBufferedPackets(conn_id_2)); | 1819 EXPECT_FALSE(store->HasBufferedPackets(conn_id_2)); |
| 1827 | 1820 |
| 1828 // Complete the first ProofSource::GetProof call and verify that a session is | 1821 // Complete the first ProofSource::GetProof call and verify that a session is |
| 1829 // created and the buffered packet is processed. | 1822 // created and the buffered packet is processed. |
| 1830 check.Call(4); | 1823 check.Call(4); |
| 1831 GetFakeProofSource()->InvokePendingCallback(0); | 1824 GetFakeProofSource()->InvokePendingCallback(0); |
| 1832 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); | 1825 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); |
| 1833 } | 1826 } |
| 1834 | 1827 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1863 ShouldCreateOrBufferPacketForConnection(conn_id_1)); | 1856 ShouldCreateOrBufferPacketForConnection(conn_id_1)); |
| 1864 | 1857 |
| 1865 EXPECT_CALL(check, Call(4)); | 1858 EXPECT_CALL(check, Call(4)); |
| 1866 EXPECT_CALL(*time_wait_list_manager_, | 1859 EXPECT_CALL(*time_wait_list_manager_, |
| 1867 AddConnectionIdToTimeWait(conn_id_1, _, true, _)); | 1860 AddConnectionIdToTimeWait(conn_id_1, _, true, _)); |
| 1868 EXPECT_CALL(*time_wait_list_manager_, | 1861 EXPECT_CALL(*time_wait_list_manager_, |
| 1869 ProcessPacket(_, client_addr_, conn_id_1, _, _)); | 1862 ProcessPacket(_, client_addr_, conn_id_1, _, _)); |
| 1870 } | 1863 } |
| 1871 | 1864 |
| 1872 // Send a CHLO that the StatelessRejector will reject. | 1865 // Send a CHLO that the StatelessRejector will reject. |
| 1873 ProcessPacket(client_addr_, conn_id_1, true, false, SerializeCHLO()); | 1866 ProcessPacket(client_addr_, conn_id_1, true, SerializeCHLO()); |
| 1874 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); | 1867 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); |
| 1875 | 1868 |
| 1876 // Send another CHLO that the StatelessRejector will reject. | 1869 // Send another CHLO that the StatelessRejector will reject. |
| 1877 ProcessPacket(client_addr_, conn_id_2, true, false, SerializeCHLO()); | 1870 ProcessPacket(client_addr_, conn_id_2, true, SerializeCHLO()); |
| 1878 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 2); | 1871 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 2); |
| 1879 | 1872 |
| 1880 // Complete the second ProofSource::GetProof call and verify that the | 1873 // Complete the second ProofSource::GetProof call and verify that the |
| 1881 // connection and packet are processed by the time wait manager. | 1874 // connection and packet are processed by the time wait manager. |
| 1882 check.Call(1); | 1875 check.Call(1); |
| 1883 GetFakeProofSource()->InvokePendingCallback(1); | 1876 GetFakeProofSource()->InvokePendingCallback(1); |
| 1884 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); | 1877 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); |
| 1885 | 1878 |
| 1886 // Verify that a data packet on that connection gets processed immediately by | 1879 // Verify that a data packet on that connection gets processed immediately by |
| 1887 // the time wait manager. | 1880 // the time wait manager. |
| 1888 check.Call(2); | 1881 check.Call(2); |
| 1889 ProcessPacket(client_addr_, conn_id_2, true, false, "My name is Data"); | 1882 ProcessPacket(client_addr_, conn_id_2, true, "My name is Data"); |
| 1890 | 1883 |
| 1891 // Verify that a data packet on the first connection gets buffered. | 1884 // Verify that a data packet on the first connection gets buffered. |
| 1892 check.Call(3); | 1885 check.Call(3); |
| 1893 ProcessPacket(client_addr_, conn_id_1, true, false, "My name is Data"); | 1886 ProcessPacket(client_addr_, conn_id_1, true, "My name is Data"); |
| 1894 EXPECT_TRUE(store->HasBufferedPackets(conn_id_1)); | 1887 EXPECT_TRUE(store->HasBufferedPackets(conn_id_1)); |
| 1895 EXPECT_FALSE(store->HasBufferedPackets(conn_id_2)); | 1888 EXPECT_FALSE(store->HasBufferedPackets(conn_id_2)); |
| 1896 | 1889 |
| 1897 // Complete the first ProofSource::GetProof call and verify that the CHLO is | 1890 // Complete the first ProofSource::GetProof call and verify that the CHLO is |
| 1898 // processed by the time wait manager and the remaining packets are discarded. | 1891 // processed by the time wait manager and the remaining packets are discarded. |
| 1899 check.Call(4); | 1892 check.Call(4); |
| 1900 GetFakeProofSource()->InvokePendingCallback(0); | 1893 GetFakeProofSource()->InvokePendingCallback(0); |
| 1901 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); | 1894 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); |
| 1902 EXPECT_FALSE(store->HasBufferedPackets(conn_id_1)); | 1895 EXPECT_FALSE(store->HasBufferedPackets(conn_id_1)); |
| 1903 EXPECT_FALSE(store->HasBufferedPackets(conn_id_2)); | 1896 EXPECT_FALSE(store->HasBufferedPackets(conn_id_2)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1922 EXPECT_CALL(check, Call(2)); | 1915 EXPECT_CALL(check, Call(2)); |
| 1923 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id_1, client_addr_)) | 1916 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id_1, client_addr_)) |
| 1924 .Times(0); | 1917 .Times(0); |
| 1925 EXPECT_CALL(*time_wait_list_manager_, | 1918 EXPECT_CALL(*time_wait_list_manager_, |
| 1926 AddConnectionIdToTimeWait(conn_id_1, _, true, _)); | 1919 AddConnectionIdToTimeWait(conn_id_1, _, true, _)); |
| 1927 EXPECT_CALL(*time_wait_list_manager_, | 1920 EXPECT_CALL(*time_wait_list_manager_, |
| 1928 ProcessPacket(_, client_addr_, conn_id_1, _, _)); | 1921 ProcessPacket(_, client_addr_, conn_id_1, _, _)); |
| 1929 } | 1922 } |
| 1930 | 1923 |
| 1931 // Send a CHLO that the StatelessRejector will reject. | 1924 // Send a CHLO that the StatelessRejector will reject. |
| 1932 ProcessPacket(client_addr_, conn_id_1, true, false, SerializeCHLO()); | 1925 ProcessPacket(client_addr_, conn_id_1, true, SerializeCHLO()); |
| 1933 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); | 1926 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); |
| 1934 EXPECT_FALSE(store->HasBufferedPackets(conn_id_1)); | 1927 EXPECT_FALSE(store->HasBufferedPackets(conn_id_1)); |
| 1935 | 1928 |
| 1936 // Send an identical CHLO which should get buffered. | 1929 // Send an identical CHLO which should get buffered. |
| 1937 check.Call(1); | 1930 check.Call(1); |
| 1938 ProcessPacket(client_addr_, conn_id_1, true, false, SerializeCHLO()); | 1931 ProcessPacket(client_addr_, conn_id_1, true, SerializeCHLO()); |
| 1939 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); | 1932 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); |
| 1940 EXPECT_TRUE(store->HasBufferedPackets(conn_id_1)); | 1933 EXPECT_TRUE(store->HasBufferedPackets(conn_id_1)); |
| 1941 | 1934 |
| 1942 // Complete the ProofSource::GetProof call and verify that the CHLO is | 1935 // Complete the ProofSource::GetProof call and verify that the CHLO is |
| 1943 // rejected and the copy is discarded. | 1936 // rejected and the copy is discarded. |
| 1944 check.Call(2); | 1937 check.Call(2); |
| 1945 GetFakeProofSource()->InvokePendingCallback(0); | 1938 GetFakeProofSource()->InvokePendingCallback(0); |
| 1946 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); | 1939 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); |
| 1947 EXPECT_FALSE(store->HasBufferedPackets(conn_id_1)); | 1940 EXPECT_FALSE(store->HasBufferedPackets(conn_id_1)); |
| 1948 } | 1941 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1964 EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id)); | 1957 EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id)); |
| 1965 | 1958 |
| 1966 EXPECT_CALL(check, Call(2)); | 1959 EXPECT_CALL(check, Call(2)); |
| 1967 EXPECT_CALL(*time_wait_list_manager_, | 1960 EXPECT_CALL(*time_wait_list_manager_, |
| 1968 ProcessPacket(_, client_addr_, conn_id, _, _)); | 1961 ProcessPacket(_, client_addr_, conn_id, _, _)); |
| 1969 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_)) | 1962 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_)) |
| 1970 .Times(0); | 1963 .Times(0); |
| 1971 } | 1964 } |
| 1972 | 1965 |
| 1973 // Send a CHLO that the StatelessRejector will accept. | 1966 // Send a CHLO that the StatelessRejector will accept. |
| 1974 ProcessPacket(client_addr_, conn_id, true, false, SerializeFullCHLO()); | 1967 ProcessPacket(client_addr_, conn_id, true, SerializeFullCHLO()); |
| 1975 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); | 1968 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); |
| 1976 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); | 1969 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); |
| 1977 | 1970 |
| 1978 // Send a data packet that will get buffered | 1971 // Send a data packet that will get buffered |
| 1979 check.Call(1); | 1972 check.Call(1); |
| 1980 ProcessPacket(client_addr_, conn_id, true, false, "My name is Data"); | 1973 ProcessPacket(client_addr_, conn_id, true, "My name is Data"); |
| 1981 EXPECT_TRUE(store->HasBufferedPackets(conn_id)); | 1974 EXPECT_TRUE(store->HasBufferedPackets(conn_id)); |
| 1982 | 1975 |
| 1983 // Pretend that enough time has gone by for the packets to get expired out of | 1976 // Pretend that enough time has gone by for the packets to get expired out of |
| 1984 // the buffer | 1977 // the buffer |
| 1985 mock_helper_.AdvanceTime( | 1978 mock_helper_.AdvanceTime( |
| 1986 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs)); | 1979 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs)); |
| 1987 QuicBufferedPacketStorePeer::expiration_alarm(store)->Cancel(); | 1980 QuicBufferedPacketStorePeer::expiration_alarm(store)->Cancel(); |
| 1988 store->OnExpirationTimeout(); | 1981 store->OnExpirationTimeout(); |
| 1989 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); | 1982 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); |
| 1990 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); | 1983 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2022 .WillOnce(testing::Return(GetSession(conn_id))); | 2015 .WillOnce(testing::Return(GetSession(conn_id))); |
| 2023 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>( | 2016 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>( |
| 2024 GetSession(conn_id)->connection()), | 2017 GetSession(conn_id)->connection()), |
| 2025 ProcessUdpPacket(_, _, _)) | 2018 ProcessUdpPacket(_, _, _)) |
| 2026 .WillOnce(testing::WithArg<2>( | 2019 .WillOnce(testing::WithArg<2>( |
| 2027 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, | 2020 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, |
| 2028 base::Unretained(this), conn_id)))); | 2021 base::Unretained(this), conn_id)))); |
| 2029 } | 2022 } |
| 2030 | 2023 |
| 2031 // Send a CHLO that the StatelessRejector will accept. | 2024 // Send a CHLO that the StatelessRejector will accept. |
| 2032 ProcessPacket(client_addr_, conn_id, true, false, SerializeFullCHLO()); | 2025 ProcessPacket(client_addr_, conn_id, true, SerializeFullCHLO()); |
| 2033 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); | 2026 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); |
| 2034 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); | 2027 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); |
| 2035 | 2028 |
| 2036 // Send a data packet that will get buffered | 2029 // Send a data packet that will get buffered |
| 2037 check.Call(1); | 2030 check.Call(1); |
| 2038 ProcessPacket(client_addr_, conn_id, true, false, "My name is Data"); | 2031 ProcessPacket(client_addr_, conn_id, true, "My name is Data"); |
| 2039 EXPECT_TRUE(store->HasBufferedPackets(conn_id)); | 2032 EXPECT_TRUE(store->HasBufferedPackets(conn_id)); |
| 2040 | 2033 |
| 2041 // Pretend that enough time has gone by for the packets to get expired out of | 2034 // Pretend that enough time has gone by for the packets to get expired out of |
| 2042 // the buffer | 2035 // the buffer |
| 2043 mock_helper_.AdvanceTime( | 2036 mock_helper_.AdvanceTime( |
| 2044 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs)); | 2037 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs)); |
| 2045 QuicBufferedPacketStorePeer::expiration_alarm(store)->Cancel(); | 2038 QuicBufferedPacketStorePeer::expiration_alarm(store)->Cancel(); |
| 2046 store->OnExpirationTimeout(); | 2039 store->OnExpirationTimeout(); |
| 2047 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); | 2040 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); |
| 2048 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); | 2041 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2064 check.Call(2); | 2057 check.Call(2); |
| 2065 GetFakeProofSource()->InvokePendingCallback(0); | 2058 GetFakeProofSource()->InvokePendingCallback(0); |
| 2066 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); | 2059 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); |
| 2067 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); | 2060 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); |
| 2068 EXPECT_FALSE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); | 2061 EXPECT_FALSE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); |
| 2069 } | 2062 } |
| 2070 | 2063 |
| 2071 } // namespace | 2064 } // namespace |
| 2072 } // namespace test | 2065 } // namespace test |
| 2073 } // namespace net | 2066 } // namespace net |
| OLD | NEW |