• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016 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 #ifndef QUICHE_QUIC_CORE_QUIC_TAG_H_
6 #define QUICHE_QUIC_CORE_QUIC_TAG_H_
7 
8 #include <cstdint>
9 #include <map>
10 #include <string>
11 #include <vector>
12 
13 #include "absl/strings/string_view.h"
14 #include "quiche/quic/platform/api/quic_export.h"
15 
16 namespace quic {
17 
18 // A QuicTag is a 32-bit used as identifiers in the QUIC handshake.  The use of
19 // a uint32_t seeks to provide a balance between the tyranny of magic number
20 // registries and the verbosity of strings. As far as the wire protocol is
21 // concerned, these are opaque, 32-bit values.
22 //
23 // Tags will often be referred to by their ASCII equivalent, e.g. EXMP. This is
24 // just a mnemonic for the value 0x504d5845 (little-endian version of the ASCII
25 // string E X M P).
26 using QuicTag = uint32_t;
27 using QuicTagValueMap = std::map<QuicTag, std::string>;
28 using QuicTagVector = std::vector<QuicTag>;
29 
30 // MakeQuicTag returns a value given the four bytes. For example:
31 //   MakeQuicTag('C', 'H', 'L', 'O');
32 QUIC_EXPORT_PRIVATE QuicTag MakeQuicTag(uint8_t a, uint8_t b, uint8_t c,
33                                         uint8_t d);
34 
35 // Returns true if |tag_vector| contains |tag|.
36 QUIC_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector,
37                                          QuicTag tag);
38 
39 // Sets |out_result| to the first tag in |our_tags| that is also in |their_tags|
40 // and returns true. If there is no intersection it returns false.
41 //
42 // If |out_index| is non-nullptr and a match is found then the index of that
43 // match in |their_tags| is written to |out_index|.
44 QUIC_EXPORT_PRIVATE bool FindMutualQuicTag(const QuicTagVector& our_tags,
45                                            const QuicTagVector& their_tags,
46                                            QuicTag* out_result,
47                                            size_t* out_index);
48 
49 // A utility function that converts a tag to a string. It will try to maintain
50 // the human friendly name if possible (i.e. kABCD -> "ABCD"), or will just
51 // treat it as a number if not.
52 QUIC_EXPORT_PRIVATE std::string QuicTagToString(QuicTag tag);
53 
54 // Utility function that converts a string of the form "ABCD" to its
55 // corresponding QuicTag. Note that tags that are less than four characters
56 // long are right-padded with zeroes. Tags that contain non-ASCII characters
57 // are represented as 8-character-long hexadecimal strings.
58 QUIC_EXPORT_PRIVATE QuicTag ParseQuicTag(absl::string_view tag_string);
59 
60 // Utility function that converts a string of the form "ABCD,EFGH" to a vector
61 // of the form {kABCD,kEFGH}. Note the caveats on ParseQuicTag.
62 QUIC_EXPORT_PRIVATE QuicTagVector
63 ParseQuicTagVector(absl::string_view tags_string);
64 
65 }  // namespace quic
66 
67 #endif  // QUICHE_QUIC_CORE_QUIC_TAG_H_
68