| 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/quic_utils.h" | 5 #include "net/quic/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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | |
| 14 #include "base/containers/adapters.h" | 13 #include "base/containers/adapters.h" |
| 15 #include "base/logging.h" | 14 #include "base/logging.h" |
| 16 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 18 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 19 #include "net/quic/quic_write_blocked_list.h" | 18 #include "net/quic/quic_write_blocked_list.h" |
| 20 | 19 |
| 21 using base::StringPiece; | 20 using base::StringPiece; |
| 22 using std::string; | 21 using std::string; |
| 23 | 22 |
| 24 namespace net { | 23 namespace net { |
| 25 | 24 |
| 26 // static | 25 // static |
| 27 uint64 QuicUtils::FNV1a_64_Hash(const char* data, int len) { | 26 uint64_t QuicUtils::FNV1a_64_Hash(const char* data, int len) { |
| 28 static const uint64 kOffset = UINT64_C(14695981039346656037); | 27 static const uint64_t kOffset = UINT64_C(14695981039346656037); |
| 29 static const uint64 kPrime = UINT64_C(1099511628211); | 28 static const uint64_t kPrime = UINT64_C(1099511628211); |
| 30 | 29 |
| 31 const uint8* octets = reinterpret_cast<const uint8*>(data); | 30 const uint8_t* octets = reinterpret_cast<const uint8_t*>(data); |
| 32 | 31 |
| 33 uint64 hash = kOffset; | 32 uint64_t hash = kOffset; |
| 34 | 33 |
| 35 for (int i = 0; i < len; ++i) { | 34 for (int i = 0; i < len; ++i) { |
| 36 hash = hash ^ octets[i]; | 35 hash = hash ^ octets[i]; |
| 37 hash = hash * kPrime; | 36 hash = hash * kPrime; |
| 38 } | 37 } |
| 39 | 38 |
| 40 return hash; | 39 return hash; |
| 41 } | 40 } |
| 42 | 41 |
| 43 // static | 42 // static |
| (...skipping 16 matching lines...) Expand all Loading... |
| 60 if (data2 == nullptr) { | 59 if (data2 == nullptr) { |
| 61 return hash; | 60 return hash; |
| 62 } | 61 } |
| 63 return IncrementalHash(hash, data2, len2); | 62 return IncrementalHash(hash, data2, len2); |
| 64 } | 63 } |
| 65 | 64 |
| 66 // static | 65 // static |
| 67 uint128 QuicUtils::IncrementalHash(uint128 hash, const char* data, size_t len) { | 66 uint128 QuicUtils::IncrementalHash(uint128 hash, const char* data, size_t len) { |
| 68 // 309485009821345068724781371 | 67 // 309485009821345068724781371 |
| 69 const uint128 kPrime(16777216, 315); | 68 const uint128 kPrime(16777216, 315); |
| 70 const uint8* octets = reinterpret_cast<const uint8*>(data); | 69 const uint8_t* octets = reinterpret_cast<const uint8_t*>(data); |
| 71 for (size_t i = 0; i < len; ++i) { | 70 for (size_t i = 0; i < len; ++i) { |
| 72 hash = hash ^ uint128(0, octets[i]); | 71 hash = hash ^ uint128(0, octets[i]); |
| 73 hash = hash * kPrime; | 72 hash = hash * kPrime; |
| 74 } | 73 } |
| 75 return hash; | 74 return hash; |
| 76 } | 75 } |
| 77 | 76 |
| 78 // static | 77 // static |
| 79 bool QuicUtils::FindMutualTag(const QuicTagVector& our_tags_vector, | 78 bool QuicUtils::FindMutualTag(const QuicTagVector& our_tags_vector, |
| 80 const QuicTag* their_tags, | 79 const QuicTag* their_tags, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 115 } |
| 117 return true; | 116 return true; |
| 118 } | 117 } |
| 119 } | 118 } |
| 120 } | 119 } |
| 121 | 120 |
| 122 return false; | 121 return false; |
| 123 } | 122 } |
| 124 | 123 |
| 125 // static | 124 // static |
| 126 void QuicUtils::SerializeUint128Short(uint128 v, uint8* out) { | 125 void QuicUtils::SerializeUint128Short(uint128 v, uint8_t* out) { |
| 127 const uint64 lo = Uint128Low64(v); | 126 const uint64_t lo = Uint128Low64(v); |
| 128 const uint64 hi = Uint128High64(v); | 127 const uint64_t hi = Uint128High64(v); |
| 129 // This assumes that the system is little-endian. | 128 // This assumes that the system is little-endian. |
| 130 memcpy(out, &lo, sizeof(lo)); | 129 memcpy(out, &lo, sizeof(lo)); |
| 131 memcpy(out + sizeof(lo), &hi, sizeof(hi) / 2); | 130 memcpy(out + sizeof(lo), &hi, sizeof(hi) / 2); |
| 132 } | 131 } |
| 133 | 132 |
| 134 #define RETURN_STRING_LITERAL(x) \ | 133 #define RETURN_STRING_LITERAL(x) \ |
| 135 case x: \ | 134 case x: \ |
| 136 return #x; | 135 return #x; |
| 137 | 136 |
| 138 // static | 137 // static |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 292 |
| 294 // static | 293 // static |
| 295 QuicTagVector QuicUtils::ParseQuicConnectionOptions( | 294 QuicTagVector QuicUtils::ParseQuicConnectionOptions( |
| 296 const std::string& connection_options) { | 295 const std::string& connection_options) { |
| 297 QuicTagVector options; | 296 QuicTagVector options; |
| 298 // Tokens are expected to be no more than 4 characters long, but we | 297 // Tokens are expected to be no more than 4 characters long, but we |
| 299 // handle overflow gracefully. | 298 // handle overflow gracefully. |
| 300 for (const base::StringPiece& token : | 299 for (const base::StringPiece& token : |
| 301 base::SplitStringPiece(connection_options, ",", base::TRIM_WHITESPACE, | 300 base::SplitStringPiece(connection_options, ",", base::TRIM_WHITESPACE, |
| 302 base::SPLIT_WANT_ALL)) { | 301 base::SPLIT_WANT_ALL)) { |
| 303 uint32 option = 0; | 302 uint32_t option = 0; |
| 304 for (char token_char : base::Reversed(token)) { | 303 for (char token_char : base::Reversed(token)) { |
| 305 option <<= 8; | 304 option <<= 8; |
| 306 option |= static_cast<unsigned char>(token_char); | 305 option |= static_cast<unsigned char>(token_char); |
| 307 } | 306 } |
| 308 options.push_back(option); | 307 options.push_back(option); |
| 309 } | 308 } |
| 310 return options; | 309 return options; |
| 311 } | 310 } |
| 312 | 311 |
| 313 // static | 312 // static |
| (...skipping 23 matching lines...) Expand all Loading... |
| 337 | 336 |
| 338 bytes_remaining -= line_bytes; | 337 bytes_remaining -= line_bytes; |
| 339 offset += line_bytes; | 338 offset += line_bytes; |
| 340 p += line_bytes; | 339 p += line_bytes; |
| 341 s += '\n'; | 340 s += '\n'; |
| 342 } | 341 } |
| 343 return s; | 342 return s; |
| 344 } | 343 } |
| 345 | 344 |
| 346 } // namespace net | 345 } // namespace net |
| OLD | NEW |