std::string name_to_resolve_;
/// channel args
grpc_channel_args* channel_args_;
- /// whether to request the service config
- bool request_service_config_;
+ std::shared_ptr<WorkSerializer> work_serializer_;
+ std::unique_ptr<ResultHandler> result_handler_;
/// pollset_set to drive the name resolution process
grpc_pollset_set* interested_parties_;
+
+ /// whether to request the service config
+ bool request_service_config_;
+ // whether or not to enable SRV DNS queries
+ bool enable_srv_queries_;
+ // timeout in milliseconds for active DNS queries
+ int query_timeout_ms_;
+ /// min interval between DNS requests
+ grpc_millis min_time_between_resolutions_;
+
/// closures used by the work_serializer
grpc_closure on_next_resolution_;
grpc_closure on_resolved_;
/// next resolution timer
bool have_next_resolution_timer_ = false;
grpc_timer next_resolution_timer_;
- /// min interval between DNS requests
- grpc_millis min_time_between_resolutions_;
/// timestamp of last DNS request
grpc_millis last_resolution_timestamp_ = -1;
/// retry backoff state
char* service_config_json_ = nullptr;
// has shutdown been initiated
bool shutdown_initiated_ = false;
- // timeout in milliseconds for active DNS queries
- int query_timeout_ms_;
- // whether or not to enable SRV DNS queries
- bool enable_srv_queries_;
};
AresDnsResolver::AresDnsResolver(ResolverArgs args)
- : Resolver(std::move(args.work_serializer), std::move(args.result_handler)),
+ : dns_server_(args.uri.authority()),
+ name_to_resolve_(absl::StripPrefix(args.uri.path(), "/")),
+ channel_args_(grpc_channel_args_copy(args.args)),
+ work_serializer_(std::move(args.work_serializer)),
+ result_handler_(std::move(args.result_handler)),
+ interested_parties_(args.pollset_set),
+ request_service_config_(!grpc_channel_args_find_bool(
+ channel_args_, GRPC_ARG_SERVICE_CONFIG_DISABLE_RESOLUTION, true)),
+ enable_srv_queries_(grpc_channel_args_find_bool(
+ channel_args_, GRPC_ARG_DNS_ENABLE_SRV_QUERIES, false)),
+ query_timeout_ms_(grpc_channel_args_find_integer(
+ channel_args_, GRPC_ARG_DNS_ARES_QUERY_TIMEOUT_MS,
+ {GRPC_DNS_ARES_DEFAULT_QUERY_TIMEOUT_MS, 0, INT_MAX})),
+ min_time_between_resolutions_(grpc_channel_args_find_integer(
+ channel_args_, GRPC_ARG_DNS_MIN_TIME_BETWEEN_RESOLUTIONS_MS,
+ {1000 * 30, 0, INT_MAX})),
backoff_(
BackOff::Options()
.set_initial_backoff(GRPC_DNS_INITIAL_CONNECT_BACKOFF_SECONDS *
.set_multiplier(GRPC_DNS_RECONNECT_BACKOFF_MULTIPLIER)
.set_jitter(GRPC_DNS_RECONNECT_JITTER)
.set_max_backoff(GRPC_DNS_RECONNECT_MAX_BACKOFF_SECONDS * 1000)) {
- // Closure Initialization
+ // Closure initialization.
GRPC_CLOSURE_INIT(&on_next_resolution_, OnNextResolution, this,
grpc_schedule_on_exec_ctx);
GRPC_CLOSURE_INIT(&on_resolved_, OnResolved, this, grpc_schedule_on_exec_ctx);
- // Get name to resolve from URI path.
- name_to_resolve_ = std::string(absl::StripPrefix(args.uri.path(), "/"));
- // Get DNS server from URI authority.
- dns_server_ = args.uri.authority();
- channel_args_ = grpc_channel_args_copy(args.args);
- // Disable service config option
- const grpc_arg* arg = grpc_channel_args_find(
- channel_args_, GRPC_ARG_SERVICE_CONFIG_DISABLE_RESOLUTION);
- request_service_config_ = !grpc_channel_arg_get_bool(arg, true);
- // Min time b/t resolutions option
- arg = grpc_channel_args_find(channel_args_,
- GRPC_ARG_DNS_MIN_TIME_BETWEEN_RESOLUTIONS_MS);
- min_time_between_resolutions_ =
- grpc_channel_arg_get_integer(arg, {1000 * 30, 0, INT_MAX});
- // Enable SRV queries option
- arg = grpc_channel_args_find(channel_args_, GRPC_ARG_DNS_ENABLE_SRV_QUERIES);
- enable_srv_queries_ = grpc_channel_arg_get_bool(arg, false);
- interested_parties_ = grpc_pollset_set_create();
- if (args.pollset_set != nullptr) {
- grpc_pollset_set_add_pollset_set(interested_parties_, args.pollset_set);
- }
-
- const grpc_arg* query_timeout_ms_arg =
- grpc_channel_args_find(channel_args_, GRPC_ARG_DNS_ARES_QUERY_TIMEOUT_MS);
- query_timeout_ms_ = grpc_channel_arg_get_integer(
- query_timeout_ms_arg,
- {GRPC_DNS_ARES_DEFAULT_QUERY_TIMEOUT_MS, 0, INT_MAX});
}
AresDnsResolver::~AresDnsResolver() {
GRPC_CARES_TRACE_LOG("resolver:%p destroying AresDnsResolver", this);
- grpc_pollset_set_destroy(interested_parties_);
grpc_channel_args_destroy(channel_args_);
}
void AresDnsResolver::OnNextResolution(void* arg, grpc_error* error) {
AresDnsResolver* r = static_cast<AresDnsResolver*>(arg);
GRPC_ERROR_REF(error); // ref owned by lambda
- r->work_serializer()->Run([r, error]() { r->OnNextResolutionLocked(error); },
- DEBUG_LOCATION);
+ r->work_serializer_->Run([r, error]() { r->OnNextResolutionLocked(error); },
+ DEBUG_LOCATION);
}
void AresDnsResolver::OnNextResolutionLocked(grpc_error* error) {
void AresDnsResolver::OnResolved(void* arg, grpc_error* error) {
AresDnsResolver* r = static_cast<AresDnsResolver*>(arg);
GRPC_ERROR_REF(error); // ref owned by lambda
- r->work_serializer()->Run([r, error]() { r->OnResolvedLocked(error); },
- DEBUG_LOCATION);
+ r->work_serializer_->Run([r, error]() { r->OnResolvedLocked(error); },
+ DEBUG_LOCATION);
}
void AresDnsResolver::OnResolvedLocked(grpc_error* error) {
}
result.args = grpc_channel_args_copy_and_add(channel_args_, new_args.data(),
new_args.size());
- result_handler()->ReturnResult(std::move(result));
+ result_handler_->ReturnResult(std::move(result));
addresses_.reset();
balancer_addresses_.reset();
// Reset backoff state so that we start from the beginning when the
grpc_error_string(error));
std::string error_message =
absl::StrCat("DNS resolution failed for service: ", name_to_resolve_);
- result_handler()->ReturnError(grpc_error_set_int(
+ result_handler_->ReturnError(grpc_error_set_int(
GRPC_ERROR_CREATE_REFERENCING_FROM_COPIED_STRING(error_message.c_str(),
&error, 1),
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE));
interested_parties_, &on_resolved_, &addresses_,
enable_srv_queries_ ? &balancer_addresses_ : nullptr,
request_service_config_ ? &service_config_json_ : nullptr,
- query_timeout_ms_, work_serializer());
+ query_timeout_ms_, work_serializer_);
last_resolution_timestamp_ = grpc_core::ExecCtx::Get()->Now();
GRPC_CARES_TRACE_LOG("resolver:%p Started resolving. pending_request_:%p",
this, pending_request_);