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

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

Issue 2808273006: Landing Recent QUIC changes until Sun Apr 9 16:12:55 (Closed)
Patch Set: increment enabled_options in e2e test Created 3 years, 8 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/core/quic_framer.h ('k') | net/quic/core/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/core/quic_framer.h" 5 #include "net/quic/core/quic_framer.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 for (const QuicFrame& frame : frames) { 329 for (const QuicFrame& frame : frames) {
330 // Determine if we should write stream frame length in header. 330 // Determine if we should write stream frame length in header.
331 const bool no_stream_frame_length = i == frames.size() - 1; 331 const bool no_stream_frame_length = i == frames.size() - 1;
332 if (!AppendTypeByte(frame, no_stream_frame_length, &writer)) { 332 if (!AppendTypeByte(frame, no_stream_frame_length, &writer)) {
333 QUIC_BUG << "AppendTypeByte failed"; 333 QUIC_BUG << "AppendTypeByte failed";
334 return 0; 334 return 0;
335 } 335 }
336 336
337 switch (frame.type) { 337 switch (frame.type) {
338 case PADDING_FRAME: 338 case PADDING_FRAME:
339 writer.WritePadding(); 339 if (!AppendPaddingFrame(frame.padding_frame, &writer)) {
340 QUIC_BUG << "AppendPaddingFrame of "
341 << frame.padding_frame.num_padding_bytes << " failed";
342 return 0;
343 }
340 break; 344 break;
341 case STREAM_FRAME: 345 case STREAM_FRAME:
342 if (!AppendStreamFrame(*frame.stream_frame, no_stream_frame_length, 346 if (!AppendStreamFrame(*frame.stream_frame, no_stream_frame_length,
343 &writer)) { 347 &writer)) {
344 QUIC_BUG << "AppendStreamFrame failed"; 348 QUIC_BUG << "AppendStreamFrame failed";
345 return 0; 349 return 0;
346 } 350 }
347 break; 351 break;
348 case ACK_FRAME: 352 case ACK_FRAME:
349 if (!AppendAckFrameAndTypeByte(*frame.ack_frame, &writer)) { 353 if (!AppendAckFrameAndTypeByte(*frame.ack_frame, &writer)) {
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 // This was a special frame type that did not match any 1010 // This was a special frame type that did not match any
1007 // of the known ones. Error. 1011 // of the known ones. Error.
1008 set_detailed_error("Illegal frame type."); 1012 set_detailed_error("Illegal frame type.");
1009 QUIC_DLOG(WARNING) << ENDPOINT << "Illegal frame type: " 1013 QUIC_DLOG(WARNING) << ENDPOINT << "Illegal frame type: "
1010 << static_cast<int>(frame_type); 1014 << static_cast<int>(frame_type);
1011 return RaiseError(QUIC_INVALID_FRAME_DATA); 1015 return RaiseError(QUIC_INVALID_FRAME_DATA);
1012 } 1016 }
1013 1017
1014 switch (frame_type) { 1018 switch (frame_type) {
1015 case PADDING_FRAME: { 1019 case PADDING_FRAME: {
1016 QuicPaddingFrame frame(reader->BytesRemaining()); 1020 QuicPaddingFrame frame;
1021 ProcessPaddingFrame(reader, &frame);
1017 if (!visitor_->OnPaddingFrame(frame)) { 1022 if (!visitor_->OnPaddingFrame(frame)) {
1018 QUIC_DVLOG(1) << "Visitor asked to stop further processing."; 1023 QUIC_DVLOG(1) << "Visitor asked to stop further processing.";
1024 // Returning true since there was no parsing error.
1025 return true;
1019 } 1026 }
1020 // We're done with the packet. 1027 continue;
1021 return true;
1022 } 1028 }
1023 1029
1024 case RST_STREAM_FRAME: { 1030 case RST_STREAM_FRAME: {
1025 QuicRstStreamFrame frame; 1031 QuicRstStreamFrame frame;
1026 if (!ProcessRstStreamFrame(reader, &frame)) { 1032 if (!ProcessRstStreamFrame(reader, &frame)) {
1027 return RaiseError(QUIC_INVALID_RST_STREAM_DATA); 1033 return RaiseError(QUIC_INVALID_RST_STREAM_DATA);
1028 } 1034 }
1029 if (!visitor_->OnRstStreamFrame(frame)) { 1035 if (!visitor_->OnRstStreamFrame(frame)) {
1030 QUIC_DVLOG(1) << "Visitor asked to stop further processing."; 1036 QUIC_DVLOG(1) << "Visitor asked to stop further processing.";
1031 // Returning true since there was no parsing error. 1037 // Returning true since there was no parsing error.
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 bool QuicFramer::ProcessBlockedFrame(QuicDataReader* reader, 1437 bool QuicFramer::ProcessBlockedFrame(QuicDataReader* reader,
1432 QuicBlockedFrame* frame) { 1438 QuicBlockedFrame* frame) {
1433 if (!reader->ReadUInt32(&frame->stream_id)) { 1439 if (!reader->ReadUInt32(&frame->stream_id)) {
1434 set_detailed_error("Unable to read stream_id."); 1440 set_detailed_error("Unable to read stream_id.");
1435 return false; 1441 return false;
1436 } 1442 }
1437 1443
1438 return true; 1444 return true;
1439 } 1445 }
1440 1446
1447 void QuicFramer::ProcessPaddingFrame(QuicDataReader* reader,
1448 QuicPaddingFrame* frame) {
1449 if (quic_version_ <= QUIC_VERSION_37) {
1450 frame->num_padding_bytes = reader->BytesRemaining() + 1;
1451 reader->ReadRemainingPayload();
1452 return;
1453 }
1454 // Type byte has been read.
1455 frame->num_padding_bytes = 1;
1456 uint8_t next_byte;
1457 while (!reader->IsDoneReading() && reader->PeekByte() == 0x00) {
1458 reader->ReadBytes(&next_byte, 1);
1459 DCHECK_EQ(0x00, next_byte);
1460 ++frame->num_padding_bytes;
1461 }
1462 }
1463
1441 // static 1464 // static
1442 QuicStringPiece QuicFramer::GetAssociatedDataFromEncryptedPacket( 1465 QuicStringPiece QuicFramer::GetAssociatedDataFromEncryptedPacket(
1443 QuicVersion version, 1466 QuicVersion version,
1444 const QuicEncryptedPacket& encrypted, 1467 const QuicEncryptedPacket& encrypted,
1445 QuicConnectionIdLength connection_id_length, 1468 QuicConnectionIdLength connection_id_length,
1446 bool includes_version, 1469 bool includes_version,
1447 bool includes_diversification_nonce, 1470 bool includes_diversification_nonce,
1448 QuicPacketNumberLength packet_number_length) { 1471 QuicPacketNumberLength packet_number_length) {
1449 // TODO(ianswett): This is identical to QuicData::AssociatedData. 1472 // TODO(ianswett): This is identical to QuicData::AssociatedData.
1450 return QuicStringPiece( 1473 return QuicStringPiece(
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 2127
2105 bool QuicFramer::AppendBlockedFrame(const QuicBlockedFrame& frame, 2128 bool QuicFramer::AppendBlockedFrame(const QuicBlockedFrame& frame,
2106 QuicDataWriter* writer) { 2129 QuicDataWriter* writer) {
2107 uint32_t stream_id = static_cast<uint32_t>(frame.stream_id); 2130 uint32_t stream_id = static_cast<uint32_t>(frame.stream_id);
2108 if (!writer->WriteUInt32(stream_id)) { 2131 if (!writer->WriteUInt32(stream_id)) {
2109 return false; 2132 return false;
2110 } 2133 }
2111 return true; 2134 return true;
2112 } 2135 }
2113 2136
2137 bool QuicFramer::AppendPaddingFrame(const QuicPaddingFrame& frame,
2138 QuicDataWriter* writer) {
2139 if (quic_version_ <= QUIC_VERSION_37) {
2140 writer->WritePadding();
2141 return true;
2142 }
2143
2144 if (frame.num_padding_bytes == 0) {
2145 return false;
2146 }
2147 if (frame.num_padding_bytes < 0) {
2148 QUIC_BUG_IF(frame.num_padding_bytes != -1);
2149 writer->WritePadding();
2150 return true;
2151 }
2152 // Please note, num_padding_bytes includes type byte which has been written.
2153 return writer->WritePaddingBytes(frame.num_padding_bytes - 1);
2154 }
2155
2114 bool QuicFramer::RaiseError(QuicErrorCode error) { 2156 bool QuicFramer::RaiseError(QuicErrorCode error) {
2115 QUIC_DLOG(INFO) << ENDPOINT << "Error: " << QuicErrorCodeToString(error) 2157 QUIC_DLOG(INFO) << ENDPOINT << "Error: " << QuicErrorCodeToString(error)
2116 << " detail: " << detailed_error_; 2158 << " detail: " << detailed_error_;
2117 set_error(error); 2159 set_error(error);
2118 visitor_->OnError(this); 2160 visitor_->OnError(this);
2119 return false; 2161 return false;
2120 } 2162 }
2121 2163
2122 } // namespace net 2164 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_framer.h ('k') | net/quic/core/quic_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698