| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/port.h" | 8 #include "base/port.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 | 11 |
| 12 // static | 12 // static |
| 13 size_t QuicUtils::StreamFramePacketOverhead(int num_frames) { | 13 size_t QuicUtils::StreamFramePacketOverhead(int num_frames) { |
| 14 // TODO(jar): Use sizeof(some name). | 14 // TODO(jar): Use sizeof(some name). |
| 15 return kPacketHeaderSize + | 15 return kPacketHeaderSize + |
| 16 (kFrameTypeSize + | 16 (kFrameTypeSize + |
| 17 kMinStreamFrameLength) * num_frames; | 17 kMinStreamFrameLength) * num_frames; |
| 18 } | 18 } |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) { | 21 uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) { |
| 22 // The following two constants are defined as part of the hash algorithm. | 22 // The following two constants are defined as part of the hash algorithm. |
| 23 // see http://www.isthe.com/chongo/tech/comp/fnv/ |
| 23 // 309485009821345068724781371 | 24 // 309485009821345068724781371 |
| 24 const uint128 kPrime(16777216, 315); | 25 const uint128 kPrime(16777216, 315); |
| 25 // 14406626329776981559649562966706236762 | 26 // 144066263297769815596495629667062367629 |
| 26 const uint128 kOffset(GG_UINT64_C(780984778246553632), | 27 const uint128 kOffset(GG_UINT64_C(7809847782465536322), |
| 27 GG_UINT64_C(4400696054689967450)); | 28 GG_UINT64_C(7113472399480571277)); |
| 28 | 29 |
| 29 const uint8* octets = reinterpret_cast<const uint8*>(data); | 30 const uint8* octets = reinterpret_cast<const uint8*>(data); |
| 30 | 31 |
| 31 uint128 hash = kOffset; | 32 uint128 hash = kOffset; |
| 32 | 33 |
| 33 for (int i = 0; i < len; ++i) { | 34 for (int i = 0; i < len; ++i) { |
| 34 hash = hash ^ uint128(0, octets[i]); | 35 hash = hash ^ uint128(0, octets[i]); |
| 35 hash = hash * kPrime; | 36 hash = hash * kPrime; |
| 36 } | 37 } |
| 37 | 38 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 RETURN_STRING_LITERAL(QUIC_TOO_MANY_OPEN_STREAMS); | 75 RETURN_STRING_LITERAL(QUIC_TOO_MANY_OPEN_STREAMS); |
| 75 RETURN_STRING_LITERAL(QUIC_PUBLIC_RESET); | 76 RETURN_STRING_LITERAL(QUIC_PUBLIC_RESET); |
| 76 RETURN_STRING_LITERAL(QUIC_CONNECTION_TIMED_OUT); | 77 RETURN_STRING_LITERAL(QUIC_CONNECTION_TIMED_OUT); |
| 77 // Intentionally have no default case, so we'll break the build | 78 // Intentionally have no default case, so we'll break the build |
| 78 // if we add errors and don't put them here. | 79 // if we add errors and don't put them here. |
| 79 } | 80 } |
| 80 return ""; | 81 return ""; |
| 81 } | 82 } |
| 82 | 83 |
| 83 } // namespace net | 84 } // namespace net |
| OLD | NEW |