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 #include "net/dns/public/host_resolver_results.h" 6 7 #include <stdint.h> 8 9 #include <optional> 10 #include <string> 11 #include <utility> 12 13 #include "base/numerics/safe_conversions.h" 14 #include "base/values.h" 15 #include "net/base/connection_endpoint_metadata.h" 16 #include "net/base/ip_address.h" 17 #include "net/base/ip_endpoint.h" 18 19 namespace net { 20 21 HostResolverEndpointResult::HostResolverEndpointResult() = default; 22 HostResolverEndpointResult::~HostResolverEndpointResult() = default; 23 HostResolverEndpointResult::HostResolverEndpointResult( 24 const HostResolverEndpointResult&) = default; 25 HostResolverEndpointResult::HostResolverEndpointResult( 26 HostResolverEndpointResult&&) = default; 27 28 ServiceEndpoint::ServiceEndpoint() = default; 29 ServiceEndpoint::~ServiceEndpoint() = default; 30 ServiceEndpoint(std::vector<IPEndPoint> ipv4_endpoints,std::vector<IPEndPoint> ipv6_endpoints,ConnectionEndpointMetadata metadata)31ServiceEndpoint::ServiceEndpoint(std::vector<IPEndPoint> ipv4_endpoints, 32 std::vector<IPEndPoint> ipv6_endpoints, 33 ConnectionEndpointMetadata metadata) 34 : ipv4_endpoints(std::move(ipv4_endpoints)), 35 ipv6_endpoints(std::move(ipv6_endpoints)), 36 metadata(std::move(metadata)) {} 37 38 ServiceEndpoint::ServiceEndpoint(const ServiceEndpoint&) = default; 39 ServiceEndpoint::ServiceEndpoint(ServiceEndpoint&&) = default; 40 ToValue() const41base::Value::Dict ServiceEndpoint::ToValue() const { 42 base::Value::Dict dict; 43 base::Value::List ipv4_endpoints_list; 44 base::Value::List ipv6_endpoints_list; 45 for (const auto& ip_endpoint : ipv4_endpoints) { 46 ipv4_endpoints_list.Append(ip_endpoint.ToValue()); 47 } 48 for (const auto& ip_endpoint : ipv6_endpoints) { 49 ipv6_endpoints_list.Append(ip_endpoint.ToValue()); 50 } 51 52 dict.Set("ipv4_endpoints", std::move(ipv4_endpoints_list)); 53 dict.Set("ipv6_endpoints", std::move(ipv6_endpoints_list)); 54 dict.Set("metadata", metadata.ToValue()); 55 return dict; 56 } 57 58 } // namespace net 59