| 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/logging.h" |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 connection_id, *current_packet_, current_server_address_, | 707 connection_id, *current_packet_, current_server_address_, |
| 708 current_client_address_, /*is_chlo=*/false); | 708 current_client_address_, /*is_chlo=*/false); |
| 709 if (rs != EnqueuePacketResult::SUCCESS) { | 709 if (rs != EnqueuePacketResult::SUCCESS) { |
| 710 OnBufferPacketFailure(rs, connection_id); | 710 OnBufferPacketFailure(rs, connection_id); |
| 711 } else if (!FLAGS_quic_create_session_after_insertion && is_new_connection) { | 711 } else if (!FLAGS_quic_create_session_after_insertion && is_new_connection) { |
| 712 ShouldCreateOrBufferPacketForConnection(connection_id); | 712 ShouldCreateOrBufferPacketForConnection(connection_id); |
| 713 } | 713 } |
| 714 } | 714 } |
| 715 | 715 |
| 716 void QuicDispatcher::ProcessChlo() { | 716 void QuicDispatcher::ProcessChlo() { |
| 717 QUIC_BUG_IF(!FLAGS_quic_buffer_packet_till_chlo && | |
| 718 FLAGS_quic_limit_num_new_sessions_per_epoll_loop) | |
| 719 << "Try to limit connection creation per epoll event while not " | |
| 720 "supporting packet buffer. " | |
| 721 "--quic_limit_num_new_sessions_per_epoll_loop = true " | |
| 722 "--quic_buffer_packet_till_chlo = false"; | |
| 723 | |
| 724 if (FLAGS_quic_create_session_after_insertion && | 717 if (FLAGS_quic_create_session_after_insertion && |
| 725 !buffered_packets_.HasBufferedPackets(current_connection_id_) && | 718 !buffered_packets_.HasBufferedPackets(current_connection_id_) && |
| 726 !ShouldCreateOrBufferPacketForConnection(current_connection_id_)) { | 719 !ShouldCreateOrBufferPacketForConnection(current_connection_id_)) { |
| 727 return; | 720 return; |
| 728 } | 721 } |
| 729 | 722 |
| 730 if (FLAGS_quic_limit_num_new_sessions_per_epoll_loop && | 723 if (FLAGS_quic_limit_num_new_sessions_per_epoll_loop && |
| 731 FLAGS_quic_buffer_packet_till_chlo && | |
| 732 new_sessions_allowed_per_event_loop_ <= 0) { | 724 new_sessions_allowed_per_event_loop_ <= 0) { |
| 733 // Can't create new session any more. Wait till next event loop. | 725 // Can't create new session any more. Wait till next event loop. |
| 734 if (!buffered_packets_.HasChloForConnection(current_connection_id_)) { | 726 if (!buffered_packets_.HasChloForConnection(current_connection_id_)) { |
| 735 // Only buffer one CHLO per connection. Remove this condition check when | 727 // Only buffer one CHLO per connection. Remove this condition check when |
| 736 // --gfe2_reloadable_flag_quic_buffer_packets_after_chlo | 728 // --gfe2_reloadable_flag_quic_buffer_packets_after_chlo |
| 737 // is deprecated because after that retransmitted CHLO should be buffered | 729 // is deprecated because after that retransmitted CHLO should be buffered |
| 738 // earlier in OnUnauthenticatedPublicHeader(). | 730 // earlier in OnUnauthenticatedPublicHeader(). |
| 739 bool is_new_connection = | 731 bool is_new_connection = |
| 740 !buffered_packets_.HasBufferedPackets(current_connection_id_); | 732 !buffered_packets_.HasBufferedPackets(current_connection_id_); |
| 741 EnqueuePacketResult rs = buffered_packets_.EnqueuePacket( | 733 EnqueuePacketResult rs = buffered_packets_.EnqueuePacket( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 752 } | 744 } |
| 753 // Creates a new session and process all buffered packets for this connection. | 745 // Creates a new session and process all buffered packets for this connection. |
| 754 QuicSession* session = | 746 QuicSession* session = |
| 755 CreateQuicSession(current_connection_id_, current_client_address_); | 747 CreateQuicSession(current_connection_id_, current_client_address_); |
| 756 DVLOG(1) << "Created new session for " << current_connection_id_; | 748 DVLOG(1) << "Created new session for " << current_connection_id_; |
| 757 session_map_.insert( | 749 session_map_.insert( |
| 758 std::make_pair(current_connection_id_, base::WrapUnique(session))); | 750 std::make_pair(current_connection_id_, base::WrapUnique(session))); |
| 759 std::list<BufferedPacket> packets = | 751 std::list<BufferedPacket> packets = |
| 760 buffered_packets_.DeliverPackets(current_connection_id_); | 752 buffered_packets_.DeliverPackets(current_connection_id_); |
| 761 // Check if CHLO is the first packet arrived on this connection. | 753 // Check if CHLO is the first packet arrived on this connection. |
| 762 if (!FLAGS_quic_create_session_after_insertion && | 754 if (!FLAGS_quic_create_session_after_insertion && packets.empty()) { |
| 763 FLAGS_quic_buffer_packet_till_chlo && packets.empty()) { | |
| 764 ShouldCreateOrBufferPacketForConnection(current_connection_id_); | 755 ShouldCreateOrBufferPacketForConnection(current_connection_id_); |
| 765 } | 756 } |
| 766 // Process CHLO at first. | 757 // Process CHLO at first. |
| 767 session->ProcessUdpPacket(current_server_address_, current_client_address_, | 758 session->ProcessUdpPacket(current_server_address_, current_client_address_, |
| 768 *current_packet_); | 759 *current_packet_); |
| 769 // Deliver queued-up packets in the same order as they arrived. | 760 // Deliver queued-up packets in the same order as they arrived. |
| 770 // Do this even when flag is off because there might be still some packets | 761 // Do this even when flag is off because there might be still some packets |
| 771 // buffered in the store before flag is turned off. | 762 // buffered in the store before flag is turned off. |
| 772 DeliverPacketsToSession(packets, session); | 763 DeliverPacketsToSession(packets, session); |
| 773 if (FLAGS_quic_limit_num_new_sessions_per_epoll_loop && | 764 if (FLAGS_quic_limit_num_new_sessions_per_epoll_loop) { |
| 774 FLAGS_quic_buffer_packet_till_chlo) { | |
| 775 --new_sessions_allowed_per_event_loop_; | 765 --new_sessions_allowed_per_event_loop_; |
| 776 } | 766 } |
| 777 } | 767 } |
| 778 | 768 |
| 779 bool QuicDispatcher::HandlePacketForTimeWait( | 769 bool QuicDispatcher::HandlePacketForTimeWait( |
| 780 const QuicPacketPublicHeader& header) { | 770 const QuicPacketPublicHeader& header) { |
| 781 if (header.reset_flag) { | 771 if (header.reset_flag) { |
| 782 // Public reset packets do not have packet numbers, so ignore the packet. | 772 // Public reset packets do not have packet numbers, so ignore the packet. |
| 783 return false; | 773 return false; |
| 784 } | 774 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 }; | 826 }; |
| 837 | 827 |
| 838 void QuicDispatcher::MaybeRejectStatelessly(QuicConnectionId connection_id, | 828 void QuicDispatcher::MaybeRejectStatelessly(QuicConnectionId connection_id, |
| 839 const QuicPacketHeader& header) { | 829 const QuicPacketHeader& header) { |
| 840 // TODO(rch): This logic should probably live completely inside the rejector. | 830 // TODO(rch): This logic should probably live completely inside the rejector. |
| 841 if (!FLAGS_quic_use_cheap_stateless_rejects || | 831 if (!FLAGS_quic_use_cheap_stateless_rejects || |
| 842 !FLAGS_enable_quic_stateless_reject_support || | 832 !FLAGS_enable_quic_stateless_reject_support || |
| 843 header.public_header.versions.front() <= QUIC_VERSION_32 || | 833 header.public_header.versions.front() <= QUIC_VERSION_32 || |
| 844 !ShouldAttemptCheapStatelessRejection()) { | 834 !ShouldAttemptCheapStatelessRejection()) { |
| 845 // Not use cheap stateless reject. | 835 // Not use cheap stateless reject. |
| 846 if (FLAGS_quic_buffer_packet_till_chlo && | 836 if (!ChloExtractor::Extract(*current_packet_, GetSupportedVersions(), |
| 847 !ChloExtractor::Extract(*current_packet_, GetSupportedVersions(), | |
| 848 nullptr)) { | 837 nullptr)) { |
| 849 // Buffer non-CHLO packets. | 838 // Buffer non-CHLO packets. |
| 850 ProcessUnauthenticatedHeaderFate(kFateBuffer, connection_id, | 839 ProcessUnauthenticatedHeaderFate(kFateBuffer, connection_id, |
| 851 header.packet_number); | 840 header.packet_number); |
| 852 return; | 841 return; |
| 853 } | 842 } |
| 854 ProcessUnauthenticatedHeaderFate(kFateProcess, connection_id, | 843 ProcessUnauthenticatedHeaderFate(kFateProcess, connection_id, |
| 855 header.packet_number); | 844 header.packet_number); |
| 856 return; | 845 return; |
| 857 } | 846 } |
| 858 | 847 |
| 859 std::unique_ptr<StatelessRejector> rejector(new StatelessRejector( | 848 std::unique_ptr<StatelessRejector> rejector(new StatelessRejector( |
| 860 header.public_header.versions.front(), GetSupportedVersions(), | 849 header.public_header.versions.front(), GetSupportedVersions(), |
| 861 crypto_config_, &compressed_certs_cache_, helper()->GetClock(), | 850 crypto_config_, &compressed_certs_cache_, helper()->GetClock(), |
| 862 helper()->GetRandomGenerator(), current_packet_->length(), | 851 helper()->GetRandomGenerator(), current_packet_->length(), |
| 863 current_client_address_, current_server_address_)); | 852 current_client_address_, current_server_address_)); |
| 864 ChloValidator validator(session_helper_.get(), current_server_address_, | 853 ChloValidator validator(session_helper_.get(), current_server_address_, |
| 865 rejector.get()); | 854 rejector.get()); |
| 866 if (!ChloExtractor::Extract(*current_packet_, GetSupportedVersions(), | 855 if (!ChloExtractor::Extract(*current_packet_, GetSupportedVersions(), |
| 867 &validator)) { | 856 &validator)) { |
| 868 if (!FLAGS_quic_buffer_packet_till_chlo) { | |
| 869 QUIC_BUG | |
| 870 << "Have to drop packet because buffering non-chlo packet is " | |
| 871 "not supported while trying to do stateless reject. " | |
| 872 "--gfe2_reloadable_flag_quic_buffer_packet_till_chlo false" | |
| 873 " --gfe2_reloadable_flag_quic_use_cheap_stateless_rejects true"; | |
| 874 ProcessUnauthenticatedHeaderFate(kFateDrop, connection_id, | |
| 875 header.packet_number); | |
| 876 return; | |
| 877 } | |
| 878 ProcessUnauthenticatedHeaderFate(kFateBuffer, connection_id, | 857 ProcessUnauthenticatedHeaderFate(kFateBuffer, connection_id, |
| 879 header.packet_number); | 858 header.packet_number); |
| 880 return; | 859 return; |
| 881 } | 860 } |
| 882 | 861 |
| 883 if (!validator.can_accept()) { | 862 if (!validator.can_accept()) { |
| 884 // This CHLO is prohibited by policy. | 863 // This CHLO is prohibited by policy. |
| 885 StatelessConnectionTerminator terminator(connection_id, &framer_, helper(), | 864 StatelessConnectionTerminator terminator(connection_id, &framer_, helper(), |
| 886 time_wait_list_manager_.get()); | 865 time_wait_list_manager_.get()); |
| 887 terminator.CloseConnection(QUIC_HANDSHAKE_FAILED, | 866 terminator.CloseConnection(QUIC_HANDSHAKE_FAILED, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 void QuicDispatcher::DeliverPacketsToSession( | 986 void QuicDispatcher::DeliverPacketsToSession( |
| 1008 const std::list<BufferedPacket>& packets, | 987 const std::list<BufferedPacket>& packets, |
| 1009 QuicSession* session) { | 988 QuicSession* session) { |
| 1010 for (const BufferedPacket& packet : packets) { | 989 for (const BufferedPacket& packet : packets) { |
| 1011 session->ProcessUdpPacket(packet.server_address, packet.client_address, | 990 session->ProcessUdpPacket(packet.server_address, packet.client_address, |
| 1012 *(packet.packet)); | 991 *(packet.packet)); |
| 1013 } | 992 } |
| 1014 } | 993 } |
| 1015 | 994 |
| 1016 } // namespace net | 995 } // namespace net |
| OLD | NEW |