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