| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/debug/stack_trace.h" | 9 #include "base/debug/stack_trace.h" |
| 10 #include "base/logging.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "net/quic/core/crypto/quic_random.h" | 13 #include "net/quic/core/crypto/quic_random.h" |
| 13 #include "net/quic/core/quic_flags.h" | 14 #include "net/quic/core/quic_flags.h" |
| 14 #include "net/quic/core/quic_utils.h" | 15 #include "net/quic/core/quic_utils.h" |
| 15 #include "net/quic/platform/api/quic_bug_tracker.h" | 16 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 16 #include "net/quic/platform/api/quic_logging.h" | |
| 17 #include "net/tools/quic/chlo_extractor.h" | 17 #include "net/tools/quic/chlo_extractor.h" |
| 18 #include "net/tools/quic/quic_per_connection_packet_writer.h" | 18 #include "net/tools/quic/quic_per_connection_packet_writer.h" |
| 19 #include "net/tools/quic/quic_simple_server_session.h" | 19 #include "net/tools/quic/quic_simple_server_session.h" |
| 20 #include "net/tools/quic/quic_simple_server_session.h" | 20 #include "net/tools/quic/quic_simple_server_session.h" |
| 21 #include "net/tools/quic/quic_time_wait_list_manager.h" | 21 #include "net/tools/quic/quic_time_wait_list_manager.h" |
| 22 #include "net/tools/quic/stateless_rejector.h" | 22 #include "net/tools/quic/stateless_rejector.h" |
| 23 | 23 |
| 24 using base::StringPiece; | 24 using base::StringPiece; |
| 25 using std::string; | 25 using std::string; |
| 26 | 26 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 ProcessChlo(); | 369 ProcessChlo(); |
| 370 break; | 370 break; |
| 371 } | 371 } |
| 372 case kFateTimeWait: | 372 case kFateTimeWait: |
| 373 // MaybeRejectStatelessly or OnExpiredPackets might have already added the | 373 // MaybeRejectStatelessly or OnExpiredPackets might have already added the |
| 374 // connection to time wait, in which case it should not be added again. | 374 // connection to time wait, in which case it should not be added again. |
| 375 if (!FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects || | 375 if (!FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects || |
| 376 !time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { | 376 !time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { |
| 377 // Add this connection_id to the time-wait state, to safely reject | 377 // Add this connection_id to the time-wait state, to safely reject |
| 378 // future packets. | 378 // future packets. |
| 379 QUIC_DLOG(INFO) << "Adding connection ID " << connection_id | 379 DVLOG(1) << "Adding connection ID " << connection_id |
| 380 << "to time-wait list."; | 380 << "to time-wait list."; |
| 381 time_wait_list_manager_->AddConnectionIdToTimeWait( | 381 time_wait_list_manager_->AddConnectionIdToTimeWait( |
| 382 connection_id, framer_.version(), | 382 connection_id, framer_.version(), |
| 383 /*connection_rejected_statelessly=*/false, nullptr); | 383 /*connection_rejected_statelessly=*/false, nullptr); |
| 384 } | 384 } |
| 385 DCHECK(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); | 385 DCHECK(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); |
| 386 time_wait_list_manager_->ProcessPacket( | 386 time_wait_list_manager_->ProcessPacket( |
| 387 current_server_address_, current_client_address_, connection_id, | 387 current_server_address_, current_client_address_, connection_id, |
| 388 packet_number, *current_packet_); | 388 packet_number, *current_packet_); |
| 389 | 389 |
| 390 if (FLAGS_quic_reloadable_flag_enable_async_get_proof) { | 390 if (FLAGS_quic_reloadable_flag_enable_async_get_proof) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 417 | 417 |
| 418 // Checks that return kFateDrop. | 418 // Checks that return kFateDrop. |
| 419 | 419 |
| 420 // Checks that return kFateTimeWait. | 420 // Checks that return kFateTimeWait. |
| 421 | 421 |
| 422 // All packets within a connection sent by a client before receiving a | 422 // All packets within a connection sent by a client before receiving a |
| 423 // response from the server are required to have the version negotiation flag | 423 // response from the server are required to have the version negotiation flag |
| 424 // set. Since this may be a client continuing a connection we lost track of | 424 // set. Since this may be a client continuing a connection we lost track of |
| 425 // via server restart, send a rejection to fast-fail the connection. | 425 // via server restart, send a rejection to fast-fail the connection. |
| 426 if (!header.public_header.version_flag) { | 426 if (!header.public_header.version_flag) { |
| 427 QUIC_DLOG(INFO) | 427 DVLOG(1) << "Packet without version arrived for unknown connection ID " |
| 428 << "Packet without version arrived for unknown connection ID " | 428 << header.public_header.connection_id; |
| 429 << header.public_header.connection_id; | |
| 430 return kFateTimeWait; | 429 return kFateTimeWait; |
| 431 } | 430 } |
| 432 | 431 |
| 433 // Check that the sequence number is within the range that the client is | 432 // Check that the sequence number is within the range that the client is |
| 434 // expected to send before receiving a response from the server. | 433 // expected to send before receiving a response from the server. |
| 435 const int kInvalidPacketNumber = 0; | 434 const int kInvalidPacketNumber = 0; |
| 436 if (header.packet_number == kInvalidPacketNumber || | 435 if (header.packet_number == kInvalidPacketNumber || |
| 437 header.packet_number > kMaxReasonableInitialPacketNumber) { | 436 header.packet_number > kMaxReasonableInitialPacketNumber) { |
| 438 return kFateTimeWait; | 437 return kFateTimeWait; |
| 439 } | 438 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 "not blocked."; | 524 "not blocked."; |
| 526 // Return without adding the connection to the blocked list, to avoid | 525 // Return without adding the connection to the blocked list, to avoid |
| 527 // infinite loops in OnCanWrite. | 526 // infinite loops in OnCanWrite. |
| 528 return; | 527 return; |
| 529 } | 528 } |
| 530 write_blocked_list_.insert(std::make_pair(blocked_writer, true)); | 529 write_blocked_list_.insert(std::make_pair(blocked_writer, true)); |
| 531 } | 530 } |
| 532 | 531 |
| 533 void QuicDispatcher::OnConnectionAddedToTimeWaitList( | 532 void QuicDispatcher::OnConnectionAddedToTimeWaitList( |
| 534 QuicConnectionId connection_id) { | 533 QuicConnectionId connection_id) { |
| 535 QUIC_DLOG(INFO) << "Connection " << connection_id | 534 DVLOG(1) << "Connection " << connection_id << " added to time wait list."; |
| 536 << " added to time wait list."; | |
| 537 } | 535 } |
| 538 | 536 |
| 539 void QuicDispatcher::OnPacket() {} | 537 void QuicDispatcher::OnPacket() {} |
| 540 | 538 |
| 541 void QuicDispatcher::OnError(QuicFramer* framer) { | 539 void QuicDispatcher::OnError(QuicFramer* framer) { |
| 542 QuicErrorCode error = framer->error(); | 540 QuicErrorCode error = framer->error(); |
| 543 SetLastError(error); | 541 SetLastError(error); |
| 544 QUIC_DLOG(INFO) << QuicErrorCodeToString(error); | 542 DVLOG(1) << QuicErrorCodeToString(error); |
| 545 } | 543 } |
| 546 | 544 |
| 547 bool QuicDispatcher::ShouldCreateSessionForUnknownVersion(QuicTag version_tag) { | 545 bool QuicDispatcher::ShouldCreateSessionForUnknownVersion(QuicTag version_tag) { |
| 548 return false; | 546 return false; |
| 549 } | 547 } |
| 550 | 548 |
| 551 bool QuicDispatcher::OnProtocolVersionMismatch( | 549 bool QuicDispatcher::OnProtocolVersionMismatch( |
| 552 QuicVersion /*received_version*/) { | 550 QuicVersion /*received_version*/) { |
| 553 QUIC_BUG_IF(!time_wait_list_manager_->IsConnectionIdInTimeWait( | 551 QUIC_BUG_IF(!time_wait_list_manager_->IsConnectionIdInTimeWait( |
| 554 current_connection_id_) && | 552 current_connection_id_) && |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 for (; new_sessions_allowed_per_event_loop_ > 0; | 652 for (; new_sessions_allowed_per_event_loop_ > 0; |
| 655 --new_sessions_allowed_per_event_loop_) { | 653 --new_sessions_allowed_per_event_loop_) { |
| 656 QuicConnectionId connection_id; | 654 QuicConnectionId connection_id; |
| 657 std::list<BufferedPacket> packets = | 655 std::list<BufferedPacket> packets = |
| 658 buffered_packets_.DeliverPacketsForNextConnection(&connection_id); | 656 buffered_packets_.DeliverPacketsForNextConnection(&connection_id); |
| 659 if (packets.empty()) { | 657 if (packets.empty()) { |
| 660 return; | 658 return; |
| 661 } | 659 } |
| 662 QuicSession* session = | 660 QuicSession* session = |
| 663 CreateQuicSession(connection_id, packets.front().client_address); | 661 CreateQuicSession(connection_id, packets.front().client_address); |
| 664 QUIC_DLOG(INFO) << "Created new session for " << connection_id; | 662 DVLOG(1) << "Created new session for " << connection_id; |
| 665 session_map_.insert( | 663 session_map_.insert( |
| 666 std::make_pair(connection_id, base::WrapUnique(session))); | 664 std::make_pair(connection_id, base::WrapUnique(session))); |
| 667 DeliverPacketsToSession(packets, session); | 665 DeliverPacketsToSession(packets, session); |
| 668 } | 666 } |
| 669 } | 667 } |
| 670 | 668 |
| 671 bool QuicDispatcher::HasChlosBuffered() const { | 669 bool QuicDispatcher::HasChlosBuffered() const { |
| 672 return buffered_packets_.HasChlosBuffered(); | 670 return buffered_packets_.HasChlosBuffered(); |
| 673 } | 671 } |
| 674 | 672 |
| 675 bool QuicDispatcher::ShouldCreateOrBufferPacketForConnection( | 673 bool QuicDispatcher::ShouldCreateOrBufferPacketForConnection( |
| 676 QuicConnectionId connection_id) { | 674 QuicConnectionId connection_id) { |
| 677 VLOG(1) << "Received packet from new connection " << connection_id; | 675 VLOG(1) << "Received packet from new connection " << connection_id; |
| 678 return true; | 676 return true; |
| 679 } | 677 } |
| 680 | 678 |
| 681 // Return true if there is any packet buffered in the store. | 679 // Return true if there is any packet buffered in the store. |
| 682 bool QuicDispatcher::HasBufferedPackets(QuicConnectionId connection_id) { | 680 bool QuicDispatcher::HasBufferedPackets(QuicConnectionId connection_id) { |
| 683 return buffered_packets_.HasBufferedPackets(connection_id); | 681 return buffered_packets_.HasBufferedPackets(connection_id); |
| 684 } | 682 } |
| 685 | 683 |
| 686 void QuicDispatcher::OnBufferPacketFailure(EnqueuePacketResult result, | 684 void QuicDispatcher::OnBufferPacketFailure(EnqueuePacketResult result, |
| 687 QuicConnectionId connection_id) { | 685 QuicConnectionId connection_id) { |
| 688 QUIC_DLOG(INFO) << "Fail to buffer packet on connection " << connection_id | 686 DVLOG(1) << "Fail to buffer packet on connection " << connection_id |
| 689 << " because of " << result; | 687 << " because of " << result; |
| 690 } | 688 } |
| 691 | 689 |
| 692 void QuicDispatcher::OnConnectionRejectedStatelessly() {} | 690 void QuicDispatcher::OnConnectionRejectedStatelessly() {} |
| 693 | 691 |
| 694 void QuicDispatcher::OnConnectionClosedStatelessly(QuicErrorCode error) {} | 692 void QuicDispatcher::OnConnectionClosedStatelessly(QuicErrorCode error) {} |
| 695 | 693 |
| 696 bool QuicDispatcher::ShouldAttemptCheapStatelessRejection() { | 694 bool QuicDispatcher::ShouldAttemptCheapStatelessRejection() { |
| 697 return true; | 695 return true; |
| 698 } | 696 } |
| 699 | 697 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 !FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && | 744 !FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && |
| 747 is_new_connection) { | 745 is_new_connection) { |
| 748 ShouldCreateOrBufferPacketForConnection(current_connection_id_); | 746 ShouldCreateOrBufferPacketForConnection(current_connection_id_); |
| 749 } | 747 } |
| 750 } | 748 } |
| 751 return; | 749 return; |
| 752 } | 750 } |
| 753 // Creates a new session and process all buffered packets for this connection. | 751 // Creates a new session and process all buffered packets for this connection. |
| 754 QuicSession* session = | 752 QuicSession* session = |
| 755 CreateQuicSession(current_connection_id_, current_client_address_); | 753 CreateQuicSession(current_connection_id_, current_client_address_); |
| 756 QUIC_DLOG(INFO) << "Created new session for " << current_connection_id_; | 754 DVLOG(1) << "Created new session for " << current_connection_id_; |
| 757 session_map_.insert( | 755 session_map_.insert( |
| 758 std::make_pair(current_connection_id_, base::WrapUnique(session))); | 756 std::make_pair(current_connection_id_, base::WrapUnique(session))); |
| 759 std::list<BufferedPacket> packets = | 757 std::list<BufferedPacket> packets = |
| 760 buffered_packets_.DeliverPackets(current_connection_id_); | 758 buffered_packets_.DeliverPackets(current_connection_id_); |
| 761 // Check if CHLO is the first packet arrived on this connection. | 759 // Check if CHLO is the first packet arrived on this connection. |
| 762 if (!FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && | 760 if (!FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && |
| 763 packets.empty()) { | 761 packets.empty()) { |
| 764 ShouldCreateOrBufferPacketForConnection(current_connection_id_); | 762 ShouldCreateOrBufferPacketForConnection(current_connection_id_); |
| 765 } | 763 } |
| 766 // Process CHLO at first. | 764 // Process CHLO at first. |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 void QuicDispatcher::DeliverPacketsToSession( | 994 void QuicDispatcher::DeliverPacketsToSession( |
| 997 const std::list<BufferedPacket>& packets, | 995 const std::list<BufferedPacket>& packets, |
| 998 QuicSession* session) { | 996 QuicSession* session) { |
| 999 for (const BufferedPacket& packet : packets) { | 997 for (const BufferedPacket& packet : packets) { |
| 1000 session->ProcessUdpPacket(packet.server_address, packet.client_address, | 998 session->ProcessUdpPacket(packet.server_address, packet.client_address, |
| 1001 *(packet.packet)); | 999 *(packet.packet)); |
| 1002 } | 1000 } |
| 1003 } | 1001 } |
| 1004 | 1002 |
| 1005 } // namespace net | 1003 } // namespace net |
| OLD | NEW |