OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/quic/quic_dispatcher.h" | 5 #include "net/quic/quic_dispatcher.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 QuicDispatcher::QuicDispatcher(const QuicConfig& config, | 157 QuicDispatcher::QuicDispatcher(const QuicConfig& config, |
158 const QuicCryptoServerConfig& crypto_config, | 158 const QuicCryptoServerConfig& crypto_config, |
159 const QuicVersionVector& supported_versions, | 159 const QuicVersionVector& supported_versions, |
160 QuicConnectionHelperInterface* helper) | 160 QuicConnectionHelperInterface* helper) |
161 : config_(config), | 161 : config_(config), |
162 crypto_config_(crypto_config), | 162 crypto_config_(crypto_config), |
163 helper_(helper), | 163 helper_(helper), |
164 delete_sessions_alarm_( | 164 delete_sessions_alarm_( |
165 helper_->CreateAlarm(new DeleteSessionsAlarm(this))), | 165 helper_->CreateAlarm(new DeleteSessionsAlarm(this))), |
166 supported_versions_(supported_versions), | 166 supported_versions_(supported_versions), |
167 supported_versions_no_connection_flow_control_(supported_versions), | |
168 current_packet_(NULL), | 167 current_packet_(NULL), |
169 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), | 168 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), |
170 framer_visitor_(new QuicFramerVisitor(this)) { | 169 framer_visitor_(new QuicFramerVisitor(this)) { |
171 framer_.set_visitor(framer_visitor_.get()); | 170 framer_.set_visitor(framer_visitor_.get()); |
172 } | 171 } |
173 | 172 |
174 QuicDispatcher::~QuicDispatcher() { | 173 QuicDispatcher::~QuicDispatcher() { |
175 STLDeleteValues(&session_map_); | 174 STLDeleteValues(&session_map_); |
176 STLDeleteElements(&closed_session_list_); | 175 STLDeleteElements(&closed_session_list_); |
177 } | 176 } |
178 | 177 |
179 void QuicDispatcher::Initialize(QuicServerPacketWriter* writer) { | 178 void QuicDispatcher::Initialize(QuicServerPacketWriter* writer) { |
180 DCHECK(writer_ == NULL); | 179 DCHECK(writer_ == NULL); |
181 writer_.reset(writer); | 180 writer_.reset(writer); |
182 time_wait_list_manager_.reset(CreateQuicTimeWaitListManager()); | 181 time_wait_list_manager_.reset(CreateQuicTimeWaitListManager()); |
183 | |
184 // Remove all versions > QUIC_VERSION_18 from the | |
185 // supported_versions_no_connection_flow_control_ vector. | |
186 QuicVersionVector::iterator connection_it = | |
187 find(supported_versions_no_connection_flow_control_.begin(), | |
188 supported_versions_no_connection_flow_control_.end(), | |
189 QUIC_VERSION_19); | |
190 if (connection_it != supported_versions_no_connection_flow_control_.end()) { | |
191 supported_versions_no_connection_flow_control_.erase( | |
192 supported_versions_no_connection_flow_control_.begin(), | |
193 connection_it + 1); | |
194 } | |
195 CHECK(!supported_versions_no_connection_flow_control_.empty()); | |
196 } | 182 } |
197 | 183 |
198 void QuicDispatcher::ProcessPacket(const IPEndPoint& server_address, | 184 void QuicDispatcher::ProcessPacket(const IPEndPoint& server_address, |
199 const IPEndPoint& client_address, | 185 const IPEndPoint& client_address, |
200 const QuicEncryptedPacket& packet) { | 186 const QuicEncryptedPacket& packet) { |
201 current_server_address_ = server_address; | 187 current_server_address_ = server_address; |
202 current_client_address_ = client_address; | 188 current_client_address_ = client_address; |
203 current_packet_ = &packet; | 189 current_packet_ = &packet; |
204 // ProcessPacket will cause the packet to be dispatched in | 190 // ProcessPacket will cause the packet to be dispatched in |
205 // OnUnauthenticatedPublicHeader, or sent to the time wait list manager | 191 // OnUnauthenticatedPublicHeader, or sent to the time wait list manager |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 session->InitializeSession(crypto_config_); | 354 session->InitializeSession(crypto_config_); |
369 return session; | 355 return session; |
370 } | 356 } |
371 | 357 |
372 QuicConnection* QuicDispatcher::CreateQuicConnection( | 358 QuicConnection* QuicDispatcher::CreateQuicConnection( |
373 QuicConnectionId connection_id, | 359 QuicConnectionId connection_id, |
374 const IPEndPoint& server_address, | 360 const IPEndPoint& server_address, |
375 const IPEndPoint& client_address, | 361 const IPEndPoint& client_address, |
376 QuicPerConnectionPacketWriter* writer) { | 362 QuicPerConnectionPacketWriter* writer) { |
377 QuicConnection* connection; | 363 QuicConnection* connection; |
378 if (FLAGS_enable_quic_connection_flow_control_2) { | 364 connection = new QuicConnection( |
379 DVLOG(1) << "Creating QuicDispatcher with all versions."; | 365 connection_id, |
380 connection = new QuicConnection(connection_id, | 366 client_address, |
381 client_address, | 367 helper_, |
382 helper_, | 368 writer, |
383 writer, | 369 false /* owns_writer */, |
384 false /* owns_writer */, | 370 true /* is_server */, |
385 true /* is_server */, | 371 supported_versions_); |
386 supported_versions_); | |
387 } else { | |
388 DVLOG(1) << "Connection flow control disabled, creating QuicDispatcher " | |
389 << "WITHOUT version 19 or higher."; | |
390 connection = new QuicConnection( | |
391 connection_id, | |
392 client_address, | |
393 helper_, | |
394 writer, | |
395 false /* owns_writer */, | |
396 true /* is_server */, | |
397 supported_versions_no_connection_flow_control_); | |
398 } | |
399 writer->set_connection(connection); | 372 writer->set_connection(connection); |
400 return connection; | 373 return connection; |
401 } | 374 } |
402 | 375 |
403 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() { | 376 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() { |
404 return new QuicTimeWaitListManager( | 377 return new QuicTimeWaitListManager( |
405 writer_.get(), this, helper_, supported_versions()); | 378 writer_.get(), this, helper_, supported_versions()); |
406 } | 379 } |
407 | 380 |
408 bool QuicDispatcher::HandlePacketForTimeWait( | 381 bool QuicDispatcher::HandlePacketForTimeWait( |
409 const QuicPacketPublicHeader& header) { | 382 const QuicPacketPublicHeader& header) { |
410 if (header.reset_flag) { | 383 if (header.reset_flag) { |
411 // Public reset packets do not have sequence numbers, so ignore the packet. | 384 // Public reset packets do not have sequence numbers, so ignore the packet. |
412 return false; | 385 return false; |
413 } | 386 } |
414 | 387 |
415 // Switch the framer to the correct version, so that the sequence number can | 388 // Switch the framer to the correct version, so that the sequence number can |
416 // be parsed correctly. | 389 // be parsed correctly. |
417 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( | 390 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( |
418 header.connection_id)); | 391 header.connection_id)); |
419 | 392 |
420 // Continue parsing the packet to extract the sequence number. Then | 393 // Continue parsing the packet to extract the sequence number. Then |
421 // send it to the time wait manager in OnUnathenticatedHeader. | 394 // send it to the time wait manager in OnUnathenticatedHeader. |
422 return true; | 395 return true; |
423 } | 396 } |
424 | 397 |
425 } // namespace net | 398 } // namespace net |
OLD | NEW |