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

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

Issue 1658373002: Move QuicPacketCreator::SerializeAllFrames into QuicPacketCreatorPeer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0202
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/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/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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 QUIC_BUG_IF(length > 0) << "Failed to copy entire length to buffer."; 406 QUIC_BUG_IF(length > 0) << "Failed to copy entire length to buffer.";
407 } 407 }
408 408
409 SerializedPacket QuicPacketCreator::ReserializeAllFrames( 409 SerializedPacket QuicPacketCreator::ReserializeAllFrames(
410 const PendingRetransmission& retransmission, 410 const PendingRetransmission& retransmission,
411 char* buffer, 411 char* buffer,
412 size_t buffer_len) { 412 size_t buffer_len) {
413 DCHECK(queued_frames_.empty()); 413 DCHECK(queued_frames_.empty());
414 DCHECK(fec_group_.get() == nullptr); 414 DCHECK(fec_group_.get() == nullptr);
415 DCHECK(!needs_padding_); 415 DCHECK(!needs_padding_);
416 QUIC_BUG_IF(retransmission.retransmittable_frames.empty())
417 << "Attempt to serialize empty packet";
416 const QuicPacketNumberLength saved_length = packet_number_length_; 418 const QuicPacketNumberLength saved_length = packet_number_length_;
417 const QuicPacketNumberLength saved_next_length = next_packet_number_length_; 419 const QuicPacketNumberLength saved_next_length = next_packet_number_length_;
418 const bool saved_should_fec_protect = fec_protect_; 420 const bool saved_should_fec_protect = fec_protect_;
419 const bool saved_needs_padding = needs_padding_; 421 const bool saved_needs_padding = needs_padding_;
420 const EncryptionLevel default_encryption_level = encryption_level_; 422 const EncryptionLevel default_encryption_level = encryption_level_;
421 423
422 // Temporarily set the packet number length, stop FEC protection, 424 // Temporarily set the packet number length, stop FEC protection,
423 // and change the encryption level. 425 // and change the encryption level.
424 packet_number_length_ = retransmission.packet_number_length; 426 packet_number_length_ = retransmission.packet_number_length;
425 next_packet_number_length_ = retransmission.packet_number_length; 427 next_packet_number_length_ = retransmission.packet_number_length;
426 fec_protect_ = false; 428 fec_protect_ = false;
427 needs_padding_ = retransmission.needs_padding; 429 needs_padding_ = retransmission.needs_padding;
428 // Only preserve the original encryption level if it's a handshake packet or 430 // Only preserve the original encryption level if it's a handshake packet or
429 // if we haven't gone forward secure. 431 // if we haven't gone forward secure.
430 if (retransmission.has_crypto_handshake || 432 if (retransmission.has_crypto_handshake ||
431 encryption_level_ != ENCRYPTION_FORWARD_SECURE) { 433 encryption_level_ != ENCRYPTION_FORWARD_SECURE) {
432 encryption_level_ = retransmission.encryption_level; 434 encryption_level_ = retransmission.encryption_level;
433 } 435 }
434 436
435 // Serialize the packet and restore the FEC and packet number length state. 437 // Serialize the packet and restore the FEC and packet number length state.
436 SerializedPacket serialized_packet = SerializeAllFrames( 438 for (const QuicFrame& frame : retransmission.retransmittable_frames) {
437 retransmission.retransmittable_frames, buffer, buffer_len); 439 bool success = AddFrame(frame, false);
440 DCHECK(success);
441 }
442 SerializedPacket serialized_packet = SerializePacket(buffer, buffer_len);
438 if (FLAGS_quic_retransmit_via_onserializedpacket) { 443 if (FLAGS_quic_retransmit_via_onserializedpacket) {
439 serialized_packet.original_packet_number = retransmission.packet_number; 444 serialized_packet.original_packet_number = retransmission.packet_number;
440 serialized_packet.transmission_type = retransmission.transmission_type; 445 serialized_packet.transmission_type = retransmission.transmission_type;
441 } 446 }
442 447
443 packet_number_length_ = saved_length; 448 packet_number_length_ = saved_length;
444 next_packet_number_length_ = saved_next_length; 449 next_packet_number_length_ = saved_next_length;
445 fec_protect_ = saved_should_fec_protect; 450 fec_protect_ = saved_should_fec_protect;
446 encryption_level_ = default_encryption_level; 451 encryption_level_ = default_encryption_level;
447 452
448 if (FLAGS_quic_retransmit_via_onserializedpacket) { 453 if (FLAGS_quic_retransmit_via_onserializedpacket) {
449 OnSerializedPacket(&serialized_packet); 454 OnSerializedPacket(&serialized_packet);
450 return NoPacket(); 455 return NoPacket();
451 } else { 456 } else {
452 has_crypto_handshake_ = NOT_HANDSHAKE; 457 has_crypto_handshake_ = NOT_HANDSHAKE;
453 needs_padding_ = saved_needs_padding; 458 needs_padding_ = saved_needs_padding;
454 return serialized_packet; 459 return serialized_packet;
455 } 460 }
456 } 461 }
457 462
458 SerializedPacket QuicPacketCreator::SerializeAllFrames(const QuicFrames& frames,
459 char* buffer,
460 size_t buffer_len) {
461 QUIC_BUG_IF(!queued_frames_.empty()) << "Frames already queued.";
462 QUIC_BUG_IF(frames.empty()) << "Attempt to serialize empty packet";
463 for (const QuicFrame& frame : frames) {
464 bool success = AddFrame(frame, false);
465 DCHECK(success);
466 }
467 SerializedPacket packet = SerializePacket(buffer, buffer_len);
468 DCHECK(packet.retransmittable_frames == nullptr);
469 return packet;
470 }
471
472 void QuicPacketCreator::Flush() { 463 void QuicPacketCreator::Flush() {
473 if (!HasPendingFrames()) { 464 if (!HasPendingFrames()) {
474 return; 465 return;
475 } 466 }
476 467
477 // TODO(rtenneti): Change the default 64 alignas value (used the default 468 // TODO(rtenneti): Change the default 64 alignas value (used the default
478 // value from CACHELINE_SIZE). 469 // value from CACHELINE_SIZE).
479 ALIGNAS(64) char seralized_packet_buffer[kMaxPacketSize]; 470 ALIGNAS(64) char seralized_packet_buffer[kMaxPacketSize];
480 SerializedPacket serialized_packet = 471 SerializedPacket serialized_packet =
481 SerializePacket(seralized_packet_buffer, kMaxPacketSize); 472 SerializePacket(seralized_packet_buffer, kMaxPacketSize);
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 packet_number_ = it == multipath_packet_number_.end() ? 0 : it->second; 856 packet_number_ = it == multipath_packet_number_.end() ? 0 : it->second;
866 current_path_ = path_id; 857 current_path_ = path_id;
867 DCHECK(current_path_ != kInvalidPathId); 858 DCHECK(current_path_ != kInvalidPathId);
868 // Send path in packet if current path is not the default path. 859 // Send path in packet if current path is not the default path.
869 send_path_id_in_packet_ = current_path_ != kDefaultPathId ? true : false; 860 send_path_id_in_packet_ = current_path_ != kDefaultPathId ? true : false;
870 // Switching path needs to update packet number length. 861 // Switching path needs to update packet number length.
871 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); 862 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight);
872 } 863 }
873 864
874 } // namespace net 865 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_creator.h ('k') | net/quic/quic_packet_creator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698