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

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

Issue 1979763002: Landing Recent QUIC changes until Sun May 8 00:39:29 2016 +0000 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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_flow_controller_test.cc ('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 <cstdint> 7 #include <cstdint>
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 if (!reader->ReadStringPiece16(&data)) { 1371 if (!reader->ReadStringPiece16(&data)) {
1372 set_detailed_error("Unable to read frame data."); 1372 set_detailed_error("Unable to read frame data.");
1373 return false; 1373 return false;
1374 } 1374 }
1375 } else { 1375 } else {
1376 if (!reader->ReadStringPiece(&data, reader->BytesRemaining())) { 1376 if (!reader->ReadStringPiece(&data, reader->BytesRemaining())) {
1377 set_detailed_error("Unable to read frame data."); 1377 set_detailed_error("Unable to read frame data.");
1378 return false; 1378 return false;
1379 } 1379 }
1380 } 1380 }
1381 frame->frame_buffer = data.data(); 1381 frame->data_buffer = data.data();
1382 frame->frame_length = static_cast<uint16_t>(data.length()); 1382 frame->data_length = static_cast<uint16_t>(data.length());
1383 1383
1384 return true; 1384 return true;
1385 } 1385 }
1386 1386
1387 bool QuicFramer::ProcessAckFrame(QuicDataReader* reader, 1387 bool QuicFramer::ProcessAckFrame(QuicDataReader* reader,
1388 uint8_t frame_type, 1388 uint8_t frame_type,
1389 QuicAckFrame* ack_frame) { 1389 QuicAckFrame* ack_frame) {
1390 // Determine the three lengths from the frame type: largest observed length, 1390 // Determine the three lengths from the frame type: largest observed length,
1391 // missing packet number length, and missing range length. 1391 // missing packet number length, and missing range length.
1392 const QuicPacketNumberLength missing_packet_number_length = 1392 const QuicPacketNumberLength missing_packet_number_length =
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 return false; 1654 return false;
1655 } 1655 }
1656 1656
1657 uint32_t error_code; 1657 uint32_t error_code;
1658 if (!reader->ReadUInt32(&error_code)) { 1658 if (!reader->ReadUInt32(&error_code)) {
1659 set_detailed_error("Unable to read rst stream error code."); 1659 set_detailed_error("Unable to read rst stream error code.");
1660 return false; 1660 return false;
1661 } 1661 }
1662 1662
1663 if (error_code >= QUIC_STREAM_LAST_ERROR) { 1663 if (error_code >= QUIC_STREAM_LAST_ERROR) {
1664 if (FLAGS_quic_ignore_invalid_error_code) { 1664 // Ignore invalid stream error code if any.
1665 // Ignore invalid stream error code if any. 1665 error_code = QUIC_STREAM_LAST_ERROR;
1666 error_code = QUIC_STREAM_LAST_ERROR;
1667 } else {
1668 set_detailed_error("Invalid rst stream error code.");
1669 return false;
1670 }
1671 } 1666 }
1672 1667
1673 frame->error_code = static_cast<QuicRstStreamErrorCode>(error_code); 1668 frame->error_code = static_cast<QuicRstStreamErrorCode>(error_code);
1674 return true; 1669 return true;
1675 } 1670 }
1676 1671
1677 bool QuicFramer::ProcessConnectionCloseFrame(QuicDataReader* reader, 1672 bool QuicFramer::ProcessConnectionCloseFrame(QuicDataReader* reader,
1678 QuicConnectionCloseFrame* frame) { 1673 QuicConnectionCloseFrame* frame) {
1679 uint32_t error_code; 1674 uint32_t error_code;
1680 if (!reader->ReadUInt32(&error_code)) { 1675 if (!reader->ReadUInt32(&error_code)) {
1681 set_detailed_error("Unable to read connection close error code."); 1676 set_detailed_error("Unable to read connection close error code.");
1682 return false; 1677 return false;
1683 } 1678 }
1684 1679
1685 if (error_code >= QUIC_LAST_ERROR) { 1680 if (error_code >= QUIC_LAST_ERROR) {
1686 if (FLAGS_quic_ignore_invalid_error_code) { 1681 // Ignore invalid QUIC error code if any.
1687 // Ignore invalid QUIC error code if any. 1682 error_code = QUIC_LAST_ERROR;
1688 error_code = QUIC_LAST_ERROR;
1689 } else {
1690 set_detailed_error("Invalid error code.");
1691 return false;
1692 }
1693 } 1683 }
1694 1684
1695 frame->error_code = static_cast<QuicErrorCode>(error_code); 1685 frame->error_code = static_cast<QuicErrorCode>(error_code);
1696 1686
1697 StringPiece error_details; 1687 StringPiece error_details;
1698 if (!reader->ReadStringPiece16(&error_details)) { 1688 if (!reader->ReadStringPiece16(&error_details)) {
1699 set_detailed_error("Unable to read connection close error details."); 1689 set_detailed_error("Unable to read connection close error details.");
1700 return false; 1690 return false;
1701 } 1691 }
1702 frame->error_details = error_details.as_string(); 1692 frame->error_details = error_details.as_string();
1703 1693
1704 return true; 1694 return true;
1705 } 1695 }
1706 1696
1707 bool QuicFramer::ProcessGoAwayFrame(QuicDataReader* reader, 1697 bool QuicFramer::ProcessGoAwayFrame(QuicDataReader* reader,
1708 QuicGoAwayFrame* frame) { 1698 QuicGoAwayFrame* frame) {
1709 uint32_t error_code; 1699 uint32_t error_code;
1710 if (!reader->ReadUInt32(&error_code)) { 1700 if (!reader->ReadUInt32(&error_code)) {
1711 set_detailed_error("Unable to read go away error code."); 1701 set_detailed_error("Unable to read go away error code.");
1712 return false; 1702 return false;
1713 } 1703 }
1714 1704
1715 if (error_code >= QUIC_LAST_ERROR) { 1705 if (error_code >= QUIC_LAST_ERROR) {
1716 if (FLAGS_quic_ignore_invalid_error_code) { 1706 // Ignore invalid QUIC error code if any.
1717 // Ignore invalid QUIC error code if any. 1707 error_code = QUIC_LAST_ERROR;
1718 error_code = QUIC_LAST_ERROR;
1719 } else {
1720 set_detailed_error("Invalid error code.");
1721 return false;
1722 }
1723 } 1708 }
1724 frame->error_code = static_cast<QuicErrorCode>(error_code); 1709 frame->error_code = static_cast<QuicErrorCode>(error_code);
1725 1710
1726 uint32_t stream_id; 1711 uint32_t stream_id;
1727 if (!reader->ReadUInt32(&stream_id)) { 1712 if (!reader->ReadUInt32(&stream_id)) {
1728 set_detailed_error("Unable to read last good stream id."); 1713 set_detailed_error("Unable to read last good stream id.");
1729 return false; 1714 return false;
1730 } 1715 }
1731 frame->last_good_stream_id = static_cast<QuicStreamId>(stream_id); 1716 frame->last_good_stream_id = static_cast<QuicStreamId>(stream_id);
1732 1717
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
2012 1997
2013 size_t QuicFramer::ComputeFrameLength( 1998 size_t QuicFramer::ComputeFrameLength(
2014 const QuicFrame& frame, 1999 const QuicFrame& frame,
2015 bool last_frame_in_packet, 2000 bool last_frame_in_packet,
2016 QuicPacketNumberLength packet_number_length) { 2001 QuicPacketNumberLength packet_number_length) {
2017 switch (frame.type) { 2002 switch (frame.type) {
2018 case STREAM_FRAME: 2003 case STREAM_FRAME:
2019 return GetMinStreamFrameSize(frame.stream_frame->stream_id, 2004 return GetMinStreamFrameSize(frame.stream_frame->stream_id,
2020 frame.stream_frame->offset, 2005 frame.stream_frame->offset,
2021 last_frame_in_packet) + 2006 last_frame_in_packet) +
2022 frame.stream_frame->frame_length; 2007 frame.stream_frame->data_length;
2023 case ACK_FRAME: { 2008 case ACK_FRAME: {
2024 return GetAckFrameSize(*frame.ack_frame, packet_number_length); 2009 return GetAckFrameSize(*frame.ack_frame, packet_number_length);
2025 } 2010 }
2026 case STOP_WAITING_FRAME: 2011 case STOP_WAITING_FRAME:
2027 return GetStopWaitingFrameSize(quic_version_, packet_number_length); 2012 return GetStopWaitingFrameSize(quic_version_, packet_number_length);
2028 case MTU_DISCOVERY_FRAME: 2013 case MTU_DISCOVERY_FRAME:
2029 // MTU discovery frames are serialized as ping frames. 2014 // MTU discovery frames are serialized as ping frames.
2030 case PING_FRAME: 2015 case PING_FRAME:
2031 // Ping has no payload. 2016 // Ping has no payload.
2032 return kQuicFrameTypeSize; 2017 return kQuicFrameTypeSize;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2132 QuicDataWriter* writer) { 2117 QuicDataWriter* writer) {
2133 if (!writer->WriteBytes(&frame.stream_id, GetStreamIdSize(frame.stream_id))) { 2118 if (!writer->WriteBytes(&frame.stream_id, GetStreamIdSize(frame.stream_id))) {
2134 QUIC_BUG << "Writing stream id size failed."; 2119 QUIC_BUG << "Writing stream id size failed.";
2135 return false; 2120 return false;
2136 } 2121 }
2137 if (!writer->WriteBytes(&frame.offset, GetStreamOffsetSize(frame.offset))) { 2122 if (!writer->WriteBytes(&frame.offset, GetStreamOffsetSize(frame.offset))) {
2138 QUIC_BUG << "Writing offset size failed."; 2123 QUIC_BUG << "Writing offset size failed.";
2139 return false; 2124 return false;
2140 } 2125 }
2141 if (!no_stream_frame_length) { 2126 if (!no_stream_frame_length) {
2142 if ((frame.frame_length > numeric_limits<uint16_t>::max()) || 2127 if ((frame.data_length > numeric_limits<uint16_t>::max()) ||
2143 !writer->WriteUInt16(static_cast<uint16_t>(frame.frame_length))) { 2128 !writer->WriteUInt16(static_cast<uint16_t>(frame.data_length))) {
2144 QUIC_BUG << "Writing stream frame length failed"; 2129 QUIC_BUG << "Writing stream frame length failed";
2145 return false; 2130 return false;
2146 } 2131 }
2147 } 2132 }
2148 2133
2149 if (!writer->WriteBytes(frame.frame_buffer, frame.frame_length)) { 2134 if (!writer->WriteBytes(frame.data_buffer, frame.data_length)) {
2150 QUIC_BUG << "Writing frame data failed."; 2135 QUIC_BUG << "Writing frame data failed.";
2151 return false; 2136 return false;
2152 } 2137 }
2153 return true; 2138 return true;
2154 } 2139 }
2155 2140
2156 void QuicFramer::set_version(const QuicVersion version) { 2141 void QuicFramer::set_version(const QuicVersion version) {
2157 DCHECK(IsSupportedVersion(version)) << QuicVersionToString(version); 2142 DCHECK(IsSupportedVersion(version)) << QuicVersionToString(version);
2158 quic_version_ = version; 2143 quic_version_ = version;
2159 } 2144 }
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
2580 2565
2581 bool QuicFramer::RaiseError(QuicErrorCode error) { 2566 bool QuicFramer::RaiseError(QuicErrorCode error) {
2582 DVLOG(1) << "Error: " << QuicUtils::ErrorToString(error) 2567 DVLOG(1) << "Error: " << QuicUtils::ErrorToString(error)
2583 << " detail: " << detailed_error_; 2568 << " detail: " << detailed_error_;
2584 set_error(error); 2569 set_error(error);
2585 visitor_->OnError(this); 2570 visitor_->OnError(this);
2586 return false; 2571 return false;
2587 } 2572 }
2588 2573
2589 } // namespace net 2574 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_flow_controller_test.cc ('k') | net/quic/quic_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698