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

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

Issue 1785513003: Simplify QUIC's encryption path now that FEC is gone. Protected by FLAG_quic_inplace_encryption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@116261116
Patch Set: Created 4 years, 9 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_framer.cc ('k') | net/quic/quic_protocol.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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 size_t encrypted_buffer_len) { 415 size_t encrypted_buffer_len) {
416 DCHECK_LT(0u, encrypted_buffer_len); 416 DCHECK_LT(0u, encrypted_buffer_len);
417 QUIC_BUG_IF(queued_frames_.empty()) << "Attempt to serialize empty packet"; 417 QUIC_BUG_IF(queued_frames_.empty()) << "Attempt to serialize empty packet";
418 QuicPacketHeader header; 418 QuicPacketHeader header;
419 // FillPacketHeader increments packet_number_. 419 // FillPacketHeader increments packet_number_.
420 FillPacketHeader(&header); 420 FillPacketHeader(&header);
421 421
422 MaybeAddPadding(); 422 MaybeAddPadding();
423 423
424 DCHECK_GE(max_plaintext_size_, packet_size_); 424 DCHECK_GE(max_plaintext_size_, packet_size_);
425 // ACK Frames will be truncated due to length only if they're the only frame
426 // in the packet, and if packet_size_ was set to max_plaintext_size_. If
427 // truncation due to length occurred, then GetSerializedFrameLength will have
428 // returned all bytes free.
429 bool possibly_truncated_by_length = packet_size_ == max_plaintext_size_ &&
430 queued_frames_.size() == 1 &&
431 queued_frames_.back().type == ACK_FRAME;
432 // Use the packet_size_ instead of the buffer size to ensure smaller 425 // Use the packet_size_ instead of the buffer size to ensure smaller
433 // packet sizes are properly used. 426 // packet sizes are properly used.
434 size_t length = framer_->BuildDataPacket(header, queued_frames_, 427 size_t length = framer_->BuildDataPacket(header, queued_frames_,
435 encrypted_buffer, packet_size_); 428 encrypted_buffer, packet_size_);
436 if (length == 0) { 429 if (length == 0) {
437 QUIC_BUG << "Failed to serialize " << queued_frames_.size() << " frames."; 430 QUIC_BUG << "Failed to serialize " << queued_frames_.size() << " frames.";
438 return; 431 return;
439 } 432 }
440 433
441 // TODO(ianswett) Consider replacing QuicPacket with something else, since 434 // ACK Frames will be truncated due to length only if they're the only frame
442 // it's only used to provide convenience methods to FEC and encryption. 435 // in the packet, and if packet_size_ was set to max_plaintext_size_. If
443 QuicPacket packet( 436 // truncation due to length occurred, then GetSerializedFrameLength will have
444 encrypted_buffer, length, 437 // returned all bytes free.
445 /* owns_buffer */ false, header.public_header.connection_id_length, 438 bool possibly_truncated_by_length = packet_size_ == max_plaintext_size_ &&
446 header.public_header.version_flag, header.public_header.multipath_flag, 439 queued_frames_.size() == 1 &&
447 header.public_header.packet_number_length); 440 queued_frames_.back().type == ACK_FRAME;
448
449 // Because of possible truncation, we can't be confident that our 441 // Because of possible truncation, we can't be confident that our
450 // packet size calculation worked correctly. 442 // packet size calculation worked correctly.
451 if (!possibly_truncated_by_length) { 443 if (!possibly_truncated_by_length) {
452 DCHECK_EQ(packet_size_, length); 444 DCHECK_EQ(packet_size_, length);
453 } 445 }
454 // Immediately encrypt the packet, to ensure we don't encrypt the same 446 size_t encrypted_length = 0;
455 // packet number multiple times. 447 if (FLAGS_quic_inplace_encryption2) {
456 size_t encrypted_length = framer_->EncryptPayload( 448 const size_t ad_len = GetStartOfEncryptedData(header);
457 packet_.encryption_level, packet_.path_id, packet_.packet_number, packet, 449 encrypted_length = framer_->EncryptInPlace(
458 encrypted_buffer, encrypted_buffer_len); 450 packet_.encryption_level, packet_.path_id, packet_.packet_number,
451 ad_len, length, encrypted_buffer_len, encrypted_buffer);
452 } else {
453 QuicPacket packet(
454 encrypted_buffer, length,
455 /* owns_buffer */ false, header.public_header.connection_id_length,
456 header.public_header.version_flag, header.public_header.multipath_flag,
457 header.public_header.packet_number_length);
458 // Immediately encrypt the packet, to ensure we don't encrypt the same
459 // packet number multiple times.
460 encrypted_length = framer_->EncryptPayload(
461 packet_.encryption_level, packet_.path_id, packet_.packet_number,
462 packet, encrypted_buffer, encrypted_buffer_len);
463 }
459 if (encrypted_length == 0) { 464 if (encrypted_length == 0) {
460 QUIC_BUG << "Failed to encrypt packet number " << packet_.packet_number; 465 QUIC_BUG << "Failed to encrypt packet number " << packet_.packet_number;
461 return; 466 return;
462 } 467 }
463 468
464 packet_size_ = 0; 469 packet_size_ = 0;
465 queued_frames_.clear(); 470 queued_frames_.clear();
466 packet_.entropy_hash = QuicFramer::GetPacketEntropyHash(header); 471 packet_.entropy_hash = QuicFramer::GetPacketEntropyHash(header);
467 packet_.encrypted_buffer = encrypted_buffer; 472 packet_.encrypted_buffer = encrypted_buffer;
468 packet_.encrypted_length = encrypted_length; 473 packet_.encrypted_length = encrypted_length;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 packet_.packet_number = it == multipath_packet_number_.end() ? 0 : it->second; 601 packet_.packet_number = it == multipath_packet_number_.end() ? 0 : it->second;
597 packet_.path_id = path_id; 602 packet_.path_id = path_id;
598 DCHECK(packet_.path_id != kInvalidPathId); 603 DCHECK(packet_.path_id != kInvalidPathId);
599 // Send path in packet if current path is not the default path. 604 // Send path in packet if current path is not the default path.
600 send_path_id_in_packet_ = packet_.path_id != kDefaultPathId ? true : false; 605 send_path_id_in_packet_ = packet_.path_id != kDefaultPathId ? true : false;
601 // Switching path needs to update packet number length. 606 // Switching path needs to update packet number length.
602 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); 607 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight);
603 } 608 }
604 609
605 } // namespace net 610 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698