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 | 9 |
9 #include <algorithm> | 10 #include <algorithm> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
13 #include "base/containers/adapters.h" | 14 #include "base/containers/adapters.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/port.h" | |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
19 #include "net/quic/quic_write_blocked_list.h" | 19 #include "net/quic/quic_write_blocked_list.h" |
20 | 20 |
21 using base::StringPiece; | 21 using base::StringPiece; |
22 using std::string; | 22 using std::string; |
23 | 23 |
24 namespace net { | 24 namespace net { |
25 | 25 |
26 // static | 26 // static |
27 uint64 QuicUtils::FNV1a_64_Hash(const char* data, int len) { | 27 uint64 QuicUtils::FNV1a_64_Hash(const char* data, int len) { |
28 static const uint64 kOffset = GG_UINT64_C(14695981039346656037); | 28 static const uint64 kOffset = UINT64_C(14695981039346656037); |
29 static const uint64 kPrime = GG_UINT64_C(1099511628211); | 29 static const uint64 kPrime = UINT64_C(1099511628211); |
30 | 30 |
31 const uint8* octets = reinterpret_cast<const uint8*>(data); | 31 const uint8* octets = reinterpret_cast<const uint8*>(data); |
32 | 32 |
33 uint64 hash = kOffset; | 33 uint64 hash = kOffset; |
34 | 34 |
35 for (int i = 0; i < len; ++i) { | 35 for (int i = 0; i < len; ++i) { |
36 hash = hash ^ octets[i]; | 36 hash = hash ^ octets[i]; |
37 hash = hash * kPrime; | 37 hash = hash * kPrime; |
38 } | 38 } |
39 | 39 |
40 return hash; | 40 return hash; |
41 } | 41 } |
42 | 42 |
43 // static | 43 // static |
44 uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) { | 44 uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) { |
45 return FNV1a_128_Hash_Two(data, len, nullptr, 0); | 45 return FNV1a_128_Hash_Two(data, len, nullptr, 0); |
46 } | 46 } |
47 | 47 |
48 // static | 48 // static |
49 uint128 QuicUtils::FNV1a_128_Hash_Two(const char* data1, | 49 uint128 QuicUtils::FNV1a_128_Hash_Two(const char* data1, |
50 int len1, | 50 int len1, |
51 const char* data2, | 51 const char* data2, |
52 int len2) { | 52 int len2) { |
53 // The two constants are defined as part of the hash algorithm. | 53 // The two constants are defined as part of the hash algorithm. |
54 // see http://www.isthe.com/chongo/tech/comp/fnv/ | 54 // see http://www.isthe.com/chongo/tech/comp/fnv/ |
55 // 144066263297769815596495629667062367629 | 55 // 144066263297769815596495629667062367629 |
56 const uint128 kOffset(GG_UINT64_C(7809847782465536322), | 56 const uint128 kOffset(UINT64_C(7809847782465536322), |
57 GG_UINT64_C(7113472399480571277)); | 57 UINT64_C(7113472399480571277)); |
58 | 58 |
59 uint128 hash = IncrementalHash(kOffset, data1, len1); | 59 uint128 hash = IncrementalHash(kOffset, data1, len1); |
60 if (data2 == nullptr) { | 60 if (data2 == nullptr) { |
61 return hash; | 61 return hash; |
62 } | 62 } |
63 return IncrementalHash(hash, data2, len2); | 63 return IncrementalHash(hash, data2, len2); |
64 } | 64 } |
65 | 65 |
66 // static | 66 // static |
67 uint128 QuicUtils::IncrementalHash(uint128 hash, const char* data, size_t len) { | 67 uint128 QuicUtils::IncrementalHash(uint128 hash, const char* data, size_t len) { |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 338 } |
339 return s; | 339 return s; |
340 } | 340 } |
341 | 341 |
342 // static | 342 // static |
343 QuicPriority QuicUtils::HighestPriority() { | 343 QuicPriority QuicUtils::HighestPriority() { |
344 return QuicWriteBlockedList::kHighestPriority; | 344 return QuicWriteBlockedList::kHighestPriority; |
345 } | 345 } |
346 | 346 |
347 } // namespace net | 347 } // namespace net |
OLD | NEW |