xref: /aosp_15_r20/external/cronet/net/dns/public/host_resolver_results.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_DNS_PUBLIC_HOST_RESOLVER_RESULTS_H_
6 #define NET_DNS_PUBLIC_HOST_RESOLVER_RESULTS_H_
7 
8 #include <optional>
9 #include <string>
10 #include <tuple>
11 #include <vector>
12 
13 #include "net/base/connection_endpoint_metadata.h"
14 #include "net/base/ip_endpoint.h"
15 #include "net/base/net_export.h"
16 
17 namespace net {
18 
19 // Host-resolution-result representation of a single endpoint and the
20 // information necessary to attempt a connection to that endpoint.
21 struct NET_EXPORT_PRIVATE HostResolverEndpointResult {
22   HostResolverEndpointResult();
23   ~HostResolverEndpointResult();
24 
25   HostResolverEndpointResult(const HostResolverEndpointResult&);
26   HostResolverEndpointResult& operator=(const HostResolverEndpointResult&) =
27       default;
28   HostResolverEndpointResult(HostResolverEndpointResult&&);
29   HostResolverEndpointResult& operator=(HostResolverEndpointResult&&) = default;
30 
31   bool operator==(const HostResolverEndpointResult& other) const {
32     return std::tie(ip_endpoints, metadata) ==
33            std::tie(other.ip_endpoints, other.metadata);
34   }
35   bool operator!=(const HostResolverEndpointResult& other) const {
36     return !(*this == other);
37   }
38 
39   // IP endpoints at which to connect to the service.
40   std::vector<net::IPEndPoint> ip_endpoints;
41 
42   // Additional metadata for creating connections to the endpoint. Typically
43   // sourced from DNS HTTPS records.
44   ConnectionEndpointMetadata metadata;
45 };
46 
47 using HostResolverEndpointResults =
48     std::vector<net::HostResolverEndpointResult>;
49 
50 // Represents a result of a service endpoint resolution. Almost the identical
51 // to HostResolverEndpointResult, but has separate IPEndPoints for each address
52 // family.
53 struct NET_EXPORT_PRIVATE ServiceEndpoint {
54   ServiceEndpoint();
55   ~ServiceEndpoint();
56 
57   ServiceEndpoint(std::vector<IPEndPoint> ipv4_endpoints,
58                   std::vector<IPEndPoint> ipv6_endpoints,
59                   ConnectionEndpointMetadata metadata);
60 
61   ServiceEndpoint(const ServiceEndpoint&);
62   ServiceEndpoint& operator=(const ServiceEndpoint&) = default;
63   ServiceEndpoint(ServiceEndpoint&&);
64   ServiceEndpoint& operator=(ServiceEndpoint&&) = default;
65 
66   bool operator==(const ServiceEndpoint& other) const {
67     return std::forward_as_tuple(ipv4_endpoints, ipv6_endpoints, metadata) ==
68            std::forward_as_tuple(other.ipv4_endpoints, other.ipv6_endpoints,
69                                  other.metadata);
70   }
71   bool operator!=(const ServiceEndpoint& other) const {
72     return !(*this == other);
73   }
74 
75   base::Value::Dict ToValue() const;
76 
77   // IPv4 endpoints at which to connect to the service.
78   std::vector<IPEndPoint> ipv4_endpoints;
79 
80   // IPv6 endpoints at which to connect to the service.
81   std::vector<IPEndPoint> ipv6_endpoints;
82 
83   // Additional metadata for creating connections to the endpoint. Typically
84   // sourced from DNS HTTPS records.
85   // TODO(crbug.com/41493696): Consider inlining EchConfigList and ALPNs rather
86   // than just using ConnectionEndpointMetadata.
87   ConnectionEndpointMetadata metadata;
88 };
89 
90 }  // namespace net
91 
92 #endif  // NET_DNS_PUBLIC_HOST_RESOLVER_RESULTS_H_
93