OLD | NEW |
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/core/quic_utils.h" | 5 #include "net/quic/core/quic_utils.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 UINT64_C(7113472399480571277)); | 117 UINT64_C(7113472399480571277)); |
118 | 118 |
119 uint128 hash = IncrementalHash(kOffset, data1, len1); | 119 uint128 hash = IncrementalHash(kOffset, data1, len1); |
120 if (data2 == nullptr) { | 120 if (data2 == nullptr) { |
121 return hash; | 121 return hash; |
122 } | 122 } |
123 return IncrementalHash(hash, data2, len2); | 123 return IncrementalHash(hash, data2, len2); |
124 } | 124 } |
125 | 125 |
126 // static | 126 // static |
127 bool QuicUtils::FindMutualTag(const QuicTagVector& our_tags_vector, | |
128 const QuicTag* their_tags, | |
129 size_t num_their_tags, | |
130 QuicTag* out_result, | |
131 size_t* out_index) { | |
132 if (our_tags_vector.empty()) { | |
133 return false; | |
134 } | |
135 const size_t num_our_tags = our_tags_vector.size(); | |
136 for (size_t i = 0; i < num_our_tags; i++) { | |
137 for (size_t j = 0; j < num_their_tags; j++) { | |
138 if (our_tags_vector[i] == their_tags[j]) { | |
139 *out_result = our_tags_vector[i]; | |
140 if (out_index != nullptr) { | |
141 *out_index = j; | |
142 } | |
143 return true; | |
144 } | |
145 } | |
146 } | |
147 | |
148 return false; | |
149 } | |
150 | |
151 // static | |
152 void QuicUtils::SerializeUint128Short(uint128 v, uint8_t* out) { | 127 void QuicUtils::SerializeUint128Short(uint128 v, uint8_t* out) { |
153 const uint64_t lo = Uint128Low64(v); | 128 const uint64_t lo = Uint128Low64(v); |
154 const uint64_t hi = Uint128High64(v); | 129 const uint64_t hi = Uint128High64(v); |
155 // This assumes that the system is little-endian. | 130 // This assumes that the system is little-endian. |
156 memcpy(out, &lo, sizeof(lo)); | 131 memcpy(out, &lo, sizeof(lo)); |
157 memcpy(out + sizeof(lo), &hi, sizeof(hi) / 2); | 132 memcpy(out + sizeof(lo), &hi, sizeof(hi) / 2); |
158 } | 133 } |
159 | 134 |
160 #define RETURN_STRING_LITERAL(x) \ | 135 #define RETURN_STRING_LITERAL(x) \ |
161 case x: \ | 136 case x: \ |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 RETURN_STRING_LITERAL(LOSS_RETRANSMISSION); | 288 RETURN_STRING_LITERAL(LOSS_RETRANSMISSION); |
314 RETURN_STRING_LITERAL(ALL_UNACKED_RETRANSMISSION); | 289 RETURN_STRING_LITERAL(ALL_UNACKED_RETRANSMISSION); |
315 RETURN_STRING_LITERAL(ALL_INITIAL_RETRANSMISSION); | 290 RETURN_STRING_LITERAL(ALL_INITIAL_RETRANSMISSION); |
316 RETURN_STRING_LITERAL(RTO_RETRANSMISSION); | 291 RETURN_STRING_LITERAL(RTO_RETRANSMISSION); |
317 RETURN_STRING_LITERAL(TLP_RETRANSMISSION); | 292 RETURN_STRING_LITERAL(TLP_RETRANSMISSION); |
318 } | 293 } |
319 return "INVALID_TRANSMISSION_TYPE"; | 294 return "INVALID_TRANSMISSION_TYPE"; |
320 } | 295 } |
321 | 296 |
322 // static | 297 // static |
323 string QuicUtils::TagToString(QuicTag tag) { | |
324 char chars[sizeof tag]; | |
325 bool ascii = true; | |
326 const QuicTag orig_tag = tag; | |
327 | |
328 for (size_t i = 0; i < arraysize(chars); i++) { | |
329 chars[i] = static_cast<char>(tag); | |
330 if ((chars[i] == 0 || chars[i] == '\xff') && i == arraysize(chars) - 1) { | |
331 chars[i] = ' '; | |
332 } | |
333 if (!isprint(static_cast<unsigned char>(chars[i]))) { | |
334 ascii = false; | |
335 break; | |
336 } | |
337 tag >>= 8; | |
338 } | |
339 | |
340 if (ascii) { | |
341 return string(chars, sizeof(chars)); | |
342 } | |
343 | |
344 return base::UintToString(orig_tag); | |
345 } | |
346 | |
347 // static | |
348 QuicTagVector QuicUtils::ParseQuicConnectionOptions( | 298 QuicTagVector QuicUtils::ParseQuicConnectionOptions( |
349 const std::string& connection_options) { | 299 const std::string& connection_options) { |
350 QuicTagVector options; | 300 QuicTagVector options; |
351 // Tokens are expected to be no more than 4 characters long, but we | 301 // Tokens are expected to be no more than 4 characters long, but we |
352 // handle overflow gracefully. | 302 // handle overflow gracefully. |
353 for (const base::StringPiece& token : | 303 for (const base::StringPiece& token : |
354 base::SplitStringPiece(connection_options, ",", base::TRIM_WHITESPACE, | 304 base::SplitStringPiece(connection_options, ",", base::TRIM_WHITESPACE, |
355 base::SPLIT_WANT_ALL)) { | 305 base::SPLIT_WANT_ALL)) { |
356 uint32_t option = 0; | 306 uint32_t option = 0; |
357 for (char token_char : base::Reversed(token)) { | 307 for (char token_char : base::Reversed(token)) { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 | 497 |
548 bytes_remaining -= line_bytes; | 498 bytes_remaining -= line_bytes; |
549 offset += line_bytes; | 499 offset += line_bytes; |
550 p += line_bytes; | 500 p += line_bytes; |
551 s += '\n'; | 501 s += '\n'; |
552 } | 502 } |
553 return s; | 503 return s; |
554 } | 504 } |
555 | 505 |
556 } // namespace net | 506 } // namespace net |
OLD | NEW |