| 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/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 last_rst_frames_.empty() && | 308 last_rst_frames_.empty() && |
| 309 last_goaway_frames_.empty() && | 309 last_goaway_frames_.empty() && |
| 310 last_window_update_frames_.empty() && | 310 last_window_update_frames_.empty() && |
| 311 last_blocked_frames_.empty() && | 311 last_blocked_frames_.empty() && |
| 312 last_ping_frames_.empty() && | 312 last_ping_frames_.empty() && |
| 313 last_close_frames_.empty()); | 313 last_close_frames_.empty()); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void QuicConnection::OnPublicResetPacket( | 316 void QuicConnection::OnPublicResetPacket( |
| 317 const QuicPublicResetPacket& packet) { | 317 const QuicPublicResetPacket& packet) { |
| 318 if (debug_visitor_.get() != NULL) { | 318 if (debug_visitor_.get() != nullptr) { |
| 319 debug_visitor_->OnPublicResetPacket(packet); | 319 debug_visitor_->OnPublicResetPacket(packet); |
| 320 } | 320 } |
| 321 CloseConnection(QUIC_PUBLIC_RESET, true); | 321 CloseConnection(QUIC_PUBLIC_RESET, true); |
| 322 | 322 |
| 323 DVLOG(1) << ENDPOINT << "Connection " << connection_id() | 323 DVLOG(1) << ENDPOINT << "Connection " << connection_id() |
| 324 << " closed via QUIC_PUBLIC_RESET from peer."; | 324 << " closed via QUIC_PUBLIC_RESET from peer."; |
| 325 } | 325 } |
| 326 | 326 |
| 327 bool QuicConnection::OnProtocolVersionMismatch(QuicVersion received_version) { | 327 bool QuicConnection::OnProtocolVersionMismatch(QuicVersion received_version) { |
| 328 DVLOG(1) << ENDPOINT << "Received packet with mismatched version " | 328 DVLOG(1) << ENDPOINT << "Received packet with mismatched version " |
| 329 << received_version; | 329 << received_version; |
| 330 // TODO(satyamshekhar): Implement no server state in this mode. | 330 // TODO(satyamshekhar): Implement no server state in this mode. |
| 331 if (!is_server_) { | 331 if (!is_server_) { |
| 332 LOG(DFATAL) << ENDPOINT << "Framer called OnProtocolVersionMismatch. " | 332 LOG(DFATAL) << ENDPOINT << "Framer called OnProtocolVersionMismatch. " |
| 333 << "Closing connection."; | 333 << "Closing connection."; |
| 334 CloseConnection(QUIC_INTERNAL_ERROR, false); | 334 CloseConnection(QUIC_INTERNAL_ERROR, false); |
| 335 return false; | 335 return false; |
| 336 } | 336 } |
| 337 DCHECK_NE(version(), received_version); | 337 DCHECK_NE(version(), received_version); |
| 338 | 338 |
| 339 if (debug_visitor_.get() != NULL) { | 339 if (debug_visitor_.get() != nullptr) { |
| 340 debug_visitor_->OnProtocolVersionMismatch(received_version); | 340 debug_visitor_->OnProtocolVersionMismatch(received_version); |
| 341 } | 341 } |
| 342 | 342 |
| 343 switch (version_negotiation_state_) { | 343 switch (version_negotiation_state_) { |
| 344 case START_NEGOTIATION: | 344 case START_NEGOTIATION: |
| 345 if (!framer_.IsSupportedVersion(received_version)) { | 345 if (!framer_.IsSupportedVersion(received_version)) { |
| 346 SendVersionNegotiationPacket(); | 346 SendVersionNegotiationPacket(); |
| 347 version_negotiation_state_ = NEGOTIATION_IN_PROGRESS; | 347 version_negotiation_state_ = NEGOTIATION_IN_PROGRESS; |
| 348 return false; | 348 return false; |
| 349 } | 349 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 360 // Might be old packets that were sent by the client before the version | 360 // Might be old packets that were sent by the client before the version |
| 361 // was negotiated. Drop these. | 361 // was negotiated. Drop these. |
| 362 return false; | 362 return false; |
| 363 | 363 |
| 364 default: | 364 default: |
| 365 DCHECK(false); | 365 DCHECK(false); |
| 366 } | 366 } |
| 367 | 367 |
| 368 version_negotiation_state_ = NEGOTIATED_VERSION; | 368 version_negotiation_state_ = NEGOTIATED_VERSION; |
| 369 visitor_->OnSuccessfulVersionNegotiation(received_version); | 369 visitor_->OnSuccessfulVersionNegotiation(received_version); |
| 370 if (debug_visitor_.get() != NULL) { | 370 if (debug_visitor_.get() != nullptr) { |
| 371 debug_visitor_->OnSuccessfulVersionNegotiation(received_version); | 371 debug_visitor_->OnSuccessfulVersionNegotiation(received_version); |
| 372 } | 372 } |
| 373 DVLOG(1) << ENDPOINT << "version negotiated " << received_version; | 373 DVLOG(1) << ENDPOINT << "version negotiated " << received_version; |
| 374 | 374 |
| 375 // Store the new version. | 375 // Store the new version. |
| 376 framer_.set_version(received_version); | 376 framer_.set_version(received_version); |
| 377 | 377 |
| 378 // TODO(satyamshekhar): Store the sequence number of this packet and close the | 378 // TODO(satyamshekhar): Store the sequence number of this packet and close the |
| 379 // connection if we ever received a packet with incorrect version and whose | 379 // connection if we ever received a packet with incorrect version and whose |
| 380 // sequence number is greater. | 380 // sequence number is greater. |
| 381 return true; | 381 return true; |
| 382 } | 382 } |
| 383 | 383 |
| 384 // Handles version negotiation for client connection. | 384 // Handles version negotiation for client connection. |
| 385 void QuicConnection::OnVersionNegotiationPacket( | 385 void QuicConnection::OnVersionNegotiationPacket( |
| 386 const QuicVersionNegotiationPacket& packet) { | 386 const QuicVersionNegotiationPacket& packet) { |
| 387 if (is_server_) { | 387 if (is_server_) { |
| 388 LOG(DFATAL) << ENDPOINT << "Framer parsed VersionNegotiationPacket." | 388 LOG(DFATAL) << ENDPOINT << "Framer parsed VersionNegotiationPacket." |
| 389 << " Closing connection."; | 389 << " Closing connection."; |
| 390 CloseConnection(QUIC_INTERNAL_ERROR, false); | 390 CloseConnection(QUIC_INTERNAL_ERROR, false); |
| 391 return; | 391 return; |
| 392 } | 392 } |
| 393 if (debug_visitor_.get() != NULL) { | 393 if (debug_visitor_.get() != nullptr) { |
| 394 debug_visitor_->OnVersionNegotiationPacket(packet); | 394 debug_visitor_->OnVersionNegotiationPacket(packet); |
| 395 } | 395 } |
| 396 | 396 |
| 397 if (version_negotiation_state_ != START_NEGOTIATION) { | 397 if (version_negotiation_state_ != START_NEGOTIATION) { |
| 398 // Possibly a duplicate version negotiation packet. | 398 // Possibly a duplicate version negotiation packet. |
| 399 return; | 399 return; |
| 400 } | 400 } |
| 401 | 401 |
| 402 if (std::find(packet.versions.begin(), | 402 if (std::find(packet.versions.begin(), |
| 403 packet.versions.end(), version()) != | 403 packet.versions.end(), version()) != |
| (...skipping 28 matching lines...) Expand all Loading... |
| 432 | 432 |
| 433 bool QuicConnection::OnUnauthenticatedHeader(const QuicPacketHeader& header) { | 433 bool QuicConnection::OnUnauthenticatedHeader(const QuicPacketHeader& header) { |
| 434 return true; | 434 return true; |
| 435 } | 435 } |
| 436 | 436 |
| 437 void QuicConnection::OnDecryptedPacket(EncryptionLevel level) { | 437 void QuicConnection::OnDecryptedPacket(EncryptionLevel level) { |
| 438 last_decrypted_packet_level_ = level; | 438 last_decrypted_packet_level_ = level; |
| 439 } | 439 } |
| 440 | 440 |
| 441 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { | 441 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { |
| 442 if (debug_visitor_.get() != NULL) { | 442 if (debug_visitor_.get() != nullptr) { |
| 443 debug_visitor_->OnPacketHeader(header); | 443 debug_visitor_->OnPacketHeader(header); |
| 444 } | 444 } |
| 445 | 445 |
| 446 if (!ProcessValidatedPacket()) { | 446 if (!ProcessValidatedPacket()) { |
| 447 return false; | 447 return false; |
| 448 } | 448 } |
| 449 | 449 |
| 450 // Will be decrement below if we fall through to return true; | 450 // Will be decrement below if we fall through to return true; |
| 451 ++stats_.packets_dropped; | 451 ++stats_.packets_dropped; |
| 452 | 452 |
| 453 if (header.public_header.connection_id != connection_id_) { | 453 if (header.public_header.connection_id != connection_id_) { |
| 454 DVLOG(1) << ENDPOINT << "Ignoring packet from unexpected ConnectionId: " | 454 DVLOG(1) << ENDPOINT << "Ignoring packet from unexpected ConnectionId: " |
| 455 << header.public_header.connection_id << " instead of " | 455 << header.public_header.connection_id << " instead of " |
| 456 << connection_id_; | 456 << connection_id_; |
| 457 if (debug_visitor_.get() != NULL) { | 457 if (debug_visitor_.get() != nullptr) { |
| 458 debug_visitor_->OnIncorrectConnectionId( | 458 debug_visitor_->OnIncorrectConnectionId( |
| 459 header.public_header.connection_id); | 459 header.public_header.connection_id); |
| 460 } | 460 } |
| 461 return false; | 461 return false; |
| 462 } | 462 } |
| 463 | 463 |
| 464 if (!Near(header.packet_sequence_number, | 464 if (!Near(header.packet_sequence_number, |
| 465 last_header_.packet_sequence_number)) { | 465 last_header_.packet_sequence_number)) { |
| 466 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number | 466 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number |
| 467 << " out of bounds. Discarding"; | 467 << " out of bounds. Discarding"; |
| 468 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER, | 468 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER, |
| 469 "Packet sequence number out of bounds"); | 469 "Packet sequence number out of bounds"); |
| 470 return false; | 470 return false; |
| 471 } | 471 } |
| 472 | 472 |
| 473 // If this packet has already been seen, or that the sender | 473 // If this packet has already been seen, or that the sender |
| 474 // has told us will not be retransmitted, then stop processing the packet. | 474 // has told us will not be retransmitted, then stop processing the packet. |
| 475 if (!received_packet_manager_.IsAwaitingPacket( | 475 if (!received_packet_manager_.IsAwaitingPacket( |
| 476 header.packet_sequence_number)) { | 476 header.packet_sequence_number)) { |
| 477 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number | 477 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number |
| 478 << " no longer being waited for. Discarding."; | 478 << " no longer being waited for. Discarding."; |
| 479 if (debug_visitor_.get() != NULL) { | 479 if (debug_visitor_.get() != nullptr) { |
| 480 debug_visitor_->OnDuplicatePacket(header.packet_sequence_number); | 480 debug_visitor_->OnDuplicatePacket(header.packet_sequence_number); |
| 481 } | 481 } |
| 482 return false; | 482 return false; |
| 483 } | 483 } |
| 484 | 484 |
| 485 if (version_negotiation_state_ != NEGOTIATED_VERSION) { | 485 if (version_negotiation_state_ != NEGOTIATED_VERSION) { |
| 486 if (is_server_) { | 486 if (is_server_) { |
| 487 if (!header.public_header.version_flag) { | 487 if (!header.public_header.version_flag) { |
| 488 DLOG(WARNING) << ENDPOINT << "Packet " << header.packet_sequence_number | 488 DLOG(WARNING) << ENDPOINT << "Packet " << header.packet_sequence_number |
| 489 << " without version flag before version negotiated."; | 489 << " without version flag before version negotiated."; |
| 490 // Packets should have the version flag till version negotiation is | 490 // Packets should have the version flag till version negotiation is |
| 491 // done. | 491 // done. |
| 492 CloseConnection(QUIC_INVALID_VERSION, false); | 492 CloseConnection(QUIC_INVALID_VERSION, false); |
| 493 return false; | 493 return false; |
| 494 } else { | 494 } else { |
| 495 DCHECK_EQ(1u, header.public_header.versions.size()); | 495 DCHECK_EQ(1u, header.public_header.versions.size()); |
| 496 DCHECK_EQ(header.public_header.versions[0], version()); | 496 DCHECK_EQ(header.public_header.versions[0], version()); |
| 497 version_negotiation_state_ = NEGOTIATED_VERSION; | 497 version_negotiation_state_ = NEGOTIATED_VERSION; |
| 498 visitor_->OnSuccessfulVersionNegotiation(version()); | 498 visitor_->OnSuccessfulVersionNegotiation(version()); |
| 499 if (debug_visitor_.get() != NULL) { | 499 if (debug_visitor_.get() != nullptr) { |
| 500 debug_visitor_->OnSuccessfulVersionNegotiation(version()); | 500 debug_visitor_->OnSuccessfulVersionNegotiation(version()); |
| 501 } | 501 } |
| 502 } | 502 } |
| 503 } else { | 503 } else { |
| 504 DCHECK(!header.public_header.version_flag); | 504 DCHECK(!header.public_header.version_flag); |
| 505 // If the client gets a packet without the version flag from the server | 505 // If the client gets a packet without the version flag from the server |
| 506 // it should stop sending version since the version negotiation is done. | 506 // it should stop sending version since the version negotiation is done. |
| 507 packet_generator_.StopSendingVersion(); | 507 packet_generator_.StopSendingVersion(); |
| 508 version_negotiation_state_ = NEGOTIATED_VERSION; | 508 version_negotiation_state_ = NEGOTIATED_VERSION; |
| 509 visitor_->OnSuccessfulVersionNegotiation(version()); | 509 visitor_->OnSuccessfulVersionNegotiation(version()); |
| 510 if (debug_visitor_.get() != NULL) { | 510 if (debug_visitor_.get() != nullptr) { |
| 511 debug_visitor_->OnSuccessfulVersionNegotiation(version()); | 511 debug_visitor_->OnSuccessfulVersionNegotiation(version()); |
| 512 } | 512 } |
| 513 } | 513 } |
| 514 } | 514 } |
| 515 | 515 |
| 516 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); | 516 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); |
| 517 | 517 |
| 518 --stats_.packets_dropped; | 518 --stats_.packets_dropped; |
| 519 DVLOG(1) << ENDPOINT << "Received packet header: " << header; | 519 DVLOG(1) << ENDPOINT << "Received packet header: " << header; |
| 520 last_header_ = header; | 520 last_header_ = header; |
| 521 DCHECK(connected_); | 521 DCHECK(connected_); |
| 522 return true; | 522 return true; |
| 523 } | 523 } |
| 524 | 524 |
| 525 void QuicConnection::OnFecProtectedPayload(StringPiece payload) { | 525 void QuicConnection::OnFecProtectedPayload(StringPiece payload) { |
| 526 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group); | 526 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group); |
| 527 DCHECK_NE(0u, last_header_.fec_group); | 527 DCHECK_NE(0u, last_header_.fec_group); |
| 528 QuicFecGroup* group = GetFecGroup(); | 528 QuicFecGroup* group = GetFecGroup(); |
| 529 if (group != NULL) { | 529 if (group != nullptr) { |
| 530 group->Update(last_decrypted_packet_level_, last_header_, payload); | 530 group->Update(last_decrypted_packet_level_, last_header_, payload); |
| 531 } | 531 } |
| 532 } | 532 } |
| 533 | 533 |
| 534 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { | 534 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { |
| 535 DCHECK(connected_); | 535 DCHECK(connected_); |
| 536 if (debug_visitor_.get() != NULL) { | 536 if (debug_visitor_.get() != nullptr) { |
| 537 debug_visitor_->OnStreamFrame(frame); | 537 debug_visitor_->OnStreamFrame(frame); |
| 538 } | 538 } |
| 539 if (frame.stream_id != kCryptoStreamId && | 539 if (frame.stream_id != kCryptoStreamId && |
| 540 last_decrypted_packet_level_ == ENCRYPTION_NONE) { | 540 last_decrypted_packet_level_ == ENCRYPTION_NONE) { |
| 541 DLOG(WARNING) << ENDPOINT | 541 DLOG(WARNING) << ENDPOINT |
| 542 << "Received an unencrypted data frame: closing connection"; | 542 << "Received an unencrypted data frame: closing connection"; |
| 543 SendConnectionClose(QUIC_UNENCRYPTED_STREAM_DATA); | 543 SendConnectionClose(QUIC_UNENCRYPTED_STREAM_DATA); |
| 544 return false; | 544 return false; |
| 545 } | 545 } |
| 546 last_stream_frames_.push_back(frame); | 546 last_stream_frames_.push_back(frame); |
| 547 return true; | 547 return true; |
| 548 } | 548 } |
| 549 | 549 |
| 550 bool QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) { | 550 bool QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) { |
| 551 DCHECK(connected_); | 551 DCHECK(connected_); |
| 552 if (debug_visitor_.get() != NULL) { | 552 if (debug_visitor_.get() != nullptr) { |
| 553 debug_visitor_->OnAckFrame(incoming_ack); | 553 debug_visitor_->OnAckFrame(incoming_ack); |
| 554 } | 554 } |
| 555 DVLOG(1) << ENDPOINT << "OnAckFrame: " << incoming_ack; | 555 DVLOG(1) << ENDPOINT << "OnAckFrame: " << incoming_ack; |
| 556 | 556 |
| 557 if (last_header_.packet_sequence_number <= largest_seen_packet_with_ack_) { | 557 if (last_header_.packet_sequence_number <= largest_seen_packet_with_ack_) { |
| 558 DVLOG(1) << ENDPOINT << "Received an old ack frame: ignoring"; | 558 DVLOG(1) << ENDPOINT << "Received an old ack frame: ignoring"; |
| 559 return true; | 559 return true; |
| 560 } | 560 } |
| 561 | 561 |
| 562 if (!ValidateAckFrame(incoming_ack)) { | 562 if (!ValidateAckFrame(incoming_ack)) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 589 const QuicStopWaitingFrame& stop_waiting) { | 589 const QuicStopWaitingFrame& stop_waiting) { |
| 590 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number; | 590 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number; |
| 591 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); | 591 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); |
| 592 // Possibly close any FecGroups which are now irrelevant. | 592 // Possibly close any FecGroups which are now irrelevant. |
| 593 CloseFecGroupsBefore(stop_waiting.least_unacked + 1); | 593 CloseFecGroupsBefore(stop_waiting.least_unacked + 1); |
| 594 } | 594 } |
| 595 | 595 |
| 596 bool QuicConnection::OnCongestionFeedbackFrame( | 596 bool QuicConnection::OnCongestionFeedbackFrame( |
| 597 const QuicCongestionFeedbackFrame& feedback) { | 597 const QuicCongestionFeedbackFrame& feedback) { |
| 598 DCHECK(connected_); | 598 DCHECK(connected_); |
| 599 if (debug_visitor_.get() != NULL) { | 599 if (debug_visitor_.get() != nullptr) { |
| 600 debug_visitor_->OnCongestionFeedbackFrame(feedback); | 600 debug_visitor_->OnCongestionFeedbackFrame(feedback); |
| 601 } | 601 } |
| 602 last_congestion_frames_.push_back(feedback); | 602 last_congestion_frames_.push_back(feedback); |
| 603 return connected_; | 603 return connected_; |
| 604 } | 604 } |
| 605 | 605 |
| 606 bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) { | 606 bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) { |
| 607 DCHECK(connected_); | 607 DCHECK(connected_); |
| 608 | 608 |
| 609 if (last_header_.packet_sequence_number <= | 609 if (last_header_.packet_sequence_number <= |
| 610 largest_seen_packet_with_stop_waiting_) { | 610 largest_seen_packet_with_stop_waiting_) { |
| 611 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring"; | 611 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring"; |
| 612 return true; | 612 return true; |
| 613 } | 613 } |
| 614 | 614 |
| 615 if (!ValidateStopWaitingFrame(frame)) { | 615 if (!ValidateStopWaitingFrame(frame)) { |
| 616 SendConnectionClose(QUIC_INVALID_STOP_WAITING_DATA); | 616 SendConnectionClose(QUIC_INVALID_STOP_WAITING_DATA); |
| 617 return false; | 617 return false; |
| 618 } | 618 } |
| 619 | 619 |
| 620 if (debug_visitor_.get() != NULL) { | 620 if (debug_visitor_.get() != nullptr) { |
| 621 debug_visitor_->OnStopWaitingFrame(frame); | 621 debug_visitor_->OnStopWaitingFrame(frame); |
| 622 } | 622 } |
| 623 | 623 |
| 624 last_stop_waiting_frames_.push_back(frame); | 624 last_stop_waiting_frames_.push_back(frame); |
| 625 return connected_; | 625 return connected_; |
| 626 } | 626 } |
| 627 | 627 |
| 628 bool QuicConnection::OnPingFrame(const QuicPingFrame& frame) { | 628 bool QuicConnection::OnPingFrame(const QuicPingFrame& frame) { |
| 629 DCHECK(connected_); | 629 DCHECK(connected_); |
| 630 if (debug_visitor_.get() != NULL) { | 630 if (debug_visitor_.get() != nullptr) { |
| 631 debug_visitor_->OnPingFrame(frame); | 631 debug_visitor_->OnPingFrame(frame); |
| 632 } | 632 } |
| 633 last_ping_frames_.push_back(frame); | 633 last_ping_frames_.push_back(frame); |
| 634 return true; | 634 return true; |
| 635 } | 635 } |
| 636 | 636 |
| 637 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { | 637 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { |
| 638 if (incoming_ack.largest_observed > packet_generator_.sequence_number()) { | 638 if (incoming_ack.largest_observed > packet_generator_.sequence_number()) { |
| 639 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:" | 639 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:" |
| 640 << incoming_ack.largest_observed << " vs " | 640 << incoming_ack.largest_observed << " vs " |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 return false; | 711 return false; |
| 712 } | 712 } |
| 713 | 713 |
| 714 return true; | 714 return true; |
| 715 } | 715 } |
| 716 | 716 |
| 717 void QuicConnection::OnFecData(const QuicFecData& fec) { | 717 void QuicConnection::OnFecData(const QuicFecData& fec) { |
| 718 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group); | 718 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group); |
| 719 DCHECK_NE(0u, last_header_.fec_group); | 719 DCHECK_NE(0u, last_header_.fec_group); |
| 720 QuicFecGroup* group = GetFecGroup(); | 720 QuicFecGroup* group = GetFecGroup(); |
| 721 if (group != NULL) { | 721 if (group != nullptr) { |
| 722 group->UpdateFec(last_decrypted_packet_level_, | 722 group->UpdateFec(last_decrypted_packet_level_, |
| 723 last_header_.packet_sequence_number, fec); | 723 last_header_.packet_sequence_number, fec); |
| 724 } | 724 } |
| 725 } | 725 } |
| 726 | 726 |
| 727 bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { | 727 bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { |
| 728 DCHECK(connected_); | 728 DCHECK(connected_); |
| 729 if (debug_visitor_.get() != NULL) { | 729 if (debug_visitor_.get() != nullptr) { |
| 730 debug_visitor_->OnRstStreamFrame(frame); | 730 debug_visitor_->OnRstStreamFrame(frame); |
| 731 } | 731 } |
| 732 DVLOG(1) << ENDPOINT << "Stream reset with error " | 732 DVLOG(1) << ENDPOINT << "Stream reset with error " |
| 733 << QuicUtils::StreamErrorToString(frame.error_code); | 733 << QuicUtils::StreamErrorToString(frame.error_code); |
| 734 last_rst_frames_.push_back(frame); | 734 last_rst_frames_.push_back(frame); |
| 735 return connected_; | 735 return connected_; |
| 736 } | 736 } |
| 737 | 737 |
| 738 bool QuicConnection::OnConnectionCloseFrame( | 738 bool QuicConnection::OnConnectionCloseFrame( |
| 739 const QuicConnectionCloseFrame& frame) { | 739 const QuicConnectionCloseFrame& frame) { |
| 740 DCHECK(connected_); | 740 DCHECK(connected_); |
| 741 if (debug_visitor_.get() != NULL) { | 741 if (debug_visitor_.get() != nullptr) { |
| 742 debug_visitor_->OnConnectionCloseFrame(frame); | 742 debug_visitor_->OnConnectionCloseFrame(frame); |
| 743 } | 743 } |
| 744 DVLOG(1) << ENDPOINT << "Connection " << connection_id() | 744 DVLOG(1) << ENDPOINT << "Connection " << connection_id() |
| 745 << " closed with error " | 745 << " closed with error " |
| 746 << QuicUtils::ErrorToString(frame.error_code) | 746 << QuicUtils::ErrorToString(frame.error_code) |
| 747 << " " << frame.error_details; | 747 << " " << frame.error_details; |
| 748 last_close_frames_.push_back(frame); | 748 last_close_frames_.push_back(frame); |
| 749 return connected_; | 749 return connected_; |
| 750 } | 750 } |
| 751 | 751 |
| 752 bool QuicConnection::OnGoAwayFrame(const QuicGoAwayFrame& frame) { | 752 bool QuicConnection::OnGoAwayFrame(const QuicGoAwayFrame& frame) { |
| 753 DCHECK(connected_); | 753 DCHECK(connected_); |
| 754 if (debug_visitor_.get() != NULL) { | 754 if (debug_visitor_.get() != nullptr) { |
| 755 debug_visitor_->OnGoAwayFrame(frame); | 755 debug_visitor_->OnGoAwayFrame(frame); |
| 756 } | 756 } |
| 757 DVLOG(1) << ENDPOINT << "Go away received with error " | 757 DVLOG(1) << ENDPOINT << "Go away received with error " |
| 758 << QuicUtils::ErrorToString(frame.error_code) | 758 << QuicUtils::ErrorToString(frame.error_code) |
| 759 << " and reason:" << frame.reason_phrase; | 759 << " and reason:" << frame.reason_phrase; |
| 760 last_goaway_frames_.push_back(frame); | 760 last_goaway_frames_.push_back(frame); |
| 761 return connected_; | 761 return connected_; |
| 762 } | 762 } |
| 763 | 763 |
| 764 bool QuicConnection::OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) { | 764 bool QuicConnection::OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) { |
| 765 DCHECK(connected_); | 765 DCHECK(connected_); |
| 766 if (debug_visitor_.get() != NULL) { | 766 if (debug_visitor_.get() != nullptr) { |
| 767 debug_visitor_->OnWindowUpdateFrame(frame); | 767 debug_visitor_->OnWindowUpdateFrame(frame); |
| 768 } | 768 } |
| 769 DVLOG(1) << ENDPOINT << "WindowUpdate received for stream: " | 769 DVLOG(1) << ENDPOINT << "WindowUpdate received for stream: " |
| 770 << frame.stream_id << " with byte offset: " << frame.byte_offset; | 770 << frame.stream_id << " with byte offset: " << frame.byte_offset; |
| 771 last_window_update_frames_.push_back(frame); | 771 last_window_update_frames_.push_back(frame); |
| 772 return connected_; | 772 return connected_; |
| 773 } | 773 } |
| 774 | 774 |
| 775 bool QuicConnection::OnBlockedFrame(const QuicBlockedFrame& frame) { | 775 bool QuicConnection::OnBlockedFrame(const QuicBlockedFrame& frame) { |
| 776 DCHECK(connected_); | 776 DCHECK(connected_); |
| 777 if (debug_visitor_.get() != NULL) { | 777 if (debug_visitor_.get() != nullptr) { |
| 778 debug_visitor_->OnBlockedFrame(frame); | 778 debug_visitor_->OnBlockedFrame(frame); |
| 779 } | 779 } |
| 780 DVLOG(1) << ENDPOINT << "Blocked frame received for stream: " | 780 DVLOG(1) << ENDPOINT << "Blocked frame received for stream: " |
| 781 << frame.stream_id; | 781 << frame.stream_id; |
| 782 last_blocked_frames_.push_back(frame); | 782 last_blocked_frames_.push_back(frame); |
| 783 return connected_; | 783 return connected_; |
| 784 } | 784 } |
| 785 | 785 |
| 786 void QuicConnection::OnPacketComplete() { | 786 void QuicConnection::OnPacketComplete() { |
| 787 // Don't do anything if this packet closed the connection. | 787 // Don't do anything if this packet closed the connection. |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 QuicStreamOffset offset, | 1018 QuicStreamOffset offset, |
| 1019 bool fin, | 1019 bool fin, |
| 1020 FecProtection fec_protection, | 1020 FecProtection fec_protection, |
| 1021 QuicAckNotifier::DelegateInterface* delegate) { | 1021 QuicAckNotifier::DelegateInterface* delegate) { |
| 1022 if (!fin && data.Empty()) { | 1022 if (!fin && data.Empty()) { |
| 1023 LOG(DFATAL) << "Attempt to send empty stream frame"; | 1023 LOG(DFATAL) << "Attempt to send empty stream frame"; |
| 1024 } | 1024 } |
| 1025 | 1025 |
| 1026 // This notifier will be owned by the AckNotifierManager (or deleted below if | 1026 // This notifier will be owned by the AckNotifierManager (or deleted below if |
| 1027 // no data or FIN was consumed). | 1027 // no data or FIN was consumed). |
| 1028 QuicAckNotifier* notifier = NULL; | 1028 QuicAckNotifier* notifier = nullptr; |
| 1029 if (delegate) { | 1029 if (delegate) { |
| 1030 notifier = new QuicAckNotifier(delegate); | 1030 notifier = new QuicAckNotifier(delegate); |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 // Opportunistically bundle an ack with every outgoing packet. | 1033 // Opportunistically bundle an ack with every outgoing packet. |
| 1034 // Particularly, we want to bundle with handshake packets since we don't know | 1034 // Particularly, we want to bundle with handshake packets since we don't know |
| 1035 // which decrypter will be used on an ack packet following a handshake | 1035 // which decrypter will be used on an ack packet following a handshake |
| 1036 // packet (a handshake packet from client to server could result in a REJ or a | 1036 // packet (a handshake packet from client to server could result in a REJ or a |
| 1037 // SHLO from the server, leading to two different decrypters at the server.) | 1037 // SHLO from the server, leading to two different decrypters at the server.) |
| 1038 // | 1038 // |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 stats_.max_packet_size = packet_generator_.max_packet_length(); | 1093 stats_.max_packet_size = packet_generator_.max_packet_length(); |
| 1094 return stats_; | 1094 return stats_; |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, | 1097 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, |
| 1098 const IPEndPoint& peer_address, | 1098 const IPEndPoint& peer_address, |
| 1099 const QuicEncryptedPacket& packet) { | 1099 const QuicEncryptedPacket& packet) { |
| 1100 if (!connected_) { | 1100 if (!connected_) { |
| 1101 return; | 1101 return; |
| 1102 } | 1102 } |
| 1103 if (debug_visitor_.get() != NULL) { | 1103 if (debug_visitor_.get() != nullptr) { |
| 1104 debug_visitor_->OnPacketReceived(self_address, peer_address, packet); | 1104 debug_visitor_->OnPacketReceived(self_address, peer_address, packet); |
| 1105 } | 1105 } |
| 1106 last_packet_revived_ = false; | 1106 last_packet_revived_ = false; |
| 1107 last_size_ = packet.length(); | 1107 last_size_ = packet.length(); |
| 1108 | 1108 |
| 1109 CheckForAddressMigration(self_address, peer_address); | 1109 CheckForAddressMigration(self_address, peer_address); |
| 1110 | 1110 |
| 1111 stats_.bytes_received += packet.length(); | 1111 stats_.bytes_received += packet.length(); |
| 1112 ++stats_.packets_received; | 1112 ++stats_.packets_received; |
| 1113 | 1113 |
| 1114 if (!framer_.ProcessPacket(packet)) { | 1114 if (!framer_.ProcessPacket(packet)) { |
| 1115 // If we are unable to decrypt this packet, it might be | 1115 // If we are unable to decrypt this packet, it might be |
| 1116 // because the CHLO or SHLO packet was lost. | 1116 // because the CHLO or SHLO packet was lost. |
| 1117 if (framer_.error() == QUIC_DECRYPTION_FAILURE) { | 1117 if (framer_.error() == QUIC_DECRYPTION_FAILURE) { |
| 1118 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && | 1118 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && |
| 1119 undecryptable_packets_.size() < kMaxUndecryptablePackets) { | 1119 undecryptable_packets_.size() < kMaxUndecryptablePackets) { |
| 1120 QueueUndecryptablePacket(packet); | 1120 QueueUndecryptablePacket(packet); |
| 1121 } else if (debug_visitor_.get() != NULL) { | 1121 } else if (debug_visitor_.get() != nullptr) { |
| 1122 debug_visitor_->OnUndecryptablePacket(); | 1122 debug_visitor_->OnUndecryptablePacket(); |
| 1123 } | 1123 } |
| 1124 } | 1124 } |
| 1125 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " | 1125 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " |
| 1126 << last_header_.packet_sequence_number; | 1126 << last_header_.packet_sequence_number; |
| 1127 return; | 1127 return; |
| 1128 } | 1128 } |
| 1129 | 1129 |
| 1130 ++stats_.packets_processed; | 1130 ++stats_.packets_processed; |
| 1131 MaybeProcessUndecryptablePackets(); | 1131 MaybeProcessUndecryptablePackets(); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 send_alarm_->Cancel(); | 1328 send_alarm_->Cancel(); |
| 1329 return true; | 1329 return true; |
| 1330 } | 1330 } |
| 1331 | 1331 |
| 1332 bool QuicConnection::WritePacket(QueuedPacket* packet) { | 1332 bool QuicConnection::WritePacket(QueuedPacket* packet) { |
| 1333 if (!WritePacketInner(packet)) { | 1333 if (!WritePacketInner(packet)) { |
| 1334 return false; | 1334 return false; |
| 1335 } | 1335 } |
| 1336 delete packet->serialized_packet.retransmittable_frames; | 1336 delete packet->serialized_packet.retransmittable_frames; |
| 1337 delete packet->serialized_packet.packet; | 1337 delete packet->serialized_packet.packet; |
| 1338 packet->serialized_packet.retransmittable_frames = NULL; | 1338 packet->serialized_packet.retransmittable_frames = nullptr; |
| 1339 packet->serialized_packet.packet = NULL; | 1339 packet->serialized_packet.packet = nullptr; |
| 1340 return true; | 1340 return true; |
| 1341 } | 1341 } |
| 1342 | 1342 |
| 1343 bool QuicConnection::WritePacketInner(QueuedPacket* packet) { | 1343 bool QuicConnection::WritePacketInner(QueuedPacket* packet) { |
| 1344 if (ShouldDiscardPacket(*packet)) { | 1344 if (ShouldDiscardPacket(*packet)) { |
| 1345 ++stats_.packets_discarded; | 1345 ++stats_.packets_discarded; |
| 1346 return true; | 1346 return true; |
| 1347 } | 1347 } |
| 1348 // Connection close packets are encrypted and saved, so don't exit early. | 1348 // Connection close packets are encrypted and saved, so don't exit early. |
| 1349 if (writer_->IsWriteBlocked() && !IsConnectionClose(*packet)) { | 1349 if (writer_->IsWriteBlocked() && !IsConnectionClose(*packet)) { |
| 1350 return false; | 1350 return false; |
| 1351 } | 1351 } |
| 1352 | 1352 |
| 1353 QuicPacketSequenceNumber sequence_number = | 1353 QuicPacketSequenceNumber sequence_number = |
| 1354 packet->serialized_packet.sequence_number; | 1354 packet->serialized_packet.sequence_number; |
| 1355 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number); | 1355 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number); |
| 1356 sequence_number_of_last_sent_packet_ = sequence_number; | 1356 sequence_number_of_last_sent_packet_ = sequence_number; |
| 1357 | 1357 |
| 1358 QuicEncryptedPacket* encrypted = framer_.EncryptPacket( | 1358 QuicEncryptedPacket* encrypted = framer_.EncryptPacket( |
| 1359 packet->encryption_level, | 1359 packet->encryption_level, |
| 1360 sequence_number, | 1360 sequence_number, |
| 1361 *packet->serialized_packet.packet); | 1361 *packet->serialized_packet.packet); |
| 1362 if (encrypted == NULL) { | 1362 if (encrypted == nullptr) { |
| 1363 LOG(DFATAL) << ENDPOINT << "Failed to encrypt packet number " | 1363 LOG(DFATAL) << ENDPOINT << "Failed to encrypt packet number " |
| 1364 << sequence_number; | 1364 << sequence_number; |
| 1365 // CloseConnection does not send close packet, so no infinite loop here. | 1365 // CloseConnection does not send close packet, so no infinite loop here. |
| 1366 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); | 1366 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); |
| 1367 return false; | 1367 return false; |
| 1368 } | 1368 } |
| 1369 | 1369 |
| 1370 // Connection close packets are eventually owned by TimeWaitListManager. | 1370 // Connection close packets are eventually owned by TimeWaitListManager. |
| 1371 // Others are deleted at the end of this call. | 1371 // Others are deleted at the end of this call. |
| 1372 scoped_ptr<QuicEncryptedPacket> encrypted_deleter; | 1372 scoped_ptr<QuicEncryptedPacket> encrypted_deleter; |
| 1373 if (IsConnectionClose(*packet)) { | 1373 if (IsConnectionClose(*packet)) { |
| 1374 DCHECK(connection_close_packet_.get() == NULL); | 1374 DCHECK(connection_close_packet_.get() == nullptr); |
| 1375 connection_close_packet_.reset(encrypted); | 1375 connection_close_packet_.reset(encrypted); |
| 1376 // This assures we won't try to write *forced* packets when blocked. | 1376 // This assures we won't try to write *forced* packets when blocked. |
| 1377 // Return true to stop processing. | 1377 // Return true to stop processing. |
| 1378 if (writer_->IsWriteBlocked()) { | 1378 if (writer_->IsWriteBlocked()) { |
| 1379 visitor_->OnWriteBlocked(); | 1379 visitor_->OnWriteBlocked(); |
| 1380 return true; | 1380 return true; |
| 1381 } | 1381 } |
| 1382 } else { | 1382 } else { |
| 1383 encrypted_deleter.reset(encrypted); | 1383 encrypted_deleter.reset(encrypted); |
| 1384 } | 1384 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1401 << QuicUtils::StringToHexASCIIDump( | 1401 << QuicUtils::StringToHexASCIIDump( |
| 1402 packet->serialized_packet.packet->AsStringPiece()); | 1402 packet->serialized_packet.packet->AsStringPiece()); |
| 1403 | 1403 |
| 1404 WriteResult result = writer_->WritePacket(encrypted->data(), | 1404 WriteResult result = writer_->WritePacket(encrypted->data(), |
| 1405 encrypted->length(), | 1405 encrypted->length(), |
| 1406 self_address().address(), | 1406 self_address().address(), |
| 1407 peer_address()); | 1407 peer_address()); |
| 1408 if (result.error_code == ERR_IO_PENDING) { | 1408 if (result.error_code == ERR_IO_PENDING) { |
| 1409 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); | 1409 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); |
| 1410 } | 1410 } |
| 1411 if (debug_visitor_.get() != NULL) { | 1411 if (debug_visitor_.get() != nullptr) { |
| 1412 // Pass the write result to the visitor. | 1412 // Pass the write result to the visitor. |
| 1413 debug_visitor_->OnPacketSent(sequence_number, | 1413 debug_visitor_->OnPacketSent(sequence_number, |
| 1414 packet->original_sequence_number, | 1414 packet->original_sequence_number, |
| 1415 packet->encryption_level, | 1415 packet->encryption_level, |
| 1416 packet->transmission_type, | 1416 packet->transmission_type, |
| 1417 *encrypted, | 1417 *encrypted, |
| 1418 result); | 1418 result); |
| 1419 } | 1419 } |
| 1420 | 1420 |
| 1421 if (result.status == WRITE_STATUS_BLOCKED) { | 1421 if (result.status == WRITE_STATUS_BLOCKED) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1523 packet_generator_.OnCongestionWindowChange(congestion_window); | 1523 packet_generator_.OnCongestionWindowChange(congestion_window); |
| 1524 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); | 1524 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); |
| 1525 } | 1525 } |
| 1526 | 1526 |
| 1527 void QuicConnection::OnHandshakeComplete() { | 1527 void QuicConnection::OnHandshakeComplete() { |
| 1528 sent_packet_manager_.SetHandshakeConfirmed(); | 1528 sent_packet_manager_.SetHandshakeConfirmed(); |
| 1529 } | 1529 } |
| 1530 | 1530 |
| 1531 void QuicConnection::SendOrQueuePacket(QueuedPacket packet) { | 1531 void QuicConnection::SendOrQueuePacket(QueuedPacket packet) { |
| 1532 // The caller of this function is responsible for checking CanWrite(). | 1532 // The caller of this function is responsible for checking CanWrite(). |
| 1533 if (packet.serialized_packet.packet == NULL) { | 1533 if (packet.serialized_packet.packet == nullptr) { |
| 1534 LOG(DFATAL) << "NULL packet passed in to SendOrQueuePacket"; | 1534 LOG(DFATAL) |
| 1535 << "packet.serialized_packet.packet == nullptr in to SendOrQueuePacket"; |
| 1535 return; | 1536 return; |
| 1536 } | 1537 } |
| 1537 | 1538 |
| 1538 sent_entropy_manager_.RecordPacketEntropyHash( | 1539 sent_entropy_manager_.RecordPacketEntropyHash( |
| 1539 packet.serialized_packet.sequence_number, | 1540 packet.serialized_packet.sequence_number, |
| 1540 packet.serialized_packet.entropy_hash); | 1541 packet.serialized_packet.entropy_hash); |
| 1541 LOG_IF(DFATAL, !queued_packets_.empty() && !writer_->IsWriteBlocked()) | 1542 LOG_IF(DFATAL, !queued_packets_.empty() && !writer_->IsWriteBlocked()) |
| 1542 << "Packets should only be left queued if we're write blocked."; | 1543 << "Packets should only be left queued if we're write blocked."; |
| 1543 if (!WritePacket(&packet)) { | 1544 if (!WritePacket(&packet)) { |
| 1544 queued_packets_.push_back(packet); | 1545 queued_packets_.push_back(packet); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 DVLOG(1) << ENDPOINT << "Processed undecryptable packet!"; | 1664 DVLOG(1) << ENDPOINT << "Processed undecryptable packet!"; |
| 1664 ++stats_.packets_processed; | 1665 ++stats_.packets_processed; |
| 1665 delete packet; | 1666 delete packet; |
| 1666 undecryptable_packets_.pop_front(); | 1667 undecryptable_packets_.pop_front(); |
| 1667 } | 1668 } |
| 1668 | 1669 |
| 1669 // Once forward secure encryption is in use, there will be no | 1670 // Once forward secure encryption is in use, there will be no |
| 1670 // new keys installed and hence any undecryptable packets will | 1671 // new keys installed and hence any undecryptable packets will |
| 1671 // never be able to be decrypted. | 1672 // never be able to be decrypted. |
| 1672 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE) { | 1673 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE) { |
| 1673 if (debug_visitor_.get() != NULL) { | 1674 if (debug_visitor_.get() != nullptr) { |
| 1674 // TODO(rtenneti): perhaps more efficient to pass the number of | 1675 // TODO(rtenneti): perhaps more efficient to pass the number of |
| 1675 // undecryptable packets as the argument to OnUndecryptablePacket so that | 1676 // undecryptable packets as the argument to OnUndecryptablePacket so that |
| 1676 // we just need to call OnUndecryptablePacket once? | 1677 // we just need to call OnUndecryptablePacket once? |
| 1677 for (size_t i = 0; i < undecryptable_packets_.size(); ++i) { | 1678 for (size_t i = 0; i < undecryptable_packets_.size(); ++i) { |
| 1678 debug_visitor_->OnUndecryptablePacket(); | 1679 debug_visitor_->OnUndecryptablePacket(); |
| 1679 } | 1680 } |
| 1680 } | 1681 } |
| 1681 STLDeleteElements(&undecryptable_packets_); | 1682 STLDeleteElements(&undecryptable_packets_); |
| 1682 } | 1683 } |
| 1683 } | 1684 } |
| 1684 | 1685 |
| 1685 void QuicConnection::MaybeProcessRevivedPacket() { | 1686 void QuicConnection::MaybeProcessRevivedPacket() { |
| 1686 QuicFecGroup* group = GetFecGroup(); | 1687 QuicFecGroup* group = GetFecGroup(); |
| 1687 if (!connected_ || group == NULL || !group->CanRevive()) { | 1688 if (!connected_ || group == nullptr || !group->CanRevive()) { |
| 1688 return; | 1689 return; |
| 1689 } | 1690 } |
| 1690 QuicPacketHeader revived_header; | 1691 QuicPacketHeader revived_header; |
| 1691 char revived_payload[kMaxPacketSize]; | 1692 char revived_payload[kMaxPacketSize]; |
| 1692 size_t len = group->Revive(&revived_header, revived_payload, kMaxPacketSize); | 1693 size_t len = group->Revive(&revived_header, revived_payload, kMaxPacketSize); |
| 1693 revived_header.public_header.connection_id = connection_id_; | 1694 revived_header.public_header.connection_id = connection_id_; |
| 1694 revived_header.public_header.connection_id_length = | 1695 revived_header.public_header.connection_id_length = |
| 1695 last_header_.public_header.connection_id_length; | 1696 last_header_.public_header.connection_id_length; |
| 1696 revived_header.public_header.version_flag = false; | 1697 revived_header.public_header.version_flag = false; |
| 1697 revived_header.public_header.reset_flag = false; | 1698 revived_header.public_header.reset_flag = false; |
| 1698 revived_header.public_header.sequence_number_length = | 1699 revived_header.public_header.sequence_number_length = |
| 1699 last_header_.public_header.sequence_number_length; | 1700 last_header_.public_header.sequence_number_length; |
| 1700 revived_header.fec_flag = false; | 1701 revived_header.fec_flag = false; |
| 1701 revived_header.is_in_fec_group = NOT_IN_FEC_GROUP; | 1702 revived_header.is_in_fec_group = NOT_IN_FEC_GROUP; |
| 1702 revived_header.fec_group = 0; | 1703 revived_header.fec_group = 0; |
| 1703 group_map_.erase(last_header_.fec_group); | 1704 group_map_.erase(last_header_.fec_group); |
| 1704 last_decrypted_packet_level_ = group->effective_encryption_level(); | 1705 last_decrypted_packet_level_ = group->effective_encryption_level(); |
| 1705 DCHECK_LT(last_decrypted_packet_level_, NUM_ENCRYPTION_LEVELS); | 1706 DCHECK_LT(last_decrypted_packet_level_, NUM_ENCRYPTION_LEVELS); |
| 1706 delete group; | 1707 delete group; |
| 1707 | 1708 |
| 1708 last_packet_revived_ = true; | 1709 last_packet_revived_ = true; |
| 1709 if (debug_visitor_.get() != NULL) { | 1710 if (debug_visitor_.get() != nullptr) { |
| 1710 debug_visitor_->OnRevivedPacket(revived_header, | 1711 debug_visitor_->OnRevivedPacket(revived_header, |
| 1711 StringPiece(revived_payload, len)); | 1712 StringPiece(revived_payload, len)); |
| 1712 } | 1713 } |
| 1713 | 1714 |
| 1714 ++stats_.packets_revived; | 1715 ++stats_.packets_revived; |
| 1715 framer_.ProcessRevivedPacket(&revived_header, | 1716 framer_.ProcessRevivedPacket(&revived_header, |
| 1716 StringPiece(revived_payload, len)); | 1717 StringPiece(revived_payload, len)); |
| 1717 } | 1718 } |
| 1718 | 1719 |
| 1719 QuicFecGroup* QuicConnection::GetFecGroup() { | 1720 QuicFecGroup* QuicConnection::GetFecGroup() { |
| 1720 QuicFecGroupNumber fec_group_num = last_header_.fec_group; | 1721 QuicFecGroupNumber fec_group_num = last_header_.fec_group; |
| 1721 if (fec_group_num == 0) { | 1722 if (fec_group_num == 0) { |
| 1722 return NULL; | 1723 return nullptr; |
| 1723 } | 1724 } |
| 1724 if (group_map_.count(fec_group_num) == 0) { | 1725 if (group_map_.count(fec_group_num) == 0) { |
| 1725 if (group_map_.size() >= kMaxFecGroups) { // Too many groups | 1726 if (group_map_.size() >= kMaxFecGroups) { // Too many groups |
| 1726 if (fec_group_num < group_map_.begin()->first) { | 1727 if (fec_group_num < group_map_.begin()->first) { |
| 1727 // The group being requested is a group we've seen before and deleted. | 1728 // The group being requested is a group we've seen before and deleted. |
| 1728 // Don't recreate it. | 1729 // Don't recreate it. |
| 1729 return NULL; | 1730 return nullptr; |
| 1730 } | 1731 } |
| 1731 // Clear the lowest group number. | 1732 // Clear the lowest group number. |
| 1732 delete group_map_.begin()->second; | 1733 delete group_map_.begin()->second; |
| 1733 group_map_.erase(group_map_.begin()); | 1734 group_map_.erase(group_map_.begin()); |
| 1734 } | 1735 } |
| 1735 group_map_[fec_group_num] = new QuicFecGroup(); | 1736 group_map_[fec_group_num] = new QuicFecGroup(); |
| 1736 } | 1737 } |
| 1737 return group_map_[fec_group_num]; | 1738 return group_map_[fec_group_num]; |
| 1738 } | 1739 } |
| 1739 | 1740 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1767 packet_generator_.FlushAllQueuedFrames(); | 1768 packet_generator_.FlushAllQueuedFrames(); |
| 1768 } | 1769 } |
| 1769 | 1770 |
| 1770 void QuicConnection::CloseConnection(QuicErrorCode error, bool from_peer) { | 1771 void QuicConnection::CloseConnection(QuicErrorCode error, bool from_peer) { |
| 1771 if (!connected_) { | 1772 if (!connected_) { |
| 1772 DLOG(DFATAL) << "Error: attempt to close an already closed connection" | 1773 DLOG(DFATAL) << "Error: attempt to close an already closed connection" |
| 1773 << base::debug::StackTrace().ToString(); | 1774 << base::debug::StackTrace().ToString(); |
| 1774 return; | 1775 return; |
| 1775 } | 1776 } |
| 1776 connected_ = false; | 1777 connected_ = false; |
| 1777 if (debug_visitor_.get() != NULL) { | 1778 if (debug_visitor_.get() != nullptr) { |
| 1778 debug_visitor_->OnConnectionClosed(error, from_peer); | 1779 debug_visitor_->OnConnectionClosed(error, from_peer); |
| 1779 } | 1780 } |
| 1780 visitor_->OnConnectionClosed(error, from_peer); | 1781 visitor_->OnConnectionClosed(error, from_peer); |
| 1781 // Cancel the alarms so they don't trigger any action now that the | 1782 // Cancel the alarms so they don't trigger any action now that the |
| 1782 // connection is closed. | 1783 // connection is closed. |
| 1783 ack_alarm_->Cancel(); | 1784 ack_alarm_->Cancel(); |
| 1784 ping_alarm_->Cancel(); | 1785 ping_alarm_->Cancel(); |
| 1785 resume_writes_alarm_->Cancel(); | 1786 resume_writes_alarm_->Cancel(); |
| 1786 retransmission_alarm_->Cancel(); | 1787 retransmission_alarm_->Cancel(); |
| 1787 send_alarm_->Cancel(); | 1788 send_alarm_->Cancel(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1969 } | 1970 } |
| 1970 QuicTime::Delta ping_timeout = QuicTime::Delta::FromSeconds(kPingTimeoutSecs); | 1971 QuicTime::Delta ping_timeout = QuicTime::Delta::FromSeconds(kPingTimeoutSecs); |
| 1971 ping_alarm_->Update(clock_->ApproximateNow().Add(ping_timeout), | 1972 ping_alarm_->Update(clock_->ApproximateNow().Add(ping_timeout), |
| 1972 QuicTime::Delta::FromSeconds(1)); | 1973 QuicTime::Delta::FromSeconds(1)); |
| 1973 } | 1974 } |
| 1974 | 1975 |
| 1975 QuicConnection::ScopedPacketBundler::ScopedPacketBundler( | 1976 QuicConnection::ScopedPacketBundler::ScopedPacketBundler( |
| 1976 QuicConnection* connection, | 1977 QuicConnection* connection, |
| 1977 AckBundling send_ack) | 1978 AckBundling send_ack) |
| 1978 : connection_(connection), | 1979 : connection_(connection), |
| 1979 already_in_batch_mode_(connection != NULL && | 1980 already_in_batch_mode_(connection != nullptr && |
| 1980 connection->packet_generator_.InBatchMode()) { | 1981 connection->packet_generator_.InBatchMode()) { |
| 1981 if (connection_ == NULL) { | 1982 if (connection_ == nullptr) { |
| 1982 return; | 1983 return; |
| 1983 } | 1984 } |
| 1984 // Move generator into batch mode. If caller wants us to include an ack, | 1985 // Move generator into batch mode. If caller wants us to include an ack, |
| 1985 // check the delayed-ack timer to see if there's ack info to be sent. | 1986 // check the delayed-ack timer to see if there's ack info to be sent. |
| 1986 if (!already_in_batch_mode_) { | 1987 if (!already_in_batch_mode_) { |
| 1987 DVLOG(1) << "Entering Batch Mode."; | 1988 DVLOG(1) << "Entering Batch Mode."; |
| 1988 connection_->packet_generator_.StartBatchOperations(); | 1989 connection_->packet_generator_.StartBatchOperations(); |
| 1989 } | 1990 } |
| 1990 // Bundle an ack if the alarm is set or with every second packet if we need to | 1991 // Bundle an ack if the alarm is set or with every second packet if we need to |
| 1991 // raise the peer's least unacked. | 1992 // raise the peer's least unacked. |
| 1992 bool ack_pending = | 1993 bool ack_pending = |
| 1993 connection_->ack_alarm_->IsSet() || connection_->stop_waiting_count_ > 1; | 1994 connection_->ack_alarm_->IsSet() || connection_->stop_waiting_count_ > 1; |
| 1994 if (send_ack == SEND_ACK || (send_ack == BUNDLE_PENDING_ACK && ack_pending)) { | 1995 if (send_ack == SEND_ACK || (send_ack == BUNDLE_PENDING_ACK && ack_pending)) { |
| 1995 DVLOG(1) << "Bundling ack with outgoing packet."; | 1996 DVLOG(1) << "Bundling ack with outgoing packet."; |
| 1996 connection_->SendAck(); | 1997 connection_->SendAck(); |
| 1997 } | 1998 } |
| 1998 } | 1999 } |
| 1999 | 2000 |
| 2000 QuicConnection::ScopedPacketBundler::~ScopedPacketBundler() { | 2001 QuicConnection::ScopedPacketBundler::~ScopedPacketBundler() { |
| 2001 if (connection_ == NULL) { | 2002 if (connection_ == nullptr) { |
| 2002 return; | 2003 return; |
| 2003 } | 2004 } |
| 2004 // If we changed the generator's batch state, restore original batch state. | 2005 // If we changed the generator's batch state, restore original batch state. |
| 2005 if (!already_in_batch_mode_) { | 2006 if (!already_in_batch_mode_) { |
| 2006 DVLOG(1) << "Leaving Batch Mode."; | 2007 DVLOG(1) << "Leaving Batch Mode."; |
| 2007 connection_->packet_generator_.FinishBatchOperations(); | 2008 connection_->packet_generator_.FinishBatchOperations(); |
| 2008 } | 2009 } |
| 2009 DCHECK_EQ(already_in_batch_mode_, | 2010 DCHECK_EQ(already_in_batch_mode_, |
| 2010 connection_->packet_generator_.InBatchMode()); | 2011 connection_->packet_generator_.InBatchMode()); |
| 2011 } | 2012 } |
| 2012 | 2013 |
| 2013 HasRetransmittableData QuicConnection::IsRetransmittable( | 2014 HasRetransmittableData QuicConnection::IsRetransmittable( |
| 2014 const QueuedPacket& packet) { | 2015 const QueuedPacket& packet) { |
| 2015 // Retransmitted packets retransmittable frames are owned by the unacked | 2016 // Retransmitted packets retransmittable frames are owned by the unacked |
| 2016 // packet map, but are not present in the serialized packet. | 2017 // packet map, but are not present in the serialized packet. |
| 2017 if (packet.transmission_type != NOT_RETRANSMISSION || | 2018 if (packet.transmission_type != NOT_RETRANSMISSION || |
| 2018 packet.serialized_packet.retransmittable_frames != NULL) { | 2019 packet.serialized_packet.retransmittable_frames != nullptr) { |
| 2019 return HAS_RETRANSMITTABLE_DATA; | 2020 return HAS_RETRANSMITTABLE_DATA; |
| 2020 } else { | 2021 } else { |
| 2021 return NO_RETRANSMITTABLE_DATA; | 2022 return NO_RETRANSMITTABLE_DATA; |
| 2022 } | 2023 } |
| 2023 } | 2024 } |
| 2024 | 2025 |
| 2025 bool QuicConnection::IsConnectionClose( | 2026 bool QuicConnection::IsConnectionClose( |
| 2026 QueuedPacket packet) { | 2027 QueuedPacket packet) { |
| 2027 RetransmittableFrames* retransmittable_frames = | 2028 RetransmittableFrames* retransmittable_frames = |
| 2028 packet.serialized_packet.retransmittable_frames; | 2029 packet.serialized_packet.retransmittable_frames; |
| 2029 if (!retransmittable_frames) { | 2030 if (!retransmittable_frames) { |
| 2030 return false; | 2031 return false; |
| 2031 } | 2032 } |
| 2032 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { | 2033 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { |
| 2033 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { | 2034 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { |
| 2034 return true; | 2035 return true; |
| 2035 } | 2036 } |
| 2036 } | 2037 } |
| 2037 return false; | 2038 return false; |
| 2038 } | 2039 } |
| 2039 | 2040 |
| 2040 } // namespace net | 2041 } // namespace net |
| OLD | NEW |