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