| 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 <utility> | 7 #include <utility> |
| 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 // Not owned. | 41 // Not owned. |
| 42 QuicDispatcher* dispatcher_; | 42 QuicDispatcher* dispatcher_; |
| 43 | 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(DeleteSessionsAlarm); | 44 DISALLOW_COPY_AND_ASSIGN(DeleteSessionsAlarm); |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 class QuicDispatcher::QuicFramerVisitor : public QuicFramerVisitorInterface { | |
| 50 public: | |
| 51 explicit QuicFramerVisitor(QuicDispatcher* dispatcher) | |
| 52 : dispatcher_(dispatcher), connection_id_(0) {} | |
| 53 | |
| 54 // QuicFramerVisitorInterface implementation | |
| 55 void OnPacket() override {} | |
| 56 bool OnUnauthenticatedPublicHeader( | |
| 57 const QuicPacketPublicHeader& header) override { | |
| 58 connection_id_ = header.connection_id; | |
| 59 return dispatcher_->OnUnauthenticatedPublicHeader(header); | |
| 60 } | |
| 61 bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override { | |
| 62 dispatcher_->OnUnauthenticatedHeader(header); | |
| 63 return false; | |
| 64 } | |
| 65 void OnError(QuicFramer* framer) override { | |
| 66 QuicErrorCode error = framer->error(); | |
| 67 dispatcher_->SetLastError(error); | |
| 68 DVLOG(1) << QuicUtils::ErrorToString(error); | |
| 69 } | |
| 70 | |
| 71 bool OnProtocolVersionMismatch(QuicVersion /*received_version*/) override { | |
| 72 DVLOG(1) << "Version mismatch, connection ID " << connection_id_; | |
| 73 // Keep processing after protocol mismatch - this will be dealt with by the | |
| 74 // time wait list or connection that we will create. | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 // The following methods should never get called because | |
| 79 // OnUnauthenticatedPublicHeader() or OnUnauthenticatedHeader() (whichever was | |
| 80 // called last), will return false and prevent a subsequent invocation of | |
| 81 // these methods. Thus, the payload of the packet is never processed in the | |
| 82 // dispatcher. | |
| 83 void OnPublicResetPacket(const QuicPublicResetPacket& /*packet*/) override { | |
| 84 DCHECK(false); | |
| 85 } | |
| 86 void OnVersionNegotiationPacket( | |
| 87 const QuicVersionNegotiationPacket& /*packet*/) override { | |
| 88 DCHECK(false); | |
| 89 } | |
| 90 void OnDecryptedPacket(EncryptionLevel level) override { DCHECK(false); } | |
| 91 bool OnPacketHeader(const QuicPacketHeader& /*header*/) override { | |
| 92 DCHECK(false); | |
| 93 return false; | |
| 94 } | |
| 95 void OnRevivedPacket() override { DCHECK(false); } | |
| 96 void OnFecProtectedPayload(StringPiece /*payload*/) override { | |
| 97 DCHECK(false); | |
| 98 } | |
| 99 bool OnStreamFrame(const QuicStreamFrame& /*frame*/) override { | |
| 100 DCHECK(false); | |
| 101 return false; | |
| 102 } | |
| 103 bool OnAckFrame(const QuicAckFrame& /*frame*/) override { | |
| 104 DCHECK(false); | |
| 105 return false; | |
| 106 } | |
| 107 bool OnStopWaitingFrame(const QuicStopWaitingFrame& /*frame*/) override { | |
| 108 DCHECK(false); | |
| 109 return false; | |
| 110 } | |
| 111 bool OnPingFrame(const QuicPingFrame& /*frame*/) override { | |
| 112 DCHECK(false); | |
| 113 return false; | |
| 114 } | |
| 115 bool OnRstStreamFrame(const QuicRstStreamFrame& /*frame*/) override { | |
| 116 DCHECK(false); | |
| 117 return false; | |
| 118 } | |
| 119 bool OnConnectionCloseFrame( | |
| 120 const QuicConnectionCloseFrame& /*frame*/) override { | |
| 121 DCHECK(false); | |
| 122 return false; | |
| 123 } | |
| 124 bool OnGoAwayFrame(const QuicGoAwayFrame& /*frame*/) override { | |
| 125 DCHECK(false); | |
| 126 return false; | |
| 127 } | |
| 128 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& /*frame*/) override { | |
| 129 DCHECK(false); | |
| 130 return false; | |
| 131 } | |
| 132 bool OnBlockedFrame(const QuicBlockedFrame& frame) override { | |
| 133 DCHECK(false); | |
| 134 return false; | |
| 135 } | |
| 136 bool OnPathCloseFrame(const QuicPathCloseFrame& frame) override { | |
| 137 DCHECK(false); | |
| 138 return false; | |
| 139 } | |
| 140 void OnFecData(StringPiece /*redundancy*/) override { DCHECK(false); } | |
| 141 void OnPacketComplete() override { DCHECK(false); } | |
| 142 | |
| 143 private: | |
| 144 QuicDispatcher* dispatcher_; | |
| 145 | |
| 146 // Latched in OnUnauthenticatedPublicHeader for use later. | |
| 147 QuicConnectionId connection_id_; | |
| 148 }; | |
| 149 | |
| 150 QuicDispatcher::QuicDispatcher(const QuicConfig& config, | 49 QuicDispatcher::QuicDispatcher(const QuicConfig& config, |
| 151 const QuicCryptoServerConfig* crypto_config, | 50 const QuicCryptoServerConfig* crypto_config, |
| 152 const QuicVersionVector& supported_versions, | 51 const QuicVersionVector& supported_versions, |
| 153 QuicConnectionHelperInterface* helper) | 52 QuicConnectionHelperInterface* helper) |
| 154 : config_(config), | 53 : config_(config), |
| 155 crypto_config_(crypto_config), | 54 crypto_config_(crypto_config), |
| 156 helper_(helper), | 55 helper_(helper), |
| 157 delete_sessions_alarm_( | 56 delete_sessions_alarm_( |
| 158 helper_->CreateAlarm(new DeleteSessionsAlarm(this))), | 57 helper_->CreateAlarm(new DeleteSessionsAlarm(this))), |
| 159 supported_versions_(supported_versions), | 58 supported_versions_(supported_versions), |
| 160 current_packet_(nullptr), | 59 current_packet_(nullptr), |
| 161 framer_(supported_versions, | 60 framer_(supported_versions, |
| 162 /*unused*/ QuicTime::Zero(), | 61 /*unused*/ QuicTime::Zero(), |
| 163 Perspective::IS_SERVER), | 62 Perspective::IS_SERVER), |
| 164 framer_visitor_(new QuicFramerVisitor(this)), | |
| 165 last_error_(QUIC_NO_ERROR) { | 63 last_error_(QUIC_NO_ERROR) { |
| 166 framer_.set_visitor(framer_visitor_.get()); | 64 framer_.set_visitor(this); |
| 167 } | 65 } |
| 168 | 66 |
| 169 QuicDispatcher::~QuicDispatcher() { | 67 QuicDispatcher::~QuicDispatcher() { |
| 170 STLDeleteValues(&session_map_); | 68 STLDeleteValues(&session_map_); |
| 171 STLDeleteElements(&closed_session_list_); | 69 STLDeleteElements(&closed_session_list_); |
| 172 } | 70 } |
| 173 | 71 |
| 174 void QuicDispatcher::InitializeWithWriter(QuicPacketWriter* writer) { | 72 void QuicDispatcher::InitializeWithWriter(QuicPacketWriter* writer) { |
| 175 DCHECK(writer_ == nullptr); | 73 DCHECK(writer_ == nullptr); |
| 176 writer_.reset(writer); | 74 writer_.reset(writer); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // TODO(ianswett): This will malfunction if the full header of the packet | 144 // TODO(ianswett): This will malfunction if the full header of the packet |
| 247 // causes a parsing error when parsed using the server's preferred | 145 // causes a parsing error when parsed using the server's preferred |
| 248 // version. | 146 // version. |
| 249 } | 147 } |
| 250 } | 148 } |
| 251 // Set the framer's version and continue processing. | 149 // Set the framer's version and continue processing. |
| 252 framer_.set_version(version); | 150 framer_.set_version(version); |
| 253 return true; | 151 return true; |
| 254 } | 152 } |
| 255 | 153 |
| 256 void QuicDispatcher::OnUnauthenticatedHeader(const QuicPacketHeader& header) { | 154 bool QuicDispatcher::OnUnauthenticatedHeader(const QuicPacketHeader& header) { |
| 257 QuicConnectionId connection_id = header.public_header.connection_id; | 155 QuicConnectionId connection_id = header.public_header.connection_id; |
| 258 | 156 |
| 259 if (time_wait_list_manager_->IsConnectionIdInTimeWait( | 157 if (time_wait_list_manager_->IsConnectionIdInTimeWait( |
| 260 header.public_header.connection_id)) { | 158 header.public_header.connection_id)) { |
| 261 // This connection ID is already in time-wait state. | 159 // This connection ID is already in time-wait state. |
| 262 time_wait_list_manager_->ProcessPacket( | 160 time_wait_list_manager_->ProcessPacket( |
| 263 current_server_address_, current_client_address_, | 161 current_server_address_, current_client_address_, |
| 264 header.public_header.connection_id, header.packet_number, | 162 header.public_header.connection_id, header.packet_number, |
| 265 *current_packet_); | 163 *current_packet_); |
| 266 return; | 164 return false; |
| 267 } | 165 } |
| 268 | 166 |
| 269 // Packet's connection ID is unknown. | 167 // Packet's connection ID is unknown. |
| 270 // Apply the validity checks. | 168 // Apply the validity checks. |
| 271 QuicPacketFate fate = ValidityChecks(header); | 169 QuicPacketFate fate = ValidityChecks(header); |
| 272 switch (fate) { | 170 switch (fate) { |
| 273 case kFateProcess: { | 171 case kFateProcess: { |
| 274 // Create a session and process the packet. | 172 // Create a session and process the packet. |
| 275 QuicServerSessionBase* session = | 173 QuicServerSessionBase* session = |
| 276 CreateQuicSession(connection_id, current_client_address_); | 174 CreateQuicSession(connection_id, current_client_address_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 292 header.public_header.connection_id)); | 190 header.public_header.connection_id)); |
| 293 time_wait_list_manager_->ProcessPacket( | 191 time_wait_list_manager_->ProcessPacket( |
| 294 current_server_address_, current_client_address_, | 192 current_server_address_, current_client_address_, |
| 295 header.public_header.connection_id, header.packet_number, | 193 header.public_header.connection_id, header.packet_number, |
| 296 *current_packet_); | 194 *current_packet_); |
| 297 break; | 195 break; |
| 298 case kFateDrop: | 196 case kFateDrop: |
| 299 // Do nothing with the packet. | 197 // Do nothing with the packet. |
| 300 break; | 198 break; |
| 301 } | 199 } |
| 200 |
| 201 return false; |
| 302 } | 202 } |
| 303 | 203 |
| 304 QuicDispatcher::QuicPacketFate QuicDispatcher::ValidityChecks( | 204 QuicDispatcher::QuicPacketFate QuicDispatcher::ValidityChecks( |
| 305 const QuicPacketHeader& header) { | 205 const QuicPacketHeader& header) { |
| 306 // To have all the checks work properly without tears, insert any new check | 206 // To have all the checks work properly without tears, insert any new check |
| 307 // into the framework of this method in the section for checks that return the | 207 // into the framework of this method in the section for checks that return the |
| 308 // check's fate value. The sections for checks must be ordered with the | 208 // check's fate value. The sections for checks must be ordered with the |
| 309 // highest priority fate first. | 209 // highest priority fate first. |
| 310 | 210 |
| 311 // Checks that return kFateDrop. | 211 // Checks that return kFateDrop. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 void QuicDispatcher::OnConnectionAddedToTimeWaitList( | 320 void QuicDispatcher::OnConnectionAddedToTimeWaitList( |
| 421 QuicConnectionId connection_id) { | 321 QuicConnectionId connection_id) { |
| 422 DVLOG(1) << "Connection " << connection_id << " added to time wait list."; | 322 DVLOG(1) << "Connection " << connection_id << " added to time wait list."; |
| 423 } | 323 } |
| 424 | 324 |
| 425 void QuicDispatcher::OnConnectionRemovedFromTimeWaitList( | 325 void QuicDispatcher::OnConnectionRemovedFromTimeWaitList( |
| 426 QuicConnectionId connection_id) { | 326 QuicConnectionId connection_id) { |
| 427 DVLOG(1) << "Connection " << connection_id << " removed from time wait list."; | 327 DVLOG(1) << "Connection " << connection_id << " removed from time wait list."; |
| 428 } | 328 } |
| 429 | 329 |
| 330 void QuicDispatcher::OnPacket() {} |
| 331 |
| 332 void QuicDispatcher::OnError(QuicFramer* framer) { |
| 333 QuicErrorCode error = framer->error(); |
| 334 SetLastError(error); |
| 335 DVLOG(1) << QuicUtils::ErrorToString(error); |
| 336 } |
| 337 |
| 338 bool QuicDispatcher::OnProtocolVersionMismatch( |
| 339 QuicVersion /*received_version*/) { |
| 340 // Keep processing after protocol mismatch - this will be dealt with by the |
| 341 // time wait list or connection that we will create. |
| 342 return true; |
| 343 } |
| 344 |
| 345 void QuicDispatcher::OnPublicResetPacket( |
| 346 const QuicPublicResetPacket& /*packet*/) { |
| 347 DCHECK(false); |
| 348 } |
| 349 |
| 350 void QuicDispatcher::OnVersionNegotiationPacket( |
| 351 const QuicVersionNegotiationPacket& /*packet*/) { |
| 352 DCHECK(false); |
| 353 } |
| 354 |
| 355 void QuicDispatcher::OnDecryptedPacket(EncryptionLevel level) { |
| 356 DCHECK(false); |
| 357 } |
| 358 |
| 359 bool QuicDispatcher::OnPacketHeader(const QuicPacketHeader& /*header*/) { |
| 360 DCHECK(false); |
| 361 return false; |
| 362 } |
| 363 |
| 364 void QuicDispatcher::OnRevivedPacket() { |
| 365 DCHECK(false); |
| 366 } |
| 367 |
| 368 void QuicDispatcher::OnFecProtectedPayload(StringPiece /*payload*/) { |
| 369 DCHECK(false); |
| 370 } |
| 371 |
| 372 bool QuicDispatcher::OnStreamFrame(const QuicStreamFrame& /*frame*/) { |
| 373 DCHECK(false); |
| 374 return false; |
| 375 } |
| 376 |
| 377 bool QuicDispatcher::OnAckFrame(const QuicAckFrame& /*frame*/) { |
| 378 DCHECK(false); |
| 379 return false; |
| 380 } |
| 381 |
| 382 bool QuicDispatcher::OnStopWaitingFrame(const QuicStopWaitingFrame& /*frame*/) { |
| 383 DCHECK(false); |
| 384 return false; |
| 385 } |
| 386 |
| 387 bool QuicDispatcher::OnPingFrame(const QuicPingFrame& /*frame*/) { |
| 388 DCHECK(false); |
| 389 return false; |
| 390 } |
| 391 |
| 392 bool QuicDispatcher::OnRstStreamFrame(const QuicRstStreamFrame& /*frame*/) { |
| 393 DCHECK(false); |
| 394 return false; |
| 395 } |
| 396 |
| 397 bool QuicDispatcher::OnConnectionCloseFrame( |
| 398 const QuicConnectionCloseFrame& /*frame*/) { |
| 399 DCHECK(false); |
| 400 return false; |
| 401 } |
| 402 |
| 403 bool QuicDispatcher::OnGoAwayFrame(const QuicGoAwayFrame& /*frame*/) { |
| 404 DCHECK(false); |
| 405 return false; |
| 406 } |
| 407 |
| 408 bool QuicDispatcher::OnWindowUpdateFrame( |
| 409 const QuicWindowUpdateFrame& /*frame*/) { |
| 410 DCHECK(false); |
| 411 return false; |
| 412 } |
| 413 |
| 414 bool QuicDispatcher::OnBlockedFrame(const QuicBlockedFrame& frame) { |
| 415 DCHECK(false); |
| 416 return false; |
| 417 } |
| 418 |
| 419 bool QuicDispatcher::OnPathCloseFrame(const QuicPathCloseFrame& frame) { |
| 420 DCHECK(false); |
| 421 return false; |
| 422 } |
| 423 |
| 424 void QuicDispatcher::OnFecData(StringPiece /*redundancy*/) { |
| 425 DCHECK(false); |
| 426 } |
| 427 |
| 428 void QuicDispatcher::OnPacketComplete() { |
| 429 DCHECK(false); |
| 430 } |
| 431 |
| 430 QuicServerSessionBase* QuicDispatcher::CreateQuicSession( | 432 QuicServerSessionBase* QuicDispatcher::CreateQuicSession( |
| 431 QuicConnectionId connection_id, | 433 QuicConnectionId connection_id, |
| 432 const IPEndPoint& client_address) { | 434 const IPEndPoint& client_address) { |
| 433 // The QuicServerSessionBase takes ownership of |connection| below. | 435 // The QuicServerSessionBase takes ownership of |connection| below. |
| 434 QuicConnection* connection = new QuicConnection( | 436 QuicConnection* connection = new QuicConnection( |
| 435 connection_id, client_address, helper_.get(), CreatePerConnectionWriter(), | 437 connection_id, client_address, helper_.get(), CreatePerConnectionWriter(), |
| 436 /* owns_writer= */ true, Perspective::IS_SERVER, supported_versions_); | 438 /* owns_writer= */ true, Perspective::IS_SERVER, supported_versions_); |
| 437 | 439 |
| 438 QuicServerSessionBase* session = | 440 QuicServerSessionBase* session = |
| 439 new QuicSimpleServerSession(config_, connection, this, crypto_config_); | 441 new QuicSimpleServerSession(config_, connection, this, crypto_config_); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 470 | 472 |
| 471 QuicPacketWriter* QuicDispatcher::CreatePerConnectionWriter() { | 473 QuicPacketWriter* QuicDispatcher::CreatePerConnectionWriter() { |
| 472 return new QuicPerConnectionPacketWriter(writer_.get()); | 474 return new QuicPerConnectionPacketWriter(writer_.get()); |
| 473 } | 475 } |
| 474 | 476 |
| 475 void QuicDispatcher::SetLastError(QuicErrorCode error) { | 477 void QuicDispatcher::SetLastError(QuicErrorCode error) { |
| 476 last_error_ = error; | 478 last_error_ = error; |
| 477 } | 479 } |
| 478 | 480 |
| 479 } // namespace net | 481 } // namespace net |
| OLD | NEW |