diff options
author | David Garcia Quintas <dgq@google.com> | 2016-03-30 23:53:50 -0700 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2016-03-30 23:53:50 -0700 |
commit | 64ddf13d1454e57df825d2923046e422abeb780c (patch) | |
tree | 944b1c2d18882e5a7ace68d7d3dea49a6b19ccb2 /src/core | |
parent | fec8ece17644da85617d116d43242317bd4218a0 (diff) |
added grpclb support to sockaddr resolver
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/lib/client_config/resolvers/sockaddr_resolver.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/core/lib/client_config/resolvers/sockaddr_resolver.c b/src/core/lib/client_config/resolvers/sockaddr_resolver.c index c787bd57d6..b3aaf46ee4 100644 --- a/src/core/lib/client_config/resolvers/sockaddr_resolver.c +++ b/src/core/lib/client_config/resolvers/sockaddr_resolver.c @@ -35,6 +35,7 @@ #include "src/core/lib/client_config/resolvers/sockaddr_resolver.h" +#include <stdbool.h> #include <stdio.h> #include <string.h> @@ -265,21 +266,27 @@ static grpc_resolver *sockaddr_create( memset(r, 0, sizeof(*r)); r->lb_policy_name = NULL; - if (0 != strcmp(args->uri->query, "")) { - gpr_slice query_slice; - gpr_slice_buffer query_parts; - - query_slice = - gpr_slice_new(args->uri->query, strlen(args->uri->query), do_nothing); - gpr_slice_buffer_init(&query_parts); - gpr_slice_split(query_slice, "=", &query_parts); - GPR_ASSERT(query_parts.count == 2); - if (0 == gpr_slice_str_cmp(query_parts.slices[0], "lb_policy")) { - r->lb_policy_name = gpr_dump_slice(query_parts.slices[1], GPR_DUMP_ASCII); + bool lb_enabled = false; + for (size_t i = 0; i < args->uri->num_query_parts; ++i) { + if (0 == strcmp("lb_policy", args->uri->query_parts[i])) { + GPR_ASSERT(args->uri->query_parts_values[i] != NULL); + r->lb_policy_name = gpr_strdup(args->uri->query_parts_values[i]); + } else if (0 == strcmp("lb_enabled", args->uri->query_parts[i])) { + GPR_ASSERT(args->uri->query_parts_values[i] != NULL); + lb_enabled = (strcmp("0", args->uri->query_parts_values[i]) != 0); } - gpr_slice_buffer_destroy(&query_parts); - gpr_slice_unref(query_slice); } + + if (r->lb_policy_name != NULL && strcmp("grpclb", r->lb_policy_name) == 0 && + !lb_enabled) { + /* we want grpclb but the "resolved" addresses aren't LB enabled. Bail + * out, as this is meant mostly for tests. */ + gpr_log(GPR_ERROR, + "Requested 'grpclb' LB policy but resolved addresses don't " + "support load balancing."); + abort(); + } + if (r->lb_policy_name == NULL) { r->lb_policy_name = gpr_strdup(default_lb_policy_name); } |