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_flow_control_(supported_versions), | |
168 supported_versions_no_connection_flow_control_(supported_versions), | 167 supported_versions_no_connection_flow_control_(supported_versions), |
169 current_packet_(NULL), | 168 current_packet_(NULL), |
170 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), | 169 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), |
171 framer_visitor_(new QuicFramerVisitor(this)) { | 170 framer_visitor_(new QuicFramerVisitor(this)) { |
172 framer_.set_visitor(framer_visitor_.get()); | 171 framer_.set_visitor(framer_visitor_.get()); |
173 } | 172 } |
174 | 173 |
175 QuicDispatcher::~QuicDispatcher() { | 174 QuicDispatcher::~QuicDispatcher() { |
176 STLDeleteValues(&session_map_); | 175 STLDeleteValues(&session_map_); |
177 STLDeleteElements(&closed_session_list_); | 176 STLDeleteElements(&closed_session_list_); |
178 } | 177 } |
179 | 178 |
180 void QuicDispatcher::Initialize(QuicServerPacketWriter* writer) { | 179 void QuicDispatcher::Initialize(QuicServerPacketWriter* writer) { |
181 DCHECK(writer_ == NULL); | 180 DCHECK(writer_ == NULL); |
182 writer_.reset(writer); | 181 writer_.reset(writer); |
183 time_wait_list_manager_.reset(CreateQuicTimeWaitListManager()); | 182 time_wait_list_manager_.reset(CreateQuicTimeWaitListManager()); |
184 | 183 |
185 // Remove all versions > QUIC_VERSION_16 from the | |
186 // supported_versions_no_flow_control_ vector. | |
187 QuicVersionVector::iterator it = | |
188 find(supported_versions_no_flow_control_.begin(), | |
189 supported_versions_no_flow_control_.end(), QUIC_VERSION_17); | |
190 if (it != supported_versions_no_flow_control_.end()) { | |
191 supported_versions_no_flow_control_.erase( | |
192 supported_versions_no_flow_control_.begin(), it + 1); | |
193 } | |
194 CHECK(!supported_versions_no_flow_control_.empty()); | |
195 | |
196 // Remove all versions > QUIC_VERSION_18 from the | 184 // Remove all versions > QUIC_VERSION_18 from the |
197 // supported_versions_no_connection_flow_control_ vector. | 185 // supported_versions_no_connection_flow_control_ vector. |
198 QuicVersionVector::iterator connection_it = | 186 QuicVersionVector::iterator connection_it = |
199 find(supported_versions_no_connection_flow_control_.begin(), | 187 find(supported_versions_no_connection_flow_control_.begin(), |
200 supported_versions_no_connection_flow_control_.end(), | 188 supported_versions_no_connection_flow_control_.end(), |
201 QUIC_VERSION_19); | 189 QUIC_VERSION_19); |
202 if (connection_it != supported_versions_no_connection_flow_control_.end()) { | 190 if (connection_it != supported_versions_no_connection_flow_control_.end()) { |
203 supported_versions_no_connection_flow_control_.erase( | 191 supported_versions_no_connection_flow_control_.erase( |
204 supported_versions_no_connection_flow_control_.begin(), | 192 supported_versions_no_connection_flow_control_.begin(), |
205 connection_it + 1); | 193 connection_it + 1); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 session->InitializeSession(crypto_config_); | 361 session->InitializeSession(crypto_config_); |
374 return session; | 362 return session; |
375 } | 363 } |
376 | 364 |
377 QuicConnection* QuicDispatcher::CreateQuicConnection( | 365 QuicConnection* QuicDispatcher::CreateQuicConnection( |
378 QuicConnectionId connection_id, | 366 QuicConnectionId connection_id, |
379 const IPEndPoint& server_address, | 367 const IPEndPoint& server_address, |
380 const IPEndPoint& client_address, | 368 const IPEndPoint& client_address, |
381 QuicPerConnectionPacketWriter* writer) { | 369 QuicPerConnectionPacketWriter* writer) { |
382 QuicConnection* connection; | 370 QuicConnection* connection; |
383 if (FLAGS_enable_quic_stream_flow_control_2 && | 371 if (FLAGS_enable_quic_connection_flow_control_2) { |
384 FLAGS_enable_quic_connection_flow_control_2) { | |
385 DVLOG(1) << "Creating QuicDispatcher with all versions."; | 372 DVLOG(1) << "Creating QuicDispatcher with all versions."; |
386 connection = new QuicConnection(connection_id, client_address, helper_, | 373 connection = new QuicConnection(connection_id, client_address, helper_, |
387 writer, true, supported_versions_); | 374 writer, true, supported_versions_); |
388 } else if (FLAGS_enable_quic_stream_flow_control_2 && | 375 } else { |
389 !FLAGS_enable_quic_connection_flow_control_2) { | |
390 DVLOG(1) << "Connection flow control disabled, creating QuicDispatcher " | 376 DVLOG(1) << "Connection flow control disabled, creating QuicDispatcher " |
391 << "WITHOUT version 19 or higher."; | 377 << "WITHOUT version 19 or higher."; |
392 connection = new QuicConnection( | 378 connection = new QuicConnection( |
393 connection_id, client_address, helper_, | 379 connection_id, client_address, helper_, writer, true, |
394 writer, true, | |
395 supported_versions_no_connection_flow_control_); | 380 supported_versions_no_connection_flow_control_); |
396 } else { | |
397 DVLOG(1) << "Flow control disabled, creating QuicDispatcher WITHOUT " | |
398 << "version 17 or higher."; | |
399 connection = new QuicConnection(connection_id, client_address, helper_, | |
400 writer, true, | |
401 supported_versions_no_flow_control_); | |
402 } | 381 } |
403 writer->set_connection(connection); | 382 writer->set_connection(connection); |
404 return connection; | 383 return connection; |
405 } | 384 } |
406 | 385 |
407 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() { | 386 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() { |
408 return new QuicTimeWaitListManager( | 387 return new QuicTimeWaitListManager( |
409 writer_.get(), this, helper_, supported_versions()); | 388 writer_.get(), this, helper_, supported_versions()); |
410 } | 389 } |
411 | 390 |
412 bool QuicDispatcher::HandlePacketForTimeWait( | 391 bool QuicDispatcher::HandlePacketForTimeWait( |
413 const QuicPacketPublicHeader& header) { | 392 const QuicPacketPublicHeader& header) { |
414 if (header.reset_flag) { | 393 if (header.reset_flag) { |
415 // Public reset packets do not have sequence numbers, so ignore the packet. | 394 // Public reset packets do not have sequence numbers, so ignore the packet. |
416 return false; | 395 return false; |
417 } | 396 } |
418 | 397 |
419 // Switch the framer to the correct version, so that the sequence number can | 398 // Switch the framer to the correct version, so that the sequence number can |
420 // be parsed correctly. | 399 // be parsed correctly. |
421 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( | 400 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( |
422 header.connection_id)); | 401 header.connection_id)); |
423 | 402 |
424 // Continue parsing the packet to extract the sequence number. Then | 403 // Continue parsing the packet to extract the sequence number. Then |
425 // send it to the time wait manager in OnUnathenticatedHeader. | 404 // send it to the time wait manager in OnUnathenticatedHeader. |
426 return true; | 405 return true; |
427 } | 406 } |
428 | 407 |
429 } // namespace net | 408 } // namespace net |
OLD | NEW |