| 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" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "net/quic/quic_blocked_writer_interface.h" | 12 #include "net/quic/quic_blocked_writer_interface.h" |
| 13 #include "net/quic/quic_connection_helper.h" | 13 #include "net/quic/quic_connection_helper.h" |
| 14 #include "net/quic/quic_flags.h" | 14 #include "net/quic/quic_flags.h" |
| 15 #include "net/quic/quic_per_connection_packet_writer.h" |
| 15 #include "net/quic/quic_time_wait_list_manager.h" | 16 #include "net/quic/quic_time_wait_list_manager.h" |
| 16 #include "net/quic/quic_utils.h" | 17 #include "net/quic/quic_utils.h" |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 | 20 |
| 20 using base::StringPiece; | 21 using base::StringPiece; |
| 21 using std::make_pair; | 22 using std::make_pair; |
| 22 using std::find; | 23 using std::find; |
| 23 | 24 |
| 24 class DeleteSessionsAlarm : public QuicAlarm::Delegate { | 25 class DeleteSessionsAlarm : public QuicAlarm::Delegate { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 DCHECK(false); | 148 DCHECK(false); |
| 148 } | 149 } |
| 149 | 150 |
| 150 private: | 151 private: |
| 151 QuicDispatcher* dispatcher_; | 152 QuicDispatcher* dispatcher_; |
| 152 | 153 |
| 153 // Latched in OnUnauthenticatedPublicHeader for use later. | 154 // Latched in OnUnauthenticatedPublicHeader for use later. |
| 154 QuicConnectionId connection_id_; | 155 QuicConnectionId connection_id_; |
| 155 }; | 156 }; |
| 156 | 157 |
| 158 QuicPacketWriter* QuicDispatcher::DefaultPacketWriterFactory::Create( |
| 159 QuicServerPacketWriter* writer, |
| 160 QuicConnection* connection) { |
| 161 return new QuicPerConnectionPacketWriter(writer, connection); |
| 162 } |
| 163 |
| 164 QuicDispatcher::PacketWriterFactoryAdapter::PacketWriterFactoryAdapter( |
| 165 QuicDispatcher* dispatcher) |
| 166 : dispatcher_(dispatcher) {} |
| 167 |
| 168 QuicDispatcher::PacketWriterFactoryAdapter::~PacketWriterFactoryAdapter() {} |
| 169 |
| 170 QuicPacketWriter* QuicDispatcher::PacketWriterFactoryAdapter::Create( |
| 171 QuicConnection* connection) const { |
| 172 return dispatcher_->packet_writer_factory_->Create( |
| 173 dispatcher_->writer_.get(), |
| 174 connection); |
| 175 } |
| 176 |
| 157 QuicDispatcher::QuicDispatcher(const QuicConfig& config, | 177 QuicDispatcher::QuicDispatcher(const QuicConfig& config, |
| 158 const QuicCryptoServerConfig& crypto_config, | 178 const QuicCryptoServerConfig& crypto_config, |
| 159 const QuicVersionVector& supported_versions, | 179 const QuicVersionVector& supported_versions, |
| 180 PacketWriterFactory* packet_writer_factory, |
| 160 QuicConnectionHelperInterface* helper) | 181 QuicConnectionHelperInterface* helper) |
| 161 : config_(config), | 182 : config_(config), |
| 162 crypto_config_(crypto_config), | 183 crypto_config_(crypto_config), |
| 163 helper_(helper), | 184 helper_(helper), |
| 164 delete_sessions_alarm_( | 185 delete_sessions_alarm_( |
| 165 helper_->CreateAlarm(new DeleteSessionsAlarm(this))), | 186 helper_->CreateAlarm(new DeleteSessionsAlarm(this))), |
| 187 packet_writer_factory_(packet_writer_factory), |
| 188 connection_writer_factory_(this), |
| 166 supported_versions_(supported_versions), | 189 supported_versions_(supported_versions), |
| 167 current_packet_(NULL), | 190 current_packet_(NULL), |
| 168 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), | 191 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), |
| 169 framer_visitor_(new QuicFramerVisitor(this)) { | 192 framer_visitor_(new QuicFramerVisitor(this)) { |
| 170 framer_.set_visitor(framer_visitor_.get()); | 193 framer_.set_visitor(framer_visitor_.get()); |
| 171 } | 194 } |
| 172 | 195 |
| 173 QuicDispatcher::~QuicDispatcher() { | 196 QuicDispatcher::~QuicDispatcher() { |
| 174 STLDeleteValues(&session_map_); | 197 STLDeleteValues(&session_map_); |
| 175 STLDeleteElements(&closed_session_list_); | 198 STLDeleteElements(&closed_session_list_); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // infinite loops in OnCanWrite. | 355 // infinite loops in OnCanWrite. |
| 333 return; | 356 return; |
| 334 } | 357 } |
| 335 write_blocked_list_.insert(make_pair(blocked_writer, true)); | 358 write_blocked_list_.insert(make_pair(blocked_writer, true)); |
| 336 } | 359 } |
| 337 | 360 |
| 338 QuicSession* QuicDispatcher::CreateQuicSession( | 361 QuicSession* QuicDispatcher::CreateQuicSession( |
| 339 QuicConnectionId connection_id, | 362 QuicConnectionId connection_id, |
| 340 const IPEndPoint& server_address, | 363 const IPEndPoint& server_address, |
| 341 const IPEndPoint& client_address) { | 364 const IPEndPoint& client_address) { |
| 342 QuicPerConnectionPacketWriter* per_connection_packet_writer = | |
| 343 new QuicPerConnectionPacketWriter(writer_.get()); | |
| 344 QuicConnection* connection = | 365 QuicConnection* connection = |
| 345 CreateQuicConnection(connection_id, | 366 CreateQuicConnection(connection_id, |
| 346 server_address, | 367 server_address, |
| 347 client_address, | 368 client_address); |
| 348 per_connection_packet_writer); | |
| 349 QuicServerSession* session = new QuicServerSession( | 369 QuicServerSession* session = new QuicServerSession( |
| 350 config_, | 370 config_, |
| 351 connection, | 371 connection, |
| 352 per_connection_packet_writer, | |
| 353 this); | 372 this); |
| 354 session->InitializeSession(crypto_config_); | 373 session->InitializeSession(crypto_config_); |
| 355 return session; | 374 return session; |
| 356 } | 375 } |
| 357 | 376 |
| 358 QuicConnection* QuicDispatcher::CreateQuicConnection( | 377 QuicConnection* QuicDispatcher::CreateQuicConnection( |
| 359 QuicConnectionId connection_id, | 378 QuicConnectionId connection_id, |
| 360 const IPEndPoint& server_address, | 379 const IPEndPoint& server_address, |
| 361 const IPEndPoint& client_address, | 380 const IPEndPoint& client_address) { |
| 362 QuicPerConnectionPacketWriter* writer) { | |
| 363 QuicConnection* connection; | 381 QuicConnection* connection; |
| 364 connection = new QuicConnection( | 382 connection = new QuicConnection( |
| 365 connection_id, | 383 connection_id, |
| 366 client_address, | 384 client_address, |
| 367 helper_, | 385 helper_, |
| 368 writer, | 386 connection_writer_factory_, |
| 369 false /* owns_writer */, | 387 /* owns_writer= */ true, |
| 370 true /* is_server */, | 388 /* is_server= */ true, |
| 371 supported_versions_); | 389 supported_versions_); |
| 372 writer->set_connection(connection); | |
| 373 return connection; | 390 return connection; |
| 374 } | 391 } |
| 375 | 392 |
| 376 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() { | 393 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() { |
| 377 return new QuicTimeWaitListManager( | 394 return new QuicTimeWaitListManager( |
| 378 writer_.get(), this, helper_, supported_versions()); | 395 writer_.get(), this, helper_, supported_versions()); |
| 379 } | 396 } |
| 380 | 397 |
| 381 bool QuicDispatcher::HandlePacketForTimeWait( | 398 bool QuicDispatcher::HandlePacketForTimeWait( |
| 382 const QuicPacketPublicHeader& header) { | 399 const QuicPacketPublicHeader& header) { |
| 383 if (header.reset_flag) { | 400 if (header.reset_flag) { |
| 384 // 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. |
| 385 return false; | 402 return false; |
| 386 } | 403 } |
| 387 | 404 |
| 388 // 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 |
| 389 // be parsed correctly. | 406 // be parsed correctly. |
| 390 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( | 407 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( |
| 391 header.connection_id)); | 408 header.connection_id)); |
| 392 | 409 |
| 393 // Continue parsing the packet to extract the sequence number. Then | 410 // Continue parsing the packet to extract the sequence number. Then |
| 394 // send it to the time wait manager in OnUnathenticatedHeader. | 411 // send it to the time wait manager in OnUnathenticatedHeader. |
| 395 return true; | 412 return true; |
| 396 } | 413 } |
| 397 | 414 |
| 398 } // namespace net | 415 } // namespace net |
| OLD | NEW |