#ifndef AWS_IO_HOST_RESOLVER_H
#define AWS_IO_HOST_RESOLVER_H
#include <aws/common/ref_count.h>
#include <aws/io/io.h>
struct aws_event_loop_group;
enum aws_address_record_type {
AWS_ADDRESS_RECORD_TYPE_A,
AWS_ADDRESS_RECORD_TYPE_AAAA
};
enum aws_get_host_address_flags {
AWS_GET_HOST_ADDRESS_COUNT_RECORD_TYPE_A = 0x00000001,
AWS_GET_HOST_ADDRESS_COUNT_RECORD_TYPE_AAAA = 0x00000002
};
struct aws_string;
struct aws_host_address {
struct aws_allocator *allocator;
const struct aws_string *host;
const struct aws_string *address;
enum aws_address_record_type record_type;
uint64_t expiry;
size_t use_count;
size_t connection_failure_count;
uint8_t weight;
};
struct aws_host_resolver;
typedef void(aws_on_host_resolved_result_fn)(
struct aws_host_resolver *resolver,
const struct aws_string *host_name,
int err_code,
const struct aws_array_list *host_addresses,
void *user_data);
typedef int(aws_resolve_host_implementation_fn)(
struct aws_allocator *allocator,
const struct aws_string *host_name,
struct aws_array_list *output_addresses,
void *user_data);
struct aws_host_resolution_config {
aws_resolve_host_implementation_fn *impl;
size_t max_ttl;
void *impl_data;
};
struct aws_host_listener;
struct aws_host_listener_options;
struct aws_host_resolver_vtable {
void (*destroy)(struct aws_host_resolver *resolver);
int (*resolve_host)(
struct aws_host_resolver *resolver,
const struct aws_string *host_name,
aws_on_host_resolved_result_fn *res,
struct aws_host_resolution_config *config,
void *user_data);
int (*record_connection_failure)(struct aws_host_resolver *resolver, struct aws_host_address *address);
int (*purge_cache)(struct aws_host_resolver *resolver);
size_t (*get_host_address_count)(
struct aws_host_resolver *resolver,
const struct aws_string *host_name,
uint32_t flags);
struct aws_host_listener *(
*add_host_listener)(struct aws_host_resolver *resolver, const struct aws_host_listener_options *options);
int (*remove_host_listener)(struct aws_host_resolver *resolver, struct aws_host_listener *listener);
};
struct aws_host_resolver {
struct aws_allocator *allocator;
void *impl;
struct aws_host_resolver_vtable *vtable;
struct aws_ref_count ref_count;
struct aws_shutdown_callback_options shutdown_options;
};
struct aws_host_resolver_default_options {
size_t max_entries;
struct aws_event_loop_group *el_group;
const struct aws_shutdown_callback_options *shutdown_options;
aws_io_clock_fn *system_clock_override_fn;
};
AWS_EXTERN_C_BEGIN
AWS_IO_API int aws_host_address_copy(const struct aws_host_address *from, struct aws_host_address *to);
AWS_IO_API void aws_host_address_move(struct aws_host_address *from, struct aws_host_address *to);
AWS_IO_API void aws_host_address_clean_up(struct aws_host_address *address);
AWS_IO_API int aws_default_dns_resolve(
struct aws_allocator *allocator,
const struct aws_string *host_name,
struct aws_array_list *output_addresses,
void *user_data);
AWS_IO_API struct aws_host_resolver *aws_host_resolver_new_default(
struct aws_allocator *allocator,
const struct aws_host_resolver_default_options *options);
AWS_IO_API struct aws_host_resolver *aws_host_resolver_acquire(struct aws_host_resolver *resolver);
AWS_IO_API void aws_host_resolver_release(struct aws_host_resolver *resolver);
AWS_IO_API int aws_host_resolver_resolve_host(
struct aws_host_resolver *resolver,
const struct aws_string *host_name,
aws_on_host_resolved_result_fn *res,
struct aws_host_resolution_config *config,
void *user_data);
AWS_IO_API int aws_host_resolver_record_connection_failure(
struct aws_host_resolver *resolver,
struct aws_host_address *address);
AWS_IO_API int aws_host_resolver_purge_cache(struct aws_host_resolver *resolver);
AWS_IO_API size_t aws_host_resolver_get_host_address_count(
struct aws_host_resolver *resolver,
const struct aws_string *host_name,
uint32_t flags);
typedef void(aws_host_listener_resolved_address_fn)(
struct aws_host_listener *listener,
const struct aws_array_list *new_address_list,
void *user_data);
typedef void(aws_host_listener_expired_address_fn)(
struct aws_host_listener *listener,
const struct aws_array_list *expired_address_list,
void *user_data);
typedef void(aws_host_listener_shutdown_fn)(void *user_data);
struct aws_host_listener_options {
struct aws_byte_cursor host_name;
aws_host_listener_resolved_address_fn *resolved_address_callback;
aws_host_listener_expired_address_fn *expired_address_callback;
aws_host_listener_shutdown_fn *shutdown_callback;
void *user_data;
bool pin_host_entry;
};
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);
AWS_IO_API int aws_host_resolver_remove_host_listener(
struct aws_host_resolver *resolver,
struct aws_host_listener *listener);
AWS_EXTERN_C_END
#endif