Skip to content
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
8 changes: 8 additions & 0 deletions include/aws/mqtt/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ int aws_mqtt_client_connection_set_http_proxy_options(
struct aws_mqtt_client_connection *connection,
struct aws_http_proxy_options *proxy_options);

/**
* Set host resolution ooptions for the connection.
*/
AWS_MQTT_API
int aws_mqtt_client_connection_set_host_resolution_options(
struct aws_mqtt_client_connection *connection,
struct aws_host_resolution_config *host_resolution_config);

/**
* Sets the minimum and maximum reconnect timeouts.
*
Expand Down
1 change: 1 addition & 0 deletions include/aws/mqtt/private/client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ struct aws_mqtt_client_connection {
struct aws_socket_options socket_options;
struct aws_http_proxy_config *http_proxy_config;
struct aws_event_loop *loop;
struct aws_host_resolution_config host_resolution_config;

/* Connect parameters */
struct aws_byte_buf client_id;
Expand Down
3 changes: 3 additions & 0 deletions include/aws/mqtt/private/v5/mqtt5_options_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <aws/common/logging.h>
#include <aws/common/ref_count.h>
#include <aws/http/proxy.h>
#include <aws/io/host_resolver.h>
#include <aws/io/retry_strategy.h>
#include <aws/io/socket.h>
#include <aws/io/tls_channel_handler.h>
Expand Down Expand Up @@ -176,6 +177,8 @@ struct aws_mqtt5_client_options_storage {

aws_mqtt5_client_termination_completion_fn *client_termination_handler;
void *client_termination_handler_user_data;

struct aws_host_resolution_config host_resolution_override;
};

AWS_EXTERN_C_BEGIN
Expand Down
8 changes: 7 additions & 1 deletion include/aws/mqtt/v5/mqtt5_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

struct aws_allocator;
struct aws_client_bootstrap;
struct aws_host_resolution_config;
struct aws_http_message;
struct aws_input_stream;
struct aws_mqtt5_client;
struct aws_mqtt5_client_lifecycle_event;
struct aws_tls_connection_options;
Expand Down Expand Up @@ -655,6 +655,12 @@ struct aws_mqtt5_client_options {
*/
aws_mqtt5_client_termination_completion_fn *client_termination_handler;
void *client_termination_handler_user_data;

/**
* Options to override aspects of DNS resolution. If unspecified, use a default that matches the regular
* configuration but changes the refresh frequency to a value that prevents DNS pinging.
*/
struct aws_host_resolution_config *host_resolution_override;
};

AWS_EXTERN_C_BEGIN
Expand Down
13 changes: 13 additions & 0 deletions source/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,10 @@ struct aws_mqtt_client_connection *aws_mqtt_client_connection_new(struct aws_mqt

connection->loop = aws_event_loop_group_get_next_loop(client->bootstrap->event_loop_group);

connection->host_resolution_config = aws_host_resolver_init_default_resolution_config();
connection->host_resolution_config.resolve_frequency_ns =
aws_timestamp_convert(connection->reconnect_timeouts.max_sec, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_NANOS, NULL);

/* Initialize the handler */
connection->handler.alloc = connection->allocator;
connection->handler.vtable = aws_mqtt_get_client_channel_vtable();
Expand Down Expand Up @@ -1195,6 +1199,15 @@ int aws_mqtt_client_connection_set_http_proxy_options(
return connection->http_proxy_config != NULL ? AWS_OP_SUCCESS : AWS_OP_ERR;
}

int aws_mqtt_client_connection_set_host_resolution_options(
struct aws_mqtt_client_connection *connection,
struct aws_host_resolution_config *host_resolution_config) {

connection->host_resolution_config = *host_resolution_config;

return AWS_OP_SUCCESS;
}

static void s_on_websocket_shutdown(struct aws_websocket *websocket, int error_code, void *user_data) {
struct aws_mqtt_client_connection *connection = user_data;

Expand Down
3 changes: 2 additions & 1 deletion source/v5/mqtt5_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ void s_websocket_transform_complete_task_fn(struct aws_task *task, void *arg, en
.on_connection_setup = s_on_websocket_setup,
.on_connection_shutdown = s_on_websocket_shutdown,
.requested_event_loop = client->loop,
};
.host_resolution_config = &client->config->host_resolution_override};

if (client->config->http_proxy_config != NULL) {
websocket_options.proxy_options = &client->config->http_proxy_options;
Expand Down Expand Up @@ -1055,6 +1055,7 @@ static void s_change_current_state_to_connecting(struct aws_mqtt5_client *client
channel_options.shutdown_callback = &s_mqtt5_client_shutdown;
channel_options.user_data = client;
channel_options.requested_event_loop = client->loop;
channel_options.host_resolution_override_config = &client->config->host_resolution_override;

if (client->config->http_proxy_config == NULL) {
result = (*client->vtable->client_bootstrap_new_socket_channel_fn)(&channel_options);
Expand Down
9 changes: 9 additions & 0 deletions source/v5/mqtt5_options_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -3956,6 +3956,15 @@ struct aws_mqtt5_client_options_storage *aws_mqtt5_client_options_storage_new(

s_apply_zero_valued_defaults_to_client_options_storage(options_storage);

/* must do this after zero-valued defaults are applied so that max reconnect is accurate */
if (options->host_resolution_override) {
options_storage->host_resolution_override = *options->host_resolution_override;
} else {
options_storage->host_resolution_override = aws_host_resolver_init_default_resolution_config();
options_storage->host_resolution_override.resolve_frequency_ns = aws_timestamp_convert(
options_storage->max_reconnect_delay_ms, AWS_TIMESTAMP_MILLIS, AWS_TIMESTAMP_NANOS, NULL);
}

return options_storage;

error:
Expand Down