| 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 // Some helpers for quic. | 5 // Some helpers for quic. |
| 6 | 6 |
| 7 #ifndef NET_QUIC_CORE_QUIC_UTILS_H_ | 7 #ifndef NET_QUIC_CORE_QUIC_UTILS_H_ |
| 8 #define NET_QUIC_CORE_QUIC_UTILS_H_ | 8 #define NET_QUIC_CORE_QUIC_UTILS_H_ |
| 9 | 9 |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #define QUIC_ALIGNED(X) __declspec(align(X)) | 25 #define QUIC_ALIGNED(X) __declspec(align(X)) |
| 26 #else | 26 #else |
| 27 #define QUIC_ALIGN_OF alignof | 27 #define QUIC_ALIGN_OF alignof |
| 28 #define QUIC_ALIGNED(X) __attribute__((aligned(X))) | 28 #define QUIC_ALIGNED(X) __attribute__((aligned(X))) |
| 29 #endif // _MSC_VER | 29 #endif // _MSC_VER |
| 30 | 30 |
| 31 namespace net { | 31 namespace net { |
| 32 | 32 |
| 33 class NET_EXPORT_PRIVATE QuicUtils { | 33 class NET_EXPORT_PRIVATE QuicUtils { |
| 34 public: | 34 public: |
| 35 enum Priority { | |
| 36 LOCAL_PRIORITY, | |
| 37 PEER_PRIORITY, | |
| 38 }; | |
| 39 | |
| 40 // Returns the 64 bit FNV1a hash of the data. See | 35 // Returns the 64 bit FNV1a hash of the data. See |
| 41 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param | 36 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param |
| 42 static uint64_t FNV1a_64_Hash(const char* data, int len); | 37 static uint64_t FNV1a_64_Hash(const char* data, int len); |
| 43 | 38 |
| 44 // returns the 128 bit FNV1a hash of the data. See | 39 // returns the 128 bit FNV1a hash of the data. See |
| 45 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param | 40 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param |
| 46 static uint128 FNV1a_128_Hash(const char* data1, int len1); | 41 static uint128 FNV1a_128_Hash(const char* data1, int len1); |
| 47 | 42 |
| 48 // returns the 128 bit FNV1a hash of the two sequences of data. See | 43 // returns the 128 bit FNV1a hash of the two sequences of data. See |
| 49 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param | 44 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param |
| 50 static uint128 FNV1a_128_Hash_Two(const char* data1, | 45 static uint128 FNV1a_128_Hash_Two(const char* data1, |
| 51 int len1, | 46 int len1, |
| 52 const char* data2, | 47 const char* data2, |
| 53 int len2); | 48 int len2); |
| 54 | 49 |
| 55 // FindMutualTag sets |out_result| to the first tag in the priority list that | 50 // FindMutualTag sets |out_result| to the first tag in the priority list that |
| 56 // is also in the other list and returns true. If there is no intersection it | 51 // is also in the other list and returns true. If there is no intersection it |
| 57 // returns false. | 52 // returns false. |
| 58 // | 53 // |
| 59 // Which list has priority is determined by |priority|. | |
| 60 // | |
| 61 // If |out_index| is non-nullptr and a match is found then the index of that | 54 // If |out_index| is non-nullptr and a match is found then the index of that |
| 62 // match in |their_tags| is written to |out_index|. | 55 // match in |their_tags| is written to |out_index|. |
| 63 static bool FindMutualTag(const QuicTagVector& our_tags, | 56 static bool FindMutualTag(const QuicTagVector& our_tags, |
| 64 const QuicTag* their_tags, | 57 const QuicTag* their_tags, |
| 65 size_t num_their_tags, | 58 size_t num_their_tags, |
| 66 Priority priority, | |
| 67 QuicTag* out_result, | 59 QuicTag* out_result, |
| 68 size_t* out_index); | 60 size_t* out_index); |
| 69 | 61 |
| 70 // SerializeUint128 writes the first 96 bits of |v| in little-endian form | 62 // SerializeUint128 writes the first 96 bits of |v| in little-endian form |
| 71 // to |out|. | 63 // to |out|. |
| 72 static void SerializeUint128Short(uint128 v, uint8_t* out); | 64 static void SerializeUint128Short(uint128 v, uint8_t* out); |
| 73 | 65 |
| 74 // Returns the name of the QuicRstStreamErrorCode as a char* | 66 // Returns the name of the QuicRstStreamErrorCode as a char* |
| 75 static const char* StreamErrorToString(QuicRstStreamErrorCode error); | 67 static const char* StreamErrorToString(QuicRstStreamErrorCode error); |
| 76 | 68 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 inline QuicIOVector MakeIOVector(base::StringPiece str, struct iovec* iov) { | 143 inline QuicIOVector MakeIOVector(base::StringPiece str, struct iovec* iov) { |
| 152 iov->iov_base = const_cast<char*>(str.data()); | 144 iov->iov_base = const_cast<char*>(str.data()); |
| 153 iov->iov_len = static_cast<size_t>(str.size()); | 145 iov->iov_len = static_cast<size_t>(str.size()); |
| 154 QuicIOVector quic_iov(iov, 1, str.size()); | 146 QuicIOVector quic_iov(iov, 1, str.size()); |
| 155 return quic_iov; | 147 return quic_iov; |
| 156 } | 148 } |
| 157 | 149 |
| 158 } // namespace net | 150 } // namespace net |
| 159 | 151 |
| 160 #endif // NET_QUIC_CORE_QUIC_UTILS_H_ | 152 #endif // NET_QUIC_CORE_QUIC_UTILS_H_ |
| OLD | NEW |