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 30 matching lines...) Expand all Loading... |
41 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param | 41 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param |
42 static uint128 FNV1a_128_Hash(const char* data1, int len1); | 42 static uint128 FNV1a_128_Hash(const char* data1, int len1); |
43 | 43 |
44 // returns the 128 bit FNV1a hash of the two sequences of data. See | 44 // returns the 128 bit FNV1a hash of the two sequences of data. See |
45 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param | 45 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param |
46 static uint128 FNV1a_128_Hash_Two(const char* data1, | 46 static uint128 FNV1a_128_Hash_Two(const char* data1, |
47 int len1, | 47 int len1, |
48 const char* data2, | 48 const char* data2, |
49 int len2); | 49 int len2); |
50 | 50 |
51 // FindMutualTag sets |out_result| to the first tag in the priority list that | |
52 // is also in the other list and returns true. If there is no intersection it | |
53 // returns false. | |
54 // | |
55 // If |out_index| is non-nullptr and a match is found then the index of that | |
56 // match in |their_tags| is written to |out_index|. | |
57 static bool FindMutualTag(const QuicTagVector& our_tags, | |
58 const QuicTag* their_tags, | |
59 size_t num_their_tags, | |
60 QuicTag* out_result, | |
61 size_t* out_index); | |
62 | |
63 // SerializeUint128 writes the first 96 bits of |v| in little-endian form | 51 // SerializeUint128 writes the first 96 bits of |v| in little-endian form |
64 // to |out|. | 52 // to |out|. |
65 static void SerializeUint128Short(uint128 v, uint8_t* out); | 53 static void SerializeUint128Short(uint128 v, uint8_t* out); |
66 | 54 |
67 // Returns the name of the QuicRstStreamErrorCode as a char* | 55 // Returns the name of the QuicRstStreamErrorCode as a char* |
68 static const char* StreamErrorToString(QuicRstStreamErrorCode error); | 56 static const char* StreamErrorToString(QuicRstStreamErrorCode error); |
69 | 57 |
70 // Returns the name of the QuicErrorCode as a char* | 58 // Returns the name of the QuicErrorCode as a char* |
71 static const char* ErrorToString(QuicErrorCode error); | 59 static const char* ErrorToString(QuicErrorCode error); |
72 | 60 |
73 // Returns the level of encryption as a char* | 61 // Returns the level of encryption as a char* |
74 static const char* EncryptionLevelToString(EncryptionLevel level); | 62 static const char* EncryptionLevelToString(EncryptionLevel level); |
75 | 63 |
76 // Returns TransmissionType as a char* | 64 // Returns TransmissionType as a char* |
77 static const char* TransmissionTypeToString(TransmissionType type); | 65 static const char* TransmissionTypeToString(TransmissionType type); |
78 | 66 |
79 // TagToString is a utility function for pretty-printing handshake messages | |
80 // that converts a tag to a string. It will try to maintain the human friendly | |
81 // name if possible (i.e. kABCD -> "ABCD"), or will just treat it as a number | |
82 // if not. | |
83 static std::string TagToString(QuicTag tag); | |
84 | |
85 // Returns the list of QUIC tags represented by the comma separated | 67 // Returns the list of QUIC tags represented by the comma separated |
86 // string in |connection_options|. | 68 // string in |connection_options|. |
87 static QuicTagVector ParseQuicConnectionOptions( | 69 static QuicTagVector ParseQuicConnectionOptions( |
88 const std::string& connection_options); | 70 const std::string& connection_options); |
89 | 71 |
90 // Returns PeerAddressChangeType as a std::string. | 72 // Returns PeerAddressChangeType as a std::string. |
91 static std::string PeerAddressChangeTypeToString(PeerAddressChangeType type); | 73 static std::string PeerAddressChangeTypeToString(PeerAddressChangeType type); |
92 | 74 |
93 static char* AsChars(unsigned char* data) { | 75 static char* AsChars(unsigned char* data) { |
94 return reinterpret_cast<char*>(data); | 76 return reinterpret_cast<char*>(data); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 inline QuicIOVector MakeIOVector(base::StringPiece str, struct iovec* iov) { | 126 inline QuicIOVector MakeIOVector(base::StringPiece str, struct iovec* iov) { |
145 iov->iov_base = const_cast<char*>(str.data()); | 127 iov->iov_base = const_cast<char*>(str.data()); |
146 iov->iov_len = static_cast<size_t>(str.size()); | 128 iov->iov_len = static_cast<size_t>(str.size()); |
147 QuicIOVector quic_iov(iov, 1, str.size()); | 129 QuicIOVector quic_iov(iov, 1, str.size()); |
148 return quic_iov; | 130 return quic_iov; |
149 } | 131 } |
150 | 132 |
151 } // namespace net | 133 } // namespace net |
152 | 134 |
153 #endif // NET_QUIC_CORE_QUIC_UTILS_H_ | 135 #endif // NET_QUIC_CORE_QUIC_UTILS_H_ |
OLD | NEW |