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

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

Issue 2241183004: Landing Recent QUIC changes until Sat Aug 13 04:32:36 2016 UTC-0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compiler error. Created 4 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/core/quic_one_block_arena_test.cc ('k') | net/quic/core/quic_packet_creator_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_packet_creator.h" 5 #include "net/quic/core/quic_packet_creator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // change. 76 // change.
77 if (length == max_packet_length_) { 77 if (length == max_packet_length_) {
78 return; 78 return;
79 } 79 }
80 80
81 max_packet_length_ = length; 81 max_packet_length_ = length;
82 max_plaintext_size_ = framer_->GetMaxPlaintextSize(max_packet_length_); 82 max_plaintext_size_ = framer_->GetMaxPlaintextSize(max_packet_length_);
83 } 83 }
84 84
85 void QuicPacketCreator::MaybeUpdatePacketNumberLength() { 85 void QuicPacketCreator::MaybeUpdatePacketNumberLength() {
86 DCHECK(!FLAGS_quic_simple_packet_number_length); 86 DCHECK(!FLAGS_quic_simple_packet_number_length_2);
87 if (!queued_frames_.empty()) { 87 if (!queued_frames_.empty()) {
88 // Don't change creator state if there are frames queued. 88 // Don't change creator state if there are frames queued.
89 return; 89 return;
90 } 90 }
91 91
92 // Update packet number length only on packet boundary. 92 // Update packet number length only on packet boundary.
93 packet_.packet_number_length = next_packet_number_length_; 93 packet_.packet_number_length = next_packet_number_length_;
94 } 94 }
95 95
96 // Stops serializing version of the protocol in packets sent after this call. 96 // Stops serializing version of the protocol in packets sent after this call.
(...skipping 11 matching lines...) Expand all
108 void QuicPacketCreator::SetDiversificationNonce( 108 void QuicPacketCreator::SetDiversificationNonce(
109 const DiversificationNonce nonce) { 109 const DiversificationNonce nonce) {
110 DCHECK(!have_diversification_nonce_); 110 DCHECK(!have_diversification_nonce_);
111 have_diversification_nonce_ = true; 111 have_diversification_nonce_ = true;
112 memcpy(&diversification_nonce_, nonce, sizeof(diversification_nonce_)); 112 memcpy(&diversification_nonce_, nonce, sizeof(diversification_nonce_));
113 } 113 }
114 114
115 void QuicPacketCreator::UpdatePacketNumberLength( 115 void QuicPacketCreator::UpdatePacketNumberLength(
116 QuicPacketNumber least_packet_awaited_by_peer, 116 QuicPacketNumber least_packet_awaited_by_peer,
117 QuicPacketCount max_packets_in_flight) { 117 QuicPacketCount max_packets_in_flight) {
118 if (FLAGS_quic_simple_packet_number_length && !queued_frames_.empty()) { 118 if (FLAGS_quic_simple_packet_number_length_2 && !queued_frames_.empty()) {
119 // Don't change creator state if there are frames queued. 119 // Don't change creator state if there are frames queued.
120 QUIC_BUG << "Called UpdatePacketNumberLength with " << queued_frames_.size() 120 QUIC_BUG << "Called UpdatePacketNumberLength with " << queued_frames_.size()
121 << " queued_frames. First frame type:" 121 << " queued_frames. First frame type:"
122 << queued_frames_.front().type 122 << queued_frames_.front().type
123 << " last frame type:" << queued_frames_.back().type; 123 << " last frame type:" << queued_frames_.back().type;
124 return; 124 return;
125 } 125 }
126 126
127 DCHECK_LE(least_packet_awaited_by_peer, packet_.packet_number + 1); 127 DCHECK_LE(least_packet_awaited_by_peer, packet_.packet_number + 1);
128 const QuicPacketNumber current_delta = 128 const QuicPacketNumber current_delta =
129 packet_.packet_number + 1 - least_packet_awaited_by_peer; 129 packet_.packet_number + 1 - least_packet_awaited_by_peer;
130 const uint64_t delta = max(current_delta, max_packets_in_flight); 130 const uint64_t delta = max(current_delta, max_packets_in_flight);
131 if (FLAGS_quic_simple_packet_number_length) { 131 if (FLAGS_quic_simple_packet_number_length_2) {
132 packet_.packet_number_length = 132 packet_.packet_number_length =
133 QuicFramer::GetMinSequenceNumberLength(delta * 4); 133 QuicFramer::GetMinSequenceNumberLength(delta * 4);
134 } else { 134 } else {
135 next_packet_number_length_ = 135 next_packet_number_length_ =
136 QuicFramer::GetMinSequenceNumberLength(delta * 4); 136 QuicFramer::GetMinSequenceNumberLength(delta * 4);
137 } 137 }
138 } 138 }
139 139
140 bool QuicPacketCreator::ConsumeData(QuicStreamId id, 140 bool QuicPacketCreator::ConsumeData(QuicStreamId id,
141 QuicIOVector iov, 141 QuicIOVector iov,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 size_t iov_offset, 202 size_t iov_offset,
203 QuicStreamOffset offset, 203 QuicStreamOffset offset,
204 bool fin, 204 bool fin,
205 QuicFrame* frame) { 205 QuicFrame* frame) {
206 DCHECK_GT(max_packet_length_, 206 DCHECK_GT(max_packet_length_,
207 StreamFramePacketOverhead(framer_->version(), connection_id_length_, 207 StreamFramePacketOverhead(framer_->version(), connection_id_length_,
208 kIncludeVersion, kIncludePathId, 208 kIncludeVersion, kIncludePathId,
209 IncludeNonceInPublicHeader(), 209 IncludeNonceInPublicHeader(),
210 PACKET_6BYTE_PACKET_NUMBER, offset)); 210 PACKET_6BYTE_PACKET_NUMBER, offset));
211 211
212 if (!FLAGS_quic_simple_packet_number_length) { 212 if (!FLAGS_quic_simple_packet_number_length_2) {
213 MaybeUpdatePacketNumberLength(); 213 MaybeUpdatePacketNumberLength();
214 } 214 }
215 QUIC_BUG_IF(!HasRoomForStreamFrame(id, offset)) 215 QUIC_BUG_IF(!HasRoomForStreamFrame(id, offset))
216 << "No room for Stream frame, BytesFree: " << BytesFree() 216 << "No room for Stream frame, BytesFree: " << BytesFree()
217 << " MinStreamFrameSize: " 217 << " MinStreamFrameSize: "
218 << QuicFramer::GetMinStreamFrameSize(id, offset, true); 218 << QuicFramer::GetMinStreamFrameSize(id, offset, true);
219 219
220 if (iov_offset == iov.total_length) { 220 if (iov_offset == iov.total_length) {
221 QUIC_BUG_IF(!fin) << "Creating a stream frame with no data or fin."; 221 QUIC_BUG_IF(!fin) << "Creating a stream frame with no data or fin.";
222 // Create a new packet for the fin, if necessary. 222 // Create a new packet for the fin, if necessary.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 DCHECK(queued_frames_.empty()); 297 DCHECK(queued_frames_.empty());
298 DCHECK_EQ(0, packet_.num_padding_bytes); 298 DCHECK_EQ(0, packet_.num_padding_bytes);
299 QUIC_BUG_IF(retransmission.retransmittable_frames.empty()) 299 QUIC_BUG_IF(retransmission.retransmittable_frames.empty())
300 << "Attempt to serialize empty packet"; 300 << "Attempt to serialize empty packet";
301 const QuicPacketNumberLength saved_length = packet_.packet_number_length; 301 const QuicPacketNumberLength saved_length = packet_.packet_number_length;
302 const QuicPacketNumberLength saved_next_length = next_packet_number_length_; 302 const QuicPacketNumberLength saved_next_length = next_packet_number_length_;
303 const EncryptionLevel default_encryption_level = packet_.encryption_level; 303 const EncryptionLevel default_encryption_level = packet_.encryption_level;
304 304
305 // Temporarily set the packet number length and change the encryption level. 305 // Temporarily set the packet number length and change the encryption level.
306 packet_.packet_number_length = retransmission.packet_number_length; 306 packet_.packet_number_length = retransmission.packet_number_length;
307 if (!FLAGS_quic_simple_packet_number_length) { 307 if (!FLAGS_quic_simple_packet_number_length_2) {
308 next_packet_number_length_ = retransmission.packet_number_length; 308 next_packet_number_length_ = retransmission.packet_number_length;
309 } 309 }
310 packet_.num_padding_bytes = retransmission.num_padding_bytes; 310 packet_.num_padding_bytes = retransmission.num_padding_bytes;
311 // Only preserve the original encryption level if it's a handshake packet or 311 // Only preserve the original encryption level if it's a handshake packet or
312 // if we haven't gone forward secure. 312 // if we haven't gone forward secure.
313 if (retransmission.has_crypto_handshake || 313 if (retransmission.has_crypto_handshake ||
314 packet_.encryption_level != ENCRYPTION_FORWARD_SECURE) { 314 packet_.encryption_level != ENCRYPTION_FORWARD_SECURE) {
315 packet_.encryption_level = retransmission.encryption_level; 315 packet_.encryption_level = retransmission.encryption_level;
316 } 316 }
317 317
318 // Serialize the packet and restore packet number length state. 318 // Serialize the packet and restore packet number length state.
319 for (const QuicFrame& frame : retransmission.retransmittable_frames) { 319 for (const QuicFrame& frame : retransmission.retransmittable_frames) {
320 bool success = AddFrame(frame, false); 320 bool success = AddFrame(frame, false);
321 LOG_IF(DFATAL, !success) 321 QUIC_BUG_IF(!success) << " Failed to add frame of type:" << frame.type
322 << " Failed to add frame of type:" << frame.type 322 << " num_frames:"
323 << " num_frames:" << retransmission.retransmittable_frames.size() 323 << retransmission.retransmittable_frames.size()
324 << " retransmission.packet_number_length:" 324 << " retransmission.packet_number_length:"
325 << retransmission.packet_number_length 325 << retransmission.packet_number_length
326 << " packet_.packet_number_length:" << packet_.packet_number_length; 326 << " packet_.packet_number_length:"
327 << packet_.packet_number_length;
327 } 328 }
328 SerializePacket(buffer, buffer_len); 329 SerializePacket(buffer, buffer_len);
329 packet_.original_path_id = retransmission.path_id; 330 packet_.original_path_id = retransmission.path_id;
330 packet_.original_packet_number = retransmission.packet_number; 331 packet_.original_packet_number = retransmission.packet_number;
331 packet_.transmission_type = retransmission.transmission_type; 332 packet_.transmission_type = retransmission.transmission_type;
332 OnSerializedPacket(); 333 OnSerializedPacket();
333 // Restore old values. 334 // Restore old values.
334 if (!FLAGS_quic_simple_packet_number_length) { 335 if (!FLAGS_quic_simple_packet_number_length_2) {
335 // OnSerializedPacket updates the packet_number_length, so it's incorrect to 336 // OnSerializedPacket updates the packet_number_length, so it's incorrect to
336 // restore it here. 337 // restore it here.
337 packet_.packet_number_length = saved_length; 338 packet_.packet_number_length = saved_length;
338 next_packet_number_length_ = saved_next_length; 339 next_packet_number_length_ = saved_next_length;
339 } 340 }
340 packet_.encryption_level = default_encryption_level; 341 packet_.encryption_level = default_encryption_level;
341 } 342 }
342 343
343 void QuicPacketCreator::Flush() { 344 void QuicPacketCreator::Flush() {
344 if (!HasPendingFrames()) { 345 if (!HasPendingFrames()) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 DCHECK_GE(max_plaintext_size_, PacketSize()); 480 DCHECK_GE(max_plaintext_size_, PacketSize());
480 return max_plaintext_size_ - 481 return max_plaintext_size_ -
481 min(max_plaintext_size_, PacketSize() + ExpansionOnNewFrame()); 482 min(max_plaintext_size_, PacketSize() + ExpansionOnNewFrame());
482 } 483 }
483 484
484 size_t QuicPacketCreator::PacketSize() { 485 size_t QuicPacketCreator::PacketSize() {
485 if (!queued_frames_.empty()) { 486 if (!queued_frames_.empty()) {
486 return packet_size_; 487 return packet_size_;
487 } 488 }
488 // Update packet number length on packet boundary. 489 // Update packet number length on packet boundary.
489 if (!FLAGS_quic_simple_packet_number_length) { 490 if (!FLAGS_quic_simple_packet_number_length_2) {
490 packet_.packet_number_length = next_packet_number_length_; 491 packet_.packet_number_length = next_packet_number_length_;
491 } 492 }
492 packet_size_ = GetPacketHeaderSize( 493 packet_size_ = GetPacketHeaderSize(
493 framer_->version(), connection_id_length_, send_version_in_packet_, 494 framer_->version(), connection_id_length_, send_version_in_packet_,
494 send_path_id_in_packet_, IncludeNonceInPublicHeader(), 495 send_path_id_in_packet_, IncludeNonceInPublicHeader(),
495 packet_.packet_number_length); 496 packet_.packet_number_length);
496 return packet_size_; 497 return packet_size_;
497 } 498 }
498 499
499 bool QuicPacketCreator::AddSavedFrame(const QuicFrame& frame) { 500 bool QuicPacketCreator::AddSavedFrame(const QuicFrame& frame) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 if (FLAGS_quic_never_write_unencrypted_data && frame.type == STREAM_FRAME && 615 if (FLAGS_quic_never_write_unencrypted_data && frame.type == STREAM_FRAME &&
615 frame.stream_frame->stream_id != kCryptoStreamId && 616 frame.stream_frame->stream_id != kCryptoStreamId &&
616 packet_.encryption_level == ENCRYPTION_NONE) { 617 packet_.encryption_level == ENCRYPTION_NONE) {
617 const string error_details = "Cannot send stream data without encryption."; 618 const string error_details = "Cannot send stream data without encryption.";
618 QUIC_BUG << error_details; 619 QUIC_BUG << error_details;
619 delegate_->OnUnrecoverableError( 620 delegate_->OnUnrecoverableError(
620 QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA, error_details, 621 QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA, error_details,
621 ConnectionCloseSource::FROM_SELF); 622 ConnectionCloseSource::FROM_SELF);
622 return false; 623 return false;
623 } 624 }
624 if (!FLAGS_quic_simple_packet_number_length) { 625 if (!FLAGS_quic_simple_packet_number_length_2) {
625 MaybeUpdatePacketNumberLength(); 626 MaybeUpdatePacketNumberLength();
626 } 627 }
627 size_t frame_len = framer_->GetSerializedFrameLength( 628 size_t frame_len = framer_->GetSerializedFrameLength(
628 frame, BytesFree(), queued_frames_.empty(), true, 629 frame, BytesFree(), queued_frames_.empty(), true,
629 packet_.packet_number_length); 630 packet_.packet_number_length);
630 if (frame_len == 0) { 631 if (frame_len == 0) {
631 // Current open packet is full. 632 // Current open packet is full.
632 Flush(); 633 Flush();
633 return false; 634 return false;
634 } 635 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 if (bit_mask_ == 0) { 719 if (bit_mask_ == 0) {
719 bit_bucket_ = random_->RandUint64(); 720 bit_bucket_ = random_->RandUint64();
720 bit_mask_ = 1; 721 bit_mask_ = 1;
721 } 722 }
722 bool result = ((bit_bucket_ & bit_mask_) != 0); 723 bool result = ((bit_bucket_ & bit_mask_) != 0);
723 bit_mask_ <<= 1; 724 bit_mask_ <<= 1;
724 return result; 725 return result;
725 } 726 }
726 727
727 } // namespace net 728 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_one_block_arena_test.cc ('k') | net/quic/core/quic_packet_creator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698