| 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 #ifndef QUIC_UTIL_HAS_UINT128 |
| 60 // Slow implementation of IncrementalHash. In practice, only used by Chromium. |
| 59 uint128 IncrementalHashSlow(uint128 hash, const char* data, size_t len) { | 61 uint128 IncrementalHashSlow(uint128 hash, const char* data, size_t len) { |
| 60 // kPrime = 309485009821345068724781371 | 62 // kPrime = 309485009821345068724781371 |
| 61 static const uint128 kPrime(16777216, 315); | 63 static const uint128 kPrime(16777216, 315); |
| 62 const uint8_t* octets = reinterpret_cast<const uint8_t*>(data); | 64 const uint8_t* octets = reinterpret_cast<const uint8_t*>(data); |
| 63 for (size_t i = 0; i < len; ++i) { | 65 for (size_t i = 0; i < len; ++i) { |
| 64 hash = hash ^ uint128(0, octets[i]); | 66 hash = hash ^ uint128(0, octets[i]); |
| 65 hash = hash * kPrime; | 67 hash = hash * kPrime; |
| 66 } | 68 } |
| 67 return hash; | 69 return hash; |
| 68 } | 70 } |
| 71 #endif |
| 69 | 72 |
| 70 uint128 IncrementalHash(uint128 hash, const char* data, size_t len) { | 73 uint128 IncrementalHash(uint128 hash, const char* data, size_t len) { |
| 71 #ifdef QUIC_UTIL_HAS_UINT128 | 74 #ifdef QUIC_UTIL_HAS_UINT128 |
| 72 return FLAGS_quic_utils_use_fast_incremental_hash | 75 return IncrementalHashFast(hash, data, len); |
| 73 ? IncrementalHashFast(hash, data, len) | |
| 74 : IncrementalHashSlow(hash, data, len); | |
| 75 #else | 76 #else |
| 76 return IncrementalHashSlow(hash, data, len); | 77 return IncrementalHashSlow(hash, data, len); |
| 77 #endif | 78 #endif |
| 78 } | 79 } |
| 79 | 80 |
| 80 bool IsInitializedIPEndPoint(const IPEndPoint& address) { | 81 bool IsInitializedIPEndPoint(const IPEndPoint& address) { |
| 81 return net::GetAddressFamily(address.address().bytes()) != | 82 return net::GetAddressFamily(address.address().bytes()) != |
| 82 net::ADDRESS_FAMILY_UNSPECIFIED; | 83 net::ADDRESS_FAMILY_UNSPECIFIED; |
| 83 } | 84 } |
| 84 | 85 |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 24)) { | 519 24)) { |
| 519 // Subnet part does not change (here, we use /24), which is considered to be | 520 // Subnet part does not change (here, we use /24), which is considered to be |
| 520 // caused by NATs. | 521 // caused by NATs. |
| 521 return IPV4_SUBNET_CHANGE; | 522 return IPV4_SUBNET_CHANGE; |
| 522 } | 523 } |
| 523 | 524 |
| 524 return UNSPECIFIED_CHANGE; | 525 return UNSPECIFIED_CHANGE; |
| 525 } | 526 } |
| 526 | 527 |
| 527 } // namespace net | 528 } // namespace net |
| OLD | NEW |