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