Revert "[ObjC] dns service resolver for cf event engine" (#33964)

Reverts grpc/grpc#33233. This is failing 100% of builds
https://source.cloud.google.com/results/invocations/248656d3-15ac-4d42-a2f8-6bec5c411e67/targets
pull/33966/head
AJ Heller 1 year ago committed by GitHub
parent 91e7f223d3
commit 48f455a9a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      CMakeLists.txt
  2. 2
      Makefile
  3. 2
      Package.swift
  4. 16
      build_autogenerated.yaml
  5. 1
      config.m4
  6. 1
      config.w32
  7. 2
      gRPC-C++.podspec
  8. 3
      gRPC-Core.podspec
  9. 2
      grpc.gemspec
  10. 3
      grpc.gyp
  11. 2
      package.xml
  12. 8
      src/core/BUILD
  13. 12
      src/core/lib/event_engine/cf_engine/cf_engine.cc
  14. 222
      src/core/lib/event_engine/cf_engine/dns_service_resolver.cc
  15. 117
      src/core/lib/event_engine/cf_engine/dns_service_resolver.h
  16. 1
      src/objective-c/tests/BUILD
  17. 2
      src/objective-c/tests/EventEngineTests/CFEventEngineTests.mm
  18. 1
      src/python/grpcio/grpc_core_dependencies.py
  19. 211
      test/core/event_engine/cf/cf_engine_test.cc
  20. 2
      test/core/event_engine/test_suite/BUILD
  21. 4
      test/core/event_engine/test_suite/cf_event_engine_test.cc
  22. 4
      test/core/event_engine/test_suite/tests/dns_test.cc
  23. 2
      tools/doxygen/Doxyfile.c++.internal
  24. 2
      tools/doxygen/Doxyfile.core.internal

9
CMakeLists.txt generated

@ -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

2
Makefile generated

@ -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 \

2
Package.swift generated

@ -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",

@ -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

1
config.m4 generated

@ -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 \

1
config.w32 generated

@ -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 " +

2
gRPC-C++.podspec generated

@ -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',

3
gRPC-Core.podspec generated

@ -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',

2
grpc.gemspec generated

@ -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 )

3
grpc.gyp generated

@ -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',

2
package.xml generated

@ -1057,8 +1057,6 @@
<file baseinstalldir="/" name="src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/event_engine/cf_engine/cfstream_endpoint.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/event_engine/cf_engine/cftype_unique_ref.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/event_engine/cf_engine/dns_service_resolver.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/event_engine/cf_engine/dns_service_resolver.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/event_engine/channel_args_endpoint_config.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/event_engine/channel_args_endpoint_config.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/event_engine/common_closures.h" role="src" />

@ -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",
],

@ -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<std::unique_ptr<EventEngine::DNSResolver>>
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<DNSServiceResolver>(
std::static_pointer_cast<CFEventEngine>(shared_from_this()));
CFEventEngine::GetDNSResolver(
const DNSResolver::ResolverOptions& /* options */) {
grpc_core::Crash("unimplemented");
}
void CFEventEngine::Run(EventEngine::Closure* closure) {

@ -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 <grpc/support/port_platform.h>
#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<int>(name.length()), name.data(),
static_cast<int>(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<EventEngine::ResolvedAddress> result;
result.emplace_back(reinterpret_cast<sockaddr*>(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<uint16_t>(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<DNSServiceResolverImpl*>(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<sockaddr_in*>(
reinterpret_cast<const sockaddr_in*>(resolved_address.address())))
->sin_port = htons(request.port);
} else if (address->sa_family == AF_INET6) {
(const_cast<sockaddr_in6*>(
reinterpret_cast<const sockaddr_in6*>(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<DNSServiceResolverImpl> that{
static_cast<DNSServiceResolverImpl*>(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<DNSServiceRef>(sdRef));
}
that->requests_.clear();
});
}
} // namespace experimental
} // namespace grpc_event_engine
#endif // GPR_APPLE

@ -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 <grpc/support/port_platform.h>
#ifdef GPR_APPLE
#include <CoreFoundation/CoreFoundation.h>
#include <dns_sd.h>
#include "absl/container/flat_hash_map.h"
#include <grpc/event_engine/event_engine.h>
#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<DNSServiceResolverImpl> {
struct DNSServiceRequest {
EventEngine::DNSResolver::LookupHostnameCallback on_resolve;
uint16_t port;
std::vector<EventEngine::ResolvedAddress> result;
bool has_ipv4_response = false;
bool has_ipv6_response = false;
};
public:
explicit DNSServiceResolverImpl(std::shared_ptr<CFEventEngine> 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<CFEventEngine> 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<DNSServiceRef, DNSServiceRequest> requests_
ABSL_GUARDED_BY(request_mu_);
};
class DNSServiceResolver : public EventEngine::DNSResolver {
public:
explicit DNSServiceResolver(std::shared_ptr<CFEventEngine> engine)
: engine_(std::move(engine)),
impl_(grpc_core::MakeRefCounted<DNSServiceResolverImpl>(
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<CFEventEngine> engine_;
grpc_core::RefCountedPtr<DNSServiceResolverImpl> impl_;
};
} // namespace experimental
} // namespace grpc_event_engine
#endif // GPR_APPLE
#endif // GRPC_SRC_CORE_LIB_EVENT_ENGINE_CF_ENGINE_DNS_SERVICE_RESOLVER_H

@ -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",
],
)

@ -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();

@ -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',

@ -19,8 +19,6 @@
#include <thread>
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <grpc/event_engine/event_engine.h>
@ -82,215 +80,6 @@ TEST(CFEventEngineTest, TestConnectionCancelled) {
client_signal.WaitForNotification();
}
namespace {
std::vector<std::string> ResolvedAddressesToStrings(
const std::vector<EventEngine::ResolvedAddress> addresses) {
std::vector<std::string> 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<CFEventEngine>();
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<CFEventEngine>();
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<CFEventEngine>();
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<CFEventEngine>();
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<CFEventEngine>();
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<CFEventEngine>();
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<CFEventEngine>();
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<CFEventEngine>();
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<CFEventEngine>();
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<int> times{10};
grpc_core::Notification resolve_signal;
auto cf_engine = std::make_shared<CFEventEngine>();
auto dns_resolver = std::move(cf_engine->GetDNSResolver({})).value();
for (int i = times; i >= 1; --i) {
dns_resolver->LookupHostname(
[&resolve_signal, &times, 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

@ -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",
],
)

@ -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();

@ -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 { \

@ -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 \

@ -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 \

Loading…
Cancel
Save