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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 const QuicPacketPublicHeader& header) { | 217 const QuicPacketPublicHeader& header) { |
218 // Port zero is only allowed for unidirectional UDP, so is disallowed by QUIC. | 218 // Port zero is only allowed for unidirectional UDP, so is disallowed by QUIC. |
219 // Given that we can't even send a reply rejecting the packet, just black hole | 219 // Given that we can't even send a reply rejecting the packet, just black hole |
220 // it. | 220 // it. |
221 if (current_client_address_.port() == 0) { | 221 if (current_client_address_.port() == 0) { |
222 return false; | 222 return false; |
223 } | 223 } |
224 | 224 |
225 // The session that we have identified as the one to which this packet | 225 // The session that we have identified as the one to which this packet |
226 // belongs. | 226 // belongs. |
227 QuicSession* session = nullptr; | 227 QuicServerSession* session = nullptr; |
228 QuicConnectionId connection_id = header.connection_id; | 228 QuicConnectionId connection_id = header.connection_id; |
229 SessionMap::iterator it = session_map_.find(connection_id); | 229 SessionMap::iterator it = session_map_.find(connection_id); |
230 if (it == session_map_.end()) { | 230 if (it == session_map_.end()) { |
231 if (time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { | 231 if (time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { |
232 return HandlePacketForTimeWait(header); | 232 return HandlePacketForTimeWait(header); |
233 } | 233 } |
234 | 234 |
235 // The packet has an unknown connection ID. | 235 // The packet has an unknown connection ID. |
236 // If the packet is a public reset, there is nothing we must do or can do. | 236 // If the packet is a public reset, there is nothing we must do or can do. |
237 if (header.reset_flag) { | 237 if (header.reset_flag) { |
(...skipping 26 matching lines...) Expand all Loading... |
264 } | 264 } |
265 | 265 |
266 session->connection()->ProcessUdpPacket( | 266 session->connection()->ProcessUdpPacket( |
267 current_server_address_, current_client_address_, *current_packet_); | 267 current_server_address_, current_client_address_, *current_packet_); |
268 | 268 |
269 // Do not parse the packet further. The session methods called above have | 269 // Do not parse the packet further. The session methods called above have |
270 // processed it completely. | 270 // processed it completely. |
271 return false; | 271 return false; |
272 } | 272 } |
273 | 273 |
274 QuicSession* QuicDispatcher::AdditionalValidityChecksThenCreateSession( | 274 QuicServerSession* QuicDispatcher::AdditionalValidityChecksThenCreateSession( |
275 const QuicPacketPublicHeader& header, | 275 const QuicPacketPublicHeader& header, |
276 QuicConnectionId connection_id) { | 276 QuicConnectionId connection_id) { |
277 QuicSession* session = CreateQuicSession( | 277 QuicServerSession* session = CreateQuicSession( |
278 connection_id, current_server_address_, current_client_address_); | 278 connection_id, current_server_address_, current_client_address_); |
279 | 279 |
280 if (session == nullptr) { | 280 if (session == nullptr) { |
281 DVLOG(1) << "Failed to create session for " << connection_id; | 281 DVLOG(1) << "Failed to create session for " << connection_id; |
282 | 282 |
283 if (!framer_.IsSupportedVersion(header.versions.front())) { | 283 if (!framer_.IsSupportedVersion(header.versions.front())) { |
284 // TODO(ianswett): Produce packet saying "no supported version". | 284 // TODO(ianswett): Produce packet saying "no supported version". |
285 return nullptr; | 285 return nullptr; |
286 } | 286 } |
287 | 287 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 blocked_writer->OnCanWrite(); | 340 blocked_writer->OnCanWrite(); |
341 } | 341 } |
342 } | 342 } |
343 | 343 |
344 bool QuicDispatcher::HasPendingWrites() const { | 344 bool QuicDispatcher::HasPendingWrites() const { |
345 return !write_blocked_list_.empty(); | 345 return !write_blocked_list_.empty(); |
346 } | 346 } |
347 | 347 |
348 void QuicDispatcher::Shutdown() { | 348 void QuicDispatcher::Shutdown() { |
349 while (!session_map_.empty()) { | 349 while (!session_map_.empty()) { |
350 QuicSession* session = session_map_.begin()->second; | 350 QuicServerSession* session = session_map_.begin()->second; |
351 session->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); | 351 session->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); |
352 // Validate that the session removes itself from the session map on close. | 352 // Validate that the session removes itself from the session map on close. |
353 DCHECK(session_map_.empty() || session_map_.begin()->second != session); | 353 DCHECK(session_map_.empty() || session_map_.begin()->second != session); |
354 } | 354 } |
355 DeleteSessions(); | 355 DeleteSessions(); |
356 } | 356 } |
357 | 357 |
358 void QuicDispatcher::OnConnectionClosed(QuicConnectionId connection_id, | 358 void QuicDispatcher::OnConnectionClosed(QuicConnectionId connection_id, |
359 QuicErrorCode error) { | 359 QuicErrorCode error) { |
360 SessionMap::iterator it = session_map_.find(connection_id); | 360 SessionMap::iterator it = session_map_.find(connection_id); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 398 |
399 void QuicDispatcher::OnConnectionRemovedFromTimeWaitList( | 399 void QuicDispatcher::OnConnectionRemovedFromTimeWaitList( |
400 QuicConnectionId connection_id) { | 400 QuicConnectionId connection_id) { |
401 DVLOG(1) << "Connection " << connection_id << " removed from time wait list."; | 401 DVLOG(1) << "Connection " << connection_id << " removed from time wait list."; |
402 } | 402 } |
403 | 403 |
404 QuicPacketWriter* QuicDispatcher::CreateWriter(int fd) { | 404 QuicPacketWriter* QuicDispatcher::CreateWriter(int fd) { |
405 return new QuicDefaultPacketWriter(fd); | 405 return new QuicDefaultPacketWriter(fd); |
406 } | 406 } |
407 | 407 |
408 QuicSession* QuicDispatcher::CreateQuicSession( | 408 QuicServerSession* QuicDispatcher::CreateQuicSession( |
409 QuicConnectionId connection_id, | 409 QuicConnectionId connection_id, |
410 const IPEndPoint& server_address, | 410 const IPEndPoint& server_address, |
411 const IPEndPoint& client_address) { | 411 const IPEndPoint& client_address) { |
412 // The QuicSession takes ownership of |connection| below. | 412 // The QuicServerSession takes ownership of |connection| below. |
413 QuicConnection* connection = new QuicConnection( | 413 QuicConnection* connection = new QuicConnection( |
414 connection_id, client_address, helper_.get(), connection_writer_factory_, | 414 connection_id, client_address, helper_.get(), connection_writer_factory_, |
415 /* owns_writer= */ true, Perspective::IS_SERVER, | 415 /* owns_writer= */ true, Perspective::IS_SERVER, |
416 crypto_config_.HasProofSource(), supported_versions_); | 416 crypto_config_.HasProofSource(), supported_versions_); |
417 | 417 |
418 QuicServerSession* session = new QuicServerSession(config_, connection, this); | 418 QuicServerSession* session = new QuicServerSession(config_, connection, this); |
419 session->InitializeSession(&crypto_config_); | 419 session->InitializeSession(&crypto_config_); |
420 return session; | 420 return session; |
421 } | 421 } |
422 | 422 |
(...skipping 14 matching lines...) Expand all Loading... |
437 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( | 437 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( |
438 header.connection_id)); | 438 header.connection_id)); |
439 | 439 |
440 // Continue parsing the packet to extract the sequence number. Then | 440 // Continue parsing the packet to extract the sequence number. Then |
441 // send it to the time wait manager in OnUnathenticatedHeader. | 441 // send it to the time wait manager in OnUnathenticatedHeader. |
442 return true; | 442 return true; |
443 } | 443 } |
444 | 444 |
445 } // namespace tools | 445 } // namespace tools |
446 } // namespace net | 446 } // namespace net |
OLD | NEW |