| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 PacketWriterFactory* packet_writer_factory, | 185 PacketWriterFactory* packet_writer_factory, |
| 186 EpollServer* epoll_server) | 186 EpollServer* epoll_server) |
| 187 : config_(config), | 187 : config_(config), |
| 188 crypto_config_(crypto_config), | 188 crypto_config_(crypto_config), |
| 189 delete_sessions_alarm_(new DeleteSessionsAlarm(this)), | 189 delete_sessions_alarm_(new DeleteSessionsAlarm(this)), |
| 190 epoll_server_(epoll_server), | 190 epoll_server_(epoll_server), |
| 191 helper_(new QuicEpollConnectionHelper(epoll_server_)), | 191 helper_(new QuicEpollConnectionHelper(epoll_server_)), |
| 192 packet_writer_factory_(packet_writer_factory), | 192 packet_writer_factory_(packet_writer_factory), |
| 193 connection_writer_factory_(this), | 193 connection_writer_factory_(this), |
| 194 supported_versions_(supported_versions), | 194 supported_versions_(supported_versions), |
| 195 current_packet_(NULL), | 195 current_packet_(nullptr), |
| 196 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), | 196 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), |
| 197 framer_visitor_(new QuicFramerVisitor(this)) { | 197 framer_visitor_(new QuicFramerVisitor(this)) { |
| 198 framer_.set_visitor(framer_visitor_.get()); | 198 framer_.set_visitor(framer_visitor_.get()); |
| 199 } | 199 } |
| 200 | 200 |
| 201 QuicDispatcher::~QuicDispatcher() { | 201 QuicDispatcher::~QuicDispatcher() { |
| 202 STLDeleteValues(&session_map_); | 202 STLDeleteValues(&session_map_); |
| 203 STLDeleteElements(&closed_session_list_); | 203 STLDeleteElements(&closed_session_list_); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void QuicDispatcher::Initialize(int fd) { | 206 void QuicDispatcher::Initialize(int fd) { |
| 207 DCHECK(writer_ == NULL); | 207 DCHECK(writer_ == nullptr); |
| 208 writer_.reset(CreateWriter(fd)); | 208 writer_.reset(CreateWriter(fd)); |
| 209 time_wait_list_manager_.reset(CreateQuicTimeWaitListManager()); | 209 time_wait_list_manager_.reset(CreateQuicTimeWaitListManager()); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void QuicDispatcher::ProcessPacket(const IPEndPoint& server_address, | 212 void QuicDispatcher::ProcessPacket(const IPEndPoint& server_address, |
| 213 const IPEndPoint& client_address, | 213 const IPEndPoint& client_address, |
| 214 const QuicEncryptedPacket& packet) { | 214 const QuicEncryptedPacket& packet) { |
| 215 current_server_address_ = server_address; | 215 current_server_address_ = server_address; |
| 216 current_client_address_ = client_address; | 216 current_client_address_ = client_address; |
| 217 current_packet_ = &packet; | 217 current_packet_ = &packet; |
| 218 // ProcessPacket will cause the packet to be dispatched in | 218 // ProcessPacket will cause the packet to be dispatched in |
| 219 // OnUnauthenticatedPublicHeader, or sent to the time wait list manager | 219 // OnUnauthenticatedPublicHeader, or sent to the time wait list manager |
| 220 // in OnAuthenticatedHeader. | 220 // in OnAuthenticatedHeader. |
| 221 framer_.ProcessPacket(packet); | 221 framer_.ProcessPacket(packet); |
| 222 // TODO(rjshade): Return a status describing if/why a packet was dropped, | 222 // TODO(rjshade): Return a status describing if/why a packet was dropped, |
| 223 // and log somehow. Maybe expose as a varz. | 223 // and log somehow. Maybe expose as a varz. |
| 224 } | 224 } |
| 225 | 225 |
| 226 bool QuicDispatcher::OnUnauthenticatedPublicHeader( | 226 bool QuicDispatcher::OnUnauthenticatedPublicHeader( |
| 227 const QuicPacketPublicHeader& header) { | 227 const QuicPacketPublicHeader& header) { |
| 228 QuicSession* session = NULL; | 228 QuicSession* session = nullptr; |
| 229 | 229 |
| 230 QuicConnectionId connection_id = header.connection_id; | 230 QuicConnectionId connection_id = header.connection_id; |
| 231 SessionMap::iterator it = session_map_.find(connection_id); | 231 SessionMap::iterator it = session_map_.find(connection_id); |
| 232 if (it == session_map_.end()) { | 232 if (it == session_map_.end()) { |
| 233 if (header.reset_flag) { | 233 if (header.reset_flag) { |
| 234 return false; | 234 return false; |
| 235 } | 235 } |
| 236 if (time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { | 236 if (time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { |
| 237 return HandlePacketForTimeWait(header); | 237 return HandlePacketForTimeWait(header); |
| 238 } | 238 } |
| 239 | 239 |
| 240 // Ensure the packet has a version negotiation bit set before creating a new | 240 // Ensure the packet has a version negotiation bit set before creating a new |
| 241 // session for it. All initial packets for a new connection are required to | 241 // session for it. All initial packets for a new connection are required to |
| 242 // have the flag set. Otherwise it may be a stray packet. | 242 // have the flag set. Otherwise it may be a stray packet. |
| 243 if (header.version_flag) { | 243 if (header.version_flag) { |
| 244 session = CreateQuicSession(connection_id, current_server_address_, | 244 session = CreateQuicSession(connection_id, current_server_address_, |
| 245 current_client_address_); | 245 current_client_address_); |
| 246 } | 246 } |
| 247 | 247 |
| 248 if (session == NULL) { | 248 if (session == nullptr) { |
| 249 DVLOG(1) << "Failed to create session for " << connection_id; | 249 DVLOG(1) << "Failed to create session for " << connection_id; |
| 250 // Add this connection_id fo the time-wait state, to safely reject future | 250 // Add this connection_id fo the time-wait state, to safely reject future |
| 251 // packets. | 251 // packets. |
| 252 | 252 |
| 253 if (header.version_flag && | 253 if (header.version_flag && |
| 254 !framer_.IsSupportedVersion(header.versions.front())) { | 254 !framer_.IsSupportedVersion(header.versions.front())) { |
| 255 // TODO(ianswett): Produce a no-version version negotiation packet. | 255 // TODO(ianswett): Produce a no-version version negotiation packet. |
| 256 return false; | 256 return false; |
| 257 } | 257 } |
| 258 | 258 |
| 259 // Use the version in the packet if possible, otherwise assume the latest. | 259 // Use the version in the packet if possible, otherwise assume the latest. |
| 260 QuicVersion version = header.version_flag ? header.versions.front() : | 260 QuicVersion version = header.version_flag ? header.versions.front() : |
| 261 supported_versions_.front(); | 261 supported_versions_.front(); |
| 262 time_wait_list_manager_->AddConnectionIdToTimeWait( | 262 time_wait_list_manager_->AddConnectionIdToTimeWait(connection_id, version, |
| 263 connection_id, version, NULL); | 263 nullptr); |
| 264 DCHECK(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); | 264 DCHECK(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); |
| 265 return HandlePacketForTimeWait(header); | 265 return HandlePacketForTimeWait(header); |
| 266 } | 266 } |
| 267 DVLOG(1) << "Created new session for " << connection_id; | 267 DVLOG(1) << "Created new session for " << connection_id; |
| 268 session_map_.insert(make_pair(connection_id, session)); | 268 session_map_.insert(make_pair(connection_id, session)); |
| 269 } else { | 269 } else { |
| 270 session = it->second; | 270 session = it->second; |
| 271 } | 271 } |
| 272 | 272 |
| 273 session->connection()->ProcessUdpPacket( | 273 session->connection()->ProcessUdpPacket( |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( | 412 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( |
| 413 header.connection_id)); | 413 header.connection_id)); |
| 414 | 414 |
| 415 // Continue parsing the packet to extract the sequence number. Then | 415 // Continue parsing the packet to extract the sequence number. Then |
| 416 // send it to the time wait manager in OnUnathenticatedHeader. | 416 // send it to the time wait manager in OnUnathenticatedHeader. |
| 417 return true; | 417 return true; |
| 418 } | 418 } |
| 419 | 419 |
| 420 } // namespace tools | 420 } // namespace tools |
| 421 } // namespace net | 421 } // namespace net |
| OLD | NEW |