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

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

Issue 1904213002: QUIC: support diversified keys with version 33. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hkdf
Patch Set: Rebase Created 4 years, 7 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 QuicBufferAllocator* buffer_allocator, 63 QuicBufferAllocator* buffer_allocator,
64 DelegateInterface* delegate) 64 DelegateInterface* delegate)
65 : delegate_(delegate), 65 : delegate_(delegate),
66 debug_delegate_(nullptr), 66 debug_delegate_(nullptr),
67 framer_(framer), 67 framer_(framer),
68 random_bool_source_(new QuicRandomBoolSource(random_generator)), 68 random_bool_source_(new QuicRandomBoolSource(random_generator)),
69 buffer_allocator_(buffer_allocator), 69 buffer_allocator_(buffer_allocator),
70 send_version_in_packet_(framer->perspective() == Perspective::IS_CLIENT), 70 send_version_in_packet_(framer->perspective() == Perspective::IS_CLIENT),
71 send_path_id_in_packet_(false), 71 send_path_id_in_packet_(false),
72 next_packet_number_length_(PACKET_1BYTE_PACKET_NUMBER), 72 next_packet_number_length_(PACKET_1BYTE_PACKET_NUMBER),
73 have_diversification_nonce_(false),
73 max_packet_length_(0), 74 max_packet_length_(0),
74 connection_id_length_(PACKET_8BYTE_CONNECTION_ID), 75 connection_id_length_(PACKET_8BYTE_CONNECTION_ID),
75 packet_size_(0), 76 packet_size_(0),
76 connection_id_(connection_id), 77 connection_id_(connection_id),
77 packet_(kDefaultPathId, 78 packet_(kDefaultPathId,
78 0, 79 0,
79 next_packet_number_length_, 80 next_packet_number_length_,
80 nullptr, 81 nullptr,
81 0, 82 0,
82 0, 83 0,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // maximum packet size if we stop sending version before it is serialized. 129 // maximum packet size if we stop sending version before it is serialized.
129 void QuicPacketCreator::StopSendingVersion() { 130 void QuicPacketCreator::StopSendingVersion() {
130 DCHECK(send_version_in_packet_); 131 DCHECK(send_version_in_packet_);
131 send_version_in_packet_ = false; 132 send_version_in_packet_ = false;
132 if (packet_size_ > 0) { 133 if (packet_size_ > 0) {
133 DCHECK_LT(kQuicVersionSize, packet_size_); 134 DCHECK_LT(kQuicVersionSize, packet_size_);
134 packet_size_ -= kQuicVersionSize; 135 packet_size_ -= kQuicVersionSize;
135 } 136 }
136 } 137 }
137 138
139 void QuicPacketCreator::SetDiversificationNonce(
140 const DiversificationNonce nonce) {
141 DCHECK(!have_diversification_nonce_);
142 have_diversification_nonce_ = true;
143 memcpy(&diversification_nonce_, nonce, sizeof(diversification_nonce_));
144 }
145
138 void QuicPacketCreator::UpdatePacketNumberLength( 146 void QuicPacketCreator::UpdatePacketNumberLength(
139 QuicPacketNumber least_packet_awaited_by_peer, 147 QuicPacketNumber least_packet_awaited_by_peer,
140 QuicPacketCount max_packets_in_flight) { 148 QuicPacketCount max_packets_in_flight) {
141 DCHECK_LE(least_packet_awaited_by_peer, packet_.packet_number + 1); 149 DCHECK_LE(least_packet_awaited_by_peer, packet_.packet_number + 1);
142 const QuicPacketNumber current_delta = 150 const QuicPacketNumber current_delta =
143 packet_.packet_number + 1 - least_packet_awaited_by_peer; 151 packet_.packet_number + 1 - least_packet_awaited_by_peer;
144 const uint64_t delta = max(current_delta, max_packets_in_flight); 152 const uint64_t delta = max(current_delta, max_packets_in_flight);
145 next_packet_number_length_ = 153 next_packet_number_length_ =
146 QuicFramer::GetMinSequenceNumberLength(delta * 4); 154 QuicFramer::GetMinSequenceNumberLength(delta * 4);
147 } 155 }
(...skipping 23 matching lines...) Expand all
171 bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id, 179 bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id,
172 QuicStreamOffset offset) { 180 QuicStreamOffset offset) {
173 return BytesFree() > QuicFramer::GetMinStreamFrameSize(id, offset, true); 181 return BytesFree() > QuicFramer::GetMinStreamFrameSize(id, offset, true);
174 } 182 }
175 183
176 // static 184 // static
177 size_t QuicPacketCreator::StreamFramePacketOverhead( 185 size_t QuicPacketCreator::StreamFramePacketOverhead(
178 QuicConnectionIdLength connection_id_length, 186 QuicConnectionIdLength connection_id_length,
179 bool include_version, 187 bool include_version,
180 bool include_path_id, 188 bool include_path_id,
189 bool include_diversification_nonce,
181 QuicPacketNumberLength packet_number_length, 190 QuicPacketNumberLength packet_number_length,
182 QuicStreamOffset offset) { 191 QuicStreamOffset offset) {
183 return GetPacketHeaderSize(connection_id_length, include_version, 192 return GetPacketHeaderSize(connection_id_length, include_version,
184 include_path_id, packet_number_length) + 193 include_path_id, include_diversification_nonce,
194 packet_number_length) +
185 // Assumes this is a stream with a single lone packet. 195 // Assumes this is a stream with a single lone packet.
186 QuicFramer::GetMinStreamFrameSize(1u, offset, true); 196 QuicFramer::GetMinStreamFrameSize(1u, offset, true);
187 } 197 }
188 198
189 void QuicPacketCreator::CreateStreamFrame(QuicStreamId id, 199 void QuicPacketCreator::CreateStreamFrame(QuicStreamId id,
190 QuicIOVector iov, 200 QuicIOVector iov,
191 size_t iov_offset, 201 size_t iov_offset,
192 QuicStreamOffset offset, 202 QuicStreamOffset offset,
193 bool fin, 203 bool fin,
194 QuicFrame* frame) { 204 QuicFrame* frame) {
195 DCHECK_GT(max_packet_length_, 205 DCHECK_GT(
196 StreamFramePacketOverhead(connection_id_length_, kIncludeVersion, 206 max_packet_length_,
197 kIncludePathId, 207 StreamFramePacketOverhead(connection_id_length_, kIncludeVersion,
198 PACKET_6BYTE_PACKET_NUMBER, offset)); 208 kIncludePathId, IncludeNonceInPublicHeader(),
209 PACKET_6BYTE_PACKET_NUMBER, offset));
199 210
200 MaybeUpdatePacketNumberLength(); 211 MaybeUpdatePacketNumberLength();
201 212
202 LOG_IF(DFATAL, !HasRoomForStreamFrame(id, offset)) 213 LOG_IF(DFATAL, !HasRoomForStreamFrame(id, offset))
203 << "No room for Stream frame, BytesFree: " << BytesFree() 214 << "No room for Stream frame, BytesFree: " << BytesFree()
204 << " MinStreamFrameSize: " 215 << " MinStreamFrameSize: "
205 << QuicFramer::GetMinStreamFrameSize(id, offset, true); 216 << QuicFramer::GetMinStreamFrameSize(id, offset, true);
206 217
207 if (iov_offset == iov.total_length) { 218 if (iov_offset == iov.total_length) {
208 QUIC_BUG_IF(!fin) << "Creating a stream frame with no data or fin."; 219 QUIC_BUG_IF(!fin) << "Creating a stream frame with no data or fin.";
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 } 393 }
383 394
384 size_t QuicPacketCreator::PacketSize() { 395 size_t QuicPacketCreator::PacketSize() {
385 if (!queued_frames_.empty()) { 396 if (!queued_frames_.empty()) {
386 return packet_size_; 397 return packet_size_;
387 } 398 }
388 // Update packet number length on packet boundary. 399 // Update packet number length on packet boundary.
389 packet_.packet_number_length = next_packet_number_length_; 400 packet_.packet_number_length = next_packet_number_length_;
390 packet_size_ = GetPacketHeaderSize( 401 packet_size_ = GetPacketHeaderSize(
391 connection_id_length_, send_version_in_packet_, send_path_id_in_packet_, 402 connection_id_length_, send_version_in_packet_, send_path_id_in_packet_,
392 packet_.packet_number_length); 403 IncludeNonceInPublicHeader(), packet_.packet_number_length);
393 return packet_size_; 404 return packet_size_;
394 } 405 }
395 406
396 bool QuicPacketCreator::AddSavedFrame(const QuicFrame& frame) { 407 bool QuicPacketCreator::AddSavedFrame(const QuicFrame& frame) {
397 return AddFrame(frame, /*save_retransmittable_frames=*/true); 408 return AddFrame(frame, /*save_retransmittable_frames=*/true);
398 } 409 }
399 410
400 bool QuicPacketCreator::AddPaddedSavedFrame(const QuicFrame& frame) { 411 bool QuicPacketCreator::AddPaddedSavedFrame(const QuicFrame& frame) {
401 if (AddFrame(frame, /*save_retransmittable_frames=*/true)) { 412 if (AddFrame(frame, /*save_retransmittable_frames=*/true)) {
402 packet_.needs_padding = true; 413 packet_.needs_padding = true;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 return SerializedPacket(kInvalidPathId, 0, PACKET_1BYTE_PACKET_NUMBER, 485 return SerializedPacket(kInvalidPathId, 0, PACKET_1BYTE_PACKET_NUMBER,
475 nullptr, 0, 0, false, false); 486 nullptr, 0, 0, false, false);
476 } 487 }
477 488
478 void QuicPacketCreator::FillPacketHeader(QuicPacketHeader* header) { 489 void QuicPacketCreator::FillPacketHeader(QuicPacketHeader* header) {
479 header->public_header.connection_id = connection_id_; 490 header->public_header.connection_id = connection_id_;
480 header->public_header.connection_id_length = connection_id_length_; 491 header->public_header.connection_id_length = connection_id_length_;
481 header->public_header.multipath_flag = send_path_id_in_packet_; 492 header->public_header.multipath_flag = send_path_id_in_packet_;
482 header->public_header.reset_flag = false; 493 header->public_header.reset_flag = false;
483 header->public_header.version_flag = send_version_in_packet_; 494 header->public_header.version_flag = send_version_in_packet_;
484 header->fec_flag = false; 495 if (IncludeNonceInPublicHeader()) {
496 DCHECK_EQ(Perspective::IS_SERVER, framer_->perspective());
497 header->public_header.nonce = &diversification_nonce_;
498 } else {
499 header->public_header.nonce = nullptr;
500 }
485 header->path_id = packet_.path_id; 501 header->path_id = packet_.path_id;
486 header->packet_number = ++packet_.packet_number; 502 header->packet_number = ++packet_.packet_number;
487 header->public_header.packet_number_length = packet_.packet_number_length; 503 header->public_header.packet_number_length = packet_.packet_number_length;
488 header->entropy_flag = random_bool_source_->RandBool(); 504 header->entropy_flag = random_bool_source_->RandBool();
489 header->is_in_fec_group = NOT_IN_FEC_GROUP; 505 header->is_in_fec_group = NOT_IN_FEC_GROUP;
490 header->fec_group = 0; 506 header->fec_group = 0;
491 } 507 }
492 508
493 bool QuicPacketCreator::ShouldRetransmit(const QuicFrame& frame) { 509 bool QuicPacketCreator::ShouldRetransmit(const QuicFrame& frame) {
494 switch (frame.type) { 510 switch (frame.type) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 // If path_id is not in the map, it's a new path. Set packet_number to 0. 604 // If path_id is not in the map, it's a new path. Set packet_number to 0.
589 packet_.packet_number = it == multipath_packet_number_.end() ? 0 : it->second; 605 packet_.packet_number = it == multipath_packet_number_.end() ? 0 : it->second;
590 packet_.path_id = path_id; 606 packet_.path_id = path_id;
591 DCHECK(packet_.path_id != kInvalidPathId); 607 DCHECK(packet_.path_id != kInvalidPathId);
592 // Send path in packet if current path is not the default path. 608 // Send path in packet if current path is not the default path.
593 send_path_id_in_packet_ = packet_.path_id != kDefaultPathId ? true : false; 609 send_path_id_in_packet_ = packet_.path_id != kDefaultPathId ? true : false;
594 // Switching path needs to update packet number length. 610 // Switching path needs to update packet number length.
595 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); 611 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight);
596 } 612 }
597 613
614 bool QuicPacketCreator::IncludeNonceInPublicHeader() {
615 return have_diversification_nonce_ &&
616 packet_.encryption_level == ENCRYPTION_INITIAL;
617 }
618
598 } // namespace net 619 } // 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