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

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

Issue 20227003: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Land Recent QUIC changes Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_protocol.h ('k') | net/quic/quic_protocol_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_protocol.h" 5 #include "net/quic/quic_protocol.h"
6
6 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "net/quic/quic_utils.h"
7 9
8 using base::StringPiece; 10 using base::StringPiece;
9 using std::map; 11 using std::map;
10 using std::numeric_limits; 12 using std::numeric_limits;
11 using std::ostream; 13 using std::ostream;
12 using std::string; 14 using std::string;
13 15
14 namespace net { 16 namespace net {
15 17
16 size_t GetPacketHeaderSize(QuicPacketHeader header) { 18 size_t GetPacketHeaderSize(QuicPacketHeader header) {
(...skipping 28 matching lines...) Expand all
45 size_t GetStartOfEncryptedData( 47 size_t GetStartOfEncryptedData(
46 QuicGuidLength guid_length, 48 QuicGuidLength guid_length,
47 bool include_version, 49 bool include_version,
48 QuicSequenceNumberLength sequence_number_length) { 50 QuicSequenceNumberLength sequence_number_length) {
49 // Don't include the fec size, since encryption starts before private flags. 51 // Don't include the fec size, since encryption starts before private flags.
50 return GetPacketHeaderSize( 52 return GetPacketHeaderSize(
51 guid_length, include_version, sequence_number_length, NOT_IN_FEC_GROUP) - 53 guid_length, include_version, sequence_number_length, NOT_IN_FEC_GROUP) -
52 kPrivateFlagsSize; 54 kPrivateFlagsSize;
53 } 55 }
54 56
55 uint32 MakeQuicTag(char a, char b, char c, char d) {
56 return static_cast<uint32>(a) |
57 static_cast<uint32>(b) << 8 |
58 static_cast<uint32>(c) << 16 |
59 static_cast<uint32>(d) << 24;
60 }
61
62 QuicPacketPublicHeader::QuicPacketPublicHeader() 57 QuicPacketPublicHeader::QuicPacketPublicHeader()
63 : guid(0), 58 : guid(0),
64 guid_length(PACKET_8BYTE_GUID), 59 guid_length(PACKET_8BYTE_GUID),
65 reset_flag(false), 60 reset_flag(false),
66 version_flag(false), 61 version_flag(false),
67 sequence_number_length(PACKET_6BYTE_SEQUENCE_NUMBER) { 62 sequence_number_length(PACKET_6BYTE_SEQUENCE_NUMBER) {
68 } 63 }
69 64
70 QuicPacketPublicHeader::QuicPacketPublicHeader( 65 QuicPacketPublicHeader::QuicPacketPublicHeader(
71 const QuicPacketPublicHeader& other) 66 const QuicPacketPublicHeader& other)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 QuicStreamFrame::QuicStreamFrame(QuicStreamId stream_id, 107 QuicStreamFrame::QuicStreamFrame(QuicStreamId stream_id,
113 bool fin, 108 bool fin,
114 QuicStreamOffset offset, 109 QuicStreamOffset offset,
115 StringPiece data) 110 StringPiece data)
116 : stream_id(stream_id), 111 : stream_id(stream_id),
117 fin(fin), 112 fin(fin),
118 offset(offset), 113 offset(offset),
119 data(data) { 114 data(data) {
120 } 115 }
121 116
117 uint32 MakeQuicTag(char a, char b, char c, char d) {
118 return static_cast<uint32>(a) |
119 static_cast<uint32>(b) << 8 |
120 static_cast<uint32>(c) << 16 |
121 static_cast<uint32>(d) << 24;
122 }
123
124 QuicVersion QuicVersionMax() { return kSupportedQuicVersions[0]; }
125
126 QuicTag QuicVersionToQuicTag(const QuicVersion version) {
127 switch (version) {
128 case QUIC_VERSION_6:
129 return MakeQuicTag('Q', '0', '0', '6');
130 // case QUIC_VERSION_7
131 // return MakeQuicTag('Q', '0', '0', '7');
132 default:
133 // This shold be an ERROR because we should never attempt to convert an
134 // invalid QuicVersion to be written to the wire.
135 LOG(ERROR) << "Unsupported QuicVersion: " << version;
136 return 0;
137 }
138 }
139
140 QuicVersion QuicTagToQuicVersion(const QuicTag version_tag) {
141 const QuicTag quic_tag_v6 = MakeQuicTag('Q', '0', '0', '6');
142 // const QuicTag quic_tag_v7 = MakeQuicTag('Q', '0', '0', '7');
143
144 if (version_tag == quic_tag_v6) {
145 return QUIC_VERSION_6;
146 // } else if (version_tag == quic_tag_v7) {
147 // return QUIC_VERSION_7;
148 } else {
149 // Reading from the client so this should not be considered an ERROR.
150 DLOG(INFO) << "Unsupported QuicTag version: "
151 << QuicUtils::TagToString(version_tag);
152 return QUIC_VERSION_UNSUPPORTED;
153 }
154 }
155
156 string QuicVersionToString(const QuicVersion version) {
157 // TODO(rjshade): Possibly start using RETURN_STRING_LITERAL here when we
158 // start supporting a lot of versions.
159 switch (version) {
160 case QUIC_VERSION_6:
161 return "QUIC_VERSION_6";
162 // case QUIC_VERSION_7:
163 // return "QUIC_VERSION_7";
164 default:
165 return "QUIC_VERSION_UNSUPPORTED";
166 }
167 }
168
169 string QuicVersionArrayToString(const QuicVersion versions[],
170 int num_versions) {
171 string result = "";
172 for (int i = 0; i < num_versions; ++i) {
173 const QuicVersion& version = versions[i];
174 result.append(QuicVersionToString(version));
175 result.append(",");
176 }
177 return result;
178 }
179
122 ostream& operator<<(ostream& os, const QuicPacketHeader& header) { 180 ostream& operator<<(ostream& os, const QuicPacketHeader& header) {
123 os << "{ guid: " << header.public_header.guid 181 os << "{ guid: " << header.public_header.guid
124 << ", guid_length:" << header.public_header.guid_length 182 << ", guid_length:" << header.public_header.guid_length
125 << ", reset_flag: " << header.public_header.reset_flag 183 << ", reset_flag: " << header.public_header.reset_flag
126 << ", version_flag: " << header.public_header.version_flag; 184 << ", version_flag: " << header.public_header.version_flag;
127 if (header.public_header.version_flag) { 185 if (header.public_header.version_flag) {
128 os << " version: "; 186 os << " version: ";
129 for (size_t i = 0; i < header.public_header.versions.size(); ++i) { 187 for (size_t i = 0; i < header.public_header.versions.size(); ++i) {
130 os << header.public_header.versions[0] << " "; 188 os << header.public_header.versions[0] << " ";
131 } 189 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 return os; 416 return os;
359 } 417 }
360 418
361 ostream& operator<<(ostream& os, const QuicConsumedData& s) { 419 ostream& operator<<(ostream& os, const QuicConsumedData& s) {
362 os << "bytes_consumed: " << s.bytes_consumed 420 os << "bytes_consumed: " << s.bytes_consumed
363 << " fin_consumed: " << s.fin_consumed; 421 << " fin_consumed: " << s.fin_consumed;
364 return os; 422 return os;
365 } 423 }
366 424
367 } // namespace net 425 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_protocol.h ('k') | net/quic/quic_protocol_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698