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

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

Issue 2963763003: In QUIC, send data is copied to streams rather than frames. Protected by FLAGS_quic_reloadable_flag… (Closed)
Patch Set: Rebase Created 3 years, 5 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_headers_stream_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"
11 #include "net/quic/core/crypto/crypto_framer.h" 11 #include "net/quic/core/crypto/crypto_framer.h"
12 #include "net/quic/core/crypto/crypto_handshake_message.h" 12 #include "net/quic/core/crypto/crypto_handshake_message.h"
13 #include "net/quic/core/crypto/crypto_protocol.h" 13 #include "net/quic/core/crypto/crypto_protocol.h"
14 #include "net/quic/core/crypto/null_decrypter.h" 14 #include "net/quic/core/crypto/null_decrypter.h"
15 #include "net/quic/core/crypto/null_encrypter.h" 15 #include "net/quic/core/crypto/null_encrypter.h"
16 #include "net/quic/core/crypto/quic_decrypter.h" 16 #include "net/quic/core/crypto/quic_decrypter.h"
17 #include "net/quic/core/crypto/quic_encrypter.h" 17 #include "net/quic/core/crypto/quic_encrypter.h"
18 #include "net/quic/core/quic_data_reader.h" 18 #include "net/quic/core/quic_data_reader.h"
19 #include "net/quic/core/quic_data_writer.h" 19 #include "net/quic/core/quic_data_writer.h"
20 #include "net/quic/core/quic_socket_address_coder.h" 20 #include "net/quic/core/quic_socket_address_coder.h"
21 #include "net/quic/core/quic_stream_frame_data_producer.h"
21 #include "net/quic/core/quic_utils.h" 22 #include "net/quic/core/quic_utils.h"
22 #include "net/quic/platform/api/quic_aligned.h" 23 #include "net/quic/platform/api/quic_aligned.h"
23 #include "net/quic/platform/api/quic_bug_tracker.h" 24 #include "net/quic/platform/api/quic_bug_tracker.h"
24 #include "net/quic/platform/api/quic_flag_utils.h" 25 #include "net/quic/platform/api/quic_flag_utils.h"
25 #include "net/quic/platform/api/quic_flags.h" 26 #include "net/quic/platform/api/quic_flags.h"
26 #include "net/quic/platform/api/quic_logging.h" 27 #include "net/quic/platform/api/quic_logging.h"
27 #include "net/quic/platform/api/quic_map_util.h" 28 #include "net/quic/platform/api/quic_map_util.h"
28 #include "net/quic/platform/api/quic_ptr_util.h" 29 #include "net/quic/platform/api/quic_ptr_util.h"
29 30
30 using std::string; 31 using std::string;
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 QuicFramer::AckFrameInfo::AckFrameInfo() 306 QuicFramer::AckFrameInfo::AckFrameInfo()
306 : max_block_length(0), first_block_length(0), num_ack_blocks(0) {} 307 : max_block_length(0), first_block_length(0), num_ack_blocks(0) {}
307 308
308 QuicFramer::AckFrameInfo::AckFrameInfo(const AckFrameInfo& other) = default; 309 QuicFramer::AckFrameInfo::AckFrameInfo(const AckFrameInfo& other) = default;
309 310
310 QuicFramer::AckFrameInfo::~AckFrameInfo() {} 311 QuicFramer::AckFrameInfo::~AckFrameInfo() {}
311 312
312 size_t QuicFramer::BuildDataPacket(const QuicPacketHeader& header, 313 size_t QuicFramer::BuildDataPacket(const QuicPacketHeader& header,
313 const QuicFrames& frames, 314 const QuicFrames& frames,
314 char* buffer, 315 char* buffer,
315 size_t packet_length) { 316 size_t packet_length,
317 QuicStreamFrameDataProducer* data_producer) {
316 QuicDataWriter writer(packet_length, buffer, perspective_, endianness()); 318 QuicDataWriter writer(packet_length, buffer, perspective_, endianness());
317 if (!AppendPacketHeader(header, &writer)) { 319 if (!AppendPacketHeader(header, &writer)) {
318 QUIC_BUG << "AppendPacketHeader failed"; 320 QUIC_BUG << "AppendPacketHeader failed";
319 return 0; 321 return 0;
320 } 322 }
321 323
322 size_t i = 0; 324 size_t i = 0;
323 for (const QuicFrame& frame : frames) { 325 for (const QuicFrame& frame : frames) {
324 // Determine if we should write stream frame length in header. 326 // Determine if we should write stream frame length in header.
325 const bool no_stream_frame_length = i == frames.size() - 1; 327 const bool no_stream_frame_length = i == frames.size() - 1;
326 if (!AppendTypeByte(frame, no_stream_frame_length, &writer)) { 328 if (!AppendTypeByte(frame, no_stream_frame_length, &writer)) {
327 QUIC_BUG << "AppendTypeByte failed"; 329 QUIC_BUG << "AppendTypeByte failed";
328 return 0; 330 return 0;
329 } 331 }
330 332
331 switch (frame.type) { 333 switch (frame.type) {
332 case PADDING_FRAME: 334 case PADDING_FRAME:
333 if (!AppendPaddingFrame(frame.padding_frame, &writer)) { 335 if (!AppendPaddingFrame(frame.padding_frame, &writer)) {
334 QUIC_BUG << "AppendPaddingFrame of " 336 QUIC_BUG << "AppendPaddingFrame of "
335 << frame.padding_frame.num_padding_bytes << " failed"; 337 << frame.padding_frame.num_padding_bytes << " failed";
336 return 0; 338 return 0;
337 } 339 }
338 break; 340 break;
339 case STREAM_FRAME: 341 case STREAM_FRAME:
340 if (!AppendStreamFrame(*frame.stream_frame, no_stream_frame_length, 342 if (!AppendStreamFrame(*frame.stream_frame, no_stream_frame_length,
341 &writer)) { 343 &writer, data_producer)) {
342 QUIC_BUG << "AppendStreamFrame failed"; 344 QUIC_BUG << "AppendStreamFrame failed";
343 return 0; 345 return 0;
344 } 346 }
345 break; 347 break;
346 case ACK_FRAME: 348 case ACK_FRAME:
347 if (!AppendAckFrameAndTypeByte(*frame.ack_frame, &writer)) { 349 if (!AppendAckFrameAndTypeByte(*frame.ack_frame, &writer)) {
348 QUIC_BUG << "AppendAckFrameAndTypeByte failed"; 350 QUIC_BUG << "AppendAckFrameAndTypeByte failed";
349 return 0; 351 return 0;
350 } 352 }
351 break; 353 break;
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 bool QuicFramer::AppendAckBlock(uint8_t gap, 1783 bool QuicFramer::AppendAckBlock(uint8_t gap,
1782 QuicPacketNumberLength length_length, 1784 QuicPacketNumberLength length_length,
1783 QuicPacketNumber length, 1785 QuicPacketNumber length,
1784 QuicDataWriter* writer) { 1786 QuicDataWriter* writer) {
1785 return writer->WriteUInt8(gap) && 1787 return writer->WriteUInt8(gap) &&
1786 AppendPacketNumber(length_length, length, writer); 1788 AppendPacketNumber(length_length, length, writer);
1787 } 1789 }
1788 1790
1789 bool QuicFramer::AppendStreamFrame(const QuicStreamFrame& frame, 1791 bool QuicFramer::AppendStreamFrame(const QuicStreamFrame& frame,
1790 bool no_stream_frame_length, 1792 bool no_stream_frame_length,
1791 QuicDataWriter* writer) { 1793 QuicDataWriter* writer,
1794 QuicStreamFrameDataProducer* data_producer) {
1792 if (!AppendStreamId(GetStreamIdSize(frame.stream_id), frame.stream_id, 1795 if (!AppendStreamId(GetStreamIdSize(frame.stream_id), frame.stream_id,
1793 writer)) { 1796 writer)) {
1794 QUIC_BUG << "Writing stream id size failed."; 1797 QUIC_BUG << "Writing stream id size failed.";
1795 return false; 1798 return false;
1796 } 1799 }
1797 if (!AppendStreamOffset(GetStreamOffsetSize(frame.offset), frame.offset, 1800 if (!AppendStreamOffset(GetStreamOffsetSize(frame.offset), frame.offset,
1798 writer)) { 1801 writer)) {
1799 QUIC_BUG << "Writing offset size failed."; 1802 QUIC_BUG << "Writing offset size failed.";
1800 return false; 1803 return false;
1801 } 1804 }
1802 if (!no_stream_frame_length) { 1805 if (!no_stream_frame_length) {
1803 if ((frame.data_length > std::numeric_limits<uint16_t>::max()) || 1806 if ((frame.data_length > std::numeric_limits<uint16_t>::max()) ||
1804 !writer->WriteUInt16(static_cast<uint16_t>(frame.data_length))) { 1807 !writer->WriteUInt16(static_cast<uint16_t>(frame.data_length))) {
1805 QUIC_BUG << "Writing stream frame length failed"; 1808 QUIC_BUG << "Writing stream frame length failed";
1806 return false; 1809 return false;
1807 } 1810 }
1808 } 1811 }
1809 1812
1813 if (data_producer != nullptr) {
1814 DCHECK_EQ(nullptr, frame.data_buffer);
1815 if (frame.data_length == 0) {
1816 return true;
1817 }
1818 if (!data_producer->WriteStreamData(frame.stream_id, frame.offset,
1819 frame.data_length, writer)) {
1820 QUIC_BUG << "Writing frame data failed.";
1821 return false;
1822 }
1823 return true;
1824 }
1825
1810 if (!writer->WriteBytes(frame.data_buffer, frame.data_length)) { 1826 if (!writer->WriteBytes(frame.data_buffer, frame.data_length)) {
1811 QUIC_BUG << "Writing frame data failed."; 1827 QUIC_BUG << "Writing frame data failed.";
1812 return false; 1828 return false;
1813 } 1829 }
1814 return true; 1830 return true;
1815 } 1831 }
1816 1832
1817 void QuicFramer::set_version(const QuicVersion version) { 1833 void QuicFramer::set_version(const QuicVersion version) {
1818 DCHECK(IsSupportedVersion(version)) << QuicVersionToString(version); 1834 DCHECK(IsSupportedVersion(version)) << QuicVersionToString(version);
1819 quic_version_ = version; 1835 quic_version_ = version;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
2150 set_error(error); 2166 set_error(error);
2151 visitor_->OnError(this); 2167 visitor_->OnError(this);
2152 return false; 2168 return false;
2153 } 2169 }
2154 2170
2155 Endianness QuicFramer::endianness() const { 2171 Endianness QuicFramer::endianness() const {
2156 return quic_version_ > QUIC_VERSION_38 ? NETWORK_BYTE_ORDER : HOST_BYTE_ORDER; 2172 return quic_version_ > QUIC_VERSION_38 ? NETWORK_BYTE_ORDER : HOST_BYTE_ORDER;
2157 } 2173 }
2158 2174
2159 } // namespace net 2175 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_framer.h ('k') | net/quic/core/quic_headers_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698