| 1 |
#ifndef AWS_IO_HOST_RESOLVER_H |
| 2 |
#define AWS_IO_HOST_RESOLVER_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include <aws/common/ref_count.h> |
| 9 |
#include <aws/io/io.h> |
| 10 |
|
| 11 |
AWS_PUSH_SANE_WARNING_LEVEL |
| 12 |
|
| 13 |
struct aws_event_loop_group; |
| 14 |
|
| 15 |
enum aws_address_record_type { |
| 16 |
|
| 17 |
AWS_ADDRESS_RECORD_TYPE_A, |
| 18 |
|
| 19 |
AWS_ADDRESS_RECORD_TYPE_AAAA |
| 20 |
}; |
| 21 |
|
| 22 |
enum aws_get_host_address_flags { |
| 23 |
|
| 24 |
AWS_GET_HOST_ADDRESS_COUNT_RECORD_TYPE_A = 0x00000001, |
| 25 |
|
| 26 |
AWS_GET_HOST_ADDRESS_COUNT_RECORD_TYPE_AAAA = 0x00000002 |
| 27 |
}; |
| 28 |
|
| 29 |
struct aws_string; |
| 30 |
|
| 31 |
struct aws_host_address { |
| 32 |
struct aws_allocator *allocator; |
| 33 |
const struct aws_string *host; |
| 34 |
const struct aws_string *address; |
| 35 |
enum aws_address_record_type record_type; |
| 36 |
uint64_t expiry; |
| 37 |
|
| 38 |
|
| 39 |
size_t use_count; |
| 40 |
|
| 41 |
size_t connection_failure_count; |
| 42 |
|
| 43 |
uint8_t weight; |
| 44 |
}; |
| 45 |
|
| 46 |
struct aws_host_resolver; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
typedef void(aws_on_host_resolved_result_fn)( |
| 54 |
struct aws_host_resolver *resolver, |
| 55 |
const struct aws_string *host_name, |
| 56 |
int err_code, |
| 57 |
const struct aws_array_list *host_addresses, |
| 58 |
void *user_data); |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
typedef int(aws_resolve_host_implementation_fn)( |
| 66 |
struct aws_allocator *allocator, |
| 67 |
const struct aws_string *host_name, |
| 68 |
struct aws_array_list *output_addresses, |
| 69 |
void *user_data); |
| 70 |
|
| 71 |
struct aws_host_resolution_config { |
| 72 |
aws_resolve_host_implementation_fn *impl; |
| 73 |
size_t max_ttl; |
| 74 |
void *impl_data; |
| 75 |
uint64_t resolve_frequency_ns; |
| 76 |
}; |
| 77 |
|
| 78 |
struct aws_host_resolver_purge_host_options { |
| 79 |
|
| 80 |
const struct aws_string *host; |
| 81 |
|
| 82 |
aws_simple_completion_callback *on_host_purge_complete_callback; |
| 83 |
|
| 84 |
void *user_data; |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
struct aws_host_resolver_vtable { |
| 89 |
|
| 90 |
void (*destroy)(struct aws_host_resolver *resolver); |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
int (*resolve_host)( |
| 95 |
struct aws_host_resolver *resolver, |
| 96 |
const struct aws_string *host_name, |
| 97 |
aws_on_host_resolved_result_fn *res, |
| 98 |
const struct aws_host_resolution_config *config, |
| 99 |
void *user_data); |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
int (*record_connection_failure)(struct aws_host_resolver *resolver, const struct aws_host_address *address); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
int (*purge_cache)(struct aws_host_resolver *resolver); |
| 110 |
|
| 111 |
|
| 112 |
int (*purge_cache_with_callback)( |
| 113 |
struct aws_host_resolver *resolver, |
| 114 |
aws_simple_completion_callback *on_purge_cache_complete_callback, |
| 115 |
void *user_data); |
| 116 |
|
| 117 |
|
| 118 |
int (*purge_host_cache)( |
| 119 |
struct aws_host_resolver *resolver, |
| 120 |
const struct aws_host_resolver_purge_host_options *options); |
| 121 |
|
| 122 |
|
| 123 |
size_t (*get_host_address_count)( |
| 124 |
struct aws_host_resolver *resolver, |
| 125 |
const struct aws_string *host_name, |
| 126 |
uint32_t flags); |
| 127 |
}; |
| 128 |
|
| 129 |
struct aws_host_resolver { |
| 130 |
struct aws_allocator *allocator; |
| 131 |
void *impl; |
| 132 |
struct aws_host_resolver_vtable *vtable; |
| 133 |
struct aws_ref_count ref_count; |
| 134 |
struct aws_shutdown_callback_options shutdown_options; |
| 135 |
}; |
| 136 |
|
| 137 |
struct aws_host_resolver_default_options { |
| 138 |
size_t max_entries; |
| 139 |
struct aws_event_loop_group *el_group; |
| 140 |
const struct aws_shutdown_callback_options *shutdown_options; |
| 141 |
aws_io_clock_fn *system_clock_override_fn; |
| 142 |
}; |
| 143 |
|
| 144 |
AWS_EXTERN_C_BEGIN |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
AWS_IO_API int aws_host_address_copy(const struct aws_host_address *from, struct aws_host_address *to); |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
AWS_IO_API void aws_host_address_move(struct aws_host_address *from, struct aws_host_address *to); |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
AWS_IO_API void aws_host_address_clean_up(struct aws_host_address *address); |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
AWS_IO_API int aws_default_dns_resolve( |
| 165 |
struct aws_allocator *allocator, |
| 166 |
const struct aws_string *host_name, |
| 167 |
struct aws_array_list *output_addresses, |
| 168 |
void *user_data); |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
AWS_IO_API struct aws_host_resolver *aws_host_resolver_new_default( |
| 203 |
struct aws_allocator *allocator, |
| 204 |
const struct aws_host_resolver_default_options *options); |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
AWS_IO_API struct aws_host_resolver *aws_host_resolver_acquire(struct aws_host_resolver *resolver); |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
AWS_IO_API void aws_host_resolver_release(struct aws_host_resolver *resolver); |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
AWS_IO_API int aws_host_resolver_resolve_host( |
| 222 |
struct aws_host_resolver *resolver, |
| 223 |
const struct aws_string *host_name, |
| 224 |
aws_on_host_resolved_result_fn *res, |
| 225 |
const struct aws_host_resolution_config *config, |
| 226 |
void *user_data); |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
AWS_IO_API int aws_host_resolver_record_connection_failure( |
| 232 |
struct aws_host_resolver *resolver, |
| 233 |
const struct aws_host_address *address); |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
AWS_IO_API int aws_host_resolver_purge_cache(struct aws_host_resolver *resolver); |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
AWS_IO_API int aws_host_resolver_purge_cache_with_callback( |
| 246 |
struct aws_host_resolver *resolver, |
| 247 |
aws_simple_completion_callback *on_purge_cache_complete_callback, |
| 248 |
void *user_data); |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
AWS_IO_API int aws_host_resolver_purge_host_cache( |
| 254 |
struct aws_host_resolver *resolver, |
| 255 |
const struct aws_host_resolver_purge_host_options *options); |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
AWS_IO_API size_t aws_host_resolver_get_host_address_count( |
| 261 |
struct aws_host_resolver *resolver, |
| 262 |
const struct aws_string *host_name, |
| 263 |
uint32_t flags); |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
AWS_IO_API struct aws_host_resolution_config aws_host_resolver_init_default_resolution_config(void); |
| 271 |
|
| 272 |
AWS_EXTERN_C_END |
| 273 |
AWS_POP_SANE_WARNING_LEVEL |
| 274 |
|
| 275 |
#endif |