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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 } | 1352 } |
1353 ack_frame->missing_packets.Add(last_packet_number - range_length, | 1353 ack_frame->missing_packets.Add(last_packet_number - range_length, |
1354 last_packet_number + 1); | 1354 last_packet_number + 1); |
1355 // Subtract an extra 1 to ensure ranges are represented efficiently and | 1355 // Subtract an extra 1 to ensure ranges are represented efficiently and |
1356 // can't overlap by 1 packet number. This allows a missing_delta of 0 | 1356 // can't overlap by 1 packet number. This allows a missing_delta of 0 |
1357 // to represent an adjacent nack range. | 1357 // to represent an adjacent nack range. |
1358 last_packet_number -= (range_length + 1); | 1358 last_packet_number -= (range_length + 1); |
1359 } | 1359 } |
1360 | 1360 |
1361 // Parse the revived packets list. | 1361 // Parse the revived packets list. |
| 1362 // TODO(ianswett): Change the ack frame so it only expresses one revived. |
1362 uint8 num_revived_packets; | 1363 uint8 num_revived_packets; |
1363 if (!reader->ReadBytes(&num_revived_packets, 1)) { | 1364 if (!reader->ReadBytes(&num_revived_packets, 1)) { |
1364 set_detailed_error("Unable to read num revived packets."); | 1365 set_detailed_error("Unable to read num revived packets."); |
1365 return false; | 1366 return false; |
1366 } | 1367 } |
1367 | 1368 |
1368 for (size_t i = 0; i < num_revived_packets; ++i) { | 1369 for (size_t i = 0; i < num_revived_packets; ++i) { |
1369 QuicPacketNumber revived_packet = 0; | 1370 QuicPacketNumber revived_packet = 0; |
1370 if (!reader->ReadBytes(&revived_packet, | 1371 if (!reader->ReadBytes(&revived_packet, |
1371 largest_observed_packet_number_length)) { | 1372 largest_observed_packet_number_length)) { |
1372 set_detailed_error("Unable to read revived packet."); | 1373 set_detailed_error("Unable to read revived packet."); |
1373 return false; | 1374 return false; |
1374 } | 1375 } |
1375 | 1376 ack_frame->latest_revived_packet = revived_packet; |
1376 ack_frame->revived_packets.insert(revived_packet); | |
1377 } | 1377 } |
1378 | 1378 |
1379 return true; | 1379 return true; |
1380 } | 1380 } |
1381 | 1381 |
1382 bool QuicFramer::ProcessTimestampsInAckFrame(QuicDataReader* reader, | 1382 bool QuicFramer::ProcessTimestampsInAckFrame(QuicDataReader* reader, |
1383 QuicAckFrame* ack_frame) { | 1383 QuicAckFrame* ack_frame) { |
1384 if (ack_frame->is_truncated) { | 1384 if (ack_frame->is_truncated) { |
1385 return true; | 1385 return true; |
1386 } | 1386 } |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 QuicPacketNumberLength largest_observed_length = | 1706 QuicPacketNumberLength largest_observed_length = |
1707 GetMinSequenceNumberLength(ack.largest_observed); | 1707 GetMinSequenceNumberLength(ack.largest_observed); |
1708 QuicPacketNumberLength missing_packet_number_length = | 1708 QuicPacketNumberLength missing_packet_number_length = |
1709 GetMinSequenceNumberLength(ack_info.max_delta); | 1709 GetMinSequenceNumberLength(ack_info.max_delta); |
1710 | 1710 |
1711 size_t ack_size = GetMinAckFrameSize(largest_observed_length); | 1711 size_t ack_size = GetMinAckFrameSize(largest_observed_length); |
1712 if (!ack_info.nack_ranges.empty()) { | 1712 if (!ack_info.nack_ranges.empty()) { |
1713 ack_size += kNumberOfNackRangesSize + kNumberOfRevivedPacketsSize; | 1713 ack_size += kNumberOfNackRangesSize + kNumberOfRevivedPacketsSize; |
1714 ack_size += min(ack_info.nack_ranges.size(), kMaxNackRanges) * | 1714 ack_size += min(ack_info.nack_ranges.size(), kMaxNackRanges) * |
1715 (missing_packet_number_length + PACKET_1BYTE_PACKET_NUMBER); | 1715 (missing_packet_number_length + PACKET_1BYTE_PACKET_NUMBER); |
1716 ack_size += min(ack.revived_packets.size(), | 1716 if (ack.latest_revived_packet != 0) { |
1717 kMaxRevivedPackets) * largest_observed_length; | 1717 ack_size += largest_observed_length; |
| 1718 } |
1718 } | 1719 } |
1719 | 1720 |
1720 // In version 23, if the ack will be truncated due to too many nack ranges, | 1721 // In version 23, if the ack will be truncated due to too many nack ranges, |
1721 // then do not include the number of timestamps (1 byte). | 1722 // then do not include the number of timestamps (1 byte). |
1722 if (ack_info.nack_ranges.size() <= kMaxNackRanges) { | 1723 if (ack_info.nack_ranges.size() <= kMaxNackRanges) { |
1723 // 1 byte for the number of timestamps. | 1724 // 1 byte for the number of timestamps. |
1724 ack_size += 1; | 1725 ack_size += 1; |
1725 if (ack.received_packet_times.size() > 0) { | 1726 if (ack.received_packet_times.size() > 0) { |
1726 // 1 byte for packet number, 4 bytes for timestamp for the first | 1727 // 1 byte for packet number, 4 bytes for timestamp for the first |
1727 // packet. | 1728 // packet. |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 return false; | 2000 return false; |
2000 } | 2001 } |
2001 // Subtract 1 so a missing_delta of 0 means an adjacent range. | 2002 // Subtract 1 so a missing_delta of 0 means an adjacent range. |
2002 last_sequence_written = ack_iter->first - 1; | 2003 last_sequence_written = ack_iter->first - 1; |
2003 ++num_ranges_written; | 2004 ++num_ranges_written; |
2004 } | 2005 } |
2005 DCHECK_EQ(num_missing_ranges, num_ranges_written); | 2006 DCHECK_EQ(num_missing_ranges, num_ranges_written); |
2006 | 2007 |
2007 // Append revived packets. | 2008 // Append revived packets. |
2008 // If not all the revived packets fit, only mention the ones that do. | 2009 // If not all the revived packets fit, only mention the ones that do. |
2009 uint8 num_revived_packets = | 2010 uint8 num_revived_packets = frame.latest_revived_packet == 0 ? 0 : 1; |
2010 static_cast<uint8>(min(frame.revived_packets.size(), kMaxRevivedPackets)); | 2011 if (((writer->capacity() - writer->length()) / |
2011 num_revived_packets = static_cast<uint8>(min( | 2012 largest_observed_length) == 0) { |
2012 static_cast<size_t>(num_revived_packets), | 2013 num_revived_packets = 0; |
2013 (writer->capacity() - writer->length()) / largest_observed_length)); | 2014 } |
2014 if (!writer->WriteBytes(&num_revived_packets, 1)) { | 2015 if (!writer->WriteBytes(&num_revived_packets, 1)) { |
2015 return false; | 2016 return false; |
2016 } | 2017 } |
2017 | 2018 |
2018 PacketNumberSet::const_iterator iter = frame.revived_packets.begin(); | 2019 if (num_revived_packets > 0) { |
2019 for (int i = 0; i < num_revived_packets; ++i, ++iter) { | 2020 LOG_IF(DFATAL, |
2020 LOG_IF(DFATAL, !frame.missing_packets.Contains(*iter)); | 2021 !frame.missing_packets.Contains(frame.latest_revived_packet)); |
2021 if (!AppendPacketSequenceNumber(largest_observed_length, | 2022 if (!AppendPacketSequenceNumber(largest_observed_length, |
2022 *iter, writer)) { | 2023 frame.latest_revived_packet, writer)) { |
2023 return false; | 2024 return false; |
2024 } | 2025 } |
2025 } | 2026 } |
2026 | 2027 |
2027 return true; | 2028 return true; |
2028 } | 2029 } |
2029 | 2030 |
2030 bool QuicFramer::AppendTimestampToAckFrame(const QuicAckFrame& frame, | 2031 bool QuicFramer::AppendTimestampToAckFrame(const QuicAckFrame& frame, |
2031 QuicDataWriter* writer) { | 2032 QuicDataWriter* writer) { |
2032 DCHECK_GE(numeric_limits<uint8>::max(), frame.received_packet_times.size()); | 2033 DCHECK_GE(numeric_limits<uint8>::max(), frame.received_packet_times.size()); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2192 | 2193 |
2193 bool QuicFramer::RaiseError(QuicErrorCode error) { | 2194 bool QuicFramer::RaiseError(QuicErrorCode error) { |
2194 DVLOG(1) << "Error: " << QuicUtils::ErrorToString(error) | 2195 DVLOG(1) << "Error: " << QuicUtils::ErrorToString(error) |
2195 << " detail: " << detailed_error_; | 2196 << " detail: " << detailed_error_; |
2196 set_error(error); | 2197 set_error(error); |
2197 visitor_->OnError(this); | 2198 visitor_->OnError(this); |
2198 return false; | 2199 return false; |
2199 } | 2200 } |
2200 | 2201 |
2201 } // namespace net | 2202 } // namespace net |
OLD | NEW |