Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(606)

Side by Side Diff: net/quic/quic_framer.cc

Issue 424003002: Inline the members of QUIC's ReceivedPacketInfo into QuicAckFrame now (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_FixRate_congestion_type_71746617
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_framer.h ('k') | net/quic/quic_framer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/containers/hash_tables.h" 7 #include "base/containers/hash_tables.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "net/quic/crypto/crypto_framer.h" 9 #include "net/quic/crypto/crypto_framer.h"
10 #include "net/quic/crypto/crypto_handshake_message.h" 10 #include "net/quic/crypto/crypto_handshake_message.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 case PACKET_FLAGS_2BYTE_SEQUENCE: 125 case PACKET_FLAGS_2BYTE_SEQUENCE:
126 return PACKET_2BYTE_SEQUENCE_NUMBER; 126 return PACKET_2BYTE_SEQUENCE_NUMBER;
127 case PACKET_FLAGS_1BYTE_SEQUENCE: 127 case PACKET_FLAGS_1BYTE_SEQUENCE:
128 return PACKET_1BYTE_SEQUENCE_NUMBER; 128 return PACKET_1BYTE_SEQUENCE_NUMBER;
129 default: 129 default:
130 LOG(DFATAL) << "Unreachable case statement."; 130 LOG(DFATAL) << "Unreachable case statement.";
131 return PACKET_6BYTE_SEQUENCE_NUMBER; 131 return PACKET_6BYTE_SEQUENCE_NUMBER;
132 } 132 }
133 } 133 }
134 134
135 bool CanTruncate( 135 bool CanTruncate(const QuicFrame& frame, size_t free_bytes) {
136 QuicVersion version, const QuicFrame& frame, size_t free_bytes) {
137 if ((frame.type == ACK_FRAME || frame.type == CONNECTION_CLOSE_FRAME) && 136 if ((frame.type == ACK_FRAME || frame.type == CONNECTION_CLOSE_FRAME) &&
138 free_bytes >= 137 free_bytes >=
139 QuicFramer::GetMinAckFrameSize(version, 138 QuicFramer::GetMinAckFrameSize(PACKET_6BYTE_SEQUENCE_NUMBER,
140 PACKET_6BYTE_SEQUENCE_NUMBER,
141 PACKET_6BYTE_SEQUENCE_NUMBER)) { 139 PACKET_6BYTE_SEQUENCE_NUMBER)) {
142 return true; 140 return true;
143 } 141 }
144 return false; 142 return false;
145 } 143 }
146 144
147 } // namespace 145 } // namespace
148 146
149 bool QuicFramerVisitorInterface::OnWindowUpdateFrame( 147 bool QuicFramerVisitorInterface::OnWindowUpdateFrame(
150 const QuicWindowUpdateFrame& frame) { 148 const QuicWindowUpdateFrame& frame) {
(...skipping 23 matching lines...) Expand all
174 DCHECK(!supported_versions.empty()); 172 DCHECK(!supported_versions.empty());
175 quic_version_ = supported_versions_[0]; 173 quic_version_ = supported_versions_[0];
176 decrypter_.reset(QuicDecrypter::Create(kNULL)); 174 decrypter_.reset(QuicDecrypter::Create(kNULL));
177 encrypter_[ENCRYPTION_NONE].reset( 175 encrypter_[ENCRYPTION_NONE].reset(
178 QuicEncrypter::Create(kNULL)); 176 QuicEncrypter::Create(kNULL));
179 } 177 }
180 178
181 QuicFramer::~QuicFramer() {} 179 QuicFramer::~QuicFramer() {}
182 180
183 // static 181 // static
184 size_t QuicFramer::GetMinStreamFrameSize(QuicVersion version, 182 size_t QuicFramer::GetMinStreamFrameSize(QuicStreamId stream_id,
185 QuicStreamId stream_id,
186 QuicStreamOffset offset, 183 QuicStreamOffset offset,
187 bool last_frame_in_packet, 184 bool last_frame_in_packet,
188 InFecGroup is_in_fec_group) { 185 InFecGroup is_in_fec_group) {
189 bool no_stream_frame_length = last_frame_in_packet && 186 bool no_stream_frame_length = last_frame_in_packet &&
190 is_in_fec_group == NOT_IN_FEC_GROUP; 187 is_in_fec_group == NOT_IN_FEC_GROUP;
191 return kQuicFrameTypeSize + GetStreamIdSize(stream_id) + 188 return kQuicFrameTypeSize + GetStreamIdSize(stream_id) +
192 GetStreamOffsetSize(offset) + 189 GetStreamOffsetSize(offset) +
193 (no_stream_frame_length ? 0 : kQuicStreamPayloadLengthSize); 190 (no_stream_frame_length ? 0 : kQuicStreamPayloadLengthSize);
194 } 191 }
195 192
196 // static 193 // static
197 size_t QuicFramer::GetMinAckFrameSize( 194 size_t QuicFramer::GetMinAckFrameSize(
198 QuicVersion version,
199 QuicSequenceNumberLength sequence_number_length, 195 QuicSequenceNumberLength sequence_number_length,
200 QuicSequenceNumberLength largest_observed_length) { 196 QuicSequenceNumberLength largest_observed_length) {
201 return kQuicFrameTypeSize + kQuicEntropyHashSize + 197 return kQuicFrameTypeSize + kQuicEntropyHashSize +
202 largest_observed_length + kQuicDeltaTimeLargestObservedSize; 198 largest_observed_length + kQuicDeltaTimeLargestObservedSize;
203 } 199 }
204 200
205 // static 201 // static
206 size_t QuicFramer::GetStopWaitingFrameSize( 202 size_t QuicFramer::GetStopWaitingFrameSize(
207 QuicSequenceNumberLength sequence_number_length) { 203 QuicSequenceNumberLength sequence_number_length) {
208 return kQuicFrameTypeSize + kQuicEntropyHashSize + 204 return kQuicFrameTypeSize + kQuicEntropyHashSize +
209 sequence_number_length; 205 sequence_number_length;
210 } 206 }
211 207
212 // static 208 // static
213 size_t QuicFramer::GetMinRstStreamFrameSize(QuicVersion quic_version) { 209 size_t QuicFramer::GetMinRstStreamFrameSize() {
214 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + 210 return kQuicFrameTypeSize + kQuicMaxStreamIdSize +
215 kQuicMaxStreamOffsetSize + kQuicErrorCodeSize + 211 kQuicMaxStreamOffsetSize + kQuicErrorCodeSize +
216 kQuicErrorDetailsLengthSize; 212 kQuicErrorDetailsLengthSize;
217 } 213 }
218 214
219 // static 215 // static
220 size_t QuicFramer::GetMinConnectionCloseFrameSize() { 216 size_t QuicFramer::GetMinConnectionCloseFrameSize() {
221 return kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicErrorDetailsLengthSize; 217 return kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicErrorDetailsLengthSize;
222 } 218 }
223 219
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 sequence_number_length); 295 sequence_number_length);
300 if (frame_len <= free_bytes) { 296 if (frame_len <= free_bytes) {
301 // Frame fits within packet. Note that acks may be truncated. 297 // Frame fits within packet. Note that acks may be truncated.
302 return frame_len; 298 return frame_len;
303 } 299 }
304 // Only truncate the first frame in a packet, so if subsequent ones go 300 // Only truncate the first frame in a packet, so if subsequent ones go
305 // over, stop including more frames. 301 // over, stop including more frames.
306 if (!first_frame) { 302 if (!first_frame) {
307 return 0; 303 return 0;
308 } 304 }
309 if (CanTruncate(quic_version_, frame, free_bytes)) { 305 if (CanTruncate(frame, free_bytes)) {
310 // Truncate the frame so the packet will not exceed kMaxPacketSize. 306 // Truncate the frame so the packet will not exceed kMaxPacketSize.
311 // Note that we may not use every byte of the writer in this case. 307 // Note that we may not use every byte of the writer in this case.
312 DVLOG(1) << "Truncating large frame, free bytes: " << free_bytes; 308 DVLOG(1) << "Truncating large frame, free bytes: " << free_bytes;
313 return free_bytes; 309 return free_bytes;
314 } 310 }
315 if (!FLAGS_quic_allow_oversized_packets_for_test) { 311 if (!FLAGS_quic_allow_oversized_packets_for_test) {
316 return 0; 312 return 0;
317 } 313 }
318 LOG(DFATAL) << "Packet size too small to fit frame."; 314 LOG(DFATAL) << "Packet size too small to fit frame.";
319 return frame_len; 315 return frame_len;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 374 }
379 break; 375 break;
380 case STOP_WAITING_FRAME: 376 case STOP_WAITING_FRAME:
381 if (!AppendStopWaitingFrame( 377 if (!AppendStopWaitingFrame(
382 header, *frame.stop_waiting_frame, &writer)) { 378 header, *frame.stop_waiting_frame, &writer)) {
383 LOG(DFATAL) << "AppendStopWaitingFrame failed"; 379 LOG(DFATAL) << "AppendStopWaitingFrame failed";
384 return kNoPacket; 380 return kNoPacket;
385 } 381 }
386 break; 382 break;
387 case PING_FRAME: 383 case PING_FRAME:
388 if (quic_version_ <= QUIC_VERSION_16) { 384 if (quic_version_ == QUIC_VERSION_16) {
389 LOG(DFATAL) << "Attempt to add a PingFrame in " 385 LOG(DFATAL) << "Attempt to add a PingFrame in "
390 << QuicVersionToString(quic_version_); 386 << QuicVersionToString(quic_version_);
391 return kNoPacket; 387 return kNoPacket;
392 } 388 }
393 // Ping has no payload. 389 // Ping has no payload.
394 break; 390 break;
395 case RST_STREAM_FRAME: 391 case RST_STREAM_FRAME:
396 if (!AppendRstStreamFrame(*frame.rst_stream_frame, &writer)) { 392 if (!AppendRstStreamFrame(*frame.rst_stream_frame, &writer)) {
397 LOG(DFATAL) << "AppendRstStreamFrame failed"; 393 LOG(DFATAL) << "AppendRstStreamFrame failed";
398 return kNoPacket; 394 return kNoPacket;
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 return PACKET_FLAGS_6BYTE_SEQUENCE; 956 return PACKET_FLAGS_6BYTE_SEQUENCE;
961 default: 957 default:
962 LOG(DFATAL) << "Unreachable case statement."; 958 LOG(DFATAL) << "Unreachable case statement.";
963 return PACKET_FLAGS_6BYTE_SEQUENCE; 959 return PACKET_FLAGS_6BYTE_SEQUENCE;
964 } 960 }
965 } 961 }
966 962
967 // static 963 // static
968 QuicFramer::AckFrameInfo QuicFramer::GetAckFrameInfo( 964 QuicFramer::AckFrameInfo QuicFramer::GetAckFrameInfo(
969 const QuicAckFrame& frame) { 965 const QuicAckFrame& frame) {
970 const ReceivedPacketInfo& received_info = frame.received_info;
971
972 AckFrameInfo ack_info; 966 AckFrameInfo ack_info;
973 if (!received_info.missing_packets.empty()) { 967 if (!frame.missing_packets.empty()) {
974 DCHECK_GE(received_info.largest_observed, 968 DCHECK_GE(frame.largest_observed, *frame.missing_packets.rbegin());
975 *received_info.missing_packets.rbegin());
976 size_t cur_range_length = 0; 969 size_t cur_range_length = 0;
977 SequenceNumberSet::const_iterator iter = 970 SequenceNumberSet::const_iterator iter = frame.missing_packets.begin();
978 received_info.missing_packets.begin();
979 QuicPacketSequenceNumber last_missing = *iter; 971 QuicPacketSequenceNumber last_missing = *iter;
980 ++iter; 972 ++iter;
981 for (; iter != received_info.missing_packets.end(); ++iter) { 973 for (; iter != frame.missing_packets.end(); ++iter) {
982 if (cur_range_length != numeric_limits<uint8>::max() && 974 if (cur_range_length != numeric_limits<uint8>::max() &&
983 *iter == (last_missing + 1)) { 975 *iter == (last_missing + 1)) {
984 ++cur_range_length; 976 ++cur_range_length;
985 } else { 977 } else {
986 ack_info.nack_ranges[last_missing - cur_range_length] 978 ack_info.nack_ranges[last_missing - cur_range_length]
987 = cur_range_length; 979 = cur_range_length;
988 cur_range_length = 0; 980 cur_range_length = 0;
989 } 981 }
990 ack_info.max_delta = max(ack_info.max_delta, *iter - last_missing); 982 ack_info.max_delta = max(ack_info.max_delta, *iter - last_missing);
991 last_missing = *iter; 983 last_missing = *iter;
992 } 984 }
993 // Include the last nack range. 985 // Include the last nack range.
994 ack_info.nack_ranges[last_missing - cur_range_length] = cur_range_length; 986 ack_info.nack_ranges[last_missing - cur_range_length] = cur_range_length;
995 // Include the range to the largest observed. 987 // Include the range to the largest observed.
996 ack_info.max_delta = max(ack_info.max_delta, 988 ack_info.max_delta = max(ack_info.max_delta,
997 received_info.largest_observed - last_missing); 989 frame.largest_observed - last_missing);
998 } 990 }
999 return ack_info; 991 return ack_info;
1000 } 992 }
1001 993
1002 bool QuicFramer::ProcessPacketHeader( 994 bool QuicFramer::ProcessPacketHeader(
1003 QuicPacketHeader* header, 995 QuicPacketHeader* header,
1004 const QuicEncryptedPacket& packet) { 996 const QuicEncryptedPacket& packet) {
1005 if (!ProcessPacketSequenceNumber(header->public_header.sequence_number_length, 997 if (!ProcessPacketSequenceNumber(header->public_header.sequence_number_length,
1006 &header->packet_sequence_number)) { 998 &header->packet_sequence_number)) {
1007 set_detailed_error("Unable to read sequence number."); 999 set_detailed_error("Unable to read sequence number.");
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 DVLOG(1) << "Visitor asked to stop further processing."; 1090 DVLOG(1) << "Visitor asked to stop further processing.";
1099 // Returning true since there was no parsing error. 1091 // Returning true since there was no parsing error.
1100 return true; 1092 return true;
1101 } 1093 }
1102 continue; 1094 continue;
1103 } 1095 }
1104 1096
1105 // Ack Frame 1097 // Ack Frame
1106 if (frame_type & kQuicFrameTypeAckMask) { 1098 if (frame_type & kQuicFrameTypeAckMask) {
1107 QuicAckFrame frame; 1099 QuicAckFrame frame;
1108 if (!ProcessAckFrame(header, frame_type, &frame)) { 1100 if (!ProcessAckFrame(frame_type, &frame)) {
1109 return RaiseError(QUIC_INVALID_ACK_DATA); 1101 return RaiseError(QUIC_INVALID_ACK_DATA);
1110 } 1102 }
1111 if (!visitor_->OnAckFrame(frame)) { 1103 if (!visitor_->OnAckFrame(frame)) {
1112 DVLOG(1) << "Visitor asked to stop further processing."; 1104 DVLOG(1) << "Visitor asked to stop further processing.";
1113 // Returning true since there was no parsing error. 1105 // Returning true since there was no parsing error.
1114 return true; 1106 return true;
1115 } 1107 }
1116 continue; 1108 continue;
1117 } 1109 }
1118 1110
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 return RaiseError(QUIC_INVALID_STOP_WAITING_DATA); 1207 return RaiseError(QUIC_INVALID_STOP_WAITING_DATA);
1216 } 1208 }
1217 if (!visitor_->OnStopWaitingFrame(stop_waiting_frame)) { 1209 if (!visitor_->OnStopWaitingFrame(stop_waiting_frame)) {
1218 DVLOG(1) << "Visitor asked to stop further processing."; 1210 DVLOG(1) << "Visitor asked to stop further processing.";
1219 // Returning true since there was no parsing error. 1211 // Returning true since there was no parsing error.
1220 return true; 1212 return true;
1221 } 1213 }
1222 continue; 1214 continue;
1223 } 1215 }
1224 case PING_FRAME: { 1216 case PING_FRAME: {
1225 if (quic_version_ <= QUIC_VERSION_16) { 1217 if (quic_version_ == QUIC_VERSION_16) {
1226 LOG(DFATAL) << "Trying to read a Ping in " 1218 LOG(DFATAL) << "Trying to read a Ping in "
1227 << QuicVersionToString(quic_version_); 1219 << QuicVersionToString(quic_version_);
1228 return RaiseError(QUIC_INTERNAL_ERROR); 1220 return RaiseError(QUIC_INTERNAL_ERROR);
1229 } 1221 }
1230 // Ping has no payload. 1222 // Ping has no payload.
1231 QuicPingFrame ping_frame; 1223 QuicPingFrame ping_frame;
1232 if (!visitor_->OnPingFrame(ping_frame)) { 1224 if (!visitor_->OnPingFrame(ping_frame)) {
1233 DVLOG(1) << "Visitor asked to stop further processing."; 1225 DVLOG(1) << "Visitor asked to stop further processing.";
1234 // Returning true since there was no parsing error. 1226 // Returning true since there was no parsing error.
1235 return true; 1227 return true;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 } 1289 }
1298 // Point frame to the right data. 1290 // Point frame to the right data.
1299 frame->data.Clear(); 1291 frame->data.Clear();
1300 if (!frame_data.empty()) { 1292 if (!frame_data.empty()) {
1301 frame->data.Append(const_cast<char*>(frame_data.data()), frame_data.size()); 1293 frame->data.Append(const_cast<char*>(frame_data.data()), frame_data.size());
1302 } 1294 }
1303 1295
1304 return true; 1296 return true;
1305 } 1297 }
1306 1298
1307 bool QuicFramer::ProcessAckFrame(const QuicPacketHeader& header, 1299 bool QuicFramer::ProcessAckFrame(uint8 frame_type, QuicAckFrame* ack_frame) {
1308 uint8 frame_type,
1309 QuicAckFrame* frame) {
1310 if (!ProcessReceivedInfo(frame_type, &frame->received_info)) {
1311 return false;
1312 }
1313 return true;
1314 }
1315
1316 bool QuicFramer::ProcessReceivedInfo(uint8 frame_type,
1317 ReceivedPacketInfo* received_info) {
1318 // Determine the three lengths from the frame type: largest observed length, 1300 // Determine the three lengths from the frame type: largest observed length,
1319 // missing sequence number length, and missing range length. 1301 // missing sequence number length, and missing range length.
1320 const QuicSequenceNumberLength missing_sequence_number_length = 1302 const QuicSequenceNumberLength missing_sequence_number_length =
1321 ReadSequenceNumberLength(frame_type); 1303 ReadSequenceNumberLength(frame_type);
1322 frame_type >>= kQuicSequenceNumberLengthShift; 1304 frame_type >>= kQuicSequenceNumberLengthShift;
1323 const QuicSequenceNumberLength largest_observed_sequence_number_length = 1305 const QuicSequenceNumberLength largest_observed_sequence_number_length =
1324 ReadSequenceNumberLength(frame_type); 1306 ReadSequenceNumberLength(frame_type);
1325 frame_type >>= kQuicSequenceNumberLengthShift; 1307 frame_type >>= kQuicSequenceNumberLengthShift;
1326 received_info->is_truncated = frame_type & kQuicAckTruncatedMask; 1308 ack_frame->is_truncated = frame_type & kQuicAckTruncatedMask;
1327 frame_type >>= kQuicAckTruncatedShift; 1309 frame_type >>= kQuicAckTruncatedShift;
1328 bool has_nacks = frame_type & kQuicHasNacksMask; 1310 bool has_nacks = frame_type & kQuicHasNacksMask;
1329 1311
1330 if (!reader_->ReadBytes(&received_info->entropy_hash, 1)) { 1312 if (!reader_->ReadBytes(&ack_frame->entropy_hash, 1)) {
1331 set_detailed_error("Unable to read entropy hash for received packets."); 1313 set_detailed_error("Unable to read entropy hash for received packets.");
1332 return false; 1314 return false;
1333 } 1315 }
1334 1316
1335 if (!reader_->ReadBytes(&received_info->largest_observed, 1317 if (!reader_->ReadBytes(&ack_frame->largest_observed,
1336 largest_observed_sequence_number_length)) { 1318 largest_observed_sequence_number_length)) {
1337 set_detailed_error("Unable to read largest observed."); 1319 set_detailed_error("Unable to read largest observed.");
1338 return false; 1320 return false;
1339 } 1321 }
1340 1322
1341 uint64 delta_time_largest_observed_us; 1323 uint64 delta_time_largest_observed_us;
1342 if (!reader_->ReadUFloat16(&delta_time_largest_observed_us)) { 1324 if (!reader_->ReadUFloat16(&delta_time_largest_observed_us)) {
1343 set_detailed_error("Unable to read delta time largest observed."); 1325 set_detailed_error("Unable to read delta time largest observed.");
1344 return false; 1326 return false;
1345 } 1327 }
1346 1328
1347 if (delta_time_largest_observed_us == kUFloat16MaxValue) { 1329 if (delta_time_largest_observed_us == kUFloat16MaxValue) {
1348 received_info->delta_time_largest_observed = QuicTime::Delta::Infinite(); 1330 ack_frame->delta_time_largest_observed = QuicTime::Delta::Infinite();
1349 } else { 1331 } else {
1350 received_info->delta_time_largest_observed = 1332 ack_frame->delta_time_largest_observed =
1351 QuicTime::Delta::FromMicroseconds(delta_time_largest_observed_us); 1333 QuicTime::Delta::FromMicroseconds(delta_time_largest_observed_us);
1352 } 1334 }
1353 1335
1354 if (!has_nacks) { 1336 if (!has_nacks) {
1355 return true; 1337 return true;
1356 } 1338 }
1357 1339
1358 uint8 num_missing_ranges; 1340 uint8 num_missing_ranges;
1359 if (!reader_->ReadBytes(&num_missing_ranges, 1)) { 1341 if (!reader_->ReadBytes(&num_missing_ranges, 1)) {
1360 set_detailed_error("Unable to read num missing packet ranges."); 1342 set_detailed_error("Unable to read num missing packet ranges.");
1361 return false; 1343 return false;
1362 } 1344 }
1363 1345
1364 QuicPacketSequenceNumber last_sequence_number = 1346 QuicPacketSequenceNumber last_sequence_number = ack_frame->largest_observed;
1365 received_info->largest_observed;
1366 for (size_t i = 0; i < num_missing_ranges; ++i) { 1347 for (size_t i = 0; i < num_missing_ranges; ++i) {
1367 QuicPacketSequenceNumber missing_delta = 0; 1348 QuicPacketSequenceNumber missing_delta = 0;
1368 if (!reader_->ReadBytes(&missing_delta, missing_sequence_number_length)) { 1349 if (!reader_->ReadBytes(&missing_delta, missing_sequence_number_length)) {
1369 set_detailed_error("Unable to read missing sequence number delta."); 1350 set_detailed_error("Unable to read missing sequence number delta.");
1370 return false; 1351 return false;
1371 } 1352 }
1372 last_sequence_number -= missing_delta; 1353 last_sequence_number -= missing_delta;
1373 QuicPacketSequenceNumber range_length = 0; 1354 QuicPacketSequenceNumber range_length = 0;
1374 if (!reader_->ReadBytes(&range_length, PACKET_1BYTE_SEQUENCE_NUMBER)) { 1355 if (!reader_->ReadBytes(&range_length, PACKET_1BYTE_SEQUENCE_NUMBER)) {
1375 set_detailed_error("Unable to read missing sequence number range."); 1356 set_detailed_error("Unable to read missing sequence number range.");
1376 return false; 1357 return false;
1377 } 1358 }
1378 for (size_t i = 0; i <= range_length; ++i) { 1359 for (size_t i = 0; i <= range_length; ++i) {
1379 received_info->missing_packets.insert(last_sequence_number - i); 1360 ack_frame->missing_packets.insert(last_sequence_number - i);
1380 } 1361 }
1381 // Subtract an extra 1 to ensure ranges are represented efficiently and 1362 // Subtract an extra 1 to ensure ranges are represented efficiently and
1382 // can't overlap by 1 sequence number. This allows a missing_delta of 0 1363 // can't overlap by 1 sequence number. This allows a missing_delta of 0
1383 // to represent an adjacent nack range. 1364 // to represent an adjacent nack range.
1384 last_sequence_number -= (range_length + 1); 1365 last_sequence_number -= (range_length + 1);
1385 } 1366 }
1386 1367
1387 // Parse the revived packets list. 1368 // Parse the revived packets list.
1388 uint8 num_revived_packets; 1369 uint8 num_revived_packets;
1389 if (!reader_->ReadBytes(&num_revived_packets, 1)) { 1370 if (!reader_->ReadBytes(&num_revived_packets, 1)) {
1390 set_detailed_error("Unable to read num revived packets."); 1371 set_detailed_error("Unable to read num revived packets.");
1391 return false; 1372 return false;
1392 } 1373 }
1393 1374
1394 for (size_t i = 0; i < num_revived_packets; ++i) { 1375 for (size_t i = 0; i < num_revived_packets; ++i) {
1395 QuicPacketSequenceNumber revived_packet = 0; 1376 QuicPacketSequenceNumber revived_packet = 0;
1396 if (!reader_->ReadBytes(&revived_packet, 1377 if (!reader_->ReadBytes(&revived_packet,
1397 largest_observed_sequence_number_length)) { 1378 largest_observed_sequence_number_length)) {
1398 set_detailed_error("Unable to read revived packet."); 1379 set_detailed_error("Unable to read revived packet.");
1399 return false; 1380 return false;
1400 } 1381 }
1401 1382
1402 received_info->revived_packets.insert(revived_packet); 1383 ack_frame->revived_packets.insert(revived_packet);
1403 } 1384 }
1404 1385
1405 return true; 1386 return true;
1406 } 1387 }
1407 1388
1408 bool QuicFramer::ProcessStopWaitingFrame(const QuicPacketHeader& header, 1389 bool QuicFramer::ProcessStopWaitingFrame(const QuicPacketHeader& header,
1409 QuicStopWaitingFrame* stop_waiting) { 1390 QuicStopWaitingFrame* stop_waiting) {
1410 if (!reader_->ReadBytes(&stop_waiting->entropy_hash, 1)) { 1391 if (!reader_->ReadBytes(&stop_waiting->entropy_hash, 1)) {
1411 set_detailed_error("Unable to read entropy hash for sent packets."); 1392 set_detailed_error("Unable to read entropy hash for sent packets.");
1412 return false; 1393 return false;
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 1743
1763 reader_.reset(new QuicDataReader(decrypted_->data(), decrypted_->length())); 1744 reader_.reset(new QuicDataReader(decrypted_->data(), decrypted_->length()));
1764 return true; 1745 return true;
1765 } 1746 }
1766 1747
1767 size_t QuicFramer::GetAckFrameSize( 1748 size_t QuicFramer::GetAckFrameSize(
1768 const QuicAckFrame& ack, 1749 const QuicAckFrame& ack,
1769 QuicSequenceNumberLength sequence_number_length) { 1750 QuicSequenceNumberLength sequence_number_length) {
1770 AckFrameInfo ack_info = GetAckFrameInfo(ack); 1751 AckFrameInfo ack_info = GetAckFrameInfo(ack);
1771 QuicSequenceNumberLength largest_observed_length = 1752 QuicSequenceNumberLength largest_observed_length =
1772 GetMinSequenceNumberLength(ack.received_info.largest_observed); 1753 GetMinSequenceNumberLength(ack.largest_observed);
1773 QuicSequenceNumberLength missing_sequence_number_length = 1754 QuicSequenceNumberLength missing_sequence_number_length =
1774 GetMinSequenceNumberLength(ack_info.max_delta); 1755 GetMinSequenceNumberLength(ack_info.max_delta);
1775 1756
1776 size_t ack_size = GetMinAckFrameSize(quic_version_, 1757 size_t ack_size = GetMinAckFrameSize(sequence_number_length,
1777 sequence_number_length,
1778 largest_observed_length); 1758 largest_observed_length);
1779 if (!ack_info.nack_ranges.empty()) { 1759 if (!ack_info.nack_ranges.empty()) {
1780 ack_size += kNumberOfNackRangesSize + kNumberOfRevivedPacketsSize; 1760 ack_size += kNumberOfNackRangesSize + kNumberOfRevivedPacketsSize;
1781 ack_size += min(ack_info.nack_ranges.size(), kMaxNackRanges) * 1761 ack_size += min(ack_info.nack_ranges.size(), kMaxNackRanges) *
1782 (missing_sequence_number_length + PACKET_1BYTE_SEQUENCE_NUMBER); 1762 (missing_sequence_number_length + PACKET_1BYTE_SEQUENCE_NUMBER);
1783 ack_size += min(ack.received_info.revived_packets.size(), 1763 ack_size += min(ack.revived_packets.size(),
1784 kMaxRevivedPackets) * largest_observed_length; 1764 kMaxRevivedPackets) * largest_observed_length;
1785 } 1765 }
1786 return ack_size; 1766 return ack_size;
1787 } 1767 }
1788 1768
1789 size_t QuicFramer::ComputeFrameLength( 1769 size_t QuicFramer::ComputeFrameLength(
1790 const QuicFrame& frame, 1770 const QuicFrame& frame,
1791 bool last_frame_in_packet, 1771 bool last_frame_in_packet,
1792 InFecGroup is_in_fec_group, 1772 InFecGroup is_in_fec_group,
1793 QuicSequenceNumberLength sequence_number_length) { 1773 QuicSequenceNumberLength sequence_number_length) {
1794 switch (frame.type) { 1774 switch (frame.type) {
1795 case STREAM_FRAME: 1775 case STREAM_FRAME:
1796 return GetMinStreamFrameSize(quic_version_, 1776 return GetMinStreamFrameSize(frame.stream_frame->stream_id,
1797 frame.stream_frame->stream_id,
1798 frame.stream_frame->offset, 1777 frame.stream_frame->offset,
1799 last_frame_in_packet, 1778 last_frame_in_packet,
1800 is_in_fec_group) + 1779 is_in_fec_group) +
1801 frame.stream_frame->data.TotalBufferSize(); 1780 frame.stream_frame->data.TotalBufferSize();
1802 case ACK_FRAME: { 1781 case ACK_FRAME: {
1803 return GetAckFrameSize(*frame.ack_frame, sequence_number_length); 1782 return GetAckFrameSize(*frame.ack_frame, sequence_number_length);
1804 } 1783 }
1805 case CONGESTION_FEEDBACK_FRAME: { 1784 case CONGESTION_FEEDBACK_FRAME: {
1806 size_t len = kQuicFrameTypeSize; 1785 size_t len = kQuicFrameTypeSize;
1807 const QuicCongestionFeedbackFrame& congestion_feedback = 1786 const QuicCongestionFeedbackFrame& congestion_feedback =
(...skipping 23 matching lines...) Expand all
1831 break; 1810 break;
1832 } 1811 }
1833 return len; 1812 return len;
1834 } 1813 }
1835 case STOP_WAITING_FRAME: 1814 case STOP_WAITING_FRAME:
1836 return GetStopWaitingFrameSize(sequence_number_length); 1815 return GetStopWaitingFrameSize(sequence_number_length);
1837 case PING_FRAME: 1816 case PING_FRAME:
1838 // Ping has no payload. 1817 // Ping has no payload.
1839 return kQuicFrameTypeSize; 1818 return kQuicFrameTypeSize;
1840 case RST_STREAM_FRAME: 1819 case RST_STREAM_FRAME:
1841 return GetMinRstStreamFrameSize(quic_version_) + 1820 return GetMinRstStreamFrameSize() +
1842 frame.rst_stream_frame->error_details.size(); 1821 frame.rst_stream_frame->error_details.size();
1843 case CONNECTION_CLOSE_FRAME: 1822 case CONNECTION_CLOSE_FRAME:
1844 return GetMinConnectionCloseFrameSize() + 1823 return GetMinConnectionCloseFrameSize() +
1845 frame.connection_close_frame->error_details.size(); 1824 frame.connection_close_frame->error_details.size();
1846 case GOAWAY_FRAME: 1825 case GOAWAY_FRAME:
1847 return GetMinGoAwayFrameSize() + frame.goaway_frame->reason_phrase.size(); 1826 return GetMinGoAwayFrameSize() + frame.goaway_frame->reason_phrase.size();
1848 case WINDOW_UPDATE_FRAME: 1827 case WINDOW_UPDATE_FRAME:
1849 return GetWindowUpdateFrameSize(); 1828 return GetWindowUpdateFrameSize();
1850 case BLOCKED_FRAME: 1829 case BLOCKED_FRAME:
1851 return GetBlockedFrameSize(); 1830 return GetBlockedFrameSize();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 void QuicFramer::set_version(const QuicVersion version) { 1948 void QuicFramer::set_version(const QuicVersion version) {
1970 DCHECK(IsSupportedVersion(version)) << QuicVersionToString(version); 1949 DCHECK(IsSupportedVersion(version)) << QuicVersionToString(version);
1971 quic_version_ = version; 1950 quic_version_ = version;
1972 } 1951 }
1973 1952
1974 bool QuicFramer::AppendAckFrameAndTypeByte( 1953 bool QuicFramer::AppendAckFrameAndTypeByte(
1975 const QuicPacketHeader& header, 1954 const QuicPacketHeader& header,
1976 const QuicAckFrame& frame, 1955 const QuicAckFrame& frame,
1977 QuicDataWriter* writer) { 1956 QuicDataWriter* writer) {
1978 AckFrameInfo ack_info = GetAckFrameInfo(frame); 1957 AckFrameInfo ack_info = GetAckFrameInfo(frame);
1979 QuicPacketSequenceNumber ack_largest_observed = 1958 QuicPacketSequenceNumber ack_largest_observed = frame.largest_observed;
1980 frame.received_info.largest_observed;
1981 QuicSequenceNumberLength largest_observed_length = 1959 QuicSequenceNumberLength largest_observed_length =
1982 GetMinSequenceNumberLength(ack_largest_observed); 1960 GetMinSequenceNumberLength(ack_largest_observed);
1983 QuicSequenceNumberLength missing_sequence_number_length = 1961 QuicSequenceNumberLength missing_sequence_number_length =
1984 GetMinSequenceNumberLength(ack_info.max_delta); 1962 GetMinSequenceNumberLength(ack_info.max_delta);
1985 // Determine whether we need to truncate ranges. 1963 // Determine whether we need to truncate ranges.
1986 size_t available_range_bytes = writer->capacity() - writer->length() - 1964 size_t available_range_bytes = writer->capacity() - writer->length() -
1987 kNumberOfRevivedPacketsSize - kNumberOfNackRangesSize - 1965 kNumberOfRevivedPacketsSize - kNumberOfNackRangesSize -
1988 GetMinAckFrameSize(quic_version_, 1966 GetMinAckFrameSize(header.public_header.sequence_number_length,
1989 header.public_header.sequence_number_length,
1990 largest_observed_length); 1967 largest_observed_length);
1991 size_t max_num_ranges = available_range_bytes / 1968 size_t max_num_ranges = available_range_bytes /
1992 (missing_sequence_number_length + PACKET_1BYTE_SEQUENCE_NUMBER); 1969 (missing_sequence_number_length + PACKET_1BYTE_SEQUENCE_NUMBER);
1993 max_num_ranges = min(kMaxNackRanges, max_num_ranges); 1970 max_num_ranges = min(kMaxNackRanges, max_num_ranges);
1994 bool truncated = ack_info.nack_ranges.size() > max_num_ranges; 1971 bool truncated = ack_info.nack_ranges.size() > max_num_ranges;
1995 DVLOG_IF(1, truncated) << "Truncating ack from " 1972 DVLOG_IF(1, truncated) << "Truncating ack from "
1996 << ack_info.nack_ranges.size() << " ranges to " 1973 << ack_info.nack_ranges.size() << " ranges to "
1997 << max_num_ranges; 1974 << max_num_ranges;
1998 // Write out the type byte by setting the low order bits and doing shifts 1975 // Write out the type byte by setting the low order bits and doing shifts
1999 // to make room for the next bit flags to be set. 1976 // to make room for the next bit flags to be set.
(...skipping 11 matching lines...) Expand all
2011 // Missing sequence number length. 1988 // Missing sequence number length.
2012 type_byte <<= kQuicSequenceNumberLengthShift; 1989 type_byte <<= kQuicSequenceNumberLengthShift;
2013 type_byte |= GetSequenceNumberFlags(missing_sequence_number_length); 1990 type_byte |= GetSequenceNumberFlags(missing_sequence_number_length);
2014 1991
2015 type_byte |= kQuicFrameTypeAckMask; 1992 type_byte |= kQuicFrameTypeAckMask;
2016 1993
2017 if (!writer->WriteUInt8(type_byte)) { 1994 if (!writer->WriteUInt8(type_byte)) {
2018 return false; 1995 return false;
2019 } 1996 }
2020 1997
2021 const ReceivedPacketInfo& received_info = frame.received_info; 1998 QuicPacketEntropyHash ack_entropy_hash = frame.entropy_hash;
2022 QuicPacketEntropyHash ack_entropy_hash = received_info.entropy_hash;
2023 NackRangeMap::reverse_iterator ack_iter = ack_info.nack_ranges.rbegin(); 1999 NackRangeMap::reverse_iterator ack_iter = ack_info.nack_ranges.rbegin();
2024 if (truncated) { 2000 if (truncated) {
2025 // Skip the nack ranges which the truncated ack won't include and set 2001 // Skip the nack ranges which the truncated ack won't include and set
2026 // a correct largest observed for the truncated ack. 2002 // a correct largest observed for the truncated ack.
2027 for (size_t i = 1; i < (ack_info.nack_ranges.size() - max_num_ranges); 2003 for (size_t i = 1; i < (ack_info.nack_ranges.size() - max_num_ranges);
2028 ++i) { 2004 ++i) {
2029 ++ack_iter; 2005 ++ack_iter;
2030 } 2006 }
2031 // If the last range is followed by acks, include them. 2007 // If the last range is followed by acks, include them.
2032 // If the last range is followed by another range, specify the end of the 2008 // If the last range is followed by another range, specify the end of the
2033 // range as the largest_observed. 2009 // range as the largest_observed.
2034 ack_largest_observed = ack_iter->first - 1; 2010 ack_largest_observed = ack_iter->first - 1;
2035 // Also update the entropy so it matches the largest observed. 2011 // Also update the entropy so it matches the largest observed.
2036 ack_entropy_hash = entropy_calculator_->EntropyHash(ack_largest_observed); 2012 ack_entropy_hash = entropy_calculator_->EntropyHash(ack_largest_observed);
2037 ++ack_iter; 2013 ++ack_iter;
2038 } 2014 }
2039 2015
2040 if (!writer->WriteUInt8(ack_entropy_hash)) { 2016 if (!writer->WriteUInt8(ack_entropy_hash)) {
2041 return false; 2017 return false;
2042 } 2018 }
2043 2019
2044 if (!AppendPacketSequenceNumber(largest_observed_length, 2020 if (!AppendPacketSequenceNumber(largest_observed_length,
2045 ack_largest_observed, writer)) { 2021 ack_largest_observed, writer)) {
2046 return false; 2022 return false;
2047 } 2023 }
2048 2024
2049 uint64 delta_time_largest_observed_us = kUFloat16MaxValue; 2025 uint64 delta_time_largest_observed_us = kUFloat16MaxValue;
2050 if (!received_info.delta_time_largest_observed.IsInfinite()) { 2026 if (!frame.delta_time_largest_observed.IsInfinite()) {
2051 DCHECK_LE(0u, 2027 DCHECK_LE(0u, frame.delta_time_largest_observed.ToMicroseconds());
2052 frame.received_info.delta_time_largest_observed.ToMicroseconds());
2053 delta_time_largest_observed_us = 2028 delta_time_largest_observed_us =
2054 received_info.delta_time_largest_observed.ToMicroseconds(); 2029 frame.delta_time_largest_observed.ToMicroseconds();
2055 } 2030 }
2056 2031
2057 if (!writer->WriteUFloat16(delta_time_largest_observed_us)) { 2032 if (!writer->WriteUFloat16(delta_time_largest_observed_us)) {
2058 return false; 2033 return false;
2059 } 2034 }
2060 2035
2061 if (ack_info.nack_ranges.empty()) { 2036 if (ack_info.nack_ranges.empty()) {
2062 return true; 2037 return true;
2063 } 2038 }
2064 2039
(...skipping 18 matching lines...) Expand all
2083 return false; 2058 return false;
2084 } 2059 }
2085 // Subtract 1 so a missing_delta of 0 means an adjacent range. 2060 // Subtract 1 so a missing_delta of 0 means an adjacent range.
2086 last_sequence_written = ack_iter->first - 1; 2061 last_sequence_written = ack_iter->first - 1;
2087 ++num_ranges_written; 2062 ++num_ranges_written;
2088 } 2063 }
2089 DCHECK_EQ(num_missing_ranges, num_ranges_written); 2064 DCHECK_EQ(num_missing_ranges, num_ranges_written);
2090 2065
2091 // Append revived packets. 2066 // Append revived packets.
2092 // If not all the revived packets fit, only mention the ones that do. 2067 // If not all the revived packets fit, only mention the ones that do.
2093 uint8 num_revived_packets = min(received_info.revived_packets.size(), 2068 uint8 num_revived_packets = min(frame.revived_packets.size(),
2094 kMaxRevivedPackets); 2069 kMaxRevivedPackets);
2095 num_revived_packets = min( 2070 num_revived_packets = min(
2096 static_cast<size_t>(num_revived_packets), 2071 static_cast<size_t>(num_revived_packets),
2097 (writer->capacity() - writer->length()) / largest_observed_length); 2072 (writer->capacity() - writer->length()) / largest_observed_length);
2098 if (!writer->WriteBytes(&num_revived_packets, 1)) { 2073 if (!writer->WriteBytes(&num_revived_packets, 1)) {
2099 return false; 2074 return false;
2100 } 2075 }
2101 2076
2102 SequenceNumberSet::const_iterator iter = 2077 SequenceNumberSet::const_iterator iter = frame.revived_packets.begin();
2103 received_info.revived_packets.begin();
2104 for (int i = 0; i < num_revived_packets; ++i, ++iter) { 2078 for (int i = 0; i < num_revived_packets; ++i, ++iter) {
2105 LOG_IF(DFATAL, !ContainsKey(received_info.missing_packets, *iter)); 2079 LOG_IF(DFATAL, !ContainsKey(frame.missing_packets, *iter));
2106 if (!AppendPacketSequenceNumber(largest_observed_length, 2080 if (!AppendPacketSequenceNumber(largest_observed_length,
2107 *iter, writer)) { 2081 *iter, writer)) {
2108 return false; 2082 return false;
2109 } 2083 }
2110 } 2084 }
2111 2085
2112 return true; 2086 return true;
2113 } 2087 }
2114 2088
2115 bool QuicFramer::AppendCongestionFeedbackFrame( 2089 bool QuicFramer::AppendCongestionFeedbackFrame(
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2292 2266
2293 bool QuicFramer::RaiseError(QuicErrorCode error) { 2267 bool QuicFramer::RaiseError(QuicErrorCode error) {
2294 DVLOG(1) << "Error detail: " << detailed_error_; 2268 DVLOG(1) << "Error detail: " << detailed_error_;
2295 set_error(error); 2269 set_error(error);
2296 visitor_->OnError(this); 2270 visitor_->OnError(this);
2297 reader_.reset(NULL); 2271 reader_.reset(NULL);
2298 return false; 2272 return false;
2299 } 2273 }
2300 2274
2301 } // namespace net 2275 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer.h ('k') | net/quic/quic_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698