| 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_framer.h" | 5 #include "net/quic/quic_framer.h" |
| 6 | 6 |
| 7 #include "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
| 8 #include "net/quic/crypto/quic_decrypter.h" | 8 #include "net/quic/crypto/quic_decrypter.h" |
| 9 #include "net/quic/crypto/quic_encrypter.h" | 9 #include "net/quic/crypto/quic_encrypter.h" |
| 10 #include "net/quic/quic_data_reader.h" | 10 #include "net/quic/quic_data_reader.h" |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 return false; | 418 return false; |
| 419 } | 419 } |
| 420 if (!ProcessReceivedInfo(&frame->received_info)) { | 420 if (!ProcessReceivedInfo(&frame->received_info)) { |
| 421 return false; | 421 return false; |
| 422 } | 422 } |
| 423 visitor_->OnAckFrame(*frame); | 423 visitor_->OnAckFrame(*frame); |
| 424 return true; | 424 return true; |
| 425 } | 425 } |
| 426 | 426 |
| 427 bool QuicFramer::ProcessReceivedInfo(ReceivedPacketInfo* received_info) { | 427 bool QuicFramer::ProcessReceivedInfo(ReceivedPacketInfo* received_info) { |
| 428 if (!reader_->ReadUInt48(&received_info->largest_received)) { | 428 if (!reader_->ReadUInt48(&received_info->largest_observed)) { |
| 429 set_detailed_error("Unable to read largest received."); | 429 set_detailed_error("Unable to read largest observed."); |
| 430 return false; | 430 return false; |
| 431 } | 431 } |
| 432 | 432 |
| 433 uint8 num_missing_packets; | 433 uint8 num_missing_packets; |
| 434 if (!reader_->ReadBytes(&num_missing_packets, 1)) { | 434 if (!reader_->ReadBytes(&num_missing_packets, 1)) { |
| 435 set_detailed_error("Unable to read num missing packets."); | 435 set_detailed_error("Unable to read num missing packets."); |
| 436 return false; | 436 return false; |
| 437 } | 437 } |
| 438 | 438 |
| 439 for (int i = 0; i < num_missing_packets; ++i) { | 439 for (int i = 0; i < num_missing_packets; ++i) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 len += 1; // fin | 664 len += 1; // fin |
| 665 len += 8; // offset | 665 len += 8; // offset |
| 666 len += 2; // space for the 16 bit length | 666 len += 2; // space for the 16 bit length |
| 667 len += frame.stream_frame->data.size(); | 667 len += frame.stream_frame->data.size(); |
| 668 break; | 668 break; |
| 669 case PDU_FRAME: | 669 case PDU_FRAME: |
| 670 DLOG(INFO) << "PDU_FRAME not yet supported"; | 670 DLOG(INFO) << "PDU_FRAME not yet supported"; |
| 671 break; // Need to support this eventually :> | 671 break; // Need to support this eventually :> |
| 672 case ACK_FRAME: { | 672 case ACK_FRAME: { |
| 673 const QuicAckFrame& ack = *frame.ack_frame; | 673 const QuicAckFrame& ack = *frame.ack_frame; |
| 674 len += 6; // largest received packet sequence number | 674 len += 6; // largest observed packet sequence number |
| 675 len += 1; // num missing packets | 675 len += 1; // num missing packets |
| 676 len += 6 * ack.received_info.missing_packets.size(); | 676 len += 6 * ack.received_info.missing_packets.size(); |
| 677 len += 6; // least packet sequence number awaiting an ack | 677 len += 6; // least packet sequence number awaiting an ack |
| 678 break; | 678 break; |
| 679 } | 679 } |
| 680 case CONGESTION_FEEDBACK_FRAME: { | 680 case CONGESTION_FEEDBACK_FRAME: { |
| 681 const QuicCongestionFeedbackFrame& congestion_feedback = | 681 const QuicCongestionFeedbackFrame& congestion_feedback = |
| 682 *frame.congestion_feedback_frame; | 682 *frame.congestion_feedback_frame; |
| 683 len += 1; // congestion feedback type | 683 len += 1; // congestion feedback type |
| 684 | 684 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 if (!writer->WriteUInt16(frame.data.size())) { | 746 if (!writer->WriteUInt16(frame.data.size())) { |
| 747 return false; | 747 return false; |
| 748 } | 748 } |
| 749 if (!writer->WriteBytes(frame.data.data(), | 749 if (!writer->WriteBytes(frame.data.data(), |
| 750 frame.data.size())) { | 750 frame.data.size())) { |
| 751 return false; | 751 return false; |
| 752 } | 752 } |
| 753 return true; | 753 return true; |
| 754 } | 754 } |
| 755 | 755 |
| 756 // TODO(alyssar): revisit the complexity here to rch's satisfaction | 756 QuicPacketSequenceNumber QuicFramer::CalculateLargestObserved( |
| 757 QuicPacketSequenceNumber QuicFramer::CalculateLargestReceived( | |
| 758 const SequenceSet& missing_packets, | 757 const SequenceSet& missing_packets, |
| 759 SequenceSet::const_iterator largest_written) { | 758 SequenceSet::const_iterator largest_written) { |
| 760 SequenceSet::const_iterator it = largest_written; | 759 SequenceSet::const_iterator it = largest_written; |
| 761 QuicPacketSequenceNumber previous_missing = *it; | 760 QuicPacketSequenceNumber previous_missing = *it; |
| 762 ++it; | 761 ++it; |
| 763 | 762 |
| 764 // See if the next thing is a gap in the missing packets: if it's a | 763 // See if the next thing is a gap in the missing packets: if it's a |
| 765 // non-missing packet we can return it. | 764 // non-missing packet we can return it. |
| 766 if (it != missing_packets.end() && previous_missing + 1 != *it) { | 765 if (it != missing_packets.end() && previous_missing + 1 != *it) { |
| 767 return *it - 1; | 766 return *it - 1; |
| 768 } | 767 } |
| 769 | 768 |
| 770 // If we've hit the end of the list, and we're not missing any packets, try | 769 // Otherwise return the largest missing packet, as indirectly observed. |
| 771 // finding a gap between the largest written and the beginning of the set. | 770 return *largest_written; |
| 772 it = largest_written++; | |
| 773 previous_missing = *it; | |
| 774 do { | |
| 775 --it; | |
| 776 if (previous_missing - 1 != *it) { | |
| 777 return previous_missing - 1; | |
| 778 } | |
| 779 previous_missing = *it; | |
| 780 } while (it != missing_packets.begin()); | |
| 781 | |
| 782 // The missing packets are entirely contiguous. Return the value of the first | |
| 783 // missing packet - 1, as that must have been seen. | |
| 784 return *missing_packets.begin() - 1; | |
| 785 } | 771 } |
| 786 | 772 |
| 787 // TODO(ianswett): Use varints or another more compact approach for all deltas. | 773 // TODO(ianswett): Use varints or another more compact approach for all deltas. |
| 788 bool QuicFramer::AppendAckFramePayload( | 774 bool QuicFramer::AppendAckFramePayload( |
| 789 const QuicAckFrame& frame, | 775 const QuicAckFrame& frame, |
| 790 QuicDataWriter* writer) { | 776 QuicDataWriter* writer) { |
| 791 if (!writer->WriteUInt48(frame.sent_info.least_unacked)) { | 777 if (!writer->WriteUInt48(frame.sent_info.least_unacked)) { |
| 792 return false; | 778 return false; |
| 793 } | 779 } |
| 794 | 780 |
| 795 size_t largest_received_offset = writer->length(); | 781 size_t largest_observed_offset = writer->length(); |
| 796 if (!writer->WriteUInt48(frame.received_info.largest_received)) { | 782 if (!writer->WriteUInt48(frame.received_info.largest_observed)) { |
| 797 return false; | 783 return false; |
| 798 } | 784 } |
| 799 | 785 |
| 800 // We don't check for overflowing uint8 here, because we only can fit 192 acks | 786 // We don't check for overflowing uint8 here, because we only can fit 192 acks |
| 801 // per packet, so if we overflow we will be truncated. | 787 // per packet, so if we overflow we will be truncated. |
| 802 uint8 num_missing_packets = frame.received_info.missing_packets.size(); | 788 uint8 num_missing_packets = frame.received_info.missing_packets.size(); |
| 803 size_t num_missing_packets_offset = writer->length(); | 789 size_t num_missing_packets_offset = writer->length(); |
| 804 if (!writer->WriteBytes(&num_missing_packets, 1)) { | 790 if (!writer->WriteBytes(&num_missing_packets, 1)) { |
| 805 return false; | 791 return false; |
| 806 } | 792 } |
| 807 | 793 |
| 808 SequenceSet::const_iterator it = frame.received_info.missing_packets.begin(); | 794 SequenceSet::const_iterator it = frame.received_info.missing_packets.begin(); |
| 809 int num_missing_packets_written = 0; | 795 int num_missing_packets_written = 0; |
| 810 for (; it != frame.received_info.missing_packets.end(); ++it) { | 796 for (; it != frame.received_info.missing_packets.end(); ++it) { |
| 811 if (!writer->WriteUInt48(*it)) { | 797 if (!writer->WriteUInt48(*it)) { |
| 812 // We are truncating. Overwrite largest_received. | 798 // We are truncating. Overwrite largest_observed. |
| 813 QuicPacketSequenceNumber largest_received = | 799 QuicPacketSequenceNumber largest_observed = |
| 814 CalculateLargestReceived(frame.received_info.missing_packets, --it); | 800 CalculateLargestObserved(frame.received_info.missing_packets, --it); |
| 815 writer->WriteUInt48ToOffset(largest_received, largest_received_offset); | 801 writer->WriteUInt48ToOffset(largest_observed, largest_observed_offset); |
| 816 writer->WriteUInt8ToOffset(num_missing_packets_written, | 802 writer->WriteUInt8ToOffset(num_missing_packets_written, |
| 817 num_missing_packets_offset); | 803 num_missing_packets_offset); |
| 818 return true; | 804 return true; |
| 819 } | 805 } |
| 820 ++num_missing_packets_written; | 806 ++num_missing_packets_written; |
| 821 DCHECK_GE(numeric_limits<uint8>::max(), num_missing_packets_written); | 807 DCHECK_GE(numeric_limits<uint8>::max(), num_missing_packets_written); |
| 822 } | 808 } |
| 823 | 809 |
| 824 return true; | 810 return true; |
| 825 } | 811 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 | 934 |
| 949 bool QuicFramer::RaiseError(QuicErrorCode error) { | 935 bool QuicFramer::RaiseError(QuicErrorCode error) { |
| 950 DLOG(INFO) << detailed_error_; | 936 DLOG(INFO) << detailed_error_; |
| 951 set_error(error); | 937 set_error(error); |
| 952 visitor_->OnError(this); | 938 visitor_->OnError(this); |
| 953 reader_.reset(NULL); | 939 reader_.reset(NULL); |
| 954 return false; | 940 return false; |
| 955 } | 941 } |
| 956 | 942 |
| 957 } // namespace net | 943 } // namespace net |
| OLD | NEW |