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> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 Uint128Low64(uhash); | 49 Uint128Low64(uhash); |
50 const uint8_t* octets = reinterpret_cast<const uint8_t*>(data); | 50 const uint8_t* octets = reinterpret_cast<const uint8_t*>(data); |
51 for (size_t i = 0; i < len; ++i) { | 51 for (size_t i = 0; i < len; ++i) { |
52 xhash = (xhash ^ octets[i]) * kPrime; | 52 xhash = (xhash ^ octets[i]) * kPrime; |
53 } | 53 } |
54 return uint128(static_cast<uint64_t>(xhash >> 64), | 54 return uint128(static_cast<uint64_t>(xhash >> 64), |
55 static_cast<uint64_t>(xhash & UINT64_C(0xFFFFFFFFFFFFFFFF))); | 55 static_cast<uint64_t>(xhash & UINT64_C(0xFFFFFFFFFFFFFFFF))); |
56 } | 56 } |
57 #endif | 57 #endif |
58 | 58 |
59 uint128 IncrementalHashSlow(uint128 hash, const char* data, size_t len) { | |
60 // kPrime = 309485009821345068724781371 | |
61 static const uint128 kPrime(16777216, 315); | |
62 const uint8_t* octets = reinterpret_cast<const uint8_t*>(data); | |
63 for (size_t i = 0; i < len; ++i) { | |
64 hash = hash ^ uint128(0, octets[i]); | |
65 hash = hash * kPrime; | |
66 } | |
67 return hash; | |
68 } | |
Ryan Hamilton
2016/02/23 23:40:43
Since this method is used below, I don't think you
Buck
2016/02/26 18:54:22
Done. Whoops, this was my merge error. I made a
| |
69 | |
70 uint128 IncrementalHash(uint128 hash, const char* data, size_t len) { | 59 uint128 IncrementalHash(uint128 hash, const char* data, size_t len) { |
71 #ifdef QUIC_UTIL_HAS_UINT128 | 60 #ifdef QUIC_UTIL_HAS_UINT128 |
72 return FLAGS_quic_utils_use_fast_incremental_hash | 61 return IncrementalHashFast(hash, data, len); |
73 ? IncrementalHashFast(hash, data, len) | |
74 : IncrementalHashSlow(hash, data, len); | |
75 #else | 62 #else |
76 return IncrementalHashSlow(hash, data, len); | 63 return IncrementalHashSlow(hash, data, len); |
77 #endif | 64 #endif |
78 } | 65 } |
79 | 66 |
80 bool IsInitializedIPEndPoint(const IPEndPoint& address) { | 67 bool IsInitializedIPEndPoint(const IPEndPoint& address) { |
81 return net::GetAddressFamily(address.address().bytes()) != | 68 return net::GetAddressFamily(address.address().bytes()) != |
82 net::ADDRESS_FAMILY_UNSPECIFIED; | 69 net::ADDRESS_FAMILY_UNSPECIFIED; |
83 } | 70 } |
84 | 71 |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 24)) { | 505 24)) { |
519 // Subnet part does not change (here, we use /24), which is considered to be | 506 // Subnet part does not change (here, we use /24), which is considered to be |
520 // caused by NATs. | 507 // caused by NATs. |
521 return IPV4_SUBNET_CHANGE; | 508 return IPV4_SUBNET_CHANGE; |
522 } | 509 } |
523 | 510 |
524 return UNSPECIFIED_CHANGE; | 511 return UNSPECIFIED_CHANGE; |
525 } | 512 } |
526 | 513 |
527 } // namespace net | 514 } // namespace net |
OLD | NEW |