| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 helper->GetClock()->ApproximateNow(), | 172 helper->GetClock()->ApproximateNow(), |
| 173 is_server), | 173 is_server), |
| 174 helper_(helper), | 174 helper_(helper), |
| 175 writer_(writer), | 175 writer_(writer), |
| 176 encryption_level_(ENCRYPTION_NONE), | 176 encryption_level_(ENCRYPTION_NONE), |
| 177 clock_(helper->GetClock()), | 177 clock_(helper->GetClock()), |
| 178 random_generator_(helper->GetRandomGenerator()), | 178 random_generator_(helper->GetRandomGenerator()), |
| 179 guid_(guid), | 179 guid_(guid), |
| 180 peer_address_(address), | 180 peer_address_(address), |
| 181 largest_seen_packet_with_ack_(0), | 181 largest_seen_packet_with_ack_(0), |
| 182 largest_seen_packet_with_stop_waiting_(0), |
| 182 pending_version_negotiation_packet_(false), | 183 pending_version_negotiation_packet_(false), |
| 183 received_packet_manager_(kTCP), | 184 received_packet_manager_(kTCP), |
| 184 ack_queued_(false), | 185 ack_queued_(false), |
| 185 stop_waiting_count_(0), | 186 stop_waiting_count_(0), |
| 186 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), | 187 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), |
| 187 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), | 188 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), |
| 188 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 189 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
| 189 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 190 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
| 190 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), | 191 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), |
| 191 debug_visitor_(NULL), | 192 debug_visitor_(NULL), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 if (!connected_ || framer->error() == QUIC_DECRYPTION_FAILURE) { | 254 if (!connected_ || framer->error() == QUIC_DECRYPTION_FAILURE) { |
| 254 return; | 255 return; |
| 255 } | 256 } |
| 256 SendConnectionCloseWithDetails(framer->error(), framer->detailed_error()); | 257 SendConnectionCloseWithDetails(framer->error(), framer->detailed_error()); |
| 257 } | 258 } |
| 258 | 259 |
| 259 void QuicConnection::OnPacket() { | 260 void QuicConnection::OnPacket() { |
| 260 DCHECK(last_stream_frames_.empty() && | 261 DCHECK(last_stream_frames_.empty() && |
| 261 last_goaway_frames_.empty() && | 262 last_goaway_frames_.empty() && |
| 262 last_window_update_frames_.empty() && | 263 last_window_update_frames_.empty() && |
| 264 last_blocked_frames_.empty() && |
| 263 last_rst_frames_.empty() && | 265 last_rst_frames_.empty() && |
| 264 last_ack_frames_.empty() && | 266 last_ack_frames_.empty() && |
| 265 last_congestion_frames_.empty()); | 267 last_congestion_frames_.empty() && |
| 268 last_stop_waiting_frames_.empty()); |
| 266 } | 269 } |
| 267 | 270 |
| 268 void QuicConnection::OnPublicResetPacket( | 271 void QuicConnection::OnPublicResetPacket( |
| 269 const QuicPublicResetPacket& packet) { | 272 const QuicPublicResetPacket& packet) { |
| 270 if (debug_visitor_) { | 273 if (debug_visitor_) { |
| 271 debug_visitor_->OnPublicResetPacket(packet); | 274 debug_visitor_->OnPublicResetPacket(packet); |
| 272 } | 275 } |
| 273 CloseConnection(QUIC_PUBLIC_RESET, true); | 276 CloseConnection(QUIC_PUBLIC_RESET, true); |
| 274 } | 277 } |
| 275 | 278 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 SendConnectionClose(QUIC_INVALID_ACK_DATA); | 489 SendConnectionClose(QUIC_INVALID_ACK_DATA); |
| 487 return false; | 490 return false; |
| 488 } | 491 } |
| 489 | 492 |
| 490 last_ack_frames_.push_back(incoming_ack); | 493 last_ack_frames_.push_back(incoming_ack); |
| 491 return connected_; | 494 return connected_; |
| 492 } | 495 } |
| 493 | 496 |
| 494 void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) { | 497 void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) { |
| 495 largest_seen_packet_with_ack_ = last_header_.packet_sequence_number; | 498 largest_seen_packet_with_ack_ = last_header_.packet_sequence_number; |
| 496 | |
| 497 received_packet_manager_.UpdatePacketInformationReceivedByPeer( | 499 received_packet_manager_.UpdatePacketInformationReceivedByPeer( |
| 498 incoming_ack.received_info); | 500 incoming_ack.received_info); |
| 499 received_packet_manager_.UpdatePacketInformationSentByPeer( | 501 if (version() <= QUIC_VERSION_15) { |
| 500 incoming_ack.sent_info); | 502 ProcessStopWaitingFrame(incoming_ack.sent_info); |
| 501 // Possibly close any FecGroups which are now irrelevant. | 503 } |
| 502 CloseFecGroupsBefore(incoming_ack.sent_info.least_unacked + 1); | |
| 503 | 504 |
| 504 sent_entropy_manager_.ClearEntropyBefore( | 505 sent_entropy_manager_.ClearEntropyBefore( |
| 505 received_packet_manager_.least_packet_awaited_by_peer() - 1); | 506 received_packet_manager_.least_packet_awaited_by_peer() - 1); |
| 506 | 507 |
| 507 bool reset_retransmission_alarm = | 508 bool reset_retransmission_alarm = |
| 508 sent_packet_manager_.OnIncomingAck(incoming_ack.received_info, | 509 sent_packet_manager_.OnIncomingAck(incoming_ack.received_info, |
| 509 time_of_last_received_packet_); | 510 time_of_last_received_packet_); |
| 510 if (sent_packet_manager_.HasPendingRetransmissions()) { | 511 if (sent_packet_manager_.HasPendingRetransmissions()) { |
| 511 WriteIfNotBlocked(); | 512 WriteIfNotBlocked(); |
| 512 } | 513 } |
| 513 | 514 |
| 514 if (reset_retransmission_alarm) { | 515 if (reset_retransmission_alarm) { |
| 515 retransmission_alarm_->Cancel(); | 516 retransmission_alarm_->Cancel(); |
| 516 QuicTime retransmission_time = | 517 QuicTime retransmission_time = |
| 517 sent_packet_manager_.GetRetransmissionTime(); | 518 sent_packet_manager_.GetRetransmissionTime(); |
| 518 if (retransmission_time != QuicTime::Zero()) { | 519 if (retransmission_time != QuicTime::Zero()) { |
| 519 retransmission_alarm_->Set(retransmission_time); | 520 retransmission_alarm_->Set(retransmission_time); |
| 520 } | 521 } |
| 521 } | 522 } |
| 522 } | 523 } |
| 523 | 524 |
| 525 void QuicConnection::ProcessStopWaitingFrame( |
| 526 const QuicStopWaitingFrame& stop_waiting) { |
| 527 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number; |
| 528 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); |
| 529 // Possibly close any FecGroups which are now irrelevant. |
| 530 CloseFecGroupsBefore(stop_waiting.least_unacked + 1); |
| 531 } |
| 532 |
| 524 bool QuicConnection::OnCongestionFeedbackFrame( | 533 bool QuicConnection::OnCongestionFeedbackFrame( |
| 525 const QuicCongestionFeedbackFrame& feedback) { | 534 const QuicCongestionFeedbackFrame& feedback) { |
| 526 DCHECK(connected_); | 535 DCHECK(connected_); |
| 527 if (debug_visitor_) { | 536 if (debug_visitor_) { |
| 528 debug_visitor_->OnCongestionFeedbackFrame(feedback); | 537 debug_visitor_->OnCongestionFeedbackFrame(feedback); |
| 529 } | 538 } |
| 530 last_congestion_frames_.push_back(feedback); | 539 last_congestion_frames_.push_back(feedback); |
| 531 return connected_; | 540 return connected_; |
| 532 } | 541 } |
| 533 | 542 |
| 543 bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) { |
| 544 DCHECK(connected_); |
| 545 |
| 546 if (last_header_.packet_sequence_number <= |
| 547 largest_seen_packet_with_stop_waiting_) { |
| 548 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring"; |
| 549 return true; |
| 550 } |
| 551 |
| 552 if (!ValidateStopWaitingFrame(frame)) { |
| 553 SendConnectionClose(QUIC_INVALID_STOP_WAITING_DATA); |
| 554 return false; |
| 555 } |
| 556 |
| 557 if (debug_visitor_) { |
| 558 debug_visitor_->OnStopWaitingFrame(frame); |
| 559 } |
| 560 |
| 561 last_stop_waiting_frames_.push_back(frame); |
| 562 return connected_; |
| 563 } |
| 564 |
| 534 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { | 565 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { |
| 535 if (incoming_ack.received_info.largest_observed > | 566 if (incoming_ack.received_info.largest_observed > |
| 536 packet_creator_.sequence_number()) { | 567 packet_creator_.sequence_number()) { |
| 537 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:" | 568 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:" |
| 538 << incoming_ack.received_info.largest_observed << " vs " | 569 << incoming_ack.received_info.largest_observed << " vs " |
| 539 << packet_creator_.sequence_number(); | 570 << packet_creator_.sequence_number(); |
| 540 // We got an error for data we have not sent. Error out. | 571 // We got an error for data we have not sent. Error out. |
| 541 return false; | 572 return false; |
| 542 } | 573 } |
| 543 | 574 |
| 544 if (incoming_ack.received_info.largest_observed < | 575 if (incoming_ack.received_info.largest_observed < |
| 545 received_packet_manager_.peer_largest_observed_packet()) { | 576 received_packet_manager_.peer_largest_observed_packet()) { |
| 546 DLOG(ERROR) << ENDPOINT << "Peer's largest_observed packet decreased:" | 577 DLOG(ERROR) << ENDPOINT << "Peer's largest_observed packet decreased:" |
| 547 << incoming_ack.received_info.largest_observed << " vs " | 578 << incoming_ack.received_info.largest_observed << " vs " |
| 548 << received_packet_manager_.peer_largest_observed_packet(); | 579 << received_packet_manager_.peer_largest_observed_packet(); |
| 549 // A new ack has a diminished largest_observed value. Error out. | 580 // A new ack has a diminished largest_observed value. Error out. |
| 550 // If this was an old packet, we wouldn't even have checked. | 581 // If this was an old packet, we wouldn't even have checked. |
| 551 return false; | 582 return false; |
| 552 } | 583 } |
| 553 | 584 |
| 554 if (incoming_ack.sent_info.least_unacked < | 585 if (version() <= QUIC_VERSION_15) { |
| 555 received_packet_manager_.peer_least_packet_awaiting_ack()) { | 586 if (!ValidateStopWaitingFrame(incoming_ack.sent_info)) { |
| 556 DLOG(ERROR) << ENDPOINT << "Peer's sent low least_unacked: " | 587 return false; |
| 557 << incoming_ack.sent_info.least_unacked << " vs " | 588 } |
| 558 << received_packet_manager_.peer_least_packet_awaiting_ack(); | |
| 559 // We never process old ack frames, so this number should only increase. | |
| 560 return false; | |
| 561 } | |
| 562 | |
| 563 if (incoming_ack.sent_info.least_unacked > | |
| 564 last_header_.packet_sequence_number) { | |
| 565 DLOG(ERROR) << ENDPOINT << "Peer sent least_unacked:" | |
| 566 << incoming_ack.sent_info.least_unacked | |
| 567 << " greater than the enclosing packet sequence number:" | |
| 568 << last_header_.packet_sequence_number; | |
| 569 return false; | |
| 570 } | 589 } |
| 571 | 590 |
| 572 if (!incoming_ack.received_info.missing_packets.empty() && | 591 if (!incoming_ack.received_info.missing_packets.empty() && |
| 573 *incoming_ack.received_info.missing_packets.rbegin() > | 592 *incoming_ack.received_info.missing_packets.rbegin() > |
| 574 incoming_ack.received_info.largest_observed) { | 593 incoming_ack.received_info.largest_observed) { |
| 575 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " | 594 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " |
| 576 << *incoming_ack.received_info.missing_packets.rbegin() | 595 << *incoming_ack.received_info.missing_packets.rbegin() |
| 577 << " which is greater than largest observed: " | 596 << " which is greater than largest observed: " |
| 578 << incoming_ack.received_info.largest_observed; | 597 << incoming_ack.received_info.largest_observed; |
| 579 return false; | 598 return false; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 602 iter != incoming_ack.received_info.revived_packets.end(); ++iter) { | 621 iter != incoming_ack.received_info.revived_packets.end(); ++iter) { |
| 603 if (!ContainsKey(incoming_ack.received_info.missing_packets, *iter)) { | 622 if (!ContainsKey(incoming_ack.received_info.missing_packets, *iter)) { |
| 604 DLOG(ERROR) << ENDPOINT | 623 DLOG(ERROR) << ENDPOINT |
| 605 << "Peer specified revived packet which was not missing."; | 624 << "Peer specified revived packet which was not missing."; |
| 606 return false; | 625 return false; |
| 607 } | 626 } |
| 608 } | 627 } |
| 609 return true; | 628 return true; |
| 610 } | 629 } |
| 611 | 630 |
| 631 bool QuicConnection::ValidateStopWaitingFrame( |
| 632 const QuicStopWaitingFrame& stop_waiting) { |
| 633 if (stop_waiting.least_unacked < |
| 634 received_packet_manager_.peer_least_packet_awaiting_ack()) { |
| 635 DLOG(ERROR) << ENDPOINT << "Peer's sent low least_unacked: " |
| 636 << stop_waiting.least_unacked << " vs " |
| 637 << received_packet_manager_.peer_least_packet_awaiting_ack(); |
| 638 // We never process old ack frames, so this number should only increase. |
| 639 return false; |
| 640 } |
| 641 |
| 642 if (stop_waiting.least_unacked > |
| 643 last_header_.packet_sequence_number) { |
| 644 DLOG(ERROR) << ENDPOINT << "Peer sent least_unacked:" |
| 645 << stop_waiting.least_unacked |
| 646 << " greater than the enclosing packet sequence number:" |
| 647 << last_header_.packet_sequence_number; |
| 648 return false; |
| 649 } |
| 650 |
| 651 return true; |
| 652 } |
| 653 |
| 612 void QuicConnection::OnFecData(const QuicFecData& fec) { | 654 void QuicConnection::OnFecData(const QuicFecData& fec) { |
| 613 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group); | 655 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group); |
| 614 DCHECK_NE(0u, last_header_.fec_group); | 656 DCHECK_NE(0u, last_header_.fec_group); |
| 615 QuicFecGroup* group = GetFecGroup(); | 657 QuicFecGroup* group = GetFecGroup(); |
| 616 if (group != NULL) { | 658 if (group != NULL) { |
| 617 group->UpdateFec(last_header_.packet_sequence_number, fec); | 659 group->UpdateFec(last_header_.packet_sequence_number, fec); |
| 618 } | 660 } |
| 619 } | 661 } |
| 620 | 662 |
| 621 bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { | 663 bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 // Don't do anything if this packet closed the connection. | 713 // Don't do anything if this packet closed the connection. |
| 672 if (!connected_) { | 714 if (!connected_) { |
| 673 ClearLastFrames(); | 715 ClearLastFrames(); |
| 674 return; | 716 return; |
| 675 } | 717 } |
| 676 | 718 |
| 677 DVLOG(1) << ENDPOINT << (last_packet_revived_ ? "Revived" : "Got") | 719 DVLOG(1) << ENDPOINT << (last_packet_revived_ ? "Revived" : "Got") |
| 678 << " packet " << last_header_.packet_sequence_number | 720 << " packet " << last_header_.packet_sequence_number |
| 679 << " with " << last_ack_frames_.size() << " acks, " | 721 << " with " << last_ack_frames_.size() << " acks, " |
| 680 << last_congestion_frames_.size() << " congestions, " | 722 << last_congestion_frames_.size() << " congestions, " |
| 723 << last_stop_waiting_frames_.size() << " stop_waiting, " |
| 681 << last_goaway_frames_.size() << " goaways, " | 724 << last_goaway_frames_.size() << " goaways, " |
| 682 << last_window_update_frames_.size() << " window updates, " | 725 << last_window_update_frames_.size() << " window updates, " |
| 726 << last_blocked_frames_.size() << " blocked, " |
| 683 << last_rst_frames_.size() << " rsts, " | 727 << last_rst_frames_.size() << " rsts, " |
| 684 << last_close_frames_.size() << " closes, " | 728 << last_close_frames_.size() << " closes, " |
| 685 << last_stream_frames_.size() | 729 << last_stream_frames_.size() |
| 686 << " stream frames for " << last_header_.public_header.guid; | 730 << " stream frames for " << last_header_.public_header.guid; |
| 687 | 731 |
| 688 MaybeQueueAck(); | 732 MaybeQueueAck(); |
| 689 | 733 |
| 690 // Discard the packet if the visitor fails to process the stream frames. | 734 // Discard the packet if the visitor fails to process the stream frames. |
| 691 if (!last_stream_frames_.empty() && | 735 if (!last_stream_frames_.empty() && |
| 692 !visitor_->OnStreamFrames(last_stream_frames_)) { | 736 !visitor_->OnStreamFrames(last_stream_frames_)) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 719 for (size_t i = 0; i < last_rst_frames_.size(); ++i) { | 763 for (size_t i = 0; i < last_rst_frames_.size(); ++i) { |
| 720 visitor_->OnRstStream(last_rst_frames_[i]); | 764 visitor_->OnRstStream(last_rst_frames_[i]); |
| 721 } | 765 } |
| 722 for (size_t i = 0; i < last_ack_frames_.size(); ++i) { | 766 for (size_t i = 0; i < last_ack_frames_.size(); ++i) { |
| 723 ProcessAckFrame(last_ack_frames_[i]); | 767 ProcessAckFrame(last_ack_frames_[i]); |
| 724 } | 768 } |
| 725 for (size_t i = 0; i < last_congestion_frames_.size(); ++i) { | 769 for (size_t i = 0; i < last_congestion_frames_.size(); ++i) { |
| 726 sent_packet_manager_.OnIncomingQuicCongestionFeedbackFrame( | 770 sent_packet_manager_.OnIncomingQuicCongestionFeedbackFrame( |
| 727 last_congestion_frames_[i], time_of_last_received_packet_); | 771 last_congestion_frames_[i], time_of_last_received_packet_); |
| 728 } | 772 } |
| 773 for (size_t i = 0; i < last_stop_waiting_frames_.size(); ++i) { |
| 774 ProcessStopWaitingFrame(last_stop_waiting_frames_[i]); |
| 775 } |
| 729 if (!last_close_frames_.empty()) { | 776 if (!last_close_frames_.empty()) { |
| 730 CloseConnection(last_close_frames_[0].error_code, true); | 777 CloseConnection(last_close_frames_[0].error_code, true); |
| 731 DCHECK(!connected_); | 778 DCHECK(!connected_); |
| 732 } | 779 } |
| 733 | 780 |
| 734 // If there are new missing packets to report, send an ack immediately. | 781 // If there are new missing packets to report, send an ack immediately. |
| 735 if (received_packet_manager_.HasNewMissingPackets()) { | 782 if (received_packet_manager_.HasNewMissingPackets()) { |
| 736 ack_queued_ = true; | 783 ack_queued_ = true; |
| 737 ack_alarm_->Cancel(); | 784 ack_alarm_->Cancel(); |
| 738 } | 785 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 759 | 806 |
| 760 if (ack_queued_) { | 807 if (ack_queued_) { |
| 761 ack_alarm_->Cancel(); | 808 ack_alarm_->Cancel(); |
| 762 } | 809 } |
| 763 } | 810 } |
| 764 | 811 |
| 765 void QuicConnection::ClearLastFrames() { | 812 void QuicConnection::ClearLastFrames() { |
| 766 last_stream_frames_.clear(); | 813 last_stream_frames_.clear(); |
| 767 last_goaway_frames_.clear(); | 814 last_goaway_frames_.clear(); |
| 768 last_window_update_frames_.clear(); | 815 last_window_update_frames_.clear(); |
| 816 last_blocked_frames_.clear(); |
| 769 last_rst_frames_.clear(); | 817 last_rst_frames_.clear(); |
| 770 last_ack_frames_.clear(); | 818 last_ack_frames_.clear(); |
| 819 last_stop_waiting_frames_.clear(); |
| 771 last_congestion_frames_.clear(); | 820 last_congestion_frames_.clear(); |
| 772 } | 821 } |
| 773 | 822 |
| 774 QuicAckFrame* QuicConnection::CreateAckFrame() { | 823 QuicAckFrame* QuicConnection::CreateAckFrame() { |
| 775 QuicAckFrame* outgoing_ack = new QuicAckFrame(); | 824 QuicAckFrame* outgoing_ack = new QuicAckFrame(); |
| 776 received_packet_manager_.UpdateReceivedPacketInfo( | 825 received_packet_manager_.UpdateReceivedPacketInfo( |
| 777 &(outgoing_ack->received_info), clock_->ApproximateNow()); | 826 &(outgoing_ack->received_info), clock_->ApproximateNow()); |
| 778 UpdateSentPacketInfo(&(outgoing_ack->sent_info)); | 827 UpdateStopWaiting(&(outgoing_ack->sent_info)); |
| 779 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack; | 828 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack; |
| 780 return outgoing_ack; | 829 return outgoing_ack; |
| 781 } | 830 } |
| 782 | 831 |
| 783 QuicCongestionFeedbackFrame* QuicConnection::CreateFeedbackFrame() { | 832 QuicCongestionFeedbackFrame* QuicConnection::CreateFeedbackFrame() { |
| 784 return new QuicCongestionFeedbackFrame(outgoing_congestion_feedback_); | 833 return new QuicCongestionFeedbackFrame(outgoing_congestion_feedback_); |
| 785 } | 834 } |
| 786 | 835 |
| 836 QuicStopWaitingFrame* QuicConnection::CreateStopWaitingFrame() { |
| 837 QuicStopWaitingFrame stop_waiting; |
| 838 UpdateStopWaiting(&stop_waiting); |
| 839 return new QuicStopWaitingFrame(stop_waiting); |
| 840 } |
| 841 |
| 787 bool QuicConnection::ShouldLastPacketInstigateAck() const { | 842 bool QuicConnection::ShouldLastPacketInstigateAck() const { |
| 788 if (!last_stream_frames_.empty() || | 843 if (!last_stream_frames_.empty() || |
| 789 !last_goaway_frames_.empty() || | 844 !last_goaway_frames_.empty() || |
| 790 !last_rst_frames_.empty()) { | 845 !last_rst_frames_.empty() || |
| 846 !last_window_update_frames_.empty() || |
| 847 !last_blocked_frames_.empty()) { |
| 791 return true; | 848 return true; |
| 792 } | 849 } |
| 793 | 850 |
| 794 if (!last_ack_frames_.empty() && | 851 if (!last_ack_frames_.empty() && |
| 795 last_ack_frames_.back().received_info.is_truncated) { | 852 last_ack_frames_.back().received_info.is_truncated) { |
| 796 return true; | 853 return true; |
| 797 } | 854 } |
| 798 | |
| 799 return false; | 855 return false; |
| 800 } | 856 } |
| 801 | 857 |
| 802 void QuicConnection::UpdateStopWaitingCount() { | 858 void QuicConnection::UpdateStopWaitingCount() { |
| 803 if (last_ack_frames_.empty()) { | 859 if (last_ack_frames_.empty()) { |
| 804 return; | 860 return; |
| 805 } | 861 } |
| 806 | 862 |
| 807 // If the peer is still waiting for a packet that we are no longer planning to | 863 // If the peer is still waiting for a packet that we are no longer planning to |
| 808 // send, send an ack to raise the high water mark. | 864 // send, send an ack to raise the high water mark. |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 return true; | 1246 return true; |
| 1191 } | 1247 } |
| 1192 } else { | 1248 } else { |
| 1193 encrypted_deleter.reset(encrypted); | 1249 encrypted_deleter.reset(encrypted); |
| 1194 } | 1250 } |
| 1195 | 1251 |
| 1196 LOG_IF(DFATAL, encrypted->length() > options()->max_packet_length) | 1252 LOG_IF(DFATAL, encrypted->length() > options()->max_packet_length) |
| 1197 << "Writing an encrypted packet larger than max_packet_length:" | 1253 << "Writing an encrypted packet larger than max_packet_length:" |
| 1198 << options()->max_packet_length << " encrypted length: " | 1254 << options()->max_packet_length << " encrypted length: " |
| 1199 << encrypted->length(); | 1255 << encrypted->length(); |
| 1200 DVLOG(1) << ENDPOINT << "Sending packet number " << sequence_number | 1256 DVLOG(1) << ENDPOINT << "Sending packet " << sequence_number |
| 1201 << " : " << (packet.packet->is_fec_packet() ? "FEC " : | 1257 << " : " << (packet.packet->is_fec_packet() ? "FEC " : |
| 1202 (packet.retransmittable == HAS_RETRANSMITTABLE_DATA | 1258 (packet.retransmittable == HAS_RETRANSMITTABLE_DATA |
| 1203 ? "data bearing " : " ack only ")) | 1259 ? "data bearing " : " ack only ")) |
| 1204 << ", encryption level: " | 1260 << ", encryption level: " |
| 1205 << QuicUtils::EncryptionLevelToString(packet.encryption_level) | 1261 << QuicUtils::EncryptionLevelToString(packet.encryption_level) |
| 1206 << ", length:" << packet.packet->length() << ", encrypted length:" | 1262 << ", length:" << packet.packet->length() << ", encrypted length:" |
| 1207 << encrypted->length(); | 1263 << encrypted->length(); |
| 1208 DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl | 1264 DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl |
| 1209 << QuicUtils::StringToHexASCIIDump(packet.packet->AsStringPiece()); | 1265 << QuicUtils::StringToHexASCIIDump(packet.packet->AsStringPiece()); |
| 1210 | 1266 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 if ((queued_packet.type == CONNECTION_CLOSE || queued_packets_.empty()) && | 1430 if ((queued_packet.type == CONNECTION_CLOSE || queued_packets_.empty()) && |
| 1375 WritePacket(queued_packet)) { | 1431 WritePacket(queued_packet)) { |
| 1376 delete packet.packet; | 1432 delete packet.packet; |
| 1377 return true; | 1433 return true; |
| 1378 } | 1434 } |
| 1379 queued_packet.type = QUEUED; | 1435 queued_packet.type = QUEUED; |
| 1380 queued_packets_.push_back(queued_packet); | 1436 queued_packets_.push_back(queued_packet); |
| 1381 return false; | 1437 return false; |
| 1382 } | 1438 } |
| 1383 | 1439 |
| 1384 void QuicConnection::UpdateSentPacketInfo(SentPacketInfo* sent_info) { | 1440 void QuicConnection::UpdateStopWaiting(QuicStopWaitingFrame* stop_waiting) { |
| 1385 sent_info->least_unacked = GetLeastUnacked(); | 1441 stop_waiting->least_unacked = GetLeastUnacked(); |
| 1386 sent_info->entropy_hash = sent_entropy_manager_.EntropyHash( | 1442 stop_waiting->entropy_hash = sent_entropy_manager_.EntropyHash( |
| 1387 sent_info->least_unacked - 1); | 1443 stop_waiting->least_unacked - 1); |
| 1388 } | 1444 } |
| 1389 | 1445 |
| 1390 void QuicConnection::SendAck() { | 1446 void QuicConnection::SendAck() { |
| 1391 ack_alarm_->Cancel(); | 1447 ack_alarm_->Cancel(); |
| 1392 stop_waiting_count_ = 0; | 1448 stop_waiting_count_ = 0; |
| 1393 // TODO(rch): delay this until the CreateFeedbackFrame | 1449 // TODO(rch): delay this until the CreateFeedbackFrame |
| 1394 // method is invoked. This requires changes SetShouldSendAck | 1450 // method is invoked. This requires changes SetShouldSendAck |
| 1395 // to be a no-arg method, and re-jiggering its implementation. | 1451 // to be a no-arg method, and re-jiggering its implementation. |
| 1396 bool send_feedback = false; | 1452 bool send_feedback = false; |
| 1397 if (received_packet_manager_.GenerateCongestionFeedback( | 1453 if (received_packet_manager_.GenerateCongestionFeedback( |
| 1398 &outgoing_congestion_feedback_)) { | 1454 &outgoing_congestion_feedback_)) { |
| 1399 DVLOG(1) << ENDPOINT << "Sending feedback: " | 1455 DVLOG(1) << ENDPOINT << "Sending feedback: " |
| 1400 << outgoing_congestion_feedback_; | 1456 << outgoing_congestion_feedback_; |
| 1401 send_feedback = true; | 1457 send_feedback = true; |
| 1402 } | 1458 } |
| 1403 | 1459 |
| 1404 packet_generator_.SetShouldSendAck(send_feedback); | 1460 packet_generator_.SetShouldSendAck(send_feedback, |
| 1461 version() > QUIC_VERSION_15); |
| 1405 } | 1462 } |
| 1406 | 1463 |
| 1407 void QuicConnection::OnRetransmissionTimeout() { | 1464 void QuicConnection::OnRetransmissionTimeout() { |
| 1408 if (!sent_packet_manager_.HasUnackedPackets()) { | 1465 if (!sent_packet_manager_.HasUnackedPackets()) { |
| 1409 return; | 1466 return; |
| 1410 } | 1467 } |
| 1411 | 1468 |
| 1412 sent_packet_manager_.OnRetransmissionTimeout(); | 1469 sent_packet_manager_.OnRetransmissionTimeout(); |
| 1413 | 1470 |
| 1414 WriteIfNotBlocked(); | 1471 WriteIfNotBlocked(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1553 ScopedPacketBundler ack_bundler(this, SEND_ACK); | 1610 ScopedPacketBundler ack_bundler(this, SEND_ACK); |
| 1554 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); | 1611 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); |
| 1555 frame->error_code = error; | 1612 frame->error_code = error; |
| 1556 frame->error_details = details; | 1613 frame->error_details = details; |
| 1557 packet_generator_.AddControlFrame(QuicFrame(frame)); | 1614 packet_generator_.AddControlFrame(QuicFrame(frame)); |
| 1558 Flush(); | 1615 Flush(); |
| 1559 } | 1616 } |
| 1560 | 1617 |
| 1561 void QuicConnection::CloseConnection(QuicErrorCode error, bool from_peer) { | 1618 void QuicConnection::CloseConnection(QuicErrorCode error, bool from_peer) { |
| 1562 DCHECK(connected_); | 1619 DCHECK(connected_); |
| 1620 if (!connected_) { |
| 1621 return; |
| 1622 } |
| 1563 connected_ = false; | 1623 connected_ = false; |
| 1564 visitor_->OnConnectionClosed(error, from_peer); | 1624 visitor_->OnConnectionClosed(error, from_peer); |
| 1565 // Cancel the alarms so they don't trigger any action now that the | 1625 // Cancel the alarms so they don't trigger any action now that the |
| 1566 // connection is closed. | 1626 // connection is closed. |
| 1567 ack_alarm_->Cancel(); | 1627 ack_alarm_->Cancel(); |
| 1568 resume_writes_alarm_->Cancel(); | 1628 resume_writes_alarm_->Cancel(); |
| 1569 retransmission_alarm_->Cancel(); | 1629 retransmission_alarm_->Cancel(); |
| 1570 send_alarm_->Cancel(); | 1630 send_alarm_->Cancel(); |
| 1571 timeout_alarm_->Cancel(); | 1631 timeout_alarm_->Cancel(); |
| 1572 } | 1632 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1722 // If we changed the generator's batch state, restore original batch state. | 1782 // If we changed the generator's batch state, restore original batch state. |
| 1723 if (!already_in_batch_mode_) { | 1783 if (!already_in_batch_mode_) { |
| 1724 DVLOG(1) << "Leaving Batch Mode."; | 1784 DVLOG(1) << "Leaving Batch Mode."; |
| 1725 connection_->packet_generator_.FinishBatchOperations(); | 1785 connection_->packet_generator_.FinishBatchOperations(); |
| 1726 } | 1786 } |
| 1727 DCHECK_EQ(already_in_batch_mode_, | 1787 DCHECK_EQ(already_in_batch_mode_, |
| 1728 connection_->packet_generator_.InBatchMode()); | 1788 connection_->packet_generator_.InBatchMode()); |
| 1729 } | 1789 } |
| 1730 | 1790 |
| 1731 } // namespace net | 1791 } // namespace net |
| OLD | NEW |