| 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" | |
| 11 #include "base/macros.h" | 10 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 13 #include "net/quic/core/crypto/quic_random.h" | 12 #include "net/quic/core/crypto/quic_random.h" |
| 14 #include "net/quic/core/quic_flags.h" | 13 #include "net/quic/core/quic_flags.h" |
| 15 #include "net/quic/core/quic_utils.h" | 14 #include "net/quic/core/quic_utils.h" |
| 16 #include "net/quic/platform/api/quic_bug_tracker.h" | 15 #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 DVLOG(1) << "Adding connection ID " << connection_id | 379 QUIC_DLOG(INFO) << "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 DVLOG(1) << "Packet without version arrived for unknown connection ID " | 427 QUIC_DLOG(INFO) |
| 428 << header.public_header.connection_id; | 428 << "Packet without version arrived for unknown connection ID " |
| 429 << header.public_header.connection_id; |
| 429 return kFateTimeWait; | 430 return kFateTimeWait; |
| 430 } | 431 } |
| 431 | 432 |
| 432 // Check that the sequence number is within the range that the client is | 433 // Check that the sequence number is within the range that the client is |
| 433 // expected to send before receiving a response from the server. | 434 // expected to send before receiving a response from the server. |
| 434 const int kInvalidPacketNumber = 0; | 435 const int kInvalidPacketNumber = 0; |
| 435 if (header.packet_number == kInvalidPacketNumber || | 436 if (header.packet_number == kInvalidPacketNumber || |
| 436 header.packet_number > kMaxReasonableInitialPacketNumber) { | 437 header.packet_number > kMaxReasonableInitialPacketNumber) { |
| 437 return kFateTimeWait; | 438 return kFateTimeWait; |
| 438 } | 439 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 "not blocked."; | 525 "not blocked."; |
| 525 // Return without adding the connection to the blocked list, to avoid | 526 // Return without adding the connection to the blocked list, to avoid |
| 526 // infinite loops in OnCanWrite. | 527 // infinite loops in OnCanWrite. |
| 527 return; | 528 return; |
| 528 } | 529 } |
| 529 write_blocked_list_.insert(std::make_pair(blocked_writer, true)); | 530 write_blocked_list_.insert(std::make_pair(blocked_writer, true)); |
| 530 } | 531 } |
| 531 | 532 |
| 532 void QuicDispatcher::OnConnectionAddedToTimeWaitList( | 533 void QuicDispatcher::OnConnectionAddedToTimeWaitList( |
| 533 QuicConnectionId connection_id) { | 534 QuicConnectionId connection_id) { |
| 534 DVLOG(1) << "Connection " << connection_id << " added to time wait list."; | 535 QUIC_DLOG(INFO) << "Connection " << connection_id |
| 536 << " added to time wait list."; |
| 535 } | 537 } |
| 536 | 538 |
| 537 void QuicDispatcher::OnPacket() {} | 539 void QuicDispatcher::OnPacket() {} |
| 538 | 540 |
| 539 void QuicDispatcher::OnError(QuicFramer* framer) { | 541 void QuicDispatcher::OnError(QuicFramer* framer) { |
| 540 QuicErrorCode error = framer->error(); | 542 QuicErrorCode error = framer->error(); |
| 541 SetLastError(error); | 543 SetLastError(error); |
| 542 DVLOG(1) << QuicErrorCodeToString(error); | 544 QUIC_DLOG(INFO) << QuicErrorCodeToString(error); |
| 543 } | 545 } |
| 544 | 546 |
| 545 bool QuicDispatcher::ShouldCreateSessionForUnknownVersion(QuicTag version_tag) { | 547 bool QuicDispatcher::ShouldCreateSessionForUnknownVersion(QuicTag version_tag) { |
| 546 return false; | 548 return false; |
| 547 } | 549 } |
| 548 | 550 |
| 549 bool QuicDispatcher::OnProtocolVersionMismatch( | 551 bool QuicDispatcher::OnProtocolVersionMismatch( |
| 550 QuicVersion /*received_version*/) { | 552 QuicVersion /*received_version*/) { |
| 551 QUIC_BUG_IF(!time_wait_list_manager_->IsConnectionIdInTimeWait( | 553 QUIC_BUG_IF(!time_wait_list_manager_->IsConnectionIdInTimeWait( |
| 552 current_connection_id_) && | 554 current_connection_id_) && |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 for (; new_sessions_allowed_per_event_loop_ > 0; | 654 for (; new_sessions_allowed_per_event_loop_ > 0; |
| 653 --new_sessions_allowed_per_event_loop_) { | 655 --new_sessions_allowed_per_event_loop_) { |
| 654 QuicConnectionId connection_id; | 656 QuicConnectionId connection_id; |
| 655 std::list<BufferedPacket> packets = | 657 std::list<BufferedPacket> packets = |
| 656 buffered_packets_.DeliverPacketsForNextConnection(&connection_id); | 658 buffered_packets_.DeliverPacketsForNextConnection(&connection_id); |
| 657 if (packets.empty()) { | 659 if (packets.empty()) { |
| 658 return; | 660 return; |
| 659 } | 661 } |
| 660 QuicSession* session = | 662 QuicSession* session = |
| 661 CreateQuicSession(connection_id, packets.front().client_address); | 663 CreateQuicSession(connection_id, packets.front().client_address); |
| 662 DVLOG(1) << "Created new session for " << connection_id; | 664 QUIC_DLOG(INFO) << "Created new session for " << connection_id; |
| 663 session_map_.insert( | 665 session_map_.insert( |
| 664 std::make_pair(connection_id, base::WrapUnique(session))); | 666 std::make_pair(connection_id, base::WrapUnique(session))); |
| 665 DeliverPacketsToSession(packets, session); | 667 DeliverPacketsToSession(packets, session); |
| 666 } | 668 } |
| 667 } | 669 } |
| 668 | 670 |
| 669 bool QuicDispatcher::HasChlosBuffered() const { | 671 bool QuicDispatcher::HasChlosBuffered() const { |
| 670 return buffered_packets_.HasChlosBuffered(); | 672 return buffered_packets_.HasChlosBuffered(); |
| 671 } | 673 } |
| 672 | 674 |
| 673 bool QuicDispatcher::ShouldCreateOrBufferPacketForConnection( | 675 bool QuicDispatcher::ShouldCreateOrBufferPacketForConnection( |
| 674 QuicConnectionId connection_id) { | 676 QuicConnectionId connection_id) { |
| 675 VLOG(1) << "Received packet from new connection " << connection_id; | 677 VLOG(1) << "Received packet from new connection " << connection_id; |
| 676 return true; | 678 return true; |
| 677 } | 679 } |
| 678 | 680 |
| 679 // Return true if there is any packet buffered in the store. | 681 // Return true if there is any packet buffered in the store. |
| 680 bool QuicDispatcher::HasBufferedPackets(QuicConnectionId connection_id) { | 682 bool QuicDispatcher::HasBufferedPackets(QuicConnectionId connection_id) { |
| 681 return buffered_packets_.HasBufferedPackets(connection_id); | 683 return buffered_packets_.HasBufferedPackets(connection_id); |
| 682 } | 684 } |
| 683 | 685 |
| 684 void QuicDispatcher::OnBufferPacketFailure(EnqueuePacketResult result, | 686 void QuicDispatcher::OnBufferPacketFailure(EnqueuePacketResult result, |
| 685 QuicConnectionId connection_id) { | 687 QuicConnectionId connection_id) { |
| 686 DVLOG(1) << "Fail to buffer packet on connection " << connection_id | 688 QUIC_DLOG(INFO) << "Fail to buffer packet on connection " << connection_id |
| 687 << " because of " << result; | 689 << " because of " << result; |
| 688 } | 690 } |
| 689 | 691 |
| 690 void QuicDispatcher::OnConnectionRejectedStatelessly() {} | 692 void QuicDispatcher::OnConnectionRejectedStatelessly() {} |
| 691 | 693 |
| 692 void QuicDispatcher::OnConnectionClosedStatelessly(QuicErrorCode error) {} | 694 void QuicDispatcher::OnConnectionClosedStatelessly(QuicErrorCode error) {} |
| 693 | 695 |
| 694 bool QuicDispatcher::ShouldAttemptCheapStatelessRejection() { | 696 bool QuicDispatcher::ShouldAttemptCheapStatelessRejection() { |
| 695 return true; | 697 return true; |
| 696 } | 698 } |
| 697 | 699 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 !FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && | 746 !FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && |
| 745 is_new_connection) { | 747 is_new_connection) { |
| 746 ShouldCreateOrBufferPacketForConnection(current_connection_id_); | 748 ShouldCreateOrBufferPacketForConnection(current_connection_id_); |
| 747 } | 749 } |
| 748 } | 750 } |
| 749 return; | 751 return; |
| 750 } | 752 } |
| 751 // Creates a new session and process all buffered packets for this connection. | 753 // Creates a new session and process all buffered packets for this connection. |
| 752 QuicSession* session = | 754 QuicSession* session = |
| 753 CreateQuicSession(current_connection_id_, current_client_address_); | 755 CreateQuicSession(current_connection_id_, current_client_address_); |
| 754 DVLOG(1) << "Created new session for " << current_connection_id_; | 756 QUIC_DLOG(INFO) << "Created new session for " << current_connection_id_; |
| 755 session_map_.insert( | 757 session_map_.insert( |
| 756 std::make_pair(current_connection_id_, base::WrapUnique(session))); | 758 std::make_pair(current_connection_id_, base::WrapUnique(session))); |
| 757 std::list<BufferedPacket> packets = | 759 std::list<BufferedPacket> packets = |
| 758 buffered_packets_.DeliverPackets(current_connection_id_); | 760 buffered_packets_.DeliverPackets(current_connection_id_); |
| 759 // Check if CHLO is the first packet arrived on this connection. | 761 // Check if CHLO is the first packet arrived on this connection. |
| 760 if (!FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && | 762 if (!FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && |
| 761 packets.empty()) { | 763 packets.empty()) { |
| 762 ShouldCreateOrBufferPacketForConnection(current_connection_id_); | 764 ShouldCreateOrBufferPacketForConnection(current_connection_id_); |
| 763 } | 765 } |
| 764 // Process CHLO at first. | 766 // Process CHLO at first. |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 void QuicDispatcher::DeliverPacketsToSession( | 996 void QuicDispatcher::DeliverPacketsToSession( |
| 995 const std::list<BufferedPacket>& packets, | 997 const std::list<BufferedPacket>& packets, |
| 996 QuicSession* session) { | 998 QuicSession* session) { |
| 997 for (const BufferedPacket& packet : packets) { | 999 for (const BufferedPacket& packet : packets) { |
| 998 session->ProcessUdpPacket(packet.server_address, packet.client_address, | 1000 session->ProcessUdpPacket(packet.server_address, packet.client_address, |
| 999 *(packet.packet)); | 1001 *(packet.packet)); |
| 1000 } | 1002 } |
| 1001 } | 1003 } |
| 1002 | 1004 |
| 1003 } // namespace net | 1005 } // namespace net |
| OLD | NEW |