From 896d92568b1b615a19dec26035596de244cbf535 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 3 Nov 2016 07:58:25 -0700 Subject: Add grpc_json_tree to handle refcounting for channel arg. --- test/core/end2end/connection_refused_test.c | 22 ++++++------- test/core/end2end/tests/cancel_after_accept.c | 23 +++++++------ test/core/end2end/tests/max_message_length.c | 47 +++++++++++++-------------- 3 files changed, 44 insertions(+), 48 deletions(-) (limited to 'test/core') diff --git a/test/core/end2end/connection_refused_test.c b/test/core/end2end/connection_refused_test.c index 13414c0378..ba9fb3d30a 100644 --- a/test/core/end2end/connection_refused_test.c +++ b/test/core/end2end/connection_refused_test.c @@ -76,18 +76,18 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_channel_args *args = NULL; if (use_service_config) { GPR_ASSERT(wait_for_ready); - grpc_method_config_table_entry entry = { - grpc_mdstr_from_string("/service/method"), - grpc_method_config_create(&wait_for_ready, NULL, NULL, NULL), - }; - grpc_method_config_table *method_config_table = - grpc_method_config_table_create(1, &entry); - GRPC_MDSTR_UNREF(entry.method_name); - grpc_method_config_unref(entry.method_config); - grpc_arg arg = - grpc_method_config_table_create_channel_arg(method_config_table); + grpc_json_tree* service_config_json = grpc_json_tree_create( + "{\n" + " \"method_config\": [ {\n" + " \"name\": [\n" + " { \"service\": \"service\", \"method\": \"method\" }\n" + " ],\n" + " \"wait_for_ready\": true\n" + " } ]\n" + "}"); + grpc_arg arg = grpc_service_config_create_channel_arg(service_config_json); args = grpc_channel_args_copy_and_add(args, &arg, 1); - grpc_method_config_table_unref(method_config_table); + grpc_json_tree_unref(service_config_json); } /* create a call, channel to a port which will refuse connection */ diff --git a/test/core/end2end/tests/cancel_after_accept.c b/test/core/end2end/tests/cancel_after_accept.c index 104d8fd54f..68a8256092 100644 --- a/test/core/end2end/tests/cancel_after_accept.c +++ b/test/core/end2end/tests/cancel_after_accept.c @@ -132,19 +132,18 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, grpc_channel_args *args = NULL; if (use_service_config) { - gpr_timespec timeout = {5, 0, GPR_TIMESPAN}; - grpc_method_config_table_entry entry = { - grpc_mdstr_from_string("/service/method"), - grpc_method_config_create(NULL, &timeout, NULL, NULL), - }; - grpc_method_config_table *method_config_table = - grpc_method_config_table_create(1, &entry); - GRPC_MDSTR_UNREF(entry.method_name); - grpc_method_config_unref(entry.method_config); - grpc_arg arg = - grpc_method_config_table_create_channel_arg(method_config_table); + grpc_json_tree* service_config_json = grpc_json_tree_create( + "{\n" + " \"method_config\": [ {\n" + " \"name\": [\n" + " { \"service\": \"service\", \"method\": \"method\" }\n" + " ],\n" + " \"timeout\": { \"seconds\": 5 }\n" + " } ]\n" + "}"); + grpc_arg arg = grpc_service_config_create_channel_arg(service_config_json); args = grpc_channel_args_copy_and_add(args, &arg, 1); - grpc_method_config_table_unref(method_config_table); + grpc_json_tree_unref(service_config_json); } grpc_end2end_test_fixture f = diff --git a/test/core/end2end/tests/max_message_length.c b/test/core/end2end/tests/max_message_length.c index 3a927ddcbc..f0bc7acdff 100644 --- a/test/core/end2end/tests/max_message_length.c +++ b/test/core/end2end/tests/max_message_length.c @@ -137,19 +137,18 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, if (use_service_config) { // We don't currently support service configs on the server side. GPR_ASSERT(send_limit); - int32_t max_request_message_bytes = 5; - grpc_method_config_table_entry entry = { - grpc_mdstr_from_string("/service/method"), - grpc_method_config_create(NULL, NULL, &max_request_message_bytes, NULL), - }; - grpc_method_config_table *method_config_table = - grpc_method_config_table_create(1, &entry); - GRPC_MDSTR_UNREF(entry.method_name); - grpc_method_config_unref(entry.method_config); - grpc_arg arg = - grpc_method_config_table_create_channel_arg(method_config_table); + grpc_json_tree* service_config_json = grpc_json_tree_create( + "{\n" + " \"method_config\": [ {\n" + " \"name\": [\n" + " { \"service\": \"service\", \"method\": \"method\" }\n" + " ],\n" + " \"max_request_message_bytes\": 5\n" + " } ]\n" + "}"); + grpc_arg arg = grpc_service_config_create_channel_arg(service_config_json); client_args = grpc_channel_args_copy_and_add(NULL, &arg, 1); - grpc_method_config_table_unref(method_config_table); + grpc_json_tree_unref(service_config_json); } else { // Set limit via channel args. grpc_arg arg; @@ -309,20 +308,18 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, if (use_service_config) { // We don't currently support service configs on the server side. GPR_ASSERT(!send_limit); - int32_t max_response_message_bytes = 5; - grpc_method_config_table_entry entry = { - grpc_mdstr_from_string("/service/method"), - grpc_method_config_create(NULL, NULL, NULL, - &max_response_message_bytes), - }; - grpc_method_config_table *method_config_table = - grpc_method_config_table_create(1, &entry); - GRPC_MDSTR_UNREF(entry.method_name); - grpc_method_config_unref(entry.method_config); - grpc_arg arg = - grpc_method_config_table_create_channel_arg(method_config_table); + grpc_json_tree* service_config_json = grpc_json_tree_create( + "{\n" + " \"method_config\": [ {\n" + " \"name\": [\n" + " { \"service\": \"service\", \"method\": \"method\" }\n" + " ],\n" + " \"max_response_message_bytes\": 5\n" + " } ]\n" + "}"); + grpc_arg arg = grpc_service_config_create_channel_arg(service_config_json); client_args = grpc_channel_args_copy_and_add(NULL, &arg, 1); - grpc_method_config_table_unref(method_config_table); + grpc_json_tree_unref(service_config_json); } else { // Set limit via channel args. grpc_arg arg; -- cgit v1.2.3 From 47f1084ce835d4288ddfa9f280e07d0a8d5719c5 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 3 Nov 2016 08:45:27 -0700 Subject: clang-format --- src/core/ext/client_channel/client_channel.c | 12 ++++++------ src/core/lib/json/json.c | 6 +++--- src/core/lib/json/json.h | 22 +++++++++++----------- src/core/lib/support/string.c | 4 ++-- src/core/lib/support/string.h | 2 +- src/core/lib/transport/method_config.c | 8 +++----- test/core/end2end/connection_refused_test.c | 2 +- test/core/end2end/tests/cancel_after_accept.c | 2 +- test/core/end2end/tests/max_message_length.c | 4 ++-- 9 files changed, 30 insertions(+), 32 deletions(-) (limited to 'test/core') diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c index d53265bc9c..4ca24c4dbc 100644 --- a/src/core/ext/client_channel/client_channel.c +++ b/src/core/ext/client_channel/client_channel.c @@ -86,21 +86,21 @@ static const grpc_mdstr_hash_table_vtable method_parameters_vtable = { static void *method_parameters_create_from_json(const grpc_json *json) { wait_for_ready_value wait_for_ready = WAIT_FOR_READY_UNSET; - gpr_timespec timeout = { 0, 0, GPR_TIMESPAN }; - for (grpc_json* field = json->child; field != NULL; field = field->next) { + gpr_timespec timeout = {0, 0, GPR_TIMESPAN}; + for (grpc_json *field = json->child; field != NULL; field = field->next) { if (field->key == NULL) continue; if (strcmp(field->key, "wait_for_ready") == 0) { if (wait_for_ready != WAIT_FOR_READY_UNSET) return NULL; // Duplicate. if (field->type != GRPC_JSON_TRUE && field->type != GRPC_JSON_FALSE) { return NULL; } - wait_for_ready = field->type == GRPC_JSON_TRUE - ? WAIT_FOR_READY_TRUE : WAIT_FOR_READY_FALSE; + wait_for_ready = field->type == GRPC_JSON_TRUE ? WAIT_FOR_READY_TRUE + : WAIT_FOR_READY_FALSE; } else if (strcmp(field->key, "timeout") == 0) { if (timeout.tv_sec > 0 || timeout.tv_nsec > 0) return NULL; // Duplicate. if (field->type != GRPC_JSON_OBJECT) return NULL; if (field->child == NULL) return NULL; - for (grpc_json* subfield = field->child; subfield != NULL; + for (grpc_json *subfield = field->child; subfield != NULL; subfield = subfield->next) { if (subfield->key == NULL) return NULL; if (strcmp(subfield->key, "seconds") == 0) { @@ -303,7 +303,7 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, grpc_channel_args_find(lb_policy_args.args, GRPC_ARG_SERVICE_CONFIG); if (channel_arg != NULL) { GPR_ASSERT(channel_arg->type == GRPC_ARG_POINTER); - grpc_json_tree* json_tree = channel_arg->value.pointer.p; + grpc_json_tree *json_tree = channel_arg->value.pointer.p; method_params_table = grpc_method_config_table_create_from_json( json_tree->root, method_parameters_create_from_json, &method_parameters_vtable); diff --git a/src/core/lib/json/json.c b/src/core/lib/json/json.c index c1a99df6c3..9acf3b0438 100644 --- a/src/core/lib/json/json.c +++ b/src/core/lib/json/json.c @@ -39,15 +39,15 @@ #include "src/core/lib/json/json.h" -grpc_json *grpc_json_create(grpc_json_type type) { - grpc_json *json = gpr_malloc(sizeof(*json)); +grpc_json* grpc_json_create(grpc_json_type type) { + grpc_json* json = gpr_malloc(sizeof(*json)); memset(json, 0, sizeof(*json)); json->type = type; return json; } -void grpc_json_destroy(grpc_json *json) { +void grpc_json_destroy(grpc_json* json) { while (json->child) { grpc_json_destroy(json->child); } diff --git a/src/core/lib/json/json.h b/src/core/lib/json/json.h index e18ace7547..1663c690e5 100644 --- a/src/core/lib/json/json.h +++ b/src/core/lib/json/json.h @@ -44,14 +44,14 @@ * are not owned by it. */ typedef struct grpc_json { - struct grpc_json *next; - struct grpc_json *prev; - struct grpc_json *child; - struct grpc_json *parent; + struct grpc_json* next; + struct grpc_json* prev; + struct grpc_json* child; + struct grpc_json* parent; grpc_json_type type; - const char *key; - const char *value; + const char* key; + const char* value; } grpc_json; /* The next two functions are going to parse the input string, and @@ -67,8 +67,8 @@ typedef struct grpc_json { * * Delete the allocated tree afterward using grpc_json_destroy(). */ -grpc_json *grpc_json_parse_string_with_len(char *input, size_t size); -grpc_json *grpc_json_parse_string(char *input); +grpc_json* grpc_json_parse_string_with_len(char* input, size_t size); +grpc_json* grpc_json_parse_string(char* input); /* This function will create a new string using gpr_realloc, and will * deserialize the grpc_json tree into it. It'll be zero-terminated, @@ -78,14 +78,14 @@ grpc_json *grpc_json_parse_string(char *input); * If indent is 0, then newlines will be suppressed as well, and the * output will be condensed at its maximum. */ -char *grpc_json_dump_to_string(grpc_json *json, int indent); +char* grpc_json_dump_to_string(grpc_json* json, int indent); /* Use these to create or delete a grpc_json object. * Deletion is recursive. We will not attempt to free any of the strings * in any of the objects of that tree. */ -grpc_json *grpc_json_create(grpc_json_type type); -void grpc_json_destroy(grpc_json *json); +grpc_json* grpc_json_create(grpc_json_type type); +void grpc_json_destroy(grpc_json* json); /* Compares two JSON trees. */ int grpc_json_cmp(const grpc_json* json1, const grpc_json* json2); diff --git a/src/core/lib/support/string.c b/src/core/lib/support/string.c index 56f29492bf..165b3189a5 100644 --- a/src/core/lib/support/string.c +++ b/src/core/lib/support/string.c @@ -196,8 +196,8 @@ int int64_ttoa(int64_t value, char *string) { return i; } -int gpr_parse_nonnegative_number(const char* value) { - char* end; +int gpr_parse_nonnegative_number(const char *value) { + char *end; long result = strtol(value, &end, 0); if (*end != '\0' || result < 0 || result > INT_MAX) return -1; return (int)result; diff --git a/src/core/lib/support/string.h b/src/core/lib/support/string.h index 3a5a8ed826..34fd154a83 100644 --- a/src/core/lib/support/string.h +++ b/src/core/lib/support/string.h @@ -81,7 +81,7 @@ where long is 32bit is size.*/ int int64_ttoa(int64_t value, char *output); // Parses a non-negative number from a value string. Returns -1 on error. -int gpr_parse_nonnegative_number(const char* value); +int gpr_parse_nonnegative_number(const char *value); /* Reverse a run of bytes */ void gpr_reverse_bytes(char *str, int len); diff --git a/src/core/lib/transport/method_config.c b/src/core/lib/transport/method_config.c index a163af91d6..1ce43ca13f 100644 --- a/src/core/lib/transport/method_config.c +++ b/src/core/lib/transport/method_config.c @@ -80,10 +80,9 @@ static char* parse_json_method_name(grpc_json* json) { // Parses the method config from \a json. Adds an entry to \a entries for // each name found, incrementing \a idx for each entry added. static bool parse_json_method_config( - grpc_json* json, - void* (*create_value)(const grpc_json* method_config_json), + grpc_json* json, void* (*create_value)(const grpc_json* method_config_json), const grpc_mdstr_hash_table_vtable* vtable, - grpc_mdstr_hash_table_entry* entries, size_t *idx) { + grpc_mdstr_hash_table_entry* entries, size_t* idx) { // Construct value. void* method_config = create_value(json); if (method_config == NULL) return NULL; @@ -135,8 +134,7 @@ grpc_mdstr_hash_table* grpc_method_config_table_create_from_json( num_entries += count_names_in_method_config_json(method); } // Populate method config table entries. - entries = - gpr_malloc(num_entries * sizeof(grpc_mdstr_hash_table_entry)); + entries = gpr_malloc(num_entries * sizeof(grpc_mdstr_hash_table_entry)); size_t idx = 0; for (grpc_json* method = field->child; method != NULL; method = method->next) { diff --git a/test/core/end2end/connection_refused_test.c b/test/core/end2end/connection_refused_test.c index ba9fb3d30a..2857ca70e8 100644 --- a/test/core/end2end/connection_refused_test.c +++ b/test/core/end2end/connection_refused_test.c @@ -76,7 +76,7 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_channel_args *args = NULL; if (use_service_config) { GPR_ASSERT(wait_for_ready); - grpc_json_tree* service_config_json = grpc_json_tree_create( + grpc_json_tree *service_config_json = grpc_json_tree_create( "{\n" " \"method_config\": [ {\n" " \"name\": [\n" diff --git a/test/core/end2end/tests/cancel_after_accept.c b/test/core/end2end/tests/cancel_after_accept.c index 68a8256092..bef33f2a33 100644 --- a/test/core/end2end/tests/cancel_after_accept.c +++ b/test/core/end2end/tests/cancel_after_accept.c @@ -132,7 +132,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, grpc_channel_args *args = NULL; if (use_service_config) { - grpc_json_tree* service_config_json = grpc_json_tree_create( + grpc_json_tree *service_config_json = grpc_json_tree_create( "{\n" " \"method_config\": [ {\n" " \"name\": [\n" diff --git a/test/core/end2end/tests/max_message_length.c b/test/core/end2end/tests/max_message_length.c index f0bc7acdff..4cffff915e 100644 --- a/test/core/end2end/tests/max_message_length.c +++ b/test/core/end2end/tests/max_message_length.c @@ -137,7 +137,7 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, if (use_service_config) { // We don't currently support service configs on the server side. GPR_ASSERT(send_limit); - grpc_json_tree* service_config_json = grpc_json_tree_create( + grpc_json_tree *service_config_json = grpc_json_tree_create( "{\n" " \"method_config\": [ {\n" " \"name\": [\n" @@ -308,7 +308,7 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, if (use_service_config) { // We don't currently support service configs on the server side. GPR_ASSERT(!send_limit); - grpc_json_tree* service_config_json = grpc_json_tree_create( + grpc_json_tree *service_config_json = grpc_json_tree_create( "{\n" " \"method_config\": [ {\n" " \"name\": [\n" -- cgit v1.2.3 From ea846a08004501fa4b63dbb5bd7bb12bd1017a33 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 3 Nov 2016 11:32:54 -0700 Subject: Rename method_config.[ch] to service_config.[ch]. --- BUILD | 16 +- CMakeLists.txt | 6 +- Makefile | 8 +- binding.gyp | 2 +- build.yaml | 4 +- config.m4 | 2 +- gRPC-Core.podspec | 6 +- grpc.gemspec | 4 +- package.xml | 4 +- src/core/ext/client_channel/client_channel.c | 2 +- src/core/lib/channel/message_size_filter.c | 2 +- src/core/lib/transport/method_config.c | 221 --------------------- src/core/lib/transport/method_config.h | 66 ------ src/core/lib/transport/service_config.c | 221 +++++++++++++++++++++ src/core/lib/transport/service_config.h | 66 ++++++ src/python/grpcio/grpc_core_dependencies.py | 2 +- test/core/end2end/connection_refused_test.c | 2 +- test/core/end2end/tests/cancel_after_accept.c | 2 +- test/core/end2end/tests/max_message_length.c | 2 +- tools/doxygen/Doxyfile.core.internal | 4 +- tools/run_tests/sources_and_headers.json | 6 +- vsprojects/vcxproj/grpc/grpc.vcxproj | 4 +- vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 4 +- .../vcxproj/grpc_test_util/grpc_test_util.vcxproj | 4 +- .../grpc_test_util/grpc_test_util.vcxproj.filters | 4 +- .../vcxproj/grpc_unsecure/grpc_unsecure.vcxproj | 4 +- .../grpc_unsecure/grpc_unsecure.vcxproj.filters | 4 +- 27 files changed, 336 insertions(+), 336 deletions(-) delete mode 100644 src/core/lib/transport/method_config.c delete mode 100644 src/core/lib/transport/method_config.h create mode 100644 src/core/lib/transport/service_config.c create mode 100644 src/core/lib/transport/service_config.h (limited to 'test/core') diff --git a/BUILD b/BUILD index 97ddc56b41..d747e71dde 100644 --- a/BUILD +++ b/BUILD @@ -251,7 +251,7 @@ cc_library( "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", - "src/core/lib/transport/method_config.h", + "src/core/lib/transport/service_config.h", "src/core/lib/transport/static_metadata.h", "src/core/lib/transport/timeout_encoding.h", "src/core/lib/transport/transport.h", @@ -435,7 +435,7 @@ cc_library( "src/core/lib/transport/mdstr_hash_table.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", - "src/core/lib/transport/method_config.c", + "src/core/lib/transport/service_config.c", "src/core/lib/transport/static_metadata.c", "src/core/lib/transport/timeout_encoding.c", "src/core/lib/transport/transport.c", @@ -675,7 +675,7 @@ cc_library( "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", - "src/core/lib/transport/method_config.h", + "src/core/lib/transport/service_config.h", "src/core/lib/transport/static_metadata.h", "src/core/lib/transport/timeout_encoding.h", "src/core/lib/transport/transport.h", @@ -844,7 +844,7 @@ cc_library( "src/core/lib/transport/mdstr_hash_table.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", - "src/core/lib/transport/method_config.c", + "src/core/lib/transport/service_config.c", "src/core/lib/transport/static_metadata.c", "src/core/lib/transport/timeout_encoding.c", "src/core/lib/transport/transport.c", @@ -1054,7 +1054,7 @@ cc_library( "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", - "src/core/lib/transport/method_config.h", + "src/core/lib/transport/service_config.h", "src/core/lib/transport/static_metadata.h", "src/core/lib/transport/timeout_encoding.h", "src/core/lib/transport/transport.h", @@ -1215,7 +1215,7 @@ cc_library( "src/core/lib/transport/mdstr_hash_table.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", - "src/core/lib/transport/method_config.c", + "src/core/lib/transport/service_config.c", "src/core/lib/transport/static_metadata.c", "src/core/lib/transport/timeout_encoding.c", "src/core/lib/transport/transport.c", @@ -2072,7 +2072,7 @@ objc_library( "src/core/lib/transport/mdstr_hash_table.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", - "src/core/lib/transport/method_config.c", + "src/core/lib/transport/service_config.c", "src/core/lib/transport/static_metadata.c", "src/core/lib/transport/timeout_encoding.c", "src/core/lib/transport/transport.c", @@ -2291,7 +2291,7 @@ objc_library( "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", - "src/core/lib/transport/method_config.h", + "src/core/lib/transport/service_config.h", "src/core/lib/transport/static_metadata.h", "src/core/lib/transport/timeout_encoding.h", "src/core/lib/transport/transport.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b073b0d68..dec3c8a7f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -392,7 +392,7 @@ add_library(grpc src/core/lib/transport/mdstr_hash_table.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c - src/core/lib/transport/method_config.c + src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c @@ -664,7 +664,7 @@ add_library(grpc_cronet src/core/lib/transport/mdstr_hash_table.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c - src/core/lib/transport/method_config.c + src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c @@ -908,7 +908,7 @@ add_library(grpc_unsecure src/core/lib/transport/mdstr_hash_table.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c - src/core/lib/transport/method_config.c + src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c diff --git a/Makefile b/Makefile index 4b713cef3b..2d4acb8757 100644 --- a/Makefile +++ b/Makefile @@ -2687,7 +2687,7 @@ LIBGRPC_SRC = \ src/core/lib/transport/mdstr_hash_table.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ - src/core/lib/transport/method_config.c \ + src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ @@ -2977,7 +2977,7 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/transport/mdstr_hash_table.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ - src/core/lib/transport/method_config.c \ + src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ @@ -3258,7 +3258,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/transport/mdstr_hash_table.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ - src/core/lib/transport/method_config.c \ + src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ @@ -3468,7 +3468,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/transport/mdstr_hash_table.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ - src/core/lib/transport/method_config.c \ + src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ diff --git a/binding.gyp b/binding.gyp index 9f3b75aaf3..7f6e06b1c3 100644 --- a/binding.gyp +++ b/binding.gyp @@ -670,7 +670,7 @@ 'src/core/lib/transport/mdstr_hash_table.c', 'src/core/lib/transport/metadata.c', 'src/core/lib/transport/metadata_batch.c', - 'src/core/lib/transport/method_config.c', + 'src/core/lib/transport/service_config.c', 'src/core/lib/transport/static_metadata.c', 'src/core/lib/transport/timeout_encoding.c', 'src/core/lib/transport/transport.c', diff --git a/build.yaml b/build.yaml index 56c220d4ab..c7bfc58ea4 100644 --- a/build.yaml +++ b/build.yaml @@ -255,7 +255,7 @@ filegroups: - src/core/lib/transport/mdstr_hash_table.h - src/core/lib/transport/metadata.h - src/core/lib/transport/metadata_batch.h - - src/core/lib/transport/method_config.h + - src/core/lib/transport/service_config.h - src/core/lib/transport/static_metadata.h - src/core/lib/transport/timeout_encoding.h - src/core/lib/transport/transport.h @@ -363,7 +363,7 @@ filegroups: - src/core/lib/transport/mdstr_hash_table.c - src/core/lib/transport/metadata.c - src/core/lib/transport/metadata_batch.c - - src/core/lib/transport/method_config.c + - src/core/lib/transport/service_config.c - src/core/lib/transport/static_metadata.c - src/core/lib/transport/timeout_encoding.c - src/core/lib/transport/transport.c diff --git a/config.m4 b/config.m4 index 8f26e42678..ff94bbc79a 100644 --- a/config.m4 +++ b/config.m4 @@ -186,7 +186,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/transport/mdstr_hash_table.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ - src/core/lib/transport/method_config.c \ + src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 43aedecd06..a6abebcac7 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -338,7 +338,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/mdstr_hash_table.h', 'src/core/lib/transport/metadata.h', 'src/core/lib/transport/metadata_batch.h', - 'src/core/lib/transport/method_config.h', + 'src/core/lib/transport/service_config.h', 'src/core/lib/transport/static_metadata.h', 'src/core/lib/transport/timeout_encoding.h', 'src/core/lib/transport/transport.h', @@ -526,7 +526,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/mdstr_hash_table.c', 'src/core/lib/transport/metadata.c', 'src/core/lib/transport/metadata_batch.c', - 'src/core/lib/transport/method_config.c', + 'src/core/lib/transport/service_config.c', 'src/core/lib/transport/static_metadata.c', 'src/core/lib/transport/timeout_encoding.c', 'src/core/lib/transport/transport.c', @@ -734,7 +734,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/mdstr_hash_table.h', 'src/core/lib/transport/metadata.h', 'src/core/lib/transport/metadata_batch.h', - 'src/core/lib/transport/method_config.h', + 'src/core/lib/transport/service_config.h', 'src/core/lib/transport/static_metadata.h', 'src/core/lib/transport/timeout_encoding.h', 'src/core/lib/transport/transport.h', diff --git a/grpc.gemspec b/grpc.gemspec index 615a962cdb..16f8381859 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -258,7 +258,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/transport/mdstr_hash_table.h ) s.files += %w( src/core/lib/transport/metadata.h ) s.files += %w( src/core/lib/transport/metadata_batch.h ) - s.files += %w( src/core/lib/transport/method_config.h ) + s.files += %w( src/core/lib/transport/service_config.h ) s.files += %w( src/core/lib/transport/static_metadata.h ) s.files += %w( src/core/lib/transport/timeout_encoding.h ) s.files += %w( src/core/lib/transport/transport.h ) @@ -446,7 +446,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/transport/mdstr_hash_table.c ) s.files += %w( src/core/lib/transport/metadata.c ) s.files += %w( src/core/lib/transport/metadata_batch.c ) - s.files += %w( src/core/lib/transport/method_config.c ) + s.files += %w( src/core/lib/transport/service_config.c ) s.files += %w( src/core/lib/transport/static_metadata.c ) s.files += %w( src/core/lib/transport/timeout_encoding.c ) s.files += %w( src/core/lib/transport/transport.c ) diff --git a/package.xml b/package.xml index a60eac6820..d402154434 100644 --- a/package.xml +++ b/package.xml @@ -265,7 +265,7 @@ - + @@ -453,7 +453,7 @@ - + diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c index d96ec57f04..d9161f47cd 100644 --- a/src/core/ext/client_channel/client_channel.c +++ b/src/core/ext/client_channel/client_channel.c @@ -55,7 +55,7 @@ #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/metadata_batch.h" -#include "src/core/lib/transport/method_config.h" +#include "src/core/lib/transport/service_config.h" #include "src/core/lib/transport/static_metadata.h" /* Client channel implementation */ diff --git a/src/core/lib/channel/message_size_filter.c b/src/core/lib/channel/message_size_filter.c index 2950eef87e..f826c74f89 100644 --- a/src/core/lib/channel/message_size_filter.c +++ b/src/core/lib/channel/message_size_filter.c @@ -40,7 +40,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/support/string.h" -#include "src/core/lib/transport/method_config.h" +#include "src/core/lib/transport/service_config.h" #define DEFAULT_MAX_SEND_MESSAGE_LENGTH -1 // Unlimited. // The protobuf library will (by default) start warning at 100 megs. diff --git a/src/core/lib/transport/method_config.c b/src/core/lib/transport/method_config.c deleted file mode 100644 index 49e60a47bc..0000000000 --- a/src/core/lib/transport/method_config.c +++ /dev/null @@ -1,221 +0,0 @@ -// -// Copyright 2015, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// - -#include "src/core/lib/transport/method_config.h" - -#include - -#include -#include -#include -#include - -#include "src/core/lib/json/json.h" -#include "src/core/lib/support/string.h" -#include "src/core/lib/transport/mdstr_hash_table.h" - -// Returns the number of names specified in the method config \a json. -static size_t count_names_in_method_config_json(grpc_json* json) { - size_t num_names = 0; - for (grpc_json* field = json->child; field != NULL; field = field->next) { - if (field->key != NULL && strcmp(field->key, "name") == 0) ++num_names; - } - return num_names; -} - -// Returns a path string for the name specified by \a json. -// Returns NULL on error. Caller takes ownership of result. -static char* parse_json_method_name(grpc_json* json) { - if (json->type != GRPC_JSON_OBJECT) return NULL; - const char* service_name = NULL; - const char* method_name = NULL; - for (grpc_json* child = json->child; child != NULL; child = child->next) { - if (child->key == NULL) return NULL; - if (child->type != GRPC_JSON_STRING) return NULL; - if (strcmp(child->key, "service") == 0) { - if (service_name != NULL) return NULL; // Duplicate. - if (child->value == NULL) return NULL; - service_name = child->value; - } else if (strcmp(child->key, "method") == 0) { - if (method_name != NULL) return NULL; // Duplicate. - if (child->value == NULL) return NULL; - method_name = child->value; - } - } - if (service_name == NULL) return NULL; // Required field. - char* path; - gpr_asprintf(&path, "/%s/%s", service_name, - method_name == NULL ? "*" : method_name); - return path; -} - -// Parses the method config from \a json. Adds an entry to \a entries for -// each name found, incrementing \a idx for each entry added. -static bool parse_json_method_config( - grpc_json* json, void* (*create_value)(const grpc_json* method_config_json), - const grpc_mdstr_hash_table_vtable* vtable, - grpc_mdstr_hash_table_entry* entries, size_t* idx) { - // Construct value. - void* method_config = create_value(json); - if (method_config == NULL) return NULL; - // Construct list of paths. - bool retval = false; - gpr_strvec paths; - gpr_strvec_init(&paths); - for (grpc_json* child = json->child; child != NULL; child = child->next) { - if (child->key == NULL) continue; - if (strcmp(child->key, "name") == 0) { - if (child->type != GRPC_JSON_ARRAY) goto done; - for (grpc_json* name = child->child; name != NULL; name = name->next) { - char* path = parse_json_method_name(name); - gpr_strvec_add(&paths, path); - } - } - } - if (paths.count == 0) goto done; // No names specified. - // Add entry for each path. - for (size_t i = 0; i < paths.count; ++i) { - entries[*idx].key = grpc_mdstr_from_string(paths.strs[i]); - entries[*idx].value = vtable->copy_value(method_config); - entries[*idx].vtable = vtable; - ++*idx; - } - retval = true; -done: - vtable->destroy_value(method_config); - gpr_strvec_destroy(&paths); - return retval; -} - -grpc_mdstr_hash_table* grpc_method_config_table_create_from_json( - const grpc_json* json, - void* (*create_value)(const grpc_json* method_config_json), - const grpc_mdstr_hash_table_vtable* vtable) { - // Traverse parsed JSON tree. - if (json->type != GRPC_JSON_OBJECT || json->key != NULL) return NULL; - size_t num_entries = 0; - grpc_mdstr_hash_table_entry* entries = NULL; - for (grpc_json* field = json->child; field != NULL; field = field->next) { - if (field->key == NULL) return NULL; - if (strcmp(field->key, "method_config") == 0) { - if (entries != NULL) return NULL; // Duplicate. - if (field->type != GRPC_JSON_ARRAY) return NULL; - // Find number of entries. - for (grpc_json* method = field->child; method != NULL; - method = method->next) { - num_entries += count_names_in_method_config_json(method); - } - // Populate method config table entries. - entries = gpr_malloc(num_entries * sizeof(grpc_mdstr_hash_table_entry)); - size_t idx = 0; - for (grpc_json* method = field->child; method != NULL; - method = method->next) { - if (!parse_json_method_config(method, create_value, vtable, entries, - &idx)) { - return NULL; - } - } - GPR_ASSERT(idx == num_entries); - } - } - // Instantiate method config table. - grpc_mdstr_hash_table* method_config_table = NULL; - if (entries != NULL) { - method_config_table = grpc_mdstr_hash_table_create(num_entries, entries); - // Clean up. - for (size_t i = 0; i < num_entries; ++i) { - GRPC_MDSTR_UNREF(entries[i].key); - vtable->destroy_value(entries[i].value); - } - gpr_free(entries); - } - return method_config_table; -} - -void* grpc_method_config_table_get(const grpc_mdstr_hash_table* table, - const grpc_mdstr* path) { - void* value = grpc_mdstr_hash_table_get(table, path); - // If we didn't find a match for the path, try looking for a wildcard - // entry (i.e., change "/service/method" to "/service/*"). - if (value == NULL) { - const char* path_str = grpc_mdstr_as_c_string(path); - const char* sep = strrchr(path_str, '/') + 1; - const size_t len = (size_t)(sep - path_str); - char* buf = gpr_malloc(len + 2); // '*' and NUL - memcpy(buf, path_str, len); - buf[len] = '*'; - buf[len + 1] = '\0'; - grpc_mdstr* wildcard_path = grpc_mdstr_from_string(buf); - gpr_free(buf); - value = grpc_mdstr_hash_table_get(table, wildcard_path); - GRPC_MDSTR_UNREF(wildcard_path); - } - return value; -} - -const char* grpc_service_config_get_lb_policy_name( - grpc_json_tree* service_config) { - grpc_json* json = service_config->root; - if (json->type != GRPC_JSON_OBJECT || json->key != NULL) return NULL; - const char* lb_policy_name = NULL; - for (grpc_json* field = json->child; field != NULL; field = field->next) { - if (field->key == NULL) return NULL; - if (strcmp(field->key, "lb_policy_name") == 0) { - if (lb_policy_name != NULL) return NULL; // Duplicate. - if (field->type != GRPC_JSON_STRING) return NULL; - lb_policy_name = field->value; - } - } - return lb_policy_name; -} - -static void* copy_json_tree(void* t) { return grpc_json_tree_ref(t); } - -static void destroy_json_tree(void* t) { grpc_json_tree_unref(t); } - -static int cmp_json_tree(void* t1, void* t2) { - grpc_json_tree* tree1 = t1; - grpc_json_tree* tree2 = t2; - return grpc_json_cmp(tree1->root, tree2->root); -} - -static grpc_arg_pointer_vtable service_config_arg_vtable = { - copy_json_tree, destroy_json_tree, cmp_json_tree}; - -grpc_arg grpc_service_config_create_channel_arg( - grpc_json_tree* service_config) { - grpc_arg arg; - arg.type = GRPC_ARG_POINTER; - arg.key = GRPC_ARG_SERVICE_CONFIG; - arg.value.pointer.p = service_config; - arg.value.pointer.vtable = &service_config_arg_vtable; - return arg; -} diff --git a/src/core/lib/transport/method_config.h b/src/core/lib/transport/method_config.h deleted file mode 100644 index 9922a7a657..0000000000 --- a/src/core/lib/transport/method_config.h +++ /dev/null @@ -1,66 +0,0 @@ -// -// Copyright 2016, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// - -#ifndef GRPC_CORE_LIB_TRANSPORT_METHOD_CONFIG_H -#define GRPC_CORE_LIB_TRANSPORT_METHOD_CONFIG_H - -#include - -#include "src/core/lib/json/json.h" -#include "src/core/lib/transport/mdstr_hash_table.h" - -/// Creates a method config table based on the data in \a json. -/// The table's keys are request paths. The table's value type is -/// returned by \a create_value(), based on data parsed from the JSON tree. -/// \a vtable provides methods used to manage the values. -/// Returns NULL on error. -grpc_mdstr_hash_table* grpc_method_config_table_create_from_json( - const grpc_json* json, - void* (*create_value)(const grpc_json* method_config_json), - const grpc_mdstr_hash_table_vtable* vtable); - -/// Gets the method config for the specified \a path, which should be of -/// the form "/service/method". -/// Returns NULL if the method has no config. -/// Caller does NOT own a reference to the result. -void* grpc_method_config_table_get(const grpc_mdstr_hash_table* table, - const grpc_mdstr* path); - -/// Gets the LB policy name from \a service_config. -/// Returns NULL if no LB policy name was specified. -/// Caller does NOT take ownership. -const char* grpc_service_config_get_lb_policy_name( - grpc_json_tree* service_config); - -/// Creates a channel arg containing \a service_config. -grpc_arg grpc_service_config_create_channel_arg(grpc_json_tree* service_config); - -#endif /* GRPC_CORE_LIB_TRANSPORT_METHOD_CONFIG_H */ diff --git a/src/core/lib/transport/service_config.c b/src/core/lib/transport/service_config.c new file mode 100644 index 0000000000..2a717e7b9b --- /dev/null +++ b/src/core/lib/transport/service_config.c @@ -0,0 +1,221 @@ +// +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#include "src/core/lib/transport/service_config.h" + +#include + +#include +#include +#include +#include + +#include "src/core/lib/json/json.h" +#include "src/core/lib/support/string.h" +#include "src/core/lib/transport/mdstr_hash_table.h" + +// Returns the number of names specified in the method config \a json. +static size_t count_names_in_method_config_json(grpc_json* json) { + size_t num_names = 0; + for (grpc_json* field = json->child; field != NULL; field = field->next) { + if (field->key != NULL && strcmp(field->key, "name") == 0) ++num_names; + } + return num_names; +} + +// Returns a path string for the name specified by \a json. +// Returns NULL on error. Caller takes ownership of result. +static char* parse_json_method_name(grpc_json* json) { + if (json->type != GRPC_JSON_OBJECT) return NULL; + const char* service_name = NULL; + const char* method_name = NULL; + for (grpc_json* child = json->child; child != NULL; child = child->next) { + if (child->key == NULL) return NULL; + if (child->type != GRPC_JSON_STRING) return NULL; + if (strcmp(child->key, "service") == 0) { + if (service_name != NULL) return NULL; // Duplicate. + if (child->value == NULL) return NULL; + service_name = child->value; + } else if (strcmp(child->key, "method") == 0) { + if (method_name != NULL) return NULL; // Duplicate. + if (child->value == NULL) return NULL; + method_name = child->value; + } + } + if (service_name == NULL) return NULL; // Required field. + char* path; + gpr_asprintf(&path, "/%s/%s", service_name, + method_name == NULL ? "*" : method_name); + return path; +} + +// Parses the method config from \a json. Adds an entry to \a entries for +// each name found, incrementing \a idx for each entry added. +static bool parse_json_method_config( + grpc_json* json, void* (*create_value)(const grpc_json* method_config_json), + const grpc_mdstr_hash_table_vtable* vtable, + grpc_mdstr_hash_table_entry* entries, size_t* idx) { + // Construct value. + void* method_config = create_value(json); + if (method_config == NULL) return NULL; + // Construct list of paths. + bool retval = false; + gpr_strvec paths; + gpr_strvec_init(&paths); + for (grpc_json* child = json->child; child != NULL; child = child->next) { + if (child->key == NULL) continue; + if (strcmp(child->key, "name") == 0) { + if (child->type != GRPC_JSON_ARRAY) goto done; + for (grpc_json* name = child->child; name != NULL; name = name->next) { + char* path = parse_json_method_name(name); + gpr_strvec_add(&paths, path); + } + } + } + if (paths.count == 0) goto done; // No names specified. + // Add entry for each path. + for (size_t i = 0; i < paths.count; ++i) { + entries[*idx].key = grpc_mdstr_from_string(paths.strs[i]); + entries[*idx].value = vtable->copy_value(method_config); + entries[*idx].vtable = vtable; + ++*idx; + } + retval = true; +done: + vtable->destroy_value(method_config); + gpr_strvec_destroy(&paths); + return retval; +} + +grpc_mdstr_hash_table* grpc_method_config_table_create_from_json( + const grpc_json* json, + void* (*create_value)(const grpc_json* method_config_json), + const grpc_mdstr_hash_table_vtable* vtable) { + // Traverse parsed JSON tree. + if (json->type != GRPC_JSON_OBJECT || json->key != NULL) return NULL; + size_t num_entries = 0; + grpc_mdstr_hash_table_entry* entries = NULL; + for (grpc_json* field = json->child; field != NULL; field = field->next) { + if (field->key == NULL) return NULL; + if (strcmp(field->key, "method_config") == 0) { + if (entries != NULL) return NULL; // Duplicate. + if (field->type != GRPC_JSON_ARRAY) return NULL; + // Find number of entries. + for (grpc_json* method = field->child; method != NULL; + method = method->next) { + num_entries += count_names_in_method_config_json(method); + } + // Populate method config table entries. + entries = gpr_malloc(num_entries * sizeof(grpc_mdstr_hash_table_entry)); + size_t idx = 0; + for (grpc_json* method = field->child; method != NULL; + method = method->next) { + if (!parse_json_method_config(method, create_value, vtable, entries, + &idx)) { + return NULL; + } + } + GPR_ASSERT(idx == num_entries); + } + } + // Instantiate method config table. + grpc_mdstr_hash_table* method_config_table = NULL; + if (entries != NULL) { + method_config_table = grpc_mdstr_hash_table_create(num_entries, entries); + // Clean up. + for (size_t i = 0; i < num_entries; ++i) { + GRPC_MDSTR_UNREF(entries[i].key); + vtable->destroy_value(entries[i].value); + } + gpr_free(entries); + } + return method_config_table; +} + +void* grpc_method_config_table_get(const grpc_mdstr_hash_table* table, + const grpc_mdstr* path) { + void* value = grpc_mdstr_hash_table_get(table, path); + // If we didn't find a match for the path, try looking for a wildcard + // entry (i.e., change "/service/method" to "/service/*"). + if (value == NULL) { + const char* path_str = grpc_mdstr_as_c_string(path); + const char* sep = strrchr(path_str, '/') + 1; + const size_t len = (size_t)(sep - path_str); + char* buf = gpr_malloc(len + 2); // '*' and NUL + memcpy(buf, path_str, len); + buf[len] = '*'; + buf[len + 1] = '\0'; + grpc_mdstr* wildcard_path = grpc_mdstr_from_string(buf); + gpr_free(buf); + value = grpc_mdstr_hash_table_get(table, wildcard_path); + GRPC_MDSTR_UNREF(wildcard_path); + } + return value; +} + +const char* grpc_service_config_get_lb_policy_name( + grpc_json_tree* service_config) { + grpc_json* json = service_config->root; + if (json->type != GRPC_JSON_OBJECT || json->key != NULL) return NULL; + const char* lb_policy_name = NULL; + for (grpc_json* field = json->child; field != NULL; field = field->next) { + if (field->key == NULL) return NULL; + if (strcmp(field->key, "lb_policy_name") == 0) { + if (lb_policy_name != NULL) return NULL; // Duplicate. + if (field->type != GRPC_JSON_STRING) return NULL; + lb_policy_name = field->value; + } + } + return lb_policy_name; +} + +static void* copy_json_tree(void* t) { return grpc_json_tree_ref(t); } + +static void destroy_json_tree(void* t) { grpc_json_tree_unref(t); } + +static int cmp_json_tree(void* t1, void* t2) { + grpc_json_tree* tree1 = t1; + grpc_json_tree* tree2 = t2; + return grpc_json_cmp(tree1->root, tree2->root); +} + +static grpc_arg_pointer_vtable service_config_arg_vtable = { + copy_json_tree, destroy_json_tree, cmp_json_tree}; + +grpc_arg grpc_service_config_create_channel_arg( + grpc_json_tree* service_config) { + grpc_arg arg; + arg.type = GRPC_ARG_POINTER; + arg.key = GRPC_ARG_SERVICE_CONFIG; + arg.value.pointer.p = service_config; + arg.value.pointer.vtable = &service_config_arg_vtable; + return arg; +} diff --git a/src/core/lib/transport/service_config.h b/src/core/lib/transport/service_config.h new file mode 100644 index 0000000000..c6c8e6be7f --- /dev/null +++ b/src/core/lib/transport/service_config.h @@ -0,0 +1,66 @@ +// +// Copyright 2016, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#ifndef GRPC_CORE_LIB_TRANSPORT_SERVICE_CONFIG_H +#define GRPC_CORE_LIB_TRANSPORT_SERVICE_CONFIG_H + +#include + +#include "src/core/lib/json/json.h" +#include "src/core/lib/transport/mdstr_hash_table.h" + +/// Creates a method config table based on the data in \a json. +/// The table's keys are request paths. The table's value type is +/// returned by \a create_value(), based on data parsed from the JSON tree. +/// \a vtable provides methods used to manage the values. +/// Returns NULL on error. +grpc_mdstr_hash_table* grpc_method_config_table_create_from_json( + const grpc_json* json, + void* (*create_value)(const grpc_json* method_config_json), + const grpc_mdstr_hash_table_vtable* vtable); + +/// Gets the method config for the specified \a path, which should be of +/// the form "/service/method". +/// Returns NULL if the method has no config. +/// Caller does NOT own a reference to the result. +void* grpc_method_config_table_get(const grpc_mdstr_hash_table* table, + const grpc_mdstr* path); + +/// Gets the LB policy name from \a service_config. +/// Returns NULL if no LB policy name was specified. +/// Caller does NOT take ownership. +const char* grpc_service_config_get_lb_policy_name( + grpc_json_tree* service_config); + +/// Creates a channel arg containing \a service_config. +grpc_arg grpc_service_config_create_channel_arg(grpc_json_tree* service_config); + +#endif /* GRPC_CORE_LIB_TRANSPORT_SERVICE_CONFIG_H */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 1ad423909f..6ec2984721 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -180,7 +180,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/transport/mdstr_hash_table.c', 'src/core/lib/transport/metadata.c', 'src/core/lib/transport/metadata_batch.c', - 'src/core/lib/transport/method_config.c', + 'src/core/lib/transport/service_config.c', 'src/core/lib/transport/static_metadata.c', 'src/core/lib/transport/timeout_encoding.c', 'src/core/lib/transport/transport.c', diff --git a/test/core/end2end/connection_refused_test.c b/test/core/end2end/connection_refused_test.c index 2857ca70e8..2814c94e2e 100644 --- a/test/core/end2end/connection_refused_test.c +++ b/test/core/end2end/connection_refused_test.c @@ -41,7 +41,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/transport/metadata.h" -#include "src/core/lib/transport/method_config.h" +#include "src/core/lib/transport/service_config.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/util/port.h" diff --git a/test/core/end2end/tests/cancel_after_accept.c b/test/core/end2end/tests/cancel_after_accept.c index bef33f2a33..a187311b79 100644 --- a/test/core/end2end/tests/cancel_after_accept.c +++ b/test/core/end2end/tests/cancel_after_accept.c @@ -44,7 +44,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/transport/metadata.h" -#include "src/core/lib/transport/method_config.h" +#include "src/core/lib/transport/service_config.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/tests/cancel_test_helpers.h" diff --git a/test/core/end2end/tests/max_message_length.c b/test/core/end2end/tests/max_message_length.c index 4cffff915e..05ac087c13 100644 --- a/test/core/end2end/tests/max_message_length.c +++ b/test/core/end2end/tests/max_message_length.c @@ -44,7 +44,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/transport/metadata.h" -#include "src/core/lib/transport/method_config.h" +#include "src/core/lib/transport/service_config.h" #include "test/core/end2end/cq_verifier.h" diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index e83298766f..c886c88402 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -875,7 +875,7 @@ src/core/lib/transport/connectivity_state.h \ src/core/lib/transport/mdstr_hash_table.h \ src/core/lib/transport/metadata.h \ src/core/lib/transport/metadata_batch.h \ -src/core/lib/transport/method_config.h \ +src/core/lib/transport/service_config.h \ src/core/lib/transport/static_metadata.h \ src/core/lib/transport/timeout_encoding.h \ src/core/lib/transport/transport.h \ @@ -1063,7 +1063,7 @@ src/core/lib/transport/connectivity_state.c \ src/core/lib/transport/mdstr_hash_table.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ -src/core/lib/transport/method_config.c \ +src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index b6c9e0ae94..bf5a0094cc 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -6604,7 +6604,7 @@ "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", - "src/core/lib/transport/method_config.h", + "src/core/lib/transport/service_config.h", "src/core/lib/transport/static_metadata.h", "src/core/lib/transport/timeout_encoding.h", "src/core/lib/transport/transport.h", @@ -6812,8 +6812,8 @@ "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.c", "src/core/lib/transport/metadata_batch.h", - "src/core/lib/transport/method_config.c", - "src/core/lib/transport/method_config.h", + "src/core/lib/transport/service_config.c", + "src/core/lib/transport/service_config.h", "src/core/lib/transport/static_metadata.c", "src/core/lib/transport/static_metadata.h", "src/core/lib/transport/timeout_encoding.c", diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index d9d0d42d67..a7aecb1c98 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -384,7 +384,7 @@ - + @@ -677,7 +677,7 @@ - + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index ab9b76073c..9574f9784a 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -310,7 +310,7 @@ src\core\lib\transport - + src\core\lib\transport @@ -974,7 +974,7 @@ src\core\lib\transport - + src\core\lib\transport diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj index 39c144d992..9d3bfa808f 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -277,7 +277,7 @@ - + @@ -528,7 +528,7 @@ - + diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters index 0fbfc3acd3..8257c731af 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -367,7 +367,7 @@ src\core\lib\transport - + src\core\lib\transport @@ -770,7 +770,7 @@ src\core\lib\transport - + src\core\lib\transport diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index 87e3921ff9..1d334bdeee 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -374,7 +374,7 @@ - + @@ -645,7 +645,7 @@ - + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index 1e719226fa..daed8db5ae 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -313,7 +313,7 @@ src\core\lib\transport - + src\core\lib\transport @@ -887,7 +887,7 @@ src\core\lib\transport - + src\core\lib\transport -- cgit v1.2.3 From 9ec28af03aaad085902c65b7a59fca5abbedcbad Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 3 Nov 2016 12:32:39 -0700 Subject: Change value of channel arg to string form, and reparse in each place we use it. --- src/core/ext/client_channel/client_channel.c | 10 ++-- src/core/lib/channel/message_size_filter.c | 10 ++-- src/core/lib/json/json.c | 59 -------------------- src/core/lib/json/json.h | 19 ------- src/core/lib/transport/service_config.c | 78 +++++++++++++-------------- src/core/lib/transport/service_config.h | 26 +++++---- test/core/end2end/connection_refused_test.c | 9 ++-- test/core/end2end/tests/cancel_after_accept.c | 9 ++-- test/core/end2end/tests/max_message_length.c | 18 ++++--- 9 files changed, 84 insertions(+), 154 deletions(-) (limited to 'test/core') diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c index d9161f47cd..023bd24c19 100644 --- a/src/core/ext/client_channel/client_channel.c +++ b/src/core/ext/client_channel/client_channel.c @@ -302,11 +302,13 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_SERVICE_CONFIG); if (channel_arg != NULL) { - GPR_ASSERT(channel_arg->type == GRPC_ARG_POINTER); - grpc_json_tree *service_config_json = channel_arg->value.pointer.p; - method_params_table = grpc_method_config_table_create_from_json( - service_config_json->root, method_parameters_create_from_json, + GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); + grpc_service_config* service_config = + grpc_service_config_create(channel_arg->value.string); + method_params_table = grpc_service_config_create_method_config_table( + service_config, method_parameters_create_from_json, &method_parameters_vtable); + grpc_service_config_destroy(service_config); } // Clean up. grpc_channel_args_destroy(chand->resolver_result); diff --git a/src/core/lib/channel/message_size_filter.c b/src/core/lib/channel/message_size_filter.c index f826c74f89..b579fa367a 100644 --- a/src/core/lib/channel/message_size_filter.c +++ b/src/core/lib/channel/message_size_filter.c @@ -223,11 +223,13 @@ static void init_channel_elem(grpc_exec_ctx* exec_ctx, const grpc_arg* channel_arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVICE_CONFIG); if (channel_arg != NULL) { - GPR_ASSERT(channel_arg->type == GRPC_ARG_POINTER); - grpc_json_tree* json_tree = channel_arg->value.pointer.p; - chand->method_limit_table = grpc_method_config_table_create_from_json( - json_tree->root, message_size_limits_create_from_json, + GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); + grpc_service_config* service_config = + grpc_service_config_create(channel_arg->value.string); + chand->method_limit_table = grpc_service_config_create_method_config_table( + service_config, message_size_limits_create_from_json, &message_size_limits_vtable); + grpc_service_config_destroy(service_config); } } diff --git a/src/core/lib/json/json.c b/src/core/lib/json/json.c index 9acf3b0438..48b13686d7 100644 --- a/src/core/lib/json/json.c +++ b/src/core/lib/json/json.c @@ -34,8 +34,6 @@ #include #include -#include -#include #include "src/core/lib/json/json.h" @@ -64,60 +62,3 @@ void grpc_json_destroy(grpc_json* json) { gpr_free(json); } - -int grpc_json_cmp(const grpc_json* json1, const grpc_json* json2) { - if (json1 == NULL) { - if (json2 != NULL) return 1; - return 0; // Both NULL. - } else { - if (json2 == NULL) return -1; - } - // Compare type. - if (json1->type > json2->type) return 1; - if (json1->type < json2->type) return -1; - // Compare key. - if (json1->key == NULL) { - if (json2->key != NULL) return -1; - } else { - if (json2->key == NULL) return 1; - int retval = strcmp(json1->key, json2->key); - if (retval != 0) return retval; - } - // Compare value. - if (json1->value == NULL) { - if (json2->value != NULL) return -1; - } else { - if (json2->value == NULL) return 1; - int retval = strcmp(json1->value, json2->value); - if (retval != 0) return retval; - } - // Recursively compare the next pointer. - int retval = grpc_json_cmp(json1->next, json2->next); - if (retval != 0) return retval; - // Recursively compare the child pointer. - retval = grpc_json_cmp(json1->child, json2->child); - if (retval != 0) return retval; - // Both are the same. - return 0; -} - -grpc_json_tree* grpc_json_tree_create(const char* json_string) { - grpc_json_tree* tree = gpr_malloc(sizeof(*tree)); - tree->string = gpr_strdup(json_string); - tree->root = grpc_json_parse_string(tree->string); - gpr_ref_init(&tree->refs, 1); - return tree; -} - -grpc_json_tree* grpc_json_tree_ref(grpc_json_tree* tree) { - gpr_ref(&tree->refs); - return tree; -} - -void grpc_json_tree_unref(grpc_json_tree* tree) { - if (gpr_unref(&tree->refs)) { - grpc_json_destroy(tree->root); - gpr_free(tree->string); - gpr_free(tree); - } -} diff --git a/src/core/lib/json/json.h b/src/core/lib/json/json.h index 1663c690e5..7111db0b52 100644 --- a/src/core/lib/json/json.h +++ b/src/core/lib/json/json.h @@ -36,8 +36,6 @@ #include -#include - #include "src/core/lib/json/json_common.h" /* A tree-like structure to hold json values. The key and value pointers @@ -87,21 +85,4 @@ char* grpc_json_dump_to_string(grpc_json* json, int indent); grpc_json* grpc_json_create(grpc_json_type type); void grpc_json_destroy(grpc_json* json); -/* Compares two JSON trees. */ -int grpc_json_cmp(const grpc_json* json1, const grpc_json* json2); - -/* A wrapper that contains the string used for underlying allocation and - is refcounted. */ -typedef struct { - grpc_json* root; - char* string; - gpr_refcount refs; -} grpc_json_tree; - -/* Creates a copy of \a json_string. */ -grpc_json_tree* grpc_json_tree_create(const char* json_string); - -grpc_json_tree* grpc_json_tree_ref(grpc_json_tree* tree); -void grpc_json_tree_unref(grpc_json_tree* tree); - #endif /* GRPC_CORE_LIB_JSON_JSON_H */ diff --git a/src/core/lib/transport/service_config.c b/src/core/lib/transport/service_config.c index 2a717e7b9b..a467b8c6af 100644 --- a/src/core/lib/transport/service_config.c +++ b/src/core/lib/transport/service_config.c @@ -42,6 +42,40 @@ #include "src/core/lib/support/string.h" #include "src/core/lib/transport/mdstr_hash_table.h" +struct grpc_service_config { + char* string; + grpc_json* json; +}; + +grpc_service_config* grpc_service_config_create(const char* json_string) { + grpc_service_config* service_config = gpr_malloc(sizeof(*service_config)); + service_config->string = gpr_strdup(json_string); + service_config->json = grpc_json_parse_string(service_config->string); + return service_config; +} + +void grpc_service_config_destroy(grpc_service_config* service_config) { + grpc_json_destroy(service_config->json); + gpr_free(service_config->string); + gpr_free(service_config); +} + +const char* grpc_service_config_get_lb_policy_name( + const grpc_service_config* service_config) { + const grpc_json* json = service_config->json; + if (json->type != GRPC_JSON_OBJECT || json->key != NULL) return NULL; + const char* lb_policy_name = NULL; + for (grpc_json* field = json->child; field != NULL; field = field->next) { + if (field->key == NULL) return NULL; + if (strcmp(field->key, "lb_policy_name") == 0) { + if (lb_policy_name != NULL) return NULL; // Duplicate. + if (field->type != GRPC_JSON_STRING) return NULL; + lb_policy_name = field->value; + } + } + return lb_policy_name; +} + // Returns the number of names specified in the method config \a json. static size_t count_names_in_method_config_json(grpc_json* json) { size_t num_names = 0; @@ -115,10 +149,11 @@ done: return retval; } -grpc_mdstr_hash_table* grpc_method_config_table_create_from_json( - const grpc_json* json, +grpc_mdstr_hash_table* grpc_service_config_create_method_config_table( + const grpc_service_config* service_config, void* (*create_value)(const grpc_json* method_config_json), const grpc_mdstr_hash_table_vtable* vtable) { + const grpc_json* json = service_config->json; // Traverse parsed JSON tree. if (json->type != GRPC_JSON_OBJECT || json->key != NULL) return NULL; size_t num_entries = 0; @@ -180,42 +215,3 @@ void* grpc_method_config_table_get(const grpc_mdstr_hash_table* table, } return value; } - -const char* grpc_service_config_get_lb_policy_name( - grpc_json_tree* service_config) { - grpc_json* json = service_config->root; - if (json->type != GRPC_JSON_OBJECT || json->key != NULL) return NULL; - const char* lb_policy_name = NULL; - for (grpc_json* field = json->child; field != NULL; field = field->next) { - if (field->key == NULL) return NULL; - if (strcmp(field->key, "lb_policy_name") == 0) { - if (lb_policy_name != NULL) return NULL; // Duplicate. - if (field->type != GRPC_JSON_STRING) return NULL; - lb_policy_name = field->value; - } - } - return lb_policy_name; -} - -static void* copy_json_tree(void* t) { return grpc_json_tree_ref(t); } - -static void destroy_json_tree(void* t) { grpc_json_tree_unref(t); } - -static int cmp_json_tree(void* t1, void* t2) { - grpc_json_tree* tree1 = t1; - grpc_json_tree* tree2 = t2; - return grpc_json_cmp(tree1->root, tree2->root); -} - -static grpc_arg_pointer_vtable service_config_arg_vtable = { - copy_json_tree, destroy_json_tree, cmp_json_tree}; - -grpc_arg grpc_service_config_create_channel_arg( - grpc_json_tree* service_config) { - grpc_arg arg; - arg.type = GRPC_ARG_POINTER; - arg.key = GRPC_ARG_SERVICE_CONFIG; - arg.value.pointer.p = service_config; - arg.value.pointer.vtable = &service_config_arg_vtable; - return arg; -} diff --git a/src/core/lib/transport/service_config.h b/src/core/lib/transport/service_config.h index c6c8e6be7f..bf50226f96 100644 --- a/src/core/lib/transport/service_config.h +++ b/src/core/lib/transport/service_config.h @@ -37,16 +37,29 @@ #include "src/core/lib/json/json.h" #include "src/core/lib/transport/mdstr_hash_table.h" +typedef struct grpc_service_config grpc_service_config; + +grpc_service_config* grpc_service_config_create(const char* json_string); +void grpc_service_config_destroy(grpc_service_config* service_config); + +/// Gets the LB policy name from \a service_config. +/// Returns NULL if no LB policy name was specified. +/// Caller does NOT take ownership. +const char* grpc_service_config_get_lb_policy_name( + const grpc_service_config* service_config); + /// Creates a method config table based on the data in \a json. /// The table's keys are request paths. The table's value type is /// returned by \a create_value(), based on data parsed from the JSON tree. /// \a vtable provides methods used to manage the values. /// Returns NULL on error. -grpc_mdstr_hash_table* grpc_method_config_table_create_from_json( - const grpc_json* json, +grpc_mdstr_hash_table* grpc_service_config_create_method_config_table( + const grpc_service_config* service_config, void* (*create_value)(const grpc_json* method_config_json), const grpc_mdstr_hash_table_vtable* vtable); +/// A helper function for looking up values in the table returned by +/// grpc_service_config_create_method_config_table(). /// Gets the method config for the specified \a path, which should be of /// the form "/service/method". /// Returns NULL if the method has no config. @@ -54,13 +67,4 @@ grpc_mdstr_hash_table* grpc_method_config_table_create_from_json( void* grpc_method_config_table_get(const grpc_mdstr_hash_table* table, const grpc_mdstr* path); -/// Gets the LB policy name from \a service_config. -/// Returns NULL if no LB policy name was specified. -/// Caller does NOT take ownership. -const char* grpc_service_config_get_lb_policy_name( - grpc_json_tree* service_config); - -/// Creates a channel arg containing \a service_config. -grpc_arg grpc_service_config_create_channel_arg(grpc_json_tree* service_config); - #endif /* GRPC_CORE_LIB_TRANSPORT_SERVICE_CONFIG_H */ diff --git a/test/core/end2end/connection_refused_test.c b/test/core/end2end/connection_refused_test.c index 2814c94e2e..c14d72f49e 100644 --- a/test/core/end2end/connection_refused_test.c +++ b/test/core/end2end/connection_refused_test.c @@ -76,7 +76,10 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_channel_args *args = NULL; if (use_service_config) { GPR_ASSERT(wait_for_ready); - grpc_json_tree *service_config_json = grpc_json_tree_create( + grpc_arg arg; + arg.type = GRPC_ARG_STRING; + arg.key = GRPC_ARG_SERVICE_CONFIG; + arg.value.string = "{\n" " \"method_config\": [ {\n" " \"name\": [\n" @@ -84,10 +87,8 @@ static void run_test(bool wait_for_ready, bool use_service_config) { " ],\n" " \"wait_for_ready\": true\n" " } ]\n" - "}"); - grpc_arg arg = grpc_service_config_create_channel_arg(service_config_json); + "}"; args = grpc_channel_args_copy_and_add(args, &arg, 1); - grpc_json_tree_unref(service_config_json); } /* create a call, channel to a port which will refuse connection */ diff --git a/test/core/end2end/tests/cancel_after_accept.c b/test/core/end2end/tests/cancel_after_accept.c index a187311b79..d3155f1902 100644 --- a/test/core/end2end/tests/cancel_after_accept.c +++ b/test/core/end2end/tests/cancel_after_accept.c @@ -132,7 +132,10 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, grpc_channel_args *args = NULL; if (use_service_config) { - grpc_json_tree *service_config_json = grpc_json_tree_create( + grpc_arg arg; + arg.type = GRPC_ARG_STRING; + arg.key = GRPC_ARG_SERVICE_CONFIG; + arg.value.string = "{\n" " \"method_config\": [ {\n" " \"name\": [\n" @@ -140,10 +143,8 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, " ],\n" " \"timeout\": { \"seconds\": 5 }\n" " } ]\n" - "}"); - grpc_arg arg = grpc_service_config_create_channel_arg(service_config_json); + "}"; args = grpc_channel_args_copy_and_add(args, &arg, 1); - grpc_json_tree_unref(service_config_json); } grpc_end2end_test_fixture f = diff --git a/test/core/end2end/tests/max_message_length.c b/test/core/end2end/tests/max_message_length.c index 05ac087c13..f1dbc214dd 100644 --- a/test/core/end2end/tests/max_message_length.c +++ b/test/core/end2end/tests/max_message_length.c @@ -137,7 +137,10 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, if (use_service_config) { // We don't currently support service configs on the server side. GPR_ASSERT(send_limit); - grpc_json_tree *service_config_json = grpc_json_tree_create( + grpc_arg arg; + arg.type = GRPC_ARG_STRING; + arg.key = GRPC_ARG_SERVICE_CONFIG; + arg.value.string = "{\n" " \"method_config\": [ {\n" " \"name\": [\n" @@ -145,10 +148,8 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, " ],\n" " \"max_request_message_bytes\": 5\n" " } ]\n" - "}"); - grpc_arg arg = grpc_service_config_create_channel_arg(service_config_json); + "}"; client_args = grpc_channel_args_copy_and_add(NULL, &arg, 1); - grpc_json_tree_unref(service_config_json); } else { // Set limit via channel args. grpc_arg arg; @@ -308,7 +309,10 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, if (use_service_config) { // We don't currently support service configs on the server side. GPR_ASSERT(!send_limit); - grpc_json_tree *service_config_json = grpc_json_tree_create( + grpc_arg arg; + arg.type = GRPC_ARG_STRING; + arg.key = GRPC_ARG_SERVICE_CONFIG; + arg.value.string = "{\n" " \"method_config\": [ {\n" " \"name\": [\n" @@ -316,10 +320,8 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, " ],\n" " \"max_response_message_bytes\": 5\n" " } ]\n" - "}"); - grpc_arg arg = grpc_service_config_create_channel_arg(service_config_json); + "}"; client_args = grpc_channel_args_copy_and_add(NULL, &arg, 1); - grpc_json_tree_unref(service_config_json); } else { // Set limit via channel args. grpc_arg arg; -- cgit v1.2.3 From c625c7a023cb688a135be96cef64543f0e08a851 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 9 Nov 2016 14:12:37 -0800 Subject: Allow fetching service config via grpc_channel_get_info(). --- include/grpc/impl/codegen/grpc_types.h | 3 +++ src/core/ext/client_channel/client_channel.c | 16 +++++++++++- test/core/client_channel/lb_policies_test.c | 37 ++++++++++++++++++++++------ 3 files changed, 48 insertions(+), 8 deletions(-) (limited to 'test/core') diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index 1bf78e4e69..9cb89e9841 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -473,6 +473,9 @@ typedef struct { /* If non-NULL, will be set to point to a string indicating the LB * policy name. Caller takes ownership. */ char **lb_policy_name; + /* If non-NULL, will be set to point to a string containing the + * service config used by the channel in JSON form. */ + char **service_config_json; } grpc_channel_info; typedef struct grpc_resource_quota grpc_resource_quota; diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c index 55cb660311..139912e4ba 100644 --- a/src/core/ext/client_channel/client_channel.c +++ b/src/core/ext/client_channel/client_channel.c @@ -144,6 +144,8 @@ typedef struct client_channel_channel_data { /** currently active load balancer */ char *lb_policy_name; grpc_lb_policy *lb_policy; + /** service config in JSON form */ + char *service_config_json; /** maps method names to method_parameters structs */ grpc_mdstr_hash_table *method_params_table; /** incoming resolver result - set by resolver.next() */ @@ -250,6 +252,7 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; bool exit_idle = false; grpc_error *state_error = GRPC_ERROR_CREATE("No load balancing policy"); + char *service_config_json = NULL; if (chand->resolver_result != NULL) { // Find LB policy name. @@ -305,8 +308,9 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, grpc_channel_args_find(chand->resolver_result, GRPC_ARG_SERVICE_CONFIG); if (channel_arg != NULL) { GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); + service_config_json = gpr_strdup(channel_arg->value.string); grpc_service_config *service_config = - grpc_service_config_create(channel_arg->value.string); + grpc_service_config_create(service_config_json); if (service_config != NULL) { method_params_table = grpc_service_config_create_method_config_table( service_config, method_parameters_create_from_json, @@ -334,6 +338,10 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, } old_lb_policy = chand->lb_policy; chand->lb_policy = lb_policy; + if (service_config_json != NULL) { + gpr_free(chand->service_config_json); + chand->service_config_json = service_config_json; + } if (chand->method_params_table != NULL) { grpc_mdstr_hash_table_unref(chand->method_params_table); } @@ -469,6 +477,11 @@ static void cc_get_channel_info(grpc_exec_ctx *exec_ctx, ? NULL : gpr_strdup(chand->lb_policy_name); } + if (info->service_config_json != NULL) { + *info->service_config_json = chand->service_config_json == NULL + ? NULL + : gpr_strdup(chand->service_config_json); + } gpr_mu_unlock(&chand->mu); } @@ -512,6 +525,7 @@ static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx, GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); } gpr_free(chand->lb_policy_name); + gpr_free(chand->service_config_json); if (chand->method_params_table != NULL) { grpc_mdstr_hash_table_unref(chand->method_params_table); } diff --git a/test/core/client_channel/lb_policies_test.c b/test/core/client_channel/lb_policies_test.c index 198aafb91f..3aba906094 100644 --- a/test/core/client_channel/lb_policies_test.c +++ b/test/core/client_channel/lb_policies_test.c @@ -43,6 +43,7 @@ #include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/client_channel/lb_policy_registry.h" +#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/channel.h" @@ -642,21 +643,43 @@ static void test_pending_calls(size_t concurrent_calls) { } static void test_get_channel_info() { - grpc_channel *channel = grpc_insecure_channel_create( - "test:127.0.0.1:1234?lb_policy=round_robin", NULL, NULL); + grpc_channel *channel = + grpc_insecure_channel_create("ipv4:127.0.0.1:1234", NULL, NULL); // Ensures that resolver returns. grpc_channel_check_connectivity_state(channel, true /* try_to_connect */); - // Use grpc_channel_get_info() to get LB policy name. - char *lb_policy_name = NULL; + // First, request no fields. This is a no-op. grpc_channel_info channel_info; + memset(&channel_info, 0, sizeof(channel_info)); + grpc_channel_get_info(channel, &channel_info); + // Request LB policy name. + char *lb_policy_name = NULL; channel_info.lb_policy_name = &lb_policy_name; grpc_channel_get_info(channel, &channel_info); GPR_ASSERT(lb_policy_name != NULL); - GPR_ASSERT(strcmp(lb_policy_name, "round_robin") == 0); + GPR_ASSERT(strcmp(lb_policy_name, "pick_first") == 0); gpr_free(lb_policy_name); - // Try again without requesting anything. This is a no-op. - channel_info.lb_policy_name = NULL; + // Request service config, which does not exist, so we'll get nothing back. + memset(&channel_info, 0, sizeof(channel_info)); + char *service_config_json = "dummy_string"; + channel_info.service_config_json = &service_config_json; + grpc_channel_get_info(channel, &channel_info); + GPR_ASSERT(service_config_json == NULL); + // Recreate the channel such that it has a service config. + grpc_channel_destroy(channel); + grpc_arg arg; + arg.type = GRPC_ARG_STRING; + arg.key = GRPC_ARG_SERVICE_CONFIG; + arg.value.string = "{\"lb_policy_name\": \"round_robin\"}"; + grpc_channel_args *args = grpc_channel_args_copy_and_add(NULL, &arg, 1); + channel = grpc_insecure_channel_create("ipv4:127.0.0.1:1234", args, NULL); + grpc_channel_args_destroy(args); + // Ensures that resolver returns. + grpc_channel_check_connectivity_state(channel, true /* try_to_connect */); + // Now request the service config again. grpc_channel_get_info(channel, &channel_info); + GPR_ASSERT(service_config_json != NULL); + GPR_ASSERT(strcmp(service_config_json, arg.value.string) == 0); + gpr_free(service_config_json); // Clean up. grpc_channel_destroy(channel); } -- cgit v1.2.3 From 84c8a027d3b9427982bc31be52e587ecd3462b9d Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 10 Nov 2016 09:39:34 -0800 Subject: Change JSON format to use the standard proto3 mapping for each type. --- src/core/ext/client_channel/client_channel.c | 49 +++++++++++++++++---------- src/core/lib/channel/message_size_filter.c | 12 +++---- src/core/lib/support/string.c | 2 +- src/core/lib/support/string.h | 2 +- src/core/lib/transport/service_config.c | 24 ++++++------- test/core/end2end/connection_refused_test.c | 4 +-- test/core/end2end/tests/cancel_after_accept.c | 4 +-- test/core/end2end/tests/max_message_length.c | 8 ++--- 8 files changed, 58 insertions(+), 47 deletions(-) (limited to 'test/core') diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c index 139912e4ba..a92a220c74 100644 --- a/src/core/ext/client_channel/client_channel.c +++ b/src/core/ext/client_channel/client_channel.c @@ -90,7 +90,7 @@ static void *method_parameters_create_from_json(const grpc_json *json) { gpr_timespec timeout = {0, 0, GPR_TIMESPAN}; for (grpc_json *field = json->child; field != NULL; field = field->next) { if (field->key == NULL) continue; - if (strcmp(field->key, "wait_for_ready") == 0) { + if (strcmp(field->key, "waitForReady") == 0) { if (wait_for_ready != WAIT_FOR_READY_UNSET) return NULL; // Duplicate. if (field->type != GRPC_JSON_TRUE && field->type != GRPC_JSON_FALSE) { return NULL; @@ -99,26 +99,39 @@ static void *method_parameters_create_from_json(const grpc_json *json) { : WAIT_FOR_READY_FALSE; } else if (strcmp(field->key, "timeout") == 0) { if (timeout.tv_sec > 0 || timeout.tv_nsec > 0) return NULL; // Duplicate. - if (field->type != GRPC_JSON_OBJECT) return NULL; - if (field->child == NULL) return NULL; - for (grpc_json *subfield = field->child; subfield != NULL; - subfield = subfield->next) { - if (subfield->key == NULL) return NULL; - if (strcmp(subfield->key, "seconds") == 0) { - if (timeout.tv_sec > 0) return NULL; // Duplicate. - if (subfield->type != GRPC_JSON_NUMBER) return NULL; - timeout.tv_sec = gpr_parse_nonnegative_number(subfield->value); - if (timeout.tv_sec == -1) return NULL; - } else if (strcmp(subfield->key, "nanos") == 0) { - if (timeout.tv_nsec > 0) return NULL; // Duplicate. - if (subfield->type != GRPC_JSON_NUMBER) return NULL; - timeout.tv_nsec = gpr_parse_nonnegative_number(subfield->value); - if (timeout.tv_nsec == -1) return NULL; - } else { - // Unknown key. + if (field->type != GRPC_JSON_STRING) return NULL; + size_t len = strlen(field->value); + if (field->value[len - 1] != 's') return NULL; + char* buf = gpr_strdup(field->value); + buf[len - 1] = '\0'; // Remove trailing 's'. + char* decimal_point = strchr(buf, '.'); + if (decimal_point != NULL) { + *decimal_point = '\0'; + timeout.tv_nsec = gpr_parse_nonnegative_int(decimal_point + 1); + if (timeout.tv_nsec == -1) { + gpr_free(buf); return NULL; } + // There should always be exactly 3, 6, or 9 fractional digits. + int multiplier = 1; + switch (strlen(decimal_point + 1)) { + case 9: + break; + case 6: + multiplier *= 1000; + break; + case 3: + multiplier *= 1000000; + break; + default: // Unsupported number of digits. + gpr_free(buf); + return NULL; + } + timeout.tv_nsec *= multiplier; } + timeout.tv_sec = gpr_parse_nonnegative_int(buf); + if (timeout.tv_sec == -1) return NULL; + gpr_free(buf); } } method_parameters *value = gpr_malloc(sizeof(method_parameters)); diff --git a/src/core/lib/channel/message_size_filter.c b/src/core/lib/channel/message_size_filter.c index 507ea26c05..28ad587c0e 100644 --- a/src/core/lib/channel/message_size_filter.c +++ b/src/core/lib/channel/message_size_filter.c @@ -65,15 +65,15 @@ static void* message_size_limits_create_from_json(const grpc_json* json) { int max_response_message_bytes = -1; for (grpc_json* field = json->child; field != NULL; field = field->next) { if (field->key == NULL) continue; - if (strcmp(field->key, "max_request_message_bytes") == 0) { + if (strcmp(field->key, "maxRequestMessageBytes") == 0) { if (max_request_message_bytes >= 0) return NULL; // Duplicate. - if (field->type != GRPC_JSON_NUMBER) return NULL; - max_request_message_bytes = gpr_parse_nonnegative_number(field->value); + if (field->type != GRPC_JSON_STRING) return NULL; + max_request_message_bytes = gpr_parse_nonnegative_int(field->value); if (max_request_message_bytes == -1) return NULL; - } else if (strcmp(field->key, "max_response_message_bytes") == 0) { + } else if (strcmp(field->key, "maxResponseMessageBytes") == 0) { if (max_response_message_bytes >= 0) return NULL; // Duplicate. - if (field->type != GRPC_JSON_NUMBER) return NULL; - max_response_message_bytes = gpr_parse_nonnegative_number(field->value); + if (field->type != GRPC_JSON_STRING) return NULL; + max_response_message_bytes = gpr_parse_nonnegative_int(field->value); if (max_response_message_bytes == -1) return NULL; } } diff --git a/src/core/lib/support/string.c b/src/core/lib/support/string.c index aa58dd15e3..f10a30f0fd 100644 --- a/src/core/lib/support/string.c +++ b/src/core/lib/support/string.c @@ -191,7 +191,7 @@ int int64_ttoa(int64_t value, char *string) { return i; } -int gpr_parse_nonnegative_number(const char *value) { +int gpr_parse_nonnegative_int(const char *value) { char *end; long result = strtol(value, &end, 0); if (*end != '\0' || result < 0 || result > INT_MAX) return -1; diff --git a/src/core/lib/support/string.h b/src/core/lib/support/string.h index a691ebb2a6..e933e2eb46 100644 --- a/src/core/lib/support/string.h +++ b/src/core/lib/support/string.h @@ -78,7 +78,7 @@ where long is 32bit is size.*/ int int64_ttoa(int64_t value, char *output); // Parses a non-negative number from a value string. Returns -1 on error. -int gpr_parse_nonnegative_number(const char *value); +int gpr_parse_nonnegative_int(const char *value); /* Reverse a run of bytes */ void gpr_reverse_bytes(char *str, int len); diff --git a/src/core/lib/transport/service_config.c b/src/core/lib/transport/service_config.c index a8494cbe8b..2e2b59e3f7 100644 --- a/src/core/lib/transport/service_config.c +++ b/src/core/lib/transport/service_config.c @@ -46,8 +46,8 @@ // JSON form, which will look like this: // // { -// "lb_policy_name": "string", // optional -// "method_config": [ // array of one or more method_config objects +// "loadBalancingPolicy": "string", // optional +// "methodConfig": [ // array of one or more method_config objects // { // "name": [ // array of one or more name objects // { @@ -55,15 +55,13 @@ // "method": "string", // optional // } // ], -// // remaining fields are optional -// "wait_for_ready": bool, -// "timeout": { -// // one or both of these fields may be specified -// "seconds": number, -// "nanos": number, -// }, -// "max_request_message_bytes": number, -// "max_response_message_bytes": number +// // remaining fields are optional. +// // see https://developers.google.com/protocol-buffers/docs/proto3#json +// // for format details. +// "waitForReady": bool, +// "timeout": "duration_string", +// "maxRequestMessageBytes": "int64_string", +// "maxResponseMessageBytes": "int64_string", // } // ] // } @@ -100,7 +98,7 @@ const char* grpc_service_config_get_lb_policy_name( const char* lb_policy_name = NULL; for (grpc_json* field = json->child; field != NULL; field = field->next) { if (field->key == NULL) return NULL; - if (strcmp(field->key, "lb_policy_name") == 0) { + if (strcmp(field->key, "loadBalancingPolicy") == 0) { if (lb_policy_name != NULL) return NULL; // Duplicate. if (field->type != GRPC_JSON_STRING) return NULL; lb_policy_name = field->value; @@ -194,7 +192,7 @@ grpc_mdstr_hash_table* grpc_service_config_create_method_config_table( grpc_mdstr_hash_table_entry* entries = NULL; for (grpc_json* field = json->child; field != NULL; field = field->next) { if (field->key == NULL) return NULL; - if (strcmp(field->key, "method_config") == 0) { + if (strcmp(field->key, "methodConfig") == 0) { if (entries != NULL) return NULL; // Duplicate. if (field->type != GRPC_JSON_ARRAY) return NULL; // Find number of entries. diff --git a/test/core/end2end/connection_refused_test.c b/test/core/end2end/connection_refused_test.c index c14d72f49e..728d6dca59 100644 --- a/test/core/end2end/connection_refused_test.c +++ b/test/core/end2end/connection_refused_test.c @@ -81,11 +81,11 @@ static void run_test(bool wait_for_ready, bool use_service_config) { arg.key = GRPC_ARG_SERVICE_CONFIG; arg.value.string = "{\n" - " \"method_config\": [ {\n" + " \"methodConfig\": [ {\n" " \"name\": [\n" " { \"service\": \"service\", \"method\": \"method\" }\n" " ],\n" - " \"wait_for_ready\": true\n" + " \"waitForReady\": true\n" " } ]\n" "}"; args = grpc_channel_args_copy_and_add(args, &arg, 1); diff --git a/test/core/end2end/tests/cancel_after_accept.c b/test/core/end2end/tests/cancel_after_accept.c index 28d24aa306..e582c59f2d 100644 --- a/test/core/end2end/tests/cancel_after_accept.c +++ b/test/core/end2end/tests/cancel_after_accept.c @@ -139,11 +139,11 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, arg.key = GRPC_ARG_SERVICE_CONFIG; arg.value.string = "{\n" - " \"method_config\": [ {\n" + " \"methodConfig\": [ {\n" " \"name\": [\n" " { \"service\": \"service\", \"method\": \"method\" }\n" " ],\n" - " \"timeout\": { \"seconds\": 5 }\n" + " \"timeout\": \"5s\"\n" " } ]\n" "}"; args = grpc_channel_args_copy_and_add(args, &arg, 1); diff --git a/test/core/end2end/tests/max_message_length.c b/test/core/end2end/tests/max_message_length.c index 90dae50b75..c222d9dfae 100644 --- a/test/core/end2end/tests/max_message_length.c +++ b/test/core/end2end/tests/max_message_length.c @@ -143,11 +143,11 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, arg.key = GRPC_ARG_SERVICE_CONFIG; arg.value.string = "{\n" - " \"method_config\": [ {\n" + " \"methodConfig\": [ {\n" " \"name\": [\n" " { \"service\": \"service\", \"method\": \"method\" }\n" " ],\n" - " \"max_request_message_bytes\": 5\n" + " \"maxRequestMessageBytes\": \"5\"\n" " } ]\n" "}"; client_args = grpc_channel_args_copy_and_add(NULL, &arg, 1); @@ -317,11 +317,11 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, arg.key = GRPC_ARG_SERVICE_CONFIG; arg.value.string = "{\n" - " \"method_config\": [ {\n" + " \"methodConfig\": [ {\n" " \"name\": [\n" " { \"service\": \"service\", \"method\": \"method\" }\n" " ],\n" - " \"max_response_message_bytes\": 5\n" + " \"maxResponseMessageBytes\": \"5\"\n" " } ]\n" "}"; client_args = grpc_channel_args_copy_and_add(NULL, &arg, 1); -- cgit v1.2.3 From 69f783dffcb94625f503a7af35fd460b83c2fd40 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 10 Nov 2016 10:10:56 -0800 Subject: Allow LB policy name to be matched in a case-insensitive manner. --- src/core/ext/client_channel/lb_policy_registry.c | 8 +++++--- test/core/client_channel/lb_policies_test.c | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'test/core') diff --git a/src/core/ext/client_channel/lb_policy_registry.c b/src/core/ext/client_channel/lb_policy_registry.c index f46a721f9d..90c149d947 100644 --- a/src/core/ext/client_channel/lb_policy_registry.c +++ b/src/core/ext/client_channel/lb_policy_registry.c @@ -35,6 +35,8 @@ #include +#include "src/core/lib/support/string.h" + #define MAX_POLICIES 10 static grpc_lb_policy_factory *g_all_of_the_lb_policies[MAX_POLICIES]; @@ -52,8 +54,8 @@ void grpc_lb_policy_registry_shutdown(void) { void grpc_register_lb_policy(grpc_lb_policy_factory *factory) { int i; for (i = 0; i < g_number_of_lb_policies; i++) { - GPR_ASSERT(0 != strcmp(factory->vtable->name, - g_all_of_the_lb_policies[i]->vtable->name)); + GPR_ASSERT(0 != gpr_stricmp(factory->vtable->name, + g_all_of_the_lb_policies[i]->vtable->name)); } GPR_ASSERT(g_number_of_lb_policies != MAX_POLICIES); grpc_lb_policy_factory_ref(factory); @@ -66,7 +68,7 @@ static grpc_lb_policy_factory *lookup_factory(const char *name) { if (name == NULL) return NULL; for (i = 0; i < g_number_of_lb_policies; i++) { - if (0 == strcmp(name, g_all_of_the_lb_policies[i]->vtable->name)) { + if (0 == gpr_stricmp(name, g_all_of_the_lb_policies[i]->vtable->name)) { return g_all_of_the_lb_policies[i]; } } diff --git a/test/core/client_channel/lb_policies_test.c b/test/core/client_channel/lb_policies_test.c index 3aba906094..b9bd637d35 100644 --- a/test/core/client_channel/lb_policies_test.c +++ b/test/core/client_channel/lb_policies_test.c @@ -554,7 +554,7 @@ static grpc_channel *create_client(const servers_fixture *f) { arg_array[0].value.integer = RETRY_TIMEOUT; arg_array[1].type = GRPC_ARG_STRING; arg_array[1].key = GRPC_ARG_LB_POLICY_NAME; - arg_array[1].value.string = "round_robin"; + arg_array[1].value.string = "ROUND_ROBIN"; args.num_args = 2; args.args = arg_array; @@ -669,7 +669,7 @@ static void test_get_channel_info() { grpc_arg arg; arg.type = GRPC_ARG_STRING; arg.key = GRPC_ARG_SERVICE_CONFIG; - arg.value.string = "{\"lb_policy_name\": \"round_robin\"}"; + arg.value.string = "{\"loadBalancingPolicy\": \"ROUND_ROBIN\"}"; grpc_channel_args *args = grpc_channel_args_copy_and_add(NULL, &arg, 1); channel = grpc_insecure_channel_create("ipv4:127.0.0.1:1234", args, NULL); grpc_channel_args_destroy(args); -- cgit v1.2.3 From 45bc38d11544852fcc981ac6039a89a4197fe329 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 17 Nov 2016 07:30:13 -0800 Subject: Fix build. --- test/core/client_channel/lb_policies_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/core') diff --git a/test/core/client_channel/lb_policies_test.c b/test/core/client_channel/lb_policies_test.c index 5255174852..95595d7c51 100644 --- a/test/core/client_channel/lb_policies_test.c +++ b/test/core/client_channel/lb_policies_test.c @@ -613,7 +613,7 @@ static void test_pending_calls(size_t concurrent_calls) { static void test_get_channel_info() { grpc_channel *channel = - grpc_insecure_channel_create("ipv4:127.0.0.1:1234", &args, NULL); + grpc_insecure_channel_create("ipv4:127.0.0.1:1234", NULL, NULL); // Ensures that resolver returns. grpc_channel_check_connectivity_state(channel, true /* try_to_connect */); // First, request no fields. This is a no-op. -- cgit v1.2.3