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

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

Issue 47283002: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compilation error Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_framer.h ('k') | net/quic/quic_framer_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_framer.h" 5 #include "net/quic/quic_framer.h"
6 6
7 #include "base/containers/hash_tables.h" 7 #include "base/containers/hash_tables.h"
8 #include "net/quic/crypto/quic_decrypter.h" 8 #include "net/quic/crypto/quic_decrypter.h"
9 #include "net/quic/crypto/quic_encrypter.h" 9 #include "net/quic/crypto/quic_encrypter.h"
10 #include "net/quic/quic_data_reader.h" 10 #include "net/quic/quic_data_reader.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 QuicPacketSequenceNumber b) { 107 QuicPacketSequenceNumber b) {
108 return (Delta(target, a) < Delta(target, b)) ? a : b; 108 return (Delta(target, a) < Delta(target, b)) ? a : b;
109 } 109 }
110 110
111 QuicTag GetNullTag(QuicVersion version) { 111 QuicTag GetNullTag(QuicVersion version) {
112 return version >= QUIC_VERSION_11 ? kNULN : kNULL; 112 return version >= QUIC_VERSION_11 ? kNULN : kNULL;
113 } 113 }
114 114
115 } // namespace 115 } // namespace
116 116
117 QuicFramer::QuicFramer(QuicVersion version, 117 QuicFramer::QuicFramer(const QuicVersionVector& supported_versions,
118 QuicTime creation_time, 118 QuicTime creation_time,
119 bool is_server) 119 bool is_server)
120 : visitor_(NULL), 120 : visitor_(NULL),
121 fec_builder_(NULL), 121 fec_builder_(NULL),
122 error_(QUIC_NO_ERROR), 122 error_(QUIC_NO_ERROR),
123 last_sequence_number_(0), 123 last_sequence_number_(0),
124 last_serialized_guid_(0), 124 last_serialized_guid_(0),
125 quic_version_(version), 125 supported_versions_(supported_versions),
126 decrypter_(QuicDecrypter::Create(GetNullTag(version))),
127 alternative_decrypter_latch_(false), 126 alternative_decrypter_latch_(false),
128 is_server_(is_server), 127 is_server_(is_server),
129 creation_time_(creation_time) { 128 creation_time_(creation_time) {
130 DCHECK(IsSupportedVersion(version)); 129 DCHECK(!supported_versions.empty());
131 encrypter_[ENCRYPTION_NONE].reset(QuicEncrypter::Create(GetNullTag(version))); 130 quic_version_ = supported_versions_[0];
131 decrypter_.reset(QuicDecrypter::Create(GetNullTag(quic_version_)));
132 encrypter_[ENCRYPTION_NONE].reset(
133 QuicEncrypter::Create(GetNullTag(quic_version_)));
132 } 134 }
133 135
134 QuicFramer::~QuicFramer() {} 136 QuicFramer::~QuicFramer() {}
135 137
136 // static 138 // static
137 size_t QuicFramer::GetMinStreamFrameSize(QuicVersion version, 139 size_t QuicFramer::GetMinStreamFrameSize(QuicVersion version,
138 QuicStreamId stream_id, 140 QuicStreamId stream_id,
139 QuicStreamOffset offset, 141 QuicStreamOffset offset,
140 bool last_frame_in_packet) { 142 bool last_frame_in_packet) {
141 return kQuicFrameTypeSize + GetStreamIdSize(stream_id) + 143 return kQuicFrameTypeSize + GetStreamIdSize(stream_id) +
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // checking for it here results in frames not being added, but the resulting 224 // checking for it here results in frames not being added, but the resulting
223 // frames do actually fit. 225 // frames do actually fit.
224 if ((frame.type == ACK_FRAME || frame.type == CONNECTION_CLOSE_FRAME) && 226 if ((frame.type == ACK_FRAME || frame.type == CONNECTION_CLOSE_FRAME) &&
225 free_bytes >= GetMinAckFrameSize()) { 227 free_bytes >= GetMinAckFrameSize()) {
226 return true; 228 return true;
227 } 229 }
228 return false; 230 return false;
229 } 231 }
230 232
231 bool QuicFramer::IsSupportedVersion(const QuicVersion version) const { 233 bool QuicFramer::IsSupportedVersion(const QuicVersion version) const {
232 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { 234 for (size_t i = 0; i < supported_versions_.size(); ++i) {
233 if (version == kSupportedQuicVersions[i]) { 235 if (version == supported_versions_[i]) {
234 return true; 236 return true;
235 } 237 }
236 } 238 }
237 return false; 239 return false;
238 } 240 }
239 241
240 size_t QuicFramer::GetSerializedFrameLength(const QuicFrame& frame, 242 size_t QuicFramer::GetSerializedFrameLength(const QuicFrame& frame,
241 size_t free_bytes, 243 size_t free_bytes,
242 bool first_frame, 244 bool first_frame,
243 bool last_frame) { 245 bool last_frame) {
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 memcpy(buffer, header_data.data(), header_data.length()); 1428 memcpy(buffer, header_data.data(), header_data.length());
1427 memcpy(buffer + header_data.length(), out->data(), out->length()); 1429 memcpy(buffer + header_data.length(), out->data(), out->length());
1428 return new QuicEncryptedPacket(buffer, len, true); 1430 return new QuicEncryptedPacket(buffer, len, true);
1429 } 1431 }
1430 1432
1431 size_t QuicFramer::GetMaxPlaintextSize(size_t ciphertext_size) { 1433 size_t QuicFramer::GetMaxPlaintextSize(size_t ciphertext_size) {
1432 // In order to keep the code simple, we don't have the current encryption 1434 // In order to keep the code simple, we don't have the current encryption
1433 // level to hand. At the moment, the NullEncrypter has a tag length of 16 1435 // level to hand. At the moment, the NullEncrypter has a tag length of 16
1434 // bytes and AES-GCM has a tag length of 12. We take the minimum plaintext 1436 // bytes and AES-GCM has a tag length of 12. We take the minimum plaintext
1435 // length just to be safe. 1437 // length just to be safe.
1436 size_t min_plaintext_size = ciphertext_size; 1438 // TODO(rtenneti): remove '- 16' after we delete QUIC_VERSION_10.
1439 size_t min_plaintext_size = ciphertext_size - 16;
1437 1440
1438 for (int i = ENCRYPTION_NONE; i < NUM_ENCRYPTION_LEVELS; i++) { 1441 for (int i = ENCRYPTION_NONE; i < NUM_ENCRYPTION_LEVELS; i++) {
1439 if (encrypter_[i].get() != NULL) { 1442 if (encrypter_[i].get() != NULL) {
1440 size_t size = encrypter_[i]->GetMaxPlaintextSize(ciphertext_size); 1443 size_t size = encrypter_[i]->GetMaxPlaintextSize(ciphertext_size);
1441 if (size < min_plaintext_size) { 1444 if (size < min_plaintext_size) {
1442 min_plaintext_size = size; 1445 min_plaintext_size = size;
1443 } 1446 }
1444 } 1447 }
1445 } 1448 }
1446 1449
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 if (it != missing_packets.end() && previous_missing + 1 != *it) { 1680 if (it != missing_packets.end() && previous_missing + 1 != *it) {
1678 return *it - 1; 1681 return *it - 1;
1679 } 1682 }
1680 1683
1681 // Otherwise return the largest missing packet, as indirectly observed. 1684 // Otherwise return the largest missing packet, as indirectly observed.
1682 return *largest_written; 1685 return *largest_written;
1683 } 1686 }
1684 1687
1685 void QuicFramer::set_version(const QuicVersion version) { 1688 void QuicFramer::set_version(const QuicVersion version) {
1686 DCHECK(IsSupportedVersion(version)); 1689 DCHECK(IsSupportedVersion(version));
1690 // Handle version incompatibility between QUIC_VERSION_10 and QUIC_VERSION_11
1691 // because of introduction of a new QUIC null encryption format in
1692 // QUIC_VERSION_11.
1687 if ((quic_version_ > QUIC_VERSION_10 && version <= QUIC_VERSION_10) || 1693 if ((quic_version_ > QUIC_VERSION_10 && version <= QUIC_VERSION_10) ||
1688 (quic_version_ <= QUIC_VERSION_10 && version > QUIC_VERSION_10)) { 1694 (quic_version_ <= QUIC_VERSION_10 && version > QUIC_VERSION_10)) {
1689 // TODO(rtenneti): remove the following code after we delete 1695 // TODO(rtenneti): remove the following code after we delete
1690 // QUIC_VERSION_10. 1696 // QUIC_VERSION_10.
1691 decrypter_.reset(QuicDecrypter::Create(GetNullTag(version))); 1697 decrypter_.reset(QuicDecrypter::Create(GetNullTag(version)));
1692 encrypter_[ENCRYPTION_NONE].reset( 1698 encrypter_[ENCRYPTION_NONE].reset(
1693 QuicEncrypter::Create(GetNullTag(version))); 1699 QuicEncrypter::Create(GetNullTag(version)));
1694 } 1700 }
1695 quic_version_ = version; 1701 quic_version_ = version;
1696 } 1702 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1909 1915
1910 bool QuicFramer::RaiseError(QuicErrorCode error) { 1916 bool QuicFramer::RaiseError(QuicErrorCode error) {
1911 DLOG(INFO) << detailed_error_; 1917 DLOG(INFO) << detailed_error_;
1912 set_error(error); 1918 set_error(error);
1913 visitor_->OnError(this); 1919 visitor_->OnError(this);
1914 reader_.reset(NULL); 1920 reader_.reset(NULL);
1915 return false; 1921 return false;
1916 } 1922 }
1917 1923
1918 } // namespace net 1924 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer.h ('k') | net/quic/quic_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698