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 1 + // frame count | 16 1 + // frame count |
17 (1 + // 8 bit type | 17 (1 + // 8 bit type |
18 2 + // 16 bit length | 18 2 + // 16 bit length |
19 kMinStreamFrameLength) * num_frames; | 19 kMinStreamFrameLength) * num_frames; |
20 } | 20 } |
21 | 21 |
22 // TODO(jar): put into an anonymous namespage. | 22 uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) { |
23 // The following two constants are defined as part of the hash algorithm. | 23 // The following two constants are defined as part of the hash algorithm. |
24 // 309485009821345068724781371 | 24 // 309485009821345068724781371 |
25 static uint128 kPrime(16777216, 315); | 25 const uint128 kPrime(16777216, 315); |
26 // 14406626329776981559649562966706236762 | 26 // 14406626329776981559649562966706236762 |
27 static uint128 kOffset(GG_UINT64_C(780984778246553632), | 27 const uint128 kOffset(GG_UINT64_C(780984778246553632), |
28 GG_UINT64_C(4400696054689967450)); | 28 GG_UINT64_C(4400696054689967450)); |
29 | 29 |
30 uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) { | |
31 const uint8* octets = reinterpret_cast<const uint8*>(data); | 30 const uint8* octets = reinterpret_cast<const uint8*>(data); |
32 | 31 |
33 uint128 hash = kOffset; | 32 uint128 hash = kOffset; |
34 | 33 |
35 for (int i = 0; i < len; ++i) { | 34 for (int i = 0; i < len; ++i) { |
36 hash = hash ^ uint128(0, octets[i]); | 35 hash = hash ^ uint128(0, octets[i]); |
37 hash = hash * kPrime; | 36 hash = hash * kPrime; |
38 } | 37 } |
39 | 38 |
40 return hash; | 39 return hash; |
(...skipping 30 matching lines...) Expand all Loading... |
71 RETURN_STRING_LITERAL(QUIC_INVALID_STREAM_ID); | 70 RETURN_STRING_LITERAL(QUIC_INVALID_STREAM_ID); |
72 RETURN_STRING_LITERAL(QUIC_TOO_MANY_OPEN_STREAMS); | 71 RETURN_STRING_LITERAL(QUIC_TOO_MANY_OPEN_STREAMS); |
73 RETURN_STRING_LITERAL(QUIC_CONNECTION_TIMED_OUT); | 72 RETURN_STRING_LITERAL(QUIC_CONNECTION_TIMED_OUT); |
74 // Intentionally have no default case, so we'll break the build | 73 // Intentionally have no default case, so we'll break the build |
75 // if we add errors and don't put them here. | 74 // if we add errors and don't put them here. |
76 } | 75 } |
77 return ""; | 76 return ""; |
78 } | 77 } |
79 | 78 |
80 } // namespace net | 79 } // namespace net |
OLD | NEW |