Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: net/tools/quic/quic_dispatcher.cc

Issue 2846013002: Remove unused packet_number parameter from multiple functions in QUIC. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/quic/quic_dispatcher.h ('k') | net/tools/quic/quic_dispatcher_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/macros.h" 9 #include "base/macros.h"
10 #include "net/quic/core/crypto/quic_random.h" 10 #include "net/quic/core/crypto/quic_random.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 } 331 }
332 332
333 bool QuicDispatcher::OnUnauthenticatedHeader(const QuicPacketHeader& header) { 333 bool QuicDispatcher::OnUnauthenticatedHeader(const QuicPacketHeader& header) {
334 QuicConnectionId connection_id = header.public_header.connection_id; 334 QuicConnectionId connection_id = header.public_header.connection_id;
335 335
336 if (time_wait_list_manager_->IsConnectionIdInTimeWait( 336 if (time_wait_list_manager_->IsConnectionIdInTimeWait(
337 header.public_header.connection_id)) { 337 header.public_header.connection_id)) {
338 // This connection ID is already in time-wait state. 338 // This connection ID is already in time-wait state.
339 time_wait_list_manager_->ProcessPacket( 339 time_wait_list_manager_->ProcessPacket(
340 current_server_address_, current_client_address_, 340 current_server_address_, current_client_address_,
341 header.public_header.connection_id, header.packet_number, 341 header.public_header.connection_id, *current_packet_);
342 *current_packet_);
343 return false; 342 return false;
344 } 343 }
345 344
346 // Packet's connection ID is unknown. Apply the validity checks. 345 // Packet's connection ID is unknown. Apply the validity checks.
347 QuicPacketFate fate = ValidityChecks(header); 346 QuicPacketFate fate = ValidityChecks(header);
348 if (fate == kFateProcess) { 347 if (fate == kFateProcess) {
349 // Execute stateless rejection logic to determine the packet fate, then 348 // Execute stateless rejection logic to determine the packet fate, then
350 // invoke ProcessUnauthenticatedHeaderFate. 349 // invoke ProcessUnauthenticatedHeaderFate.
351 MaybeRejectStatelessly(connection_id, header); 350 MaybeRejectStatelessly(connection_id,
351 header.public_header.versions.front());
352 } else { 352 } else {
353 // If the fate is already known, process it without executing stateless 353 // If the fate is already known, process it without executing stateless
354 // rejection logic. 354 // rejection logic.
355 ProcessUnauthenticatedHeaderFate(fate, connection_id, header.packet_number); 355 ProcessUnauthenticatedHeaderFate(fate, connection_id);
356 } 356 }
357 357
358 return false; 358 return false;
359 } 359 }
360 360
361 void QuicDispatcher::ProcessUnauthenticatedHeaderFate( 361 void QuicDispatcher::ProcessUnauthenticatedHeaderFate(
362 QuicPacketFate fate, 362 QuicPacketFate fate,
363 QuicConnectionId connection_id, 363 QuicConnectionId connection_id) {
364 QuicPacketNumber packet_number) {
365 switch (fate) { 364 switch (fate) {
366 case kFateProcess: { 365 case kFateProcess: {
367 ProcessChlo(packet_number); 366 ProcessChlo();
368 break; 367 break;
369 } 368 }
370 case kFateTimeWait: 369 case kFateTimeWait:
371 // MaybeRejectStatelessly or OnExpiredPackets might have already added the 370 // MaybeRejectStatelessly or OnExpiredPackets might have already added the
372 // connection to time wait, in which case it should not be added again. 371 // connection to time wait, in which case it should not be added again.
373 if (!FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects || 372 if (!FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects ||
374 !time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { 373 !time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) {
375 // Add this connection_id to the time-wait state, to safely reject 374 // Add this connection_id to the time-wait state, to safely reject
376 // future packets. 375 // future packets.
377 QUIC_DLOG(INFO) << "Adding connection ID " << connection_id 376 QUIC_DLOG(INFO) << "Adding connection ID " << connection_id
378 << "to time-wait list."; 377 << "to time-wait list.";
379 time_wait_list_manager_->AddConnectionIdToTimeWait( 378 time_wait_list_manager_->AddConnectionIdToTimeWait(
380 connection_id, framer_.version(), 379 connection_id, framer_.version(),
381 /*connection_rejected_statelessly=*/false, nullptr); 380 /*connection_rejected_statelessly=*/false, nullptr);
382 } 381 }
383 DCHECK(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); 382 DCHECK(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
384 time_wait_list_manager_->ProcessPacket( 383 time_wait_list_manager_->ProcessPacket(current_server_address_,
385 current_server_address_, current_client_address_, connection_id, 384 current_client_address_,
386 packet_number, *current_packet_); 385 connection_id, *current_packet_);
387 386
388 // Any packets which were buffered while the stateless rejector logic was 387 // Any packets which were buffered while the stateless rejector logic was
389 // running should be discarded. Do not inform the time wait list manager, 388 // running should be discarded. Do not inform the time wait list manager,
390 // which should already have a made a decision about sending a reject 389 // which should already have a made a decision about sending a reject
391 // based on the CHLO alone. 390 // based on the CHLO alone.
392 buffered_packets_.DiscardPackets(connection_id); 391 buffered_packets_.DiscardPackets(connection_id);
393 break; 392 break;
394 case kFateBuffer: 393 case kFateBuffer:
395 // This packet is a non-CHLO packet which has arrived before the 394 // This packet is a non-CHLO packet which has arrived before the
396 // corresponding CHLO, *or* this packet was received while the 395 // corresponding CHLO, *or* this packet was received while the
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 connection_id, *current_packet_, current_server_address_, 709 connection_id, *current_packet_, current_server_address_,
711 current_client_address_, /*is_chlo=*/false); 710 current_client_address_, /*is_chlo=*/false);
712 if (rs != EnqueuePacketResult::SUCCESS) { 711 if (rs != EnqueuePacketResult::SUCCESS) {
713 OnBufferPacketFailure(rs, connection_id); 712 OnBufferPacketFailure(rs, connection_id);
714 } else if (!FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && 713 } else if (!FLAGS_quic_reloadable_flag_quic_create_session_after_insertion &&
715 is_new_connection) { 714 is_new_connection) {
716 ShouldCreateOrBufferPacketForConnection(connection_id); 715 ShouldCreateOrBufferPacketForConnection(connection_id);
717 } 716 }
718 } 717 }
719 718
720 void QuicDispatcher::ProcessChlo(QuicPacketNumber packet_number) { 719 void QuicDispatcher::ProcessChlo() {
721 if (!accept_new_connections_) { 720 if (!accept_new_connections_) {
722 // Don't any create new connection. 721 // Don't any create new connection.
723 time_wait_list_manager()->AddConnectionIdToTimeWait( 722 time_wait_list_manager()->AddConnectionIdToTimeWait(
724 current_connection_id(), framer()->version(), 723 current_connection_id(), framer()->version(),
725 /*connection_rejected_statelessly=*/false, 724 /*connection_rejected_statelessly=*/false,
726 /*termination_packets=*/nullptr); 725 /*termination_packets=*/nullptr);
727 // This will trigger sending Public Reset packet. 726 // This will trigger sending Public Reset packet.
728 time_wait_list_manager()->ProcessPacket( 727 time_wait_list_manager()->ProcessPacket(
729 current_server_address(), current_client_address(), 728 current_server_address(), current_client_address(),
730 current_connection_id(), packet_number, current_packet()); 729 current_connection_id(), current_packet());
731 return; 730 return;
732 } 731 }
733 if (FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && 732 if (FLAGS_quic_reloadable_flag_quic_create_session_after_insertion &&
734 !buffered_packets_.HasBufferedPackets(current_connection_id_) && 733 !buffered_packets_.HasBufferedPackets(current_connection_id_) &&
735 !ShouldCreateOrBufferPacketForConnection(current_connection_id_)) { 734 !ShouldCreateOrBufferPacketForConnection(current_connection_id_)) {
736 QUIC_FLAG_COUNT_N(quic_reloadable_flag_quic_create_session_after_insertion, 735 QUIC_FLAG_COUNT_N(quic_reloadable_flag_quic_create_session_after_insertion,
737 2, 5); 736 2, 5);
738 return; 737 return;
739 } 738 }
740 if (FLAGS_quic_allow_chlo_buffering && 739 if (FLAGS_quic_allow_chlo_buffering &&
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 807
809 bool QuicDispatcher::OnUnauthenticatedUnknownPublicHeader( 808 bool QuicDispatcher::OnUnauthenticatedUnknownPublicHeader(
810 const QuicPacketPublicHeader& header) { 809 const QuicPacketPublicHeader& header) {
811 return true; 810 return true;
812 } 811 }
813 812
814 class StatelessRejectorProcessDoneCallback 813 class StatelessRejectorProcessDoneCallback
815 : public StatelessRejector::ProcessDoneCallback { 814 : public StatelessRejector::ProcessDoneCallback {
816 public: 815 public:
817 StatelessRejectorProcessDoneCallback(QuicDispatcher* dispatcher, 816 StatelessRejectorProcessDoneCallback(QuicDispatcher* dispatcher,
818 QuicPacketNumber packet_number,
819 QuicVersion first_version) 817 QuicVersion first_version)
820 : dispatcher_(dispatcher), 818 : dispatcher_(dispatcher),
821 current_client_address_(dispatcher->current_client_address_), 819 current_client_address_(dispatcher->current_client_address_),
822 current_server_address_(dispatcher->current_server_address_), 820 current_server_address_(dispatcher->current_server_address_),
823 current_packet_( 821 current_packet_(
824 dispatcher->current_packet_->Clone()), // Note: copies the packet 822 dispatcher->current_packet_->Clone()), // Note: copies the packet
825 packet_number_(packet_number),
826 first_version_(first_version) {} 823 first_version_(first_version) {}
827 824
828 void Run(std::unique_ptr<StatelessRejector> rejector) override { 825 void Run(std::unique_ptr<StatelessRejector> rejector) override {
829 dispatcher_->OnStatelessRejectorProcessDone( 826 dispatcher_->OnStatelessRejectorProcessDone(
830 std::move(rejector), current_client_address_, current_server_address_, 827 std::move(rejector), current_client_address_, current_server_address_,
831 std::move(current_packet_), packet_number_, first_version_); 828 std::move(current_packet_), first_version_);
832 } 829 }
833 830
834 private: 831 private:
835 QuicDispatcher* dispatcher_; 832 QuicDispatcher* dispatcher_;
836 QuicSocketAddress current_client_address_; 833 QuicSocketAddress current_client_address_;
837 QuicSocketAddress current_server_address_; 834 QuicSocketAddress current_server_address_;
838 std::unique_ptr<QuicReceivedPacket> current_packet_; 835 std::unique_ptr<QuicReceivedPacket> current_packet_;
839 QuicPacketNumber packet_number_;
840 QuicVersion first_version_; 836 QuicVersion first_version_;
841 }; 837 };
842 838
843 void QuicDispatcher::MaybeRejectStatelessly(QuicConnectionId connection_id, 839 void QuicDispatcher::MaybeRejectStatelessly(QuicConnectionId connection_id,
844 const QuicPacketHeader& header) { 840 QuicVersion version) {
845 // TODO(rch): This logic should probably live completely inside the rejector. 841 // TODO(rch): This logic should probably live completely inside the rejector.
846 if (!FLAGS_quic_allow_chlo_buffering || 842 if (!FLAGS_quic_allow_chlo_buffering ||
847 !FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects || 843 !FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects ||
848 !FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support || 844 !FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support ||
849 !ShouldAttemptCheapStatelessRejection()) { 845 !ShouldAttemptCheapStatelessRejection()) {
850 // Not use cheap stateless reject. 846 // Not use cheap stateless reject.
851 if (FLAGS_quic_allow_chlo_buffering && 847 if (FLAGS_quic_allow_chlo_buffering &&
852 !ChloExtractor::Extract(*current_packet_, GetSupportedVersions(), 848 !ChloExtractor::Extract(*current_packet_, GetSupportedVersions(),
853 nullptr)) { 849 nullptr)) {
854 // Buffer non-CHLO packets. 850 // Buffer non-CHLO packets.
855 ProcessUnauthenticatedHeaderFate(kFateBuffer, connection_id, 851 ProcessUnauthenticatedHeaderFate(kFateBuffer, connection_id);
856 header.packet_number);
857 return; 852 return;
858 } 853 }
859 ProcessUnauthenticatedHeaderFate(kFateProcess, connection_id, 854 ProcessUnauthenticatedHeaderFate(kFateProcess, connection_id);
860 header.packet_number);
861 return; 855 return;
862 } 856 }
863 857
864 std::unique_ptr<StatelessRejector> rejector(new StatelessRejector( 858 std::unique_ptr<StatelessRejector> rejector(new StatelessRejector(
865 header.public_header.versions.front(), GetSupportedVersions(), 859 version, GetSupportedVersions(), crypto_config_, &compressed_certs_cache_,
866 crypto_config_, &compressed_certs_cache_, helper()->GetClock(), 860 helper()->GetClock(), helper()->GetRandomGenerator(),
867 helper()->GetRandomGenerator(), current_packet_->length(), 861 current_packet_->length(), current_client_address_,
868 current_client_address_, current_server_address_)); 862 current_server_address_));
869 ChloValidator validator(session_helper_.get(), current_server_address_, 863 ChloValidator validator(session_helper_.get(), current_server_address_,
870 rejector.get()); 864 rejector.get());
871 if (!ChloExtractor::Extract(*current_packet_, GetSupportedVersions(), 865 if (!ChloExtractor::Extract(*current_packet_, GetSupportedVersions(),
872 &validator)) { 866 &validator)) {
873 ProcessUnauthenticatedHeaderFate(kFateBuffer, connection_id, 867 ProcessUnauthenticatedHeaderFate(kFateBuffer, connection_id);
874 header.packet_number);
875 return; 868 return;
876 } 869 }
877 870
878 if (!validator.can_accept()) { 871 if (!validator.can_accept()) {
879 // This CHLO is prohibited by policy. 872 // This CHLO is prohibited by policy.
880 StatelessConnectionTerminator terminator(connection_id, &framer_, helper(), 873 StatelessConnectionTerminator terminator(connection_id, &framer_, helper(),
881 time_wait_list_manager_.get()); 874 time_wait_list_manager_.get());
882 terminator.CloseConnection(QUIC_HANDSHAKE_FAILED, 875 terminator.CloseConnection(QUIC_HANDSHAKE_FAILED,
883 validator.error_details()); 876 validator.error_details());
884 OnConnectionClosedStatelessly(QUIC_HANDSHAKE_FAILED); 877 OnConnectionClosedStatelessly(QUIC_HANDSHAKE_FAILED);
885 ProcessUnauthenticatedHeaderFate(kFateTimeWait, connection_id, 878 ProcessUnauthenticatedHeaderFate(kFateTimeWait, connection_id);
886 header.packet_number);
887 return; 879 return;
888 } 880 }
889 881
890 // If we were able to make a decision about this CHLO based purely on the 882 // If we were able to make a decision about this CHLO based purely on the
891 // information available in OnChlo, just invoke the done callback immediately. 883 // information available in OnChlo, just invoke the done callback immediately.
892 if (rejector->state() != StatelessRejector::UNKNOWN) { 884 if (rejector->state() != StatelessRejector::UNKNOWN) {
893 ProcessStatelessRejectorState(std::move(rejector), header.packet_number, 885 ProcessStatelessRejectorState(std::move(rejector), version);
894 header.public_header.versions.front());
895 return; 886 return;
896 } 887 }
897 888
898 // Insert into set of connection IDs to buffer 889 // Insert into set of connection IDs to buffer
899 const bool ok = 890 const bool ok =
900 temporarily_buffered_connections_.insert(connection_id).second; 891 temporarily_buffered_connections_.insert(connection_id).second;
901 QUIC_BUG_IF(!ok) 892 QUIC_BUG_IF(!ok)
902 << "Processing multiple stateless rejections for connection ID " 893 << "Processing multiple stateless rejections for connection ID "
903 << connection_id; 894 << connection_id;
904 895
905 // Continue stateless rejector processing 896 // Continue stateless rejector processing
906 std::unique_ptr<StatelessRejectorProcessDoneCallback> cb( 897 std::unique_ptr<StatelessRejectorProcessDoneCallback> cb(
907 new StatelessRejectorProcessDoneCallback( 898 new StatelessRejectorProcessDoneCallback(this, version));
908 this, header.packet_number, header.public_header.versions.front()));
909 StatelessRejector::Process(std::move(rejector), std::move(cb)); 899 StatelessRejector::Process(std::move(rejector), std::move(cb));
910 } 900 }
911 901
912 void QuicDispatcher::OnStatelessRejectorProcessDone( 902 void QuicDispatcher::OnStatelessRejectorProcessDone(
913 std::unique_ptr<StatelessRejector> rejector, 903 std::unique_ptr<StatelessRejector> rejector,
914 const QuicSocketAddress& current_client_address, 904 const QuicSocketAddress& current_client_address,
915 const QuicSocketAddress& current_server_address, 905 const QuicSocketAddress& current_server_address,
916 std::unique_ptr<QuicReceivedPacket> current_packet, 906 std::unique_ptr<QuicReceivedPacket> current_packet,
917 QuicPacketNumber packet_number,
918 QuicVersion first_version) { 907 QuicVersion first_version) {
919 // Stop buffering packets on this connection 908 // Stop buffering packets on this connection
920 const auto num_erased = 909 const auto num_erased =
921 temporarily_buffered_connections_.erase(rejector->connection_id()); 910 temporarily_buffered_connections_.erase(rejector->connection_id());
922 QUIC_BUG_IF(num_erased != 1) << "Completing stateless rejection logic for " 911 QUIC_BUG_IF(num_erased != 1) << "Completing stateless rejection logic for "
923 "non-buffered connection ID " 912 "non-buffered connection ID "
924 << rejector->connection_id(); 913 << rejector->connection_id();
925 914
926 // If this connection has gone into time-wait during the async processing, 915 // If this connection has gone into time-wait during the async processing,
927 // don't proceed. 916 // don't proceed.
928 if (time_wait_list_manager_->IsConnectionIdInTimeWait( 917 if (time_wait_list_manager_->IsConnectionIdInTimeWait(
929 rejector->connection_id())) { 918 rejector->connection_id())) {
930 time_wait_list_manager_->ProcessPacket( 919 time_wait_list_manager_->ProcessPacket(
931 current_server_address, current_client_address, 920 current_server_address, current_client_address,
932 rejector->connection_id(), packet_number, *current_packet); 921 rejector->connection_id(), *current_packet);
933 return; 922 return;
934 } 923 }
935 924
936 // Reset current_* to correspond to the packet which initiated the stateless 925 // Reset current_* to correspond to the packet which initiated the stateless
937 // reject logic. 926 // reject logic.
938 current_client_address_ = current_client_address; 927 current_client_address_ = current_client_address;
939 current_server_address_ = current_server_address; 928 current_server_address_ = current_server_address;
940 current_packet_ = current_packet.get(); 929 current_packet_ = current_packet.get();
941 current_connection_id_ = rejector->connection_id(); 930 current_connection_id_ = rejector->connection_id();
942 931
943 ProcessStatelessRejectorState(std::move(rejector), packet_number, 932 ProcessStatelessRejectorState(std::move(rejector), first_version);
944 first_version);
945 } 933 }
946 934
947 void QuicDispatcher::ProcessStatelessRejectorState( 935 void QuicDispatcher::ProcessStatelessRejectorState(
948 std::unique_ptr<StatelessRejector> rejector, 936 std::unique_ptr<StatelessRejector> rejector,
949 QuicPacketNumber packet_number,
950 QuicVersion first_version) { 937 QuicVersion first_version) {
951 QuicPacketFate fate; 938 QuicPacketFate fate;
952 switch (rejector->state()) { 939 switch (rejector->state()) {
953 case StatelessRejector::FAILED: { 940 case StatelessRejector::FAILED: {
954 // There was an error processing the client hello. 941 // There was an error processing the client hello.
955 StatelessConnectionTerminator terminator(rejector->connection_id(), 942 StatelessConnectionTerminator terminator(rejector->connection_id(),
956 &framer_, helper(), 943 &framer_, helper(),
957 time_wait_list_manager_.get()); 944 time_wait_list_manager_.get());
958 terminator.CloseConnection(rejector->error(), rejector->error_details()); 945 terminator.CloseConnection(rejector->error(), rejector->error_details());
959 fate = kFateTimeWait; 946 fate = kFateTimeWait;
(...skipping 21 matching lines...) Expand all
981 OnConnectionRejectedStatelessly(); 968 OnConnectionRejectedStatelessly();
982 fate = kFateTimeWait; 969 fate = kFateTimeWait;
983 break; 970 break;
984 } 971 }
985 972
986 default: 973 default:
987 QUIC_BUG << "Rejector has invalid state " << rejector->state(); 974 QUIC_BUG << "Rejector has invalid state " << rejector->state();
988 fate = kFateDrop; 975 fate = kFateDrop;
989 break; 976 break;
990 } 977 }
991 ProcessUnauthenticatedHeaderFate(fate, rejector->connection_id(), 978 ProcessUnauthenticatedHeaderFate(fate, rejector->connection_id());
992 packet_number);
993 } 979 }
994 980
995 const QuicVersionVector& QuicDispatcher::GetSupportedVersions() { 981 const QuicVersionVector& QuicDispatcher::GetSupportedVersions() {
996 return version_manager_->GetSupportedVersions(); 982 return version_manager_->GetSupportedVersions();
997 } 983 }
998 984
999 void QuicDispatcher::DeliverPacketsToSession( 985 void QuicDispatcher::DeliverPacketsToSession(
1000 const std::list<BufferedPacket>& packets, 986 const std::list<BufferedPacket>& packets,
1001 QuicSession* session) { 987 QuicSession* session) {
1002 for (const BufferedPacket& packet : packets) { 988 for (const BufferedPacket& packet : packets) {
1003 session->ProcessUdpPacket(packet.server_address, packet.client_address, 989 session->ProcessUdpPacket(packet.server_address, packet.client_address,
1004 *(packet.packet)); 990 *(packet.packet));
1005 } 991 }
1006 } 992 }
1007 993
1008 } // namespace net 994 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_dispatcher.h ('k') | net/tools/quic/quic_dispatcher_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698