Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS Ping Proposal #559

Merged
merged 8 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/aws/io/channel_bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ struct aws_socket_channel_bootstrap_options {
bool enable_read_back_pressure;
void *user_data;
struct aws_event_loop *requested_event_loop;
const struct aws_host_resolution_config *host_resolution_override_config;
};

/**
Expand Down
80 changes: 7 additions & 73 deletions include/aws/io/host_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct aws_host_resolution_config {
aws_resolve_host_implementation_fn *impl;
size_t max_ttl;
void *impl_data;
uint64_t resolve_frequency_ns; /* 0 defaults to 1 second interval */
};

struct aws_host_listener;
Expand Down Expand Up @@ -125,13 +126,6 @@ struct aws_host_resolver_vtable {
struct aws_host_resolver *resolver,
const struct aws_string *host_name,
uint32_t flags);

/** creates and adds a listener to the host resolver. */
struct aws_host_listener *(
*add_host_listener)(struct aws_host_resolver *resolver, const struct aws_host_listener_options *options);

/** removes a host listener from the host resolver and frees it. */
int (*remove_host_listener)(struct aws_host_resolver *resolver, struct aws_host_listener *listener);
};

struct aws_host_resolver {
Expand Down Expand Up @@ -270,72 +264,12 @@ AWS_IO_API size_t aws_host_resolver_get_host_address_count(
const struct aws_string *host_name,
uint32_t flags);

/* Callback for receiving new host addresses from a listener. Memory for the new address list is only guaranteed to
* exist during the callback, and must be copied if the caller needs it to persist after. */
typedef void(aws_host_listener_resolved_address_fn)(
/* Listener that owns this callback. */
struct aws_host_listener *listener,

/* Array list of aws_host_address structures. To get an item:
*
* struct aws_host_address *host_address = NULL;
* aws_array_list_get_at_ptr(new_address_list, (void **)&host_address, address_index);
* */
const struct aws_array_list *new_address_list,

/* User data that was specified when adding the listener. */
void *user_data);

/* Callback for learning of an expired address from a listener. Memory for the expired address list is only guaranteed
* to exist during the callback, and must be copied if the caller needs it to persist after. */
typedef void(aws_host_listener_expired_address_fn)(
/* Listener that owns this callback. */
struct aws_host_listener *listener,

/* Array list of aws_host_address structures. To get an item:
*
* struct aws_host_address *host_address = NULL;
* aws_array_list_get_at_ptr(new_address_list, (void **)&host_address, address_index);
* */
const struct aws_array_list *expired_address_list,

/* User data that was specified when adding the listener. */
void *user_data);

/* Callback for when the listener has completed its clean up. */
typedef void(aws_host_listener_shutdown_fn)(void *user_data);

struct aws_host_listener_options {

/* Name of the host to listen for notifications from. */
struct aws_byte_cursor host_name;

/* Callback for when an address is resolved for the specified host. */
aws_host_listener_resolved_address_fn *resolved_address_callback;

/* Callback for when a resolved address expires for the specified host. */
aws_host_listener_expired_address_fn *expired_address_callback;

/* Callback for when a listener has completely shutdown. */
aws_host_listener_shutdown_fn *shutdown_callback;

/* User data to be passed into each callback. */
void *user_data;

/* Lets the resolver know to keep the resolution thread alive for as long as this listener is attached */
bool pin_host_entry;
};

/* Create and add a listener to the host resolver using the specified options. */
AWS_IO_API struct aws_host_listener *aws_host_resolver_add_host_listener(
struct aws_host_resolver *resolver,
const struct aws_host_listener_options *options);

/* Remove the specified listener from the host resolver, triggering clean up of the listener. Note: this may not happen
* synchronously, and it is necessary to wait for the listener's shutdown callback to trigger. */
AWS_IO_API int aws_host_resolver_remove_host_listener(
struct aws_host_resolver *resolver,
struct aws_host_listener *listener);
/**
* Returns the default host resolution config used internally if none specified.
*
* @return default host resolution config
*/
AWS_IO_API struct aws_host_resolution_config aws_host_resolver_init_default_resolution_config(void);

AWS_EXTERN_C_END

Expand Down
15 changes: 7 additions & 8 deletions source/channel_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
# pragma warning(disable : 4221)
#endif

#define DEFAULT_DNS_TTL 30

static void s_client_bootstrap_destroy_impl(struct aws_client_bootstrap *bootstrap) {
AWS_ASSERT(bootstrap);
AWS_LOGF_DEBUG(AWS_LS_IO_CHANNEL_BOOTSTRAP, "id=%p: bootstrap destroying", (void *)bootstrap);
Expand Down Expand Up @@ -85,11 +83,7 @@ struct aws_client_bootstrap *aws_client_bootstrap_new(
if (options->host_resolution_config) {
bootstrap->host_resolver_config = *options->host_resolution_config;
} else {
bootstrap->host_resolver_config = (struct aws_host_resolution_config){
.impl = aws_default_dns_resolve,
.max_ttl = DEFAULT_DNS_TTL,
.impl_data = NULL,
};
bootstrap->host_resolver_config = aws_host_resolver_init_default_resolution_config();
}

return bootstrap;
Expand Down Expand Up @@ -829,11 +823,16 @@ int aws_client_bootstrap_new_socket_channel(struct aws_socket_channel_bootstrap_
goto error;
}

const struct aws_host_resolution_config *host_resolution_config = &bootstrap->host_resolver_config;
if (options->host_resolution_override_config) {
host_resolution_config = options->host_resolution_override_config;
}

if (aws_host_resolver_resolve_host(
bootstrap->host_resolver,
client_connection_args->host_name,
s_on_host_resolved,
&bootstrap->host_resolver_config,
host_resolution_config,
client_connection_args)) {
goto error;
}
Expand Down
Loading