xref: /aosp_15_r20/external/cronet/net/base/connection_endpoint_metadata.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors
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 NET_BASE_CONNECTION_ENDPOINT_METADATA_H_
6 #define NET_BASE_CONNECTION_ENDPOINT_METADATA_H_
7 
8 #include <stdint.h>
9 
10 #include <optional>
11 #include <string>
12 #include <tuple>
13 #include <vector>
14 
15 #include "base/values.h"
16 #include "net/base/net_export.h"
17 
18 namespace net {
19 
20 // Metadata used to create UDP/TCP/TLS/etc connections or information about such
21 // a connection.
22 struct NET_EXPORT_PRIVATE ConnectionEndpointMetadata {
23   // Expected to be parsed/consumed only by BoringSSL code and thus passed
24   // around here only as a raw byte array.
25   using EchConfigList = std::vector<uint8_t>;
26 
27   ConnectionEndpointMetadata();
28   ConnectionEndpointMetadata(std::vector<std::string> supported_protocol_alpns,
29                              EchConfigList ech_config_list,
30                              std::string target_name);
31   ~ConnectionEndpointMetadata();
32 
33   ConnectionEndpointMetadata(const ConnectionEndpointMetadata&);
34   ConnectionEndpointMetadata& operator=(const ConnectionEndpointMetadata&) =
35       default;
36   ConnectionEndpointMetadata(ConnectionEndpointMetadata&&);
37   ConnectionEndpointMetadata& operator=(ConnectionEndpointMetadata&&) = default;
38 
39   bool operator==(const ConnectionEndpointMetadata& other) const {
40     return std::tie(supported_protocol_alpns, ech_config_list, target_name) ==
41            std::tie(other.supported_protocol_alpns, other.ech_config_list,
42                     target_name);
43   }
44 
45   base::Value ToValue() const;
46   static std::optional<ConnectionEndpointMetadata> FromValue(
47       const base::Value& value);
48 
49   // ALPN strings for protocols supported by the endpoint. Empty for default
50   // non-protocol endpoint.
51   std::vector<std::string> supported_protocol_alpns;
52 
53   // If not empty, TLS Encrypted Client Hello config for the service.
54   EchConfigList ech_config_list;
55 
56   // The target domain name of this metadata.
57   std::string target_name;
58 };
59 
60 }  // namespace net
61 
62 #endif  // NET_BASE_CONNECTION_ENDPOINT_METADATA_H_
63