| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 // | |
| 5 // Some helpers for quic. | |
| 6 | |
| 7 #ifndef NET_QUIC_QUIC_UTILS_H_ | |
| 8 #define NET_QUIC_QUIC_UTILS_H_ | |
| 9 | |
| 10 #include <string> | |
| 11 | |
| 12 #include "net/base/int128.h" | |
| 13 #include "net/base/net_export.h" | |
| 14 #include "net/quic/quic_protocol.h" | |
| 15 | |
| 16 namespace net { | |
| 17 | |
| 18 class NET_EXPORT_PRIVATE QuicUtils { | |
| 19 public: | |
| 20 enum Priority { | |
| 21 LOCAL_PRIORITY, | |
| 22 PEER_PRIORITY, | |
| 23 }; | |
| 24 | |
| 25 // Returns the 64 bit FNV1a hash of the data. See | |
| 26 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param | |
| 27 static uint64 FNV1a_64_Hash(const char* data, int len); | |
| 28 | |
| 29 // returns the 128 bit FNV1a hash of the data. See | |
| 30 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param | |
| 31 static uint128 FNV1a_128_Hash(const char* data1, int len1); | |
| 32 | |
| 33 // returns the 128 bit FNV1a hash of the two sequences of data. See | |
| 34 // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param | |
| 35 static uint128 FNV1a_128_Hash_Two(const char* data1, | |
| 36 int len1, | |
| 37 const char* data2, | |
| 38 int len2); | |
| 39 | |
| 40 // returns the 128 bit FNV1a hash of the |data|, starting with the | |
| 41 // previous hash. | |
| 42 static uint128 IncrementalHash(uint128 hash, const char* data, size_t len); | |
| 43 | |
| 44 // FindMutualTag sets |out_result| to the first tag in the priority list that | |
| 45 // is also in the other list and returns true. If there is no intersection it | |
| 46 // returns false. | |
| 47 // | |
| 48 // Which list has priority is determined by |priority|. | |
| 49 // | |
| 50 // If |out_index| is non-nullptr and a match is found then the index of that | |
| 51 // match in |their_tags| is written to |out_index|. | |
| 52 static bool FindMutualTag(const QuicTagVector& our_tags, | |
| 53 const QuicTag* their_tags, | |
| 54 size_t num_their_tags, | |
| 55 Priority priority, | |
| 56 QuicTag* out_result, | |
| 57 size_t* out_index); | |
| 58 | |
| 59 // SerializeUint128 writes |v| in little-endian form to |out|. | |
| 60 static void SerializeUint128(uint128 v, uint8* out); | |
| 61 | |
| 62 // SerializeUint128 writes the first 96 bits of |v| in little-endian form | |
| 63 // to |out|. | |
| 64 static void SerializeUint128Short(uint128 v, uint8* out); | |
| 65 | |
| 66 // Returns the name of the QuicRstStreamErrorCode as a char* | |
| 67 static const char* StreamErrorToString(QuicRstStreamErrorCode error); | |
| 68 | |
| 69 // Returns the name of the QuicErrorCode as a char* | |
| 70 static const char* ErrorToString(QuicErrorCode error); | |
| 71 | |
| 72 // Returns the level of encryption as a char* | |
| 73 static const char* EncryptionLevelToString(EncryptionLevel level); | |
| 74 | |
| 75 // Returns TransmissionType as a char* | |
| 76 static const char* TransmissionTypeToString(TransmissionType type); | |
| 77 | |
| 78 // TagToString is a utility function for pretty-printing handshake messages | |
| 79 // that converts a tag to a string. It will try to maintain the human friendly | |
| 80 // name if possible (i.e. kABCD -> "ABCD"), or will just treat it as a number | |
| 81 // if not. | |
| 82 static std::string TagToString(QuicTag tag); | |
| 83 | |
| 84 // Returns the list of QUIC tags represented by the comma separated | |
| 85 // string in |connection_options|. | |
| 86 static QuicTagVector ParseQuicConnectionOptions( | |
| 87 const std::string& connection_options); | |
| 88 | |
| 89 // Given a binary buffer, return a hex+ASCII dump in the style of | |
| 90 // tcpdump's -X and -XX options: | |
| 91 // "0x0000: 0090 69bd 5400 000d 610f 0189 0800 4500 ..i.T...a.....E.\n" | |
| 92 // "0x0010: 001c fb98 4000 4001 7e18 d8ef 2301 455d ....@.@.~...#.E]\n" | |
| 93 // "0x0020: 7fe2 0800 6bcb 0bc6 806e ....k....n\n" | |
| 94 static std::string StringToHexASCIIDump(base::StringPiece in_buffer); | |
| 95 | |
| 96 static char* AsChars(unsigned char* data) { | |
| 97 return reinterpret_cast<char*>(data); | |
| 98 } | |
| 99 | |
| 100 static QuicPriority LowestPriority(); | |
| 101 | |
| 102 static QuicPriority HighestPriority(); | |
| 103 | |
| 104 private: | |
| 105 DISALLOW_COPY_AND_ASSIGN(QuicUtils); | |
| 106 }; | |
| 107 | |
| 108 // Utility function that returns an IOVector object wrapped around |str|. | |
| 109 inline IOVector MakeIOVector(base::StringPiece str) { | |
| 110 IOVector iov; | |
| 111 iov.Append(const_cast<char*>(str.data()), str.size()); | |
| 112 return iov; | |
| 113 } | |
| 114 | |
| 115 } // namespace net | |
| 116 | |
| 117 #endif // NET_QUIC_QUIC_UTILS_H_ | |
| OLD | NEW |