| 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 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 DVLOG(1) << "Created new session for " << connection_id; | 638 DVLOG(1) << "Created new session for " << connection_id; |
| 639 session_map_.insert(std::make_pair(connection_id, session)); | 639 session_map_.insert(std::make_pair(connection_id, session)); |
| 640 DeliverPacketsToSession(packets, session); | 640 DeliverPacketsToSession(packets, session); |
| 641 } | 641 } |
| 642 } | 642 } |
| 643 | 643 |
| 644 bool QuicDispatcher::HasChlosBuffered() const { | 644 bool QuicDispatcher::HasChlosBuffered() const { |
| 645 return buffered_packets_.HasChlosBuffered(); | 645 return buffered_packets_.HasChlosBuffered(); |
| 646 } | 646 } |
| 647 | 647 |
| 648 void QuicDispatcher::OnNewConnectionAdded(QuicConnectionId connection_id) { | 648 bool QuicDispatcher::ShouldCreateOrBufferPacketForConnection( |
| 649 QuicConnectionId connection_id) { |
| 649 VLOG(1) << "Received packet from new connection " << connection_id; | 650 VLOG(1) << "Received packet from new connection " << connection_id; |
| 651 return true; |
| 650 } | 652 } |
| 651 | 653 |
| 652 // Return true if there is any packet buffered in the store. | 654 // Return true if there is any packet buffered in the store. |
| 653 bool QuicDispatcher::HasBufferedPackets(QuicConnectionId connection_id) { | 655 bool QuicDispatcher::HasBufferedPackets(QuicConnectionId connection_id) { |
| 654 return buffered_packets_.HasBufferedPackets(connection_id); | 656 return buffered_packets_.HasBufferedPackets(connection_id); |
| 655 } | 657 } |
| 656 | 658 |
| 657 void QuicDispatcher::OnBufferPacketFailure(EnqueuePacketResult result, | 659 void QuicDispatcher::OnBufferPacketFailure(EnqueuePacketResult result, |
| 658 QuicConnectionId connection_id) { | 660 QuicConnectionId connection_id) { |
| 659 DVLOG(1) << "Fail to buffer packet on connection " << connection_id | 661 DVLOG(1) << "Fail to buffer packet on connection " << connection_id |
| 660 << " because of " << result; | 662 << " because of " << result; |
| 661 } | 663 } |
| 662 | 664 |
| 663 void QuicDispatcher::OnConnectionRejectedStatelessly() {} | 665 void QuicDispatcher::OnConnectionRejectedStatelessly() {} |
| 664 | 666 |
| 665 void QuicDispatcher::OnConnectionClosedStatelessly(QuicErrorCode error) {} | 667 void QuicDispatcher::OnConnectionClosedStatelessly(QuicErrorCode error) {} |
| 666 | 668 |
| 667 bool QuicDispatcher::ShouldAttemptCheapStatelessRejection() { | 669 bool QuicDispatcher::ShouldAttemptCheapStatelessRejection() { |
| 668 return true; | 670 return true; |
| 669 } | 671 } |
| 670 | 672 |
| 671 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() { | 673 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() { |
| 672 return new QuicTimeWaitListManager(writer_.get(), this, helper_.get(), | 674 return new QuicTimeWaitListManager(writer_.get(), this, helper_.get(), |
| 673 alarm_factory_.get()); | 675 alarm_factory_.get()); |
| 674 } | 676 } |
| 675 | 677 |
| 676 void QuicDispatcher::BufferEarlyPacket(QuicConnectionId connection_id) { | 678 void QuicDispatcher::BufferEarlyPacket(QuicConnectionId connection_id) { |
| 677 bool is_new_connection = !buffered_packets_.HasBufferedPackets(connection_id); | 679 bool is_new_connection = !buffered_packets_.HasBufferedPackets(connection_id); |
| 680 if (FLAGS_quic_create_session_after_insertion && is_new_connection && |
| 681 !ShouldCreateOrBufferPacketForConnection(connection_id)) { |
| 682 return; |
| 683 } |
| 678 EnqueuePacketResult rs = buffered_packets_.EnqueuePacket( | 684 EnqueuePacketResult rs = buffered_packets_.EnqueuePacket( |
| 679 connection_id, *current_packet_, current_server_address_, | 685 connection_id, *current_packet_, current_server_address_, |
| 680 current_client_address_, /*is_chlo=*/false); | 686 current_client_address_, /*is_chlo=*/false); |
| 681 if (rs != EnqueuePacketResult::SUCCESS) { | 687 if (rs != EnqueuePacketResult::SUCCESS) { |
| 682 OnBufferPacketFailure(rs, connection_id); | 688 OnBufferPacketFailure(rs, connection_id); |
| 683 } else if (is_new_connection) { | 689 } else if (FLAGS_quic_create_session_after_insertion && is_new_connection) { |
| 684 OnNewConnectionAdded(connection_id); | 690 ShouldCreateOrBufferPacketForConnection(connection_id); |
| 685 } | 691 } |
| 686 } | 692 } |
| 687 | 693 |
| 688 void QuicDispatcher::ProcessChlo() { | 694 void QuicDispatcher::ProcessChlo() { |
| 689 QUIC_BUG_IF(!FLAGS_quic_buffer_packet_till_chlo && | 695 QUIC_BUG_IF(!FLAGS_quic_buffer_packet_till_chlo && |
| 690 FLAGS_quic_limit_num_new_sessions_per_epoll_loop) | 696 FLAGS_quic_limit_num_new_sessions_per_epoll_loop) |
| 691 << "Try to limit connection creation per epoll event while not " | 697 << "Try to limit connection creation per epoll event while not " |
| 692 "supporting packet buffer. " | 698 "supporting packet buffer. " |
| 693 "--quic_limit_num_new_sessions_per_epoll_loop = true " | 699 "--quic_limit_num_new_sessions_per_epoll_loop = true " |
| 694 "--quic_buffer_packet_till_chlo = false"; | 700 "--quic_buffer_packet_till_chlo = false"; |
| 695 | 701 |
| 702 if (FLAGS_quic_create_session_after_insertion && |
| 703 !buffered_packets_.HasBufferedPackets(current_connection_id_) && |
| 704 !ShouldCreateOrBufferPacketForConnection(current_connection_id_)) { |
| 705 return; |
| 706 } |
| 707 |
| 696 if (FLAGS_quic_limit_num_new_sessions_per_epoll_loop && | 708 if (FLAGS_quic_limit_num_new_sessions_per_epoll_loop && |
| 697 FLAGS_quic_buffer_packet_till_chlo && | 709 FLAGS_quic_buffer_packet_till_chlo && |
| 698 new_sessions_allowed_per_event_loop_ <= 0) { | 710 new_sessions_allowed_per_event_loop_ <= 0) { |
| 699 // Can't create new session any more. Wait till next event loop. | 711 // Can't create new session any more. Wait till next event loop. |
| 700 if (!buffered_packets_.HasChloForConnection(current_connection_id_)) { | 712 if (!buffered_packets_.HasChloForConnection(current_connection_id_)) { |
| 701 // Only buffer one CHLO per connection. Remove this condition check when | 713 // Only buffer one CHLO per connection. Remove this condition check when |
| 702 // --gfe2_reloadable_flag_quic_buffer_packets_after_chlo | 714 // --gfe2_reloadable_flag_quic_buffer_packets_after_chlo |
| 703 // is deprecated because after that retransmitted CHLO should be buffered | 715 // is deprecated because after that retransmitted CHLO should be buffered |
| 704 // earlier in OnUnauthenticatedPublicHeader(). | 716 // earlier in OnUnauthenticatedPublicHeader(). |
| 705 bool is_new_connection = | 717 bool is_new_connection = |
| 706 !buffered_packets_.HasBufferedPackets(current_connection_id_); | 718 !buffered_packets_.HasBufferedPackets(current_connection_id_); |
| 707 EnqueuePacketResult rs = buffered_packets_.EnqueuePacket( | 719 EnqueuePacketResult rs = buffered_packets_.EnqueuePacket( |
| 708 current_connection_id_, *current_packet_, current_server_address_, | 720 current_connection_id_, *current_packet_, current_server_address_, |
| 709 current_client_address_, /*is_chlo=*/true); | 721 current_client_address_, /*is_chlo=*/true); |
| 710 if (rs != EnqueuePacketResult::SUCCESS) { | 722 if (rs != EnqueuePacketResult::SUCCESS) { |
| 711 OnBufferPacketFailure(rs, current_connection_id_); | 723 OnBufferPacketFailure(rs, current_connection_id_); |
| 712 } else if (is_new_connection) { | 724 } else if (!FLAGS_quic_create_session_after_insertion && |
| 713 OnNewConnectionAdded(current_connection_id_); | 725 is_new_connection) { |
| 726 ShouldCreateOrBufferPacketForConnection(current_connection_id_); |
| 714 } | 727 } |
| 715 } | 728 } |
| 716 return; | 729 return; |
| 717 } | 730 } |
| 718 | |
| 719 // Creates a new session and process all buffered packets for this connection. | 731 // Creates a new session and process all buffered packets for this connection. |
| 720 QuicServerSessionBase* session = | 732 QuicServerSessionBase* session = |
| 721 CreateQuicSession(current_connection_id_, current_client_address_); | 733 CreateQuicSession(current_connection_id_, current_client_address_); |
| 722 DVLOG(1) << "Created new session for " << current_connection_id_; | 734 DVLOG(1) << "Created new session for " << current_connection_id_; |
| 723 session_map_.insert(std::make_pair(current_connection_id_, session)); | 735 session_map_.insert(std::make_pair(current_connection_id_, session)); |
| 724 std::list<BufferedPacket> packets = | 736 std::list<BufferedPacket> packets = |
| 725 buffered_packets_.DeliverPackets(current_connection_id_); | 737 buffered_packets_.DeliverPackets(current_connection_id_); |
| 726 // Check if CHLO is the first packet arrived on this connection. | 738 // Check if CHLO is the first packet arrived on this connection. |
| 727 if (FLAGS_quic_buffer_packet_till_chlo && packets.empty()) { | 739 if (!FLAGS_quic_create_session_after_insertion && |
| 728 OnNewConnectionAdded(current_connection_id_); | 740 FLAGS_quic_buffer_packet_till_chlo && packets.empty()) { |
| 741 ShouldCreateOrBufferPacketForConnection(current_connection_id_); |
| 729 } | 742 } |
| 730 // Process CHLO at first. | 743 // Process CHLO at first. |
| 731 session->ProcessUdpPacket(current_server_address_, current_client_address_, | 744 session->ProcessUdpPacket(current_server_address_, current_client_address_, |
| 732 *current_packet_); | 745 *current_packet_); |
| 733 | |
| 734 // Deliver queued-up packets in the same order as they arrived. | 746 // Deliver queued-up packets in the same order as they arrived. |
| 735 // Do this even when flag is off because there might be still some packets | 747 // Do this even when flag is off because there might be still some packets |
| 736 // buffered in the store before flag is turned off. | 748 // buffered in the store before flag is turned off. |
| 737 DeliverPacketsToSession(packets, session); | 749 DeliverPacketsToSession(packets, session); |
| 738 if (FLAGS_quic_limit_num_new_sessions_per_epoll_loop && | 750 if (FLAGS_quic_limit_num_new_sessions_per_epoll_loop && |
| 739 FLAGS_quic_buffer_packet_till_chlo) { | 751 FLAGS_quic_buffer_packet_till_chlo) { |
| 740 --new_sessions_allowed_per_event_loop_; | 752 --new_sessions_allowed_per_event_loop_; |
| 741 } | 753 } |
| 742 } | 754 } |
| 743 | 755 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 void QuicDispatcher::DeliverPacketsToSession( | 922 void QuicDispatcher::DeliverPacketsToSession( |
| 911 const std::list<BufferedPacket>& packets, | 923 const std::list<BufferedPacket>& packets, |
| 912 QuicServerSessionBase* session) { | 924 QuicServerSessionBase* session) { |
| 913 for (const BufferedPacket& packet : packets) { | 925 for (const BufferedPacket& packet : packets) { |
| 914 session->ProcessUdpPacket(packet.server_address, packet.client_address, | 926 session->ProcessUdpPacket(packet.server_address, packet.client_address, |
| 915 *(packet.packet)); | 927 *(packet.packet)); |
| 916 } | 928 } |
| 917 } | 929 } |
| 918 | 930 |
| 919 } // namespace net | 931 } // namespace net |
| OLD | NEW |