diff options
author | Mark D. Roth <roth@google.com> | 2016-10-21 10:43:45 -0700 |
---|---|---|
committer | Mark D. Roth <roth@google.com> | 2016-10-21 10:43:45 -0700 |
commit | 3686996786faa2671e487707c78b32c0e4a63d80 (patch) | |
tree | 1a5089bb66495d7453c094290112179a27301140 /src | |
parent | 16883a37efa49ef2d58ea57c6dbbba66497f2232 (diff) |
Encode server name, LB policy name, and addresses in channel args.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/ext/client_config/lb_policy_factory.c | 22 | ||||
-rw-r--r-- | src/core/ext/client_config/lb_policy_factory.h | 4 | ||||
-rw-r--r-- | src/core/ext/resolver/dns/native/dns_resolver.c | 14 | ||||
-rw-r--r-- | src/core/ext/resolver/sockaddr/sockaddr_resolver.c | 13 |
4 files changed, 48 insertions, 5 deletions
diff --git a/src/core/ext/client_config/lb_policy_factory.c b/src/core/ext/client_config/lb_policy_factory.c index 55e346180d..676fdaf555 100644 --- a/src/core/ext/client_config/lb_policy_factory.c +++ b/src/core/ext/client_config/lb_policy_factory.c @@ -124,6 +124,28 @@ void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses) { gpr_free(addresses); } +static void* lb_addresses_copy(void* addresses) { + return grpc_lb_addresses_copy(addresses); +} +static void lb_addresses_destroy(void* addresses) { + grpc_lb_addresses_destroy(addresses); +} +static int lb_addresses_cmp(void* addresses1, void* addresses2) { + return grpc_lb_addresses_cmp(addresses1, addresses2); +} +static const grpc_arg_pointer_vtable lb_addresses_arg_vtable = { + lb_addresses_copy, lb_addresses_destroy, lb_addresses_cmp}; + +grpc_arg grpc_lb_addresses_create_channel_arg( + const grpc_lb_addresses *addresses) { + grpc_arg arg; + arg.type = GRPC_ARG_POINTER; + arg.key = GRPC_ARG_LB_ADDRESSES; + arg.value.pointer.p = (void*)addresses; + arg.value.pointer.vtable = &lb_addresses_arg_vtable; + return arg; +} + void grpc_lb_policy_factory_ref(grpc_lb_policy_factory* factory) { factory->vtable->ref(factory); } diff --git a/src/core/ext/client_config/lb_policy_factory.h b/src/core/ext/client_config/lb_policy_factory.h index 61c3f419d1..f0798a3167 100644 --- a/src/core/ext/client_config/lb_policy_factory.h +++ b/src/core/ext/client_config/lb_policy_factory.h @@ -97,6 +97,10 @@ int grpc_lb_addresses_cmp(const grpc_lb_addresses *addresses1, * be invoked to destroy the \a user_data field of each address. */ void grpc_lb_addresses_destroy(grpc_lb_addresses *addresses); +/** Returns a channel arg containing \a addresses. */ +grpc_arg grpc_lb_addresses_create_channel_arg( + const grpc_lb_addresses *addresses); + /** Arguments passed to LB policies. */ /* TODO(roth, ctiller): Consider replacing this struct with grpc_channel_args. See comment in resolver_result.h for details. */ diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index 0694d8b6b7..039fb2225d 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -55,6 +55,7 @@ typedef struct { /** base class: must be first */ grpc_resolver base; /** target name */ +// FIXME: remove target_name when resolver_result goes away char *target_name; /** name to resolve (usually the same as target_name) */ char *name_to_resolve; @@ -178,10 +179,12 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, r->addresses->addrs[i].len, false /* is_balancer */, NULL /* balancer_name */, NULL /* user_data */); } + grpc_arg new_arg = grpc_lb_addresses_create_channel_arg(addresses); + grpc_channel_args* args = + grpc_channel_args_copy_and_add(r->channel_args, &new_arg, 1); grpc_resolved_addresses_destroy(r->addresses); result = grpc_resolver_result_create( - r->target_name, addresses, NULL /* lb_policy_name */, - grpc_channel_args_copy(r->channel_args)); + r->target_name, addresses, NULL /* lb_policy_name */, args); } else { gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now); @@ -268,7 +271,12 @@ static grpc_resolver *dns_create(grpc_resolver_args *args, r->target_name = gpr_strdup(path); r->name_to_resolve = proxy_name == NULL ? gpr_strdup(path) : proxy_name; r->default_port = gpr_strdup(default_port); - r->channel_args = grpc_channel_args_copy(args->args); + grpc_arg server_name_arg; + server_name_arg.type = GRPC_ARG_STRING; + server_name_arg.key = GRPC_ARG_SERVER_NAME; + server_name_arg.value.string = (char*)path; + r->channel_args = + grpc_channel_args_copy_and_add(args->args, &server_name_arg, 1); gpr_backoff_init(&r->backoff_state, BACKOFF_MULTIPLIER, BACKOFF_JITTER, BACKOFF_MIN_SECONDS * 1000, BACKOFF_MAX_SECONDS * 1000); return &r->base; diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index d34094f8e8..93a34bf305 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -52,6 +52,7 @@ typedef struct { /** base class: must be first */ grpc_resolver base; /** the path component of the uri passed in */ +// FIXME: remove target_name when resolver_result goes away char *target_name; /** the addresses that we've 'resolved' */ grpc_lb_addresses *addresses; @@ -120,9 +121,12 @@ static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, sockaddr_resolver *r) { if (r->next_completion != NULL && !r->published) { r->published = true; + grpc_arg arg = grpc_lb_addresses_create_channel_arg(r->addresses); + grpc_channel_args* args = + grpc_channel_args_copy_and_add(r->channel_args, &arg, 1); *r->target_result = grpc_resolver_result_create( r->target_name, grpc_lb_addresses_copy(r->addresses), - NULL /* lb_policy_name */, grpc_channel_args_copy(r->channel_args)); + NULL /* lb_policy_name */, args); grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; } @@ -204,7 +208,12 @@ static grpc_resolver *sockaddr_create(grpc_resolver_args *args, memset(r, 0, sizeof(*r)); r->target_name = gpr_strdup(args->uri->path); r->addresses = addresses; - r->channel_args = grpc_channel_args_copy(args->args); + grpc_arg server_name_arg; + server_name_arg.type = GRPC_ARG_STRING; + server_name_arg.key = GRPC_ARG_SERVER_NAME; + server_name_arg.value.string = args->uri->path; + r->channel_args = + grpc_channel_args_copy_and_add(args->args, &server_name_arg, 1); gpr_mu_init(&r->mu); grpc_resolver_init(&r->base, &sockaddr_resolver_vtable); return &r->base; |