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" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 const QuicPacketPublicHeader& header) { | 206 const QuicPacketPublicHeader& header) { |
207 // Port zero is only allowed for unidirectional UDP, so is disallowed by QUIC. | 207 // Port zero is only allowed for unidirectional UDP, so is disallowed by QUIC. |
208 // Given that we can't even send a reply rejecting the packet, just black hole | 208 // Given that we can't even send a reply rejecting the packet, just black hole |
209 // it. | 209 // it. |
210 if (current_client_address_.port() == 0) { | 210 if (current_client_address_.port() == 0) { |
211 return false; | 211 return false; |
212 } | 212 } |
213 | 213 |
214 // The session that we have identified as the one to which this packet | 214 // The session that we have identified as the one to which this packet |
215 // belongs. | 215 // belongs. |
216 QuicSession* session = nullptr; | 216 QuicServerSession* session = nullptr; |
217 QuicConnectionId connection_id = header.connection_id; | 217 QuicConnectionId connection_id = header.connection_id; |
218 SessionMap::iterator it = session_map_.find(connection_id); | 218 SessionMap::iterator it = session_map_.find(connection_id); |
219 if (it == session_map_.end()) { | 219 if (it == session_map_.end()) { |
220 if (time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { | 220 if (time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { |
221 return HandlePacketForTimeWait(header); | 221 return HandlePacketForTimeWait(header); |
222 } | 222 } |
223 | 223 |
224 // The packet has an unknown connection ID. | 224 // The packet has an unknown connection ID. |
225 // If the packet is a public reset, there is nothing we must do or can do. | 225 // If the packet is a public reset, there is nothing we must do or can do. |
226 if (header.reset_flag) { | 226 if (header.reset_flag) { |
(...skipping 26 matching lines...) Expand all Loading... |
253 } | 253 } |
254 | 254 |
255 session->connection()->ProcessUdpPacket( | 255 session->connection()->ProcessUdpPacket( |
256 current_server_address_, current_client_address_, *current_packet_); | 256 current_server_address_, current_client_address_, *current_packet_); |
257 | 257 |
258 // Do not parse the packet further. The session methods called above have | 258 // Do not parse the packet further. The session methods called above have |
259 // processed it completely. | 259 // processed it completely. |
260 return false; | 260 return false; |
261 } | 261 } |
262 | 262 |
263 QuicSession* QuicDispatcher::AdditionalValidityChecksThenCreateSession( | 263 QuicServerSession* QuicDispatcher::AdditionalValidityChecksThenCreateSession( |
264 const QuicPacketPublicHeader& header, | 264 const QuicPacketPublicHeader& header, |
265 QuicConnectionId connection_id) { | 265 QuicConnectionId connection_id) { |
266 QuicSession* session = CreateQuicSession( | 266 QuicServerSession* session = CreateQuicSession( |
267 connection_id, current_server_address_, current_client_address_); | 267 connection_id, current_server_address_, current_client_address_); |
268 | 268 |
269 if (session == nullptr) { | 269 if (session == nullptr) { |
270 DVLOG(1) << "Failed to create session for " << connection_id; | 270 DVLOG(1) << "Failed to create session for " << connection_id; |
271 | 271 |
272 if (!framer_.IsSupportedVersion(header.versions.front())) { | 272 if (!framer_.IsSupportedVersion(header.versions.front())) { |
273 // TODO(ianswett): Produce packet saying "no supported version". | 273 // TODO(ianswett): Produce packet saying "no supported version". |
274 return nullptr; | 274 return nullptr; |
275 } | 275 } |
276 | 276 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 blocked_writer->OnCanWrite(); | 329 blocked_writer->OnCanWrite(); |
330 } | 330 } |
331 } | 331 } |
332 | 332 |
333 bool QuicDispatcher::HasPendingWrites() const { | 333 bool QuicDispatcher::HasPendingWrites() const { |
334 return !write_blocked_list_.empty(); | 334 return !write_blocked_list_.empty(); |
335 } | 335 } |
336 | 336 |
337 void QuicDispatcher::Shutdown() { | 337 void QuicDispatcher::Shutdown() { |
338 while (!session_map_.empty()) { | 338 while (!session_map_.empty()) { |
339 QuicSession* session = session_map_.begin()->second; | 339 QuicServerSession* session = session_map_.begin()->second; |
340 session->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); | 340 session->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); |
341 // Validate that the session removes itself from the session map on close. | 341 // Validate that the session removes itself from the session map on close. |
342 DCHECK(session_map_.empty() || session_map_.begin()->second != session); | 342 DCHECK(session_map_.empty() || session_map_.begin()->second != session); |
343 } | 343 } |
344 DeleteSessions(); | 344 DeleteSessions(); |
345 } | 345 } |
346 | 346 |
347 void QuicDispatcher::OnConnectionClosed(QuicConnectionId connection_id, | 347 void QuicDispatcher::OnConnectionClosed(QuicConnectionId connection_id, |
348 QuicErrorCode error) { | 348 QuicErrorCode error) { |
349 SessionMap::iterator it = session_map_.find(connection_id); | 349 SessionMap::iterator it = session_map_.find(connection_id); |
(...skipping 30 matching lines...) Expand all Loading... |
380 void QuicDispatcher::OnConnectionAddedToTimeWaitList( | 380 void QuicDispatcher::OnConnectionAddedToTimeWaitList( |
381 QuicConnectionId connection_id) { | 381 QuicConnectionId connection_id) { |
382 DVLOG(1) << "Connection " << connection_id << " added to time wait list."; | 382 DVLOG(1) << "Connection " << connection_id << " added to time wait list."; |
383 } | 383 } |
384 | 384 |
385 void QuicDispatcher::OnConnectionRemovedFromTimeWaitList( | 385 void QuicDispatcher::OnConnectionRemovedFromTimeWaitList( |
386 QuicConnectionId connection_id) { | 386 QuicConnectionId connection_id) { |
387 DVLOG(1) << "Connection " << connection_id << " removed from time wait list."; | 387 DVLOG(1) << "Connection " << connection_id << " removed from time wait list."; |
388 } | 388 } |
389 | 389 |
390 QuicSession* QuicDispatcher::CreateQuicSession( | 390 QuicServerSession* QuicDispatcher::CreateQuicSession( |
391 QuicConnectionId connection_id, | 391 QuicConnectionId connection_id, |
392 const IPEndPoint& server_address, | 392 const IPEndPoint& server_address, |
393 const IPEndPoint& client_address) { | 393 const IPEndPoint& client_address) { |
394 // The QuicSession takes ownership of |connection| below. | 394 // The QuicServerSession takes ownership of |connection| below. |
395 QuicConnection* connection = new QuicConnection( | 395 QuicConnection* connection = new QuicConnection( |
396 connection_id, client_address, helper_, connection_writer_factory_, | 396 connection_id, client_address, helper_, connection_writer_factory_, |
397 /* owns_writer= */ true, Perspective::IS_SERVER, | 397 /* owns_writer= */ true, Perspective::IS_SERVER, |
398 crypto_config_.HasProofSource(), supported_versions_); | 398 crypto_config_.HasProofSource(), supported_versions_); |
399 | 399 |
400 QuicServerSession* session = new QuicServerSession(config_, connection, this); | 400 QuicServerSession* session = new QuicServerSession(config_, connection, this); |
401 session->InitializeSession(&crypto_config_); | 401 session->InitializeSession(&crypto_config_); |
402 return session; | 402 return session; |
403 } | 403 } |
404 | 404 |
(...skipping 13 matching lines...) Expand all Loading... |
418 // be parsed correctly. | 418 // be parsed correctly. |
419 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( | 419 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( |
420 header.connection_id)); | 420 header.connection_id)); |
421 | 421 |
422 // Continue parsing the packet to extract the sequence number. Then | 422 // Continue parsing the packet to extract the sequence number. Then |
423 // send it to the time wait manager in OnUnathenticatedHeader. | 423 // send it to the time wait manager in OnUnathenticatedHeader. |
424 return true; | 424 return true; |
425 } | 425 } |
426 | 426 |
427 } // namespace net | 427 } // namespace net |
OLD | NEW |