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

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

Issue 2747443002: Landing recent QUIC changes until Sun Mar 5 09:18:09 2017 +0000 (Closed)
Patch Set: Fixed formatting errors in quic_error_mapping.cc Created 3 years, 9 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 size_t QuicFramer::GetWindowUpdateFrameSize() { 200 size_t QuicFramer::GetWindowUpdateFrameSize() {
201 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize; 201 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize;
202 } 202 }
203 203
204 // static 204 // static
205 size_t QuicFramer::GetBlockedFrameSize() { 205 size_t QuicFramer::GetBlockedFrameSize() {
206 return kQuicFrameTypeSize + kQuicMaxStreamIdSize; 206 return kQuicFrameTypeSize + kQuicMaxStreamIdSize;
207 } 207 }
208 208
209 // static 209 // static
210 size_t QuicFramer::GetPathCloseFrameSize() {
211 return kQuicFrameTypeSize + kQuicPathIdSize;
212 }
213
214 // static
215 size_t QuicFramer::GetStreamIdSize(QuicStreamId stream_id) { 210 size_t QuicFramer::GetStreamIdSize(QuicStreamId stream_id) {
216 // Sizes are 1 through 4 bytes. 211 // Sizes are 1 through 4 bytes.
217 for (int i = 1; i <= 4; ++i) { 212 for (int i = 1; i <= 4; ++i) {
218 stream_id >>= 8; 213 stream_id >>= 8;
219 if (stream_id == 0) { 214 if (stream_id == 0) {
220 return i; 215 return i;
221 } 216 }
222 } 217 }
223 QUIC_BUG << "Failed to determine StreamIDSize."; 218 QUIC_BUG << "Failed to determine StreamIDSize.";
224 return 4; 219 return 4;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 QUIC_BUG << "AppendWindowUpdateFrame failed"; 386 QUIC_BUG << "AppendWindowUpdateFrame failed";
392 return 0; 387 return 0;
393 } 388 }
394 break; 389 break;
395 case BLOCKED_FRAME: 390 case BLOCKED_FRAME:
396 if (!AppendBlockedFrame(*frame.blocked_frame, &writer)) { 391 if (!AppendBlockedFrame(*frame.blocked_frame, &writer)) {
397 QUIC_BUG << "AppendBlockedFrame failed"; 392 QUIC_BUG << "AppendBlockedFrame failed";
398 return 0; 393 return 0;
399 } 394 }
400 break; 395 break;
401 case PATH_CLOSE_FRAME:
402 if (!AppendPathCloseFrame(*frame.path_close_frame, &writer)) {
403 QUIC_BUG << "AppendPathCloseFrame failed";
404 return 0;
405 }
406 break;
407 default: 396 default:
408 RaiseError(QUIC_INVALID_FRAME_DATA); 397 RaiseError(QUIC_INVALID_FRAME_DATA);
409 QUIC_BUG << "QUIC_INVALID_FRAME_DATA"; 398 QUIC_BUG << "QUIC_INVALID_FRAME_DATA";
410 return 0; 399 return 0;
411 } 400 }
412 ++i; 401 ++i;
413 } 402 }
414 403
415 return writer.length(); 404 return writer.length();
416 } 405 }
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 return false; 766 return false;
778 } 767 }
779 768
780 public_header->multipath_flag = 769 public_header->multipath_flag =
781 (public_flags & PACKET_PUBLIC_FLAGS_MULTIPATH) != 0; 770 (public_flags & PACKET_PUBLIC_FLAGS_MULTIPATH) != 0;
782 public_header->reset_flag = (public_flags & PACKET_PUBLIC_FLAGS_RST) != 0; 771 public_header->reset_flag = (public_flags & PACKET_PUBLIC_FLAGS_RST) != 0;
783 public_header->version_flag = 772 public_header->version_flag =
784 (public_flags & PACKET_PUBLIC_FLAGS_VERSION) != 0; 773 (public_flags & PACKET_PUBLIC_FLAGS_VERSION) != 0;
785 774
786 if (validate_flags_ && !public_header->version_flag && 775 if (validate_flags_ && !public_header->version_flag &&
787 public_flags > PACKET_PUBLIC_FLAGS_MAX) { 776 public_flags > (FLAGS_quic_reloadable_flag_quic_remove_multipath_bit
777 ? PACKET_PUBLIC_FLAGS_MAX_WITHOUT_MULTIPATH_FLAG
778 : PACKET_PUBLIC_FLAGS_MAX)) {
788 set_detailed_error("Illegal public flags value."); 779 set_detailed_error("Illegal public flags value.");
789 return false; 780 return false;
790 } 781 }
791 782
792 if (public_header->reset_flag && public_header->version_flag) { 783 if (public_header->reset_flag && public_header->version_flag) {
793 set_detailed_error("Got version flag in reset packet"); 784 set_detailed_error("Got version flag in reset packet");
794 return false; 785 return false;
795 } 786 }
796 787
797 switch (public_flags & PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID) { 788 switch (public_flags & PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID) {
(...skipping 20 matching lines...) Expand all
818 if (!reader->ReadUInt32(&version_tag)) { 809 if (!reader->ReadUInt32(&version_tag)) {
819 set_detailed_error("Unable to read protocol version."); 810 set_detailed_error("Unable to read protocol version.");
820 return false; 811 return false;
821 } 812 }
822 813
823 // If the version from the new packet is the same as the version of this 814 // If the version from the new packet is the same as the version of this
824 // framer, then the public flags should be set to something we understand. 815 // framer, then the public flags should be set to something we understand.
825 // If not, this raises an error. 816 // If not, this raises an error.
826 last_version_tag_ = version_tag; 817 last_version_tag_ = version_tag;
827 QuicVersion version = QuicTagToQuicVersion(version_tag); 818 QuicVersion version = QuicTagToQuicVersion(version_tag);
828 if (version == quic_version_ && public_flags > PACKET_PUBLIC_FLAGS_MAX) { 819 if (version == quic_version_ &&
820 public_flags > (FLAGS_quic_reloadable_flag_quic_remove_multipath_bit
821 ? PACKET_PUBLIC_FLAGS_MAX_WITHOUT_MULTIPATH_FLAG
822 : PACKET_PUBLIC_FLAGS_MAX)) {
829 set_detailed_error("Illegal public flags value."); 823 set_detailed_error("Illegal public flags value.");
830 return false; 824 return false;
831 } 825 }
832 public_header->versions.push_back(version); 826 public_header->versions.push_back(version);
833 } 827 }
834 828
835 // A nonce should only be present in packets from the server to the client, 829 // A nonce should only be present in packets from the server to the client,
836 // which are neither version negotiation nor public reset packets. 830 // which are neither version negotiation nor public reset packets.
837 if (public_flags & PACKET_PUBLIC_FLAGS_NONCE && 831 if (public_flags & PACKET_PUBLIC_FLAGS_NONCE &&
838 !(public_flags & PACKET_PUBLIC_FLAGS_VERSION) && 832 !(public_flags & PACKET_PUBLIC_FLAGS_VERSION) &&
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 // Ping has no payload. 1100 // Ping has no payload.
1107 QuicPingFrame ping_frame; 1101 QuicPingFrame ping_frame;
1108 if (!visitor_->OnPingFrame(ping_frame)) { 1102 if (!visitor_->OnPingFrame(ping_frame)) {
1109 QUIC_DVLOG(1) << ENDPOINT 1103 QUIC_DVLOG(1) << ENDPOINT
1110 << "Visitor asked to stop further processing."; 1104 << "Visitor asked to stop further processing.";
1111 // Returning true since there was no parsing error. 1105 // Returning true since there was no parsing error.
1112 return true; 1106 return true;
1113 } 1107 }
1114 continue; 1108 continue;
1115 } 1109 }
1116 case PATH_CLOSE_FRAME: {
1117 QuicPathCloseFrame path_close_frame;
1118 if (!ProcessPathCloseFrame(reader, &path_close_frame)) {
1119 return RaiseError(QUIC_INVALID_PATH_CLOSE_DATA);
1120 }
1121 if (!visitor_->OnPathCloseFrame(path_close_frame)) {
1122 QUIC_DVLOG(1) << ENDPOINT
1123 << "Visitor asked to stop further processing.";
1124 // Returning true since there was no parsing error.
1125 return true;
1126 }
1127 continue;
1128 }
1129 1110
1130 default: 1111 default:
1131 set_detailed_error("Illegal frame type."); 1112 set_detailed_error("Illegal frame type.");
1132 QUIC_DLOG(WARNING) << ENDPOINT << "Illegal frame type: " 1113 QUIC_DLOG(WARNING) << ENDPOINT << "Illegal frame type: "
1133 << static_cast<int>(frame_type); 1114 << static_cast<int>(frame_type);
1134 return RaiseError(QUIC_INVALID_FRAME_DATA); 1115 return RaiseError(QUIC_INVALID_FRAME_DATA);
1135 } 1116 }
1136 } 1117 }
1137 1118
1138 return true; 1119 return true;
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 bool QuicFramer::ProcessBlockedFrame(QuicDataReader* reader, 1423 bool QuicFramer::ProcessBlockedFrame(QuicDataReader* reader,
1443 QuicBlockedFrame* frame) { 1424 QuicBlockedFrame* frame) {
1444 if (!reader->ReadUInt32(&frame->stream_id)) { 1425 if (!reader->ReadUInt32(&frame->stream_id)) {
1445 set_detailed_error("Unable to read stream_id."); 1426 set_detailed_error("Unable to read stream_id.");
1446 return false; 1427 return false;
1447 } 1428 }
1448 1429
1449 return true; 1430 return true;
1450 } 1431 }
1451 1432
1452 bool QuicFramer::ProcessPathCloseFrame(QuicDataReader* reader,
1453 QuicPathCloseFrame* frame) {
1454 if (!reader->ReadBytes(&frame->path_id, 1)) {
1455 set_detailed_error("Unable to read path_id.");
1456 return false;
1457 }
1458
1459 return true;
1460 }
1461
1462 // static 1433 // static
1463 QuicStringPiece QuicFramer::GetAssociatedDataFromEncryptedPacket( 1434 QuicStringPiece QuicFramer::GetAssociatedDataFromEncryptedPacket(
1464 QuicVersion version, 1435 QuicVersion version,
1465 const QuicEncryptedPacket& encrypted, 1436 const QuicEncryptedPacket& encrypted,
1466 QuicConnectionIdLength connection_id_length, 1437 QuicConnectionIdLength connection_id_length,
1467 bool includes_version, 1438 bool includes_version,
1468 bool includes_diversification_nonce, 1439 bool includes_diversification_nonce,
1469 QuicPacketNumberLength packet_number_length) { 1440 QuicPacketNumberLength packet_number_length) {
1470 // TODO(ianswett): This is identical to QuicData::AssociatedData. 1441 // TODO(ianswett): This is identical to QuicData::AssociatedData.
1471 return QuicStringPiece( 1442 return QuicStringPiece(
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 return GetRstStreamFrameSize(); 1663 return GetRstStreamFrameSize();
1693 case CONNECTION_CLOSE_FRAME: 1664 case CONNECTION_CLOSE_FRAME:
1694 return GetMinConnectionCloseFrameSize() + 1665 return GetMinConnectionCloseFrameSize() +
1695 frame.connection_close_frame->error_details.size(); 1666 frame.connection_close_frame->error_details.size();
1696 case GOAWAY_FRAME: 1667 case GOAWAY_FRAME:
1697 return GetMinGoAwayFrameSize() + frame.goaway_frame->reason_phrase.size(); 1668 return GetMinGoAwayFrameSize() + frame.goaway_frame->reason_phrase.size();
1698 case WINDOW_UPDATE_FRAME: 1669 case WINDOW_UPDATE_FRAME:
1699 return GetWindowUpdateFrameSize(); 1670 return GetWindowUpdateFrameSize();
1700 case BLOCKED_FRAME: 1671 case BLOCKED_FRAME:
1701 return GetBlockedFrameSize(); 1672 return GetBlockedFrameSize();
1702 case PATH_CLOSE_FRAME:
1703 return GetPathCloseFrameSize();
1704 case PADDING_FRAME: 1673 case PADDING_FRAME:
1705 DCHECK(false); 1674 DCHECK(false);
1706 return 0; 1675 return 0;
1707 case NUM_FRAME_TYPES: 1676 case NUM_FRAME_TYPES:
1708 DCHECK(false); 1677 DCHECK(false);
1709 return 0; 1678 return 0;
1710 } 1679 }
1711 1680
1712 // Not reachable, but some Chrome compilers can't figure that out. *sigh* 1681 // Not reachable, but some Chrome compilers can't figure that out. *sigh*
1713 DCHECK(false); 1682 DCHECK(false);
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
2127 2096
2128 bool QuicFramer::AppendBlockedFrame(const QuicBlockedFrame& frame, 2097 bool QuicFramer::AppendBlockedFrame(const QuicBlockedFrame& frame,
2129 QuicDataWriter* writer) { 2098 QuicDataWriter* writer) {
2130 uint32_t stream_id = static_cast<uint32_t>(frame.stream_id); 2099 uint32_t stream_id = static_cast<uint32_t>(frame.stream_id);
2131 if (!writer->WriteUInt32(stream_id)) { 2100 if (!writer->WriteUInt32(stream_id)) {
2132 return false; 2101 return false;
2133 } 2102 }
2134 return true; 2103 return true;
2135 } 2104 }
2136 2105
2137 bool QuicFramer::AppendPathCloseFrame(const QuicPathCloseFrame& frame,
2138 QuicDataWriter* writer) {
2139 uint8_t path_id = static_cast<uint8_t>(frame.path_id);
2140 if (!writer->WriteUInt8(path_id)) {
2141 return false;
2142 }
2143 return true;
2144 }
2145
2146 bool QuicFramer::RaiseError(QuicErrorCode error) { 2106 bool QuicFramer::RaiseError(QuicErrorCode error) {
2147 QUIC_DLOG(INFO) << ENDPOINT << "Error: " << QuicErrorCodeToString(error) 2107 QUIC_DLOG(INFO) << ENDPOINT << "Error: " << QuicErrorCodeToString(error)
2148 << " detail: " << detailed_error_; 2108 << " detail: " << detailed_error_;
2149 set_error(error); 2109 set_error(error);
2150 visitor_->OnError(this); 2110 visitor_->OnError(this);
2151 return false; 2111 return false;
2152 } 2112 }
2153 2113
2154 } // namespace net 2114 } // 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