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

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

Issue 1658393003: Make a SerializedPacket a member variable of QuicPacketCreator to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@113076102
Patch Set: Created 4 years, 10 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_packet_creator.h ('k') | net/quic/test_tools/quic_packet_creator_peer.h » ('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_packet_creator.h" 5 #include "net/quic/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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 DelegateInterface* delegate) 87 DelegateInterface* delegate)
88 : delegate_(delegate), 88 : delegate_(delegate),
89 debug_delegate_(nullptr), 89 debug_delegate_(nullptr),
90 framer_(framer), 90 framer_(framer),
91 random_bool_source_(new QuicRandomBoolSource(random_generator)), 91 random_bool_source_(new QuicRandomBoolSource(random_generator)),
92 buffer_allocator_(buffer_allocator), 92 buffer_allocator_(buffer_allocator),
93 send_version_in_packet_(framer->perspective() == Perspective::IS_CLIENT), 93 send_version_in_packet_(framer->perspective() == Perspective::IS_CLIENT),
94 send_path_id_in_packet_(false), 94 send_path_id_in_packet_(false),
95 next_packet_number_length_(PACKET_1BYTE_PACKET_NUMBER), 95 next_packet_number_length_(PACKET_1BYTE_PACKET_NUMBER),
96 max_packet_length_(0), 96 max_packet_length_(0),
97 connection_id_length_(PACKET_8BYTE_CONNECTION_ID),
98 packet_size_(0),
97 connection_id_(connection_id), 99 connection_id_(connection_id),
98 encryption_level_(ENCRYPTION_NONE), 100 packet_(kDefaultPathId,
99 has_ack_(false), 101 0,
100 has_stop_waiting_(false), 102 next_packet_number_length_,
101 current_path_(kDefaultPathId), 103 nullptr,
102 packet_number_(0), 104 0,
103 connection_id_length_(PACKET_8BYTE_CONNECTION_ID), 105 nullptr,
104 packet_number_length_(next_packet_number_length_), 106 false,
105 packet_size_(0), 107 false),
106 needs_padding_(false),
107 has_crypto_handshake_(NOT_HANDSHAKE),
108 should_fec_protect_next_packet_(false), 108 should_fec_protect_next_packet_(false),
109 fec_protect_(false), 109 fec_protect_(false),
110 max_packets_per_fec_group_(kDefaultMaxPacketsPerFecGroup), 110 max_packets_per_fec_group_(kDefaultMaxPacketsPerFecGroup),
111 fec_send_policy_(FEC_ANY_TRIGGER), 111 fec_send_policy_(FEC_ANY_TRIGGER),
112 fec_timeout_(QuicTime::Delta::Zero()), 112 fec_timeout_(QuicTime::Delta::Zero()),
113 rtt_multiplier_for_fec_timeout_(kRttMultiplierForFecTimeout) { 113 rtt_multiplier_for_fec_timeout_(kRttMultiplierForFecTimeout) {
114 SetMaxPacketLength(kDefaultMaxPacketSize); 114 SetMaxPacketLength(kDefaultMaxPacketSize);
115 } 115 }
116 116
117 QuicPacketCreator::~QuicPacketCreator() { 117 QuicPacketCreator::~QuicPacketCreator() {
118 if (queued_retransmittable_frames_.get() != nullptr) { 118 if (packet_.retransmittable_frames != nullptr) {
119 QuicUtils::DeleteFrames(queued_retransmittable_frames_.get()); 119 QuicUtils::DeleteFrames(packet_.retransmittable_frames);
120 delete packet_.retransmittable_frames;
121 }
122 if (packet_.packet != nullptr) {
123 delete packet_.packet;
120 } 124 }
121 } 125 }
122 126
123 void QuicPacketCreator::OnBuiltFecProtectedPayload( 127 void QuicPacketCreator::OnBuiltFecProtectedPayload(
124 const QuicPacketHeader& header, 128 const QuicPacketHeader& header,
125 StringPiece payload) { 129 StringPiece payload) {
126 if (fec_group_.get() != nullptr) { 130 if (fec_group_.get() != nullptr) {
127 DCHECK_NE(0u, header.fec_group); 131 DCHECK_NE(0u, header.fec_group);
128 fec_group_->Update(encryption_level_, header, payload); 132 fec_group_->Update(packet_.encryption_level, header, payload);
129 } 133 }
130 } 134 }
131 135
132 void QuicPacketCreator::SetEncrypter(EncryptionLevel level, 136 void QuicPacketCreator::SetEncrypter(EncryptionLevel level,
133 QuicEncrypter* encrypter) { 137 QuicEncrypter* encrypter) {
134 framer_->SetEncrypter(level, encrypter); 138 framer_->SetEncrypter(level, encrypter);
135 max_plaintext_size_ = framer_->GetMaxPlaintextSize(max_packet_length_); 139 max_plaintext_size_ = framer_->GetMaxPlaintextSize(max_packet_length_);
136 } 140 }
137 141
138 bool QuicPacketCreator::CanSetMaxPacketLength() const { 142 bool QuicPacketCreator::CanSetMaxPacketLength() const {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 // Don't update any lengths when an FEC group is open, to ensure same 216 // Don't update any lengths when an FEC group is open, to ensure same
213 // packet header size in all packets within a group. 217 // packet header size in all packets within a group.
214 return IN_FEC_GROUP; 218 return IN_FEC_GROUP;
215 } 219 }
216 if (!queued_frames_.empty()) { 220 if (!queued_frames_.empty()) {
217 // Don't change creator state if there are frames queued. 221 // Don't change creator state if there are frames queued.
218 return NOT_IN_FEC_GROUP; 222 return NOT_IN_FEC_GROUP;
219 } 223 }
220 224
221 // Update packet number length only on packet and FEC group boundaries. 225 // Update packet number length only on packet and FEC group boundaries.
222 packet_number_length_ = next_packet_number_length_; 226 packet_.packet_number_length = next_packet_number_length_;
223 227
224 if (!fec_protect_) { 228 if (!fec_protect_) {
225 return NOT_IN_FEC_GROUP; 229 return NOT_IN_FEC_GROUP;
226 } 230 }
227 // Start a new FEC group since protection is on. Set the fec group number to 231 // Start a new FEC group since protection is on. Set the fec group number to
228 // the packet number of the next packet. 232 // the packet number of the next packet.
229 fec_group_.reset(new QuicFecGroup(packet_number_ + 1)); 233 fec_group_.reset(new QuicFecGroup(packet_.packet_number + 1));
230 return IN_FEC_GROUP; 234 return IN_FEC_GROUP;
231 } 235 }
232 236
233 // Stops serializing version of the protocol in packets sent after this call. 237 // Stops serializing version of the protocol in packets sent after this call.
234 // A packet that is already open might send kQuicVersionSize bytes less than the 238 // A packet that is already open might send kQuicVersionSize bytes less than the
235 // maximum packet size if we stop sending version before it is serialized. 239 // maximum packet size if we stop sending version before it is serialized.
236 void QuicPacketCreator::StopSendingVersion() { 240 void QuicPacketCreator::StopSendingVersion() {
237 DCHECK(send_version_in_packet_); 241 DCHECK(send_version_in_packet_);
238 send_version_in_packet_ = false; 242 send_version_in_packet_ = false;
239 if (packet_size_ > 0) { 243 if (packet_size_ > 0) {
240 DCHECK_LT(kQuicVersionSize, packet_size_); 244 DCHECK_LT(kQuicVersionSize, packet_size_);
241 packet_size_ -= kQuicVersionSize; 245 packet_size_ -= kQuicVersionSize;
242 } 246 }
243 } 247 }
244 248
245 void QuicPacketCreator::UpdatePacketNumberLength( 249 void QuicPacketCreator::UpdatePacketNumberLength(
246 QuicPacketNumber least_packet_awaited_by_peer, 250 QuicPacketNumber least_packet_awaited_by_peer,
247 QuicPacketCount max_packets_in_flight) { 251 QuicPacketCount max_packets_in_flight) {
248 DCHECK_LE(least_packet_awaited_by_peer, packet_number_ + 1); 252 DCHECK_LE(least_packet_awaited_by_peer, packet_.packet_number + 1);
249 // Since the packet creator will not change packet number length mid FEC 253 // Since the packet creator will not change packet number length mid FEC
250 // group, include the size of an FEC group to be safe. 254 // group, include the size of an FEC group to be safe.
251 const QuicPacketNumber current_delta = max_packets_per_fec_group_ + 255 const QuicPacketNumber current_delta = max_packets_per_fec_group_ +
252 packet_number_ + 1 - 256 packet_.packet_number + 1 -
253 least_packet_awaited_by_peer; 257 least_packet_awaited_by_peer;
254 const uint64_t delta = max(current_delta, max_packets_in_flight); 258 const uint64_t delta = max(current_delta, max_packets_in_flight);
255 next_packet_number_length_ = 259 next_packet_number_length_ =
256 QuicFramer::GetMinSequenceNumberLength(delta * 4); 260 QuicFramer::GetMinSequenceNumberLength(delta * 4);
257 } 261 }
258 262
259 bool QuicPacketCreator::ConsumeData(QuicStreamId id, 263 bool QuicPacketCreator::ConsumeData(QuicStreamId id,
260 QuicIOVector iov, 264 QuicIOVector iov,
261 size_t iov_offset, 265 size_t iov_offset,
262 QuicStreamOffset offset, 266 QuicStreamOffset offset,
263 bool fin, 267 bool fin,
264 bool needs_padding, 268 bool needs_padding,
265 QuicFrame* frame, 269 QuicFrame* frame,
266 FecProtection fec_protection) { 270 FecProtection fec_protection) {
267 if (!HasRoomForStreamFrame(id, offset)) { 271 if (!HasRoomForStreamFrame(id, offset)) {
268 return false; 272 return false;
269 } 273 }
270 if (fec_protection == MUST_FEC_PROTECT) { 274 if (fec_protection == MUST_FEC_PROTECT) {
271 should_fec_protect_next_packet_ = true; 275 should_fec_protect_next_packet_ = true;
272 MaybeStartFecProtection(); 276 MaybeStartFecProtection();
273 } 277 }
274 CreateStreamFrame(id, iov, iov_offset, offset, fin, frame); 278 CreateStreamFrame(id, iov, iov_offset, offset, fin, frame);
275 if (!AddFrame(*frame, /*save_retransmittable_frames=*/true)) { 279 if (!AddFrame(*frame, /*save_retransmittable_frames=*/true)) {
276 // Fails if we try to write unencrypted stream data. 280 // Fails if we try to write unencrypted stream data.
277 delete frame->stream_frame; 281 delete frame->stream_frame;
278 return false; 282 return false;
279 } 283 }
280 if (needs_padding) { 284 if (needs_padding) {
281 needs_padding_ = true; 285 packet_.needs_padding = true;
282 } 286 }
283 if (fec_protection == MUST_FEC_PROTECT && 287 if (fec_protection == MUST_FEC_PROTECT &&
284 iov_offset + frame->stream_frame->frame_length == iov.total_length) { 288 iov_offset + frame->stream_frame->frame_length == iov.total_length) {
285 // Turn off FEC protection when we're done writing protected data. 289 // Turn off FEC protection when we're done writing protected data.
286 DVLOG(1) << "Turning FEC protection OFF"; 290 DVLOG(1) << "Turning FEC protection OFF";
287 should_fec_protect_next_packet_ = false; 291 should_fec_protect_next_packet_ = false;
288 } 292 }
289 return true; 293 return true;
290 } 294 }
291 295
292 bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id, 296 bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id,
293 QuicStreamOffset offset) const { 297 QuicStreamOffset offset) {
294 // TODO(jri): This is a simple safe decision for now, but make 298 // TODO(jri): This is a simple safe decision for now, but make
295 // is_in_fec_group a parameter. Same as with all public methods in 299 // is_in_fec_group a parameter. Same as with all public methods in
296 // QuicPacketCreator. 300 // QuicPacketCreator.
297 return BytesFree() > 301 return BytesFree() >
298 QuicFramer::GetMinStreamFrameSize( 302 QuicFramer::GetMinStreamFrameSize(
299 id, offset, true, fec_protect_ ? IN_FEC_GROUP : NOT_IN_FEC_GROUP); 303 id, offset, true, fec_protect_ ? IN_FEC_GROUP : NOT_IN_FEC_GROUP);
300 } 304 }
301 305
302 // static 306 // static
303 size_t QuicPacketCreator::StreamFramePacketOverhead( 307 size_t QuicPacketCreator::StreamFramePacketOverhead(
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } 409 }
406 QUIC_BUG_IF(length > 0) << "Failed to copy entire length to buffer."; 410 QUIC_BUG_IF(length > 0) << "Failed to copy entire length to buffer.";
407 } 411 }
408 412
409 SerializedPacket QuicPacketCreator::ReserializeAllFrames( 413 SerializedPacket QuicPacketCreator::ReserializeAllFrames(
410 const PendingRetransmission& retransmission, 414 const PendingRetransmission& retransmission,
411 char* buffer, 415 char* buffer,
412 size_t buffer_len) { 416 size_t buffer_len) {
413 DCHECK(queued_frames_.empty()); 417 DCHECK(queued_frames_.empty());
414 DCHECK(fec_group_.get() == nullptr); 418 DCHECK(fec_group_.get() == nullptr);
415 DCHECK(!needs_padding_); 419 DCHECK(!packet_.needs_padding);
416 QUIC_BUG_IF(retransmission.retransmittable_frames.empty()) 420 QUIC_BUG_IF(retransmission.retransmittable_frames.empty())
417 << "Attempt to serialize empty packet"; 421 << "Attempt to serialize empty packet";
418 const QuicPacketNumberLength saved_length = packet_number_length_; 422 const QuicPacketNumberLength saved_length = packet_.packet_number_length;
419 const QuicPacketNumberLength saved_next_length = next_packet_number_length_; 423 const QuicPacketNumberLength saved_next_length = next_packet_number_length_;
420 const bool saved_should_fec_protect = fec_protect_; 424 const bool saved_should_fec_protect = fec_protect_;
421 const bool saved_needs_padding = needs_padding_; 425 const bool saved_needs_padding = packet_.needs_padding;
422 const EncryptionLevel default_encryption_level = encryption_level_; 426 const EncryptionLevel default_encryption_level = packet_.encryption_level;
423 427
424 // Temporarily set the packet number length, stop FEC protection, 428 // Temporarily set the packet number length, stop FEC protection,
425 // and change the encryption level. 429 // and change the encryption level.
426 packet_number_length_ = retransmission.packet_number_length; 430 packet_.packet_number_length = retransmission.packet_number_length;
427 next_packet_number_length_ = retransmission.packet_number_length; 431 next_packet_number_length_ = retransmission.packet_number_length;
428 fec_protect_ = false; 432 fec_protect_ = false;
429 needs_padding_ = retransmission.needs_padding; 433 packet_.needs_padding = retransmission.needs_padding;
430 // Only preserve the original encryption level if it's a handshake packet or 434 // Only preserve the original encryption level if it's a handshake packet or
431 // if we haven't gone forward secure. 435 // if we haven't gone forward secure.
432 if (retransmission.has_crypto_handshake || 436 if (retransmission.has_crypto_handshake ||
433 encryption_level_ != ENCRYPTION_FORWARD_SECURE) { 437 packet_.encryption_level != ENCRYPTION_FORWARD_SECURE) {
434 encryption_level_ = retransmission.encryption_level; 438 packet_.encryption_level = retransmission.encryption_level;
435 } 439 }
436 440
437 // Serialize the packet and restore the FEC and packet number length state. 441 // Serialize the packet and restore the FEC and packet number length state.
438 for (const QuicFrame& frame : retransmission.retransmittable_frames) { 442 for (const QuicFrame& frame : retransmission.retransmittable_frames) {
439 bool success = AddFrame(frame, false); 443 bool success = AddFrame(frame, false);
440 DCHECK(success); 444 DCHECK(success);
441 } 445 }
442 SerializedPacket serialized_packet = SerializePacket(buffer, buffer_len); 446 SerializePacket(buffer, buffer_len);
443 if (FLAGS_quic_retransmit_via_onserializedpacket) { 447 if (FLAGS_quic_retransmit_via_onserializedpacket) {
444 serialized_packet.original_packet_number = retransmission.packet_number; 448 packet_.original_packet_number = retransmission.packet_number;
445 serialized_packet.transmission_type = retransmission.transmission_type; 449 packet_.transmission_type = retransmission.transmission_type;
446 } 450 OnSerializedPacket();
447 451 // Restore old values.
448 packet_number_length_ = saved_length; 452 packet_.packet_number_length = saved_length;
449 next_packet_number_length_ = saved_next_length; 453 next_packet_number_length_ = saved_next_length;
450 fec_protect_ = saved_should_fec_protect; 454 fec_protect_ = saved_should_fec_protect;
451 encryption_level_ = default_encryption_level; 455 packet_.encryption_level = default_encryption_level;
452
453 if (FLAGS_quic_retransmit_via_onserializedpacket) {
454 OnSerializedPacket(&serialized_packet);
455 return NoPacket(); 456 return NoPacket();
456 } else { 457 } else {
457 has_crypto_handshake_ = NOT_HANDSHAKE; 458 SerializedPacket packet_copy = packet_;
458 needs_padding_ = saved_needs_padding; 459 ClearPacket();
459 return serialized_packet; 460 // Restore old values.
461 packet_.needs_padding = saved_needs_padding;
462 packet_.packet_number_length = saved_length;
463 next_packet_number_length_ = saved_next_length;
464 fec_protect_ = saved_should_fec_protect;
465 packet_.encryption_level = default_encryption_level;
466 return packet_copy;
460 } 467 }
461 } 468 }
462 469
463 void QuicPacketCreator::Flush() { 470 void QuicPacketCreator::Flush() {
464 if (!HasPendingFrames()) { 471 if (!HasPendingFrames()) {
465 return; 472 return;
466 } 473 }
467 474
468 // TODO(rtenneti): Change the default 64 alignas value (used the default 475 // TODO(rtenneti): Change the default 64 alignas value (used the default
469 // value from CACHELINE_SIZE). 476 // value from CACHELINE_SIZE).
470 ALIGNAS(64) char seralized_packet_buffer[kMaxPacketSize]; 477 ALIGNAS(64) char seralized_packet_buffer[kMaxPacketSize];
471 SerializedPacket serialized_packet = 478 SerializePacket(seralized_packet_buffer, kMaxPacketSize);
472 SerializePacket(seralized_packet_buffer, kMaxPacketSize); 479 OnSerializedPacket();
473 OnSerializedPacket(&serialized_packet);
474 } 480 }
475 481
476 void QuicPacketCreator::OnSerializedPacket(SerializedPacket* packet) { 482 void QuicPacketCreator::OnSerializedPacket() {
477 if (packet->packet == nullptr) { 483 if (packet_.packet == nullptr) {
478 QUIC_BUG << "Failed to SerializePacket. fec_policy:" << fec_send_policy() 484 QUIC_BUG << "Failed to SerializePacket. fec_policy:" << fec_send_policy()
479 << " should_fec_protect_:" << should_fec_protect_next_packet_; 485 << " should_fec_protect_:" << should_fec_protect_next_packet_;
480 delegate_->CloseConnection(QUIC_FAILED_TO_SERIALIZE_PACKET, false); 486 delegate_->CloseConnection(QUIC_FAILED_TO_SERIALIZE_PACKET, false);
481 return; 487 return;
482 } 488 }
483 // There may be AckListeners interested in this packet. 489
484 packet->listeners.swap(ack_listeners_); 490 delegate_->OnSerializedPacket(&packet_);
485 DCHECK(ack_listeners_.empty()); 491 ClearPacket();
486 delegate_->OnSerializedPacket(packet);
487 has_ack_ = false;
488 has_stop_waiting_ = false;
489 has_crypto_handshake_ = NOT_HANDSHAKE;
490 needs_padding_ = false;
491 MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/false, 492 MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/false,
492 /*is_fec_timeout=*/false); 493 /*is_fec_timeout=*/false);
493 // Maximum packet size may be only enacted while no packet is currently being 494 // Maximum packet size may be only enacted while no packet is currently being
494 // constructed, so here we have a good opportunity to actually change it. 495 // constructed, so here we have a good opportunity to actually change it.
495 if (CanSetMaxPacketLength()) { 496 if (CanSetMaxPacketLength()) {
496 SetMaxPacketLength(max_packet_length_); 497 SetMaxPacketLength(max_packet_length_);
497 } 498 }
498 } 499 }
499 500
501 void QuicPacketCreator::ClearPacket() {
502 packet_.has_ack = false;
503 packet_.has_stop_waiting = false;
504 packet_.has_crypto_handshake = NOT_HANDSHAKE;
505 packet_.needs_padding = false;
506 packet_.is_fec_packet = false;
507 packet_.original_packet_number = 0;
508 packet_.transmission_type = NOT_RETRANSMISSION;
509 packet_.packet = nullptr;
510 packet_.retransmittable_frames = nullptr;
511 packet_.listeners.clear();
512 }
513
500 bool QuicPacketCreator::HasPendingFrames() const { 514 bool QuicPacketCreator::HasPendingFrames() const {
501 return !queued_frames_.empty(); 515 return !queued_frames_.empty();
502 } 516 }
503 517
504 bool QuicPacketCreator::HasPendingRetransmittableFrames() const { 518 bool QuicPacketCreator::HasPendingRetransmittableFrames() const {
505 return queued_retransmittable_frames_.get() != nullptr && 519 return packet_.retransmittable_frames != nullptr &&
506 !queued_retransmittable_frames_->empty(); 520 !packet_.retransmittable_frames->empty();
507 } 521 }
508 522
509 size_t QuicPacketCreator::ExpansionOnNewFrame() const { 523 size_t QuicPacketCreator::ExpansionOnNewFrame() const {
510 // If packet is FEC protected, there's no expansion. 524 // If packet is FEC protected, there's no expansion.
511 if (fec_protect_) { 525 if (fec_protect_) {
512 return 0; 526 return 0;
513 } 527 }
514 // If the last frame in the packet is a stream frame, then it will expand to 528 // If the last frame in the packet is a stream frame, then it will expand to
515 // include the stream_length field when a new frame is added. 529 // include the stream_length field when a new frame is added.
516 bool has_trailing_stream_frame = 530 bool has_trailing_stream_frame =
517 !queued_frames_.empty() && queued_frames_.back().type == STREAM_FRAME; 531 !queued_frames_.empty() && queued_frames_.back().type == STREAM_FRAME;
518 return has_trailing_stream_frame ? kQuicStreamPayloadLengthSize : 0; 532 return has_trailing_stream_frame ? kQuicStreamPayloadLengthSize : 0;
519 } 533 }
520 534
521 size_t QuicPacketCreator::BytesFree() const { 535 size_t QuicPacketCreator::BytesFree() {
522 DCHECK_GE(max_plaintext_size_, PacketSize()); 536 DCHECK_GE(max_plaintext_size_, PacketSize());
523 return max_plaintext_size_ - 537 return max_plaintext_size_ -
524 min(max_plaintext_size_, PacketSize() + ExpansionOnNewFrame()); 538 min(max_plaintext_size_, PacketSize() + ExpansionOnNewFrame());
525 } 539 }
526 540
527 size_t QuicPacketCreator::PacketSize() const { 541 size_t QuicPacketCreator::PacketSize() {
528 if (!queued_frames_.empty()) { 542 if (!queued_frames_.empty()) {
529 return packet_size_; 543 return packet_size_;
530 } 544 }
531 if (fec_group_.get() == nullptr) { 545 if (fec_group_.get() == nullptr) {
532 // Update packet number length on packet and FEC boundary. 546 // Update packet number length on packet and FEC boundary.
533 packet_number_length_ = next_packet_number_length_; 547 packet_.packet_number_length = next_packet_number_length_;
534 } 548 }
535 packet_size_ = GetPacketHeaderSize( 549 packet_size_ =
536 connection_id_length_, send_version_in_packet_, send_path_id_in_packet_, 550 GetPacketHeaderSize(connection_id_length_, send_version_in_packet_,
537 packet_number_length_, fec_protect_ ? IN_FEC_GROUP : NOT_IN_FEC_GROUP); 551 send_path_id_in_packet_, packet_.packet_number_length,
552 fec_protect_ ? IN_FEC_GROUP : NOT_IN_FEC_GROUP);
538 return packet_size_; 553 return packet_size_;
539 } 554 }
540 555
541 bool QuicPacketCreator::AddSavedFrame(const QuicFrame& frame) { 556 bool QuicPacketCreator::AddSavedFrame(const QuicFrame& frame) {
542 return AddFrame(frame, /*save_retransmittable_frames=*/true); 557 return AddFrame(frame, /*save_retransmittable_frames=*/true);
543 } 558 }
544 559
545 bool QuicPacketCreator::AddPaddedSavedFrame(const QuicFrame& frame) { 560 bool QuicPacketCreator::AddPaddedSavedFrame(const QuicFrame& frame) {
546 if (AddFrame(frame, /*save_retransmittable_frames=*/true)) { 561 if (AddFrame(frame, /*save_retransmittable_frames=*/true)) {
547 needs_padding_ = true; 562 packet_.needs_padding = true;
548 return true; 563 return true;
549 } 564 }
550 return false; 565 return false;
551 } 566 }
552 567
553 void QuicPacketCreator::AddAckListener(QuicAckListenerInterface* listener, 568 void QuicPacketCreator::AddAckListener(QuicAckListenerInterface* listener,
554 QuicPacketLength length) { 569 QuicPacketLength length) {
555 DCHECK(!queued_frames_.empty()); 570 DCHECK(!queued_frames_.empty());
556 ack_listeners_.push_back(AckListenerWrapper(listener, length)); 571 packet_.listeners.push_back(AckListenerWrapper(listener, length));
557 } 572 }
558 573
559 SerializedPacket QuicPacketCreator::SerializePacket( 574 void QuicPacketCreator::SerializePacket(char* encrypted_buffer,
560 char* encrypted_buffer, 575 size_t encrypted_buffer_len) {
561 size_t encrypted_buffer_len) {
562 DCHECK_LT(0u, encrypted_buffer_len); 576 DCHECK_LT(0u, encrypted_buffer_len);
563 QUIC_BUG_IF(queued_frames_.empty()) << "Attempt to serialize empty packet"; 577 QUIC_BUG_IF(queued_frames_.empty()) << "Attempt to serialize empty packet";
564 if (fec_group_.get() != nullptr) { 578 if (fec_group_.get() != nullptr) {
565 DCHECK_GE(packet_number_ + 1, fec_group_->FecGroupNumber()); 579 DCHECK_GE(packet_.packet_number + 1, fec_group_->FecGroupNumber());
566 } 580 }
567 QuicPacketHeader header; 581 QuicPacketHeader header;
568 // FillPacketHeader increments packet_number_. 582 // FillPacketHeader increments packet_number_.
569 FillPacketHeader(fec_group_ != nullptr ? fec_group_->FecGroupNumber() : 0, 583 FillPacketHeader(fec_group_ != nullptr ? fec_group_->FecGroupNumber() : 0,
570 false, &header); 584 false, &header);
571 585
572 MaybeAddPadding(); 586 MaybeAddPadding();
573 587
574 DCHECK_GE(max_plaintext_size_, packet_size_); 588 DCHECK_GE(max_plaintext_size_, packet_size_);
575 // ACK Frames will be truncated due to length only if they're the only frame 589 // ACK Frames will be truncated due to length only if they're the only frame
576 // in the packet, and if packet_size_ was set to max_plaintext_size_. If 590 // in the packet, and if packet_size_ was set to max_plaintext_size_. If
577 // truncation due to length occurred, then GetSerializedFrameLength will have 591 // truncation due to length occurred, then GetSerializedFrameLength will have
578 // returned all bytes free. 592 // returned all bytes free.
579 bool possibly_truncated_by_length = packet_size_ == max_plaintext_size_ && 593 bool possibly_truncated_by_length = packet_size_ == max_plaintext_size_ &&
580 queued_frames_.size() == 1 && 594 queued_frames_.size() == 1 &&
581 queued_frames_.back().type == ACK_FRAME; 595 queued_frames_.back().type == ACK_FRAME;
582 // Use the packet_size_ instead of the buffer size to ensure smaller 596 // Use the packet_size_ instead of the buffer size to ensure smaller
583 // packet sizes are properly used. 597 // packet sizes are properly used.
584 size_t length = framer_->BuildDataPacket(header, queued_frames_, 598 size_t length = framer_->BuildDataPacket(header, queued_frames_,
585 encrypted_buffer, packet_size_); 599 encrypted_buffer, packet_size_);
586 if (length == 0) { 600 if (length == 0) {
587 QUIC_BUG << "Failed to serialize " << queued_frames_.size() << " frames."; 601 QUIC_BUG << "Failed to serialize " << queued_frames_.size() << " frames.";
588 return NoPacket(); 602 return;
589 } 603 }
590 604
591 // TODO(ianswett) Consider replacing QuicPacket with something else, since 605 // TODO(ianswett) Consider replacing QuicPacket with something else, since
592 // it's only used to provide convenience methods to FEC and encryption. 606 // it's only used to provide convenience methods to FEC and encryption.
593 QuicPacket packet( 607 QuicPacket packet(
594 encrypted_buffer, length, 608 encrypted_buffer, length,
595 /* owns_buffer */ false, header.public_header.connection_id_length, 609 /* owns_buffer */ false, header.public_header.connection_id_length,
596 header.public_header.version_flag, header.public_header.multipath_flag, 610 header.public_header.version_flag, header.public_header.multipath_flag,
597 header.public_header.packet_number_length); 611 header.public_header.packet_number_length);
598 OnBuiltFecProtectedPayload(header, packet.FecProtectedData()); 612 OnBuiltFecProtectedPayload(header, packet.FecProtectedData());
599 613
600 // Because of possible truncation, we can't be confident that our 614 // Because of possible truncation, we can't be confident that our
601 // packet size calculation worked correctly. 615 // packet size calculation worked correctly.
602 if (!possibly_truncated_by_length) { 616 if (!possibly_truncated_by_length) {
603 DCHECK_EQ(packet_size_, length); 617 DCHECK_EQ(packet_size_, length);
604 } 618 }
605 // Immediately encrypt the packet, to ensure we don't encrypt the same 619 // Immediately encrypt the packet, to ensure we don't encrypt the same
606 // packet number multiple times. 620 // packet number multiple times.
607 size_t encrypted_length = 621 size_t encrypted_length = framer_->EncryptPayload(
608 framer_->EncryptPayload(encryption_level_, current_path_, packet_number_, 622 packet_.encryption_level, packet_.path_id, packet_.packet_number, packet,
609 packet, encrypted_buffer, encrypted_buffer_len); 623 encrypted_buffer, encrypted_buffer_len);
610 if (encrypted_length == 0) { 624 if (encrypted_length == 0) {
611 QUIC_BUG << "Failed to encrypt packet number " << packet_number_; 625 QUIC_BUG << "Failed to encrypt packet number " << packet_.packet_number;
612 return NoPacket(); 626 return;
613 } 627 }
614 628
615 packet_size_ = 0; 629 packet_size_ = 0;
616 queued_frames_.clear(); 630 queued_frames_.clear();
617 return SerializedPacket( 631 packet_.entropy_hash = QuicFramer::GetPacketEntropyHash(header);
618 current_path_, header.packet_number, 632 packet_.packet =
619 header.public_header.packet_number_length, encrypted_buffer, 633 new QuicEncryptedPacket(encrypted_buffer, encrypted_length, false);
620 encrypted_length,
621 /* owns_buffer*/ false, QuicFramer::GetPacketEntropyHash(header),
622 queued_retransmittable_frames_.release(), needs_padding_,
623 has_crypto_handshake_, has_ack_, has_stop_waiting_, encryption_level_);
624 } 634 }
625 635
626 SerializedPacket QuicPacketCreator::SerializeFec(char* buffer, 636 void QuicPacketCreator::SerializeFec(char* buffer, size_t buffer_len) {
627 size_t buffer_len) {
628 DCHECK_LT(0u, buffer_len); 637 DCHECK_LT(0u, buffer_len);
629 if (fec_group_.get() == nullptr || fec_group_->NumReceivedPackets() <= 0) { 638 if (fec_group_.get() == nullptr || fec_group_->NumReceivedPackets() <= 0) {
630 QUIC_BUG << "SerializeFEC called but no group or zero packets in group."; 639 QUIC_BUG << "SerializeFEC called but no group or zero packets in group.";
631 // TODO(jri): Make this a public method of framer? 640 return;
632 return NoPacket();
633 } 641 }
634 if (FLAGS_quic_no_unencrypted_fec && encryption_level_ == ENCRYPTION_NONE) { 642 if (FLAGS_quic_no_unencrypted_fec &&
643 packet_.encryption_level == ENCRYPTION_NONE) {
635 QUIC_BUG << "SerializeFEC must be called with encryption."; 644 QUIC_BUG << "SerializeFEC must be called with encryption.";
636 delegate_->CloseConnection(QUIC_UNENCRYPTED_FEC_DATA, false); 645 delegate_->CloseConnection(QUIC_UNENCRYPTED_FEC_DATA, false);
637 return NoPacket(); 646 return;
638 } 647 }
639 DCHECK_EQ(0u, queued_frames_.size()); 648 DCHECK_EQ(0u, queued_frames_.size());
640 QuicPacketHeader header; 649 QuicPacketHeader header;
641 FillPacketHeader(fec_group_->FecGroupNumber(), true, &header); 650 FillPacketHeader(fec_group_->FecGroupNumber(), true, &header);
642 scoped_ptr<QuicPacket> packet( 651 scoped_ptr<QuicPacket> packet(
643 framer_->BuildFecPacket(header, fec_group_->PayloadParity())); 652 framer_->BuildFecPacket(header, fec_group_->PayloadParity()));
644 fec_group_.reset(nullptr); 653 fec_group_.reset(nullptr);
645 packet_size_ = 0; 654 packet_size_ = 0;
646 QUIC_BUG_IF(packet == nullptr) << "Failed to serialize fec packet for group:" 655 QUIC_BUG_IF(packet == nullptr) << "Failed to serialize fec packet for group:"
647 << fec_group_->FecGroupNumber(); 656 << fec_group_->FecGroupNumber();
648 DCHECK_GE(max_packet_length_, packet->length()); 657 DCHECK_GE(max_packet_length_, packet->length());
649 // Immediately encrypt the packet, to ensure we don't encrypt the same packet 658 // Immediately encrypt the packet, to ensure we don't encrypt the same packet
650 // packet number multiple times. 659 // packet number multiple times.
651 size_t encrypted_length = 660 size_t encrypted_length = framer_->EncryptPayload(
652 framer_->EncryptPayload(encryption_level_, current_path_, packet_number_, 661 packet_.encryption_level, packet_.path_id, packet_.packet_number, *packet,
653 *packet, buffer, buffer_len); 662 buffer, buffer_len);
654 if (encrypted_length == 0) { 663 if (encrypted_length == 0) {
655 QUIC_BUG << "Failed to encrypt packet number " << packet_number_; 664 QUIC_BUG << "Failed to encrypt packet number " << packet_.packet_number;
656 return NoPacket(); 665 return;
657 } 666 }
658 SerializedPacket serialized( 667 packet_.entropy_hash = QuicFramer::GetPacketEntropyHash(header);
659 current_path_, header.packet_number, 668 packet_.packet = new QuicEncryptedPacket(buffer, encrypted_length, false);
660 header.public_header.packet_number_length, buffer, encrypted_length, 669 packet_.is_fec_packet = true;
661 /* owns_buffer */ false, QuicFramer::GetPacketEntropyHash(header),
662 nullptr, false, NOT_HANDSHAKE, false, false, encryption_level_);
663 serialized.is_fec_packet = true;
664 return serialized;
665 } 670 }
666 671
667 QuicEncryptedPacket* QuicPacketCreator::SerializeVersionNegotiationPacket( 672 QuicEncryptedPacket* QuicPacketCreator::SerializeVersionNegotiationPacket(
668 const QuicVersionVector& supported_versions) { 673 const QuicVersionVector& supported_versions) {
669 DCHECK_EQ(Perspective::IS_SERVER, framer_->perspective()); 674 DCHECK_EQ(Perspective::IS_SERVER, framer_->perspective());
670 QuicEncryptedPacket* encrypted = QuicFramer::BuildVersionNegotiationPacket( 675 QuicEncryptedPacket* encrypted = QuicFramer::BuildVersionNegotiationPacket(
671 connection_id_, supported_versions); 676 connection_id_, supported_versions);
672 DCHECK(encrypted); 677 DCHECK(encrypted);
673 DCHECK_GE(max_packet_length_, encrypted->length()); 678 DCHECK_GE(max_packet_length_, encrypted->length());
674 return encrypted; 679 return encrypted;
675 } 680 }
676 681
682 // TODO(jri): Make this a public method of framer?
677 SerializedPacket QuicPacketCreator::NoPacket() { 683 SerializedPacket QuicPacketCreator::NoPacket() {
678 return SerializedPacket(kInvalidPathId, 0, PACKET_1BYTE_PACKET_NUMBER, 684 return SerializedPacket(kInvalidPathId, 0, PACKET_1BYTE_PACKET_NUMBER,
679 nullptr, 0, nullptr, false, false); 685 nullptr, 0, nullptr, false, false);
680 } 686 }
681 687
682 void QuicPacketCreator::FillPacketHeader(QuicFecGroupNumber fec_group, 688 void QuicPacketCreator::FillPacketHeader(QuicFecGroupNumber fec_group,
683 bool fec_flag, 689 bool fec_flag,
684 QuicPacketHeader* header) { 690 QuicPacketHeader* header) {
685 header->public_header.connection_id = connection_id_; 691 header->public_header.connection_id = connection_id_;
686 header->public_header.connection_id_length = connection_id_length_; 692 header->public_header.connection_id_length = connection_id_length_;
687 header->public_header.multipath_flag = send_path_id_in_packet_; 693 header->public_header.multipath_flag = send_path_id_in_packet_;
688 header->public_header.reset_flag = false; 694 header->public_header.reset_flag = false;
689 header->public_header.version_flag = send_version_in_packet_; 695 header->public_header.version_flag = send_version_in_packet_;
690 header->fec_flag = fec_flag; 696 header->fec_flag = fec_flag;
691 header->path_id = current_path_; 697 header->path_id = packet_.path_id;
692 header->packet_number = ++packet_number_; 698 header->packet_number = ++packet_.packet_number;
693 header->public_header.packet_number_length = packet_number_length_; 699 header->public_header.packet_number_length = packet_.packet_number_length;
694 header->entropy_flag = random_bool_source_->RandBool(); 700 header->entropy_flag = random_bool_source_->RandBool();
695 header->is_in_fec_group = fec_group == 0 ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; 701 header->is_in_fec_group = fec_group == 0 ? NOT_IN_FEC_GROUP : IN_FEC_GROUP;
696 header->fec_group = fec_group; 702 header->fec_group = fec_group;
697 } 703 }
698 704
699 bool QuicPacketCreator::ShouldRetransmit(const QuicFrame& frame) { 705 bool QuicPacketCreator::ShouldRetransmit(const QuicFrame& frame) {
700 switch (frame.type) { 706 switch (frame.type) {
701 case ACK_FRAME: 707 case ACK_FRAME:
702 case PADDING_FRAME: 708 case PADDING_FRAME:
703 case STOP_WAITING_FRAME: 709 case STOP_WAITING_FRAME:
704 case MTU_DISCOVERY_FRAME: 710 case MTU_DISCOVERY_FRAME:
705 return false; 711 return false;
706 default: 712 default:
707 return true; 713 return true;
708 } 714 }
709 } 715 }
710 716
711 bool QuicPacketCreator::AddFrame(const QuicFrame& frame, 717 bool QuicPacketCreator::AddFrame(const QuicFrame& frame,
712 bool save_retransmittable_frames) { 718 bool save_retransmittable_frames) {
713 DVLOG(1) << "Adding frame: " << frame; 719 DVLOG(1) << "Adding frame: " << frame;
714 if (FLAGS_quic_never_write_unencrypted_data && frame.type == STREAM_FRAME && 720 if (FLAGS_quic_never_write_unencrypted_data && frame.type == STREAM_FRAME &&
715 frame.stream_frame->stream_id != kCryptoStreamId && 721 frame.stream_frame->stream_id != kCryptoStreamId &&
716 encryption_level_ == ENCRYPTION_NONE) { 722 packet_.encryption_level == ENCRYPTION_NONE) {
717 QUIC_BUG << "Cannot send stream data without encryption."; 723 QUIC_BUG << "Cannot send stream data without encryption.";
718 delegate_->CloseConnection(QUIC_UNENCRYPTED_STREAM_DATA, false); 724 delegate_->CloseConnection(QUIC_UNENCRYPTED_STREAM_DATA, false);
719 return false; 725 return false;
720 } 726 }
721 InFecGroup is_in_fec_group = MaybeUpdateLengthsAndStartFec(); 727 InFecGroup is_in_fec_group = MaybeUpdateLengthsAndStartFec();
722 728
723 size_t frame_len = framer_->GetSerializedFrameLength( 729 size_t frame_len = framer_->GetSerializedFrameLength(
724 frame, BytesFree(), queued_frames_.empty(), true, is_in_fec_group, 730 frame, BytesFree(), queued_frames_.empty(), true, is_in_fec_group,
725 packet_number_length_); 731 packet_.packet_number_length);
726 if (frame_len == 0) { 732 if (frame_len == 0) {
727 // Current open packet is full. 733 // Current open packet is full.
728 Flush(); 734 Flush();
729 return false; 735 return false;
730 } 736 }
731 DCHECK_LT(0u, packet_size_); 737 DCHECK_LT(0u, packet_size_);
732 packet_size_ += ExpansionOnNewFrame() + frame_len; 738 packet_size_ += ExpansionOnNewFrame() + frame_len;
733 739
734 if (save_retransmittable_frames && ShouldRetransmit(frame)) { 740 if (save_retransmittable_frames && ShouldRetransmit(frame)) {
735 if (queued_retransmittable_frames_.get() == nullptr) { 741 if (packet_.retransmittable_frames == nullptr) {
736 queued_retransmittable_frames_.reset(new QuicFrames()); 742 packet_.retransmittable_frames = new QuicFrames();
737 queued_retransmittable_frames_->reserve(2); 743 packet_.retransmittable_frames->reserve(2);
738 } 744 }
739 queued_retransmittable_frames_->push_back(frame); 745 packet_.retransmittable_frames->push_back(frame);
740 queued_frames_.push_back(frame); 746 queued_frames_.push_back(frame);
741 if (frame.type == STREAM_FRAME && 747 if (frame.type == STREAM_FRAME &&
742 frame.stream_frame->stream_id == kCryptoStreamId) { 748 frame.stream_frame->stream_id == kCryptoStreamId) {
743 has_crypto_handshake_ = IS_HANDSHAKE; 749 packet_.has_crypto_handshake = IS_HANDSHAKE;
744 } 750 }
745 } else { 751 } else {
746 queued_frames_.push_back(frame); 752 queued_frames_.push_back(frame);
747 } 753 }
748 754
749 if (frame.type == ACK_FRAME) { 755 if (frame.type == ACK_FRAME) {
750 has_ack_ = true; 756 packet_.has_ack = true;
751 } 757 }
752 if (frame.type == STOP_WAITING_FRAME) { 758 if (frame.type == STOP_WAITING_FRAME) {
753 has_stop_waiting_ = true; 759 packet_.has_stop_waiting = true;
754 } 760 }
755 if (debug_delegate_ != nullptr) { 761 if (debug_delegate_ != nullptr) {
756 debug_delegate_->OnFrameAddedToPacket(frame); 762 debug_delegate_->OnFrameAddedToPacket(frame);
757 } 763 }
758 764
759 return true; 765 return true;
760 } 766 }
761 767
762 void QuicPacketCreator::MaybeAddPadding() { 768 void QuicPacketCreator::MaybeAddPadding() {
763 if (!needs_padding_) { 769 if (!packet_.needs_padding) {
764 return; 770 return;
765 } 771 }
766 772
767 if (BytesFree() == 0) { 773 if (BytesFree() == 0) {
768 // Don't pad full packets. 774 // Don't pad full packets.
769 return; 775 return;
770 } 776 }
771 777
772 bool success = AddFrame(QuicFrame(QuicPaddingFrame()), false); 778 bool success = AddFrame(QuicFrame(QuicPaddingFrame()), false);
773 DCHECK(success); 779 DCHECK(success);
(...skipping 10 matching lines...) Expand all
784 Flush(); 790 Flush();
785 791
786 StartFecProtectingPackets(); 792 StartFecProtectingPackets();
787 DCHECK(fec_protect_); 793 DCHECK(fec_protect_);
788 } 794 }
789 795
790 void QuicPacketCreator::MaybeSendFecPacketAndCloseGroup(bool force_send_fec, 796 void QuicPacketCreator::MaybeSendFecPacketAndCloseGroup(bool force_send_fec,
791 bool is_fec_timeout) { 797 bool is_fec_timeout) {
792 if (ShouldSendFec(force_send_fec)) { 798 if (ShouldSendFec(force_send_fec)) {
793 if ((FLAGS_quic_no_unencrypted_fec && 799 if ((FLAGS_quic_no_unencrypted_fec &&
794 encryption_level_ == ENCRYPTION_NONE) || 800 packet_.encryption_level == ENCRYPTION_NONE) ||
795 (fec_send_policy_ == FEC_ALARM_TRIGGER && !is_fec_timeout)) { 801 (fec_send_policy_ == FEC_ALARM_TRIGGER && !is_fec_timeout)) {
796 ResetFecGroup(); 802 ResetFecGroup();
797 delegate_->OnResetFecGroup(); 803 delegate_->OnResetFecGroup();
798 } else { 804 } else {
799 // TODO(zhongyi): Change the default 64 alignas value (used the default 805 // TODO(zhongyi): Change the default 64 alignas value (used the default
800 // value from CACHELINE_SIZE). 806 // value from CACHELINE_SIZE).
801 ALIGNAS(64) char seralized_fec_buffer[kMaxPacketSize]; 807 ALIGNAS(64) char seralized_fec_buffer[kMaxPacketSize];
802 SerializedPacket serialized_fec = 808 SerializeFec(seralized_fec_buffer, kMaxPacketSize);
803 SerializeFec(seralized_fec_buffer, kMaxPacketSize); 809 OnSerializedPacket();
804 OnSerializedPacket(&serialized_fec);
805 } 810 }
806 } 811 }
807 812
808 if (!should_fec_protect_next_packet_ && fec_protect_ && !IsFecGroupOpen()) { 813 if (!should_fec_protect_next_packet_ && fec_protect_ && !IsFecGroupOpen()) {
809 StopFecProtectingPackets(); 814 StopFecProtectingPackets();
810 } 815 }
811 } 816 }
812 817
813 QuicTime::Delta QuicPacketCreator::GetFecTimeout( 818 QuicTime::Delta QuicPacketCreator::GetFecTimeout(
814 QuicPacketNumber packet_number) { 819 QuicPacketNumber packet_number) {
(...skipping 14 matching lines...) Expand all
829 } 834 }
830 835
831 void QuicPacketCreator::OnRttChange(QuicTime::Delta rtt) { 836 void QuicPacketCreator::OnRttChange(QuicTime::Delta rtt) {
832 fec_timeout_ = rtt.Multiply(rtt_multiplier_for_fec_timeout_); 837 fec_timeout_ = rtt.Multiply(rtt_multiplier_for_fec_timeout_);
833 } 838 }
834 839
835 void QuicPacketCreator::SetCurrentPath( 840 void QuicPacketCreator::SetCurrentPath(
836 QuicPathId path_id, 841 QuicPathId path_id,
837 QuicPacketNumber least_packet_awaited_by_peer, 842 QuicPacketNumber least_packet_awaited_by_peer,
838 QuicPacketCount max_packets_in_flight) { 843 QuicPacketCount max_packets_in_flight) {
839 if (current_path_ == path_id) { 844 if (packet_.path_id == path_id) {
840 return; 845 return;
841 } 846 }
842 847
843 if (HasPendingFrames()) { 848 if (HasPendingFrames()) {
844 QUIC_BUG << "Unable to change paths when a packet is under construction."; 849 QUIC_BUG << "Unable to change paths when a packet is under construction.";
845 return; 850 return;
846 } 851 }
847 852
848 // Send FEC packet and close FEC group. 853 // Send FEC packet and close FEC group.
849 MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, 854 MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true,
850 /*is_fec_timeout=*/false); 855 /*is_fec_timeout=*/false);
851 // Save current packet number and load switching path's packet number. 856 // Save current packet number and load switching path's packet number.
852 multipath_packet_number_[current_path_] = packet_number_; 857 multipath_packet_number_[packet_.path_id] = packet_.packet_number;
853 hash_map<QuicPathId, QuicPacketNumber>::iterator it = 858 hash_map<QuicPathId, QuicPacketNumber>::iterator it =
854 multipath_packet_number_.find(path_id); 859 multipath_packet_number_.find(path_id);
855 // If path_id is not in the map, it's a new path. Set packet_number to 0. 860 // If path_id is not in the map, it's a new path. Set packet_number to 0.
856 packet_number_ = it == multipath_packet_number_.end() ? 0 : it->second; 861 packet_.packet_number = it == multipath_packet_number_.end() ? 0 : it->second;
857 current_path_ = path_id; 862 packet_.path_id = path_id;
858 DCHECK(current_path_ != kInvalidPathId); 863 DCHECK(packet_.path_id != kInvalidPathId);
859 // Send path in packet if current path is not the default path. 864 // Send path in packet if current path is not the default path.
860 send_path_id_in_packet_ = current_path_ != kDefaultPathId ? true : false; 865 send_path_id_in_packet_ = packet_.path_id != kDefaultPathId ? true : false;
861 // Switching path needs to update packet number length. 866 // Switching path needs to update packet number length.
862 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); 867 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight);
863 } 868 }
864 869
865 } // namespace net 870 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_creator.h ('k') | net/quic/test_tools/quic_packet_creator_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698