Skip to content

Commit

Permalink
Merge pull request #1 from opencurve/patch-0809
Browse files Browse the repository at this point in the history
parse override endpoint to support ip and custom port, skip dns resolve logic
  • Loading branch information
h0hmj authored Aug 9, 2022
2 parents d4f3ff0 + f2afe60 commit 16cc17d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 22 deletions.
38 changes: 37 additions & 1 deletion source/s3_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <aws/s3/private/s3_copy_object.h>
#include <inttypes.h>
#include <math.h>
#include <errno.h>

#if _MSC_VER
# pragma warning(disable : 4232) /* function pointer to dll symbol */
Expand Down Expand Up @@ -676,8 +677,43 @@ struct aws_s3_meta_request *aws_s3_client_make_meta_request(
}

if (was_created) {
// try to support "ip:port", "ip", "hostname:port", "hostname" format
struct aws_array_list raw_endpoint_split;
AWS_ZERO_STRUCT(raw_endpoint_split);
struct aws_byte_cursor raw_endpoint = aws_byte_cursor_from_string(endpoint_host_name);
if (aws_array_list_init_dynamic(
&raw_endpoint_split, client->allocator, 2, sizeof(struct aws_byte_cursor))) {
error_occurred = true;
goto unlock;
}
if (aws_byte_cursor_split_on_char(&raw_endpoint, ':', &raw_endpoint_split)) {
error_occurred = true;
goto unlock;
}
struct aws_byte_cursor raw_host_name;
AWS_ZERO_STRUCT(raw_host_name);
if (aws_array_list_get_at(&raw_endpoint_split, &raw_host_name, 0)) {
error_occurred = true;
goto unlock;
}
struct aws_byte_cursor raw_port;
if (aws_array_list_length(&raw_endpoint_split) == 2) {
// seems we have port?
AWS_ZERO_STRUCT(raw_port);
if (aws_array_list_get_at(&raw_endpoint_split, &raw_port, 1)) {
error_occurred = true;
goto unlock;
}
errno = 0;
port = (uint16_t)strtoul((const char *)(raw_port.ptr), NULL, 0);
if (errno != 0) {
error_occurred = true;
goto unlock;
}
}

struct aws_s3_endpoint_options endpoint_options = {
.host_name = endpoint_host_name,
.host_name = aws_string_new_from_cursor(client->allocator, &raw_host_name),
.shutdown_callback = client->vtable->endpoint_shutdown_callback,
.client_bootstrap = client->client_bootstrap,
.tls_connection_options = is_https ? client->tls_connection_options : NULL,
Expand Down
44 changes: 23 additions & 21 deletions source/s3_endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,29 @@ struct aws_s3_endpoint *aws_s3_endpoint_new(
endpoint->allocator = allocator;
endpoint->host_name = options->host_name;

struct aws_host_resolution_config host_resolver_config;
AWS_ZERO_STRUCT(host_resolver_config);
host_resolver_config.impl = aws_default_dns_resolve;
host_resolver_config.max_ttl = options->dns_host_address_ttl_seconds;
host_resolver_config.impl_data = NULL;

if (aws_host_resolver_resolve_host(
options->client_bootstrap->host_resolver,
endpoint->host_name,
s_s3_endpoint_on_host_resolver_address_resolved,
&host_resolver_config,
NULL)) {

AWS_LOGF_ERROR(
AWS_LS_S3_ENDPOINT,
"id=%p: Error trying to resolve host for endpoint %s",
(void *)endpoint,
(const char *)endpoint->host_name->bytes);

goto error_cleanup;
}
/* skip dns resolution related logic
struct aws_host_resolution_config host_resolver_config;
AWS_ZERO_STRUCT(host_resolver_config);
host_resolver_config.impl = aws_default_dns_resolve;
host_resolver_config.max_ttl = options->dns_host_address_ttl_seconds;
host_resolver_config.impl_data = NULL;
if (aws_host_resolver_resolve_host(
options->client_bootstrap->host_resolver,
endpoint->host_name,
s_s3_endpoint_on_host_resolver_address_resolved,
&host_resolver_config,
NULL)) {
AWS_LOGF_ERROR(
AWS_LS_S3_ENDPOINT,
"id=%p: Error trying to resolve host for endpoint %s",
(void *)endpoint,
(const char *)endpoint->host_name->bytes);
goto error_cleanup;
}
*/

endpoint->http_connection_manager = s_s3_endpoint_create_http_connection_manager(
endpoint,
Expand Down

0 comments on commit 16cc17d

Please sign in to comment.