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/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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 alarm_factory_(std::move(alarm_factory)), | 204 alarm_factory_(std::move(alarm_factory)), |
205 delete_sessions_alarm_( | 205 delete_sessions_alarm_( |
206 alarm_factory_->CreateAlarm(new DeleteSessionsAlarm(this))), | 206 alarm_factory_->CreateAlarm(new DeleteSessionsAlarm(this))), |
207 buffered_packets_(this, helper_->GetClock(), alarm_factory_.get()), | 207 buffered_packets_(this, helper_->GetClock(), alarm_factory_.get()), |
208 current_packet_(nullptr), | 208 current_packet_(nullptr), |
209 version_manager_(version_manager), | 209 version_manager_(version_manager), |
210 framer_(GetSupportedVersions(), | 210 framer_(GetSupportedVersions(), |
211 /*unused*/ QuicTime::Zero(), | 211 /*unused*/ QuicTime::Zero(), |
212 Perspective::IS_SERVER), | 212 Perspective::IS_SERVER), |
213 last_error_(QUIC_NO_ERROR), | 213 last_error_(QUIC_NO_ERROR), |
214 new_sessions_allowed_per_event_loop_(0u) { | 214 new_sessions_allowed_per_event_loop_(0u), |
| 215 accept_new_connections_(true) { |
215 framer_.set_visitor(this); | 216 framer_.set_visitor(this); |
216 } | 217 } |
217 | 218 |
218 QuicDispatcher::~QuicDispatcher() { | 219 QuicDispatcher::~QuicDispatcher() { |
219 session_map_.clear(); | 220 session_map_.clear(); |
220 closed_session_list_.clear(); | 221 closed_session_list_.clear(); |
221 } | 222 } |
222 | 223 |
223 void QuicDispatcher::InitializeWithWriter(QuicPacketWriter* writer) { | 224 void QuicDispatcher::InitializeWithWriter(QuicPacketWriter* writer) { |
224 DCHECK(writer_ == nullptr); | 225 DCHECK(writer_ == nullptr); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 357 |
357 return false; | 358 return false; |
358 } | 359 } |
359 | 360 |
360 void QuicDispatcher::ProcessUnauthenticatedHeaderFate( | 361 void QuicDispatcher::ProcessUnauthenticatedHeaderFate( |
361 QuicPacketFate fate, | 362 QuicPacketFate fate, |
362 QuicConnectionId connection_id, | 363 QuicConnectionId connection_id, |
363 QuicPacketNumber packet_number) { | 364 QuicPacketNumber packet_number) { |
364 switch (fate) { | 365 switch (fate) { |
365 case kFateProcess: { | 366 case kFateProcess: { |
366 ProcessChlo(); | 367 ProcessChlo(packet_number); |
367 break; | 368 break; |
368 } | 369 } |
369 case kFateTimeWait: | 370 case kFateTimeWait: |
370 // MaybeRejectStatelessly or OnExpiredPackets might have already added the | 371 // MaybeRejectStatelessly or OnExpiredPackets might have already added the |
371 // connection to time wait, in which case it should not be added again. | 372 // connection to time wait, in which case it should not be added again. |
372 if (!FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects || | 373 if (!FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects || |
373 !time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { | 374 !time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { |
374 // Add this connection_id to the time-wait state, to safely reject | 375 // Add this connection_id to the time-wait state, to safely reject |
375 // future packets. | 376 // future packets. |
376 QUIC_DLOG(INFO) << "Adding connection ID " << connection_id | 377 QUIC_DLOG(INFO) << "Adding connection ID " << connection_id |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 if (should_close_statelessly) { | 443 if (should_close_statelessly) { |
443 DCHECK(connection->termination_packets() != nullptr && | 444 DCHECK(connection->termination_packets() != nullptr && |
444 !connection->termination_packets()->empty()); | 445 !connection->termination_packets()->empty()); |
445 } | 446 } |
446 time_wait_list_manager_->AddConnectionIdToTimeWait( | 447 time_wait_list_manager_->AddConnectionIdToTimeWait( |
447 it->first, connection->version(), should_close_statelessly, | 448 it->first, connection->version(), should_close_statelessly, |
448 connection->termination_packets()); | 449 connection->termination_packets()); |
449 session_map_.erase(it); | 450 session_map_.erase(it); |
450 } | 451 } |
451 | 452 |
| 453 void QuicDispatcher::StopAcceptingNewConnections() { |
| 454 accept_new_connections_ = false; |
| 455 } |
| 456 |
452 void QuicDispatcher::DeleteSessions() { | 457 void QuicDispatcher::DeleteSessions() { |
453 closed_session_list_.clear(); | 458 closed_session_list_.clear(); |
454 } | 459 } |
455 | 460 |
456 void QuicDispatcher::OnCanWrite() { | 461 void QuicDispatcher::OnCanWrite() { |
457 // The socket is now writable. | 462 // The socket is now writable. |
458 writer_->SetWritable(); | 463 writer_->SetWritable(); |
459 | 464 |
460 // Give all the blocked writers one chance to write, until we're blocked again | 465 // Give all the blocked writers one chance to write, until we're blocked again |
461 // or there's no work left. | 466 // or there's no work left. |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 connection_id, *current_packet_, current_server_address_, | 708 connection_id, *current_packet_, current_server_address_, |
704 current_client_address_, /*is_chlo=*/false); | 709 current_client_address_, /*is_chlo=*/false); |
705 if (rs != EnqueuePacketResult::SUCCESS) { | 710 if (rs != EnqueuePacketResult::SUCCESS) { |
706 OnBufferPacketFailure(rs, connection_id); | 711 OnBufferPacketFailure(rs, connection_id); |
707 } else if (!FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && | 712 } else if (!FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && |
708 is_new_connection) { | 713 is_new_connection) { |
709 ShouldCreateOrBufferPacketForConnection(connection_id); | 714 ShouldCreateOrBufferPacketForConnection(connection_id); |
710 } | 715 } |
711 } | 716 } |
712 | 717 |
713 void QuicDispatcher::ProcessChlo() { | 718 void QuicDispatcher::ProcessChlo(QuicPacketNumber packet_number) { |
| 719 if (!accept_new_connections_) { |
| 720 // Don't any create new connection. |
| 721 time_wait_list_manager()->AddConnectionIdToTimeWait( |
| 722 current_connection_id(), framer()->version(), |
| 723 /*connection_rejected_statelessly=*/false, |
| 724 /*termination_packets=*/nullptr); |
| 725 // This will trigger sending Public Reset packet. |
| 726 time_wait_list_manager()->ProcessPacket( |
| 727 current_server_address(), current_client_address(), |
| 728 current_connection_id(), packet_number, current_packet()); |
| 729 return; |
| 730 } |
714 if (FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && | 731 if (FLAGS_quic_reloadable_flag_quic_create_session_after_insertion && |
715 !buffered_packets_.HasBufferedPackets(current_connection_id_) && | 732 !buffered_packets_.HasBufferedPackets(current_connection_id_) && |
716 !ShouldCreateOrBufferPacketForConnection(current_connection_id_)) { | 733 !ShouldCreateOrBufferPacketForConnection(current_connection_id_)) { |
717 QUIC_FLAG_COUNT_N(quic_reloadable_flag_quic_create_session_after_insertion, | 734 QUIC_FLAG_COUNT_N(quic_reloadable_flag_quic_create_session_after_insertion, |
718 2, 5); | 735 2, 5); |
719 return; | 736 return; |
720 } | 737 } |
721 if (FLAGS_quic_allow_chlo_buffering && | 738 if (FLAGS_quic_allow_chlo_buffering && |
722 FLAGS_quic_reloadable_flag_quic_limit_num_new_sessions_per_epoll_loop && | 739 FLAGS_quic_reloadable_flag_quic_limit_num_new_sessions_per_epoll_loop && |
723 new_sessions_allowed_per_event_loop_ <= 0) { | 740 new_sessions_allowed_per_event_loop_ <= 0) { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 void QuicDispatcher::DeliverPacketsToSession( | 997 void QuicDispatcher::DeliverPacketsToSession( |
981 const std::list<BufferedPacket>& packets, | 998 const std::list<BufferedPacket>& packets, |
982 QuicSession* session) { | 999 QuicSession* session) { |
983 for (const BufferedPacket& packet : packets) { | 1000 for (const BufferedPacket& packet : packets) { |
984 session->ProcessUdpPacket(packet.server_address, packet.client_address, | 1001 session->ProcessUdpPacket(packet.server_address, packet.client_address, |
985 *(packet.packet)); | 1002 *(packet.packet)); |
986 } | 1003 } |
987 } | 1004 } |
988 | 1005 |
989 } // namespace net | 1006 } // namespace net |
OLD | NEW |