diff --git a/CMakeLists.txt b/CMakeLists.txt index e2006b26891..0392d456561 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2158,7 +2158,6 @@ add_library(grpc src/core/lib/event_engine/ares_resolver.cc src/core/lib/event_engine/cf_engine/cf_engine.cc src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc - src/core/lib/event_engine/cf_engine/dns_service_resolver.cc src/core/lib/event_engine/channel_args_endpoint_config.cc src/core/lib/event_engine/default_event_engine.cc src/core/lib/event_engine/default_event_engine_factory.cc @@ -2868,7 +2867,6 @@ add_library(grpc_unsecure src/core/lib/event_engine/ares_resolver.cc src/core/lib/event_engine/cf_engine/cf_engine.cc src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc - src/core/lib/event_engine/cf_engine/dns_service_resolver.cc src/core/lib/event_engine/channel_args_endpoint_config.cc src/core/lib/event_engine/default_event_engine.cc src/core/lib/event_engine/default_event_engine_factory.cc @@ -4407,7 +4405,6 @@ add_library(grpc_authorization_provider src/core/lib/event_engine/ares_resolver.cc src/core/lib/event_engine/cf_engine/cf_engine.cc src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc - src/core/lib/event_engine/cf_engine/dns_service_resolver.cc src/core/lib/event_engine/channel_args_endpoint_config.cc src/core/lib/event_engine/default_event_engine.cc src/core/lib/event_engine/default_event_engine_factory.cc @@ -8142,10 +8139,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) test/core/event_engine/test_suite/event_engine_test_framework.cc test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc test/core/event_engine/test_suite/tests/client_test.cc - test/core/event_engine/test_suite/tests/dns_test.cc test/core/event_engine/test_suite/tests/timer_test.cc - test/core/util/fake_udp_and_tcp_server.cc - test/cpp/util/get_grpc_test_runfile_dir.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) @@ -8175,7 +8169,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) ${_gRPC_ZLIB_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} grpc_unsecure - grpc++_test_util + grpc_test_util ) @@ -12451,7 +12445,6 @@ add_executable(frame_test src/core/lib/event_engine/ares_resolver.cc src/core/lib/event_engine/cf_engine/cf_engine.cc src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc - src/core/lib/event_engine/cf_engine/dns_service_resolver.cc src/core/lib/event_engine/channel_args_endpoint_config.cc src/core/lib/event_engine/default_event_engine.cc src/core/lib/event_engine/default_event_engine_factory.cc diff --git a/Makefile b/Makefile index 7e39779d5a1..f1a04b993b0 100644 --- a/Makefile +++ b/Makefile @@ -1440,7 +1440,6 @@ LIBGRPC_SRC = \ src/core/lib/event_engine/ares_resolver.cc \ src/core/lib/event_engine/cf_engine/cf_engine.cc \ src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc \ - src/core/lib/event_engine/cf_engine/dns_service_resolver.cc \ src/core/lib/event_engine/channel_args_endpoint_config.cc \ src/core/lib/event_engine/default_event_engine.cc \ src/core/lib/event_engine/default_event_engine_factory.cc \ @@ -2003,7 +2002,6 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/event_engine/ares_resolver.cc \ src/core/lib/event_engine/cf_engine/cf_engine.cc \ src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc \ - src/core/lib/event_engine/cf_engine/dns_service_resolver.cc \ src/core/lib/event_engine/channel_args_endpoint_config.cc \ src/core/lib/event_engine/default_event_engine.cc \ src/core/lib/event_engine/default_event_engine_factory.cc \ diff --git a/Package.swift b/Package.swift index 56699d86e08..b712cd822d9 100644 --- a/Package.swift +++ b/Package.swift @@ -1069,8 +1069,6 @@ let package = Package( "src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc", "src/core/lib/event_engine/cf_engine/cfstream_endpoint.h", "src/core/lib/event_engine/cf_engine/cftype_unique_ref.h", - "src/core/lib/event_engine/cf_engine/dns_service_resolver.cc", - "src/core/lib/event_engine/cf_engine/dns_service_resolver.h", "src/core/lib/event_engine/channel_args_endpoint_config.cc", "src/core/lib/event_engine/channel_args_endpoint_config.h", "src/core/lib/event_engine/common_closures.h", diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 11b83926476..da1291c2353 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -687,7 +687,6 @@ libs: - src/core/lib/event_engine/cf_engine/cf_engine.h - src/core/lib/event_engine/cf_engine/cfstream_endpoint.h - src/core/lib/event_engine/cf_engine/cftype_unique_ref.h - - src/core/lib/event_engine/cf_engine/dns_service_resolver.h - src/core/lib/event_engine/channel_args_endpoint_config.h - src/core/lib/event_engine/common_closures.h - src/core/lib/event_engine/default_event_engine.h @@ -1502,7 +1501,6 @@ libs: - src/core/lib/event_engine/ares_resolver.cc - src/core/lib/event_engine/cf_engine/cf_engine.cc - src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc - - src/core/lib/event_engine/cf_engine/dns_service_resolver.cc - src/core/lib/event_engine/channel_args_endpoint_config.cc - src/core/lib/event_engine/default_event_engine.cc - src/core/lib/event_engine/default_event_engine_factory.cc @@ -2086,7 +2084,6 @@ libs: - src/core/lib/event_engine/cf_engine/cf_engine.h - src/core/lib/event_engine/cf_engine/cfstream_endpoint.h - src/core/lib/event_engine/cf_engine/cftype_unique_ref.h - - src/core/lib/event_engine/cf_engine/dns_service_resolver.h - src/core/lib/event_engine/channel_args_endpoint_config.h - src/core/lib/event_engine/common_closures.h - src/core/lib/event_engine/default_event_engine.h @@ -2508,7 +2505,6 @@ libs: - src/core/lib/event_engine/ares_resolver.cc - src/core/lib/event_engine/cf_engine/cf_engine.cc - src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc - - src/core/lib/event_engine/cf_engine/dns_service_resolver.cc - src/core/lib/event_engine/channel_args_endpoint_config.cc - src/core/lib/event_engine/default_event_engine.cc - src/core/lib/event_engine/default_event_engine_factory.cc @@ -3596,7 +3592,6 @@ libs: - src/core/lib/event_engine/cf_engine/cf_engine.h - src/core/lib/event_engine/cf_engine/cfstream_endpoint.h - src/core/lib/event_engine/cf_engine/cftype_unique_ref.h - - src/core/lib/event_engine/cf_engine/dns_service_resolver.h - src/core/lib/event_engine/channel_args_endpoint_config.h - src/core/lib/event_engine/common_closures.h - src/core/lib/event_engine/default_event_engine.h @@ -3897,7 +3892,6 @@ libs: - src/core/lib/event_engine/ares_resolver.cc - src/core/lib/event_engine/cf_engine/cf_engine.cc - src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc - - src/core/lib/event_engine/cf_engine/dns_service_resolver.cc - src/core/lib/event_engine/channel_args_endpoint_config.cc - src/core/lib/event_engine/default_event_engine.cc - src/core/lib/event_engine/default_event_engine_factory.cc @@ -5888,23 +5882,17 @@ targets: - test/core/event_engine/test_suite/event_engine_test_framework.h - test/core/event_engine/test_suite/posix/oracle_event_engine_posix.h - test/core/event_engine/test_suite/tests/client_test.h - - test/core/event_engine/test_suite/tests/dns_test.h - test/core/event_engine/test_suite/tests/timer_test.h - - test/core/util/fake_udp_and_tcp_server.h - - test/cpp/util/get_grpc_test_runfile_dir.h src: - test/core/event_engine/event_engine_test_utils.cc - test/core/event_engine/test_suite/cf_event_engine_test.cc - test/core/event_engine/test_suite/event_engine_test_framework.cc - test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc - test/core/event_engine/test_suite/tests/client_test.cc - - test/core/event_engine/test_suite/tests/dns_test.cc - test/core/event_engine/test_suite/tests/timer_test.cc - - test/core/util/fake_udp_and_tcp_server.cc - - test/cpp/util/get_grpc_test_runfile_dir.cc deps: - grpc_unsecure - - grpc++_test_util + - grpc_test_util platforms: - linux - posix @@ -8126,7 +8114,6 @@ targets: - src/core/lib/event_engine/cf_engine/cf_engine.h - src/core/lib/event_engine/cf_engine/cfstream_endpoint.h - src/core/lib/event_engine/cf_engine/cftype_unique_ref.h - - src/core/lib/event_engine/cf_engine/dns_service_resolver.h - src/core/lib/event_engine/channel_args_endpoint_config.h - src/core/lib/event_engine/common_closures.h - src/core/lib/event_engine/default_event_engine.h @@ -8409,7 +8396,6 @@ targets: - src/core/lib/event_engine/ares_resolver.cc - src/core/lib/event_engine/cf_engine/cf_engine.cc - src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc - - src/core/lib/event_engine/cf_engine/dns_service_resolver.cc - src/core/lib/event_engine/channel_args_endpoint_config.cc - src/core/lib/event_engine/default_event_engine.cc - src/core/lib/event_engine/default_event_engine_factory.cc diff --git a/config.m4 b/config.m4 index 93a4b2c5b50..7963168b683 100644 --- a/config.m4 +++ b/config.m4 @@ -522,7 +522,6 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/event_engine/ares_resolver.cc \ src/core/lib/event_engine/cf_engine/cf_engine.cc \ src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc \ - src/core/lib/event_engine/cf_engine/dns_service_resolver.cc \ src/core/lib/event_engine/channel_args_endpoint_config.cc \ src/core/lib/event_engine/default_event_engine.cc \ src/core/lib/event_engine/default_event_engine_factory.cc \ diff --git a/config.w32 b/config.w32 index 6de00278ef0..e8412bdeb19 100644 --- a/config.w32 +++ b/config.w32 @@ -487,7 +487,6 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\event_engine\\ares_resolver.cc " + "src\\core\\lib\\event_engine\\cf_engine\\cf_engine.cc " + "src\\core\\lib\\event_engine\\cf_engine\\cfstream_endpoint.cc " + - "src\\core\\lib\\event_engine\\cf_engine\\dns_service_resolver.cc " + "src\\core\\lib\\event_engine\\channel_args_endpoint_config.cc " + "src\\core\\lib\\event_engine\\default_event_engine.cc " + "src\\core\\lib\\event_engine\\default_event_engine_factory.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index d9590738516..0ff4a859756 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -758,7 +758,6 @@ Pod::Spec.new do |s| 'src/core/lib/event_engine/cf_engine/cf_engine.h', 'src/core/lib/event_engine/cf_engine/cfstream_endpoint.h', 'src/core/lib/event_engine/cf_engine/cftype_unique_ref.h', - 'src/core/lib/event_engine/cf_engine/dns_service_resolver.h', 'src/core/lib/event_engine/channel_args_endpoint_config.h', 'src/core/lib/event_engine/common_closures.h', 'src/core/lib/event_engine/default_event_engine.h', @@ -1808,7 +1807,6 @@ Pod::Spec.new do |s| 'src/core/lib/event_engine/cf_engine/cf_engine.h', 'src/core/lib/event_engine/cf_engine/cfstream_endpoint.h', 'src/core/lib/event_engine/cf_engine/cftype_unique_ref.h', - 'src/core/lib/event_engine/cf_engine/dns_service_resolver.h', 'src/core/lib/event_engine/channel_args_endpoint_config.h', 'src/core/lib/event_engine/common_closures.h', 'src/core/lib/event_engine/default_event_engine.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index c6f4811efe8..1f7ee059f52 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -1170,8 +1170,6 @@ Pod::Spec.new do |s| 'src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc', 'src/core/lib/event_engine/cf_engine/cfstream_endpoint.h', 'src/core/lib/event_engine/cf_engine/cftype_unique_ref.h', - 'src/core/lib/event_engine/cf_engine/dns_service_resolver.cc', - 'src/core/lib/event_engine/cf_engine/dns_service_resolver.h', 'src/core/lib/event_engine/channel_args_endpoint_config.cc', 'src/core/lib/event_engine/channel_args_endpoint_config.h', 'src/core/lib/event_engine/common_closures.h', @@ -2544,7 +2542,6 @@ Pod::Spec.new do |s| 'src/core/lib/event_engine/cf_engine/cf_engine.h', 'src/core/lib/event_engine/cf_engine/cfstream_endpoint.h', 'src/core/lib/event_engine/cf_engine/cftype_unique_ref.h', - 'src/core/lib/event_engine/cf_engine/dns_service_resolver.h', 'src/core/lib/event_engine/channel_args_endpoint_config.h', 'src/core/lib/event_engine/common_closures.h', 'src/core/lib/event_engine/default_event_engine.h', diff --git a/grpc.gemspec b/grpc.gemspec index d3d4df3b6cc..8eecc38bea7 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -1075,8 +1075,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc ) s.files += %w( src/core/lib/event_engine/cf_engine/cfstream_endpoint.h ) s.files += %w( src/core/lib/event_engine/cf_engine/cftype_unique_ref.h ) - s.files += %w( src/core/lib/event_engine/cf_engine/dns_service_resolver.cc ) - s.files += %w( src/core/lib/event_engine/cf_engine/dns_service_resolver.h ) s.files += %w( src/core/lib/event_engine/channel_args_endpoint_config.cc ) s.files += %w( src/core/lib/event_engine/channel_args_endpoint_config.h ) s.files += %w( src/core/lib/event_engine/common_closures.h ) diff --git a/grpc.gyp b/grpc.gyp index 4ac488d26ea..9a53deff7e9 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -744,7 +744,6 @@ 'src/core/lib/event_engine/ares_resolver.cc', 'src/core/lib/event_engine/cf_engine/cf_engine.cc', 'src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc', - 'src/core/lib/event_engine/cf_engine/dns_service_resolver.cc', 'src/core/lib/event_engine/channel_args_endpoint_config.cc', 'src/core/lib/event_engine/default_event_engine.cc', 'src/core/lib/event_engine/default_event_engine_factory.cc', @@ -1246,7 +1245,6 @@ 'src/core/lib/event_engine/ares_resolver.cc', 'src/core/lib/event_engine/cf_engine/cf_engine.cc', 'src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc', - 'src/core/lib/event_engine/cf_engine/dns_service_resolver.cc', 'src/core/lib/event_engine/channel_args_endpoint_config.cc', 'src/core/lib/event_engine/default_event_engine.cc', 'src/core/lib/event_engine/default_event_engine_factory.cc', @@ -1768,7 +1766,6 @@ 'src/core/lib/event_engine/ares_resolver.cc', 'src/core/lib/event_engine/cf_engine/cf_engine.cc', 'src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc', - 'src/core/lib/event_engine/cf_engine/dns_service_resolver.cc', 'src/core/lib/event_engine/channel_args_endpoint_config.cc', 'src/core/lib/event_engine/default_event_engine.cc', 'src/core/lib/event_engine/default_event_engine_factory.cc', diff --git a/package.xml b/package.xml index 3a8afe9b3fd..00f44d11922 100644 --- a/package.xml +++ b/package.xml @@ -1057,8 +1057,6 @@ - - diff --git a/src/core/BUILD b/src/core/BUILD index 68efe9d4737..f1a323e6687 100644 --- a/src/core/BUILD +++ b/src/core/BUILD @@ -2125,18 +2125,13 @@ grpc_cc_library( srcs = [ "lib/event_engine/cf_engine/cf_engine.cc", "lib/event_engine/cf_engine/cfstream_endpoint.cc", - "lib/event_engine/cf_engine/dns_service_resolver.cc", ], hdrs = [ "lib/event_engine/cf_engine/cf_engine.h", "lib/event_engine/cf_engine/cfstream_endpoint.h", "lib/event_engine/cf_engine/cftype_unique_ref.h", - "lib/event_engine/cf_engine/dns_service_resolver.h", - ], - external_deps = [ - "absl/container:flat_hash_map", - "absl/strings:str_format", ], + external_deps = ["absl/strings:str_format"], deps = [ "event_engine_common", "event_engine_tcp_socket_utils", @@ -2152,7 +2147,6 @@ grpc_cc_library( "strerror", "//:event_engine_base_hdrs", "//:gpr", - "//:parse_address", "//:ref_counted_ptr", "//:sockaddr_utils", ], diff --git a/src/core/lib/event_engine/cf_engine/cf_engine.cc b/src/core/lib/event_engine/cf_engine/cf_engine.cc index af0b7248d19..f835e64a21e 100644 --- a/src/core/lib/event_engine/cf_engine/cf_engine.cc +++ b/src/core/lib/event_engine/cf_engine/cf_engine.cc @@ -22,7 +22,6 @@ #include "src/core/lib/event_engine/cf_engine/cf_engine.h" #include "src/core/lib/event_engine/cf_engine/cfstream_endpoint.h" -#include "src/core/lib/event_engine/cf_engine/dns_service_resolver.h" #include "src/core/lib/event_engine/posix_engine/timer_manager.h" #include "src/core/lib/event_engine/tcp_socket_utils.h" #include "src/core/lib/event_engine/thread_pool/thread_pool.h" @@ -157,14 +156,9 @@ bool CFEventEngine::CancelConnectInternal(ConnectionHandle handle, bool CFEventEngine::IsWorkerThread() { grpc_core::Crash("unimplemented"); } absl::StatusOr> -CFEventEngine::GetDNSResolver(const DNSResolver::ResolverOptions& options) { - if (!options.dns_server.empty()) { - return absl::InvalidArgumentError( - "CFEventEngine does not support custom DNS servers"); - } - - return std::make_unique( - std::static_pointer_cast(shared_from_this())); +CFEventEngine::GetDNSResolver( + const DNSResolver::ResolverOptions& /* options */) { + grpc_core::Crash("unimplemented"); } void CFEventEngine::Run(EventEngine::Closure* closure) { diff --git a/src/core/lib/event_engine/cf_engine/dns_service_resolver.cc b/src/core/lib/event_engine/cf_engine/dns_service_resolver.cc deleted file mode 100644 index c19f9afe463..00000000000 --- a/src/core/lib/event_engine/cf_engine/dns_service_resolver.cc +++ /dev/null @@ -1,222 +0,0 @@ -// Copyright 2023 The gRPC Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -#ifdef GPR_APPLE - -#include "absl/strings/str_format.h" - -#include "src/core/lib/address_utils/parse_address.h" -#include "src/core/lib/event_engine/cf_engine/dns_service_resolver.h" -#include "src/core/lib/event_engine/posix_engine/lockfree_event.h" -#include "src/core/lib/event_engine/tcp_socket_utils.h" -#include "src/core/lib/event_engine/trace.h" -#include "src/core/lib/gprpp/host_port.h" - -namespace grpc_event_engine { -namespace experimental { - -void DNSServiceResolverImpl::LookupHostname( - EventEngine::DNSResolver::LookupHostnameCallback on_resolve, - absl::string_view name, absl::string_view default_port) { - GRPC_EVENT_ENGINE_DNS_TRACE( - "DNSServiceResolverImpl::LookupHostname: name: %.*s, default_port: %.*s, " - "this: %p", - static_cast(name.length()), name.data(), - static_cast(default_port.length()), default_port.data(), this); - - absl::string_view host; - absl::string_view port_string; - if (!grpc_core::SplitHostPort(name, &host, &port_string)) { - engine_->Run([on_resolve = std::move(on_resolve), - status = absl::InvalidArgumentError( - absl::StrCat("Unparseable name: ", name))]() mutable { - on_resolve(status); - }); - return; - } - GPR_ASSERT(!host.empty()); - if (port_string.empty()) { - if (default_port.empty()) { - engine_->Run([on_resolve = std::move(on_resolve), - status = absl::InvalidArgumentError(absl::StrFormat( - "No port in name %s or default_port argument", - name))]() mutable { on_resolve(std::move(status)); }); - return; - } - port_string = default_port; - } - - int port = 0; - if (port_string == "http") { - port = 80; - } else if (port_string == "https") { - port = 443; - } else if (!absl::SimpleAtoi(port_string, &port)) { - engine_->Run([on_resolve = std::move(on_resolve), - status = absl::InvalidArgumentError(absl::StrCat( - "Failed to parse port in name: ", name))]() mutable { - on_resolve(std::move(status)); - }); - return; - } - - // TODO(yijiem): Change this when refactoring code in - // src/core/lib/address_utils to use EventEngine::ResolvedAddress. - grpc_resolved_address addr; - const std::string hostport = grpc_core::JoinHostPort(host, port); - if (grpc_parse_ipv4_hostport(hostport.c_str(), &addr, - /*log_errors=*/false) || - grpc_parse_ipv6_hostport(hostport.c_str(), &addr, - /*log_errors=*/false)) { - // Early out if the target is an ipv4 or ipv6 literal. - std::vector result; - result.emplace_back(reinterpret_cast(addr.addr), addr.len); - engine_->Run([on_resolve = std::move(on_resolve), - result = std::move(result)]() mutable { - on_resolve(std::move(result)); - }); - return; - } - - DNSServiceRef sdRef; - auto host_string = std::string{host}; - auto error = DNSServiceGetAddrInfo( - &sdRef, kDNSServiceFlagsTimeout | kDNSServiceFlagsReturnIntermediates, 0, - kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6, host_string.c_str(), - &DNSServiceResolverImpl::ResolveCallback, this /* do not Ref */); - - if (error != kDNSServiceErr_NoError) { - engine_->Run([on_resolve = std::move(on_resolve), - status = absl::UnknownError(absl::StrFormat( - "DNSServiceGetAddrInfo failed with error:%d", - error))]() mutable { on_resolve(std::move(status)); }); - return; - } - - grpc_core::ReleasableMutexLock lock(&request_mu_); - - error = DNSServiceSetDispatchQueue(sdRef, queue_); - if (error != kDNSServiceErr_NoError) { - engine_->Run([on_resolve = std::move(on_resolve), - status = absl::UnknownError(absl::StrFormat( - "DNSServiceSetDispatchQueue failed with error:%d", - error))]() mutable { on_resolve(std::move(status)); }); - return; - } - - requests_.try_emplace( - sdRef, DNSServiceRequest{ - std::move(on_resolve), static_cast(port), {}}); -} - -/* static */ -void DNSServiceResolverImpl::ResolveCallback( - DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, - DNSServiceErrorType errorCode, const char* hostname, - const struct sockaddr* address, uint32_t ttl, void* context) { - GRPC_EVENT_ENGINE_DNS_TRACE( - "DNSServiceResolverImpl::ResolveCallback: sdRef: %p, flags: %x, " - "interface: %d, errorCode: %d, hostname: %s, addressFamily: %d, ttl: " - "%d, " - "this: %p", - sdRef, flags, interfaceIndex, errorCode, hostname, address->sa_family, - ttl, context); - - // no need to increase refcount here, since ResolveCallback and Shutdown is - // called from the serial queue and it is guarenteed that it won't be called - // after the sdRef is deallocated - auto that = static_cast(context); - - grpc_core::ReleasableMutexLock lock(&that->request_mu_); - auto request_it = that->requests_.find(sdRef); - GPR_ASSERT(request_it != that->requests_.end()); - auto& request = request_it->second; - - if (errorCode != kDNSServiceErr_NoError && - errorCode != kDNSServiceErr_NoSuchRecord) { - request.on_resolve(absl::UnknownError(absl::StrFormat( - "address lookup failed for %s: errorCode: %d", hostname, errorCode))); - that->requests_.erase(request_it); - DNSServiceRefDeallocate(sdRef); - return; - } - - // set received ipv4 or ipv6 response, even for kDNSServiceErr_NoSuchRecord - if (address->sa_family == AF_INET) { - request.has_ipv4_response = true; - } else if (address->sa_family == AF_INET6) { - request.has_ipv6_response = true; - } - - // collect results if there is no error (not kDNSServiceErr_NoSuchRecord) - if (errorCode == kDNSServiceErr_NoError) { - request.result.emplace_back(address, address->sa_len); - auto& resolved_address = request.result.back(); - if (address->sa_family == AF_INET) { - (const_cast( - reinterpret_cast(resolved_address.address()))) - ->sin_port = htons(request.port); - } else if (address->sa_family == AF_INET6) { - (const_cast( - reinterpret_cast(resolved_address.address()))) - ->sin6_port = htons(request.port); - } - - GRPC_EVENT_ENGINE_DNS_TRACE( - "DNSServiceResolverImpl::ResolveCallback: " - "sdRef: %p, hostname: %s, addressPort: %s, this: %p", - sdRef, hostname, - ResolvedAddressToString(resolved_address).value_or("ERROR").c_str(), - context); - } - - if (!(flags & kDNSServiceFlagsMoreComing) && request.has_ipv4_response && - request.has_ipv6_response) { - if (request.result.empty()) { - request.on_resolve(absl::NotFoundError(absl::StrFormat( - "address lookup failed for %s: Domain name not found", hostname))); - } else { - request.on_resolve(std::move(request.result)); - } - that->requests_.erase(request_it); - DNSServiceRefDeallocate(sdRef); - } -} - -void DNSServiceResolverImpl::Shutdown() { - dispatch_async_f(queue_, Ref().release(), [](void* thatPtr) { - grpc_core::RefCountedPtr that{ - static_cast(thatPtr)}; - grpc_core::MutexLock lock(&that->request_mu_); - for (auto& kv : that->requests_) { - auto& sdRef = kv.first; - auto& request = kv.second; - GRPC_EVENT_ENGINE_DNS_TRACE( - "DNSServiceResolverImpl::Shutdown sdRef: %p, this: %p", sdRef, - thatPtr); - - request.on_resolve( - absl::CancelledError("DNSServiceResolverImpl::Shutdown")); - DNSServiceRefDeallocate(static_cast(sdRef)); - } - that->requests_.clear(); - }); -} - -} // namespace experimental -} // namespace grpc_event_engine - -#endif // GPR_APPLE diff --git a/src/core/lib/event_engine/cf_engine/dns_service_resolver.h b/src/core/lib/event_engine/cf_engine/dns_service_resolver.h deleted file mode 100644 index 00a55a30500..00000000000 --- a/src/core/lib/event_engine/cf_engine/dns_service_resolver.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2023 The gRPC Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#ifndef GRPC_SRC_CORE_LIB_EVENT_ENGINE_CF_ENGINE_DNS_SERVICE_RESOLVER_H -#define GRPC_SRC_CORE_LIB_EVENT_ENGINE_CF_ENGINE_DNS_SERVICE_RESOLVER_H -#include - -#ifdef GPR_APPLE - -#include -#include - -#include "absl/container/flat_hash_map.h" - -#include - -#include "src/core/lib/event_engine/cf_engine/cf_engine.h" -#include "src/core/lib/gprpp/ref_counted.h" -#include "src/core/lib/gprpp/ref_counted_ptr.h" - -namespace grpc_event_engine { -namespace experimental { - -class DNSServiceResolverImpl - : public grpc_core::RefCounted { - struct DNSServiceRequest { - EventEngine::DNSResolver::LookupHostnameCallback on_resolve; - uint16_t port; - std::vector result; - bool has_ipv4_response = false; - bool has_ipv6_response = false; - }; - - public: - explicit DNSServiceResolverImpl(std::shared_ptr engine) - : engine_(std::move((engine))) {} - ~DNSServiceResolverImpl() override { - GPR_ASSERT(requests_.empty()); - dispatch_release(queue_); - } - - void Shutdown(); - - void LookupHostname( - EventEngine::DNSResolver::LookupHostnameCallback on_resolve, - absl::string_view name, absl::string_view default_port); - - private: - static void ResolveCallback(DNSServiceRef sdRef, DNSServiceFlags flags, - uint32_t interfaceIndex, - DNSServiceErrorType errorCode, - const char* hostname, - const struct sockaddr* address, uint32_t ttl, - void* context); - - private: - std::shared_ptr engine_; - // DNSServiceSetDispatchQueue requires a serial dispatch queue - dispatch_queue_t queue_ = - dispatch_queue_create("dns_service_resolver", nullptr); - grpc_core::Mutex request_mu_; - absl::flat_hash_map requests_ - ABSL_GUARDED_BY(request_mu_); -}; - -class DNSServiceResolver : public EventEngine::DNSResolver { - public: - explicit DNSServiceResolver(std::shared_ptr engine) - : engine_(std::move(engine)), - impl_(grpc_core::MakeRefCounted( - std::move((engine_)))) {} - - ~DNSServiceResolver() override { impl_->Shutdown(); } - - void LookupHostname( - EventEngine::DNSResolver::LookupHostnameCallback on_resolve, - absl::string_view name, absl::string_view default_port) override { - impl_->LookupHostname(std::move(on_resolve), name, default_port); - }; - - void LookupSRV(EventEngine::DNSResolver::LookupSRVCallback on_resolve, - absl::string_view /* name */) override { - engine_->Run([on_resolve = std::move(on_resolve)]() mutable { - on_resolve(absl::UnimplementedError( - "The DNS Service resolver does not support looking up SRV records")); - }); - } - - void LookupTXT(EventEngine::DNSResolver::LookupTXTCallback on_resolve, - absl::string_view /* name */) override { - engine_->Run([on_resolve = std::move(on_resolve)]() mutable { - on_resolve(absl::UnimplementedError( - "The DNS Service resolver does not support looking up TXT records")); - }); - } - - private: - std::shared_ptr engine_; - grpc_core::RefCountedPtr impl_; -}; - -} // namespace experimental -} // namespace grpc_event_engine - -#endif // GPR_APPLE - -#endif // GRPC_SRC_CORE_LIB_EVENT_ENGINE_CF_ENGINE_DNS_SERVICE_RESOLVER_H diff --git a/src/objective-c/tests/BUILD b/src/objective-c/tests/BUILD index bfbe19b773e..9eef39eaba6 100644 --- a/src/objective-c/tests/BUILD +++ b/src/objective-c/tests/BUILD @@ -341,7 +341,6 @@ grpc_objc_testing_library( "//src/core:cf_event_engine", "//test/core/event_engine/test_suite/posix:oracle_event_engine_posix", "//test/core/event_engine/test_suite/tests:client", - "//test/core/event_engine/test_suite/tests:dns", "//test/core/event_engine/test_suite/tests:timer", ], ) diff --git a/src/objective-c/tests/EventEngineTests/CFEventEngineTests.mm b/src/objective-c/tests/EventEngineTests/CFEventEngineTests.mm index 98859183246..2f32a409314 100644 --- a/src/objective-c/tests/EventEngineTests/CFEventEngineTests.mm +++ b/src/objective-c/tests/EventEngineTests/CFEventEngineTests.mm @@ -24,7 +24,6 @@ #include "test/core/event_engine/test_suite/event_engine_test_framework.h" #include "test/core/event_engine/test_suite/posix/oracle_event_engine_posix.h" #include "test/core/event_engine/test_suite/tests/client_test.h" -#include "test/core/event_engine/test_suite/tests/dns_test.h" #include "test/core/event_engine/test_suite/tests/timer_test.h" #include "test/core/util/test_config.h" @@ -54,7 +53,6 @@ SetEventEngineFactories(factory, oracle_factory); grpc_event_engine::experimental::InitTimerTests(); grpc_event_engine::experimental::InitClientTests(); - grpc_event_engine::experimental::InitDNSTests(); // TODO(ctiller): EventEngine temporarily needs grpc to be initialized first // until we clear out the iomgr shutdown code. grpc_init(); diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 76fbcce089e..3a03e18ac08 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -496,7 +496,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/event_engine/ares_resolver.cc', 'src/core/lib/event_engine/cf_engine/cf_engine.cc', 'src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc', - 'src/core/lib/event_engine/cf_engine/dns_service_resolver.cc', 'src/core/lib/event_engine/channel_args_endpoint_config.cc', 'src/core/lib/event_engine/default_event_engine.cc', 'src/core/lib/event_engine/default_event_engine_factory.cc', diff --git a/test/core/event_engine/cf/cf_engine_test.cc b/test/core/event_engine/cf/cf_engine_test.cc index ae9e540b359..f50b40f82fa 100644 --- a/test/core/event_engine/cf/cf_engine_test.cc +++ b/test/core/event_engine/cf/cf_engine_test.cc @@ -19,8 +19,6 @@ #include #include "absl/status/status.h" -#include "absl/strings/str_format.h" -#include "gmock/gmock.h" #include "gtest/gtest.h" #include @@ -82,215 +80,6 @@ TEST(CFEventEngineTest, TestConnectionCancelled) { client_signal.WaitForNotification(); } -namespace { -std::vector ResolvedAddressesToStrings( - const std::vector addresses) { - std::vector ip_strings; - std::transform(addresses.cbegin(), addresses.cend(), - std::back_inserter(ip_strings), [](auto const& address) { - return ResolvedAddressToString(address).value_or("ERROR"); - }); - return ip_strings; -} -} // namespace - -TEST(CFEventEngineTest, TestCreateDNSResolver) { - grpc_core::MemoryQuota memory_quota("cf_engine_test"); - auto cf_engine = std::make_shared(); - - EXPECT_TRUE(cf_engine->GetDNSResolver({}).status().ok()); - EXPECT_TRUE(cf_engine->GetDNSResolver({.dns_server = ""}).status().ok()); - EXPECT_EQ( - cf_engine->GetDNSResolver({.dns_server = "8.8.8.8"}).status().code(), - absl::StatusCode::kInvalidArgument); - EXPECT_EQ( - cf_engine->GetDNSResolver({.dns_server = "8.8.8.8:53"}).status().code(), - absl::StatusCode::kInvalidArgument); - EXPECT_EQ( - cf_engine->GetDNSResolver({.dns_server = "invalid"}).status().code(), - absl::StatusCode::kInvalidArgument); -} - -TEST(CFEventEngineTest, TestResolveLocalhost) { - grpc_core::Notification resolve_signal; - - auto cf_engine = std::make_shared(); - auto dns_resolver = cf_engine->GetDNSResolver({}); - - dns_resolver.value()->LookupHostname( - [&resolve_signal](auto result) { - EXPECT_TRUE(result.status().ok()); - EXPECT_THAT(ResolvedAddressesToStrings(result.value()), - testing::UnorderedElementsAre("127.0.0.1:80", "[::1]:80")); - - resolve_signal.Notify(); - }, - "localhost", "80"); - - resolve_signal.WaitForNotification(); -} - -TEST(CFEventEngineTest, TestResolveRemote) { - grpc_core::Notification resolve_signal; - - auto cf_engine = std::make_shared(); - auto dns_resolver = cf_engine->GetDNSResolver({}); - - dns_resolver.value()->LookupHostname( - [&resolve_signal](auto result) { - EXPECT_TRUE(result.status().ok()); - EXPECT_THAT(ResolvedAddressesToStrings(result.value()), - testing::UnorderedElementsAre("127.0.0.1:80", "[::1]:80")); - - resolve_signal.Notify(); - }, - "localtest.me:80", "443"); - - resolve_signal.WaitForNotification(); -} - -TEST(CFEventEngineTest, TestResolveIPv4Remote) { - grpc_core::Notification resolve_signal; - - auto cf_engine = std::make_shared(); - auto dns_resolver = cf_engine->GetDNSResolver({}); - - dns_resolver.value()->LookupHostname( - [&resolve_signal](auto result) { - EXPECT_TRUE(result.status().ok()); - EXPECT_THAT(ResolvedAddressesToStrings(result.value()), - testing::IsSubsetOf( - {"1.2.3.4:80", "[64:ff9b::102:304]:80" /*NAT64*/})); - - resolve_signal.Notify(); - }, - "1.2.3.4.nip.io:80", ""); - - resolve_signal.WaitForNotification(); -} - -TEST(CFEventEngineTest, TestResolveIPv6Remote) { - grpc_core::Notification resolve_signal; - - auto cf_engine = std::make_shared(); - auto dns_resolver = cf_engine->GetDNSResolver({}); - - dns_resolver.value()->LookupHostname( - [&resolve_signal](auto result) { - EXPECT_TRUE(result.status().ok()); - EXPECT_THAT( - ResolvedAddressesToStrings(result.value()), - testing::UnorderedElementsAre("[2607:f8b0:400a:801::1002]:80")); - - resolve_signal.Notify(); - }, - "2607-f8b0-400a-801--1002.sslip.io.", "80"); - - resolve_signal.WaitForNotification(); -} - -TEST(CFEventEngineTest, TestResolveIPv4Literal) { - grpc_core::Notification resolve_signal; - - auto cf_engine = std::make_shared(); - auto dns_resolver = cf_engine->GetDNSResolver({}); - - dns_resolver.value()->LookupHostname( - [&resolve_signal](auto result) { - EXPECT_TRUE(result.status().ok()); - EXPECT_THAT(ResolvedAddressesToStrings(result.value()), - testing::UnorderedElementsAre("1.2.3.4:443")); - - resolve_signal.Notify(); - }, - "1.2.3.4", "https"); - - resolve_signal.WaitForNotification(); -} - -TEST(CFEventEngineTest, TestResolveIPv6Literal) { - grpc_core::Notification resolve_signal; - - auto cf_engine = std::make_shared(); - auto dns_resolver = cf_engine->GetDNSResolver({}); - - dns_resolver.value()->LookupHostname( - [&resolve_signal](auto result) { - EXPECT_TRUE(result.status().ok()); - EXPECT_THAT( - ResolvedAddressesToStrings(result.value()), - testing::UnorderedElementsAre("[2607:f8b0:400a:801::1002]:443")); - - resolve_signal.Notify(); - }, - "[2607:f8b0:400a:801::1002]", "443"); - - resolve_signal.WaitForNotification(); -} - -TEST(CFEventEngineTest, TestResolveNoRecord) { - grpc_core::Notification resolve_signal; - auto cf_engine = std::make_shared(); - auto dns_resolver = std::move(cf_engine->GetDNSResolver({})).value(); - - dns_resolver->LookupHostname( - [&resolve_signal](auto result) { - EXPECT_EQ(result.status().code(), absl::StatusCode::kNotFound); - - resolve_signal.Notify(); - }, - "nonexisting-target.dns-test.event-engine.", "443"); - - resolve_signal.WaitForNotification(); -} - -TEST(CFEventEngineTest, TestResolveCanceled) { - grpc_core::Notification resolve_signal; - auto cf_engine = std::make_shared(); - auto dns_resolver = std::move(cf_engine->GetDNSResolver({})).value(); - - dns_resolver->LookupHostname( - [&resolve_signal](auto result) { - // query may have already finished before canceling, only verity the - // code if status is not ok - if (!result.status().ok()) { - EXPECT_EQ(result.status().code(), absl::StatusCode::kCancelled); - } - - resolve_signal.Notify(); - }, - "dont-care-since-wont-be-resolved.localtest.me", "443"); - - dns_resolver.reset(); - resolve_signal.WaitForNotification(); -} - -TEST(CFEventEngineTest, TestResolveMany) { - std::atomic times{10}; - grpc_core::Notification resolve_signal; - auto cf_engine = std::make_shared(); - auto dns_resolver = std::move(cf_engine->GetDNSResolver({})).value(); - - for (int i = times; i >= 1; --i) { - dns_resolver->LookupHostname( - [&resolve_signal, ×, i](auto result) { - EXPECT_TRUE(result.status().ok()); - EXPECT_THAT( - ResolvedAddressesToStrings(result.value()), - testing::IsSubsetOf( - {absl::StrFormat("100.0.0.%d:443", i), - absl::StrFormat("[64:ff9b::6400:%x]:443", i) /*NAT64*/})); - - if (--times == 0) { - resolve_signal.Notify(); - } - }, - absl::StrFormat("100.0.0.%d.nip.io", i), "443"); - } - - resolve_signal.WaitForNotification(); -} - } // namespace experimental } // namespace grpc_event_engine diff --git a/test/core/event_engine/test_suite/BUILD b/test/core/event_engine/test_suite/BUILD index 48eee5e0bf5..cc485a4d9a2 100644 --- a/test/core/event_engine/test_suite/BUILD +++ b/test/core/event_engine/test_suite/BUILD @@ -96,7 +96,6 @@ grpc_cc_test( grpc_cc_test( name = "cf_event_engine_test", srcs = ["cf_event_engine_test.cc"], - copts = ["-DGRPC_IOS_EVENT_ENGINE_CLIENT=1"], tags = [ "no_linux", "no_windows", @@ -106,7 +105,6 @@ grpc_cc_test( "//src/core:cf_event_engine", "//test/core/event_engine/test_suite/posix:oracle_event_engine_posix", "//test/core/event_engine/test_suite/tests:client", - "//test/core/event_engine/test_suite/tests:dns", "//test/core/event_engine/test_suite/tests:timer", ], ) diff --git a/test/core/event_engine/test_suite/cf_event_engine_test.cc b/test/core/event_engine/test_suite/cf_event_engine_test.cc index 78241c45a50..1d222514cb6 100644 --- a/test/core/event_engine/test_suite/cf_event_engine_test.cc +++ b/test/core/event_engine/test_suite/cf_event_engine_test.cc @@ -21,7 +21,6 @@ #include "test/core/event_engine/test_suite/event_engine_test_framework.h" #include "test/core/event_engine/test_suite/posix/oracle_event_engine_posix.h" #include "test/core/event_engine/test_suite/tests/client_test.h" -#include "test/core/event_engine/test_suite/tests/dns_test.h" #include "test/core/event_engine/test_suite/tests/timer_test.h" #include "test/core/util/test_config.h" @@ -38,7 +37,8 @@ int main(int argc, char** argv) { SetEventEngineFactories(factory, oracle_factory); grpc_event_engine::experimental::InitTimerTests(); grpc_event_engine::experimental::InitClientTests(); - grpc_event_engine::experimental::InitDNSTests(); + // TODO(vigneshbabu): remove when the experiment is over + grpc_core::ForceEnableExperiment("event_engine_client", true); // TODO(ctiller): EventEngine temporarily needs grpc to be initialized first // until we clear out the iomgr shutdown code. grpc_init(); diff --git a/test/core/event_engine/test_suite/tests/dns_test.cc b/test/core/event_engine/test_suite/tests/dns_test.cc index 18e6ae5d345..cbd48e26bc7 100644 --- a/test/core/event_engine/test_suite/tests/dns_test.cc +++ b/test/core/event_engine/test_suite/tests/dns_test.cc @@ -194,9 +194,6 @@ class EventEngineDNSTest : public EventEngineTest { EventEngineDNSTest::DNSServer EventEngineDNSTest::dns_server_; -// TODO(hork): implement XFAIL for resolvers that don't support TXT or SRV -#ifndef GRPC_IOS_EVENT_ENGINE_CLIENT - TEST_F(EventEngineDNSTest, QueryNXHostname) { auto dns_resolver = CreateDefaultDNSResolver(); dns_resolver->LookupHostname( @@ -368,7 +365,6 @@ TEST_F(EventEngineDNSTest, TestCancelActiveDNSQuery) { dns_resolver.reset(); dns_resolver_signal_.WaitForNotification(); } -#endif // GRPC_IOS_EVENT_ENGINE_CLIENT #define EXPECT_SUCCESS() \ do { \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 637de7d2295..ab7809664f8 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -2072,8 +2072,6 @@ src/core/lib/event_engine/cf_engine/cf_engine.h \ src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc \ src/core/lib/event_engine/cf_engine/cfstream_endpoint.h \ src/core/lib/event_engine/cf_engine/cftype_unique_ref.h \ -src/core/lib/event_engine/cf_engine/dns_service_resolver.cc \ -src/core/lib/event_engine/cf_engine/dns_service_resolver.h \ src/core/lib/event_engine/channel_args_endpoint_config.cc \ src/core/lib/event_engine/channel_args_endpoint_config.h \ src/core/lib/event_engine/common_closures.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 17607e9339a..d5b0b9258ab 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1850,8 +1850,6 @@ src/core/lib/event_engine/cf_engine/cf_engine.h \ src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc \ src/core/lib/event_engine/cf_engine/cfstream_endpoint.h \ src/core/lib/event_engine/cf_engine/cftype_unique_ref.h \ -src/core/lib/event_engine/cf_engine/dns_service_resolver.cc \ -src/core/lib/event_engine/cf_engine/dns_service_resolver.h \ src/core/lib/event_engine/channel_args_endpoint_config.cc \ src/core/lib/event_engine/channel_args_endpoint_config.h \ src/core/lib/event_engine/common_closures.h \