| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 DCHECK(false); | 117 DCHECK(false); |
| 118 } | 118 } |
| 119 | 119 |
| 120 private: | 120 private: |
| 121 QuicDispatcher* dispatcher_; | 121 QuicDispatcher* dispatcher_; |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 QuicDispatcher::QuicDispatcher(const QuicConfig& config, | 124 QuicDispatcher::QuicDispatcher(const QuicConfig& config, |
| 125 const QuicCryptoServerConfig& crypto_config, | 125 const QuicCryptoServerConfig& crypto_config, |
| 126 const QuicVersionVector& supported_versions, | 126 const QuicVersionVector& supported_versions, |
| 127 int fd, | |
| 128 EpollServer* epoll_server) | 127 EpollServer* epoll_server) |
| 129 : config_(config), | 128 : config_(config), |
| 130 crypto_config_(crypto_config), | 129 crypto_config_(crypto_config), |
| 131 time_wait_list_manager_( | 130 time_wait_list_manager_( |
| 132 new QuicTimeWaitListManager(this, epoll_server, supported_versions)), | 131 new QuicTimeWaitListManager(this, epoll_server, supported_versions)), |
| 133 delete_sessions_alarm_(new DeleteSessionsAlarm(this)), | 132 delete_sessions_alarm_(new DeleteSessionsAlarm(this)), |
| 134 epoll_server_(epoll_server), | 133 epoll_server_(epoll_server), |
| 135 helper_(new QuicEpollConnectionHelper(epoll_server_)), | 134 helper_(new QuicEpollConnectionHelper(epoll_server_)), |
| 136 writer_(new QuicPacketWriterWrapper(new QuicDefaultPacketWriter(fd))), | |
| 137 supported_versions_(supported_versions), | 135 supported_versions_(supported_versions), |
| 138 current_packet_(NULL), | 136 current_packet_(NULL), |
| 139 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), | 137 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), |
| 140 framer_visitor_(new QuicFramerVisitor(this)) { | 138 framer_visitor_(new QuicFramerVisitor(this)) { |
| 141 framer_.set_visitor(framer_visitor_.get()); | 139 framer_.set_visitor(framer_visitor_.get()); |
| 142 } | 140 } |
| 143 | 141 |
| 144 QuicDispatcher::~QuicDispatcher() { | 142 QuicDispatcher::~QuicDispatcher() { |
| 145 STLDeleteValues(&session_map_); | 143 STLDeleteValues(&session_map_); |
| 146 STLDeleteElements(&closed_session_list_); | 144 STLDeleteElements(&closed_session_list_); |
| 147 } | 145 } |
| 148 | 146 |
| 147 void QuicDispatcher::Initialize(int fd) { |
| 148 DCHECK(writer_ == NULL); |
| 149 writer_.reset(CreateWriterWrapper(CreateWriter(fd))); |
| 150 } |
| 151 |
| 149 // TODO(fnk): remove the Writer interface implementation in favor of | 152 // TODO(fnk): remove the Writer interface implementation in favor of |
| 150 // direct requests for blocked list placement from Connection/Session. | 153 // direct requests for blocked list placement from Connection/Session. |
| 151 WriteResult QuicDispatcher::WritePacket(const char* buffer, size_t buf_len, | 154 WriteResult QuicDispatcher::WritePacket(const char* buffer, size_t buf_len, |
| 152 const IPAddressNumber& self_address, | 155 const IPAddressNumber& self_address, |
| 153 const IPEndPoint& peer_address, | 156 const IPEndPoint& peer_address, |
| 154 QuicBlockedWriterInterface* writer) { | 157 QuicBlockedWriterInterface* writer) { |
| 155 if (IsWriteBlocked()) { | 158 if (IsWriteBlocked()) { |
| 156 write_blocked_list_.insert(make_pair(writer, true)); | 159 write_blocked_list_.insert(make_pair(writer, true)); |
| 157 return WriteResult(WRITE_STATUS_BLOCKED, EAGAIN); | 160 return WriteResult(WRITE_STATUS_BLOCKED, EAGAIN); |
| 158 } | 161 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 << QuicUtils::ErrorToString(error); | 323 << QuicUtils::ErrorToString(error); |
| 321 | 324 |
| 322 if (closed_session_list_.empty()) { | 325 if (closed_session_list_.empty()) { |
| 323 epoll_server_->RegisterAlarmApproximateDelta( | 326 epoll_server_->RegisterAlarmApproximateDelta( |
| 324 0, delete_sessions_alarm_.get()); | 327 0, delete_sessions_alarm_.get()); |
| 325 } | 328 } |
| 326 closed_session_list_.push_back(it->second); | 329 closed_session_list_.push_back(it->second); |
| 327 CleanUpSession(it); | 330 CleanUpSession(it); |
| 328 } | 331 } |
| 329 | 332 |
| 330 void QuicDispatcher::set_fd(int fd) { | |
| 331 writer_->set_writer(new QuicDefaultPacketWriter(fd)); | |
| 332 } | |
| 333 | |
| 334 QuicSession* QuicDispatcher::CreateQuicSession( | 333 QuicSession* QuicDispatcher::CreateQuicSession( |
| 335 QuicGuid guid, | 334 QuicGuid guid, |
| 336 const IPEndPoint& server_address, | 335 const IPEndPoint& server_address, |
| 337 const IPEndPoint& client_address) { | 336 const IPEndPoint& client_address) { |
| 338 QuicServerSession* session = new QuicServerSession( | 337 QuicServerSession* session = new QuicServerSession( |
| 339 config_, new QuicConnection(guid, client_address, helper_.get(), this, | 338 config_, new QuicConnection(guid, client_address, helper_.get(), this, |
| 340 true, supported_versions_), this); | 339 true, supported_versions_), this); |
| 341 session->InitializeSession(crypto_config_); | 340 session->InitializeSession(crypto_config_); |
| 342 return session; | 341 return session; |
| 343 } | 342 } |
| 344 | 343 |
| 344 QuicPacketWriter* QuicDispatcher::CreateWriter(int fd) { |
| 345 return new QuicDefaultPacketWriter(fd); |
| 346 } |
| 347 |
| 348 QuicPacketWriterWrapper* QuicDispatcher::CreateWriterWrapper( |
| 349 QuicPacketWriter* writer) { |
| 350 return new QuicPacketWriterWrapper(writer); |
| 351 } |
| 352 |
| 353 void QuicDispatcher::set_writer(QuicPacketWriter* writer) { |
| 354 writer_->set_writer(writer); |
| 355 } |
| 356 |
| 345 bool QuicDispatcher::HandlePacketForTimeWait( | 357 bool QuicDispatcher::HandlePacketForTimeWait( |
| 346 const QuicPacketPublicHeader& header) { | 358 const QuicPacketPublicHeader& header) { |
| 347 if (header.reset_flag) { | 359 if (header.reset_flag) { |
| 348 // Public reset packets do not have sequence numbers, so ignore the packet. | 360 // Public reset packets do not have sequence numbers, so ignore the packet. |
| 349 return false; | 361 return false; |
| 350 } | 362 } |
| 351 | 363 |
| 352 // Switch the framer to the correct version, so that the sequence number can | 364 // Switch the framer to the correct version, so that the sequence number can |
| 353 // be parsed correctly. | 365 // be parsed correctly. |
| 354 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromGuid( | 366 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromGuid( |
| 355 header.guid)); | 367 header.guid)); |
| 356 | 368 |
| 357 // Continue parsing the packet to extract the sequence number. Then | 369 // Continue parsing the packet to extract the sequence number. Then |
| 358 // send it to the time wait manager in OnUnathenticatedHeader. | 370 // send it to the time wait manager in OnUnathenticatedHeader. |
| 359 return true; | 371 return true; |
| 360 } | 372 } |
| 361 | 373 |
| 362 } // namespace tools | 374 } // namespace tools |
| 363 } // namespace net | 375 } // namespace net |
| OLD | NEW |