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

Side by Side Diff: net/quic/core/quic_config.cc

Issue 2517603003: Moves QuicTag typedefs, and QuicTag utility methods to quic_tag.{h,cc}. No behavior change. (Closed)
Patch Set: Created 4 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
« no previous file with comments | « net/quic/core/crypto/quic_crypto_server_config.cc ('k') | net/quic/core/quic_framer.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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/core/quic_config.h" 5 #include "net/quic/core/quic_config.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "net/quic/core/crypto/crypto_handshake_message.h" 10 #include "net/quic/core/crypto/crypto_handshake_message.h"
(...skipping 14 matching lines...) Expand all
25 QuicTag tag, 25 QuicTag tag,
26 QuicConfigPresence presence, 26 QuicConfigPresence presence,
27 uint32_t default_value, 27 uint32_t default_value,
28 uint32_t* out, 28 uint32_t* out,
29 string* error_details) { 29 string* error_details) {
30 DCHECK(error_details != nullptr); 30 DCHECK(error_details != nullptr);
31 QuicErrorCode error = msg.GetUint32(tag, out); 31 QuicErrorCode error = msg.GetUint32(tag, out);
32 switch (error) { 32 switch (error) {
33 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: 33 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND:
34 if (presence == PRESENCE_REQUIRED) { 34 if (presence == PRESENCE_REQUIRED) {
35 *error_details = "Missing " + QuicUtils::TagToString(tag); 35 *error_details = "Missing " + QuicTagToString(tag);
36 break; 36 break;
37 } 37 }
38 error = QUIC_NO_ERROR; 38 error = QUIC_NO_ERROR;
39 *out = default_value; 39 *out = default_value;
40 break; 40 break;
41 case QUIC_NO_ERROR: 41 case QUIC_NO_ERROR:
42 break; 42 break;
43 default: 43 default:
44 *error_details = "Bad " + QuicUtils::TagToString(tag); 44 *error_details = "Bad " + QuicTagToString(tag);
45 break; 45 break;
46 } 46 }
47 return error; 47 return error;
48 } 48 }
49 49
50 QuicConfigValue::QuicConfigValue(QuicTag tag, QuicConfigPresence presence) 50 QuicConfigValue::QuicConfigValue(QuicTag tag, QuicConfigPresence presence)
51 : tag_(tag), presence_(presence) {} 51 : tag_(tag), presence_(presence) {}
52 QuicConfigValue::~QuicConfigValue() {} 52 QuicConfigValue::~QuicConfigValue() {}
53 53
54 QuicNegotiableValue::QuicNegotiableValue(QuicTag tag, 54 QuicNegotiableValue::QuicNegotiableValue(QuicTag tag,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 string* error_details) { 97 string* error_details) {
98 DCHECK(!negotiated()); 98 DCHECK(!negotiated());
99 DCHECK(error_details != nullptr); 99 DCHECK(error_details != nullptr);
100 uint32_t value; 100 uint32_t value;
101 QuicErrorCode error = ReadUint32(peer_hello, tag_, presence_, default_value_, 101 QuicErrorCode error = ReadUint32(peer_hello, tag_, presence_, default_value_,
102 &value, error_details); 102 &value, error_details);
103 if (error != QUIC_NO_ERROR) { 103 if (error != QUIC_NO_ERROR) {
104 return error; 104 return error;
105 } 105 }
106 if (hello_type == SERVER && value > max_value_) { 106 if (hello_type == SERVER && value > max_value_) {
107 *error_details = 107 *error_details = "Invalid value received for " + QuicTagToString(tag_);
108 "Invalid value received for " + QuicUtils::TagToString(tag_);
109 return QUIC_INVALID_NEGOTIATED_VALUE; 108 return QUIC_INVALID_NEGOTIATED_VALUE;
110 } 109 }
111 110
112 set_negotiated(true); 111 set_negotiated(true);
113 negotiated_value_ = min(value, max_value_); 112 negotiated_value_ = min(value, max_value_);
114 return QUIC_NO_ERROR; 113 return QUIC_NO_ERROR;
115 } 114 }
116 115
117 QuicFixedUint32::QuicFixedUint32(QuicTag tag, QuicConfigPresence presence) 116 QuicFixedUint32::QuicFixedUint32(QuicTag tag, QuicConfigPresence presence)
118 : QuicConfigValue(tag, presence), 117 : QuicConfigValue(tag, presence),
119 has_send_value_(false), 118 has_send_value_(false),
120 has_receive_value_(false) {} 119 has_receive_value_(false) {}
121 QuicFixedUint32::~QuicFixedUint32() {} 120 QuicFixedUint32::~QuicFixedUint32() {}
122 121
123 bool QuicFixedUint32::HasSendValue() const { 122 bool QuicFixedUint32::HasSendValue() const {
124 return has_send_value_; 123 return has_send_value_;
125 } 124 }
126 125
127 uint32_t QuicFixedUint32::GetSendValue() const { 126 uint32_t QuicFixedUint32::GetSendValue() const {
128 QUIC_BUG_IF(!has_send_value_) << "No send value to get for tag:" 127 QUIC_BUG_IF(!has_send_value_) << "No send value to get for tag:"
129 << QuicUtils::TagToString(tag_); 128 << QuicTagToString(tag_);
130 return send_value_; 129 return send_value_;
131 } 130 }
132 131
133 void QuicFixedUint32::SetSendValue(uint32_t value) { 132 void QuicFixedUint32::SetSendValue(uint32_t value) {
134 has_send_value_ = true; 133 has_send_value_ = true;
135 send_value_ = value; 134 send_value_ = value;
136 } 135 }
137 136
138 bool QuicFixedUint32::HasReceivedValue() const { 137 bool QuicFixedUint32::HasReceivedValue() const {
139 return has_receive_value_; 138 return has_receive_value_;
140 } 139 }
141 140
142 uint32_t QuicFixedUint32::GetReceivedValue() const { 141 uint32_t QuicFixedUint32::GetReceivedValue() const {
143 QUIC_BUG_IF(!has_receive_value_) << "No receive value to get for tag:" 142 QUIC_BUG_IF(!has_receive_value_) << "No receive value to get for tag:"
144 << QuicUtils::TagToString(tag_); 143 << QuicTagToString(tag_);
145 return receive_value_; 144 return receive_value_;
146 } 145 }
147 146
148 void QuicFixedUint32::SetReceivedValue(uint32_t value) { 147 void QuicFixedUint32::SetReceivedValue(uint32_t value) {
149 has_receive_value_ = true; 148 has_receive_value_ = true;
150 receive_value_ = value; 149 receive_value_ = value;
151 } 150 }
152 151
153 void QuicFixedUint32::ToHandshakeMessage(CryptoHandshakeMessage* out) const { 152 void QuicFixedUint32::ToHandshakeMessage(CryptoHandshakeMessage* out) const {
154 if (has_send_value_) { 153 if (has_send_value_) {
155 out->SetValue(tag_, send_value_); 154 out->SetValue(tag_, send_value_);
156 } 155 }
157 } 156 }
158 157
159 QuicErrorCode QuicFixedUint32::ProcessPeerHello( 158 QuicErrorCode QuicFixedUint32::ProcessPeerHello(
160 const CryptoHandshakeMessage& peer_hello, 159 const CryptoHandshakeMessage& peer_hello,
161 HelloType hello_type, 160 HelloType hello_type,
162 string* error_details) { 161 string* error_details) {
163 DCHECK(error_details != nullptr); 162 DCHECK(error_details != nullptr);
164 QuicErrorCode error = peer_hello.GetUint32(tag_, &receive_value_); 163 QuicErrorCode error = peer_hello.GetUint32(tag_, &receive_value_);
165 switch (error) { 164 switch (error) {
166 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: 165 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND:
167 if (presence_ == PRESENCE_OPTIONAL) { 166 if (presence_ == PRESENCE_OPTIONAL) {
168 return QUIC_NO_ERROR; 167 return QUIC_NO_ERROR;
169 } 168 }
170 *error_details = "Missing " + QuicUtils::TagToString(tag_); 169 *error_details = "Missing " + QuicTagToString(tag_);
171 break; 170 break;
172 case QUIC_NO_ERROR: 171 case QUIC_NO_ERROR:
173 has_receive_value_ = true; 172 has_receive_value_ = true;
174 break; 173 break;
175 default: 174 default:
176 *error_details = "Bad " + QuicUtils::TagToString(tag_); 175 *error_details = "Bad " + QuicTagToString(tag_);
177 break; 176 break;
178 } 177 }
179 return error; 178 return error;
180 } 179 }
181 180
182 QuicFixedTagVector::QuicFixedTagVector(QuicTag name, 181 QuicFixedTagVector::QuicFixedTagVector(QuicTag name,
183 QuicConfigPresence presence) 182 QuicConfigPresence presence)
184 : QuicConfigValue(name, presence), 183 : QuicConfigValue(name, presence),
185 has_send_values_(false), 184 has_send_values_(false),
186 has_receive_values_(false) {} 185 has_receive_values_(false) {}
187 186
188 QuicFixedTagVector::QuicFixedTagVector(const QuicFixedTagVector& other) = 187 QuicFixedTagVector::QuicFixedTagVector(const QuicFixedTagVector& other) =
189 default; 188 default;
190 189
191 QuicFixedTagVector::~QuicFixedTagVector() {} 190 QuicFixedTagVector::~QuicFixedTagVector() {}
192 191
193 bool QuicFixedTagVector::HasSendValues() const { 192 bool QuicFixedTagVector::HasSendValues() const {
194 return has_send_values_; 193 return has_send_values_;
195 } 194 }
196 195
197 QuicTagVector QuicFixedTagVector::GetSendValues() const { 196 QuicTagVector QuicFixedTagVector::GetSendValues() const {
198 QUIC_BUG_IF(!has_send_values_) << "No send values to get for tag:" 197 QUIC_BUG_IF(!has_send_values_) << "No send values to get for tag:"
199 << QuicUtils::TagToString(tag_); 198 << QuicTagToString(tag_);
200 return send_values_; 199 return send_values_;
201 } 200 }
202 201
203 void QuicFixedTagVector::SetSendValues(const QuicTagVector& values) { 202 void QuicFixedTagVector::SetSendValues(const QuicTagVector& values) {
204 has_send_values_ = true; 203 has_send_values_ = true;
205 send_values_ = values; 204 send_values_ = values;
206 } 205 }
207 206
208 bool QuicFixedTagVector::HasReceivedValues() const { 207 bool QuicFixedTagVector::HasReceivedValues() const {
209 return has_receive_values_; 208 return has_receive_values_;
210 } 209 }
211 210
212 QuicTagVector QuicFixedTagVector::GetReceivedValues() const { 211 QuicTagVector QuicFixedTagVector::GetReceivedValues() const {
213 QUIC_BUG_IF(!has_receive_values_) << "No receive value to get for tag:" 212 QUIC_BUG_IF(!has_receive_values_) << "No receive value to get for tag:"
214 << QuicUtils::TagToString(tag_); 213 << QuicTagToString(tag_);
215 return receive_values_; 214 return receive_values_;
216 } 215 }
217 216
218 void QuicFixedTagVector::SetReceivedValues(const QuicTagVector& values) { 217 void QuicFixedTagVector::SetReceivedValues(const QuicTagVector& values) {
219 has_receive_values_ = true; 218 has_receive_values_ = true;
220 receive_values_ = values; 219 receive_values_ = values;
221 } 220 }
222 221
223 void QuicFixedTagVector::ToHandshakeMessage(CryptoHandshakeMessage* out) const { 222 void QuicFixedTagVector::ToHandshakeMessage(CryptoHandshakeMessage* out) const {
224 if (has_send_values_) { 223 if (has_send_values_) {
225 out->SetVector(tag_, send_values_); 224 out->SetVector(tag_, send_values_);
226 } 225 }
227 } 226 }
228 227
229 QuicErrorCode QuicFixedTagVector::ProcessPeerHello( 228 QuicErrorCode QuicFixedTagVector::ProcessPeerHello(
230 const CryptoHandshakeMessage& peer_hello, 229 const CryptoHandshakeMessage& peer_hello,
231 HelloType hello_type, 230 HelloType hello_type,
232 string* error_details) { 231 string* error_details) {
233 DCHECK(error_details != nullptr); 232 DCHECK(error_details != nullptr);
234 const QuicTag* received_tags; 233 const QuicTag* received_tags;
235 size_t received_tags_length; 234 size_t received_tags_length;
236 QuicErrorCode error = 235 QuicErrorCode error =
237 peer_hello.GetTaglist(tag_, &received_tags, &received_tags_length); 236 peer_hello.GetTaglist(tag_, &received_tags, &received_tags_length);
238 switch (error) { 237 switch (error) {
239 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: 238 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND:
240 if (presence_ == PRESENCE_OPTIONAL) { 239 if (presence_ == PRESENCE_OPTIONAL) {
241 return QUIC_NO_ERROR; 240 return QUIC_NO_ERROR;
242 } 241 }
243 *error_details = "Missing " + QuicUtils::TagToString(tag_); 242 *error_details = "Missing " + QuicTagToString(tag_);
244 break; 243 break;
245 case QUIC_NO_ERROR: 244 case QUIC_NO_ERROR:
246 DVLOG(1) << "Received Connection Option tags from receiver."; 245 DVLOG(1) << "Received Connection Option tags from receiver.";
247 has_receive_values_ = true; 246 has_receive_values_ = true;
248 for (size_t i = 0; i < received_tags_length; ++i) { 247 for (size_t i = 0; i < received_tags_length; ++i) {
249 receive_values_.push_back(received_tags[i]); 248 receive_values_.push_back(received_tags[i]);
250 } 249 }
251 break; 250 break;
252 default: 251 default:
253 *error_details = "Bad " + QuicUtils::TagToString(tag_); 252 *error_details = "Bad " + QuicTagToString(tag_);
254 break; 253 break;
255 } 254 }
256 return error; 255 return error;
257 } 256 }
258 257
259 QuicFixedIPEndPoint::QuicFixedIPEndPoint(QuicTag tag, 258 QuicFixedIPEndPoint::QuicFixedIPEndPoint(QuicTag tag,
260 QuicConfigPresence presence) 259 QuicConfigPresence presence)
261 : QuicConfigValue(tag, presence), 260 : QuicConfigValue(tag, presence),
262 has_send_value_(false), 261 has_send_value_(false),
263 has_receive_value_(false) {} 262 has_receive_value_(false) {}
264 263
265 QuicFixedIPEndPoint::~QuicFixedIPEndPoint() {} 264 QuicFixedIPEndPoint::~QuicFixedIPEndPoint() {}
266 265
267 bool QuicFixedIPEndPoint::HasSendValue() const { 266 bool QuicFixedIPEndPoint::HasSendValue() const {
268 return has_send_value_; 267 return has_send_value_;
269 } 268 }
270 269
271 const IPEndPoint& QuicFixedIPEndPoint::GetSendValue() const { 270 const IPEndPoint& QuicFixedIPEndPoint::GetSendValue() const {
272 QUIC_BUG_IF(!has_send_value_) << "No send value to get for tag:" 271 QUIC_BUG_IF(!has_send_value_) << "No send value to get for tag:"
273 << QuicUtils::TagToString(tag_); 272 << QuicTagToString(tag_);
274 return send_value_; 273 return send_value_;
275 } 274 }
276 275
277 void QuicFixedIPEndPoint::SetSendValue(const IPEndPoint& value) { 276 void QuicFixedIPEndPoint::SetSendValue(const IPEndPoint& value) {
278 has_send_value_ = true; 277 has_send_value_ = true;
279 send_value_ = value; 278 send_value_ = value;
280 } 279 }
281 280
282 bool QuicFixedIPEndPoint::HasReceivedValue() const { 281 bool QuicFixedIPEndPoint::HasReceivedValue() const {
283 return has_receive_value_; 282 return has_receive_value_;
284 } 283 }
285 284
286 const IPEndPoint& QuicFixedIPEndPoint::GetReceivedValue() const { 285 const IPEndPoint& QuicFixedIPEndPoint::GetReceivedValue() const {
287 QUIC_BUG_IF(!has_receive_value_) << "No receive value to get for tag:" 286 QUIC_BUG_IF(!has_receive_value_) << "No receive value to get for tag:"
288 << QuicUtils::TagToString(tag_); 287 << QuicTagToString(tag_);
289 return receive_value_; 288 return receive_value_;
290 } 289 }
291 290
292 void QuicFixedIPEndPoint::SetReceivedValue(const IPEndPoint& value) { 291 void QuicFixedIPEndPoint::SetReceivedValue(const IPEndPoint& value) {
293 has_receive_value_ = true; 292 has_receive_value_ = true;
294 receive_value_ = value; 293 receive_value_ = value;
295 } 294 }
296 295
297 void QuicFixedIPEndPoint::ToHandshakeMessage( 296 void QuicFixedIPEndPoint::ToHandshakeMessage(
298 CryptoHandshakeMessage* out) const { 297 CryptoHandshakeMessage* out) const {
299 if (has_send_value_) { 298 if (has_send_value_) {
300 QuicSocketAddressCoder address_coder(send_value_); 299 QuicSocketAddressCoder address_coder(send_value_);
301 out->SetStringPiece(tag_, address_coder.Encode()); 300 out->SetStringPiece(tag_, address_coder.Encode());
302 } 301 }
303 } 302 }
304 303
305 QuicErrorCode QuicFixedIPEndPoint::ProcessPeerHello( 304 QuicErrorCode QuicFixedIPEndPoint::ProcessPeerHello(
306 const CryptoHandshakeMessage& peer_hello, 305 const CryptoHandshakeMessage& peer_hello,
307 HelloType hello_type, 306 HelloType hello_type,
308 string* error_details) { 307 string* error_details) {
309 base::StringPiece address; 308 base::StringPiece address;
310 if (!peer_hello.GetStringPiece(tag_, &address)) { 309 if (!peer_hello.GetStringPiece(tag_, &address)) {
311 if (presence_ == PRESENCE_REQUIRED) { 310 if (presence_ == PRESENCE_REQUIRED) {
312 *error_details = "Missing " + QuicUtils::TagToString(tag_); 311 *error_details = "Missing " + QuicTagToString(tag_);
313 return QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND; 312 return QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND;
314 } 313 }
315 } else { 314 } else {
316 QuicSocketAddressCoder address_coder; 315 QuicSocketAddressCoder address_coder;
317 if (address_coder.Decode(address.data(), address.length())) { 316 if (address_coder.Decode(address.data(), address.length())) {
318 SetReceivedValue(IPEndPoint(address_coder.ip(), address_coder.port())); 317 SetReceivedValue(IPEndPoint(address_coder.ip(), address_coder.port()));
319 } 318 }
320 } 319 }
321 return QUIC_NO_ERROR; 320 return QUIC_NO_ERROR;
322 } 321 }
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 error_details); 672 error_details);
674 } 673 }
675 if (error == QUIC_NO_ERROR) { 674 if (error == QUIC_NO_ERROR) {
676 error = force_hol_blocking_.ProcessPeerHello(peer_hello, hello_type, 675 error = force_hol_blocking_.ProcessPeerHello(peer_hello, hello_type,
677 error_details); 676 error_details);
678 } 677 }
679 return error; 678 return error;
680 } 679 }
681 680
682 } // namespace net 681 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/crypto/quic_crypto_server_config.cc ('k') | net/quic/core/quic_framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698