Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 10 | #include "net/base/int128.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 11 | #include "net/base/net_export.h" |
| 12 | #include "net/quic/quic_protocol.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | |
| 14 | namespace net { |
| 15 | |
| 16 | class NET_EXPORT_PRIVATE QuicUtils { |
| 17 | public: |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 18 | enum Priority { |
| 19 | LOCAL_PRIORITY, |
| 20 | PEER_PRIORITY, |
| 21 | }; |
| 22 | |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 23 | // returns the 64 bit FNV1a hash of the data. See |
| 24 | // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param |
| 25 | static uint64 FNV1a_64_Hash(const char* data, int len); |
| 26 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 27 | // returns the 128 bit FNV1a hash of the data. See |
| 28 | // http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param |
| 29 | static uint128 FNV1a_128_Hash(const char* data, int len); |
| 30 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 31 | // FindMutualTag sets |out_result| to the first tag in the priority list that |
| 32 | // is also in the other list and returns true. If there is no intersection it |
| 33 | // returns false. |
| 34 | // |
| 35 | // Which list has priority is determined by |priority|. |
| 36 | // |
| 37 | // If |out_index| is non-NULL and a match is found then the index of that |
| 38 | // match in |their_tags| is written to |out_index|. |
| 39 | static bool FindMutualTag(const QuicTagVector& our_tags, |
| 40 | const QuicTag* their_tags, |
| 41 | size_t num_their_tags, |
| 42 | Priority priority, |
| 43 | QuicTag* out_result, |
| 44 | size_t* out_index); |
| 45 | |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 46 | // SerializeUint128 writes |v| in little-endian form to |out|. |
| 47 | static void SerializeUint128(uint128 v, uint8* out); |
| 48 | |
| 49 | // ParseUint128 parses a little-endian uint128 from |in| and returns it. |
| 50 | static uint128 ParseUint128(const uint8* in); |
| 51 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 52 | // Returns the name of the QuicRstStreamErrorCode as a char* |
| 53 | static const char* StreamErrorToString(QuicRstStreamErrorCode error); |
| 54 | |
| 55 | // Returns the name of the QuicErrorCode as a char* |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 56 | static const char* ErrorToString(QuicErrorCode error); |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 57 | |
| 58 | // Returns the level of encryption as a char* |
| 59 | static const char* EncryptionLevelToString(EncryptionLevel level); |
| 60 | |
| 61 | // TagToString is a utility function for pretty-printing handshake messages |
| 62 | // that converts a tag to a string. It will try to maintain the human friendly |
| 63 | // name if possible (i.e. kABCD -> "ABCD"), or will just treat it as a number |
| 64 | // if not. |
| 65 | static std::string TagToString(QuicTag tag); |
| 66 | |
| 67 | // Given a binary buffer, return a hex+ASCII dump in the style of |
| 68 | // tcpdump's -X and -XX options: |
| 69 | // "0x0000: 0090 69bd 5400 000d 610f 0189 0800 4500 ..i.T...a.....E.\n" |
| 70 | // "0x0010: 001c fb98 4000 4001 7e18 d8ef 2301 455d ....@.@.~...#.E]\n" |
| 71 | // "0x0020: 7fe2 0800 6bcb 0bc6 806e ....k....n\n" |
| 72 | static std::string StringToHexASCIIDump(base::StringPiece in_buffer); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 73 | |
| 74 | static char* AsChars(unsigned char* data) { |
| 75 | return reinterpret_cast<char*>(data); |
| 76 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | } // namespace net |
| 80 | |
| 81 | #endif // NET_QUIC_QUIC_UTILS_H_ |