| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 that are for chromium codebase. |
| 6 | 6 |
| 7 #ifndef NET_QUIC_QUIC_UTILS_H_ | 7 #ifndef NET_QUIC_QUIC_UTILS_CHROMIUM_H_ |
| 8 #define NET_QUIC_QUIC_UTILS_H_ | 8 #define NET_QUIC_QUIC_UTILS_CHROMIUM_H_ |
| 9 | 9 |
| 10 #include "net/base/int128.h" | 10 #include "base/basictypes.h" |
| 11 #include "net/base/net_export.h" | 11 #include "base/logging.h" |
| 12 #include "net/quic/quic_protocol.h" | |
| 13 | 12 |
| 14 namespace net { | 13 namespace net { |
| 15 | 14 |
| 16 // | 15 // |
| 17 // Find*() | 16 // Find*() |
| 18 // | 17 // |
| 19 | 18 |
| 20 // Returns a const reference to the value associated with the given key if it | 19 // Returns a const reference to the value associated with the given key if it |
| 21 // exists. Crashes otherwise. | 20 // exists. Crashes otherwise. |
| 22 // | 21 // |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 typename Collection::value_type::second_type* | 68 typename Collection::value_type::second_type* |
| 70 FindOrNull(Collection& collection, // NOLINT | 69 FindOrNull(Collection& collection, // NOLINT |
| 71 const typename Collection::value_type::first_type& key) { | 70 const typename Collection::value_type::first_type& key) { |
| 72 typename Collection::iterator it = collection.find(key); | 71 typename Collection::iterator it = collection.find(key); |
| 73 if (it == collection.end()) { | 72 if (it == collection.end()) { |
| 74 return 0; | 73 return 0; |
| 75 } | 74 } |
| 76 return &it->second; | 75 return &it->second; |
| 77 } | 76 } |
| 78 | 77 |
| 79 class NET_EXPORT_PRIVATE QuicUtils { | |
| 80 public: | |
| 81 enum Priority { | |
| 82 LOCAL_PRIORITY, | |
| 83 PEER_PRIORITY, | |
| 84 }; | |
| 85 | |
| 86 // returns the 64 bit FNV1a hash of the data. See | |
| 87 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param | |
| 88 static uint64 FNV1a_64_Hash(const char* data, int len); | |
| 89 | |
| 90 // returns the 128 bit FNV1a hash of the data. See | |
| 91 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param | |
| 92 static uint128 FNV1a_128_Hash(const char* data, int len); | |
| 93 | |
| 94 // FindMutualTag sets |out_result| to the first tag in the priority list that | |
| 95 // is also in the other list and returns true. If there is no intersection it | |
| 96 // returns false. | |
| 97 // | |
| 98 // Which list has priority is determined by |priority|. | |
| 99 // | |
| 100 // If |out_index| is non-NULL and a match is found then the index of that | |
| 101 // match in |their_tags| is written to |out_index|. | |
| 102 static bool FindMutualTag(const QuicTagVector& our_tags, | |
| 103 const QuicTag* their_tags, | |
| 104 size_t num_their_tags, | |
| 105 Priority priority, | |
| 106 QuicTag* out_result, | |
| 107 size_t* out_index); | |
| 108 | |
| 109 // SerializeUint128 writes |v| in little-endian form to |out|. | |
| 110 static void SerializeUint128(uint128 v, uint8* out); | |
| 111 | |
| 112 // SerializeUint128 writes the first 96 bits of |v| in little-endian form | |
| 113 // to |out|. | |
| 114 static void SerializeUint128Short(uint128 v, uint8* out); | |
| 115 | |
| 116 // Returns the name of the QuicRstStreamErrorCode as a char* | |
| 117 static const char* StreamErrorToString(QuicRstStreamErrorCode error); | |
| 118 | |
| 119 // Returns the name of the QuicErrorCode as a char* | |
| 120 static const char* ErrorToString(QuicErrorCode error); | |
| 121 | |
| 122 // Returns the level of encryption as a char* | |
| 123 static const char* EncryptionLevelToString(EncryptionLevel level); | |
| 124 | |
| 125 // TagToString is a utility function for pretty-printing handshake messages | |
| 126 // that converts a tag to a string. It will try to maintain the human friendly | |
| 127 // name if possible (i.e. kABCD -> "ABCD"), or will just treat it as a number | |
| 128 // if not. | |
| 129 static std::string TagToString(QuicTag tag); | |
| 130 | |
| 131 // Given a binary buffer, return a hex+ASCII dump in the style of | |
| 132 // tcpdump's -X and -XX options: | |
| 133 // "0x0000: 0090 69bd 5400 000d 610f 0189 0800 4500 ..i.T...a.....E.\n" | |
| 134 // "0x0010: 001c fb98 4000 4001 7e18 d8ef 2301 455d ....@.@.~...#.E]\n" | |
| 135 // "0x0020: 7fe2 0800 6bcb 0bc6 806e ....k....n\n" | |
| 136 static std::string StringToHexASCIIDump(base::StringPiece in_buffer); | |
| 137 | |
| 138 static char* AsChars(unsigned char* data) { | |
| 139 return reinterpret_cast<char*>(data); | |
| 140 } | |
| 141 | |
| 142 static QuicPriority LowestPriority(); | |
| 143 | |
| 144 static QuicPriority HighestPriority(); | |
| 145 }; | |
| 146 | |
| 147 // Utility function that returns an IOVector object wrapped around |str|. | |
| 148 inline IOVector MakeIOVector(base::StringPiece str) { | |
| 149 IOVector iov; | |
| 150 iov.Append(const_cast<char*>(str.data()), str.size()); | |
| 151 return iov; | |
| 152 } | |
| 153 | |
| 154 } // namespace net | 78 } // namespace net |
| 155 | 79 |
| 156 #endif // NET_QUIC_QUIC_UTILS_H_ | 80 #endif // NET_QUIC_QUIC_UTILS_CHROMIUM_H_ |
| OLD | NEW |